Subversion Repositories VORC

Rev

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

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