Subversion Repositories VORC

Rev

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