Subversion Repositories PEEPS

Rev

Rev 6 | 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");