Subversion Repositories ORC

Rev

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