Subversion Repositories PEEPS

Rev

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