Subversion Repositories VORC

Rev

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