Subversion Repositories ORC

Rev

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

Rev Author Line No. Line
35 - 1
#!/usr/bin/perl
2
 
3
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
4
 
5
#use strict;
6
use cPanelUserConfig;
7
use CGI qw/param cookie header start_html url/;
8
use HTML::Tiny;
9
use tableViewer;
10
use RollerCon;
43 - 11
use DateTime;
12
#use DateTime::Duration;
13
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
35 - 14
our $h = HTML::Tiny->new( mode => 'html' );
15
 
16
my $cookie_string;
17
our ($EML, $PWD, $LVL);
18
my $user;
19
my $username;
20
my $RCid;
21
my $RCAUTH_cookie;
22
#my $YEAR = "2022";
23
 
24
$cookie_string = authenticate(1) || die;
25
($EML, $PWD, $LVL) = split /&/, $cookie_string;
26
$user = getUser($EML);
27
$username = $h->a ({ href=>"/schedule/manage_user.pl?submit=View&RCid=$user->{RCid}" }, $user->{derby_name});
28
$RCid = $user->{RCid};
29
$RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
30
 
31
if (convertDepartments($user->{department})->{CLA} < 1 and $LVL < 4) {
32
	print header(-cookie=>$RCAUTH_cookie);
33
	printRCHeader("Unauthorized Page");
34
	print $h->div ({ class=>"error" }, "No Access");
35
	print $h->div ("Your user account is not registered to sign up for MVP Classes, so you can't see this page.  It's possible that your access is still being reviewed.  Please be patient.");
36
	print $h->a ({ href=>"/schedule/" }, "[Go Home]");
37
	print $h->close ("html");
38
	exit;
39
}
40
 
41
 
42
my $pageTitle = "MVP Classes";
43
my $prefscookie = "newmvpclasses";
44
our $DBTABLE = 'v_mvp_class';
45
my %COLUMNS = (
46
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
47
	note				=> [qw(Class         5    text     static )],
48
	date				=> [qw(Date         10    date              )],
49
	dayofweek		=> [qw(Day          15    select    default )],
50
	start_time	=> [qw(StartTime    20    text      )],
51
	end_time		=> [qw(EndTime      25    text       )],
52
	time				=> [qw(Time         30    text      default )],
53
	location		=> [qw(Track        35    select    default )],
54
	role				=> [qw(Coach        40    select    default )],
55
	available		=> [qw(SignUp       45    text      static )]
56
);
57
my $stylesheet = "/style.css";
58
my $homeURL = '/schedule/';
59
my @pagelimitoptions = ("All", 5, 10, 25);
60
 
61
# Set any custom "where" DB filters here...
62
my @whereClause;
63
 
64
# If we need to modify line item values, create a subroutine named "modify_$columnname"
65
#    It will receive a hashref to the object lineitem
66
 
67
#use WebDB;
68
#my $dbh = WebDB::connect;
69
my $dbh = getRCDBH;
70
 
