Subversion Repositories VORC

Rev

Rev 182 | 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 WebDB;
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;
# Add checking to make sure they're in this department
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $user = getUser ($EML);
$user->{department} = convertDepartments $user->{department};

if ($user->{department}->{"OFF"} < 1 and $LVL < 4) {
        print header(-cookie=>$RCAUTH_cookie);
        printRCHeader("Unauthorized Page");
        print $h->div ({ class=>"error" }, "You're not an Official");
        print $h->div ("Your user account is not registered as an Official, so you can't see this page.  It's possible that your access is still being reviewed.  Please be patient.");
        print $h->a ({ href=>"/schedule/" }, "[Go Home]");
        print $h->close ("html");
        exit;   
}

my $username = $h->a ({ href=>"/schedule/view_user.pl?submit=View&RCid=$user->{RCid}" }, $user->{derby_name});
my $RCid = $user->{RCid};
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
#my $YEAR = 1900 + (localtime)[5]; #which year of data to display, default to current
my $YEAR = param ("year") // 1900 + (localtime)[5];

#$LVL = 1;

my $dbh = WebDB::connect ();

my $games = $dbh->prepare ("select * from v_shift_officiating where year(date) = ? and now() > date and RCid = ? and gtype in ('challenge', 'selected staffing', 'full length', 'challenge-rs1', 'challenge-rs2') order by date desc, time desc");
my $teams = $dbh->prepare ("select team1, team2 from game where id = ?");
my $headofficial = $dbh->prepare ("select derby_name from v_shift_officiating where id = ? and tla = ?");

my $date = `date +"%m%d%y%H%M%S"`; chomp $date;
my $filename = "RollerCon_${YEAR}_OHD_$user->{derby_name}_${date}_$$.csv";
  
print "Content-type: text/CSV\n";
# The Content-Disposition will generate a prompt to save the file. If you want
# to stream the file to the browser, comment out the following line.
print "Content-Disposition: attachment; filename=$filename\n";
print "\n";

print "Date,Event Name,Event Location,Event Host,Home / High Seed,Visitor / Low Seed,Association,Game Type,Position,2nd Position,Software,Head Referee,Head NSO,Notes\n";

$games->execute ($YEAR, $user->{RCid});
while (my $game = $games->fetchrow_hashref ()) {
  $teams->execute ($game->{id});
  my ($team1, $team2) = $teams->fetchrow_array ();
  
  $headofficial->execute ($game->{id}, "HR");
  my ($HR) = $headofficial->fetchrow_array ();
  
  $headofficial->execute ($game->{id}, "PLT/HNSO");
  my ($HNSO) = $headofficial->fetchrow_array ();
  
  if ($game->{tla} eq "PLT/HNSO") {
    $game->{tla} = "HNSO";
    $game->{tla2} = "PLT";
  } elsif ($game->{tla} eq "HR") {
    $game->{tla2} = "IPR";
  } else {
    $game->{tla2} = "";
  }
  
  my @line;
  push @line, $game->{date};
  push @line, 'RollerCon '.$YEAR;
  push @line, '"The Expo at World Market Center, Las Vegas, NV"';
  push @line, 'RollerCon';
  push @line, $team1;
  push @line, $team2;
  push @line, "Other";
  push @line, $game->{gtype} eq "challenge" ? "Other" : "Reg";
  push @line, $game->{tla};
  push @line, $game->{tla2};
  push @line, $game->{tla} eq "SBO" ? "C" : "";
  push @line, $HR;
  push @line, $HNSO;
  push @line, $game->{gtype} eq "challenge" ? "30 minute game without a halftime" : "";
  
  print join ",", @line;
  print "\n";
}

exit;