Subversion Repositories ORC

Rev

Rev 8 | Go to most recent revision | Details | 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;
6
use CGI qw/param cookie header start_html url/;
7
use HTML::Tiny;
8
use tableViewer;
9
use RollerCon;
10
our $h = HTML::Tiny->new( mode => 'html' );
11
 
12
my $cookie_string = authenticate (3) || 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});
16
my $RCid = $user->{RCid};
17
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
18
my $YEAR;
19
 
20
 
21
my $pageTitle = "Dev Log Viewer";
22
my $prefscookie = "logscookie";
23
our $DBTABLE = 'v_log';
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
 
39
# Set any custom "where" DB filters here...
40
my @whereClause;
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
 
46
 
47
 
48
 
49
 
50
# Ideally, nothing below this comment needs to change
51
#-------------------------------------------------------------------------------
52
 
53
 
54
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
55
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
56
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
57
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
58
our @defaultFields     = sort byfield grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
59
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
60
 
61
our @allFields = sort byfield keys %NAME;
62
our @displayFields = ();
63
our @hideFields = ();
64
my $QUERY_STRING;
65
 
66
my $pagelimit = param ("limit") // $pagelimitoptions[$#pagelimitoptions];
67
my $curpage = param ("page") // 1;
68
 
69
our %FORM;
70
my $FILTER;
71
foreach (param()) {
72
 	if (/^year$/) { #
73
		$YEAR = param($_);
74
		next;
75
	}
76
 
77
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
78
 
79
	if ((/^filter/) and ($FORM{$_} ne '')) {	# Build a set of filters to apply
80
		my ($filter,$field) = split /-/, $_;
81
		$FILTER->{$field} = $FORM{$_};
82
	}	elsif ($FORM{$_} eq "true")			# Compile list of fields to display
83
		{ push @displayFields, $_; }
84
}
85
 
86
 
87
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
88
							                    #  	build the data for the cookie that remembers the page setup
89
	my $disFields = join ":", @displayFields;
90
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
91
 
92
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
93
}
94
 
95
 
96
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
97
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
98
		my ($disF, $filts, $sb, $al) = split /&/,$prefs;
99
		@displayFields = split /:/,$disF;
100
 
101
		foreach my $pair (split /:/, $filts)	{
102
			my ($key, $value) = split /=/, $pair;
103
			$FORM{"filter-$key"} = $value;
104
			$FILTER->{$key} = $value;
105
		}
106
 
107
		$FORM{sortby} = $sb;
108
		$FORM{autoload} = $al;
109
		$QUERY_STRING = $prefs;
110
	}	else {
111
	  @displayFields = @defaultFields; # Otherwise suppply a default list of columns.
112
	  $FORM{autoload} = 1;             # And turn aut0load on by default.
113
	}
114
}
115
 
116
# let's just make sure the columns are in the right order (and there aren't any missing)
117
@displayFields = sort byfield uniq @displayFields, @staticFields;
118
 
119
# If the field isn't in the displayFields list,	then add it to the hideFields list
120
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
121
 
122
# Process any filters provided in the form to pass to the database
123
push @whereClause, map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
124
#push @whereClause, "year(date) = '$YEAR'";
125
 
126
 
127
							#  Given the fields to display and the where conditions,
128
							#	  "getData" will return a reference to an array of
129
							#	  hash references of the results.
130
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
131
my @ProductList = @{ $data };
132
 
133
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
134
my $x = scalar @ProductList; # How many results were returned?
135
 
136
# If the user is trying to download the Excel file, send it to them and then exit out.
137
if ($FORM{excel}) {
138
  exportExcel (\@ProductList, "RC_Officiating_Shifts");
139
  exit;
140
}
141
 
142
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.";
143
 
144
# Set some cookie stuff...
145
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/' unless $path eq "/";
146
my $queryCookie = cookie(-NAME=>$prefscookie,
147
			-VALUE=>"$QUERY_STRING",
148
			-PATH=>"$path",
149
			-EXPIRES=>'+365d');
