Subversion Repositories PEEPS

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 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
use DateTime;
17
my $dt = DateTime->today;
18
$dt =~ s/T00\:00\:00$//;
19
 
20
my $cookie_string = authenticate (1) || die;
21
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
22
my $user = $ORCUSER;
23
#my $activated = $ORCUSER->{access};
24
 
25
 
26
my %LOOKUP = (
27
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
28
  person_id    => [qw(MemberID      5    number  id         )],
29
  policy_id    => [qw(PolicyID     10    number  policy_id  )],
30
  first_name   => [qw(FirstName    15    text    name_first )],
31
  last_name    => [qw(LastName     20    text    name_last  )],
32
  skater_name  => [qw(SkaterName   25    text    derby_name )],
33
);
34
 
35
my %NAME              = map  { $_ => $LOOKUP{$_}->[0] } keys %LOOKUP;
36
my %colOrderHash      = map  { $_ => $LOOKUP{$_}->[1] } keys %LOOKUP;
37
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b}; }
38
my %colFilterTypeHash = map  { $_ => $LOOKUP{$_}->[2] } keys %LOOKUP;
39
my %field_name =        map  { $_ => $LOOKUP{$_}->[3] } keys %LOOKUP;
40
 
41
 
42
print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
43
printRCHeader("Insurance Verification");
44
 
45
 
46
#  push @policyhistory, $h->div ({ class=>"rTableRow ".($policy{id} == $active_policy ? "highlighted" : "shaded"), onClick=>"window.location.href='view_policy?id=$policy{id}'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;" }, $policy{id}, $policy{policy_name}, $policy{start}, $policy{end}) ]);
47
 
48
 
