Subversion Repositories ORC

Rev

Details | Last modification | View Log | RSS feed

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