Subversion Repositories VORC

Rev

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