Subversion Repositories ORC

Rev

Rev 45 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
45 - 1
#!/usr/bin/perl
2
 
3
use strict;
4
use cPanelUserConfig;
5
use RollerCon;
6
use WebDB;
7
use tableViewer;
8
use CGI;
9
use CGI::Cookie;
10
use DateTime;
11
use HTML::Tiny;
12
our $h = HTML::Tiny->new( mode => 'html' );
13
 
14
my $cookie_string = authenticate(2) || die;
15
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
16
my $user = getUser($EML);
17
$user->{department} = convertDepartments ($user->{department});
18
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
19
my $DEPTS = getDepartments ();
20
 
21
my $date = param ("date");
22
my $dt;
23
if ($date =~ /^\d{4}-\d{2}-\d{2}$/) {
24
  my ($YYYY, $MM, $DD) = split /-/, $date;
25
  $dt = DateTime->new(
26
    year  => $YYYY,
27
    month => $MM,
28
    day   => $DD
29
  );
30
} else {
31
  $dt = DateTime->today;
32
  $date = $dt->date;
33
#  noForm ($date);
34
}
35
my $day = $dt->day_name;
36
 
37
my $dept = param ("dept") // noForm ($date);
38
 
39
 
40
my %class = qw(
41
	U Unrestricted
42
	M Mens
43
	W Womens
44
	SS Single-Gender
45
);
46
my %dbfields = qw(
47
	type				5
48
	role				10
49
	location		15
50
	time				20
51
	derby_name	25
52
);
53
 
54
 
55
 
56
my $dbh = WebDB::connect ();
57
 
58
print CGI::header(-cookie=>$RCAUTH_cookie);
59
 
60
 
61
print<<output;
62
<html><head><title>RollerCon VORC - $DEPTS->{$dept} Schedule - $day ($date)</title>
63
<link rel="stylesheet" type="text/css" href="/style.css">
64
</head>
65
<body>
66
output
67
 
68
print $h->div ({class=>"bold"}, "$DEPTS->{$dept} - $day ($date)"), $h->br;
69
 
46 - 70
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");
45 - 71
$query->execute ($dept, $date);
72
 
73
my @constants = ("&nbsp;", "&nbsp;", "&nbsp;");
74
print $h->open ('div', { class=>'rTable' });
75
 
76
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")]);
77
while (my $shift = $query->fetchrow_hashref) {
78
	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 )]);
79
}
80
 
81
print $h->close ('div', { class=>'rTable' });
82
 
83
print<<tail;
84
</BODY>
85
</HTML>
86
tail
87
 
88
exit;
89
 
90
 
91
my $gcount = 1; my $tcount = '';
92
my $sth = $dbh->prepare("select distinct teams, track, level, time, gtype, restrictions from v_shift_officiating where date = ? order by track, time");
93
my $crewhan = $dbh->prepare("select role, derby_name from v_shift_officiating where date = ? and track = ? and time = ?");
94
my $leadhan = $dbh->prepare("select location, time, derby_name from v_shift where dept = 'OFF' and date = ? order by location, time");
95
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");
96
 
97
my @leads = ("<table>\n", "<tr><td colspan=5><b>Lead Shifts</b></td></tr>\n");
98
$leadhan->execute($date);
99
my $tc = 'C1';
100
while (my $lshift = $leadhan->fetchrow_hashref()) {
101
	if ($tc ne $lshift->{location}) {
102
		push @leads, "<tr><td colspan=5>&nbsp;</td></tr>\n";
103
		$tc = $lshift->{location};
104
	}
105
	push @leads, "<tr><td>$lshift->{location}</td><td>&nbsp;</td><td>$lshift->{time}</td><td>&nbsp;</td><td>$lshift->{derby_name}</td></tr>\n";
106
}
107
push @leads, "</table>\n";
108
 
