Subversion Repositories VORC

Rev

Rev 50 | Rev 56 | 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
 
35 - 5
#use strict;
8 - 6
use cPanelUserConfig;
35 - 7
use CGI qw/param cookie header start_html url/;
8
use HTML::Tiny;
9
use tableViewer;
2 - 10
use RollerCon;
35 - 11
our $h = HTML::Tiny->new( mode => 'html' );
2 - 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;
35 - 21
our ($EML, $PWD, $LVL);
2 - 22
my $user;
23
my $username;
24
my $RCid;
25
my $RCAUTH_cookie;
53 bgadell 26
my $YEAR = 1900 + (localtime)[5];
2 - 27
 
28
if ($secure) {
29
	$cookie_string = authenticate(2) || die;
30
	($EML, $PWD, $LVL) = split /&/, $cookie_string;
31
	$user = getUser($EML);
35 - 32
	$username = $h->a ({ href=>"/schedule/manage_user.pl?submit=View&RCid=$user->{RCid}" }, $user->{derby_name});
2 - 33
	$RCid = $user->{RCid};
34
	$RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
35
}
36
 
35 - 37
 
38
my $pageTitle = "Game Scores";
39
my $prefscookie = "rcscores";
2 - 40
our $DBTABLE = 'v_scores';
35 - 41
my %COLUMNS = (
42
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
43
	id					=> [qw(ID            5    number            )],
44
	date				=> [qw(Date         10    date              )],
45
	dayofweek		=> [qw(Day          15    select    default )],
46
	track				=> [qw(Track        20    select    default )],
47
	type				=> [qw(Type         25    select            )],
48
	time				=> [qw(Time         30    text      default )],
49
	team1				=> [qw(Team1        35    text      static )],
50
	team2				=> [qw(Team2        40    text      static )]
51
);
52
my $stylesheet = "/style.css";
53
my $homeURL = '/schedule/';
54
my @pagelimitoptions = ("All", 5, 10, 25);
55
 
56
# Set any custom "where" DB filters here...
57
my @whereClause;
58
 
59
# If we need to modify line item values, create a subroutine named "modify_$columnname"
60
#    It will receive a hashref to the object lineitem
61
 
62
sub modify_id {
63
  my $t = shift;
64
 	if ($secure) {
65
  	if ($t->{team1_score} or $t->{team2_score}) {
66
			$t->{id} .= " <A HREF='#' onClick=\"window.open('update_score.pl?GID=$t->{id}','Enter Score','resizable,height=260,width=370'); return false;\">[update score]</a>";
67
		} else {
68
			$t->{id} .= " <A HREF='#' onClick=\"window.open('update_score.pl?GID=$t->{id}','Enter Score','resizable,height=260,width=370'); return false;\">[enter score]</a>";
69
		}
70
	}
71
  return $t->{id};
72
}
73
 
74
sub modify_team1 {
75
  my $t = shift;
76
	$t->{team1} .= " ($t->{team1_score})" unless !defined $t->{team1_score};
77
	$t->{team2} .= " ($t->{team2_score})" unless !defined $t->{team2_score};;
78
 
79
	if ($t->{team1_score} > 0 or $t->{team2_score} > 0) { #SPIKE SEZ DO SOMETHING HERE RE GAME SCORE OF 0
80
 		if ($t->{team1_score} > $t->{team2_score}) { $t->{team1} = "<b>$t->{team1}</b>"; } else { $t->{team2} = "<b>$t->{team2}</b>"; }
81
  }
82
 	return $t->{team1};
83
}
84
 
50 bgadell 85
sub modify_time {
86
  my $t = shift;
87
  return convertTime $t->{time};
88
}
35 - 89
 
90
 
91
# Ideally, nothing below this comment needs to change
92
#-------------------------------------------------------------------------------
93
 
94
 
95
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
96
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
97
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
98
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
99
our @defaultFields     = sort byfield grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
100
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
101
 
102
our @allFields = sort byfield keys %NAME;
2 - 103
our @displayFields = ();
104
our @hideFields = ();
35 - 105
my $QUERY_STRING;
2 - 106
 
35 - 107
my $pagelimit = param ("limit") // $pagelimitoptions[$#pagelimitoptions];
108
my $curpage = param ("page") // 1;
2 - 109
 
35 - 110
our %FORM;
111
my $FILTER;
112
foreach (param()) {
113
 	if (/^year$/) { #
2 - 114
		$YEAR = param($_);
115
		next;
116
	}
35 - 117
 
2 - 118
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
119
 
35 - 120
	if ((/^filter/) and ($FORM{$_} ne '')) {	# Build a set of filters to apply
121
		my ($filter,$field) = split /-/, $_;
2 - 122
		$FILTER->{$field} = $FORM{$_};
35 - 123
	}	elsif ($FORM{$_} eq "true")			# Compile list of fields to display
124
		{ push @displayFields, $_; }
2 - 125
}
126
 
35 - 127
my @yearoptions;
128
foreach (@{&getYears()}) {
129
	push @yearoptions, $YEAR eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_);
130
}
2 - 131
 
