Subversion Repositories ORC

Rev

Rev 38 | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

use strict;
use cPanelUserConfig;
use RollerCon;
use WebDB;
use tableViewer;
use CGI;
use CGI::Cookie;
use DateTime;

my $cookie_string = authenticate(2) || die;
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $user = getUser($EML);
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");

my $date = param ("date");
my $dt;
if ($date =~ /^\d{4}-\d{2}-\d{2}$/) {
  my ($YYYY, $MM, $DD) = split /-/, $date;
  $dt = DateTime->new(
    year  => $YYYY,
    month => $MM,
    day   => $DD
  );
} else {
  $dt = DateTime->today;
  $date = $dt->date;
}
my $day = $dt->day_name;

my %class = qw(
        U Unrestricted
        M Mens
        W Womens
        SS Single-Gender
);

my $dbh = WebDB::connect ();

print CGI::header(-cookie=>$RCAUTH_cookie);




print<<output;
<html><head><title>RollerCon VORC - Daily Officiating Schedule - $day ($date)</title>
<link rel="stylesheet" type="text/css" href="/rollercon.css">
</head>
<body text="#000000" bgcolor="#FFFFFF" link="#0000EE" vlink="#551A8B" alink="#FF0000">
output

my $gcount = 1; my $tcount = '';
my $sth = $dbh->prepare("select distinct teams, track, level, time, gtype, restrictions from v_shift_officiating where date = ? order by track, time");
my $crewhan = $dbh->prepare("select role, derby_name from v_shift_officiating where date = ? and track = ? and time = ?");
my $leadhan = $dbh->prepare("select location, time, derby_name from v_shift where dept = 'OFF' and date = ? order by location, time");
my $openshifthan = $dbh->prepare("select time, level, restrictions, gtype, teams, tla, name from v_shift_officiating where tla <> 'ALT' and isNull(derby_name) = 1 and date = ? and track = ? order by time");

my @leads = ("<table>\n", "<tr><td colspan=5><b>Lead Shifts</b></td></tr>\n");
$leadhan->execute($date);
my $tc = 'C1';
while (my $lshift = $leadhan->fetchrow_hashref()) {
        if ($tc ne $lshift->{location}) {
                push @leads, "<tr><td colspan=5>&nbsp;</td></tr>\n";
                $tc = $lshift->{location};
        }
        push @leads, "<tr><td>$lshift->{location}</td><td>&nbsp;</td><td>$lshift->{time}</td><td>&nbsp;</td><td>$lshift->{derby_name}</td></tr>\n";
}
push @leads, "</table>\n";

