Subversion Repositories ORC

Rev

Rev 26 | Details | Compare with Previous | Last modification | View Log | RSS feed

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