Subversion Repositories VORC

Rev

Rev 138 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 138 Rev 196
Line 16... Line 16...
16
use RollerCon;
16
use RollerCon;
17
our $h = HTML::Tiny->new( mode => 'html' );
17
our $h = HTML::Tiny->new( mode => 'html' );
Line 18... Line 18...
18
 
18
 
19
my $cookie_string = authenticate (1) || die;
19
my $cookie_string = authenticate (1) || die;
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
-
 
21
my $user = getUser ($EML);
-
 
22
my $username = $h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$user->{RCid}" }, $user->{derby_name});
-
 
23
my $RCid = $user->{RCid};
20
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
Line 24... Line -...
24
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
-
 
25
 
-
 
26
 
21
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
27
 
-
 
28
my $pageTitle = "Log Viewer";
22
 
29
my $prefscookie = "logscookie";
23
my $pageTitle = "Log Viewer";
30
our $DBTABLE = 'v_log';
24
our $DBTABLE = 'v_log';
31
my %COLUMNS = (
25
my %COLUMNS = (
32
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
26
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
33
	eventid     => [qw(EventID       5    number      default )],
27
  eventid     => [qw(EventID       5    number      default )],
34
	timestamp   => [qw(Timestamp    10    date        default )],
28
  timestamp   => [qw(Timestamp    10    date        default )],
35
	event       => [qw(Event        15    text        default )],
29
  event       => [qw(Event        15    text        default )],
36
	RCid        => [qw(RCID         20    number      default )],
30
  RCid        => [qw(RCID         20    number      default )],
37
	derby_name  => [qw(DerbyName    25    select      default )],
31
  derby_name  => [qw(DerbyName    25    select      default )],
38
	email       => [qw(Email        30    text                )],
32
  email       => [qw(Email        30    text                )],
39
	real_name   => [qw(FullName     35    text                )],
33
  real_name   => [qw(FullName     35    text                )],
40
	access      => [qw(Role         40    select              )]
-
 
41
);
-
 
42
my $stylesheet = "/style.css";
-
 
43
my $homeURL = '/schedule/';
-
 
44
my @pagelimitoptions = ("All", 5, 10, 25);
-
 
Line -... Line 34...
-
 
34
  access      => [qw(Role         40    select              )]
-
 
35
);
-
 
36
 
Line 45... Line 37...
45
my @whereClause;
37
my @whereClause;
46
push @whereClause, "RCid = $RCid" unless $LVL > 2;
38
# Unless they're a manager or higher, users should only see their own logs.
Line 47... Line 39...
47
 
39
push @whereClause, "RCid = $ORCUSER->{RCid}" unless $LVL > 2;
48
 
40
 
49
# If we need to modify line item values, create a subroutine named "modify_$columnname"
41
# If we need to modify line item values, create a subroutine named "modify_$columnname"
50
#    It will receive a hashref to the object lineitem
42
#    It will receive a hashref to the object lineitem
Line -... Line 43...
-
 
43
 
-
 
