Subversion Repositories ORC

Rev

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