$sth->execute($date);
while (my $g = $sth->fetchrow_hashref()) {
        if ($tcount ne $g->{track}) { #pagebreak whenever we change tracks
                print "<div class='pagebreak'><hr></div>\n" unless !$tcount;
                print @leads;
                
                my @openshifts = ("<table>\n", "<tr><td colspan=5><b>Open Shifts on $g->{track}</b></td></tr>\n");
                $openshifthan->execute($date, $g->{track});
                while (my @oshift = $openshifthan->fetchrow_array()) {
                        my $sh = join "</td><td>&nbsp;</td><td>", @oshift;
                        push @openshifts, "<tr><td>$sh</td></tr>\n";
                }
                push @openshifts, "</table>\n";
                print "<br><br><br><br>";
                print @openshifts;
                
                print "<div class='pagebreak'><hr></div>\n";
                $gcount = 1;
                $tcount = $g->{track};
        }
        
        $g->{gtype} = join '', map { ucfirst lc } split /(\s+)/, $g->{gtype}; # Capitalize the game time to look nicer

        my %crew;
        $crewhan->execute($date, $g->{track}, $g->{time});
        while (my ($k, $v) = $crewhan->fetchrow_array()) {
                $crew{$k} = $v;
        }
        my $P1 = "PLT-1";
        my $P2 = "PLT-2";
        my $PH = "PLT";
        my $OPR1 = "OPR-1";
        if ($g->{gtype} eq "Full Length" or $g->{gtype} eq "Selected Staffing") {
                $P1 = 'PLT/H';
                $P2 = 'PLT';
                $PH = $P1;
        } elsif ($g->{gtype} eq "Challenge-rs1") {
                $crew{'OPR-1'} = "<i>-not staffed-</i>";
                $crew{'OPR-2'} = "<i>-not staffed-</i>";
                $crew{'OPR-3'} = "<i>-not staffed-</i>";
                $crew{'PLT-1'} = "<i>-not staffed-</i>";
                $crew{'PLT-2'} = "<i>-not staffed-</i>";
                $crew{'SK-1'} = "<i>-not staffed-</i>";
                $crew{'SK-2'} = "<i>-not staffed-</i>";
                $crew{'PBM'} = "<i>-not staffed-</i>";
        } elsif ($g->{gtype} eq "Challenge-rs2") {
                $OPR1 = "OPR";

                $crew{'IPR'} = "<i>-not staffed-</i>";
                $crew{'OPR-2'} = "<i>-not staffed-</i>";
                $crew{'OPR-3'} = "<i>-not staffed-</i>";
                $crew{'PLT-1'} = "<i>-not staffed-</i>";
                $crew{'PLT-2'} = "<i>-not staffed-</i>";
                $crew{'SK-1'} = "<i>-not staffed-</i>";
                $crew{'SK-2'} = "<i>-not staffed-</i>";
                $crew{'PBM'} = "<i>-not staffed-</i>";
        } elsif ($g->{gtype} eq "Scrimmage") {
                $crew{'PLT-1'} = "<i>-not staffed-</i>";
                $crew{'PLT-2'} = "<i>-not staffed-</i>";
                $crew{'SK-1'} = "<i>-not staffed-</i>";
                $crew{'SK-2'} = "<i>-not staffed-</i>";
                $crew{'PBM'} = "<i>-not staffed-</i>";
                $crew{'PBT-1'} = "<i>-not staffed-</i>";
                $crew{'PBT-2'} = "<i>-not staffed-</i>";
                $crew{'SO'} = "<i>-not staffed-</i>";
        }
                
        my $A = '';
        if (defined $crew{'ALT'}) {
                $A = "ALT:";
        } else {
                $crew{'ALT'} = '';
        }
        
        print<<game;
<table>
        <tr><td>Date:</td><td>$day ($date)</td><td>&nbsp;</td><td>Track:</td><td>$g->{track}</td></tr>
        <tr><td>Time:</td><td>$g->{time}</td><td>&nbsp;</td><td>Class:</td><td>$class{$g->{restrictions}} $g->{level} $g->{gtype}</td></tr>
        <tr><td>Game:</td><td colspan=4>$g->{teams}</td></tr>
        <tr><td colspan=5>&nbsp;</td></tr>
        <tr><td>HR:</td><td>$crew{'HR'}</td><td>&nbsp;</td><td>$PH:</td><td>$crew{$P1}</td></tr>
        <tr><td>IPR:</td><td>$crew{'IPR'}</td><td>&nbsp;</td><td>PLT:</td><td>$crew{$P2}</td></tr>
        <tr><td>JR:</td><td>$crew{'JR-1'}</td><td>&nbsp;</td><td>SK:</td><td>$crew{'SK-1'}</td></tr>
        <tr><td>JR:</td><td>$crew{'JR-2'}</td><td>&nbsp;</td><td>SK:</td><td>$crew{'SK-2'}</td></tr>
        <tr><td>OPR:</td><td>$crew{$OPR1}</td><td>&nbsp;</td><td>PBM:</td><td>$crew{'PBM'}</td></tr>
        <tr><td>OPR:</td><td>$crew{'OPR-2'}</td><td>&nbsp;</td><td>PBT:</td><td>$crew{'PBT-1'}</td></tr>
        <tr><td>OPR:</td><td>$crew{'OPR-3'}</td><td>&nbsp;</td><td>PBT:</td><td>$crew{'PBT-2'}</td></tr>
        <tr><td>$A</td><td>$crew{'ALT'}</td><td>&nbsp;</td><td>JT:</td><td>$crew{'JT'}</td></tr>
        <tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>SO:</td><td>$crew{'SO'}</td></tr>
</table><br><br><br><br><br><br><br><br><br><br><br><br>
game

        $gcount++ % 2 == 0 ? print "<div class='pagebreak'><hr></div>\n" : { };
}



print<<tail;
</BODY>
</HTML>
tail