Subversion Repositories PEEPS

Rev

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

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