Subversion Repositories VORC

Rev

Rev 171 | 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";

use strict;
use cPanelUserConfig;
use RollerCon;
use tableViewer;
use CGI qw/param cookie header start_html url/;
use HTML::Tiny;
my $h = HTML::Tiny->new( mode => 'html' );

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

print header (),
                        start_html (-title => "Updating Officating Huddle Hours", -style => {'src' => "/style.css"} ); 

my %huddles = (
  Thursday => "2024-07-11",
  Friday   => "2024-07-12",
  Saturday => "2024-07-13",
);

my $dbh = getRCDBH ();

#$dbh->do ("INSERT INTO shift
#        (dept,role,type,date,location,start_time,end_time,doubletime,note,assignee_id)
#        VALUES(?,?,?,?,?,?,?,?,?)", undef, "OFF", "Officiating Huddle", "selected", $FTS->{date}, "C1", "09:00:00", "09:30:00", 0, "", $user->{RCid});



#foreach (sort keys %ENV) {
#       print "$_: $ENV{$_}\n<br>";
#}

print $h->p ("Updating your Officiating Huddle Attendance:");
print $h->open ("ul");
foreach (sort { $huddles{$a} cmp $huddles{$b} } keys %huddles) {
  my ($exists) = $dbh->selectrow_array ("select id from shift where date = ? and assignee_id = ? and role = 'Officiating Huddle'", undef, $huddles{$_}, $user->{RCid});
  if (param ($_)) {
    if (!$exists) {
      print $h->li ("Adding $huddles{$_} $_");
      logit ($user->{RCid}, "Added Officiating Huddle attendance for $huddles{$_}");
      $dbh->do ("INSERT INTO shift
          (dept,role,type,date,location,start_time,end_time,doubletime,note,assignee_id)
          VALUES(?,?,?,?,?,?,?,?,?,?)", undef, "OFF", "Officiating Huddle", "selected", $huddles{$_}, "C1", "09:00:00", "09:30:00", 0, "", $user->{RCid})
          or print $h->div ({class=>"error"}, $dbh->errstr());
    }
  } else {
    if ($exists) {
      print $h->li ("Deleting $huddles{$_} $_");
      logit ($user->{RCid}, "Removed Officiating Huddle attendance for $huddles{$_}");
      $dbh->do ("DELETE FROM shift where dept = ? and role = ? and date = ? and start_time = ? and assignee_id = ?", undef,
          "OFF", "Officiating Huddle", $huddles{$_}, "09:00:00", $user->{RCid})
           or print $h->div ({class=>"error"}, $dbh->errstr());
    }
  }
}
print $h->close ("ul");
print $h->p ("Done");
print $h->button ({ onClick=>"window.close();" }, "Close");
print $h->close ("html");

exit;