49
my ($EARCH, @ERRORS, $count);
50
foreach (keys %LOOKUP) {
51
  $EARCH->{$_} = WebDB::trim scalar param $_;
52
  if ($colFilterTypeHash{$_} eq "number" and $EARCH->{$_} !~ /^\d*$/) {
53
    push @ERRORS, "$NAME{$_} should be a number (and you entered '$EARCH->{$_}').";
54
    $EARCH->{$_} = "";
55
  }
56
  if ($colFilterTypeHash{$_} eq "text" and $EARCH->{$_} !~ qr/^[\p{L}\p{M}\p{P}\s\'-]*$/u) {
57
    push @ERRORS, "$NAME{$_} should be text (and you entered '$EARCH->{$_}').";
58
    $EARCH->{$_} = "";
59
  }
60
  $count++ unless !$EARCH->{$_};
61
}
62
push @ERRORS, "At least two fields must be included to search (you entered $count)." unless $count != 1;
63
 
64
 
65
print $h->form ( { name => "insuranceVerification", method => "post", action => url }, [
66
  $h->div ({class=>"hint"}, "At least two fields are required. If more than two are entered, they will all need to match."),
67
  scalar @ERRORS ? $h->div ({class=>"error"}, @ERRORS) : [],
68
  $h->div ({ class => "rTableRow" },
69
    map {  $h->div ({class=>"rTableCellr"}, $NAME{$_}).$h->div ({class=>"rTableCellr"}, $h->input ({name => "$_", value => $EARCH->{$_}})) } sort byfield keys %LOOKUP),
70
 
71
#  "Member ID: ", $h->input ({name => "person_id"}), $h->br,
72
#  "Policy ID: ", $h->input ({name => "policy_id"}), $h->br,
73
#  "First Name: ", $h->input ({name => "first_name"}), $h->br,
74
#  "Last Name: ", $h->input ({name => "last_name"}), $h->br,
75
#  "Skater Name: ", $h->input ({name => "skater_name"}), $h->br,
76
  $h->button ("Verify Insurance")#, $h->button ("Reset")
77
]);
78
 
79
if ($count and !scalar @ERRORS) {
80
 
81
  my $where = join " and ", map { "$field_name{$_} = ?" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP;
82
  my ($person_id, $first, $last, $derby_name, $policy_id, $league) = $dbh->selectrow_array ("select id, name_first, name_last, derby_name, policy_id, group_concat(distinct league_name SEPARATOR ', ') from v_person where ".$where, undef, map { $EARCH->{$_} } grep { $EARCH->{$_} } sort byfield keys %LOOKUP);
83
  if ($policy_id) {
84
    $first =~ s/(.).+(..)/$1 . '*' x (length($&)-3) . $2/e;
85
    $last  =~ s/(.).+(..)/$1 . '*' x (length($&)-3) . $2/e;
86
    my $policy = getCoverageByID ($policy_id, $person_id);
87
    print $h->div ({class => "rTableRow"}, "Results:", [$h->div ({class=>"rTableCell"}, "$first $last", $derby_name." [".$league."]", "Insured Through: $policy->{end}")]);
88
#    logit ($user->{id}, "Successfull Insurance Lookup: $derby_name [$league] Through: $policy->{end}");
89
    logit ($user->{id}, "Successfull Insurance Lookup: ".join (": ", map { "$field_name{$_} = $EARCH->{$_}" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP));
90
  } else {
91
    print $h->div ({class => "rTableRow"}, "No Matching Results Found.");
92
    logit ($user->{id}, "Failed Insurance Lookup: ".join (": ", map { "$field_name{$_} = $EARCH->{$_}" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP));
93
  }
94
 
95
 
96
}
97
 
98
 
99
 
100
 
101
print $h->close ("body", "html");
102
exit;
103
 
104
#foreach (sort keys %ENV) {
105
#	print "$_: $ENV{$_}\n<br>";
106
#}
107
 
108
 
109
my @announcements;
110
 
111
my @everyone;
112
push @everyone, $h->li ($h->a ( { href=>"people" }, "Look at a list of people." ));
113
push @everyone, $h->li ($h->a ( { href=>"organizations" }, "...or a list of leagues." ));
114
my @leads;
115
 
116
my @insurance;
117
$user->{policy} = isPersonCovered ($user->{id});
118
if ($user->{policy}) {
119
  my $daysremaining = remainingPolicyDays ($user->{id}, $user->{policy});
120
  push @insurance, $h->li ("You are currently covered by Policy ID: $user->{policy}");
121
  push @insurance, $h->li ("You have $daysremaining days remaining in coverage.");
122
  if ($daysremaining <= 90) {
123
    push @insurance, $h->li ($h->a ( { href=>"attestation" }, "You're eligible to renew." ));
124
  }
125
 
126
} else {
127
  push @insurance, $h->li ($h->a ( { href=>"attestation" }, "Purchase Insurance." ));
128
}
129
push @insurance, $h->li ($h->a ( { href=>"insurance" }, "View Insurance History." ));
130
 
131
 
132
my @managers;
133
 
134
my @sysadmins;
135
 
136
my @activity_log;
137
my $alog = $dbh->prepare("select timestamp, event from log where person_id = ? order by timestamp desc limit 10");
138
$alog->execute($user->{person_id});
139
while (my @logs = $alog->fetchrow_array) {
140
	my ($d, $t) = split /\s+/, $logs[0];
141
	push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);
142
}
143
 
144
my @reference;
145
 
146
printRCHeader("Home");
147
print $h->close ("table");
148
 
149
print $h->form ({ name => "Req", action => url });
150
 
151
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Announcement:"), $h->ul ([ @announcements ]) ]) if (scalar @announcements);
152
 
153
#print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Note:"), "<b>Your account is being reviewed.</b>", $h->br, "You won't have access to view or sign-up for things until you've been approved / added to a department.", $h->br, "Please watch your email for notifications." ]) unless $activated;
154
 
155
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do:"), $h->ul ([ @everyone ]) ]);
156
 
157
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Personal Insurance:"), $h->ul ([ @insurance ]) ]);
158
 
159
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Lead:"), $h->ul ([ @leads ]) ]) if ($LVL > 1);
160
 
161
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Manager:"), $h->ul ([ @managers ]) ]) if ($LVL > 2);
162
 
163
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a SysAdmin:"), $h->ul ([ @sysadmins ]) ]) if ($LVL >= 5);
164
 
165
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Your Latest Activity:"), $h->ul ([ @activity_log ]), $h->h5 ($h->a ({ href=>"log?excel=0&autoload=1&eventid=true&timestamp=true&event=true&RCid=true&derby_name=true&filter-timestamp=&filter-event=&filter-RCid=".$user->{RCid}."&filter-derby_name=&sortby=eventid&limit=25&page=1" }, "[Your entire log history]")) ]);
166
 
167
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Reference:"), $h->ul ([ @reference ]) ]);
168
 
169
print $h->close ("body"), $h->close ("html");
170
 
171