Rev 3 | Rev 5 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed
#!/usr/bin/perl# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)#my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";#close STDERR;#open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";#warn "Redirecting errors to ${error_log_path}vorc_error.log";use strict;use PEEPS;use CGI qw/param header start_html url/;use CGI::Cookie;our $h = HTML::Tiny->new( mode => 'html' );my $dbh = getRCDBH ();$ENV{HTTPS} = 'ON' if $ENV{SERVER_NAME} =~ /^peeps/;use DateTime;my $dt = DateTime->today;$dt =~ s/T00\:00\:00$//;my $cookie_string = authenticate (1) || die;my ($EML, $PWD, $LVL) = split /&/, $cookie_string;my $user = $ORCUSER;#my $activated = $ORCUSER->{access};my %LOOKUP = (# colname => [qw(DisplayName N type status)], status -> static | default | <blank>person_id => [qw(MemberID 5 number id )],policy_id => [qw(PolicyID 10 number policy_id )],first_name => [qw(FirstName 15 text name_first )],last_name => [qw(LastName 20 text name_last )],skater_name => [qw(SkaterName 25 text derby_name )],);my %NAME = map { $_ => $LOOKUP{$_}->[0] } keys %LOOKUP;my %colOrderHash = map { $_ => $LOOKUP{$_}->[1] } keys %LOOKUP;sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b}; }my %colFilterTypeHash = map { $_ => $LOOKUP{$_}->[2] } keys %LOOKUP;my %field_name = map { $_ => $LOOKUP{$_}->[3] } keys %LOOKUP;print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));printRCHeader("Insurance Verification");# 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}) ]);my ($EARCH, @ERRORS, $count);foreach (keys %LOOKUP) {$EARCH->{$_} = WebDB::trim scalar param $_;if ($colFilterTypeHash{$_} eq "number" and $EARCH->{$_} !~ /^\d*$/) {push @ERRORS, "$NAME{$_} should be a number (and you entered '$EARCH->{$_}').";$EARCH->{$_} = "";}if ($colFilterTypeHash{$_} eq "text" and $EARCH->{$_} !~ qr/^[\p{L}\p{M}\p{P}\s\'-]*$/u) {push @ERRORS, "$NAME{$_} should be text (and you entered '$EARCH->{$_}').";$EARCH->{$_} = "";}$count++ unless !$EARCH->{$_};}push @ERRORS, "At least two fields must be included to search (you entered $count)." unless $count != 1;print $h->form ( { name => "insuranceVerification", method => "post", action => url }, [$h->div ({class=>"hint"}, "At least two fields are required. If more than two are entered, they will all need to match."),scalar @ERRORS ? $h->div ({class=>"error"}, @ERRORS) : [],$h->div ({ class => "rTableRow" },map { $h->div ({class=>"rTableCellr"}, $NAME{$_}).$h->div ({class=>"rTableCellr"}, $h->input ({name => "$_", value => $EARCH->{$_}})) } sort byfield keys %LOOKUP),# "Member ID: ", $h->input ({name => "person_id"}), $h->br,# "Policy ID: ", $h->input ({name => "policy_id"}), $h->br,# "First Name: ", $h->input ({name => "first_name"}), $h->br,# "Last Name: ", $h->input ({name => "last_name"}), $h->br,# "Skater Name: ", $h->input ({name => "skater_name"}), $h->br,$h->button ("Verify Insurance")#, $h->button ("Reset")]);if ($count and !scalar @ERRORS) {my $where = join " and ", map { "$field_name{$_} = ?" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP;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);if ($policy_id) {$first =~ s/(.).+(..)/$1 . '*' x (length($&)-3) . $2/e;$last =~ s/(.).+(..)/$1 . '*' x (length($&)-3) . $2/e;my $policy = getCoverageByID ($policy_id, $person_id);print $h->div ({class => "rTableRow"}, "Results:", [$h->div ({class=>"rTableCell"}, "$first $last", $derby_name." [".$league."]", "Insured Through: $policy->{end}")]);# logit ($user->{id}, "Successfull Insurance Lookup: $derby_name [$league] Through: $policy->{end}");logit ($user->{id}, "Successfull Insurance Lookup: ".join (": ", map { "$field_name{$_} = $EARCH->{$_}" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP));} else {print $h->div ({class => "rTableRow"}, "No Matching Results Found.");logit ($user->{id}, "Failed Insurance Lookup: ".join (": ", map { "$field_name{$_} = $EARCH->{$_}" } grep { $EARCH->{$_} } sort byfield keys %LOOKUP));}}print $h->close ("body", "html");exit;#foreach (sort keys %ENV) {# print "$_: $ENV{$_}\n<br>";#}my @announcements;my @everyone;push @everyone, $h->li ($h->a ( { href=>"people" }, "Look at a list of people." ));push @everyone, $h->li ($h->a ( { href=>"organizations" }, "...or a list of leagues." ));my @leads;my @insurance;$user->{policy} = isPersonCovered ($user->{id});if ($user->{policy}) {my $daysremaining = remainingPolicyDays ($user->{id}, $user->{policy});push @insurance, $h->li ("You are currently covered by Policy ID: $user->{policy}");push @insurance, $h->li ("You have $daysremaining days remaining in coverage.");if ($daysremaining <= 90) {push @insurance, $h->li ($h->a ( { href=>"attestation" }, "You're eligible to renew." ));}} else {push @insurance, $h->li ($h->a ( { href=>"attestation" }, "Purchase Insurance." ));}push @insurance, $h->li ($h->a ( { href=>"insurance" }, "View Insurance History." ));my @managers;my @sysadmins;my @activity_log;my $alog = $dbh->prepare("select timestamp, event from log where person_id = ? order by timestamp desc limit 10");$alog->execute($user->{person_id});while (my @logs = $alog->fetchrow_array) {my ($d, $t) = split /\s+/, $logs[0];push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);}my @reference;printRCHeader("Home");print $h->close ("table");print $h->form ({ name => "Req", action => url });print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Announcement:"), $h->ul ([ @announcements ]) ]) if (scalar @announcements);#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;print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do:"), $h->ul ([ @everyone ]) ]);print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Personal Insurance:"), $h->ul ([ @insurance ]) ]);print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Lead:"), $h->ul ([ @leads ]) ]) if ($LVL > 1);print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Manager:"), $h->ul ([ @managers ]) ]) if ($LVL > 2);print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a SysAdmin:"), $h->ul ([ @sysadmins ]) ]) if ($LVL >= 5);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×tamp=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]")) ]);print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Reference:"), $h->ul ([ @reference ]) ]);print $h->close ("body"), $h->close ("html");