Subversion Repositories ORC

Rev

Rev 2 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
2 - 1
#!/usr/bin/perl
2
 
3
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
4
 
8 - 5
use cPanelUserConfig;
2 - 6
use CGI qw/:standard/;
7
use scanFunctions;
8
use RollerCon;
9
use Spreadsheet::WriteExcel;
10
use DateTime;
11
use DateTime::Duration;
12
 
13
my $secure = "";
14
if ($ENV{REQUEST_URI}  =~ /^\/scores.pl/) {
15
	$secure = 0;
16
} else {
17
	$secure = 1;
18
}
19
 
20
my $cookie_string;
21
my ($EML, $PWD, $LVL);
22
my $user;
23
my $username;
24
my $RCid;
25
my $RCAUTH_cookie;
26
my $YEAR = 1900 + (localtime)[5]; #which year of data to display, default to current
27
 
28
if ($secure) {
29
	$cookie_string = authenticate(2) || die;
30
	($EML, $PWD, $LVL) = split /&/, $cookie_string;
31
	$user = getUser($EML);
32
	$username = $user->{derby_name};
33
	$RCid = $user->{RCid};
34
	$RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
35
}
36
 
37
our $DBTABLE = 'v_scores';
38
our %NAME = qw(
39
		id						 ID
40
		date					 Date
41
		dayofweek			 Day
42
		track					 Track
43
		type					 Type
44
		time					 Time
45
		team1					 Team1
46
		team2					 Team2
47
	);
48
our %colOrderHash = qw(id 1 date 2 dayofweek 3 track 4 time 5 type 6 team1 7 team2 8);
49
my $orderby = "date, time";
50
our @allFields = sort { $colOrderHash{$a} <=> $colOrderHash{$b} } keys %NAME;
51
our @defaultFields = (qw(dayofweek track time team1 team2));
52
our @displayFields = ();
53
our @hideFields = ();
54
our %colFilterTypeHash = qw(
55
		id						 number
56
		date					 date
57
		dayofweek			 select
58
		track					 select
59
		type					 select
60
		time					 text
61
		team1					 text
62
		team2					 text
63
	);
64
 
65
 
66
 
67
foreach (param())
68
{
69
	if (/^year$/) { #
70
		$YEAR = param($_);
71
		next;
72
	}
73
 
74
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
75
 
76
	if ((/^filter/) and ($FORM{$_} ne ''))		# Build a set of filters to apply
77
		{
78
		my ($filter,$field) = split /-/, $_;
79
 
80
		$FILTER->{$field} = $FORM{$_};
81
		}
82
	elsif ($FORM{$_} eq "true")			# Compile list of fields to display
83
		{ push @displayFields, $_; }			# @displayFields is declared in scanFunctions.pm
84
}
85
 
86
 
87
if (exists $FORM{autoload})				# If the FORM was submitted (i.e. the page is being redisplayed),
88
{							#	build the data for the cookie that remembers the page setup
89
	my $disFields = join ":", @displayFields;
90
	my @filters;
91
	my @f = keys %{$FILTER};
92
	foreach $key (@f)
93
		{ push @filters, "$key=$FILTER->{$key}"; }
94
	my $fils = join ":", @filters;
95
 
96
	$QUERY_STRING = "$disFields\&$fils\&$FORM{autoload}";
97
}
98
 
99
 
100
if (!(exists $FORM{autoload}))				# No FORM was submitted, suppply a default list of columns
101
{
102
	if (my $prefs = cookie('RCSCORES'))	# Has this user been here before and saved a cookie?
103
	{
104
		my ($disF, $filts, $al) = split /&/,$prefs;
105
		@displayFields = split /:/,$disF;
106
 
107
		foreach $pair (split /:/, $filts)
108
		{
109
			my ($key, $value) = split /=/, $pair;
110
			$FORM{"filter-$key"} = $value;
111
			$FILTER->{$key} = $value;
112
		}
113
 
114
		$FORM{autoload} = $al;
115
		$QUERY_STRING = $prefs;
116
	}
117
	else
118
		{ @displayFields = @defaultFields; }
119
}
120
 
121
 
122
							# Build the field lists to display and hide columns.
123
							#	If the field isn't in the displayFields list,
124
							#	then add it to the hideFields list.
125
							#
