Subversion Repositories VORC

Rev

Rev 196 | 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 cPanelUserConfig;
use CGI qw/param cookie header start_html url/;
use HTML::Tiny;
use tableViewer;
use RollerCon;
our $h = HTML::Tiny->new( mode => 'html' );

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

my $pageTitle = "MVP Pass Tickets";
our $DBTABLE = 'v_ticket';
my %COLUMNS = (
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
  id          => [qw(MVPid         5    text      default )],
  event_name  => [qw(Event        10    text         )],
  order_date  => [qw(PurchaseDate 15    date        default )],
  ticket_type => [qw(TicketType   20    select              )],
  full_name   => [qw(MVPFullName     25    text       default         )],
  email       => [qw(MVPEmail        30    text       default         )],
  derby_name  => [qw(MVPDerbyName    35    text       default )],
  RCid        => [qw(RCID         40    select      default )],
  vorc_full_name   => [qw(VORCFullName     45    text       default         )],
  vorc_email       => [qw(VORCEmail        50    text       default         )],
  vorc_derby_name  => [qw(VORCDerbyName    55    text       default )],
);

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

# If we need to modify line item values, create a subroutine named "modify_$columnname"
#    It will receive a hashref to the object lineitem

sub modify_RCid {
  my $t = shift;
  return $t->{RCid} if $t->{RCid};
  $t->{RCid} = "";
  
  my $dbh = getRCDBH;
  my ($match) = $dbh->selectrow_array ("select RCid from v_official where isnull(MVPid) = true and email = (select email from v_ticket where id = ?) union
    select RCid from v_official where isnull(MVPid) = true and real_name = (select full_name from v_ticket where id = ?) union
    select RCid from v_official where isnull(MVPid) = true and derby_name = (select derby_name from v_ticket where id = ?)", undef, $t->{id}, $t->{id}, $t->{id});
  
  if ($match) {
    my $tempuser = getUser $match;
    $t->{RCid} = $h->button ({ onClick=>"window.open('update_mvp_ticket.pl?change=add&RCid=$match&MVPid=$t->{id}','Change MVP Ticket','resizable,height=260,width=370'); return false;" }, "Accept $match");
    $t->{vorc_full_name}  = $h->div ({ class=>"hint", style=>"font-size:x-small" }, $tempuser->{real_name});
    $t->{vorc_email}      = $h->div ({ class=>"hint", style=>"font-size:x-small" }, $tempuser->{email});
    $t->{vorc_derby_name} = $h->div ({ class=>"hint", style=>"font-size:x-small" }, $tempuser->{derby_name});
  }
  
  return $t->{RCid};
}

sub modify_email {
  my $t = shift;
  
  if ($t->{email} and !$t->{RCid}) {
    $t->{email} = $h->a ({ href=>"/schedule/users.pl?filter-email=$t->{email}&ignoreCookie=1" }, $t->{email});
  }
  
  return $t->{email};
}

sub modify_derby_name {
  my $t = shift;
  
  if ($t->{derby_name} and !$t->{RCid}) {
    my $temp = $t->{derby_name};
    $temp =~ s/"//g;
    $t->{derby_name} = $h->a ({ href=>"/schedule/users.pl?filter-derby_name=$temp&ignoreCookie=1" }, $t->{derby_name});
  }
  
  return $t->{derby_name};
}

sub modify_full_name {
  my $t = shift;
  
  if ($t->{full_name} and !$t->{RCid}) {
    $t->{full_name} = $h->a ({ href=>"/schedule/users.pl?filter-real_name=$t->{full_name}&ignoreCookie=1" }, $t->{full_name});
  }
  
  return $t->{full_name};
}

# 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_RCid {
  my $colName = shift;
  my $filter = shift // "";
  
  if ($filter)  {
    return $filter =~ /^\d+$/ ? "$colName = $filter" : $filter eq "true" ? "isnull($colName) = 0" : "isnull($colName) = 1";
  } else {
    no strict;
    my @options = ("", "true", "-blank-");
    my $dbh = getRCDBH;
    push @options, map { @{$_} } @{$dbh->selectall_arrayref ("select distinct RCid from v_ticket where isnull(RCid) = 0 order by RCid")};
    
    @options = map { $FORM{"filter-RCid"} eq $_ ?
                       ( $h->option ({ selected=>[] }, $_) ) :
                       ( $h->option (                  $_) )  } @options;
    
    my $autoload = param ("autoload") // 1;
    return $autoload ? $h->select ({ name=>"filter-RCid", onChange=>"page.value = 1; submit();" }, [@options]) : $h->select ({ name=>"filter-RCid" }, [$h->option (), @options]);
  }
}

# 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_thing.pl?field=$t->{field}&choice=View'";
#}

# Call the function to print the table view page (with available options)
printTablePage ({ Title   => $pageTitle,
                  Table   => $DBTABLE, 
                  Columns => \%COLUMNS, 
                  RCAuth  => $RCAUTH_cookie,
                  DisplayYearSelect  => 0,
                 });