44
sub modify_derby_name {
Line 51... Line -...
51
 
-
 
52
sub modify_derby_name {
-
 
53
  my $li = shift;
-
 
54
  return $h->a ({ href=>"view_user.pl?RCid=$li->{RCid}" }, $li->{derby_name});
-
 
55
}
-
 
56
 
-
 
57
 
-
 
58
 
-
 
59
# Ideally, nothing below this comment needs to change
-
 
60
#-------------------------------------------------------------------------------
-
 
61
 
-
 
62
 
-
 
63
our %NAME              = map  { $_ => $COLUMNS{$_}->[0] } keys %COLUMNS;
-
 
64
our %colOrderHash      = map  { $_ => $COLUMNS{$_}->[1] } keys %COLUMNS;
-
 
65
our %colFilterTypeHash = map  { $_ => $COLUMNS{$_}->[2] } keys %COLUMNS;
-
 
66
our @staticFields      = sort byfield grep { $COLUMNS{$_}->[3] eq 'static' } keys %COLUMNS;
-
 
67
our @defaultFields     = sort byfield grep { defined $COLUMNS{$_}->[3] } keys %COLUMNS;
-
 
68
#our @defaultFields     = grep { $COLUMNS{$_}->[3] eq 'default' or inArray ($_, \@staticFields) } keys %COLUMNS;
-
 
69
 
-
 
70
our @allFields = sort byfield keys %NAME;
-
 
71
our @displayFields = ();
-
 
72
our @hideFields = ();
-
 
73
my $QUERY_STRING;
-
 
74
 
-
 
75
my $pagelimit = param ("limit") // $pagelimitoptions[$#pagelimitoptions];
-
 
76
my $curpage = param ("page") // 1;
-
 
77
 
-
 
78
our %FORM;
-
 
79
my $FILTER;
-
 
80
foreach (param()) {
-
 
81
	$FORM{$_} = param($_);				# Retrieve all of the FORM data submitted
-
 
82
	
-
 
83
	if ((/^filter/) and ($FORM{$_} ne '')) {	# Build a set of filters to apply
-
 
84
		my ($filter,$field) = split /-/, $_;		
-
 
85
		$FILTER->{$field} = $FORM{$_} unless notInArray ($field, \@allFields);
-
 
86
	}	elsif ($FORM{$_} eq "true")			# Compile list of fields to display
-
 
87
		{ push @displayFields, $_; }
-
 
88
}
-
 
89
 
-
 
90
 
-
 
91
if (exists $FORM{autoload})	{			# If the FORM was submitted (i.e. the page is being redisplayed),
-
 
92
							                    #  	build the data for the cookie that remembers the page setup
-
 
93
	my $disFields = join ":", @displayFields;
-
 
94
	my $fils = join ":", map { "$_=$FILTER->{$_}" } keys %{$FILTER};
-
 
95
		
-
 
96
	$QUERY_STRING = $disFields.'&'.$fils.'&'.$FORM{sortby}.'&'.$FORM{autoload};
-
 
97
}
-
 
98
 
-
 
99
 
-
 
100
if (!(exists $FORM{autoload}))	{			# No FORM was submitted...
-
 
101
	if (my $prefs = cookie ($prefscookie) and !defined param ("ignoreCookie"))	{ # Check for cookies from previous visits.
-
 
102
		my ($disF, $filts, $sb, $al) = split /&/,$prefs;
-
 
103
		@displayFields = split /:/,$disF;
-
 
104
		
-
 
105
		foreach my $pair (split /:/, $filts)	{
-
 
106
			my ($key, $value) = split /=/, $pair;
-
 
107
			$FORM{"filter-$key"} = $value;
-
 
108
			$FILTER->{$key} = $value;
-
 
109
		}
-
 
110
		
-
 
111
		$FORM{sortby} = $sb;
-
 
112
		$FORM{autoload} = $al;
-
 
113
		$QUERY_STRING = $prefs;
-
 
114
	}	else {
-
 
115
	  @displayFields = @defaultFields; # Otherwise suppply a default list of columns.
-
 
116
	  $FORM{autoload} = 1;             # And turn aut0load on by default.
-
 
117
	} 
-
 
118
}
-
 
119
 
-
 
120
# let's just make sure the columns are in the right order (and there aren't any missing)
-
 
121
@displayFields = grep { inArray($_, \@allFields) } sort byfield uniq @displayFields, @staticFields;
-
 
122
 
-
 
123
# If the field isn't in the displayFields list,	then add it to the hideFields list
-
 
124
@hideFields = grep { notInArray ($_, \@displayFields) } @allFields;
-
 
125
 
-
 
126
# Process any filters provided in the form to pass to the database
-
 
127
@whereClause = map { filter ($_, $FILTER->{$_}) } grep { defined $FILTER->{$_} } @displayFields;
-
 
128
push @whereClause, "RCid = $RCid" unless $LVL > 2;
-
 
129
 
-
 
130
							#  Given the fields to display and the where conditions,
-
 
131
							#	  "getData" will return a reference to an array of
-
 
132
							#	  hash references of the results.
-
 
133
my ($data, $datacount) = getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit);
-
 
134
my @ProductList = @{ $data };
-
 
135
 
-
 
136
#my @ProductList = @{ getData (\@displayFields, \@whereClause, $DBTABLE, $FORM{sortby}, $curpage, $pagelimit) };
-
 
137
my $x = scalar @ProductList; # How many results were returned?
-
 
138
 
-
 
139
# If the user is trying to download an excel export, create the file...
-
 
140
my $filename = $FORM{excel} ? exportExcel (\@ProductList) : "";
-
 
