Subversion Repositories PEEPS

Rev

Rev 3 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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