Subversion Repositories PEEPS

Rev

Rev 35 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 35 Rev 59
Line 42... Line 42...
42
my $dt = DateTime->today;
42
my $dt = DateTime->today;
43
$dt =~ s/T00\:00\:00$//;
43
$dt =~ s/T00\:00\:00$//;
Line 44... Line 44...
44
 
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");
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 $userid = WebDB::trim scalar param ("userid") // $user->{id};
-
 
47
my $terminate = WebDB::trim scalar param ("terminate") // undef;
Line 46... Line 48...
46
my $userid = WebDB::trim scalar param ("userid") // $user->{id};
48
my $reinstate = WebDB::trim scalar param ("reinstate") // undef;
Line -... Line 49...
-
 
49
 
-
 
50
my $coverage = getCoverageByID ($coverage_id, $userid) // ERROR ("PolicyID Not Found", "Can't find a policy (that belongs to this user) with that ID.", "PolicyID provided to View Policy not found");
-
 
51
 
-
 
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 $coverage->{person_id}") unless isPersonCovered ($coverage->{person_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 coverage set coverage.terminated = date(now()), active = null where id = ? and person_id = ?", undef, $coverage->{id}, $coverage->{person_id});
-
 
61
  logit ($user->{id}, "Terminated policy $coverage->{id} for person $coverage->{person_id}");
-
 
62
  logit ($coverage->{person_id}, "Policy $coverage->{id} was terminated by a System Admin");
-
 
63
  
-
 
64
  $coverage = getCoverageByID ($coverage_id, $userid);
-
 
65
}
-
 
66
 
-
 
67
if ($reinstate) {
-
 
68
  ERROR ("Unauthorized", "Only System Admins can reinstate a policy", "SECURITY: Attempt to reinstate policy $coverage->{id} for $coverage->{person_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 $coverage->{person_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 $coverage->{person_id}") unless $coverage->{still_valid};
-
 
77
  
-
 
78
  $dbh->do ("update coverage set coverage.terminated = null, active = 1 where id = ? and person_id = ?", undef, $coverage->{id}, $coverage->{person_id});
-
 
79
  logit ($user->{id}, "Reinstated policy $coverage->{id} for person $coverage->{person_id}");
-
 
80
  logit ($coverage->{person_id}, "Policy $coverage->{id} was reinstated by a System Admin");
-
 
81
  
-
 
82
  $coverage = getCoverageByID ($coverage_id, $userid);
-
 
83
}
-
 
84
 
-
 
85
if ($coverage->{terminated}) {
-
 
86
  use WebDB;
-
 
87
  my $dbh = WebDB::connect;
-
 
88
  
47
 
89
  ($coverage->{still_valid}) = $dbh->selectrow_array ("select if(datediff(?, date(now())) >= 0, 1, 0)", undef, $coverage->{end});
-
 
90
}
48
my $coverage = getCoverageByID ($coverage_id, $userid) // ERROR ("PolicyID Not Found", "Can't find a policy (that belongs to this user) with that ID.", "PolicyID provided to View Policy not found");
91
 
49
 
92
#$coverage->{active} = $coverage->{active} ? "True" : "False";
-
 
93
$coverage->{active} = isPersonCovered ($coverage->{person_id}) eq $coverage->{id} ? "True" : "False";
-
 
94
$coverage->{terminated} = "False" unless $coverage->{terminated};
-
 
95
$coverage->{created} .= " UTC";
-
 
96
$coverage->{terminated} .= ($user->{SYSADMIN} and isPersonCovered ($coverage->{person_id}) eq $coverage->{id}) ? "  ".$h->button ({onClick=>"if (confirm('Are you sure you want to terminate this policy?')) { window.location.href='view_policy?terminate=true&id=$coverage->{id}&userid=$coverage->{person_id}'; } else { return false; }"}, "Terminate") : "";
Line 50... Line 97...
50
$coverage->{active} = $coverage->{active} ? "True" : "False";
97
$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_policy?reinstate=true&id=$coverage->{id}&userid=$coverage->{person_id}'; } else { return false; }"}, "Reinstate") : "";
51
$coverage->{terminated} = $coverage->{terminated} ? "True" : "False";
98