141
my $signedOnAs = $username ? "Welcome, $username. ".$h->a ({ href=>"index.pl?LOGOUT" }, "[Log Out]") : "You are not signed in.";
-
 
142
my $xlsLink = $filename ? "&nbsp; &nbsp; ".$h->a ({ href=>$filename }, "[Download Now]") : "";
-
 
143
 
-
 
144
# Set some cookie stuff...
-
 
145
my $path = `dirname $ENV{SCRIPT_NAME}`; chomp $path; $path .= '/' unless $path eq "/";
-
 
146
my $queryCookie = cookie(-NAME=>$prefscookie,
-
 
147
			-VALUE=>"$QUERY_STRING",
-
 
148
			-PATH=>"$path",
-
 
149
			-EXPIRES=>'+365d');
-
 
150
 
-
 
151
print header (-cookie=> [ $queryCookie, $RCAUTH_cookie ] );
-
 
152
 
-
 
153
# 	print "<!-- FORM \n\n";				# Debug code to dump the FORM to a html comment
-
 
154
#	print "I'm catching updates!!!\n\n";
-
 
155
#	foreach $key (sort (keys %FORM))		#	Must be done after the header is written!
-
 
156
# 		{ print "\t$key:  $FORM{$key}\n"; }
-
 
157
# 	print "--> \n\n";
-
 
158
# 	
-
 
159
# 
-
 
160
# 	print "<!-- ENV \n\n";				# Debug code to dump the ENV to a html comment
-
 
161
# 	foreach $key (sort (keys %ENV))			#	Must be done after the header is written!
-
 
162
# 		{ print "\t$key:  $ENV{$key}\n"; }
-
 
163
# 	print "--> \n\n";
-
 
164
# 
-
 
165
# 	print "\n\n\n\n<!-- $QUERY_STRING --> \n\n\n\n";
-
 
166
 
-
 
167
 
-
 
168
#------------------
-
 
169
 
-
 
170
# Toggle the autoload fields within the table elements 
-
 
171
our ($onClick, $onChange);   # (also used in scanFunctions)
-
 
172
my ($radiobutton, $refreshbutton, $sortby);
-
 
173
if ($FORM{autoload}) {					  
-
 
174
	$onClick = "onClick='submit();'";
-
 
175
	$onChange = "onChange='submit();'";
-
 
176
  $radiobutton = $h->div ({ class=>'autoload' },
-
 
177
    ["Autoload Changes: ",
-
 
178
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();', checked=>[] }), "On ", 
-
 
179
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();' }), "Off ",
-
 
180
    ]);
-
 
181
  $refreshbutton = "";
-
 
182
  $sortby = $h->select ({name=>"sortby", onChange=>'submit();' }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
-
 
183
} else {
-
 
184
  $onClick = "";
-
 
185
	$onChange = "";
-
 
186
  $radiobutton = $h->div ({ class=>'autoload' }, 
-
 
187
    ["Autoload Changes: ",
-
 
188
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>1, onClick=>'submit();' }), "On ", 
-
 
189
    $h->input ({ type=>"radio", name=>'autoload', class=>'accent', value=>0, onClick=>'submit();', checked=>[] }), "Off ",
-
 
190
    ]);
-
 
191
  $refreshbutton = $h->input ({ type=>"button", value=>"Refresh", onClick=>"submit(); return false;" });
-
 
192
  $sortby = $h->select ({name=>"sortby" }, [ map { $FORM{sortby} eq $_ ? $h->option ({ value=>$_, selected=>[] }, $NAME{$_}) : $h->option ({ value=>$_ }, $NAME{$_}) } @displayFields ]);
-
 
193
}
-
 
194
 
-
 
195
 
-
 
196
 
-
 
197
	 
-
 
198
print start_html (-title => $pageTitle, -style => {'src' => $stylesheet} );
-
 
199
 
-
 
200
# Print the header
-
 
201
 
-
 
202
print $h->open ('form', { action=>url, method=>'POST', name=>'Req' });
-
 
203
print $h->input ({ type=>"hidden", name=>"excel", value=>0 });
-
 
204
print $h->div ({ class => "accent pageheader" }, [
-
 
205
  $h->h1 ($pageTitle),
-
 
206
  $h->div ({ class=>"sp0" }, [
-
 
207
    $h->div ({ class=>"spLeft" }, [
-
 
208
      $radiobutton
-
 
209
    ]),
-
 
210
    $h->div ({ class=>"spRight" }, [
-
 
211
      $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
-
 
212
      $refreshbutton
-
 
213
    ]),
-
 
214
  ]),
-
 
215
]);
-
 