71
sub modify_available {
72
	my $t = shift;
43 - 73
 
74
 	my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
75
	my $cutoff = DateTime->new(
76
        year => $yyyy,
77
        month => $mm,
78
        day => $dd,
79
        hour => 5,
80
        minute => 0,
81
        second => 0,
82
        time_zone => 'America/Los_Angeles'
83
  );
84
 
85
  return "CLOSED" unless $now < $cutoff;
86
 
35 - 87
	($t->{signedup}) = $dbh->selectrow_array ("select id from v_shift where RCid = ? and date = ? and start_time = ? and location = ?", undef, $RCid, $t->{date}, $t->{start_time}, $t->{location} );
88
	my $droplink = $h->a ({ onClick=>"if (confirm('Really? You want to drop this shift?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "[DROP]");
89
	if (!$t->{available}) {
90
	  my $full = "FULL";
91
	  $full .= " | ".$droplink unless !$t->{signedup};
92
	  return $full;
93
  }
94
 
95
	my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
96
	$t->{available} .= " Open";
97
  $t->{available} .= " | ".$droplink unless !$t->{signedup};
98
	if (signUpEligible ($ORCUSER, $t, "class")) {
99
		# SIGN UP
100
		$t->{available} .= " | ".$h->a ({ onClick=>"window.open('make_shift_change.pl?change=add&RCid=$RCid&id=$classkey','Confirm Shift Change','resizable,height=260,width=370'); return false;" }, "[SIGN UP]");
101
	}
102
	if ($user->{department}->{CLA} >= 2 or $LVL > 4 or $user->{department}->{VCI} >= 2) {
103
		# ADD USER
104
		$t->{available} ? $t->{available} .= " | " : {};
105
		$t->{available} .= $h->a ({ onClick=>"window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$classkey','Confirm Shift Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]");
106
	}
107
 
108
	return $t->{available};
109
}
110
 
111
sub filter_available {
112
  my $colName = shift;
113
	my $filter = shift;
114
 
115
	if (defined $filter)	{
116
		if ($filter eq "Full") {
117
			return "$colName = 0";
118
		}
119
		return "$colName > 0";
120
	}	else {
121
		my $thing = "filter-${colName}";
122
		my $Options = "<OPTION></OPTION>"."<OPTION>Available</OPTION>"."<OPTION>Full</OPTION>";
123
 
124
		$Options =~ s/>($FORM{$thing})/ selected>$1/;
125
		return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
126
	}
127
}
128
 
129
# Ideally, nothing below this comment needs to change
130
#-------------------------------------------------------------------------------
131
 
132
 
133
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
134
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
135
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
136
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
137
our @defaultFields     = sort byfield grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
138
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
139
 
140
our @allFields = sort byfield keys %NAME;
141
our @displayFields = ();
142
our @hideFields = ();
143
my $QUERY_STRING;
144
 
145
my $pagelimit = param ("limit") // "All"; #$pagelimitoptions[$#pagelimitoptions];
146
my $curpage = param ("page") // 1;
147
 
148
our %FORM;
149
my $FILTER;
150
foreach (param()) {
151
# 	if (/^year$/) { #
152
#		$YEAR = param($_);
153
#		next;
154
#	}
155
 
156
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
157
 
158
	if ((/^filter/) and ($FORM{$_} ne '')) {	# Build a set of filters to apply
159
		my ($filter,$field) = split /-/, $_;
160
		$FILTER->{$field} = $FORM{$_};
161
	}	elsif ($FORM{$_} eq "true")	{		# Compile list of fields to display
162
	  if ($_ ne "shiftinclude") {
163
		  push @displayFields, $_;
164
		}
165
	}
166
}
167
 
168
#my @yearoptions = ($YEAR);
169
#foreach (@{&getYears()}) {
170
#	push @yearoptions, $YEAR eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_);
171
#}
172
 
173
 
174
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
175
							                    #  	build the data for the cookie that remembers the page setup
176
	my $disFields = join ":", @displayFields;
177
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
178
 
179
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload}.'&'.$FORM{shiftinclude};
180
}
181
 
182
 
183
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
184
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
185
		my ($disF, $filts, $sb, $al, $si) = split /&/,$prefs;
186
		@displayFields = split /:/,$disF;
187
 
188
		foreach my $pair (split /:/, $filts)	{
189
			my ($key, $value) = split /=/, $pair;
190
			$FORM{"filter-$key"} = $value;
191
			$FILTER->{$key} = $value;
192
		}
193
 
194
		$FORM{sortby} = $sb;
195
		$FORM{autoload} = $al;
196
		$FORM{shiftinclude} = $si;
197
		$QUERY_STRING = $prefs;
198
	}	else {
199
	  @displayFields = @defaultFields; # Otherwise suppply a default list of columns.
200
	  $FORM{autoload} = 1;             # And turn aut0load on by default.
201
		$FORM{sortby} = "note";
202
	}
203
}
204
 
205
# let's just make sure the columns are in the right order (and there aren't any missing)
206
@displayFields = sort byfield uniq @displayFields, @staticFields;
207
 
208
# If the field isn't in the displayFields list,	then add it to the hideFields list
209
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
210
 
211
# Process any filters provided in the form to pass to the database
212
push @whereClause, map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
213
#push @whereClause, "year(date) = '$YEAR'";
214
#warn join " and ", @whereClause;
215
 