126
@displayFields = sort byfield @displayFields;
127
foreach $field (@allFields) { if (! &inArray($field, \@displayFields)) { push @hideFields, $field; } }
128
 
129
 
130
my @whereClause = ("year(date) = '$YEAR'");					# Process the filters to build the components of the where clause
131
foreach $field (@allFields)
132
{
133
	if (! &inArray($field, \@hideFields))
134
	{
135
		if ($FILTER->{$field})
136
		{
137
			push @whereClause, &generica($field, $FILTER->{$field});
138
			delete $FILTER->{$field};
139
		}
140
	}
141
}
142
 
143
							#  Given the fields to display and the where conditions,
144
							#	"getData" will return a reference to an array of
145
							#	hash references of the results.
146
my @ProductList = @{&getData(\@displayFields, \@whereClause, $DBTABLE, $orderby)};
147
my $x = scalar @ProductList;
148
 
149
 
150
if ($secure) {
151
	if ($FORM{excel})
152
	{
153
		my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
154
	#	$filename = `dirname $ENV{REQUEST_URI}`; chomp $filename; $filename .= "/xls/${date}_$$.xls";
155
		$filename = "/schedule/xls/${date}_$$.xls";
156
 
157
	        # Create a new Excel workbook
158
#		my $workbook = Spreadsheet::WriteExcel->new("/var/www/html${filename}");
159
	my $workbook = Spreadsheet::WriteExcel->new("/home/rollerco/officials.rollercon.com${filename}");
160
 
161
	        # Add a worksheet
162
	        my $worksheet = $workbook->add_worksheet();
163
 
164
	#	open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
165
	#	my $workbook  = Spreadsheet::WriteExcel->new($fh);
166
	#	my $worksheet = $workbook->add_worksheet();
167
 
168
 
169
		my $format = $workbook->add_format();
170
		$format->set_bold();
171
 
172
		my $col = $row = 0;
173
 
174
		foreach $f (@displayFields)
175
			{ $worksheet->write($row, $col++, "$NAME{$f}", $format); }
176
 
177
		foreach $t (sort @ProductList)			# Unt now we print the tickets!
178
		{
179
			$col = 0;
180
			$row++;
181
			if (exists $f->{team1_score} and exists $f->{team2_score}) {
182
				$f->{team1} .= " ($f->{team1_score})";
183
				$f->{team2} .= " ($f->{team2_score})";
184
			}
185
 
186
			foreach $f (@displayFields)
187
				{
188
					$t->{$f} =~ s/<br>/\n/ig; $worksheet->write($row, $col++, "$t->{$f}");
189
				}
190
		}
191
 
192
		$workbook->close();
193
 
194
	}
195
}
196
 
197
 
198
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/';
199
my $queryCookie = cookie(-NAME=>'RCSCORES',
200
			-VALUE=>"$QUERY_STRING",
201
			-PATH=>"$path",
202
			-EXPIRES=>'+365d');
203
#my $Auth_Cook = cookie(-NAME=>'RequestToolAuthorized',
204
#			-VALUE=>"$authCookie",
205
#			-PATH=>'/cbrt/cgi-bin/');
206
 
207
if ($secure) {
208
	print header(-cookie=>[$RCAUTH_cookie,$queryCookie]);
209
} else {
210
	print header(-cookie=>[$queryCookie]);
211
}
212
 
213
 
214
 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
215
	print "I'm catching updates!!!\n\n";
216
	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
217
 		{ print "\t$key:  $FORM{$key}\n"; }
218
 	print "--> \n\n";
219
#
220
#
221
 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
222
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
223
# 		{ print "\t$key:  $ENV{$key}\n"; }
224
	print "REQUEST_URI: $ENV{REQUEST_URI}\n";
225
 	print "--> \n\n";
226
#
227
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
228
 
229
 
230
#------------------
231
 
232
 
233
if ($FORM{autoload})					  # Toggle the autoload fields within the table elements
234
	{ $auto = "onClick='submit();'";
235
	 $auto2 = "onChange='submit();'"; }
236
else
237
	{ $auto = "";
238
	 $auto2 = ""; }
239
 
240
 
