Subversion Repositories VORC

Rev

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

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