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