241
my $signedOnAs = $username ? "You are currently signed in as $username. <font size=-2><a href='index.pl' onClick=\"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;\">[Log Out]</a></font>" : "You are not signed in.";
242
my $xlsLink = $filename ? "&nbsp; &nbsp; <A href='$filename'><FONT color='#0077BD'>Download Now.</FONT></a>" : "";
243
my $yearoptions;
244
foreach (@{&getYears()}) {
245
	$yearoptions .= $YEAR eq $_ ? "<option selected>$_</option>" : "<option>$_</option>";
246
}
247
 
248
print<<header;
249
	<html><head><title>RollerCon Game Scores - $YEAR</title></head>
250
	<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#FF0000">
251
	<form action="scores.pl" method=POST name=Scores>
252
	<input type=hidden name=excel value=0>
253
 
254
	<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
255
		<TR>
256
			<TD>
257
			<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
258
				<TR>
259
					<TD width=680 bgcolor="#0077BD" height=60><FONT color=white face=verdana size=6><i><strong>&nbsp;RollerCon Game Scores - $YEAR</strong></i></font></TD>
260
					<TD><img SRC="/images/headerblank.gif" NOSAVE height=38 width=165></TD>
261
				</TR>
262
			</TABLE>
263
			</TD>
264
		<TR>
265
			<TD>&nbsp</TD>
266
		</TR>
267
		<TR>
268
			<TD>
269
			<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
270
				<TR>
271
					<TD rowspan=2 align=left width=610>
272
					<TABLE border=0 cellspacing=0>
273
header
274
 
275
							# Print the Hidden fields' check boxes
276
 
277
					my $tc = 1;
278
					foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields)