109
$sth->execute($date);
110
while (my $g = $sth->fetchrow_hashref()) {
111
	if ($tcount ne $g->{track}) { #pagebreak whenever we change tracks
112
		print "<div class='pagebreak'><hr></div>\n" unless !$tcount;
113
		print @leads;
114
 
115
		my @openshifts = ("<table>\n", "<tr><td colspan=5><b>Open Shifts on $g->{track}</b></td></tr>\n");
116
		$openshifthan->execute($date, $g->{track});
117
		while (my @oshift = $openshifthan->fetchrow_array()) {
118
			my $sh = join "</td><td>&nbsp;</td><td>", @oshift;
119
			push @openshifts, "<tr><td>$sh</td></tr>\n";
120
		}
121
		push @openshifts, "</table>\n";
122
		print "<br><br><br><br>";
123
		print @openshifts;
124
 
125
		print "<div class='pagebreak'><hr></div>\n";
126
		$gcount = 1;
127
		$tcount = $g->{track};
128
	}
129
 
130
	$g->{gtype} = join '', map { ucfirst lc } split /(\s+)/, $g->{gtype}; # Capitalize the game time to look nicer
131
 
132
	my %crew;
133
	$crewhan->execute($date, $g->{track}, $g->{time});
134
	while (my ($k, $v) = $crewhan->fetchrow_array()) {
135
		$crew{$k} = $v;
136
	}
137
	my $P1 = "PLT-1";
138
	my $P2 = "PLT-2";
139
	my $PH = "PLT";
140
	my $OPR1 = "OPR-1";
141
	if ($g->{gtype} eq "Full Length" or $g->{gtype} eq "Selected Staffing") {
142
		$P1 = 'PLT/H';
143
		$P2 = 'PLT';
144
		$PH = $P1;
145
	} elsif ($g->{gtype} eq "Challenge-rs1") {
146
		$crew{'OPR-1'} = "<i>-not staffed-</i>";
147
		$crew{'OPR-2'} = "<i>-not staffed-</i>";
148
		$crew{'OPR-3'} = "<i>-not staffed-</i>";
149
		$crew{'PLT-1'} = "<i>-not staffed-</i>";
150
		$crew{'PLT-2'} = "<i>-not staffed-</i>";
151
		$crew{'SK-1'} = "<i>-not staffed-</i>";
152
		$crew{'SK-2'} = "<i>-not staffed-</i>";
153
		$crew{'PBM'} = "<i>-not staffed-</i>";
154
	} elsif ($g->{gtype} eq "Challenge-rs2") {
155
		$OPR1 = "OPR";
156
 
157
		$crew{'IPR'} = "<i>-not staffed-</i>";
158
		$crew{'OPR-2'} = "<i>-not staffed-</i>";
159
		$crew{'OPR-3'} = "<i>-not staffed-</i>";
160
		$crew{'PLT-1'} = "<i>-not staffed-</i>";
161
		$crew{'PLT-2'} = "<i>-not staffed-</i>";
162
		$crew{'SK-1'} = "<i>-not staffed-</i>";
163
		$crew{'SK-2'} = "<i>-not staffed-</i>";
164
		$crew{'PBM'} = "<i>-not staffed-</i>";
165
	} elsif ($g->{gtype} eq "Scrimmage") {
166
		$crew{'PLT-1'} = "<i>-not staffed-</i>";
167
		$crew{'PLT-2'} = "<i>-not staffed-</i>";
168
		$crew{'SK-1'} = "<i>-not staffed-</i>";
169
		$crew{'SK-2'} = "<i>-not staffed-</i>";
170
		$crew{'PBM'} = "<i>-not staffed-</i>";
171
		$crew{'PBT-1'} = "<i>-not staffed-</i>";
172
		$crew{'PBT-2'} = "<i>-not staffed-</i>";
173
		$crew{'SO'} = "<i>-not staffed-</i>";
174
	}
175
 
176
	my $A = '';
177
	if (defined $crew{'ALT'}) {
178
		$A = "ALT:";
179
	} else {
180
		$crew{'ALT'} = '';
181
	}
182
 
183
	print<<game;
184
<table>
185
	<tr><td>Date:</td><td>$day ($date)</td><td>&nbsp;</td><td>Track:</td><td>$g->{track}</td></tr>
186
	<tr><td>Time:</td><td>$g->{time}</td><td>&nbsp;</td><td>Class:</td><td>$class{$g->{restrictions}} $g->{level} $g->{gtype}</td></tr>
187
	<tr><td>Game:</td><td colspan=4>$g->{teams}</td></tr>
188
	<tr><td colspan=5>&nbsp;</td></tr>
189
	<tr><td>HR:</td><td>$crew{'HR'}</td><td>&nbsp;</td><td>$PH:</td><td>$crew{$P1}</td></tr>
190
	<tr><td>IPR:</td><td>$crew{'IPR'}</td><td>&nbsp;</td><td>PLT:</td><td>$crew{$P2}</td></tr>
191
	<tr><td>JR:</td><td>$crew{'JR-1'}</td><td>&nbsp;</td><td>SK:</td><td>$crew{'SK-1'}</td></tr>
192
	<tr><td>JR:</td><td>$crew{'JR-2'}</td><td>&nbsp;</td><td>SK:</td><td>$crew{'SK-2'}</td></tr>
193
	<tr><td>OPR:</td><td>$crew{$OPR1}</td><td>&nbsp;</td><td>PBM:</td><td>$crew{'PBM'}</td></tr>
194
	<tr><td>OPR:</td><td>$crew{'OPR-2'}</td><td>&nbsp;</td><td>PBT:</td><td>$crew{'PBT-1'}</td></tr>
195
	<tr><td>OPR:</td><td>$crew{'OPR-3'}</td><td>&nbsp;</td><td>PBT:</td><td>$crew{'PBT-2'}</td></tr>
196
	<tr><td>$A</td><td>$crew{'ALT'}</td><td>&nbsp;</td><td>JT:</td><td>$crew{'JT'}</td></tr>
197
	<tr><td>&nbsp;</td><td>&nbsp;</td><td>&nbsp;</td><td>SO:</td><td>$crew{'SO'}</td></tr>
198
</table><br><br><br><br><br><br><br><br><br><br><br><br>
199
game
200
 
201
	$gcount++ % 2 == 0 ? print "<div class='pagebreak'><hr></div>\n" : { };
202
}
203
 
204
 
205
 
206
print<<tail;
207
</BODY>
208
</HTML>
209
tail
210
 
211
 
212
 
213
sub noForm {
214
	my $tempdate = shift;
215
 
216
	print header (-cookie=> [ $RCAUTH_cookie ] );
217
	print "Please pick a department and date to print:";
218
	print $h->form ({ action=> url }, [
219
		$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,
220
		$h->input ({
221
  	    name => "date",
222
  	    type => "date",
223
  	    value => $tempdate,
224
  	    required => [],
225
  	    override => 1,
226
  	    size => 30
227
  	  }), $h->br,
228
  	$h->input ({ type => "submit" })
229
	]);
230
 
231
	exit;
232
}