Subversion Repositories VORC

Rev

Blame | 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;
use DateTime;
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
our $h = HTML::Tiny->new( mode => 'html' );

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

my $pageTitle = "Seminars";
our $DBTABLE = 'v_seminar_new';
my %COLUMNS = (
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
  name        => [qw(Seminar         5    text     static )],
  date        => [qw(Date         10    date              )],
  dayofweek   => [qw(Day          15    select    default )],
  start_time  => [qw(StartTime    20    text      )],
  end_time    => [qw(EndTime      25    text       )],
  time        => [qw(Time         30    text      default )],
  location    => [qw(Track        35    select    default )],
  coach       => [qw(Coach        40    text    default )],
  assistant   => [qw(Assistant    41    select     )],
  available   => [qw(SignUp       45    text       static)]
);

if ($LVL >= RollerCon::ADMIN) {
  $COLUMNS{id}       = [qw(Admin         1    none        default )];
  $COLUMNS{available}= [qw(SignUp       45    text       )]
}

if ($LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{COA} >= RollerCon::USER) {
  $COLUMNS{note}       = [qw(Notes         60    text         )],
  $COLUMNS{capacity}   = [qw(Capacity      65    number        default )],
  $COLUMNS{count}      = [qw(Count         70    number      default )],
  $COLUMNS{stars}      = [qw(Stars         75    number      default )],
  $COLUMNS{responses}  = [qw(Responses     80    number      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

my $dbh = getRCDBH;

sub modify_coach {
  my $line = shift;
  if ($line->{coachRCid} =~ / & /) {
    return join " & ", map { $h->a ({ href=>"view_coach.pl?RCid=".$_ }, getUser($_)->{derby_name}) } split / & /, $line->{coachRCid};
  }
  return $line->{coach} ? $h->a ({ href=>"view_coach.pl?RCid=".$line->{coachRCid} }, $line->{coach}) : "";
}

sub modify_id {
  my $hr = shift;
  my $clicky = $hr->{count} ? "event.stopPropagation(); if (confirm('WARNING!\\nYou are modifying a seminar that someone has signed up for.')==true) {return true;} else {return false;}" : "return true;";
  my $extrawarning = $hr->{count} ? "\\nWARNING! It appears someone is signed up for it." : "";
  return join "&nbsp;", #$hr->{id},
         $h->a ({ href=>"view_seminar.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
         $h->a ({ href=>"view_seminar.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
         $h->a ({ href=>"view_seminar.pl?id=$hr->{id}&choice=Delete", onClick=>"event.stopPropagation(); if (confirm('Are you sure you want to DELETE this seminar?$extrawarning')==true) {return true;} else {return false;}" }, "[Delete]")
  ;
};

sub modify_available {
  my $t = shift;
  
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
  my $cutoff = DateTime->new(
        year => $yyyy,
        month => $mm,
        day => $dd,
        hour => 5,
        minute => 0,
        second => 0,
        time_zone => 'America/Los_Angeles'
  );
  
  return "CLOSED" unless $now < $cutoff;
  
  my $classkey = join '|', "SEM", $t->{date}, $t->{start_time}, $t->{location};
  
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_seminar_signup_new where RCid = ? and id = ?", undef, $RCid, $t->{id} );
  my $droplink = $h->a ({ onClick=>"if (confirm('Really? You want to drop this seminar?')==true) { window.open('make_shift_change.pl?change=del&RCid=$RCid&id=$t->{id}&role=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "[DROP]");
  if (!$t->{available}) {
    my $full = "FULL";
    $full .= " | ".$droplink unless !$t->{signedup};
    return $full;
  }
  
  $t->{available} .= " Open"; 
  $t->{available} .= " | ".$droplink unless !$t->{signedup};
  if (findConflict ($ORCUSER->{RCid}, $t->{id}, "seminar")) {
    $t->{available} .= " | *schedule conflict*" unless $t->{signedup};
  } elsif (signUpEligible ($ORCUSER, $t, "seminar")) {
    # SIGN UP
    $t->{available} .= " | ".$h->a ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$RCid&id=$classkey','Confirm Seminar Change','resizable,height=260,width=370'); return false;" }, "[SIGN UP]");
  }
  if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {
    # ADD USER
    $t->{available} ? $t->{available} .= " | " : {};
    $t->{available} .= $h->a ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$classkey','Confirm Seminar Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]");
  }
  
  return $t->{available};
}

sub filter_available {
  my $colName = shift;
  my $filter = shift;
  
  if (defined $filter)  {
    if ($filter eq "Full") {
      return "$colName = 0";
    }
    return "$colName > 0";
  } else {
    my $Options = "<OPTION></OPTION>"."<OPTION>Available</OPTION>"."<OPTION>Full</OPTION>";
    my $tmpfilter = getFilterValue ($colName);
    
    $Options =~ s/>($tmpfilter)/ selected>$1/;
    return "<SELECT name=filter-${colName} onChange='page.value = 1; submit();'>$Options</SELECT>";
  }
}

sub modify_time {
  my $t = shift;
  return convertTime $t->{time};
}

sub modify_start_time {
  my $t = shift;
  return convertTime $t->{start_time};
}

sub modify_end_time {
  my $t = shift;
  return convertTime $t->{end_time};
}

sub modify_stars {
  my $t = shift;
  if ($t->{coach} eq $ORCUSER->{derby_name} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::MANAGER) {
    $t->{stars} = $t->{stars};
  } else {
    $t->{stars} = '&nbsp;';
  }
}

sub modify_responses {
  my $t = shift;
  if ($t->{coachRCid} == $ORCUSER->{RCid} or $LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::MANAGER) {
    $t->{responses} = $t->{responses} // '0';
  } else {
    $t->{responses} = '&nbsp;';
  }
}

# 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)

# Uncomment and update if we want to enable clicking on a row to open a new page.
#
sub addRowClick {
  my $t = shift;
  
  if ($LVL >= RollerCon::ADMIN or $ORCUSER->{department}->{MVP} >= RollerCon::VOLUNTEER or $ORCUSER->{department}->{COA} >= RollerCon::VOLUNTEER) {
    return "location.href='view_seminar.pl?id=$t->{id}&choice=View'";
  } else {
    return "";
  }
}

# Call the function to print the table view page (with available options)

printTablePage ({ Title   => $pageTitle,
                  Table   => $DBTABLE, 
                  Columns => \%COLUMNS, 
                  RCAuth  => $RCAUTH_cookie,
                  DisplayYearSelect => 1,
                  ShowMyShifts       => 1,
                  PersonalTimeButton => 1,
                  HeaderButton => { field  => "id",
                                    button => $h->input ({ type=>"button", value=>"Add", onClick=>"event.stopPropagation(); window.location.href='view_seminar.pl'" }) }
                 });