Subversion Repositories VORC

Rev

Rev 138 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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