| 2 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
|
|
|
4 |
#my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
|
|
|
5 |
#close STDERR;
|
|
|
6 |
#open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
|
|
|
7 |
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
|
|
|
8 |
|
|
|
9 |
#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }
|
|
|
10 |
|
|
|
11 |
use strict;
|
|
|
12 |
use CGI qw/param cookie header start_html url/;
|
|
|
13 |
use HTML::Tiny;
|
|
|
14 |
use tableViewer;
|
|
|
15 |
use PEEPS;
|
|
|
16 |
our $h = HTML::Tiny->new( mode => 'html' );
|
| 3 |
- |
17 |
$ENV{HTTPS} = 'ON';
|
| 2 |
- |
18 |
|
|
|
19 |
my $cookie_string = authenticate (1) || die;
|
|
|
20 |
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
21 |
my $PEEPSAUTH_cookie = CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string",-expires=>"+30m");
|
|
|
22 |
|
|
|
23 |
my $pageTitle = "Org Log Viewer";
|
|
|
24 |
our $DBTABLE = 'v_org_log';
|
|
|
25 |
my %COLUMNS = (
|
|
|
26 |
# colname => [qw(DisplayName N type status)], status -> static | default | <blank>
|
|
|
27 |
eventid => [qw(EventID 5 number default )],
|
|
|
28 |
timestamp => [qw(Timestamp 10 date default )],
|
|
|
29 |
event => [qw(Event 15 text default )],
|
|
|
30 |
person_id => [qw(PEEPSID 20 number )],
|
|
|
31 |
derby_name => [qw(Actor 25 select default )],
|
|
|
32 |
organization_id => [qw(ORGID 30 number )],
|
|
|
33 |
league_name => [qw(League 35 select default )],
|
|
|
34 |
);
|
|
|
35 |
|
|
|
36 |
my @leagues = @{ isLeagueAdmin ($ORCUSER->{person_id}) };
|
|
|
37 |
|
|
|
38 |
do {
|
|
|
39 |
print header (-cookie=> [ $cookie_string, $PEEPSAUTH_cookie ] );
|
|
|
40 |
printRCHeader ("Organization Log Viewer");
|
|
|
41 |
print $h->div ({class => "error"}, "Only League Admins can view the Organization Log");
|
|
|
42 |
print $h->close ("body", "html");
|
|
|
43 |
logit ($ORCUSER->{person_id}, "Tried to view the Organization Logs and isn't a League Admin");
|
|
|
44 |
exit;
|
|
|
45 |
} unless $ORCUSER->{SYSADMIN} or scalar @leagues;
|
|
|
46 |
|
|
|
47 |
# Set any custom "where" DB filters here...
|
|
|
48 |
my @whereClause;
|
|
|
49 |
|
|
|
50 |
push @whereClause, "organization_id in (".join (", ", @leagues).")" unless $ORCUSER->{SYSADMIN};
|
|
|
51 |
|
|
|
52 |
|
|
|
53 |
# If we need to modify line item values, create a subroutine named "modify_$columnname"
|
|
|
54 |
# It will receive a hashref to the object lineitem
|
|
|
55 |
|
|
|
56 |
# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
|
|
|
57 |
# It will receive two fields, the field name and the current filter value (if any)
|
|
|
58 |
|
|
|
59 |
sub filter_derby_name {
|
|
|
60 |
my $colName = shift;
|
|
|
61 |
my $filter = shift;
|
|
|
62 |
my $dbh = getDBConnection ();
|
|
|
63 |
|
|
|
64 |
if (defined $filter) {
|
|
|
65 |
if ($filter eq "<-blank->") {
|
|
|
66 |
return "$colName = \"\" or isnull($colName) = 1";
|
|
|
67 |
} else {
|
|
|
68 |
return "$colName = \"$filter\"";
|
|
|
69 |
}
|
|
|
70 |
} else {
|
|
|
71 |
my $Options = $ORCUSER->{SYSADMIN} ?
|
|
|
72 |
$h->option ("", "<-blank->", @{ $dbh->selectall_arrayref ("select distinct derby_name from $DBTABLE where derby_name <> '' order by derby_name") })
|
|
|
73 |
: $h->option ("", @{ $dbh->selectall_arrayref ("select distinct derby_name from $DBTABLE where organization_id in (".join (", ", @leagues).") order by derby_name") });
|
|
|
74 |
|
|
|
75 |
my $tmpfilter = getFilterValue ($colName);
|
|
|
76 |
|
|
|
77 |
$Options =~ s/>($tmpfilter)/ selected>$1/;
|
|
|
78 |
return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
|
|
|
79 |
}
|
|
|
80 |
}
|
|
|
81 |
|
|
|
82 |
sub filter_league_name {
|
|
|
83 |
my $colName = shift;
|
|
|
84 |
my $filter = shift;
|
|
|
85 |
my $dbh = getDBConnection ();
|
|
|
86 |
|
|
|
87 |
if (defined $filter) {
|
|
|
88 |
if ($filter eq "<-blank->") {
|
|
|
89 |
return "$colName = \"\" or isnull($colName) = 1";
|
|
|
90 |
} else {
|
|
|
91 |
return "$colName = \"$filter\"";
|
|
|
92 |
}
|
|
|
93 |
} else {
|
|
|
94 |
my $Options = $ORCUSER->{SYSADMIN} ?
|
|
|
95 |
$h->option ("", "<-blank->", @{ $dbh->selectall_arrayref ("select distinct league_name from $DBTABLE where league_name <> '' order by league_name") })
|
|
|
96 |
: $h->option ("", sort map { getLeagueName ($_) } @leagues);
|
|
|
97 |
|
|
|
98 |
my $tmpfilter = getFilterValue ($colName);
|
|
|
99 |
|
|
|
100 |
$Options =~ s/>($tmpfilter)/ selected>$1/;
|
|
|
101 |
return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
|
|
|
106 |
# Uncomment and update if we want to enable clicking on a row to open a new page.
|
|
|
107 |
#
|
|
|
108 |
#sub addRowClick {
|
|
|
109 |
# my $t = shift;
|
|
|
110 |
# return "location.href='view_thing.pl?field=$t->{field}&choice=View'";
|
|
|
111 |
#}
|
|
|
112 |
|
|
|
113 |
# Call the function to print the table view page (with available options)
|
|
|
114 |
printTablePage ({ Title => $pageTitle,
|
|
|
115 |
# Prefs => $prefscookie,
|
|
|
116 |
Table => $DBTABLE,
|
|
|
117 |
Columns => \%COLUMNS,
|
|
|
118 |
RCAuth => $PEEPSAUTH_cookie,
|
|
|
119 |
Where => join (" and ", @whereClause),
|
|
|
120 |
DisplayYearSelect => 0,
|
|
|
121 |
ShowMyShifts => 0,
|
|
|
122 |
PersonalTimeButton => 0,
|
|
|
123 |
HighlightShifts => 0,
|
|
|
124 |
# HeaderButton => { field => "id",
|
|
|
125 |
# button => $h->input ({ type=>"button", value=>"Add", onClick=>"window.location.href='view_game.pl'" }) }
|
|
|
126 |
});
|
|
|
127 |
|