| 29 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
|
|
|
4 |
#my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
|
|
|
5 |
#close STDERR;
|
|
|
6 |
#open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
|
|
|
7 |
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
|
|
|
8 |
|
|
|
9 |
use strict;
|
|
|
10 |
use PEEPS;
|
|
|
11 |
use CGI qw/param header start_html url/;
|
|
|
12 |
use CGI::Cookie;
|
|
|
13 |
our $h = HTML::Tiny->new( mode => 'html' );
|
|
|
14 |
my $dbh = getRCDBH ();
|
|
|
15 |
|
|
|
16 |
my $cookie_string = authenticate (1) || die;
|
|
|
17 |
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
18 |
my $user = $ORCUSER;
|
|
|
19 |
#my $activated = $ORCUSER->{access};
|
|
|
20 |
|
|
|
21 |
my %FIELDS = (
|
|
|
22 |
id => 5,
|
|
|
23 |
policy_name => 10,
|
|
|
24 |
fee => 15,
|
|
|
25 |
organization_id => 20,
|
|
|
26 |
created => 25,
|
|
|
27 |
start => 30,
|
|
|
28 |
end => 35,
|
|
|
29 |
active => 40,
|
|
|
30 |
terminated => 45,
|
|
|
31 |
policy_id => 50,
|
|
|
32 |
square_id => 55
|
|
|
33 |
);
|
|
|
34 |
sub byfield { $FIELDS{$a} <=> $FIELDS{$b}; }
|
|
|
35 |
|
|
|
36 |
|
|
|
37 |
#foreach (sort keys %ENV) {
|
|
|
38 |
# warn "$_: $ENV{$_}";
|
|
|
39 |
#}
|
|
|
40 |
|
|
|
41 |
use DateTime;
|
|
|
42 |
my $dt = DateTime->today;
|
|
|
43 |
$dt =~ s/T00\:00\:00$//;
|
|
|
44 |
|
|
|
45 |
my $coverage_id = WebDB::trim scalar param ("id") // ERROR ("Missing PolicyID", "Can't view a policy without an ID to look for.", "No PolicyID provided to View Policy");
|
|
|
46 |
my $leagueid = WebDB::trim scalar param ("leagueid") // ERROR ("Missing PolicyID", "Can't view a policy without an ID to look for.", "No PolicyID provided to View Policy");
|
| 59 |
- |
47 |
my $terminate = WebDB::trim scalar param ("terminate") // undef;
|
|
|
48 |
my $reinstate = WebDB::trim scalar param ("reinstate") // undef;
|
| 29 |
- |
49 |
|
|
|
50 |
my $coverage = getOrgCoverageByID ($coverage_id, $leagueid) // ERROR ("PolicyID Not Found", "Can't find a policy (for this league) with that ID.", "PolicyID provided to View Policy not found");
|
|
|
51 |
|
| 59 |
- |
52 |
if ($terminate) {
|
|
|
53 |
ERROR ("Unauthorized", "Only System Admins can terminate a policy", "SECURITY: Attempt to terminate policy $coverage->{id} for $coverage->{person_id}") unless $user->{SYSADMIN};
|
|
|
54 |
ERROR ("Invalid Policy", "You attempted to terminate a policy that isn't valid", "Attempted to terminate invalid policy $coverage->{id} for league $coverage->{organization_id}") unless isLeagueCovered ($coverage->{organization_id}) eq $coverage->{id};
|
|
|
55 |
|
|
|
56 |
# We've checked that they're a SysAdmin and that this is the current valid policy. Go ahead and terminate it.
|
|
|
57 |
use WebDB;
|
|
|
58 |
my $dbh = WebDB::connect;
|
|
|
59 |
|
|
|
60 |
$dbh->do ("update org_coverage set org_coverage.terminated = date(now()), active = null where id = ? and organization_id = ?", undef, $coverage->{id}, $coverage->{organization_id});
|
|
|
61 |
logit ($user->{id}, "Terminated policy $coverage->{id} for league $coverage->{organization_id}");
|
|
|
62 |
orglogit ($user->{id}, $coverage->{organization_id}, "Policy $coverage->{id} was terminated by a System Admin");
|
|
|
63 |
|
|
|
64 |
$coverage = getOrgCoverageByID ($coverage_id, $leagueid);
|
|
|
65 |
}
|
|
|
66 |
|
|
|
67 |
if ($reinstate) {
|
|
|
68 |
ERROR ("Unauthorized", "Only System Admins can reinstate a policy", "SECURITY: Attempt to reinstate policy $coverage->{id} for league $coverage->{organization_id}") unless $user->{SYSADMIN};
|
|
|
69 |
ERROR ("Invalid Policy", "You attempted to reinstate a policy that isn't valid", "Attempted to reinstate invalid policy $coverage->{id} for league $coverage->{organization_id}") unless $coverage->{terminated} =~ /^\d{4}-\d{2}-\d{2}$/;
|
|
|
70 |
|
|
|
71 |
# We've checked that they're a SysAdmin and that this is the current valid policy. Go ahead and terminate it.
|
|
|
72 |
use WebDB;
|
|
|
73 |
my $dbh = WebDB::connect;
|
|
|
74 |
|
|
|
75 |
($coverage->{still_valid}) = $dbh->selectrow_array ("select if(datediff(?, date(now())) >= 0, 1, 0)", undef, $coverage->{end});
|
|
|
76 |
ERROR ("Invalid Policy", "You attempted to reinstate a policy that ended before today", "Attempted to reinstate already ended policy $coverage->{id} for league $coverage->{organization_id}") unless $coverage->{still_valid};
|
|
|
77 |
|
|
|
78 |
$dbh->do ("update org_coverage set org_coverage.terminated = null, active = 1 where id = ? and organization_id = ?", undef, $coverage->{id}, $coverage->{organization_id});
|
|
|
79 |
logit ($user->{id}, "Reinstated policy $coverage->{id} for league $coverage->{organization_id}");
|
|
|
80 |
orglogit ($user->{id}, $coverage->{organization_id}, "Policy $coverage->{id} was reinstated by a System Admin");
|
|
|
81 |
|
|
|
82 |
$coverage = getOrgCoverageByID ($coverage_id, $leagueid);
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
if ($coverage->{terminated}) {
|
|
|
86 |
use WebDB;
|
|
|
87 |
my $dbh = WebDB::connect;
|
|
|
88 |
|
|
|
89 |
($coverage->{still_valid}) = $dbh->selectrow_array ("select if(datediff(?, date(now())) >= 0, 1, 0)", undef, $coverage->{end});
|
|
|
90 |
}
|
|
|
91 |
|
|
|
92 |
|
|
|
93 |
#$coverage->{active} = $coverage->{active} ? "True" : "False";
|
|
|
94 |
$coverage->{active} = isLeagueCovered ($coverage->{organization_id}) eq $coverage->{id} ? "True" : "False";
|
|
|
95 |
$coverage->{terminated} = "False" unless $coverage->{terminated};
|
| 29 |
- |
96 |
$coverage->{created} .= " UTC";
|
| 59 |
- |
97 |
$coverage->{terminated} .= ($user->{SYSADMIN} and isLeagueCovered ($coverage->{organization_id}) eq $coverage->{id}) ? " ".$h->button ({onClick=>"if (confirm('Are you sure you want to terminate this policy?')) { window.location.href='view_org_policy?terminate=true&id=$coverage->{id}&leagueid=$coverage->{organization_id}'; } else { return false; }"}, "Terminate") : "";
|
|
|
98 |
$coverage->{terminated} .= ($user->{SYSADMIN} and $coverage->{terminated} =~ /^\d{4}-\d{2}-\d{2}$/ and $coverage->{still_valid}) ? " ".$h->button ({onClick=>"if (confirm('Are you sure you want to reinstate this policy?')) { window.location.href='view_org_policy?reinstate=true&id=$coverage->{id}&leagueid=$coverage->{organization_id}'; } else { return false; }"}, "Reinstate") : "";
|
| 29 |
- |
99 |
|
| 59 |
- |
100 |
$coverage->{organization_id} = $coverage->{organization_id} ? $h->a ({ href=>"view_league?id=$coverage->{organization_id}" }, $coverage->{organization_id}." [".getLeagueName ($coverage->{organization_id})."]") : "";
|
|
|
101 |
|
| 29 |
- |
102 |
print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
|
|
|
103 |
printRCHeader("View Policy: ".$coverage_id);
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Policy Details:"),
|
|
|
107 |
$h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [
|
| 30 |
- |
108 |
$h->div ({ class=>"rTableRow" }, map { [$h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, ucfirst ($_).": ", $coverage->{$_})] } sort byfield grep { exists $FIELDS{$_} } keys %{$coverage})]),
|
|
|
109 |
$h->p ($h->input ({ type=>"button", onClick=>"window.location.href='$ENV{HTTP_REFERER}'", value=>"Back"}))]);
|
| 29 |
- |
110 |
|
|
|
111 |
print $h->close ("body"), $h->close ("html");
|
|
|
112 |
|
|
|
113 |
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
|
|
|
117 |
|
|
|
118 |
|
|
|
119 |
|
|
|
120 |
sub ERROR {
|
|
|
121 |
my $header = shift // "Unknown Error";
|
|
|
122 |
my $text = shift // "Something unexpectedly bad happened.";
|
|
|
123 |
my $logmsg = shift // "Unknown Error happened while viewing the Attestation page";
|
|
|
124 |
|
|
|
125 |
print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
|
|
|
126 |
printRCHeader("Atttestation");
|
|
|
127 |
print $h->close ("table");
|
|
|
128 |
print $h->h2 ($header);
|
|
|
129 |
print $h->div ({ style=>"max-width:450px;" }, $text, " ");
|
|
|
130 |
print $h->button ({onclick => "window.location.href='/';"}, "Home");
|
|
|
131 |
print $h->close ("BODY", "HTML");
|
|
|
132 |
logit ($user->{id}, $logmsg);
|
|
|
133 |
exit;
|
|
|
134 |
}
|
|
|
135 |
|