35 - 132
 
133
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
134
							                    #  	build the data for the cookie that remembers the page setup
2 - 135
	my $disFields = join ":", @displayFields;
35 - 136
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
2 - 137
 
35 - 138
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
2 - 139
}
140
 
141
 
35 - 142
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
143
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
144
		my ($disF, $filts, $sb, $al) = split /&/,$prefs;
2 - 145
		@displayFields = split /:/,$disF;
146
 
35 - 147
		foreach my $pair (split /:/, $filts)	{
2 - 148
			my ($key, $value) = split /=/, $pair;
149
			$FORM{"filter-$key"} = $value;
150
			$FILTER->{$key} = $value;
151
		}
152
 
35 - 153
		$FORM{sortby} = $sb;
2 - 154
		$FORM{autoload} = $al;
155
		$QUERY_STRING = $prefs;
35 - 156
	}	else {
157
	  @displayFields = @defaultFields; # Otherwise suppply a default list of columns.
158
	  $FORM{autoload} = 1;             # And turn aut0load on by default.
159
	}
2 - 160
}
161
 
35 - 162
# let's just make sure the columns are in the right order (and there aren't any missing)
163
@displayFields = sort byfield uniq @displayFields, @staticFields;
2 - 164
 
35 - 165
# If the field isn't in the displayFields list,	then add it to the hideFields list
166
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
2 - 167
 
35 - 168
# Process any filters provided in the form to pass to the database
169
push @whereClause, map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
170
push @whereClause, "year(date) = '$YEAR'";
2 - 171
 
172
 
173
							#  Given the fields to display and the where conditions,
35 - 174
							#	  "getData" will return a reference to an array of
175
							#	  hash references of the results.
176
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
177
my @ProductList = @{ $data };
2 - 178
 
35 - 179
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
180
my $x = scalar @ProductList; # How many results were returned?
2 - 181
 
35 - 182
# If the user is trying to download the Excel file, send it to them and then exit out.
183
if ($secure and $FORM{excel}) {
184
  exportExcel (\@ProductList, "RC_Officiating_Shifts");
185
  exit;
2 - 186
}
187
 
35 - 188
my $signedOnAs = $username ? "Welcome, $username. ".$h->a ({ href=>"index.pl", onClick=>"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;" }, "[Log Out]") : "You are not signed in.";
2 - 189
 
35 - 190
# Set some cookie stuff...
191
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
192
my $queryCookie = cookie(-NAME=>$prefscookie,
2 - 193
			-VALUE=>"$QUERY_STRING",
194
			-PATH=>"$path",
195
			-EXPIRES=>'+365d');
196
 
35 - 197
# Print the header
2 - 198
if ($secure) {
199
	print header(-cookie=>[$RCAUTH_cookie,$queryCookie]);
200
} else {
201
	print header(-cookie=>[$queryCookie]);
202
}
203
 
35 - 204
# 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
205
#	print "I'm catching updates!!!\n\n";
206
#	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
207
# 		{ print "\t$key:  $FORM{$key}\n"; }
208
# 	print "--> \n\n";
2 - 209
#
210
#
35 - 211
# 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
2 - 212
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
213
# 		{ print "\t$key:  $ENV{$key}\n"; }
35 - 214
# 	print "--> \n\n";
2 - 215
#
216
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
217
 
218
 
219
#------------------
220
 
