Subversion Repositories ORC

Rev

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