279
						{
280
						if ($tc == 1)
281
							{print "\t\t\t\t\t\t<TR>\n\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n"; $tc++;}
282
						elsif ($tc == 4)
283
							{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n\t\t\t\t\t\t</TR>\n"; $tc=1;}
284
						else
285
							{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n"; $tc++;}
286
						}
287
 
288
 					if ($FORM{autoload})
289
 						{
290
 						$trueChecked = "checked";
291
 						$falseChecked = "";
292
 						}
293
 					else
294
 						{
295
 						$trueChecked = "";
296
 						$falseChecked = "checked";
297
 	 					}
298
 
299
					print<<header3;
300
						<TR>
301
							<TD colspan=4 align=center><FONT face=verdana size=1 color=#0077BD><B>
302
							Autoload: <INPUT type=radio name=autoload value=1 onClick='Scores.submit();' $trueChecked>On  <INPUT type=radio name=autoload value=0 onClick='Scores.submit();' $falseChecked>Off
303
							</TD>
304
						</TR>
305
					</TABLE>
306
					</TD>
307
					<TD nowrap>
308
						<A HREF='' onClick="window.document.Scores.submit(); return false;"><IMG SRC='/images/refresh.button.gif' border=0></A><br>
309
header3
310
 
311
if ($secure) {
312
	print<<header5;
313
						<strong><a href='' onClick='window.document.Scores.excel.value=1; window.document.Scores.submit(); return false;'><FONT face=verdana size=1>Export Displayed Data as Excel Document.</a>$xlsLink</font>
314
					</TD>
315
				</TR>
316
				<TR>
317
					<TD align=left><B><FONT face=verdana size=1>$signedOnAs<br>
318
					Display <A HREF='' onClick="window.document.Scores.method = 'GET'; window.document.Scores.submit(); return false;">Full URL</a> : <select name=year onchange='Scores.submit();'>$yearoptions</select> : <a href=/schedule/>[Go HOME]</a></TD>
319
				</TR>
320
header5
321
} else {
322
	print "</TD>\n</TR>\n";
323
}
324
 
325
print<<header4;
326
 
327
			</TABLE>
328
			</TD>
329
		</TR>
330
		<TR>
331
			<TD>&nbsp</TD>
332
		</TR>
333
		<TR>
334
			<TD>
335
			<TABLE border=0 cellspacing=2 cellpadding=4 width=100\%>
336
				<TR bgcolor=#0077BD>
337
header4
338
 
339
							# Print the Column headings
340
				foreach $f (@displayFields)
341
					{ print "\t\t\t\t\t<TD align=left nowrap><FONT face=verdana color=white size=1><B><INPUT type=checkbox name=$f value=true checked $auto>$NAME{$f}</TD>\n"; }
342
				print "<TD>&nbsp;</TD>\n" if $secure;
343
				print "\t\t\t\t</TR>\n\t\t\t\t<TR>\n";
344
							# and now the filter boxes
345
 
346
				foreach $f (@displayFields)
347
					{
348
					print "\t\t\t\t\t<TD align=left bgcolor=#E6E6E6><FONT size=1 face=verdana>";
349
					print &generica($f);
350
#					print "&nbsp;";
351
					print "</TD>\n";
352
					}
353
				print "<TD bgcolor=#E6E6E6>&nbsp;</TD>\n" if $secure;
354
				print "\t\t\t\t</TR></FORM>\n";
355
 
356
				my $cw = scalar @displayFields + 1;
357
 
358
				print<<header2;
359
				</TR>
360
				<TR>
361
					<TD colspan=$cw><P><P></TD>
362
				</TR>
363
header2
364
 
365
 
366
my $co = '#FFFFFF';
367
 
368
foreach $t (@ProductList)			# Unt now we print the tickets!
369
{
370
	if ($t->{team1_score} > 0 and $t->{team2_score} > 0) { #SPIKE SEZ DO SOMETHING HERE RE GAME SCORE OF 0
371
			$t->{team1} .= " ($t->{team1_score})";
372
			$t->{team2} .= " ($t->{team2_score})";
373
		if ($t->{team1_score} > $t->{team2_score}) { $t->{team1} = "<b>$t->{team1}</b>"; } else { $t->{team2} = "<b>$t->{team2}</b>"; }
374
	}
375
 
376
 
377
	print "\t\t\t\t<TR>\n";
378
	foreach $f (@displayFields)
379
		{
380
			$f =~ s/^HOST\.//;
381
			$f =~ s/^FRAME\.//;
382
			print "\t\t\t\t\t<TD align=left valign=top bgcolor='$co'><FONT face=verdana size=1>".$t->{$f}."&nbsp</TD>\n";
383
		}
384
	print "<TD>";
385
	if ($secure and $YEAR eq "2019") {
386
		if ($t->{team1_score} or $t->{team2_score}) {
387
			print "<FONT face=verdana size=1><A HREF='#' onClick=\"window.open('update_score.pl?GID=$t->{id}','Enter Score','resizable,height=260,width=370'); return false;\">[update score]</a>";
388
		} else {
389
			print "<FONT face=verdana size=1><A HREF='#' onClick=\"window.open('update_score.pl?GID=$t->{id}','Enter Score','resizable,height=260,width=370'); return false;\">[enter score]</a>";
390
		}
391
	}
392
	print "</TD>";
393
 
394
	print "\t\t\t\t</TR>\n";
395
 
396
	if ($co eq '#FFFFFF')
397
		{ $co = '#F9F9F9'; }
398
	else
399
		{ $co = '#FFFFFF'; }
400
 
401
}
402
 
403
print<<tail;
404
			</TABLE>
405
			</TD>
406
		</TR>
407
	</TABLE>
408
	<br><br>
409
	<FONT face=verdana size=2><B>$x Record(s) Displayed</font>
410
	<BR><BR>
411
	<FONT face=verdana size=1><B>This page was displayed on $now<BR>
412
	Please direct questions, problems, and concerns to <FONT face=verdana color=#0077BD>officials.rollercon.schedule\@gmail.com</FONT>
413
 
414
	<SCRIPT language="JavaScript">
415
	<!--
416
 
417
	var ticket_window, severity_window, user_window;
418
 
419
	function NewWindow () {
420
		if ((ticket_window == null) || (ticket_window.closed == true))
421
			ticket_window = open(\"\",\"Details\",\"width=650,height=650,menubar,scrollbars,resizable\");
422
		ticket_window.focus();
423
		return true;
424
		}
425
 
426
	function SevWindow () {
427
		if ((severity_window == null) || (severity_window.closed == true))
428
			severity_window = open(\"\",\"SevDetails\",\"width=500,height=300,menubar\");
429
		severity_window.focus();
430
		return true;
431
		}
432
 
433
	function UserWindow () {
434
		if ((user_window == null) || (user_window.closed == true))
435
			user_window = open(\"\",\"UserDetails\",\"width=310,height=115,menubar\");
436
		user_window.focus();
437
		return true;
438
		}
439
 
440
	//-->
441
	</SCRIPT>
442
 
443
</body></html>
444
tail
445