Subversion Repositories PEEPS

Rev

Rev 2 | Rev 4 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | RSS feed

#!/usr/bin/perl

# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
#my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
#close STDERR;
#open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
#warn "Redirecting errors to ${error_log_path}vorc_error.log";

#if ($ENV{SHELL}) { die "This script shouldn't be executed from the command line!\n"; }

use strict;
use CGI qw/param cookie header start_html url/;
use HTML::Tiny;
use tableViewer;
use PEEPS;
our $h = HTML::Tiny->new( mode => 'html' );
$ENV{HTTPS} = 'ON';

my $cookie_string = authenticate () || die;
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $PEEPSAUTH_cookie = CGI::Cookie->new(-name=>'PEEPSAUTH',-value=>"$cookie_string",-expires=>"+30m");

my $pageTitle = "PEEPS - People";
our $DBTABLE = 'full_person';
my %COLUMNS = (
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
  id                => [qw(ID           5    number      default )],
  email             => [qw(Email       10    text                )],
  name_first        => [qw(FirstName   15    text        default )],
  name_middle       => [qw(MiddleName  20    text                )],
  name_last         => [qw(LastName    25    text        default )],
  derby_name        => [qw(DerbyName   30    text        default )],
  derby_short_name  => [qw(Nickname    35    text                )],
  pronouns          => [qw(Pronouns    40    select              )],
  birthdate         => [qw(BDay        45    date                )],
  active            => [qw(Active      50    select      default )],
  league_id         => [qw(LeagueID    51    number       )],
  league_name       => [qw(League      52    select       )],
  role              => [qw(Role        53    text        default )],
  policy_id         => [qw(Policy      54    number      default )],
  created           => [qw(Created     55    date        default )],
  updated           => [qw(Updated     60    date        default )],
);

# Set any custom "where" DB filters here...
my @whereClause;

# Only let users see people from leagues where they're a League Admin (unless they're a SysAdmin)
my $org = getLeagueAffiliation ($ORCUSER->{person_id});
#use Data::Dumper; warn Dumper $org;
push @whereClause, "league_id in (".join (", ", grep { inArray ("League Admin", $org->{$_}) } keys %{$org}).")" unless $ORCUSER->{SYSADMIN};
#warn @whereClause;
# If we need to modify line item values, create a subroutine named "modify_$columnname"
#    It will receive a hashref to the object lineitem

# If we need to modify how a filter works, create a subroutine named "filter_$columnname"
#    It will receive two fields, the field name and the current filter value (if any)


sub filter_league_name {
  my $colName = shift;
  my $filter = shift;
  my $dbh = getDBConnection ();
  
  if (defined $filter)  {
    if ($filter eq "<-blank->") {
      return "$colName = \"\" or isnull($colName) = 1";
    } elsif ($filter eq "<-not blank->") {
      return "$colName <> \"\" and isnull($colName) = 0";
    } elsif ($filter eq "<-Member League->") {
      return "$colName in (select distinct $colName from organization where type = 'member league')";
    } elsif ($filter eq "<-Non-Member League->") {
      return "$colName in (select distinct $colName from organization where type = 'Non-Member League')";
    } else {
      return "$colName = \"$filter\"";      
    }
  } else {    
    my $Options = $ORCUSER->{SYSADMIN} ?
         $h->option ("", "<-blank->", "<-not blank->", "<-Member League->", "<-Non-Member League->", @{ $dbh->selectall_arrayref ("select distinct league_name from organization order by league_name") })
       : $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%') });
    
    my $tmpfilter = getFilterValue ($colName);
    
    $Options =~ s/>($tmpfilter)/ selected>$1/;
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
  }
}

# Uncomment and update if we want to enable clicking on a row to open a new page.
#
sub addRowClick {
  my $t = shift;
  return "location.href='view_user?person_id=$t->{id}&choice=View'";
}

# Call the function to print the table view page (with available options)
printTablePage ({ Title     => $pageTitle,
#                  Prefs     => $prefscookie,
                  Table     => $DBTABLE,
                  Columns   => \%COLUMNS,
                  PEEPSAuth => $PEEPSAUTH_cookie,
                  Where     => join (" and ", @whereClause),
#                  HeaderButton       => { field  => "id",
#                                          button => $h->input ({ type=>"button", value=>"Add", onClick=>"window.location.href='view_game'" }) }
               });