| 2 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
######################################
|
|
|
4 |
#
|
|
|
5 |
#
|
|
|
6 |
# $Log: req.pl,v $
|
|
|
7 |
#
|
|
|
8 |
######################################
|
|
|
9 |
|
|
|
10 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
11 |
|
|
|
12 |
use CGI qw/:standard/;
|
|
|
13 |
use lib "/home/rollerco/perl5/lib/perl5";
|
|
|
14 |
use scanFunctions;
|
|
|
15 |
use RollerCon;
|
|
|
16 |
use Spreadsheet::WriteExcel;
|
|
|
17 |
|
|
|
18 |
my $cookie_string = authenticate(2) || die;
|
|
|
19 |
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
20 |
my $user = getUser($EML);
|
|
|
21 |
my $username = $user->{derby_name};
|
|
|
22 |
my $RCid = $user->{RCid};
|
|
|
23 |
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
|
|
|
24 |
my $YEAR = 1900 + (localtime)[5]; #which year of data to display, default to current
|
|
|
25 |
|
|
|
26 |
our $DBTABLE = 'v_lead_shift';
|
|
|
27 |
our @allFields = (qw(id date dayofweek track time assignee_id derby_name));
|
|
|
28 |
our @defaultFields = (qw(date track time derby_name));
|
|
|
29 |
our @displayFields = ();
|
|
|
30 |
our @hideFields = ();
|
|
|
31 |
our %NAME = (
|
|
|
32 |
"id" => "ID",
|
|
|
33 |
"date" => "Date",
|
|
|
34 |
"dayofweek" => "Day",
|
|
|
35 |
"track" => "Track",
|
|
|
36 |
"time" => "Time",
|
|
|
37 |
"assignee_id" => "RCid",
|
|
|
38 |
"derby_name" => "Name"
|
|
|
39 |
);
|
|
|
40 |
our %colOrderHash = (
|
|
|
41 |
"id" => 5,
|
|
|
42 |
"date" => 10,
|
|
|
43 |
"dayofweek" => 12,
|
|
|
44 |
"track" => 15,
|
|
|
45 |
"time" => 25,
|
|
|
46 |
"assignee_id" => 30,
|
|
|
47 |
"derby_name" => 35
|
|
|
48 |
);
|
|
|
49 |
our %colFilterTypeHash = (
|
|
|
50 |
"id" => "number",
|
|
|
51 |
"date" => "date",
|
|
|
52 |
"dayofweek" => "select",
|
|
|
53 |
"track" => "select",
|
|
|
54 |
"time" => "text",
|
|
|
55 |
"assignee_id" => "number",
|
|
|
56 |
"derby_name" => "select"
|
|
|
57 |
);
|
|
|
58 |
my $orderby = "date, track, time";
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
foreach (param())
|
|
|
62 |
{
|
|
|
63 |
if (/^year$/) { #
|
|
|
64 |
$YEAR = param($_);
|
|
|
65 |
next;
|
|
|
66 |
}
|
|
|
67 |
|
|
|
68 |
$FORM{$_} = param($_); # Retrieve all of the FORM data submitted
|
|
|
69 |
|
|
|
70 |
if ((/^filter/) and ($FORM{$_} ne '')) # Build a set of filters to apply
|
|
|
71 |
{
|
|
|
72 |
my ($filter,$field) = split /-/, $_;
|
|
|
73 |
|
|
|
74 |
$FILTER->{$field} = $FORM{$_};
|
|
|
75 |
}
|
|
|
76 |
elsif ($FORM{$_} eq "true") # Compile list of fields to display
|
|
|
77 |
{ push @displayFields, $_; } # @displayFields is declared in scanFunctions.pm
|
|
|
78 |
}
|
|
|
79 |
|
|
|
80 |
|
|
|
81 |
if (exists $FORM{autoload}) # If the FORM was submitted (i.e. the page is being redisplayed),
|
|
|
82 |
{ # build the data for the cookie that remembers the page setup
|
|
|
83 |
my $disFields = join ":", @displayFields;
|
|
|
84 |
my @filters;
|
|
|
85 |
my @f = keys %{$FILTER};
|
|
|
86 |
foreach $key (@f)
|
|
|
87 |
{ push @filters, "$key=$FILTER->{$key}"; }
|
|
|
88 |
my $fils = join ":", @filters;
|
|
|
89 |
|
|
|
90 |
$QUERY_STRING = "$disFields\&$fils\&$FORM{autoload}";
|
|
|
91 |
}
|
|
|
92 |
|
|
|
93 |
|
|
|
94 |
if (!(exists $FORM{autoload})) # No FORM was submitted, suppply a default list of columns
|
|
|
95 |
{
|
|
|
96 |
if (my $prefs = cookie('RC_Lead_Shifts')) # Has this user been here before and saved a cookie?
|
|
|
97 |
{
|
|
|
98 |
my ($disF, $filts, $al) = split /&/,$prefs;
|
|
|
99 |
@displayFields = split /:/,$disF;
|
|
|
100 |
|
|
|
101 |
foreach $pair (split /:/, $filts)
|
|
|
102 |
{
|
|
|
103 |
my ($key, $value) = split /=/, $pair;
|
|
|
104 |
$FORM{"filter-$key"} = $value;
|
|
|
105 |
$FILTER->{$key} = $value;
|
|
|
106 |
}
|
|
|
107 |
|
|
|
108 |
$FORM{autoload} = $al;
|
|
|
109 |
$QUERY_STRING = $prefs;
|
|
|
110 |
}
|
|
|
111 |
else
|
|
|
112 |
{ @displayFields = @defaultFields; }
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
|
|
|
116 |
# Build the field lists to display and hide columns.
|
|
|
117 |
# If the field isn't in the displayFields list,
|
|
|
118 |
# then add it to the hideFields list.
|
|
|
119 |
#
|
|
|
120 |
@displayFields = sort byfield @displayFields;
|
|
|
121 |
foreach $field (@allFields) { if (! &inArray($field, \@displayFields)) { push @hideFields, $field; } }
|
|
|
122 |
|
|
|
123 |
|
|
|
124 |
my @whereClause = ("year(date) = '$YEAR'"); # Process the filters to build the components of the where clause
|
|
|
125 |
foreach $field (@allFields)
|
|
|
126 |
{
|
|
|
127 |
if (! &inArray($field, \@hideFields))
|
|
|
128 |
{
|
|
|
129 |
if ($FILTER->{$field})
|
|
|
130 |
{
|
|
|
131 |
push @whereClause, &generica($field, $FILTER->{$field});
|
|
|
132 |
delete $FILTER->{$field};
|
|
|
133 |
}
|
|
|
134 |
}
|
|
|
135 |
}
|
|
|
136 |
|
|
|
137 |
# Given the fields to display and the where conditions,
|
|
|
138 |
# "getData" will return a reference to an array of
|
|
|
139 |
# hash references of the results.
|
|
|
140 |
my @ProductList = @{&getData(\@displayFields, \@whereClause, $DBTABLE, $orderby)};
|
|
|
141 |
my $x = scalar @ProductList;
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
if ($FORM{excel})
|
|
|
145 |
{
|
|
|
146 |
my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
|
|
|
147 |
$filename = `dirname $ENV{REQUEST_URI}`; chomp $filename; $filename .= "/xls/${date}_$$.xls";
|
|
|
148 |
|
|
|
149 |
# Create a new Excel workbook
|
|
|
150 |
my $workbook = Spreadsheet::WriteExcel->new("/home/rollerco/officials.rollercon.com${filename}");
|
|
|
151 |
|
|
|
152 |
# Add a worksheet
|
|
|
153 |
my $worksheet = $workbook->add_worksheet();
|
|
|
154 |
|
|
|
155 |
# open my $fh, '>', \my $str or die "Failed to open filehandle: $!";
|
|
|
156 |
# my $workbook = Spreadsheet::WriteExcel->new($fh);
|
|
|
157 |
# my $worksheet = $workbook->add_worksheet();
|
|
|
158 |
|
|
|
159 |
|
|
|
160 |
my $format = $workbook->add_format();
|
|
|
161 |
$format->set_bold();
|
|
|
162 |
|
|
|
163 |
my $col = $row = 0;
|
|
|
164 |
|
|
|
165 |
foreach $f (@displayFields)
|
|
|
166 |
{ $worksheet->write($row, $col++, "$NAME{$f}", $format); }
|
|
|
167 |
|
|
|
168 |
foreach $t (sort @ProductList) # Unt now we print the tickets!
|
|
|
169 |
{
|
|
|
170 |
$col = 0;
|
|
|
171 |
$row++;
|
|
|
172 |
foreach $f (@displayFields)
|
|
|
173 |
{
|
|
|
174 |
$f =~ s/^HOST\.//;
|
|
|
175 |
$f =~ s/^FRAME\.//;
|
|
|
176 |
$t->{$f} =~ s/<br>/\n/ig; $worksheet->write($row, $col++, "$t->{$f}");
|
|
|
177 |
}
|
|
|
178 |
}
|
|
|
179 |
|
|
|
180 |
$workbook->close();
|
|
|
181 |
|
|
|
182 |
}
|
|
|
183 |
|
|
|
184 |
|
|
|
185 |
|
|
|
186 |
my $path = `dirname $ENV{REQUEST_URI}`; chomp $path; $path .= '/';
|
|
|
187 |
my $queryCookie = cookie(-NAME=>'RC_Lead_Shifts',
|
|
|
188 |
-VALUE=>"$QUERY_STRING",
|
|
|
189 |
-PATH=>"$path",
|
|
|
190 |
-EXPIRES=>'+365d');
|
|
|
191 |
#my $Auth_Cook = cookie(-NAME=>'RequestToolAuthorized',
|
|
|
192 |
# -VALUE=>"$authCookie",
|
|
|
193 |
# -PATH=>'/cbrt/cgi-bin/');
|
|
|
194 |
|
|
|
195 |
print header(-cookie=>[$RCAUTH_cookie,$queryCookie]);
|
|
|
196 |
|
|
|
197 |
|
|
|
198 |
print "<!-- FORM \n\n"; # Debug code to dump the FORM to a html comment
|
|
|
199 |
print "I'm catching updates!!!\n\n";
|
|
|
200 |
foreach $key (sort (keys %FORM)) # Must be done after the header is written!
|
|
|
201 |
{ print "\t$key: $FORM{$key}\n"; }
|
|
|
202 |
print "--> \n\n";
|
|
|
203 |
#
|
|
|
204 |
#
|
|
|
205 |
# print "<!-- ENV \n\n"; # Debug code to dump the ENV to a html comment
|
|
|
206 |
# foreach $key (sort (keys %ENV)) # Must be done after the header is written!
|
|
|
207 |
# { print "\t$key: $ENV{$key}\n"; }
|
|
|
208 |
# print "--> \n\n";
|
|
|
209 |
#
|
|
|
210 |
# print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
|
|
|
211 |
|
|
|
212 |
|
|
|
213 |
#------------------
|
|
|
214 |
|
|
|
215 |
|
|
|
216 |
if ($FORM{autoload}) # Toggle the autoload fields within the table elements
|
|
|
217 |
{ $auto = "onClick='submit();'";
|
|
|
218 |
$auto2 = "onChange='submit();'"; }
|
|
|
219 |
else
|
|
|
220 |
{ $auto = "";
|
|
|
221 |
$auto2 = ""; }
|
|
|
222 |
|
|
|
223 |
|
|
|
224 |
my $signedOnAs = $username ? "You are currently signed in as $username. <font size=-2><a href='index.pl' onClick=\"document.cookie = 'RCAUTH=; expires=Thu, 01 Jan 1970 00:00:01 GMT; path=/';return true;\">[Log Out]</a></font>" : "You are not signed in.";
|
|
|
225 |
my $xlsLink = $filename ? " <A href='$filename'><FONT color='#0077BD'>Download Now.</FONT></a>" : "";
|
|
|
226 |
my $yearoptions;
|
|
|
227 |
foreach (@{&getYears()}) {
|
|
|
228 |
$yearoptions .= $YEAR eq $_ ? "<option selected>$_</option>" : "<option>$_</option>";
|
|
|
229 |
}
|
|
|
230 |
|
|
|
231 |
print<<header;
|
|
|
232 |
<html><head><title>RollerCon Officials Schedule Manager - $YEAR Track Leads</title></head>
|
|
|
233 |
<body text="#000000" bgcolor="#FFFFFF" link="#000000" vlink="#000000" alink="#FF0000">
|
|
|
234 |
<form action="lead_shifts.pl" method=POST name=Req>
|
|
|
235 |
<input type=hidden name=excel value=0>
|
|
|
236 |
|
|
|
237 |
<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
|
|
|
238 |
<TR>
|
|
|
239 |
<TD>
|
|
|
240 |
<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
|
|
|
241 |
<TR>
|
|
|
242 |
<TD width=720 bgcolor="#0077BD" height=60><FONT color=white face=verdana size=6><i><strong> Officiating Track Lead Schedule - $YEAR</strong></i></font></TD>
|
|
|
243 |
<TD><img SRC="/images/headerblank.gif" NOSAVE height=38 width=165></TD>
|
|
|
244 |
</TR>
|
|
|
245 |
</TABLE>
|
|
|
246 |
</TD>
|
|
|
247 |
<TR>
|
|
|
248 |
<TD> </TD>
|
|
|
249 |
</TR>
|
|
|
250 |
<TR>
|
|
|
251 |
<TD>
|
|
|
252 |
<TABLE cellpadding=0 cellspacing=0 hspace=0 vspace=0 border=0>
|
|
|
253 |
<TR>
|
|
|
254 |
<TD rowspan=2 align=left width=610>
|
|
|
255 |
<TABLE border=0 cellspacing=0>
|
|
|
256 |
header
|
|
|
257 |
|
|
|
258 |
# Print the Hidden fields' check boxes
|
|
|
259 |
|
|
|
260 |
my $tc = 1;
|
|
|
261 |
foreach $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields)
|
|
|
262 |
{
|
|
|
263 |
if ($tc == 1)
|
|
|
264 |
{print "\t\t\t\t\t\t<TR>\n\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n"; $tc++;}
|
|
|
265 |
elsif ($tc == 4)
|
|
|
266 |
{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n\t\t\t\t\t\t</TR>\n"; $tc=1;}
|
|
|
267 |
else
|
|
|
268 |
{print "\t\t\t\t\t\t\t<TD width=25% nowrap><FONT face=verdana size=1><b><INPUT type=checkbox name=$field value=true $auto>$NAME{$field}</TD>\n"; $tc++;}
|
|
|
269 |
}
|
|
|
270 |
|
|
|
271 |
if ($FORM{autoload})
|
|
|
272 |
{
|
|
|
273 |
$trueChecked = "checked";
|
|
|
274 |
$falseChecked = "";
|
|
|
275 |
}
|
|
|
276 |
else
|
|
|
277 |
{
|
|
|
278 |
$trueChecked = "";
|
|
|
279 |
$falseChecked = "checked";
|
|
|
280 |
}
|
|
|
281 |
|
|
|
282 |
print<<header3;
|
|
|
283 |
<TR>
|
|
|
284 |
<TD colspan=4 align=center><FONT face=verdana size=1 color=#0077BD><B>
|
|
|
285 |
Autoload: <INPUT type=radio name=autoload value=1 onClick='Req.submit();' $trueChecked>On <INPUT type=radio name=autoload value=0 onClick='Req.submit();' $falseChecked>Off
|
|
|
286 |
</TD>
|
|
|
287 |
</TR>
|
|
|
288 |
</TABLE>
|
|
|
289 |
</TD>
|
|
|
290 |
<TD nowrap>
|
|
|
291 |
<A HREF='' onClick="window.document.Req.submit(); return false;"><IMG SRC='/images/refresh.button.gif' border=0></A><br>
|
|
|
292 |
<strong><a href='' onClick="window.document.Req.excel.value=1; window.document.Req.submit(); return false;"><FONT face=verdana size=1>Export Displayed Data as Excel Document.</a>$xlsLink</font>
|
|
|
293 |
</TD>
|
|
|
294 |
</TR>
|
|
|
295 |
<TR>
|
|
|
296 |
<TD align=left><B><FONT face=verdana size=1>$signedOnAs<br>
|
|
|
297 |
Display <A HREF='' onClick="window.document.Req.method = 'GET'; window.document.Req.submit(); return false;">Full URL</a> : <select name=year onchange='Req.submit();'>$yearoptions</select> : <a href=/schedule/>[Go HOME]</a></TD>
|
|
|
298 |
</TR>
|
|
|
299 |
|
|
|
300 |
</TABLE>
|
|
|
301 |
</TD>
|
|
|
302 |
</TR>
|
|
|
303 |
<TR>
|
|
|
304 |
<TD> </TD>
|
|
|
305 |
</TR>
|
|
|
306 |
<TR>
|
|
|
307 |
<TD>
|
|
|
308 |
<TABLE border=0 cellspacing=2 cellpadding=4 width=100\%>
|
|
|
309 |
<TR bgcolor=#0077BD>
|
|
|
310 |
header3
|
|
|
311 |
|
|
|
312 |
# Print the Column headings
|
|
|
313 |
foreach $f (@displayFields)
|
|
|
314 |
{ print "\t\t\t\t\t<TD align=left nowrap><FONT face=verdana color=white size=1><B><INPUT type=checkbox name=$f value=true checked $auto>$NAME{$f}</TD>\n"; }
|
|
|
315 |
|
|
|
316 |
print "\t\t\t\t</TR>\n\t\t\t\t<TR>\n";
|
|
|
317 |
# and now the filter boxes
|
|
|
318 |
|
|
|
319 |
foreach $f (@displayFields)
|
|
|
320 |
{
|
|
|
321 |
print "\t\t\t\t\t<TD align=left bgcolor=#E6E6E6><FONT size=1 face=verdana>";
|
|
|
322 |
print &generica($f);
|
|
|
323 |
# print " ";
|
|
|
324 |
print "</TD>\n";
|
|
|
325 |
}
|
|
|
326 |
print "\t\t\t\t</TR></FORM>\n";
|
|
|
327 |
|
|
|
328 |
my $cw = scalar @displayFields;
|
|
|
329 |
|
|
|
330 |
print<<header2;
|
|
|
331 |
</TR>
|
|
|
332 |
<TR>
|
|
|
333 |
<TD colspan=$cw><P><P></TD>
|
|
|
334 |
</TR>
|
|
|
335 |
header2
|
|
|
336 |
|
|
|
337 |
|
|
|
338 |
my $co = '#FFFFFF';
|
|
|
339 |
|
|
|
340 |
foreach $t (@ProductList) # Unt now we print the tickets!
|
|
|
341 |
{
|
|
|
342 |
if ($t->{assignee_id} == $RCid or ($LVL >= 3 and $t->{derby_name})) {
|
|
|
343 |
$t->{derby_name} = "$t->{derby_name} <A HREF='#' onClick=\"window.open('make_lead_shift_change.pl?change=del&shift=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[DROP]</a>";
|
|
|
344 |
} elsif (!$t->{derby_name}) {
|
|
|
345 |
$t->{derby_name} = "<A HREF='#' onClick=\"window.open('make_lead_shift_change.pl?change=add&shift=$t->{id}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[SIGN UP]</a>";
|
|
|
346 |
}
|
|
|
347 |
|
|
|
348 |
|
|
|
349 |
print "\t\t\t\t<TR>\n";
|
|
|
350 |
foreach $f (@displayFields)
|
|
|
351 |
{
|
|
|
352 |
$f =~ s/^HOST\.//;
|
|
|
353 |
$f =~ s/^FRAME\.//;
|
|
|
354 |
print "\t\t\t\t\t<TD align=left valign=top bgcolor='$co'><FONT face=verdana size=1>".$t->{$f}." </TD>\n";
|
|
|
355 |
}
|
|
|
356 |
print "\t\t\t\t</TR>\n";
|
|
|
357 |
|
|
|
358 |
if ($co eq '#FFFFFF')
|
|
|
359 |
{ $co = '#F9F9F9'; }
|
|
|
360 |
else
|
|
|
361 |
{ $co = '#FFFFFF'; }
|
|
|
362 |
|
|
|
363 |
}
|
|
|
364 |
|
|
|
365 |
print<<tail;
|
|
|
366 |
</TABLE>
|
|
|
367 |
</TD>
|
|
|
368 |
</TR>
|
|
|
369 |
</TABLE>
|
|
|
370 |
<br><br>
|
|
|
371 |
<FONT face=verdana size=2><B>$x Record(s) Displayed</font>
|
|
|
372 |
<BR><BR>
|
|
|
373 |
<FONT face=verdana size=1><B>This page was displayed on $now<BR>
|
|
|
374 |
Please direct questions, problems, and concerns to <FONT face=verdana color=#0077BD>officials.rollercon.schedule\@gmail.com</FONT>
|
|
|
375 |
|
|
|
376 |
<SCRIPT language="JavaScript">
|
|
|
377 |
<!--
|
|
|
378 |
|
|
|
379 |
var ticket_window, severity_window, user_window;
|
|
|
380 |
|
|
|
381 |
function NewWindow () {
|
|
|
382 |
if ((ticket_window == null) || (ticket_window.closed == true))
|
|
|
383 |
ticket_window = open(\"\",\"Details\",\"width=650,height=650,menubar,scrollbars,resizable\");
|
|
|
384 |
ticket_window.focus();
|
|
|
385 |
return true;
|
|
|
386 |
}
|
|
|
387 |
|
|
|
388 |
function SevWindow () {
|
|
|
389 |
if ((severity_window == null) || (severity_window.closed == true))
|
|
|
390 |
severity_window = open(\"\",\"SevDetails\",\"width=500,height=300,menubar\");
|
|
|
391 |
severity_window.focus();
|
|
|
392 |
return true;
|
|
|
393 |
}
|
|
|
394 |
|
|
|
395 |
function UserWindow () {
|
|
|
396 |
if ((user_window == null) || (user_window.closed == true))
|
|
|
397 |
user_window = open(\"\",\"UserDetails\",\"width=310,height=115,menubar\");
|
|
|
398 |
user_window.focus();
|
|
|
399 |
return true;
|
|
|
400 |
}
|
|
|
401 |
|
|
|
402 |
//-->
|
|
|
403 |
</SCRIPT>
|
|
|
404 |
|
|
|
405 |
tail
|
|
|
406 |
|