| 50 |
bgadell |
1 |
#package tableViewer;
|
|
|
2 |
|
| 7 |
- |
3 |
#######################################################################
|
|
|
4 |
# A set of functions to assist the scan data display tool.
|
| 196 |
- |
5 |
# Kept here to unclutter the main script.
|
| 7 |
- |
6 |
#######################################################################
|
|
|
7 |
#
|
|
|
8 |
#
|
|
|
9 |
# $Log: scanFunctions.pm,v $
|
|
|
10 |
#
|
|
|
11 |
|
| 50 |
bgadell |
12 |
#use strict;
|
|
|
13 |
use Exporter 'import';
|
| 9 |
- |
14 |
use cPanelUserConfig;
|
| 7 |
- |
15 |
use DBI ();
|
|
|
16 |
use WebDB;
|
|
|
17 |
|
| 196 |
- |
18 |
our @EXPORT = qw( byfield currentTime exportExcel fetchColEntries fetchDerbyNameWithRCid filter getData getDBConnection inArray notInArray uniq whereInArray printTablePage );
|
| 50 |
bgadell |
19 |
|
| 153 |
- |
20 |
my $internalDBH = WebDB::connect () || die "Unable to connect to Database\n\n";
|
| 7 |
- |
21 |
|
|
|
22 |
sub currentTime {
|
| 25 |
- |
23 |
use DateTime;
|
|
|
24 |
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
|
|
|
25 |
$now =~ s/T/ at /;
|
| 7 |
- |
26 |
|
| 25 |
- |
27 |
return $now." US/Pacific";
|
| 7 |
- |
28 |
}
|
|
|
29 |
|
| 196 |
- |
30 |
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b}; }
|
| 7 |
- |
31 |
|
|
|
32 |
sub exportExcel {
|
|
|
33 |
my $listref = shift;
|
| 196 |
- |
34 |
my $FN_Prefix = shift // "VORC_Export";
|
| 218 |
- |
35 |
my $displayFields = shift // "";
|
| 7 |
- |
36 |
|
|
|
37 |
use Spreadsheet::WriteExcel;
|
| 196 |
- |
38 |
|
|
|
39 |
my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
|
| 7 |
- |
40 |
my $filename = "${FN_Prefix}_${date}_$$.xls";
|
|
|
41 |
|
| 196 |
- |
42 |
print "Content-type: application/vnd.ms-excel\n";
|
| 7 |
- |
43 |
# The Content-Disposition will generate a prompt to save the file. If you want
|
|
|
44 |
# to stream the file to the browser, comment out the following line.
|
|
|
45 |
print "Content-Disposition: attachment; filename=$filename\n";
|
|
|
46 |
print "\n";
|
| 196 |
- |
47 |
|
| 7 |
- |
48 |
# Create a new workbook and add a worksheet. The special Perl filehandle - will
|
|
|
49 |
# redirect the output to STDOUT
|
|
|
50 |
#
|
|
|
51 |
my $workbook = Spreadsheet::WriteExcel->new(\*STDOUT);
|
|
|
52 |
my $worksheet = $workbook->add_worksheet();
|
| 196 |
- |
53 |
|
|
|
54 |
my $format = $workbook->add_format();
|
|
|
55 |
$format->set_bold();
|
|
|
56 |
|
|
|
57 |
my $col = $row = 0;
|
|
|
58 |
|
| 218 |
- |
59 |
foreach $f (@$displayFields)
|
| 196 |
- |
60 |
{ $worksheet->write($row, $col++, "$NAME{$f}", $format); }
|
|
|
61 |
|
|
|
62 |
foreach $t (sort @{ $listref }) # Unt now we print the tickets!
|
|
|
63 |
{
|
|
|
64 |
$col = 0;
|
|
|
65 |
$row++;
|
| 218 |
- |
66 |
foreach $f (@$displayFields) {
|
| 196 |
- |
67 |
if ($f eq "derby_name") {
|
|
|
68 |
if ($user->{department}->{"OFF"} < 2 and $t->{derby_name} and $t->{RCid} != $RCid and $LVL < 5) {
|
|
|
69 |
$t->{derby_name} = "FILLED";
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
$t->{$f} =~ s/<br>/\n/ig; $worksheet->write($row, $col++, "$t->{$f}");
|
|
|
73 |
}
|
|
|
74 |
}
|
|
|
75 |
|
|
|
76 |
$workbook->close();
|
| 7 |
- |
77 |
return;
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
|
| 196 |
- |
81 |
sub fetchColEntries {
|
|
|
82 |
my $colName = shift;
|
|
|
83 |
my $selection = shift;
|
| 197 |
- |
84 |
my $year = shift // "year(now())";
|
| 196 |
- |
85 |
my $table = $DBTABLE;
|
|
|
86 |
my $optionList = "";
|
| 7 |
- |
87 |
|
|
|
88 |
if ($colName eq "derby_name" and $LVL < 2) {
|
|
|
89 |
# special case to anonymize assignees...
|
| 122 |
- |
90 |
my @opts = ("-blank-", $ORCUSER->{derby_name});
|
|
|
91 |
push @opts, map { @{$_} } @{ $internalDBH->selectall_arrayref ("select derby_name from official where showme = 1 and derby_name <> ? order by derby_name", undef, $ORCUSER->{derby_name}) };
|
|
|
92 |
$optionList = join "", map { $selection eq $_ ? "<OPTION selected>$_</OPTION>" : "<OPTION>$_</OPTION>" } @opts;
|
| 7 |
- |
93 |
} else {
|
| 197 |
- |
94 |
my $dept_where = $table eq "v_shift" ? "where dept != 'PER' and year(date) = $year" : "";
|
| 46 |
- |
95 |
my $orderby = $colName eq "dayofweek" ? "field(dayofweek, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')" : $colName;
|
| 196 |
- |
96 |
my $cathan = $internalDBH->prepare("select distinct nullif($colName, '') from $table $dept_where order by $orderby");
|
|
|
97 |
|
|
|
98 |
$cathan->execute();
|
|
|
99 |
while (my ($cat) = $cathan->fetchrow) {
|
|
|
100 |
if (!$cat) { $cat = "-blank-"; }
|
|
|
101 |
if ($cat eq $selection) {
|
|
|
102 |
$optionList .= "<OPTION selected>$cat</OPTION>";
|
|
|
103 |
} else {
|
|
|
104 |
$optionList .= "<OPTION>$cat</OPTION>";
|
|
|
105 |
}
|
|
|
106 |
}
|
| 7 |
- |
107 |
}
|
|
|
108 |
|
| 196 |
- |
109 |
return $optionList;
|
| 7 |
- |
110 |
}
|
|
|
111 |
|
|
|
112 |
sub fetchDerbyNameWithRCid {
|
| 97 |
bgadell |
113 |
my $ATTRIBUTES;
|
|
|
114 |
if (ref $_[0] eq "HASH") {
|
|
|
115 |
$ATTRIBUTES = shift;
|
|
|
116 |
}
|
| 7 |
- |
117 |
my $DEPT = shift // "";
|
| 57 |
bgadell |
118 |
my $selected = shift // "";
|
| 196 |
- |
119 |
my $optionList = "";
|
|
|
120 |
|
|
|
121 |
my $cathan;
|
|
|
122 |
if (!$DEPT or $DEPT eq "CMP") {
|
|
|
123 |
$cathan = $internalDBH->prepare("select RCid, derby_name from official where access > 0 order by derby_name");
|
|
|
124 |
$cathan->execute();
|
| 57 |
bgadell |
125 |
} elsif ($DEPT eq "CLA") {
|
| 97 |
bgadell |
126 |
$cathan = $internalDBH->prepare("select RCid, derby_name from v_official where access > 0 and isnull(MVPid) = false and last_login > CURRENT_DATE - INTERVAL 365 DAY order by derby_name");
|
| 57 |
bgadell |
127 |
$cathan->execute;
|
| 217 |
- |
128 |
} elsif ($DEPT eq "EMT") {
|
|
|
129 |
$cathan = $internalDBH->prepare("select RCid, derby_name from v_official where access > 0 and emt_verified = true and last_login > CURRENT_DATE - INTERVAL 365 DAY order by derby_name");
|
|
|
130 |
$cathan->execute;
|
| 196 |
- |
131 |
} else {
|
| 97 |
bgadell |
132 |
$cathan = $internalDBH->prepare("select RCid, derby_name from official where access > 0 and (department like ? and department not like ?) and last_login > CURRENT_DATE - INTERVAL 365 DAY order by derby_name");
|
| 16 |
- |
133 |
$cathan->execute("%".$DEPT."%", "%".$DEPT."-0%");
|
| 196 |
- |
134 |
}
|
| 97 |
bgadell |
135 |
|
|
|
136 |
my $valuelabel = $ATTRIBUTES->{DATALIST} ? "data-value" : "value";
|
| 196 |
- |
137 |
while (my ($id, $cat) = $cathan->fetchrow) {
|
|
|
138 |
if ($id == $selected) {
|
|
|
139 |
$optionList .= "<OPTION $valuelabel=$id selected>$cat</OPTION>";
|
|
|
140 |
} else {
|
|
|
141 |
$optionList .= "<OPTION $valuelabel=$id>$cat</OPTION>";
|
|
|
142 |
}
|
|
|
143 |
}
|
| 7 |
- |
144 |
|
| 196 |
- |
145 |
return $optionList;
|
| 7 |
- |
146 |
}
|
|
|
147 |
|
|
|
148 |
|
|
|
149 |
sub filter {
|
| 196 |
- |
150 |
my $colName = shift;
|
|
|
151 |
my $filter = shift;
|
| 197 |
- |
152 |
my $year = shift;
|
| 196 |
- |
153 |
|
|
|
154 |
if (exists &{"filter_".$colName}) { return &{"filter_".$colName} ($colName, $filter); }
|
|
|
155 |
|
|
|
156 |
if ($colFilterTypeHash{$colName} eq 'select')
|
|
|
157 |
{
|
|
|
158 |
if (defined $filter) {
|
|
|
159 |
if ($filter eq "-blank-") {
|
|
|
160 |
return "($colName = '' or isNull($colName) = 1)";
|
|
|
161 |
}
|
|
|
162 |
# $filter = s/'/\'/g;
|
|
|
163 |
return "$colName = \"$filter\"";
|
|
|
164 |
}
|
|
|
165 |
else
|
|
|
166 |
{
|
|
|
167 |
my $thing = "filter-${colName}";
|
| 197 |
- |
168 |
my $categories = $year ? fetchColEntries ($colName, $FORM{$thing}, $year) : fetchColEntries ($colName, $FORM{$thing});
|
| 196 |
- |
169 |
my $Options = "<OPTION></OPTION>".$categories;
|
| 7 |
- |
170 |
|
| 196 |
- |
171 |
$Options =~ s/>($FORM{$thing})/ selected>$1/;
|
|
|
172 |
return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
|
|
|
173 |
}
|
|
|
174 |
} elsif ($colFilterTypeHash{$colName} eq 'text') {
|
|
|
175 |
if (defined $filter)
|
|
|
176 |
{
|
|
|
177 |
if ($filter =~ /\d{1,2}:\d{2}/ and $ORCUSER->{timeformat} eq "ampm") {
|
|
|
178 |
my ($h, $m) = split /:/, $filter;
|
|
|
179 |
my $caret;
|
|
|
180 |
if ($h =~ s/^\^\s*//) { $caret = "^"; }
|
|
|
181 |
if ($h < 8) { $h += 12; }
|
|
|
182 |
$filter = $caret.join ":", $h, $m;
|
|
|
183 |
}
|
|
|
184 |
|
|
|
185 |
if ($filter =~ s/^=\s*//) { return "$colName = \"$filter\""; }
|
|
|
186 |
|
|
|
187 |
if ($filter !~ s/^\^\s*//) { $filter = "\%$filter"; }
|
|
|
188 |
if ($filter !~ s/\s*\$$//) { $filter = "$filter\%"; }
|
|
|
189 |
$filter =~ s/\*/%/g;
|
|
|
190 |
|
|
|
191 |
return "$colName like \"$filter\"";
|
|
|
192 |
}
|
|
|
193 |
else
|
|
|
194 |
{
|
|
|
195 |
my $thing = "filter-${colName}";
|
|
|
196 |
return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
|
|
|
197 |
}
|
|
|
198 |
} elsif ($colFilterTypeHash{$colName} eq 'number') {
|
|
|
199 |
if (defined $filter)
|
|
|
200 |
{
|
|
|
201 |
if ($filter =~ /^[>=<]\s*/) { return "$colName $filter"; }
|
|
|
202 |
else { return "$colName = $filter"; }
|
|
|
203 |
}
|
|
|
204 |
else
|
|
|
205 |
{
|
|
|
206 |
my $thing = "filter-${colName}";
|
|
|
207 |
return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=2 $onChange>";
|
|
|
208 |
}
|
|
|
209 |
} elsif ($colFilterTypeHash{$colName} eq 'date') {
|
|
|
210 |
if (defined $filter)
|
|
|
211 |
{
|
|
|
212 |
if ($filter =~ s/^<\s*//) { return "$colName < '$filter'"; }
|
|
|
213 |
if ($filter =~ s/^>\s*//) { return "$colName > '$filter'"; }
|
|
|
214 |
|
|
|
215 |
return "$colName = '$filter'";
|
|
|
216 |
}
|
|
|
217 |
else
|
|
|
218 |
{
|
|
|
219 |
my $thing = "filter-${colName}";
|
|
|
220 |
return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
|
|
|
221 |
}
|
|
|
222 |
} elsif ($colFilterTypeHash{$colName} eq 'boolean') {
|
|
|
223 |
if (defined $filter)
|
|
|
224 |
{
|
|
|
225 |
return "$colName = $filter";
|
|
|
226 |
}
|
|
|
227 |
else
|
|
|
228 |
{
|
|
|
229 |
my $thing = "filter-${colName}";
|
|
|
230 |
my $Options = "<OPTION></OPTION><OPTION>True</OPTION><OPTION>False</OPTION>";
|
|
|
231 |
|
|
|
232 |
$Options =~ s/>($FORM{$thing})/ selected>$1/;
|
|
|
233 |
return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
|
|
|
234 |
}
|
|
|
235 |
} elsif ($colFilterTypeHash{$colName} eq 'ERROR') {
|
|
|
236 |
return "<center><strong><font color=red>ERROR!</font>";
|
|
|
237 |
} elsif ($colFilterTypeHash{$colName} eq 'none') {
|
|
|
238 |
return;
|
|
|
239 |
}
|
| 7 |
- |
240 |
}
|
|
|
241 |
|
|
|
242 |
|
|
|
243 |
sub getData {
|
| 196 |
- |
244 |
my $fields = shift;
|
|
|
245 |
my $whereClause = shift;
|
|
|
246 |
my $table = shift;
|
|
|
247 |
my $orderby = shift;
|
|
|
248 |
my $curpage = shift; $curpage = 1 unless $curpage;
|
|
|
249 |
my $pagelimit = shift // "All";
|
| 7 |
- |
250 |
|
| 196 |
- |
251 |
my $selected = '*';
|
| 208 |
- |
252 |
if ($table eq "v_class_new") {
|
| 199 |
- |
253 |
foreach (@{$whereClause}) {
|
| 208 |
- |
254 |
/^RCid = \d+$/ and $table = "v_class_signup_new";
|
| 199 |
- |
255 |
}
|
|
|
256 |
|
|
|
257 |
}
|
| 196 |
- |
258 |
$whereClause = scalar @{$whereClause} > 0 ? "where ".join (" and ", @{$whereClause}) : '';
|
|
|
259 |
|
| 7 |
- |
260 |
if ($orderby eq "dayofweek") {
|
| 196 |
- |
261 |
$orderby = "order by date, time";
|
| 7 |
- |
262 |
} elsif ($orderby eq "eventid") { # only applicable to the log viewer...
|
| 196 |
- |
263 |
$orderby = "order by eventid desc";
|
|
|
264 |
} elsif ($orderby eq "key") { # for the settings page, the column name 'key' is a reserved word in mysql
|
|
|
265 |
$orderby = "order by ${table}.key";
|
| 7 |
- |
266 |
} else {
|
| 196 |
- |
267 |
$orderby = $orderby eq "" ? "" : "order by $orderby";
|
| 7 |
- |
268 |
}
|
|
|
269 |
|
|
|
270 |
my $getMe;
|
|
|
271 |
if ($pagelimit eq "All") {
|
| 196 |
- |
272 |
$getMe = "select distinct * from $table $whereClause $orderby";
|
| 7 |
- |
273 |
} else {
|
|
|
274 |
$curpage = ($curpage - 1) * $pagelimit;
|
| 196 |
- |
275 |
$getMe = "select distinct * from $table $whereClause $orderby limit $curpage, $pagelimit";
|
| 7 |
- |
276 |
}
|
| 196 |
- |
277 |
my ($totalcount) = @{$internalDBH->selectrow_arrayref ("select distinct count(*) from $table $whereClause")};
|
| 199 |
- |
278 |
# warn $getMe;
|
| 196 |
- |
279 |
my $limhan = $internalDBH->prepare($getMe); # Get the tickets from the DB
|
|
|
280 |
$limhan->execute();
|
|
|
281 |
|
|
|
282 |
my @results = ();
|
|
|
283 |
while (my $P = $limhan->fetchrow_hashref)
|
|
|
284 |
{
|
|
|
285 |
push @results, $P;
|
|
|
286 |
}
|
|
|
287 |
|
|
|
288 |
return (\@results, $totalcount);
|
| 7 |
- |
289 |
}
|
|
|
290 |
|
|
|
291 |
|
|
|
292 |
sub getDBConnection {
|
|
|
293 |
use WebDB;
|
|
|
294 |
$dbh = WebDB::connect ();
|
|
|
295 |
return $dbh;
|
|
|
296 |
}
|
|
|
297 |
|
|
|
298 |
|
|
|
299 |
sub inArray {
|
| 196 |
- |
300 |
my $item = shift;
|
|
|
301 |
my $array = shift;
|
|
|
302 |
foreach (@{$array})
|
|
|
303 |
{
|
|
|
304 |
return 1 if $item eq $_;
|
|
|
305 |
}
|
|
|
306 |
return 0;
|
| 7 |
- |
307 |
}
|
|
|
308 |
|
|
|
309 |
sub notInArray {
|
| 196 |
- |
310 |
return ! inArray (@_);
|
| 7 |
- |
311 |
}
|
|
|
312 |
|
|
|
313 |
|
|
|
314 |
sub uniq (@) {
|
|
|
315 |
# From CPAN List::MoreUtils, version 0.22
|
|
|
316 |
my %h;
|
|
|
317 |
map { $h{$_}++ == 0 ? $_ : () } @_;
|
|
|
318 |
}
|
|
|
319 |
|
|
|
320 |
|
|
|
321 |
sub whereInArray {
|
| 196 |
- |
322 |
my $item = shift;
|
|
|
323 |
my $array = shift;
|
|
|
324 |
my $i = 0;
|
|
|
325 |
foreach (@{$array})
|
|
|
326 |
{
|
|
|
327 |
return $i if $item eq $_;
|
|
|
328 |
$i++;
|
|
|
329 |
}
|
|
|
330 |
return -1;
|
| 7 |
- |
331 |
}
|
|
|
332 |
|
| 196 |
- |
333 |
sub printTablePage {
|
|
|
334 |
my $paramhash = shift;
|
|
|
335 |
my $RCAUTH_cookie = $paramhash->{RCAuth} // "";
|
|
|
336 |
my $pageTitle = $paramhash->{Title};
|
|
|
337 |
my $prefscookie = $paramhash->{Prefs} // "";
|
|
|
338 |
($prefscookie = lc $pageTitle) =~ s/\s+//g unless $prefscookie;
|
|
|
339 |
my $DBTABLE = $paramhash->{Table};
|
|
|
340 |
my $COLUMNS = $paramhash->{Columns};
|
|
|
341 |
my $defaultWhereClause = $paramhash->{Where} // "";
|
|
|
342 |
my $displayYearSelect = $paramhash->{DisplayYearSelect} // 1;
|
|
|
343 |
my $showMyShiftsOption = $paramhash->{ShowMyShifts} // 0;
|
|
|
344 |
my $highlightShifts = $paramhash->{HighlightShifts} // 0;
|
|
|
345 |
my $headerButton = $paramhash->{HeaderButton} // "";
|
|
|
346 |
my $blockPersonalTime = $paramhash->{PersonalTimeButton} // "";
|
|
|
347 |
|
| 229 |
- |
348 |
use CGI qw/param cookie header start_html url url_param/;
|
| 196 |
- |
349 |
use HTML::Tiny;
|
|
|
350 |
my $h = HTML::Tiny->new( mode => 'html' );
|
|
|
351 |
|
|
|
352 |
my $stylesheet = "/style.css";
|
|
|
353 |
my $homeURL = '/schedule/';
|
|
|
354 |
my @pagelimitoptions = ("All", 5, 10, 25);
|
|
|
355 |
my $YEAR;
|
|
|
356 |
|
|
|
357 |
# Extract the column names and build utility variables
|
|
|
358 |
my %NAME = map { $_ => $COLUMNS->{$_}->[0] } keys %{$COLUMNS};
|
|
|
359 |
my %colOrderHash = map { $_ => $COLUMNS->{$_}->[1] } keys %{$COLUMNS};
|
|
|
360 |
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b}; }
|
|
|
361 |
our %colFilterTypeHash = map { $_ => $COLUMNS->{$_}->[2] } keys %{$COLUMNS};
|
|
|
362 |
my @staticFields = sort byfield grep { $COLUMNS->{$_}->[3] and $COLUMNS->{$_}->[3] eq 'static' } keys %{$COLUMNS};
|
|
|
363 |
my @defaultFields = sort byfield grep { defined $COLUMNS->{$_}->[3] } keys %{$COLUMNS};
|
|
|
364 |
|
|
|
365 |
my @allFields = sort byfield keys %NAME;
|
|
|
366 |
my @displayFields = ();
|
|
|
367 |
my @hideFields = ();
|
|
|
368 |
my $QUERY_STRING;
|
|
|
369 |
|
|
|
370 |
my $pagelimit = param ("limit") // $pagelimitoptions[$#pagelimitoptions];
|
|
|
371 |
my $curpage = param ("page") // 1;
|
|
|
372 |
|
|
|
373 |
our %FORM;
|
|
|
374 |
my $FILTER;
|
|
|
375 |
foreach (param()) {
|
|
|
376 |
if (/^year$/) {
|
|
|
377 |
$YEAR = param($_);
|
|
|
378 |
next;
|
|
|
379 |
}
|
|
|
380 |
|
|
|
381 |
$FORM{$_} = param($_); # Retrieve all of the FORM data submitted
|
|
|
382 |
#warn "$_: $FORM{$_}";
|
|
|
383 |
|
|
|
384 |
if ((/^filter/) and ($FORM{$_} ne '')) { # Build a set of filters to apply
|
|
|
385 |
my ($filter,$field) = split /-/, $_;
|
|
|
386 |
$FILTER->{$field} = $FORM{$_} unless notInArray ($field, \@allFields);
|
|
|
387 |
} elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
388 |
{ push @displayFields, $_ unless /shiftinclude/; }
|
|
|
389 |
}
|
| 229 |
- |
390 |
|
|
|
391 |
foreach (url_param()) {
|
|
|
392 |
if (/^year$/) {
|
|
|
393 |
$YEAR = url_param($_);
|
|
|
394 |
next;
|
|
|
395 |
}
|
|
|
396 |
|
|
|
397 |
$FORM{$_} = url_param($_); # Retrieve all of the FORM data submitted
|
|
|
398 |
#warn "$_: $FORM{$_}";
|
|
|
399 |
|
|
|
400 |
if ((/^filter/) and ($FORM{$_} ne '')) { # Build a set of filters to apply
|
|
|
401 |
my ($filter,$field) = split /-/, $_;
|
|
|
402 |
$FILTER->{$field} = $FORM{$_} unless notInArray ($field, \@allFields);
|
|
|
403 |
} elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
404 |
{ push @displayFields, $_ unless /shiftinclude/; }
|
|
|
405 |
}
|
| 196 |
- |
406 |
|
|
|
407 |
if (exists $FORM{autoload}) { # If the FORM was submitted (i.e. the page is being redisplayed),
|
|
|
408 |
# build the data for the cookie that remembers the page setup
|
|
|
409 |
my $disFields = join ":", @displayFields;
|
|
|
410 |
my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
|
|
|
411 |
|
|
|
412 |
$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
|
|
|
413 |
$QUERY_STRING .= '&'.$FORM{shiftinclude} unless !$FORM{shiftinclude};
|
|
|
414 |
}
|
|
|
415 |
|
|
|
416 |
if (!(exists $FORM{autoload})) { # No FORM was submitted...
|
|
|
417 |
if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie")) { # Check for cookies from previous visits.
|
|
|
418 |
my ($disF, $filts, $sb, $al, $si) = split /&/,$prefs;
|
|
|
419 |
@displayFields = split /:/,$disF;
|
|
|
420 |
|
|
|
421 |
foreach my $pair (split /:/, $filts) {
|
|
|
422 |
my ($key, $value) = split /=/, $pair;
|
|
|
423 |
$FORM{"filter-$key"} = $value;
|
|
|
424 |
$FILTER->{$key} = $value;
|
|
|
425 |
}
|
|
|
426 |
|
|
|
427 |
$FORM{sortby} = $sb;
|
|
|
428 |
$FORM{autoload} = $al;
|
|
|
429 |
$FORM{shiftinclude} = $si;
|
|
|
430 |
$QUERY_STRING = $prefs;
|
|
|
431 |
} else {
|
|
|
432 |
@displayFields = @defaultFields; # Otherwise suppply a default list of columns.
|
|
|
433 |
$FORM{autoload} = 1; # And turn autoload on by default.
|
|
|
434 |
}
|
|
|
435 |
}
|
|
|
436 |
|
|
|
437 |
# let's just make sure the columns are in the right order (and there aren't any missing)
|
|
|
438 |
@displayFields = grep { inArray($_, \@allFields) } sort byfield uniq @displayFields, @staticFields;
|
|
|
439 |
|
|
|
440 |
# If the field isn't in the displayFields list, then add it to the hideFields list
|
|
|
441 |
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
|
|
|
442 |
|
|
|
443 |
# Process any filters provided in the form to pass to the database
|
|
|
444 |
my @whereClause; # = $defaultWhereClause;
|
|
|
445 |
push @whereClause, $defaultWhereClause unless !$defaultWhereClause;
|
|
|
446 |
if ($displayYearSelect) {
|
|
|
447 |
my $yearfield = inArray("date", \@allFields) ? 'year(date)' : "year"; # some pages only use the year, and not a date
|
|
|
448 |
|
|
|
449 |
if ($YEAR) {
|
|
|
450 |
push @whereClause, "$yearfield = '$YEAR'";
|
|
|
451 |
} else {
|
|
|
452 |
push @whereClause, "$yearfield = year(now())";
|
|
|
453 |
}
|
|
|
454 |
}
|
|
|
455 |
push @whereClause, map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
|
|
|
456 |
|
|
|
457 |
# Given the fields to display and the where conditions,
|
|
|
458 |
# "getData" will return a reference to an array of
|
|
|
459 |
# hash references of the results.
|
|
|
460 |
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
|
|
|
461 |
my @ProductList = @{ $data };
|
|
|
462 |
|
|
|
463 |
my $x = scalar @ProductList; # How many results were returned?
|
|
|
464 |
|
|
|
465 |
# If the user is trying to download the Excel file, send it to them and then exit out.
|
|
|
466 |
if ($FORM{excel}) {
|
|
|
467 |
(my $filename = $pageTitle) =~ s/\s+/_/g;
|
| 218 |
- |
468 |
exportExcel (\@ProductList, $filename, \@displayFields);
|
| 196 |
- |
469 |
exit;
|
|
|
470 |
}
|
|
|
471 |
|
|
|
472 |
my @shifts;
|
|
|
473 |
if ($FORM{shiftinclude} eq "true") {
|
|
|
474 |
my @SIWhere = ("year(date) = '$YEAR'");
|
|
|
475 |
push @SIWhere, "RCid = $ORCUSER->{RCid}";
|
|
|
476 |
my ($d, $c) = getData (\@displayFields, \@SIWhere, $DBTABLE, $FORM{sortby});
|
|
|
477 |
@shifts = @{ $d };
|
|
|
478 |
}
|
|
|
479 |
|
|
|
480 |
my $username = $h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$ORCUSER->{RCid}" }, $ORCUSER->{derby_name});
|
|
|
481 |
my $signedOnAs = $username ? "Welcome, $username. ".$h->input ({ type=>"button", value=>"Log Out", onClick=>"window.location.href='index.pl?LOGOUT';" }) : "You are not signed in.";
|
|
|
482 |
|
|
|
483 |
# Set some cookie stuff...
|
|
|
484 |
my $path = `dirname $ENV{SCRIPT_NAME}`; chomp $path; $path .= '/' unless $path eq "/";
|
|
|
485 |
my $queryCookie = cookie(-NAME=>$prefscookie,
|
|
|
486 |
-VALUE=>"$QUERY_STRING",
|
|
|
487 |
-PATH=>"$path",
|
|
|
488 |
-EXPIRES=>'+365d');
|
|
|
489 |
|
|
|
490 |
# Print the header
|
|
|
491 |
print header (-cookie=> [ $queryCookie, $RCAUTH_cookie ] );
|
|
|
492 |
|
|
|
493 |
#------------------
|
|
|
494 |
|
|
|
495 |
# Toggle the autoload fields within the table elements
|
|
|
496 |
our ($onClick, $onChange); # (also used in scanFunctions)
|
|
|
497 |
my ($radiobutton, $refreshbutton, $sortby);
|
|
|
498 |
if ($FORM{autoload}) {
|
|
|
499 |
$onClick = "onClick='submit();'";
|
|
|
500 |
$onChange = "onChange='page.value = 1; submit();'";
|
|
|
501 |
$radiobutton = $h->div ({ class=>'autoload' },
|
|
|
502 |
["Autoload Changes: ",
|
|
|
503 |
$h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ",
|
|
|
504 |
$h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
|
|
|
505 |
]);
|
|
|
506 |
$refreshbutton = "";
|
|
|
507 |
$sortby = $h->select ({name=>"sortby", onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
|
|
|
508 |
} else {
|
|
|
509 |
$onClick = "";
|
|
|
510 |
$onChange = "onChange='page.value = 1;'";
|
|
|
511 |
$radiobutton = $h->div ({ class=>'autoload' },
|
|
|
512 |
["Autoload Changes: ",
|
|
|
513 |
$h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ",
|
|
|
514 |
$h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
|
|
|
515 |
]);
|
|
|
516 |
$refreshbutton = $h->input ({ type=>"button", value=>"Refresh", onClick=>"submit(); return false;" });
|
|
|
517 |
$sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
|
|
|
518 |
}
|
|
|
519 |
|
|
|
520 |
# "Shift Include" shows a checkbox to include a users shifts at the top of the page
|
|
|
521 |
my $SIChecked;
|
|
|
522 |
if ($showMyShiftsOption) {
|
| 208 |
- |
523 |
my $things = $DBTABLE eq "v_class_new" ? "classes" : "shifts";
|
| 196 |
- |
524 |
if ($FORM{shiftinclude}) {
|
| 199 |
- |
525 |
$SIChecked = "Show my $things: ".$h->input ({ type=>"checkbox", name=>"shiftinclude", value=>"true", checked=>[], onClick=>'submit();' });
|
| 196 |
- |
526 |
} else {
|
| 199 |
- |
527 |
$SIChecked = "Show my $things: ".$h->input ({ type=>"checkbox", name=>"shiftinclude", value=>"true", onClick=>'submit();' });
|
| 196 |
- |
528 |
}
|
|
|
529 |
}
|
|
|
530 |
|
|
|
531 |
# If the block personal time flag is set, include a button to go to that form.
|
|
|
532 |
$SIChecked .= ' '.$h->input ({ type=>"button", value=>"Block Personal Time", onClick=>"window.location.href='personal_time.pl'" }) unless !$blockPersonalTime;
|
|
|
533 |
$SIChecked .= $h->br unless !$SIChecked;
|
|
|
534 |
|
|
|
535 |
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
|
|
|
536 |
|
|
|
537 |
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
|
|
|
538 |
print $h->input ({ type=>"hidden", name=>"excel", value=>0 });
|
|
|
539 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
540 |
$h->h1 ($pageTitle),
|
|
|
541 |
$h->div ({ class=>"sp0" }, [
|
|
|
542 |
$h->div ({ class=>"spLeft" }, [
|
|
|
543 |
$radiobutton
|
|
|
544 |
]),
|
|
|
545 |
$h->div ({ class=>"spRight" }, [
|
|
|
546 |
$h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href=".$homeURL }),
|
|
|
547 |
$refreshbutton
|
|
|
548 |
]),
|
|
|
549 |
]),
|
|
|
550 |
]);
|
|
|
551 |
|
|
|
552 |
# Print the Hidden fields' check boxes (if there are any)
|
|
|
553 |
my $c = 1;
|
|
|
554 |
my @hiddencheckboxes;
|
|
|
555 |
my @hiddenrows;
|
|
|
556 |
foreach my $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
|
|
|
557 |
if ($FORM{autoload}) {
|
|
|
558 |
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} ]);
|
|
|
559 |
} else {
|
|
|
560 |
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} ]);
|
|
|
561 |
}
|
|
|
562 |
if ($c++ % 4 == 0) {
|
|
|
563 |
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
|
|
|
564 |
@hiddencheckboxes = [];
|
|
|
565 |
}
|
|
|
566 |
}
|
|
|
567 |
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
|
|
|
568 |
|
|
|
569 |
if (scalar @hideFields) {
|
|
|
570 |
my @topleft;
|
|
|
571 |
push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
|
|
|
572 |
push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
|
|
|
573 |
|
|
|
574 |
print $h->div ({ class=>"sp0" }, [
|
|
|
575 |
$h->div ({ class=>"spLeft" }, [ @topleft ]),
|
|
|
576 |
$h->div ({ class=>"spRight" }, [
|
|
|
577 |
$signedOnAs, $h->br,
|
|
|
578 |
$SIChecked,
|
|
|
579 |
])
|
|
|
580 |
]);
|
|
|
581 |
}
|
|
|
582 |
|
|
|
583 |
# Print the main table...............................................
|
|
|
584 |
|
|
|
585 |
print $h->open ('div', { class=>'rTable' });
|
|
|
586 |
|
|
|
587 |
my @tmptitlerow;
|
|
|
588 |
foreach my $f (@displayFields) { # Print the Column headings
|
| 203 |
- |
589 |
my $special_button = "";
|
| 196 |
- |
590 |
if ($headerButton) {
|
|
|
591 |
if ($f eq $headerButton->{field}) {
|
|
|
592 |
$special_button = ' '.$headerButton->{button};
|
|
|
593 |
}
|
|
|
594 |
}
|
|
|
595 |
if (inArray ($f, \@staticFields)) {
|
|
|
596 |
push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f}, $special_button ]);
|
|
|
597 |
} else {
|
|
|
598 |
if ($FORM{autoload}) {
|
|
|
599 |
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}, $special_button ]);
|
|
|
600 |
} else {
|
|
|
601 |
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}, $special_button ]);
|
|
|
602 |
}
|
|
|
603 |
}
|
|
|
604 |
}
|
|
|
605 |
|
|
|
606 |
# Print the filter boxes...
|
| 197 |
- |
607 |
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ map { $h->div ({ class=>'rTableCell filters' }, filter ($_, undef, $YEAR)) } @displayFields ], $h->div ({ class=>"rTableCell" }));
|
| 196 |
- |
608 |
|
|
|
609 |
if ($FORM{shiftinclude}) { # Include all of the user's shifts at the top
|
|
|
610 |
foreach my $t (@shifts) {
|
|
|
611 |
no strict;
|
|
|
612 |
print $h->div ({ class=>'rTableRow highlighted' }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_} ? $t->{$_} : "") } @displayFields ]);
|
|
|
613 |
}
|
|
|
614 |
print $h->hr ({ width=>"500%" });
|
|
|
615 |
}
|
|
|
616 |
|
|
|
617 |
|
|
|
618 |
# Print the things
|
|
|
619 |
foreach my $t (@ProductList) {
|
|
|
620 |
my $shading = ($highlightShifts and $t->{RCid} eq $ORCUSER->{RCid}) ? "highlighted" : "shaded";
|
|
|
621 |
no strict; # 'strict' doesn't like the exists functionality
|
|
|
622 |
my $rowclick = (exists &addRowClick) ? addRowClick ($t) : "";
|
|
|
623 |
|
|
|
624 |
print $h->div ({ class=>'rTableRow '.$shading, onClick=>$rowclick }, [ map { $h->div ({ class=>'rTableCell' }, exists &{"modify_".$_} ? &{"modify_".$_} ($t) : $t->{$_} ? $t->{$_} : "") } @displayFields ]);
|
|
|
625 |
}
|
|
|
626 |
|
|
|
627 |
print $h->close ('div');
|
|
|
628 |
|
|
|
629 |
# close things out................................................
|
|
|
630 |
|
|
|
631 |
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
|
|
|
632 |
if ($curpage > $pages) { $curpage = $pages; }
|
|
|
633 |
|
|
|
634 |
my @pagerange;
|
|
|
635 |
if ($pages <= 5 ) {
|
|
|
636 |
@pagerange = 1 .. $pages;
|
|
|
637 |
} else {
|
|
|
638 |
if ($curpage <= 3) {
|
|
|
639 |
@pagerange = (1, 2, 3, 4, ">>");
|
|
|
640 |
} elsif ($curpage >= $pages - 2) {
|
|
|
641 |
@pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
|
|
|
642 |
} else {
|
|
|
643 |
@pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
|
|
|
644 |
}
|
|
|
645 |
}
|
|
|
646 |
|
|
|
647 |
my @yearoptions;
|
|
|
648 |
if ($displayYearSelect) {
|
|
|
649 |
my $currentyear;
|
|
|
650 |
foreach (@{&getYears()}) {
|
|
|
651 |
push @yearoptions, $YEAR eq $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_);
|
|
|
652 |
$currentyear = $_;
|
|
|
653 |
}
|
|
|
654 |
$yearoptions[$#yearoptions] = $h->option ({ selected=>[] }, $currentyear) unless $YEAR;
|
|
|
655 |
}
|
|
|
656 |
|
|
|
657 |
print $h->br; # print $h->br;
|
|
|
658 |
print $h->div ({ class=>"sp0" }, [
|
|
|
659 |
$h->div ({ class=>"spLeft" }, [
|
|
|
660 |
$h->div ({ class=>"footer" }, [
|
|
|
661 |
"To bookmark, save, or send this exact view, use the ",
|
|
|
662 |
$h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
|
|
|
663 |
$h->br,
|
|
|
664 |
"If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
|
|
|
665 |
$h->br,
|
|
|
666 |
$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.]"),
|
|
|
667 |
$h->br,
|
|
|
668 |
"This page was displayed on ", currentTime (),
|
|
|
669 |
$h->br,
|
|
|
670 |
"Please direct questions, problems, and concerns to $SYSTEM_EMAIL",
|
|
|
671 |
$displayYearSelect ? $h->br."Displaying: ".$h->select ({ name=>"year", onchange=>"Req.submit();" }, [ @yearoptions ]) : $h->br
|
|
|
672 |
])
|
|
|
673 |
]),
|
|
|
674 |
$h->div ({ class=>"spRight" }, [
|
|
|
675 |
$h->h5 ([
|
|
|
676 |
"$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,
|
|
|
677 |
"Sorted by ", $sortby, $h->br,
|
|
|
678 |
"Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
|
|
|
679 |
( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
|
|
|
680 |
$_ eq "<<" ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
|
|
|
681 |
$_ eq ">>" ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
|
|
|
682 |
$h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
|
|
|
683 |
$h->input ({ type=>"hidden", name=>"page", value=>$curpage })
|
|
|
684 |
])
|
|
|
685 |
]),
|
|
|
686 |
]);
|
|
|
687 |
|
|
|
688 |
print $h->close('form');
|
|
|
689 |
print $h->close('body');
|
|
|
690 |
print $h->close('html');
|
|
|
691 |
}
|
| 7 |
- |
692 |
|
|
|
693 |
# Leave this alone, it's needed to compile correctly
|
|
|
694 |
return 1;
|