Subversion Repositories VORC

Rev

Rev 153 | Rev 197 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 153 Rev 196
Line 1... Line 1...
1
#package tableViewer;
1
#package tableViewer;
Line 2... Line 2...
2
 
2
 
3
#######################################################################
3
#######################################################################
4
# A set of functions to assist the scan data display tool.
4
# A set of functions to assist the scan data display tool.
5
#	Kept here to unclutter the main script.
5
# Kept here to unclutter the main script.
6
#######################################################################
6
#######################################################################
7
#
7
#
8
#
8
#
9
# $Log: scanFunctions.pm,v $
9
# $Log: scanFunctions.pm,v $
Line 13... Line 13...
13
use Exporter 'import';
13
use Exporter 'import';
14
use cPanelUserConfig;
14
use cPanelUserConfig;
15
use DBI ();
15
use DBI ();
16
use WebDB;
16
use WebDB;
Line 17... Line 17...
17
 
17
 
Line 18... Line -...
18
our @EXPORT = qw( byfield currentTime exportExcel fetchColEntries fetchDerbyNameWithRCid filter getData getDBConnection inArray notInArray uniq whereInArray );
-
 
19
 
18
our @EXPORT = qw( byfield currentTime exportExcel fetchColEntries fetchDerbyNameWithRCid filter getData getDBConnection inArray notInArray uniq whereInArray printTablePage );
Line 20... Line 19...
20
#my $internalDBH = &getDBConnection || die "Unable to connect to Database\n\n";
19
 
21
my $internalDBH = WebDB::connect () || die "Unable to connect to Database\n\n";
20
my $internalDBH = WebDB::connect () || die "Unable to connect to Database\n\n";
22
 
21
 
23
sub currentTime {
22
sub currentTime {
Line 24... Line 23...
24
  use DateTime;
23
  use DateTime;
25
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
24
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
Line 26... Line 25...
26
  $now =~ s/T/ at /;
25
  $now =~ s/T/ at /;
Line 27... Line 26...
27
  
26
  
28
  return $now." US/Pacific";
27
  return $now." US/Pacific";
29
}
28
}
Line 30... Line 29...
30
 
29
 
31
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b};	}
30
sub byfield { $colOrderHash{$a} <=> $colOrderHash{$b}; }
32
 
31
 
33
sub exportExcel {
32
sub exportExcel {
Line 34... Line 33...
34
  my $listref = shift;
33
  my $listref = shift;
35
  my $FN_Prefix = shift // "ORC_Export";
34
  my $FN_Prefix = shift // "VORC_Export";
36
  
35
  
37
  use Spreadsheet::WriteExcel;
36
  use Spreadsheet::WriteExcel;
38
 
37
  
39
	my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
38
  my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
40
  my $filename = "${FN_Prefix}_${date}_$$.xls";
39
  my $filename = "${FN_Prefix}_${date}_$$.xls";
41
  
40
  
42
	print "Content-type: application/vnd.ms-excel\n";
41
  print "Content-type: application/vnd.ms-excel\n";
43
  # The Content-Disposition will generate a prompt to save the file. If you want
42
  # 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.
43
  # to stream the file to the browser, comment out the following line.
45
  print "Content-Disposition: attachment; filename=$filename\n";
44
  print "Content-Disposition: attachment; filename=$filename\n";
46
  print "\n";
45
  print "\n";
47
 
46
  
48
  # Create a new workbook and add a worksheet. The special Perl filehandle - will
47
  # Create a new workbook and add a worksheet. The special Perl filehandle - will
49
  # redirect the output to STDOUT
48
  # redirect the output to STDOUT
50
  #
49
  #
51
  my $workbook  = Spreadsheet::WriteExcel->new(\*STDOUT);
50
  my $workbook  = Spreadsheet::WriteExcel->new(\*STDOUT);
52
  my $worksheet = $workbook->add_worksheet();
51
  my $worksheet = $workbook->add_worksheet();
53
	
52
  
54
	my $format = $workbook->add_format();
53
  my $format = $workbook->add_format();
55
	$format->set_bold();
54
  $format->set_bold();
56
	
55
  
57
	my $col = $row = 0;
56
  my $col = $row = 0;
58
	
57
  
59
	foreach $f (@displayFields)
58
  foreach $f (@displayFields)
60
		{ $worksheet->write($row, $col++, "$NAME{$f}", $format); }
59
    { $worksheet->write($row, $col++, "$NAME{$f}", $format); }
61
	
60
  
62
	foreach $t (sort @{ $listref })			# Unt now we print the tickets!
61
  foreach $t (sort @{ $listref })     # Unt now we print the tickets!
63
	{
62
  {
64
		$col = 0;
63
    $col = 0;
65
		$row++;
64
    $row++;
66
		foreach $f (@displayFields)	{
65
    foreach $f (@displayFields) {
67
			if ($f eq "derby_name") {
66
      if ($f eq "derby_name") {
68
				if ($user->{department}->{"OFF"} < 2 and $t->{derby_name} and $t->{RCid} != $RCid and $LVL < 5) {
67
        if ($user->{department}->{"OFF"} < 2 and $t->{derby_name} and $t->{RCid} != $RCid and $LVL < 5) {
69
    			$t->{derby_name} = "FILLED";
68
          $t->{derby_name} = "FILLED";
70
  			}
69
        }
Line 71... Line 70...
71
			}
70
      }
72
			$t->{$f} =~ s/<br>/\n/ig; $worksheet->write($row, $col++, "$t->{$f}");
71
      $t->{$f} =~ s/<br>/\n/ig; $worksheet->write($row, $col++, "$t->{$f}");
73
		}
72
    }
74
	}
73
  }
75
	
74
  
Line 76... Line 75...
76
	$workbook->close();
75
  $workbook->close();
77
  return;
76
  return;
78
}
77
}
79
 
