Subversion Repositories ORC

Rev

Details | Last modification | View Log | RSS feed

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