Subversion Repositories ORC

Rev

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