Subversion Repositories VORC

Rev

Rev 138 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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