216
							#  Given the fields to display and the where conditions,
217
							#	  "getData" will return a reference to an array of
218
							#	  hash references of the results.
219
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
220
my @ProductList = @{ $data };
221
 
222
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
223
my $x = scalar @ProductList; # How many results were returned?
224
 
225
# If the user is trying to download the Excel file, send it to them and then exit out.
226
if ($FORM{excel}) {
227
  exportExcel (\@ProductList, "MVP_Class_List");
228
  exit;
229
}
230
 
231
my @shifts;
232
if ($FORM{shiftinclude} eq "true") {
233
  my @SIWhere; # = ("year(date) = '$YEAR'");
234
  push @SIWhere, "RCid = $ORCUSER->{RCid}", "dept='CLA'";
235
  my ($d, $c) = getData (\@displayFields, \@SIWhere, 'v_shift', $FORM{sortby});
236
  @shifts = @{ $d };
237
}
238
 
239
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.";
240
 
241
# Set some cookie stuff...
242
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
243
my $queryCookie = cookie(-NAME=>$prefscookie,
244
			-VALUE=>"$QUERY_STRING",
245
			-PATH=>"$path",
246
			-EXPIRES=>'+365d');
247
 
248
my $SIChecked;
249
if ($FORM{shiftinclude}) {
250
  $SIChecked = $h->input ({ type=>"checkbox", name=>"shiftinclude", value=>"true", checked=>[], onClick=>'submit();' });
251
} else {
252
  $SIChecked = $h->input ({ type=>"checkbox", name=>"shiftinclude", value=>"true", onClick=>'submit();' });
253
}
254
 
255
# Print the header
256
print header(-cookie=>[$RCAUTH_cookie,$queryCookie]);
257
 
258
# 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
259
#	print "I'm catching updates!!!\n\n";
260
#	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
261
# 		{ print "\t$key:  $FORM{$key}\n"; }
262
# 	print "--> \n\n";
263
#
264
#
265
# 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
266
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
267
# 		{ print "\t$key:  $ENV{$key}\n"; }
268
# 	print "--> \n\n";
269
#
270
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
271
 
272
 
273
#------------------
274
 
275
# Toggle the autoload fields within the table elements
276
our ($onClick, $onChange);   # (also used in scanFunctions)
277
my ($radiobutton, $refreshbutton, $sortby);
278
if ($FORM{autoload}) {
279
	$onClick = "onClick='submit();'";
280
	$onChange = "onChange='page.value = 1; submit();'";
281
  $radiobutton = $h->div ({ class=>'autoload' },
282
    ["Autoload Changes: ",
283
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
284
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
285
    ]);
286
  $sortby = $h->select ({name=>"sortby", onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
287
} else {
288
  $onClick = "";
289
	$onChange = "onChange='page.value = 1;'";
290
  $radiobutton = $h->div ({ class=>'autoload' },
291
    ["Autoload Changes: ",
292
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ",
293
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
294
    ]);
295
  $refreshbutton = $h->input ({ type=>"button", value=>"Refresh", onClick=>"submit(); return false;" });
296
  $sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
297
}
298
 
299
 
300
 
301
 
302
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
303
 
304
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
305
print $h->input ({ type=>"hidden", name=>"excel", value=>0 });
306
print $h->div ({ class => "accent pageheader" }, [
307
  $h->h1 ($pageTitle),
308
  $h->div ({ class=>"sp0" }, [
309
    $h->div ({ class=>"spLeft" }, [
310
      $radiobutton
311
    ]),
312
    $h->div ({ class=>"spRight" }, [
313
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
314
      $refreshbutton
315
    ]),
316
  ]),
317
]);
318
 
319
# Print the Hidden fields' check boxes (if there are any)
320
 
321
my $c = 1;
322
my @hiddencheckboxes;
323
my @hiddenrows;
324
foreach my $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
325
  if ($FORM{autoload}) {
326
    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} ]);
327
  } else {
328
    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} ]);
329
  }
330
  if ($c++ % 4 == 0) {
331
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
332
    @hiddencheckboxes = [];
333
  }
334
}
335
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
336
 
337
 
