Subversion Repositories VORC

Rev

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