Subversion Repositories VORC

Rev

Rev 138 | 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 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 (RollerCon::USER) || die;
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");

my $pageTitle = "Games";
our $DBTABLE = 'v_games';
my %COLUMNS = (
# colname   =>  [qw(DisplayName       N    type     status)],   status ->  static | default | <blank>
# id           => [qw(Change         5    none        static )],
  teams        => [qw(Teams         10    text      default )],
  date         => [qw(Date          15    date        default )],
  dayofweek    => [qw(Day           20    select            )],
  time         => [qw(Time          25    text        default )],
  start_time   => [qw(Start         30    text         )],
  end_time     => [qw(End           35    text         )],
  volhours     => [qw(Length        40    number            )],
  track        => [qw(Track         45    select      default )],
  level        => [qw(Level         50    select      default )],
  restrictions => [qw(R             60    select      default )],
  gtype        => [qw(Type          65    select      default )],
  notes        => [qw(Notes         70    text         )],
);

if ($LVL >= RollerCon::ADMIN) {
  $COLUMNS{id} = [qw(Change         5    number       static  )];
}

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_id {
  my $hr = shift;
  my $clicky = $hr->{count} ? "event.stopPropagation(); if (confirm('WARNING!\\nYou are modifying a class 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_game.pl?id=$hr->{id}&choice=Update", onClick=>$clicky }, "[Edit]"),
         $h->a ({ href=>"view_game.pl?id=$hr->{id}&choice=Copy" }, "[Copy]"),
         $h->a ({ href=>"view_game.pl?id=$hr->{id}&choice=Delete", onClick=>"event.stopPropagation(); if (confirm('Are you sure you want to DELETE this game?$extrawarning')==true) {return true;} else {return false;}" }, "[Delete]")
  ;
};

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};
}

# 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_game.pl?id=$t->{id}&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,
                  PersonalTimeButton => 1,
                  HeaderButton => { field  => "id",
                                    button => $h->input ({ type=>"button", value=>"Add", onClick=>"window.location.href='view_game.pl'" }) }
                 });