Subversion Repositories PEEPS

Rev

Rev 29 | 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 ();

my $cookie_string = authenticate (1) || die;
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $user = $ORCUSER;
#my $activated = $ORCUSER->{access};

my %FIELDS = (
  id          => 5,
  policy_name => 10,
  fee         => 15,
  organization_id   => 20,
  created     => 25,
  start       => 30,
  end         => 35,
  active      => 40,
  terminated  => 45,
  policy_id   => 50,
  square_id   => 55
);
sub byfield { $FIELDS{$a} <=> $FIELDS{$b}; }


#foreach (sort keys %ENV) {
#       warn "$_: $ENV{$_}";
#}

use DateTime;
my $dt = DateTime->today;
$dt =~ s/T00\:00\:00$//;

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");
my $leagueid = WebDB::trim scalar param ("leagueid") // ERROR ("Missing PolicyID", "Can't view a policy without an ID to look for.", "No PolicyID provided to View Policy");

my $coverage = getOrgCoverageByID ($coverage_id, $leagueid) // ERROR ("PolicyID Not Found", "Can't find a policy (for this league) with that ID.", "PolicyID provided to View Policy not found");

$coverage->{active} = $coverage->{active} ? "True" : "False";
$coverage->{terminated} = $coverage->{terminated} ? "True" : "False";
$coverage->{created} .= " UTC";

print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
printRCHeader("View Policy: ".$coverage_id);


print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Policy Details:"),
        $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [
          $h->div ({ class=>"rTableRow" }, map { [$h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, ucfirst ($_).": ", $coverage->{$_})] } sort byfield grep { exists $FIELDS{$_} } keys %{$coverage})]),
          $h->p ($h->input ({ type=>"button", onClick=>"window.location.href='$ENV{HTTP_REFERER}'", value=>"Back"}))]);

print $h->close ("body"), $h->close ("html");








sub ERROR {
  my $header = shift // "Unknown Error";
  my $text   = shift // "Something unexpectedly bad happened.";
  my $logmsg = shift // "Unknown Error happened while viewing the Attestation page";
  
  print header (-cookie=>CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string"));
  printRCHeader("Atttestation");
  print $h->close ("table");
  print $h->h2 ($header);
  print $h->div ({ style=>"max-width:450px;" }, $text, "&nbsp;");
  print $h->button ({onclick => "window.location.href='/';"}, "Home");
  print $h->close ("BODY", "HTML");
  logit ($user->{id}, $logmsg);
  exit; 
}