Subversion Repositories VORC

Rev

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

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