Subversion Repositories VORC

Rev

Details | Last modification | View Log | RSS feed

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