216
 
-
 
217
# Print the Hidden fields' check boxes (if there are any)
-
 
218
 
-
 
219
my $c = 1;
-
 
220
my @hiddencheckboxes;
-
 
221
my @hiddenrows;
-
 
222
foreach my $field (sort { $NAME{$a} cmp $NAME{$b}; } @hideFields) {
-
 
223
  if ($FORM{autoload}) {
-
 
224
    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} ]);
-
 
225
  } else {
-
 
226
    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} ]);
-
 
227
  }
-
 
228
  if ($c++ % 4 == 0) {
-
 
229
    push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]);
-
 
230
    @hiddencheckboxes = [];
-
 
231
  }
-
 
232
}
-
 
233
push @hiddenrows, $h->div ({ class=>'rTableRow' }, [ @hiddencheckboxes ]) unless --$c % 4 == 0;
-
 
234
 
-
 
235
 
-
 
236
if (scalar @hideFields) {
-
 
237
  my @topleft;
-
 
238
  push @topleft, $h->div ({ class=>"nowrap" }, "Hidden Columns:");
-
 
239
  push @topleft, $h->div ({ class=>'rTable' }, [ @hiddenrows ]);
-
 
240
  
-
 
241
  print $h->div ({ class=>"sp0" }, [
-
 
242
    $h->div ({ class=>"spLeft"  }, [ @topleft ]),
-
 
243
    $h->div ({ class=>"spRight" }, [
-
 
244
      $signedOnAs
-
 
245
    ])
-
 
246
  ]);
-
 
247
}
-
 
248
 
-
 
249
# Print the main table...............................................
-
 
250
 
-
 
251
print $h->open ('div', { class=>'rTable' });
-
 
252
 
-
 
253
my @tmptitlerow;
-
 
254
foreach my $f (@displayFields)	{  # Print the Column headings
-
 
255
  if (inArray ($f, \@staticFields)) {
-
 
256
    push @tmptitlerow, $h->div ({ class=>'rTableHead' }, [ $h->input ({ type=>"hidden", name=>$f, value=>"true" }), $NAME{$f} ]);
-
 
257
  } else {
-
 
258
    if ($FORM{autoload}) {
-
 
259
      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} ]);
-
 
260
    } else {
-
 
261
      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} ]);      
-
 
262
    }
-
 
263
  }
-
 
264
}
-
 
265
 
-
 
266
my @tmpfilters;
-
 
267
foreach my $f (@displayFields) {  # and now the filter boxes
-
 
268
  push @tmpfilters, $h->div ({ class=>'rTableCell filters' }, filter ($f) )
-
 
269
}
-
 
270
 
-
 
271
print $h->div ({ class=>'rTableHeading' }, [ @tmptitlerow ], [ @tmpfilters ], $h->div ({ class=>"rTableCell" }));
-
 
272
 
-
 
273
foreach my $t (@ProductList)	{		# Unt now we print the things!
-
 
274
  my @tmprow;
-
 
275
	foreach my $f (@displayFields)
-
 
276
		{
-
 
277
		  $t->{$f} = "" unless $t->{$f}; # HTML::Tiny throws a warning for null fields from the DB, so give it an empty string instead
-
 
278
		  # Look to see if there's a function named modify_<fieldname>() defined for this field
-
 
279
		  no strict;
-
 
280
		  if (exists &{"modify_".$f}) {
-
 
281
		    $t->{$f} = &{"modify_".$f} ($t);
-
 
282
		  } 
-
 
283
		  
-
 
284
		  push @tmprow, $h->div ({ class=>'rTableCell' }, $t->{$f});
-
 
285
		}
-
 
286
  print $h->div ({ class=>'rTableRow shaded' }, [ @tmprow ]);
-
 
287
}
-
 
288
 
-
 
289
print $h->close ('div');
-
 
290
 
-
 
291
# close things out................................................
-
 
292
 
-
 
293
my $pages = $pagelimit eq "All" ? 1 : int( $datacount / $pagelimit + 0.99 );
-
 
294
if ($curpage > $pages) { $curpage = $pages; }
-
 
295
 
-
 
296
my @pagerange;
-
 