150
 
151
# Print the header
152
print header (-cookie=> [ $queryCookie, $RCAUTH_cookie ] );
153
 
154
# 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
155
#	print "I'm catching updates!!!\n\n";
156
#	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
157
# 		{ print "\t$key:  $FORM{$key}\n"; }
158
# 	print "--> \n\n";
159
#
160
#
161
# 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
162
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
163
# 		{ print "\t$key:  $ENV{$key}\n"; }
164
# 	print "--> \n\n";
165
#
166
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
167
 
168
 
169
#------------------
170
 
171
# Toggle the autoload fields within the table elements
172
our ($onClick, $onChange);   # (also used in scanFunctions)
173
my ($radiobutton, $refreshbutton, $sortby);
174
if ($FORM{autoload}) {
175
	$onClick = "onClick='submit();'";
176
	$onChange = "onChange='page.value = 1; submit();'";
177
  $radiobutton = $h->div ({ class=>'autoload' },
178
    ["Autoload Changes: ",
179
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
180
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
181
    ]);
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 = "onChange='page.value = 1;'";
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
    ]);
191
  $refreshbutton = $h->input ({ type=>"button", value=>"Apply Changes", onClick=>"submit(); return false;" });
192
  $sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
193
}
194
 
195
 
196
 
197
 
198
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
199
 
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
]);
214
 
215
# Print the Hidden fields' check boxes (if there are any)
216
 
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;
232
 
233
 
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
}
246
 
247
# Print the main table...............................................
248
 
249
print $h->open ('div', { class=>'rTable' });
250
 
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
}
263
 
264
# Print the filter boxes...
265
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ map { $h->div ({ class=>'rTableCell filters' }, filter ($_)) } @displayFields ], $h->div ({ class=>"rTableCell" }));
266
 
267
# Print the things
268
foreach my $t (@ProductList)	{
269
  print $h->div ({ class=>'rTableRow shaded' }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_}) } @displayFields ]);
270
}
271
 
272
 
273
 
274
 
275
print $h->close ('div');
276
 
277
# close things out................................................
278
 
279
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
280
if ($curpage > $pages) { $curpage = $pages; }
281
 
282
my @pagerange;
283
if ($pages <= 5 ) {
284
  @pagerange = 1 .. $pages;
285
} else {
286
  if ($curpage <= 3) {
287
    @pagerange = (1, 2, 3, 4, ">>");
288
  } elsif ($curpage >= $pages - 2) {
289
    @pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
290
  } else {
291
    @pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
292
  }
293
}
294
 
295
print $h->br; # print $h->br;
296
print $h->div ({ class=>"sp0" }, [
297
    $h->div ({ class=>"spLeft" }, [
298
      $h->div ({ class=>"footer" }, [
299
        "To bookmark, save, or send this exact view, use the ",
300
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
301
        $h->br,
302
        "If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
303
        $h->br,
304
        $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.]"),
305
        $h->br,
306
        "This page was displayed on ", currentTime (),
307
        $h->br,
308
        "Please direct questions, problems, and concerns to noone\@gmail.com"
309
      ])
310
    ]),
311
    $h->div ({ class=>"spRight" }, [
312
      $h->h5 ([
313
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,
314
               "Sorted by ", $sortby, $h->br,
315
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
316
               ( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
317
                                                $_ eq "<<"     ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
318
                                                $_ eq ">>"     ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
319
                                                                 $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
320
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
321
      ])
322
    ]),
323
]);
324
 
325
#print $h->br; # print $h->br;
326
#print $h->h5 ("$x Record(s) Displayed");
327
#print $h->div ({ class=>"footer" }, [
328
#  "To bookmark, save, or send this exact view, use the ",
329
#  $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
330
#  $h->br,
331
#  "This page was displayed on $now",
332
#  $h->br,
333
#  "Please direct questions, problems, and concerns to noone\@gmail.com"
334
#]);
335
 
336
 
337
print $h->close('form');
338
print $h->close('html');