Subversion Repositories ORC

Rev

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