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 () || 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 = "PEEPS - People";
23
our $DBTABLE = 'full_person';
24
my %COLUMNS = (
25
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
26
  id                => [qw(ID           5    number      default )],
27
  email             => [qw(Email       10    text                )],
28
  name_first        => [qw(FirstName   15    text        default )],
29
  name_middle       => [qw(MiddleName  20    text                )],
30
  name_last         => [qw(LastName    25    text        default )],
31
  derby_name        => [qw(DerbyName   30    text        default )],
32
  derby_short_name  => [qw(Nickname    35    text                )],
33
  pronouns          => [qw(Pronouns    40    select              )],
34
  birthdate         => [qw(BDay        45    date                )],
35
  active            => [qw(Active      50    select      default )],
36
  league_id         => [qw(LeagueID    51    number       )],
37
  league_name       => [qw(League      52    select       )],
38
  role              => [qw(Role        53    text        default )],
39
  policy_id         => [qw(Policy      54    number      default )],
40
  created           => [qw(Created     55    date        default )],
41
  updated           => [qw(Updated     60    date        default )],
42
);
43
 
44
# Set any custom "where" DB filters here...
45
my @whereClause;
46
 
47
# Only let users see people from leagues where they're a League Admin (unless they're a SysAdmin)
48
my $org = getLeagueAffiliation ($ORCUSER->{person_id});
49
#use Data::Dumper; warn Dumper $org;
50
push @whereClause, "league_id in (".join (", ", grep { inArray ("League Admin", $org->{$_}) } keys %{$org}).")" unless $ORCUSER->{SYSADMIN};
51
#warn @whereClause;
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
 
59
sub filter_league_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
    } elsif ($filter eq "<-not blank->") {
68
      return "$colName <> \"\" and isnull($colName) = 0";
69
    } elsif ($filter eq "<-Member League->") {
70
      return "$colName in (select distinct $colName from organization where type = 'member league')";
71
    } elsif ($filter eq "<-Non-Member League->") {
72
      return "$colName in (select distinct $colName from organization where type = 'Non-Member League')";
73
    } else {
74
      return "$colName = \"$filter\"";
75
    }
76
  } else {
77
    my $Options = $ORCUSER->{SYSADMIN} ?
78
         $h->option ("", "<-blank->", "<-not blank->", "<-Member League->", "<-Non-Member League->", @{ $dbh->selectall_arrayref ("select distinct league_name from organization order by league_name") })
79
       : $h->option ("", @{ $dbh->selectall_arrayref ("select distinct league_name from full_person where id = ? and role like ? order by league_name", undef, $ORCUSER->{person_id}, '%League Admin%') });
80
 
81
    my $tmpfilter = getFilterValue ($colName);
82
 
83
    $Options =~ s/>($tmpfilter)/ selected>$1/;
84
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
85
  }
86
}
87
 
88
# Uncomment and update if we want to enable clicking on a row to open a new page.
89
#
90
sub addRowClick {
91
  my $t = shift;
92
  return "location.href='view_user?person_id=$t->{id}&choice=View'";
93
}
94
 
95
# Call the function to print the table view page (with available options)
96
printTablePage ({ Title     => $pageTitle,
97
#                  Prefs     => $prefscookie,
98
                  Table     => $DBTABLE,
99
                  Columns   => \%COLUMNS,
100
                  PEEPSAuth => $PEEPSAUTH_cookie,
101
                  Where     => join (" and ", @whereClause),
102
#                  HeaderButton       => { field  => "id",
103
#                                          button => $h->input ({ type=>"button", value=>"Add", onClick=>"window.location.href='view_game'" }) }
104
               });
105