Subversion Repositories VORC

Rev

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

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