Subversion Repositories VORC

Rev

Rev 138 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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