Subversion Repositories VORC

Rev

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