78
 
80
 
79
 
81
sub fetchColEntries {                        
80
sub fetchColEntries {
82
	my $colName = shift;
81
  my $colName = shift;
83
	my $selection = shift;
82
  my $selection = shift;
84
	my $table = $DBTABLE;
83
  my $table = $DBTABLE;
85
	my $optionList = "";
84
  my $optionList = "";
86
  
85
  
87
  if ($colName eq "derby_name" and $LVL < 2) {
86
  if ($colName eq "derby_name" and $LVL < 2) {
88
    # special case to anonymize assignees...
87
    # special case to anonymize assignees...
89
    my @opts = ("-blank-", $ORCUSER->{derby_name});
88
    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}) };
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}) };
91
    $optionList = join "", map { $selection eq $_ ? "<OPTION selected>$_</OPTION>" : "<OPTION>$_</OPTION>" } @opts;
90
    $optionList = join "", map { $selection eq $_ ? "<OPTION selected>$_</OPTION>" : "<OPTION>$_</OPTION>" } @opts;
92
  } else {
91
  } else {
93
    my $dept_where = $table eq "v_shift" ? "where dept != 'PER' and year(date) = year(now())" : "";
92
    my $dept_where = $table eq "v_shift" ? "where dept != 'PER' and year(date) = year(now())" : "";
94
    my $orderby = $colName eq "dayofweek" ? "field(dayofweek, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')" : $colName;
93
    my $orderby = $colName eq "dayofweek" ? "field(dayofweek, 'Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday')" : $colName;
95
	  my $cathan = $internalDBH->prepare("select distinct $colName from $table $dept_where order by $orderby");
94
    my $cathan = $internalDBH->prepare("select distinct nullif($colName, '') from $table $dept_where order by $orderby");
Line 96... Line 95...
96
 
95
    
97
  	$cathan->execute();
96
    $cathan->execute();
Line 98... Line 97...
98
  	while (my ($cat) = $cathan->fetchrow) {
97
    while (my ($cat) = $cathan->fetchrow) {
99
  	  if ($cat eq "") { $cat = "-blank-"; }
98
      if (!$cat) { $cat = "-blank-"; }
100
  	  if ($cat eq $selection) {
99
      if ($cat eq $selection) {
101
  	    $optionList .= "<OPTION selected>$cat</OPTION>";
100
        $optionList .= "<OPTION selected>$cat</OPTION>";
102
  	  } else {
101
      } else {
103
  		  $optionList .= "<OPTION>$cat</OPTION>";
102
        $optionList .= "<OPTION>$cat</OPTION>";
104
  		}
103
      }
105
  	}
104
    }
106
  }
105
  }
107
  
106
  
108
	return $optionList;
107
  return $optionList;
109
}
108
}
110
 
109
 
