Subversion Repositories VORC

Rev

Rev 48 | Rev 65 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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