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