111
sub fetchDerbyNameWithRCid {
110
sub fetchDerbyNameWithRCid {
112
  my $ATTRIBUTES;
111
  my $ATTRIBUTES;
113
  if (ref $_[0] eq "HASH") {
112
  if (ref $_[0] eq "HASH") {
114
    $ATTRIBUTES = shift;
113
    $ATTRIBUTES = shift;
115
  }
114
  }
116
  my $DEPT = shift // "";
115
  my $DEPT = shift // "";
117
  my $selected = shift // "";
116
  my $selected = shift // "";
Line 118... Line 117...
118
	my $optionList = "";
117
  my $optionList = "";
119
	
118
  
120
	my $cathan;
119
  my $cathan;
121
	if (!$DEPT or $DEPT eq "CMP") {
120
  if (!$DEPT or $DEPT eq "CMP") {
122
	  $cathan = $internalDBH->prepare("select RCid, derby_name from official where access > 0 order by derby_name");
121
    $cathan = $internalDBH->prepare("select RCid, derby_name from official where access > 0 order by derby_name");
123
  	$cathan->execute();
122
    $cathan->execute();
124
  } elsif ($DEPT eq "CLA") {
123
  } elsif ($DEPT eq "CLA") {
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");
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");
Line 126... Line 125...
126
    $cathan->execute;
125
    $cathan->execute;
127
	} else {
126
  } else {
Line 128... Line 127...
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");
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");
129
    $cathan->execute("%".$DEPT."%", "%".$DEPT."-0%");
128
    $cathan->execute("%".$DEPT."%", "%".$DEPT."-0%");
130
	}
129
  }
131
  
130
  
132
  my $valuelabel = $ATTRIBUTES->{DATALIST} ? "data-value" : "value";
131
  my $valuelabel = $ATTRIBUTES->{DATALIST} ? "data-value" : "value";
133
	while (my ($id, $cat) = $cathan->fetchrow) {
132
  while (my ($id, $cat) = $cathan->fetchrow) {
134
	  if ($id == $selected) {
133
    if ($id == $selected) {
135
	    $optionList .= "<OPTION $valuelabel=$id selected>$cat</OPTION>";
134
      $optionList .= "<OPTION $valuelabel=$id selected>$cat</OPTION>";
136
	  } else {
135
    } else {
137
	    $optionList .= "<OPTION $valuelabel=$id>$cat</OPTION>";
136
      $optionList .= "<OPTION $valuelabel=$id>$cat</OPTION>";
138
	  }
137
    }
139
	}
138
  }
140
 
139
 
141
	return $optionList;
140
  return $optionList;
142
}
141
}
143
 
142
 
144
 
143
 