297
if ($pages <= 5 ) {
-
 
298
  @pagerange = 1 .. $pages;
-
 
299
} else {  
-
 
300
  if ($curpage <= 3) {
-
 
301
    @pagerange = (1, 2, 3, 4, ">>");
-
 
302
  } elsif ($curpage >= $pages - 2) {
-
 
303
    @pagerange = ("<<", $pages-3, $pages-2, $pages-1, $pages);
-
 
304
  } else {
-
 
305
    @pagerange = ("<<", $curpage-1, $curpage, $curpage+1, ">>");
-
 
306
  }
-
 
307
}
-
 
308
 
-
 
309
print $h->br; # print $h->br;
-
 
310
print $h->div ({ class=>"sp0" }, [
-
 
311
    $h->div ({ class=>"spLeft" }, [
-
 
312
      $h->div ({ class=>"footer" }, [
-
 
313
        "To bookmark, save, or send this exact view, use the ",
-
 
314
        $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
-
 
315
        $h->br,
-
 
316
        "If this page is displaying oddly, ", $h->a ({ href=>url ()."?ignoreCookie=1" }, "[Reset Your View]"),
-
 
317
        $h->br,
-
 
318
        $h->a ({ href=>"", onClick=>"window.document.Req.excel.value=1; window.document.Req.submit(); return false;" }, "[Export Displayed Data as an Excel Document.]")."&nbsp;&nbsp;".$xlsLink,
-
 
319
        $h->br,
-
 
320
        "This page was displayed on ", currentTime (),
-
 
321
        $h->br,
-
 
322
        "Please direct questions, problems, and concerns to $SYSTEM_EMAIL"
-
 
323
      ])
-
 
324
    ]),
-
 
325
    $h->div ({ class=>"spRight" }, [
-
 
326
      $h->h5 ([
-
 
327
               "$x of $datacount Record". ($x == 1 ? "" : "s") ." Displayed", $h->br,               
-
 
328
               "Sorted by ", $sortby, $h->br,
-
 
329
               "Displaying ", $h->select ({ name=>"limit", onChange=>"page.value = 1; submit();" }, [ map { $pagelimit == $_ ? $h->option ({ selected=>[] }, $_) : $h->option ($_) } @pagelimitoptions ]), " Per Page", $h->br,
-
 
330
               ( $pages > 1 ? ( join " ", map { $_ == $curpage ? "<B>$_</b>" :
-
 
331
                                                $_ eq "<<"     ? $h->a ({ onClick=>qq{Req.page.value=1; Req.submit();} }, "$_") :
-
 
332
                                                $_ eq ">>"     ? $h->a ({ onClick=>qq{Req.page.value=$pages; Req.submit();} }, "$_") :
-
 
333
                                                                 $h->a ({ onClick=>qq{Req.page.value=$_; Req.submit();} }, "[$_]") } @pagerange ) : "" ), $h->br,
-
 
334
               $h->input ({ type=>"hidden", name=>"page", value=>$curpage })
-
 
335
      ])
-
 
336
    ]),
-
 
337
]);
-
 
338
 
-
 
339
#print $h->br; # print $h->br;
-
 
340
#print $h->h5 ("$x Record(s) Displayed");
-
 
341
#print $h->div ({ class=>"footer" }, [
-
 
342
#  "To bookmark, save, or send this exact view, use the ",
-
 
343
#  $h->a ({ href=>'', onClick=>"window.document.Req.method = 'GET'; Req.submit(); return false;" }, "[Full URL]"),
-
 
344
#  $h->br,
-
 
345
#  "This page was displayed on $now",
-
 
346
#  $h->br,
45
  my $li = shift;
-
 
46
  return $h->a ({ href=>"view_user.pl?RCid=$li->{RCid}" }, $li->{derby_name});
-
 
47
}
-
 
48
 
-
 
49
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
-
 
50
#    It will receive two fields, the field name and the current filter value (if any)
-
 
51
 
-
 
52
# Uncomment and update if we want to enable clicking on a row to open a new page.
-
 
53
#
-
 
54
#sub addRowClick {
-
 
55
#  my $t = shift;
-
 
56
#  return "location.href='view_thing.pl?field=$t->{field}&choice=View'";
-
 
57
#}
-
 
58
 
-
 
59
# Call the function to print the table view page (with available options)
-
 
60
printTablePage ({ Title   => $pageTitle,