Subversion Repositories PEEPS

Rev

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