Subversion Repositories VORC

Rev

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

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