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' );
use DateTime;
use DateTime::Duration;
my $now = DateTime->now (time_zone => 'America/Los_Angeles');

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");

# Add checking to make sure they're in this department
if ($ORCUSER->{department}->{"ANN"} < 1 and $LVL < 4 and $ORCUSER->{department}->{"VCI"} < 2) {
  print header (-cookie=>$RCAUTH_cookie);
  printRCHeader ("Unauthorized Page");
  print $h->div ({ class=>"error" }, "You're not an Announcer");
  print $h->div ("Your user account is not registered as an Announcer, so you can't see these shifts.  It's possible that your access is still being reviewed.  Please be patient."), $h->br;
  print $h->button ({ onClick=>"window.location.href='/schedule/';" }, "Home");
  print $h->close ("html");
  exit; 
}

my $username = $h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$ORCUSER->{RCid}" }, $ORCUSER->{derby_name});
my $RCid = $ORCUSER->{RCid};

my $pageTitle = "Announcer Shifts";
our $DBTABLE = 'v_shift_announcer';
my %COLUMNS = (
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
  id             => [qw(ID           5    number            )],
  date           => [qw(Date        10    date      default )],
  dayofweek      => [qw(Day         15    select            )],
  time           => [qw(Time        20    text      default )],
  volhours       => [qw(VolHours    23    number            )],
  track          => [qw(Track       25    select    default )],
  teams          => [qw(Teams       30    text      default )],
  level          => [qw(Level       35    select    default )],
  restrictions   => [qw(Rs          40    select            )],
  gtype          => [qw(Type        45    select    default )],
  signup         => [qw(SignUp      46    select            )],
  notes          => [qw(Notes       50    text              )],
  role           => [qw(Role        55    select            )],
  tla            => [qw(TLA         60    select    default )],
  name           => [qw(Position    65    text              )],
  type           => [qw(Class       70    select    default )],
  RCid           => [qw(RCid        75    number            )],
  derby_name     => [qw(Assignee    80    select    default )]
);

if ($ORCUSER->{department}->{"ANN"} > 1 or $LVL >= 4 or $ORCUSER->{department}->{"VCI"} >= 2) {
  # Announcer Leads (and higher) can see a couple of extra fields
  $COLUMNS{'real_name'} = [qw(RealName    85    text)];
  $COLUMNS{'email'}     = [qw(Email       90    text)];
}

# If we need to modify line item values, create a subroutine named "modify_$columnname"
#    It will receive a hashref to the object lineitem (RETURN the modified field at the end of the function!)

sub modify_derby_name {
  my $t = shift;  
  
  if ($ORCUSER->{department}->{"ANN"} < 2 and $t->{derby_name} and $t->{RCid} != $RCid and $LVL < 5) {
    $t->{derby_name} = "FILLED" unless getUser($t->{RCid})->{showme};
  }
  
  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'
  );
  
  if (($t->{RCid} == $RCid and $t->{signup} ne "selected" and $now < $cutoff) or ($t->{derby_name} and ($ORCUSER->{department}->{"ANN"} >= 2 or $LVL >= 5))) {
    # DROP
    $t->{derby_name} = "$t->{derby_name} <A HREF='#' onClick=\"window.open('make_shift_change.pl?change=del&RCid=$t->{RCid}&id=$t->{id}&role=$t->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[DROP]</a>";
    if ($ORCUSER->{department}->{"ANN"} >= 2 or $LVL > 4) {
      # NO SHOW
      $t->{derby_name} .= " | <A HREF='#' onClick=\"if (confirm('Really? They were a no show?')==true) { window.open('make_shift_change.pl?noshow=true&change=del&RCid=$t->{RCid}&id=$t->{id}&role=$t->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false; }\">[NO SHOW]</a>";
    }
  } elsif (!$t->{derby_name}) {
    $t->{dept} = "ANN";
#    if ($t->{track} eq "C3" or $t->{track} eq "C5") {
    if ($t->{track} eq "C5") {
      return "*no announcers*";
    }
    if (findConflict ($ORCUSER->{RCid}, $t->{id}, "game")) {
      $t->{derby_name} .= "*schedule conflict*";
    } elsif (signUpEligible ($ORCUSER, $t) and $now < $cutoff) {
      # SIGN UP
      $t->{derby_name} = "<A HREF='#' onClick=\"window.open('make_shift_change.pl?change=add&RCid=$RCid&id=$t->{id}&role=$t->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[SIGN UP]</a>";
    }
    if ($ORCUSER->{department}->{"ANN"} >= 2 or $LVL > 4) {
      # ADD USER
      $t->{derby_name} ? $t->{derby_name} .= " | " : {};
      $t->{derby_name} .= "<A HREF='#' onClick=\"window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$t->{id}&role=$t->{role}','Confirm Shift Change','resizable,height=260,width=370'); return false;\">[ADD USER]</a>";
    }
  }
  return $t->{derby_name};
}

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

# 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;
#  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 => 1,
                  ShowMyShifts  => 1,
                  HighlightShifts => 1,
                  PersonalTimeButton => 1,
#                  Where   => "track <> 'C3'",
                  Where   => "track <> 'C5'",
               });