35 - 221
# Toggle the autoload fields within the table elements
222
our ($onClick, $onChange);   # (also used in scanFunctions)
223
my ($radiobutton, $refreshbutton, $sortby);
224
if ($FORM{autoload}) {
225
	$onClick = "onClick='submit();'";
226
	$onChange = "onChange='page.value = 1; submit();'";
227
  $radiobutton = $h->div ({ class=>'autoload' },
228
    ["Autoload Changes: ",
229
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
230
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
231
    ]);
232
  $sortby = $h->select ({name=>"sortby", onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
233
} else {
234
  $onClick = "";
235
	$onChange = "onChange='page.value = 1;'";
236
  $radiobutton = $h->div ({ class=>'autoload' },
237
    ["Autoload Changes: ",
238
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ",
239
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
240
    ]);
241
  $refreshbutton = $h->input ({ type=>"button", value=>"Refresh", onClick=>"submit(); return false;" });
242
  $sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
243
}
2 - 244
 
245
 
246
 
35 - 247
 
248
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
249
 
250
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
251
print $h->input ({ type=>"hidden", name=>"excel", value=>0 });
252
print $h->div ({ class => "accent pageheader" }, [
253
  $h->h1 ($pageTitle),
254
  $h->div ({ class=>"sp0" }, [
255
    $h->div ({ class=>"spLeft" }, [
256
      $radiobutton
257
    ]),
258
    $h->div ({ class=>"spRight" }, [
259
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
260
      $refreshbutton
261
    ]),
262
  ]),
263
]);
264
 
265
# Print the Hidden fields' check boxes (if there are any)
266
 
267
my $c = 1;
268
my @hiddencheckboxes;
269
my @hiddenrows;
270
foreach my $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
271
  if ($FORM{autoload}) {
272
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters nowrap', onClick=>"Req.$field.click();" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation(); submit();" }), $NAME{$field} ]);
273
  } else {
274
    push @hiddencheckboxes, $h->div ({ class=>'rTableCell quarters nowrap', onClick=>"Req.$field.checked=!Req.$field.checked;" }, [ $h->input ({ type=>'checkbox', class=>'accent', name=>$field, value=>'true', onClick=>"event.stopPropagation();" }), $NAME{$field} ]);
275
  }
276
  if ($c++ % 4 == 0) {
277
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
278
    @hiddencheckboxes = [];
279
  }
2 - 280
}
35 - 281
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
2 - 282
 
283
 
35 - 284
if (scalar @hideFields) {
285
  my @topleft;
286
  push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
287
  push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
288
 
289
  print $h->div ({ class=>"sp0" }, [
290
    $h->div ({ class=>"spLeft"  }, [ @topleft ]),
291
    $h->div ({ class=>"spRight" }, [
292
      $signedOnAs
293
    ])
294
  ]);
295
}
2 - 296
 
35 - 297
# Print the main table...............................................
2 - 298
 
35 - 299
print $h->open ('div', { class=>'rTable' });
2 - 300
 
35 - 301
my @tmptitlerow;
302
foreach my $f (@displayFields)	{  # Print the Column headings
303
  if (inArray ($f, \@staticFields)) {
304
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
305
  } else {
306
    if ($FORM{autoload}) {
307
      push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.click();" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>'event.stopPropagation(); submit();' }), $NAME{$f} ]);
308
    } else {
309
      push @tmptitlerow, $h->div ({ class=>'rTableHead', onClick=>"Req.$f.checked=!Req.$f.checked;" }, [ $h->input ({ type=>"checkbox", class=>"accent", name=>$f, value=>"true", checked=>[], onClick=>"event.stopPropagation();" }), $NAME{$f} ]);
310
    }
311
  }
2 - 312
}
313
 
35 - 314
# Print the filter boxes...
315
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ map { $h->div ({ class=>'rTableCell filters' }, filter ($_)) } @displayFields ], $h->div ({ class=>"rTableCell" }));
2 - 316
 
35 - 317
# Print the things
318
foreach my $t (@ProductList)	{
319
  print $h->div ({ class=>'rTableRow shaded' }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_}) } @displayFields ]);
320
}
2 - 321
 
322
 
323
 
324
 
35 - 325
print $h->close ('div');
2 - 326
 
35 - 327
# close things out................................................
2 - 328
 
35 - 329
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
330
if ($curpage > $pages) { $curpage = $pages; }
2 - 331
 
35 - 332
my @pagerange;
333
if ($pages <= 5 ) {
334
  @pagerange = 1 .. $pages;
335
} else {
336
  if ($curpage <= 3) {
337
    @pagerange = (1, 2, 3, 4, ">>");
338
  } elsif ($curpage >= $pages - 2) {
339
    @pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
340
  } else {
341
    @pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
342
  }
2 - 343
}
344
 
35 - 345
my @excelcode;
2 - 346
 
35 - 347
if ($secure) {
348
  push @excelcode, $h->br;
349
  push @excelcode, $h->a ({ href=>"", target=>"_new", onClick=>"window.document.Req.excel.value=1; window.document.Req.submit(); window.document.Req.excel.value=0; return false;" }, "[Export Displayed Data as an Excel Document.]");
350
}
2 - 351
 
352
 
35 - 353
print $h->br; # print $h->br;
354
print $h->div ({ class=>"sp0" }, [
355
    $h->div ({ class=>"spLeft" }, [
356
      $h->div ({ class=>"footer" }, [
357
        "To bookmark, save, or send this exact view, use the ",
358
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
359
        $h->br,
360
        "If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
361
        @excelcode,
362
        $h->br,
363
        "This page was displayed on ", currentTime (),
364
        $h->br,
365
        "Please direct questions, problems, and concerns to Officials.RollerCon.Schedule\@gmail.com",
366
        $h->br,
367
        "Displaying: ", $h->select ({ name=>"year", onchange=>"Req.submit();" }, [ @yearoptions ])
368
      ])
369
    ]),
370
    $h->div ({ class=>"spRight" }, [
371
      $h->h5 ([
372
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,
373
               "Sorted by ", $sortby, $h->br,
374
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
375
               ( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
376
                                                $_ eq "<<"     ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
377
                                                $_ eq ">>"     ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
378
                                                                 $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
379
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
380
      ])
381
    ]),
382
]);
2 - 383
 
35 - 384
#print $h->br; # print $h->br;
385
#print $h->h5 ("$x Record(s) Displayed");
386
#print $h->div ({ class=>"footer" }, [
387
#  "To bookmark, save, or send this exact view, use the ",
388
#  $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
389
#  $h->br,
390
#  "This page was displayed on $now",
391
#  $h->br,
392
#  "Please direct questions, problems, and concerns to noone\@gmail.com"
393
#]);
2 - 394
 
395
 
35 - 396
print $h->close('form');
397
print $h->close('html');