Subversion Repositories ORC

Rev

Rev 7 | Go to most recent revision | Details | Last modification | View Log | RSS feed

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