145
sub filter {
144
sub filter {
146
	my $colName = shift;
145
  my $colName = shift;
147
	my $filter = shift;
146
  my $filter = shift;
148
	
147
  
149
	if (exists &{"filter_".$colName}) { return &{"filter_".$colName} ($colName, $filter); }
148
  if (exists &{"filter_".$colName}) { return &{"filter_".$colName} ($colName, $filter); }
150
 
149
  
151
	if ($colFilterTypeHash{$colName} eq 'select')
150
  if ($colFilterTypeHash{$colName} eq 'select')
152
	{
151
  {
153
		if (defined $filter)	{
152
    if (defined $filter)  {
154
			if ($filter eq "-blank-") {
153
      if ($filter eq "-blank-") {
155
				return "($colName = '' or isNull($colName) = 1)";
154
        return "($colName = '' or isNull($colName) = 1)";
156
			}
155
      }
157
#			$filter = s/'/\'/g;
156
#     $filter = s/'/\'/g;
158
			return "$colName = \"$filter\"";
157
      return "$colName = \"$filter\"";
159
		}
158
    }
160
		else
159
    else
161
		{
160
    {
162
			my $thing = "filter-${colName}";
161
      my $thing = "filter-${colName}";
163
			my $categories = &fetchColEntries($colName, $FORM{$thing});
162
      my $categories = fetchColEntries ($colName, $FORM{$thing});
164
			my $Options = "<OPTION></OPTION>".$categories;
-
 
165
	
-
 
166
			$Options =~ s/>($FORM{$thing})/ selected>$1/;
-
 
167
			return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
-
 
Line -... Line 163...
-
 
163
      my $Options = "<OPTION></OPTION>".$categories;
-
 
164
      
-
 
165
      $Options =~ s/>($FORM{$thing})/ selected>$1/;
-
 
166
      return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
168
		}
167
    }
169
	} elsif ($colFilterTypeHash{$colName} eq 'text') {
168
  } elsif ($colFilterTypeHash{$colName} eq 'text') {
170
		if (defined $filter)
169
    if (defined $filter)
171
		{
170
    {
172
			if ($filter =~ /\d{1,2}:\d{2}/ and $ORCUSER->{timeformat} eq "ampm") {
171
      if ($filter =~ /\d{1,2}:\d{2}/ and $ORCUSER->{timeformat} eq "ampm") {
173
			  my ($h, $m) = split /:/, $filter;
172
        my ($h, $m) = split /:/, $filter;
174
			  my $caret;
173
        my $caret;
175
			  if ($h =~ s/^\^\s*//) { $caret = "^"; }
174
        if ($h =~ s/^\^\s*//) { $caret = "^"; }
176
			  if ($h < 8) { $h += 12; }
175
        if ($h < 8) { $h += 12; }
177
			  $filter = $caret.join ":", $h, $m;
176
        $filter = $caret.join ":", $h, $m;
178
			}
177
      }
179
			
178
      
180
			if ($filter =~ s/^=\s*//) { return "$colName = \"$filter\""; }
179
      if ($filter =~ s/^=\s*//) { return "$colName = \"$filter\""; }
181
			
180
      
182
			if ($filter !~ s/^\^\s*//) { $filter = "\%$filter"; }
181
      if ($filter !~ s/^\^\s*//) { $filter = "\%$filter"; }
183
			if ($filter !~ s/\s*\$$//) { $filter = "$filter\%"; }
182
      if ($filter !~ s/\s*\$$//) { $filter = "$filter\%"; }
184
			$filter =~ s/\*/%/g;
183
      $filter =~ s/\*/%/g;
185
      
184
      
186
			return "$colName like \"$filter\"";
185
      return "$colName like \"$filter\"";
187
		}
186
    }
188
		else
187
    else
189
		{
188
    {
190
			my $thing = "filter-${colName}";
189
      my $thing = "filter-${colName}";
191
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
190
      return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
192
		}
191
    }
193
	} elsif ($colFilterTypeHash{$colName} eq 'number') {
192
  } elsif ($colFilterTypeHash{$colName} eq 'number') {
194
		if (defined $filter)
193
    if (defined $filter)
195
		{
194
    {
196
			if ($filter =~ /^[>=<]\s*/) { return "$colName $filter"; }
195
      if ($filter =~ /^[>=<]\s*/) { return "$colName $filter"; }
197
			else { return "$colName = $filter"; }
196
      else { return "$colName = $filter"; }
198
		}
197
    }
199
		else
198
    else
200
		{
199
    {
201
			my $thing = "filter-${colName}";
200
      my $thing = "filter-${colName}";
202
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=2 $onChange>";
201
      return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=2 $onChange>";
203
		}
202
    }
204
	} elsif ($colFilterTypeHash{$colName} eq 'date') {
203
  } elsif ($colFilterTypeHash{$colName} eq 'date') {
205
		if (defined $filter)
204
    if (defined $filter)
206
		{
205
    {
207
			if ($filter =~ s/^<\s*//) { return "$colName < '$filter'"; }
206
      if ($filter =~ s/^<\s*//) { return "$colName < '$filter'"; }
208
			if ($filter =~ s/^>\s*//) { return "$colName > '$filter'"; }
207
      if ($filter =~ s/^>\s*//) { return "$colName > '$filter'"; }
209
			
208
      
210
			return "$colName = '$filter'";
209
      return "$colName = '$filter'";
211
		}
210
    }
212
		else
211
    else
213
		{
212
    {
214
			my $thing = "filter-${colName}";
213
      my $thing = "filter-${colName}";
215
			return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
214
      return "<INPUT type=text name=$thing value=\"$FORM{$thing}\" size=15 $onChange>";
216
		}
215
    }
217
	} elsif ($colFilterTypeHash{$colName} eq 'boolean') {
216
  } elsif ($colFilterTypeHash{$colName} eq 'boolean') {
Line 218... Line 217...
218
		if (defined $filter)
217
    if (defined $filter)
219
		{
218
    {
220
			return "$colName = $filter";
219
      return "$colName = $filter";
221
		}
220
    }
222
		else
221
    else
223
		{
222
    {
224
			my $thing = "filter-${colName}";
223
      my $thing = "filter-${colName}";
225
			my $Options = "<OPTION></OPTION><OPTION>True</OPTION><OPTION>False</OPTION>";
224
      my $Options = "<OPTION></OPTION><OPTION>True</OPTION><OPTION>False</OPTION>";
226
	
225
      
227
			$Options =~ s/>($FORM{$thing})/ selected>$1/;
226
      $Options =~ s/>($FORM{$thing})/ selected>$1/;
Line 228... Line 227...
228
			return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
227
      return "<SELECT name=filter-${colName} $onChange>$Options</SELECT>";
229
		}
228
    }
230
	} elsif ($colFilterTypeHash{$colName} eq 'ERROR') {
229
  } elsif ($colFilterTypeHash{$colName} eq 'ERROR') {
231
		return "<center><strong><font color=red>ERROR!</font>";
230
    return "<center><strong><font color=red>ERROR!</font>";
-
 
231
  } elsif ($colFilterTypeHash{$colName} eq 'none') {
-
 
232
    return;
232
	} elsif ($colFilterTypeHash{$colName} eq 'none') {
233
  }
233
		return;
234
}
234
	}
235
 
Line 235... Line 236...
235
}
236
 
236
 
237
sub getData {
237
 
238
  my $fields = shift;
238
sub getData {
239
  my $whereClause = shift;
239
	my $fields = shift;
240
  my $table = shift;
240
	my $whereClause = shift;
241
  my $orderby = shift;
241
	my $table = shift;
242
  my $curpage = shift; $curpage = 1 unless $curpage;
242
	my $orderby = shift;
243
  my $pagelimit = shift // "All";
243
	my $curpage = shift; $curpage = 1 unless $curpage;
244
  
244
	my $pagelimit = shift // "All";
245
  my $selected = '*';
245
	
246
  $whereClause = scalar @{$whereClause} > 0 ? "where ".join (" and ", @{$whereClause}) : '';
246
	my $selected = '*';
247
  
247
	$whereClause = scalar @{$whereClause} > 0 ? "where ".join " and ", @{$whereClause} : '';
248
  if ($orderby eq "dayofweek") {
248
  
249
    $orderby = "order by date, time";
249
  if ($orderby eq "dayofweek") {
250
  } elsif ($orderby eq "eventid") { # only applicable to the log viewer...
250
   	$orderby = "order by date, time";
251
    $orderby = "order by eventid desc";
251
  } elsif ($orderby eq "eventid") { # only applicable to the log viewer...
252
  } elsif ($orderby eq "key") { # for the settings page, the column name 'key' is a reserved word in mysql
252
   	$orderby = "order by eventid desc";
253
    $orderby = "order by ${table}.key";
253
  } else {
254
  } else {
254
	  $orderby = $orderby eq "" ? "" : "order by $orderby";
255
    $orderby = $orderby eq "" ? "" : "order by $orderby";
Line 255... Line 256...
255
  }
256
  }
256
  
257
  
Line 282... Line 283...
282
  return $dbh;
283
  return $dbh;
283
}
284
}
Line 284... Line 285...
284
 
285
 
285
 
286
 
286
sub inArray {
287
sub inArray {
287
	my $item = shift;
288
  my $item = shift;
288
	my $array = shift;
289
  my $array = shift;
289
	foreach (@{$array})
290
  foreach (@{$array})
290
	{
291
  {
291
		return 1 if $item eq $_;
292
    return 1 if $item eq $_;
292
	}
293
  }
Line 293... Line 294...
293
	return 0;
294
  return 0;
294
}
295
}
295
 
296
 
Line 296... Line 297...
296
sub notInArray {
297
sub notInArray {
297
	return ! inArray (@_);
298
  return ! inArray (@_);
Line 304... Line 305...
304
    map { $h{$_}++ == 0 ? $_ : () } @_;
305
    map { $h{$_}++ == 0 ? $_ : () } @_;
305
}
306
}
Line 306... Line 307...
306
 
307
 
307
 
308
 
308
sub whereInArray {
309
sub whereInArray {
309
	my $item = shift;
310
  my $item = shift;
310
	my $array = shift;
311
  my $array = shift;
311
	my $i = 0;
312
  my $i = 0;
312
	foreach (@{$array})
313
  foreach (@{$array})
313
	{
314
  {
314
		return $i if $item eq $_;
315
    return $i if $item eq $_;
315
		$i++;
316
    $i++;
316
	}
317
  }
Line -... Line 318...
-
 
318
  return -1;
-
 
319
}
-
 
320
 
-
 
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
317
	return -1;
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');
Line 318... Line 660...
318
}
660
  print $h->close('body');
319
 
661
  print $h->close('html');