338
if (scalar @hideFields) {
339
  my @topleft;
340
  push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
341
  push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
342
 
343
  print $h->div ({ class=>"sp0" }, [
344
    $h->div ({ class=>"spLeft"  }, [ @topleft ]),
345
    $h->div ({ class=>"spRight" }, [
346
      $signedOnAs, $h->br,
347
      "Show my classes: ", $SIChecked, $h->br,
348
      $h->input ({ type=>"button", value=>"Block Personal Time", onClick=>"window.location.href='manage_personal_time.pl'" }),
349
    ])
350
  ]);
351
}
352
 
353
# Print the main table...............................................
354
 
355
print $h->open ('div', { class=>'rTable' });
356
 
357
my @tmptitlerow;
358
foreach my $f (@displayFields)	{  # Print the Column headings
359
  if (inArray ($f, \@staticFields)) {
360
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
361
  } else {
362
    if ($FORM{autoload}) {
363
      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} ]);
364
    } else {
365
      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} ]);
366
    }
367
  }
368
}
369
 
370
# Print the filter boxes...
371
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ map { $h->div ({ class=>'rTableCell filters' }, filter ($_)) } @displayFields ], $h->div ({ class=>"rTableCell" }));
372
 
373
if ($FORM{shiftinclude}) {  # Include all of the user's shifts at the top
374
  foreach my $t (@shifts)	{
375
	  print $h->div ({ class=>'rTableRow highlighted' }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_}) } @displayFields ]);
376
  }
377
  print $h->hr ({ width=>"500%" });
378
}
379
 
380
# Print the things
381
foreach my $t (@ProductList)	{
382
  my @display = map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_}) } @displayFields;
383
  if ($t->{signedup}) {
384
	  print $h->div ({ class=>'rTableRow highlighted' }, [ @display ]);
385
  } else {
386
	  print $h->div ({ class=>'rTableRow shaded' }, [ @display ]);
387
  }
388
}
389
 
390
 
391
 
392
 
393
print $h->close ('div');
394
 
395
# close things out................................................
396
 
397
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
398
if ($curpage > $pages) { $curpage = $pages; }
399
 
400
my @pagerange;
401
if ($pages <= 5 ) {
402
  @pagerange = 1 .. $pages;
403
} else {
404
  if ($curpage <= 3) {
405
    @pagerange = (1, 2, 3, 4, ">>");
406
  } elsif ($curpage >= $pages - 2) {
407
    @pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
408
  } else {
409
    @pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
410
  }
411
}
412
 
413
my @excelcode;
414
push @excelcode, $h->br;
415
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.]");
416
 
417
 
418
print $h->br; # print $h->br;
419
print $h->div ({ class=>"sp0" }, [
420
    $h->div ({ class=>"spLeft" }, [
421
      $h->div ({ class=>"footer" }, [
422
        "To bookmark, save, or send this exact view, use the ",
423
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
424
        $h->br,
425
        "If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
426
        @excelcode,
427
        $h->br,
428
        "This page was displayed on ", currentTime (),
429
        $h->br,
430
        "Please direct questions, problems, and concerns to Officials.RollerCon.Schedule\@gmail.com",
431
#        $h->br,
432
#        "Displaying: ", $h->select ({ name=>"year", onchange=>"Req.submit();" }, [ @yearoptions ])
433
      ])
434
    ]),
435
    $h->div ({ class=>"spRight" }, [
436
      $h->h5 ([
437
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,
438
               "Sorted by ", $sortby, $h->br,
439
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
440
               ( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
441
                                                $_ eq "<<"     ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
442
                                                $_ eq ">>"     ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
443
                                                                 $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
444
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
445
      ])
446
    ]),
447
]);
448
 
449
#print $h->br; # print $h->br;
450
#print $h->h5 ("$x Record(s) Displayed");
451
#print $h->div ({ class=>"footer" }, [
452
#  "To bookmark, save, or send this exact view, use the ",
453
#  $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
454
#  $h->br,
455
#  "This page was displayed on $now",
456
#  $h->br,
457
#  "Please direct questions, problems, and concerns to noone\@gmail.com"
458
#]);
459
 
460
 
461
print $h->close('form');
462
print $h->close('html');