Subversion Repositories VORC

Rev

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

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