Subversion Repositories VORC

Rev

Rev 121 | Rev 196 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
56 bgadell 1
#!/usr/bin/perl
2
 
3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
close STDERR;
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";
8
 
9
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
10
 
11
#use strict;
12
use cPanelUserConfig;
13
use CGI qw/param cookie header start_html url/;
14
use HTML::Tiny;
15
use tableViewer;
16
use RollerCon;
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};
23
my $username = $h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$user->{RCid}" }, $user->{derby_name});
24
my $RCid = $user->{RCid};
25
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
26
#my $YEAR = 1900 + (localtime)[5];
27
 
28
 
29
my $pageTitle = "VORC System Settings";
30
my $prefscookie = "viewsettings";
31
our $DBTABLE = 'setting';
32
my %COLUMNS = (
33
# 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         )],
37
);
38
my $stylesheet = "/style.css";
39
my $homeURL = '/schedule/';
40
my @pagelimitoptions = ("All", 5, 10, 25);
41
 
42
my @whereClause;
43
 
44
# If we need to modify line item values, create a subroutine named "modify_$columnname"
45
#    It will receive a hashref to the object lineitem
46
 
47
sub modify_key {
48
  my $hr = shift;
49
  return join "&nbsp;",
50
         $h->a ({ href=>"view_setting.pl?setting.key=$hr->{'key'}&choice=Update", onClick=>$clicky }, "[Edit]"),
51
         $h->a ({ href=>"view_setting.pl?setting.key=$hr->{'key'}&choice=Copy" }, "[Copy]"),
52
         $h->a ({ href=>"view_setting.pl?setting.key=$hr->{'key'}&choice=Delete", onClick=>"event.stopPropagation(); if (confirm('Are you sure you want to DELETE this setting?')==true) {return true;} else {return false;}" }, "[Delete]"),
53
         $hr->{key}
54
  ;
55
};
56
 
57
sub modify_time {
58
  my $t = shift;
59
  return convertTime $t->{time};
60
}
61
 
62
sub modify_start_time {
63
  my $t = shift;
64
  return convertTime $t->{start_time};
65
}
66
 
67
sub modify_end_time {
68
  my $t = shift;
69
  return convertTime $t->{end_time};
70
}
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;
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
 
138 - 164
my $signedOnAs = $username ? "Welcome, $username. ".$h->a ({ href=>"index.pl?LOGOUT" }, "[Log Out]") : "You are not signed in.";
56 bgadell 165
 
166
# Set some cookie stuff...
65 bgadell 167
my $path = `dirname $ENV{SCRIPT_NAME}`; chomp $path; $path .= '/' unless $path eq "/";
56 bgadell 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"; }
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) {
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} ]);
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;
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' });
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} ]);
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,
65 bgadell 332
        "Please direct questions, problems, and concerns to $SYSTEM_EMAIL",
56 bgadell 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
 
362
 
363
print $h->close('form');
364
print $h->close('html');