Subversion Repositories ORC

Rev

Rev 8 | 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;
35 - 26
my $YEAR = "2022";
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
 
85
 
86
 
87
# Ideally, nothing below this comment needs to change
88
#-------------------------------------------------------------------------------
89
 
90
 
91
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
92
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
93
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
94
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
95
our @defaultFields     = sort byfield grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
96
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
97
 
98
our @allFields = sort byfield keys %NAME;
2 - 99
our @displayFields = ();
100
our @hideFields = ();
35 - 101
my $QUERY_STRING;
2 - 102
 
35 - 103
my $pagelimit = param ("limit") // $pagelimitoptions[$#pagelimitoptions];
104
my $curpage = param ("page") // 1;
2 - 105
 
35 - 106
our %FORM;
107
my $FILTER;
108
foreach (param()) {
109
 	if (/^year$/) { #
2 - 110
		$YEAR = param($_);
111
		next;
112
	}
35 - 113
 
2 - 114
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
115
 
35 - 116
	if ((/^filter/) and ($FORM{$_} ne '')) {	# Build a set of filters to apply
117
		my ($filter,$field) = split /-/, $_;
2 - 118
		$FILTER->{$field} = $FORM{$_};
35 - 119
	}	elsif ($FORM{$_} eq "true")			# Compile list of fields to display
120
		{ push @displayFields, $_; }
2 - 121
}
122
 
35 - 123
my @yearoptions;
124
foreach (@{&getYears()}) {
125
	push @yearoptions, $YEAR eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_);
126
}
2 - 127
 
35 - 128
 
129
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
130
							                    #  	build the data for the cookie that remembers the page setup
2 - 131
	my $disFields = join ":", @displayFields;
35 - 132
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
2 - 133
 
35 - 134
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
2 - 135
}
136
 
137
 
35 - 138
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
139
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
140
		my ($disF, $filts, $sb, $al) = split /&/,$prefs;
2 - 141
		@displayFields = split /:/,$disF;
142
 
35 - 143
		foreach my $pair (split /:/, $filts)	{
2 - 144
			my ($key, $value) = split /=/, $pair;
145
			$FORM{"filter-$key"} = $value;
146
			$FILTER->{$key} = $value;
147
		}
148
 
35 - 149
		$FORM{sortby} = $sb;
2 - 150
		$FORM{autoload} = $al;
151
		$QUERY_STRING = $prefs;
35 - 152
	}	else {
153
	  @displayFields = @defaultFields; # Otherwise suppply a default list of columns.
154
	  $FORM{autoload} = 1;             # And turn aut0load on by default.
155
	}
2 - 156
}
157
 
35 - 158
# let's just make sure the columns are in the right order (and there aren't any missing)
159
@displayFields = sort byfield uniq @displayFields, @staticFields;
2 - 160
 
35 - 161
# If the field isn't in the displayFields list,	then add it to the hideFields list
162
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
2 - 163
 
35 - 164
# Process any filters provided in the form to pass to the database
165
push @whereClause, map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
166
push @whereClause, "year(date) = '$YEAR'";
2 - 167
 
168
 
169
							#  Given the fields to display and the where conditions,
35 - 170
							#	  "getData" will return a reference to an array of
171
							#	  hash references of the results.
172
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
173
my @ProductList = @{ $data };
2 - 174
 
35 - 175
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
176
my $x = scalar @ProductList; # How many results were returned?
2 - 177
 
35 - 178
# If the user is trying to download the Excel file, send it to them and then exit out.
179
if ($secure and $FORM{excel}) {
180
  exportExcel (\@ProductList, "RC_Officiating_Shifts");
181
  exit;
2 - 182
}
183
 
35 - 184
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 - 185
 
35 - 186
# Set some cookie stuff...
187
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
188
my $queryCookie = cookie(-NAME=>$prefscookie,
2 - 189
			-VALUE=>"$QUERY_STRING",
190
			-PATH=>"$path",
191
			-EXPIRES=>'+365d');
192
 
35 - 193
# Print the header
2 - 194
if ($secure) {
195
	print header(-cookie=>[$RCAUTH_cookie,$queryCookie]);
196
} else {
197
	print header(-cookie=>[$queryCookie]);
198
}
199
 
35 - 200
# 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
201
#	print "I'm catching updates!!!\n\n";
202
#	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
203
# 		{ print "\t$key:  $FORM{$key}\n"; }
204
# 	print "--> \n\n";
2 - 205
#
206
#
35 - 207
# 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
2 - 208
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
209
# 		{ print "\t$key:  $ENV{$key}\n"; }
35 - 210
# 	print "--> \n\n";
2 - 211
#
212
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
213
 
214
 
215
#------------------
216
 
