| Line 27... |
Line 27... |
| 27 |
|
27 |
|
| 28 |
my $pageTitle = "View League";
|
28 |
my $pageTitle = "View League";
|
| 29 |
my $homeURL = "/";
|
29 |
my $homeURL = "/";
|
| 30 |
my $DBTable = "organization";
|
30 |
my $DBTable = "organization";
|
| 31 |
my %FIELDS = (
|
31 |
my %FIELDS = (
|
| 32 |
id => [qw(ID 5 auto static )],
|
32 |
id => [qw(ID 5 auto static )],
|
| 33 |
league_name => [qw(DisplayName 10 text required )],
|
33 |
league_name => ["League Display Name", 10, 'text', 'required' ],
|
| 34 |
business_name => [qw(BusinessName 15 text )],
|
34 |
business_name => ["Business Name", 15, 'text' ],
|
| 35 |
city => [qw(City 20 text )],
|
35 |
city => [qw(City 20 text )],
|
| 36 |
state_province => [qw(State/Province 25 text )],
|
36 |
state_province => [qw(State/Province 25 text )],
|
| 37 |
country => [qw(Country 30 text )],
|
37 |
country => [qw(Country 30 text )],
|
| 38 |
url => [qw(URL 35 text )],
|
38 |
url => [qw(URL 35 text )],
|
| 39 |
type => [qw(Type 40 select required )],
|
39 |
type => [qw(Type 40 select required )],
|
| 40 |
status => [qw(Status 45 select required )],
|
40 |
status => [qw(Status 45 select required )],
|
| 41 |
legal_entity_type => [qw(LegalType 50 text )],
|
41 |
legal_entity_type => ["Legal Org Type", 50, 'text', ],
|
| 42 |
tax_id => [qw(TaxID 55 text )],
|
42 |
tax_id => [qw(TaxID 55 text )],
|
| 43 |
date_established => [qw(Established 60 date )],
|
43 |
date_established => [qw(Established 60 date )],
|
| 44 |
updated => [qw(Updated 65 readonly static )],
|
44 |
updated => [qw(Updated 65 readonly static )],
|
| Line 45... |
Line 45... |
| 45 |
);
|
45 |
);
|
| 46 |
|
46 |
|
| 47 |
|
47 |
|
| 48 |
my %fieldDisplayName = map { $_ => $FIELDS{$_}->[0] } keys %FIELDS;
|
48 |
my %fieldDisplayName = map { $_ => $FIELDS{$_}->[0] } keys %FIELDS;
|
| 49 |
my %fieldType = map { $_ => $FIELDS{$_}->[2] } keys %FIELDS;
|
49 |
my %fieldType = map { $_ => $FIELDS{$_}->[2] } keys %FIELDS;
|
| 50 |
my @requiredFields = sort fieldOrder grep { defined $FIELDS{$_}->[3] } keys %FIELDS;
|
50 |
my @requiredFields = sort fieldOrder grep { defined $FIELDS{$_}->[3] } keys %FIELDS;
|
| 51 |
my @DBFields = sort fieldOrder grep { $fieldType{$_} =~ /^(text|select|number|switch|date|time|auto)/ } keys %FIELDS;
|
51 |
my @DBFields = sort fieldOrder grep { $fieldType{$_} =~ /^(text|select|number|switch|date|time|auto)/ } keys %FIELDS;
|
| Line 52... |
Line 52... |
| 52 |
my @ROFields = sort fieldOrder grep { $fieldType{$_} =~ /^(readonly)/ } keys %FIELDS;
|
52 |
my @ROFields = sort fieldOrder grep { $fieldType{$_} =~ /^(readonly)/ } keys %FIELDS;
|
| 53 |
my @SAFields = qw/ league_name business_name type status legal_entity_type /;
|
53 |
my @SAFields = qw/ type status /;
|
| 54 |
my $primary = $DBFields[0];
|
54 |
my $primary = $DBFields[0];
|
| Line 98... |
Line 98... |
| 98 |
sub display_form {
|
98 |
sub display_form {
|
| 99 |
my $R = shift;
|
99 |
my $R = shift;
|
| 100 |
my $view = shift // "";
|
100 |
my $view = shift // "";
|
| 101 |
my $actionbutton;
|
101 |
my $actionbutton;
|
| Line 102... |
Line 102... |
| 102 |
|
102 |
|
| Line 103... |
Line 103... |
| 103 |
$view = "View" unless $ORCUSER->{SYSADMIN};
|
103 |
$view = "View" unless $ORCUSER->{SYSADMIN} or $leagueAdmin;
|
| 104 |
|
104 |
|
| 105 |
if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
|
105 |
if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
|
| 106 |
print &formField ("Cancel", "Back", "POSTSAVE");
|
106 |
print &formField ("Cancel", "Back", "POSTSAVE");
|
| Line 124... |
Line 124... |
| 124 |
if ($view eq "Update") {
|
124 |
if ($view eq "Update") {
|
| 125 |
# We'd like to update that thing, give the user a form...
|
125 |
# We'd like to update that thing, give the user a form...
|
| 126 |
print $h->p ("Updating League: $R->{$primary}...");
|
126 |
print $h->p ("Updating League: $R->{$primary}...");
|
| Line 127... |
Line 127... |
| 127 |
|
127 |
|
| - |
|
128 |
foreach (@DBFields) {
|
| 128 |
foreach (@DBFields) {
|
129 |
if (notInArray ($_, \@SAFields) or $ORCUSER->{SYSADMIN}) {
|
| - |
|
130 |
$F{$_} = formField ($_, $F{$_});
|
| - |
|
131 |
}
|
| 129 |
$F{$_} = formField ($_, $F{$_});
|
132 |
|
| Line 130... |
Line 133... |
| 130 |
}
|
133 |
}
|
| 131 |
|
134 |
|
| 132 |
$actionbutton = formField ("choice", "Save");
|
135 |
$actionbutton = formField ("choice", "Save");
|
| Line 147... |
Line 150... |
| 147 |
print $h->p ("Viewing League: $R->{$primary}...");
|
150 |
print $h->p ("Viewing League: $R->{$primary}...");
|
| 148 |
$F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
|
151 |
$F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
|
| Line 149... |
Line 152... |
| 149 |
|
152 |
|
| 150 |
# Put the time fields into the user's preference
|
153 |
# Put the time fields into the user's preference
|
| - |
|
154 |
map { $F{$_} = convertTime $F{$_} } grep { $fieldType{$_} eq "time" } keys %FIELDS;
|
| Line 151... |
Line 155... |
| 151 |
map { $F{$_} = convertTime $F{$_} } grep { $fieldType{$_} eq "time" } keys %FIELDS;
|
155 |
$F{url} = $h->a ({href => $F{url}, target=>"_blank"}, $F{url}) unless !$F{url};
|
| 152 |
|
156 |
|
| 153 |
$actionbutton = formField ("choice", "Update") if $ORCUSER->{SYSADMIN};
|
157 |
$actionbutton = formField ("choice", "Update") if $ORCUSER->{SYSADMIN} or $leagueAdmin;
|
| 154 |
if ($view eq "POSTSAVE" or $choice eq "View") {
|
158 |
if ($view eq "POSTSAVE" or $choice eq "View") {
|
| 155 |
$actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
|
159 |
$actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
|
| 156 |
} else {
|
160 |
} else {
|
| Line 183... |
Line 187... |
| 183 |
])
|
187 |
])
|
| 184 |
);
|
188 |
);
|
| Line 185... |
Line 189... |
| 185 |
|
189 |
|
| Line -... |
Line 190... |
| - |
|
190 |
print $actionbutton;
|
| - |
|
191 |
|
| - |
|
192 |
return unless $leagueAdmin or inArray ($R->{$primary} ,[keys %{$org}]) or $ORCUSER->{SYSADMIN};
|
| - |
|
193 |
|
| - |
|
194 |
my @role_section = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(Role Count) ) ]));
|
| - |
|
195 |
my @roles = @{ $dbh->selectall_arrayref ("select role, count(role) from role where member_org_id = ? group by role order by role", undef, $R->{$primary}) };
|
| - |
|
196 |
my ($total_members) = $dbh->selectrow_array ("select count(distinct person_id) from role where member_org_id = ?", undef, $R->{$primary});
|
| - |
|
197 |
foreach (@roles) {
|
| - |
|
198 |
my %role;
|
| - |
|
199 |
@role{qw/role count/} = @{$_};
|
| - |
|
200 |
|
| - |
|
201 |
push @role_section, $h->div ({ class=>"rTableRow shaded", onClick=>"window.location.href='people?excel=0&autoload=1&id=true&name_first=true&name_last=true&derby_name=true&league_id=true&role=true&created=true&updated=true&filter-id=&filter-name_first=&filter-name_last=&filter-derby_name=&filter-league_id=".$R->{$primary}."&filter-role=".$role{role}."&filter-created=&filter-updated=&sortby=id&limit=25&page=1'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;" }, $role{role}, $role{count}) ]);
|
| - |
|
202 |
}
|
| 186 |
print $actionbutton;
|
203 |
push @role_section, $h->div ({ class=>"rTableRow shaded", onClick=>"window.location.href='people?excel=0&autoload=1&id=true&name_first=true&name_last=true&derby_name=true&league_id=true&role=true&created=true&updated=true&filter-id=&filter-name_first=&filter-name_last=&filter-derby_name=&filter-league_id=".$R->{$primary}."&filter-role=&filter-created=&filter-updated=&sortby=id&limit=25&page=1'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;font-weight: bold;" }, "Total Members", $total_members) ]);
|
| 187 |
|
204 |
|
| Line 188... |
Line 205... |
| 188 |
my @policyhistory = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(ID Policy Start End) ) ]));
|
205 |
my @policyhistory = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(ID Policy Start End) ) ]));
|
| 189 |
my @policy_columns = qw(id organization_id policy_name fee created start end active);
|
206 |
my @policy_columns = qw(id organization_id policy_name fee created start end active);
|
| Line 205... |
Line 222... |
| 205 |
((!$active_policy or remainingOrgPolicyDays ($R->{$primary}, $active_policy) <= 90) ? $h->button (($active_policy ? "Renew" : "Purchase")." General Liability") : ""),
|
222 |
((!$active_policy or remainingOrgPolicyDays ($R->{$primary}, $active_policy) <= 90) ? $h->button (($active_policy ? "Renew" : "Purchase")." General Liability") : ""),
|
| 206 |
((!$active_alcohol_policy or remainingOrgPolicyDays ($R->{$primary}, $active_alcohol_policy) <= 90) ? $h->button (($active_alcohol_policy ? "Renew" : "Purchase")." Alcohol Liability") : "")
|
223 |
((!$active_alcohol_policy or remainingOrgPolicyDays ($R->{$primary}, $active_alcohol_policy) <= 90) ? $h->button (($active_alcohol_policy ? "Renew" : "Purchase")." Alcohol Liability") : "")
|
| 207 |
]);
|
224 |
]);
|
| 208 |
}
|
225 |
}
|
| Line -... |
Line 226... |
| - |
|
226 |
|
| - |
|
227 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "League Role Counts:"), $h->ul ([ @role_section ])]);
|
| 209 |
|
228 |
|
| Line 210... |
Line 229... |
| 210 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "League Insurance Policy History:"), $h->ul ([ @policyhistory ])]);
|
229 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "League Insurance Policy History:"), $h->ul ([ @policyhistory ])]);
|
| Line 211... |
Line 230... |
| 211 |
|
230 |
|
| 212 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Recent Activity:"), getOrgLog ($R->{$primary})]) unless $R->{$primary} !~ /^\d+$/;
|
231 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Recent Activity:"), getOrgLog ($R->{$primary})]) unless $R->{$primary} !~ /^\d+$/;
|
| Line 213... |
Line 232... |
| 213 |
|
232 |
|
| 214 |
print $h->close ("form");
|
233 |
print $h->close ("form");
|
| Line 215... |
Line 234... |
| 215 |
}
|
234 |
}
|
| 216 |
|
235 |
|
| 217 |
sub process_form {
|
236 |
sub process_form {
|
| 218 |
error ("ERROR: Only SysAdmins can change leagues.") unless $ORCUSER->{SYSADMIN};
|
237 |
error ("ERROR: Only SysAdmins or League Admins can change leagues.") unless $ORCUSER->{SYSADMIN} or $leagueAdmin;
|
| Line 226... |
Line 245... |
| 226 |
}
|
245 |
}
|
| 227 |
}
|
246 |
}
|
| Line 228... |
Line 247... |
| 228 |
|
247 |
|
| 229 |
# check for required fields
|
248 |
# check for required fields
|
| 230 |
my @errors = ();
|
249 |
my @errors = ();
|
| 231 |
foreach (@requiredFields) {
|
250 |
foreach (grep {notInArray ($_, \@SAFields) unless $ORCUSER->{SYSADMIN} } @requiredFields) {
|
| 232 |
push @errors, "$fieldDisplayName{$_} is missing." if $FORM{$_} eq "" and $FIELDS{$_}->[3] ne "static";
|
251 |
push @errors, "$fieldDisplayName{$_} is missing." if $FORM{$_} eq "" and $FIELDS{$_}->[3] ne "static";
|
| Line 233... |
Line 252... |
| 233 |
}
|
252 |
}
|
| 234 |
|
253 |
|
| Line 248... |
Line 267... |
| 248 |
|
267 |
|
| 249 |
display_form ({ $primary=>$FORM{$primary} }, "POSTSAVE");
|
268 |
display_form ({ $primary=>$FORM{$primary} }, "POSTSAVE");
|
| Line 250... |
Line 269... |
| 250 |
}
|
269 |
}
|
| 251 |
|
270 |
|
| Line 252... |
Line 271... |
| 252 |
sub saveForm {
|
271 |
sub saveForm {
|
| Line 253... |
Line 272... |
| 253 |
error ("ERROR: Only SysAdmins can change league details.") unless $ORCUSER->{SYSADMIN};
|
272 |
error ("ERROR: Only SysAdmins or League Admins can change league details.") unless $ORCUSER->{SYSADMIN} or $leagueAdmin;
|
| 254 |
|
273 |
|
| Line 271... |
Line 290... |
| 271 |
|
290 |
|
| 272 |
error ("ERROR: Attempting to edit existing league, but league ID not found [$FTS->{$primary}]!") unless $OG->{$primary} =~ /^\d+$/;
|
291 |
error ("ERROR: Attempting to edit existing league, but league ID not found [$FTS->{$primary}]!") unless $OG->{$primary} =~ /^\d+$/;
|
| Line 273... |
Line 292... |
| 273 |
my $league_name = getLeagueName ($FTS->{$primary});
|
292 |
my $league_name = getLeagueName ($FTS->{$primary});
|
| - |
|
293 |
|
| 274 |
|
294 |
foreach my $field (grep { notInArray ($_, \@ROFields) } keys %{$FTS}) {
|
| 275 |
foreach my $field (grep { notInArray ($_, \@ROFields) } keys %{$FTS}) {
|
295 |
if (notInArray ($field, \@SAFields) or $ORCUSER->{SYSADMIN}) {
|
| 276 |
if ($FTS->{$field} ne $OG->{$field}) {
|
296 |
if ($FTS->{$field} ne $OG->{$field}) {
|
| 277 |
$dbh->do ("update $DBTable set $field = ?, updated = now() where $primary = ?", undef, $FTS->{$field}, $FTS->{$primary});
|
297 |
$dbh->do ("update $DBTable set $field = ?, updated = now() where $primary = ?", undef, $FTS->{$field}, $FTS->{$primary});
|
| - |
|
298 |
logit ($ORCUSER->{person_id}, "Updated league $league_name [$FTS->{$primary}]: $field -> $FTS->{$field}");
|
| 278 |
logit ($ORCUSER->{person_id}, "Updated league $league_name [$FTS->{$primary}]: $field -> $FTS->{$field}");
|
299 |
orglogit ($ORCUSER->{person_id}, $FTS->{$primary}, "Updated league: $field -> $FTS->{$field}");
|
| 279 |
orglogit ($ORCUSER->{person_id}, $FTS->{$primary}, "Updated league: $field -> $FTS->{$field}");
|
300 |
}
|
| Line 280... |
Line 301... |
| 280 |
}
|
301 |
}
|