Subversion Repositories ORC

Rev

Rev 45 | 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;
use HTML::Tiny;
our $h = HTML::Tiny->new( mode => 'html' );

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

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;
#  noForm ($date);
}
my $day = $dt->day_name;

my $dept = param ("dept") // noForm ($date);


my %class = qw(
        U Unrestricted
        M Mens
        W Womens
        SS Single-Gender
);
my %dbfields = qw(
        type                            5
        role                            10
        location                15
        time                            20
        derby_name      25
);



my $dbh = WebDB::connect ();

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


print<<output;
<html><head><title>RollerCon VORC - $DEPTS->{$dept} Schedule - $day ($date)</title>
<link rel="stylesheet" type="text/css" href="/style.css">
</head>
<body>
output

print $h->div ({class=>"bold"}, "$DEPTS->{$dept} - $day ($date)"), $h->br;

my $query = $dbh->prepare ("select type, role, location, time, derby_name from v_shift where dept = ? and date = ? order by start_time, field(type, 'manager', 'lead', 'selected', 'open'), location, end_time");
$query->execute ($dept, $date);

my @constants = ("&nbsp;", "&nbsp;", "&nbsp;");
print $h->open ('div', { class=>'rTable' });

print $h->div ({ class=>"rTableRow" }, [$h->div ({ class=>"rTableCell bold" }, map { ucfirst $_ } sort { $dbfields{$a} <=> $dbfields{$b} } keys %dbfields), $h->div ({ class=>"rTableCell bold" }, "Time In", "Time Out", "Add to VORC")]);
while (my $shift = $query->fetchrow_hashref) {
        print $h->div ({ class=>"rTableRow" }, [$h->div ({ class=>"rTableCell", style=>"border: 1px dotted black;" }, map { $shift->{$_} } sort { $dbfields{$a} <=> $dbfields{$b} } keys %{$shift} ), $h->div ({ class=>"rTableCell", style=>"border: 1px dotted black;" }, @constants )]);
}

print $h->close ('div', { class=>'rTable' });

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

exit;


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



sub noForm {
        my $tempdate = shift;
        
        print header (-cookie=> [ $RCAUTH_cookie ] );
        print "Please pick a department and date to print:";
        print $h->form ({ action=> url }, [
                $h->select ({ name => "dept" }, [ $h->option (), map { $h->option ({ value => "$_" }, $DEPTS->{$_}) } ($LVL >= 5 or $user->{department}->{VCI} >= 2) ? sort keys %{$DEPTS} : sort keys %{$user->{department}} ]), $h->br,
                $h->input ({
            name => "date",
            type => "date",
            value => $tempdate,
            required => [],
            override => 1,
            size => 30
          }), $h->br,
        $h->input ({ type => "submit" })
        ]);
        
        exit;
}