35 - 217
# Toggle the autoload fields within the table elements
218
our ($onClick, $onChange);   # (also used in scanFunctions)
219
my ($radiobutton, $refreshbutton, $sortby);
220
if ($FORM{autoload}) {
221
	$onClick = "onClick='submit();'";
222
	$onChange = "onChange='page.value = 1; submit();'";
223
  $radiobutton = $h->div ({ class=>'autoload' },
224
    ["Autoload Changes: ",
225
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
226
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
227
    ]);
228
  $sortby = $h->select ({name=>"sortby", onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
229
} else {
230
  $onClick = "";
231
	$onChange = "onChange='page.value = 1;'";
232
  $radiobutton = $h->div ({ class=>'autoload' },
233
    ["Autoload Changes: ",
234
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ",
235
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
236
    ]);
237
  $refreshbutton = $h->input ({ type=>"button", value=>"Refresh", onClick=>"submit(); return false;" });
238
  $sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
239
}
2 - 240
 
241
 
242
 
35 - 243
 
244
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
245
 
246
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
247
print $h->input ({ type=>"hidden", name=>"excel", value=>0 });
248
print $h->div ({ class => "accent pageheader" }, [
249
  $h->h1 ($pageTitle),
250
  $h->div ({ class=>"sp0" }, [
251
    $h->div ({ class=>"spLeft" }, [
252
      $radiobutton
253
    ]),
254
    $h->div ({ class=>"spRight" }, [
255
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
256
      $refreshbutton
257
    ]),
258
  ]),
259
]);
260
 
261
# Print the Hidden fields' check boxes (if there are any)
262
 
263
my $c = 1;
264
my @hiddencheckboxes;
265
my @hiddenrows;
266
foreach my $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
267
  if ($FORM{autoload}) {
268
    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} ]);
269
  } else {
270
    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} ]);
271
  }
272
  if ($c++ % 4 == 0) {
273
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
274
    @hiddencheckboxes = [];
275
  }
2 - 276
}
35 - 277
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
2 - 278
 
279
 
35 - 280
if (scalar @hideFields) {
281
  my @topleft;
282
  push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
283
  push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
284
 
285
  print $h->div ({ class=>"sp0" }, [
286
    $h->div ({ class=>"spLeft"  }, [ @topleft ]),
287
    $h->div ({ class=>"spRight" }, [
288
      $signedOnAs
289
    ])
290
  ]);
291
}
2 - 292
 
35 - 293
# Print the main table...............................................
2 - 294
 
35 - 295
print $h->open ('div', { class=>'rTable' });
2 - 296
 
35 - 297
my @tmptitlerow;
298
foreach my $f (@displayFields)	{  # Print the Column headings
299
  if (inArray ($f, \@staticFields)) {
300
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
301
  } else {
302
    if ($FORM{autoload}) {
303
      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} ]);
304
    } else {
305
      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} ]);
306
    }
307
  }
2 - 308
}
309
 
35 - 310
# Print the filter boxes...
311
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ map { $h->div ({ class=>'rTableCell filters' }, filter ($_)) } @displayFields ], $h->div ({ class=>"rTableCell" }));
2 - 312
 
35 - 313
# Print the things
314
foreach my $t (@ProductList)	{
315
  print $h->div ({ class=>'rTableRow shaded' }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_}) } @displayFields ]);
316
}
2 - 317
 
318
 
319
 
320
 
35 - 321
print $h->close ('div');
2 - 322
 
35 - 323
# close things out................................................
2 - 324
 
35 - 325
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
326
if ($curpage > $pages) { $curpage = $pages; }
2 - 327
 
35 - 328
my @pagerange;
329
if ($pages <= 5 ) {
330
  @pagerange = 1 .. $pages;
331
} else {
332
  if ($curpage <= 3) {
333
    @pagerange = (1, 2, 3, 4, ">>");
334
  } elsif ($curpage >= $pages - 2) {
335
    @pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
336
  } else {
337
    @pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
338
  }
2 - 339
}
340
 
35 - 341
my @excelcode;
2 - 342
 
35 - 343
if ($secure) {
344
  push @excelcode, $h->br;
345
  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.]");
346
}
2 - 347
 
348
 
35 - 349
print $h->br; # print $h->br;
350
print $h->div ({ class=>"sp0" }, [
351
    $h->div ({ class=>"spLeft" }, [
352
      $h->div ({ class=>"footer" }, [
353
        "To bookmark, save, or send this exact view, use the ",
354
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
355
        $h->br,
356
        "If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
357
        @excelcode,
358
        $h->br,
359
        "This page was displayed on ", currentTime (),
360
        $h->br,
361
        "Please direct questions, problems, and concerns to Officials.RollerCon.Schedule\@gmail.com",
362
        $h->br,
363
        "Displaying: ", $h->select ({ name=>"year", onchange=>"Req.submit();" }, [ @yearoptions ])
364
      ])
365
    ]),
366
    $h->div ({ class=>"spRight" }, [
367
      $h->h5 ([
368
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,
369
               "Sorted by ", $sortby, $h->br,
370
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
371
               ( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
372
                                                $_ eq "<<"     ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
373
                                                $_ eq ">>"     ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
374
                                                                 $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
375
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
376
      ])
377
    ]),
378
]);
2 - 379
 
35 - 380
#print $h->br; # print $h->br;
381
#print $h->h5 ("$x Record(s) Displayed");
382
#print $h->div ({ class=>"footer" }, [
383
#  "To bookmark, save, or send this exact view, use the ",
384
#  $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
385
#  $h->br,
386
#  "This page was displayed on $now",
387
#  $h->br,
388
#  "Please direct questions, problems, and concerns to noone\@gmail.com"
389
#]);
2 - 390
 
391
 
35 - 392
print $h->close('form');
393
print $h->close('html');