Subversion Repositories VORC

Rev

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