Subversion Repositories VORC

Rev

Rev 182 | Rev 194 | 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";

use strict;
use cPanelUserConfig;
use RollerCon;
use CGI qw/param header start_html url/;
use CGI::Cookie;
#use WebDB;
our $h = HTML::Tiny->new( mode => 'html' );
my $dbh = getRCDBH ();

my $cookie_string = authenticate (1) || die;
my ($EML, $PWD, $LVL) = split /&/, $cookie_string;
#my $user = getUser($EML);
my $user = $ORCUSER;
#$user->{department} = convertDepartments $user->{department};
#my $activated = max (values %{ $user->{department} });
my $activated = $ORCUSER->{access};
my $DEPTS = getDepartments ();

print header (-cookie=>CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m"));

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


use DateTime;
my $dt = DateTime->today;
$dt =~ s/T00\:00\:00$//;

my @announcements;
#push @announcements, $h->li ($h->a ({ href=>'__LINK__?'.$user->{discount_code} }, "THANK YOU! You've earned a discounted pass for next year. Click here to redeem.")) if $user->{discount_code};

if ($user->{department}->{EMT} >= RollerCon::USER and !$user->{emt_verified}) {
        push @announcements, $h->li ("NOTE: Anyone in the EMT department can see shifts, but you cannot sign up for them until your credentials have been verified. Start here: ".$h->a ({ href => "https://rollercon.com/help-wanted/emts/", target => "_blank" }, "https://rollercon.com/help-wanted/emts/"));
}

my $volhours = getSchedule ($user->{RCid}, 'all', 'hours');
if ($volhours) {
  push @announcements, $h->li ("Volunteer Hours: You currently have credit for $volhours hour(s) of volunteer time.");
}

my ($announcement) = $dbh->selectrow_array ("select value from setting where setting.key = ?", undef, "ANNOUNCEMENT");
push @announcements, $h->li ($announcement) if $announcement;

if ($user->{department}->{OFF} > 0) {
  my @days = ("Thursday", "Friday", "Saturday");
  my @dayschecked;
        foreach my $day (@{$dbh->selectall_arrayref ("select dayofweek from v_shift where year(date) = year(now()) and RCid = ? and role = 'Officiating Huddle'", undef, $user->{RCid})}) {
          push @dayschecked, @{$day};
        }
  
  use tableViewer qw/inArray/;
  push @announcements, $h->li ("Did you attend the Officiating Huddle on:"),
    $h->form ({ action => "add_officiating_huddle_time.pl", target => "_blank" }, [
      map ({ inArray($_, \@dayschecked) ? $h->input ({ type => "checkbox", name => $_, checked => [] }).$_.$h->br : $h->input ({ type => "checkbox", name => $_ }).$_.$h->br } @days),
      $h->input ({ type => "submit", value => scalar @dayschecked ? "Update my hours." : "Give me credit!" })
    ]);
}


my $schedule = getSchedule ($user->{RCid});

my @everyone;
my @printDEPTS = map { $DEPTS->{$_} } grep { $user->{department}->{$_} > 0 } grep { !/(ANN)|(OFF)/ } sort keys %{$user->{department}};
push @printDEPTS, "Officiating Lead" if $user->{department}->{"OFF"} > 1;
my $printDEPTS = join ", ", @printDEPTS;
push @everyone, $h->li ($h->a ({ href=>"/schedule/shifts.pl" }, "View and Sign Up for $printDEPTS Shifts")) if $printDEPTS;
push @everyone, $h->li ($h->a ({ href=>"/schedule/officiating_shifts.pl" }, "View and Sign Up for Officiating Shifts")) if $user->{department}->{OFF} > 0;

if ($user->{department}->{OFF} > 0) {
        foreach my $officiating_year (@{$dbh->selectall_arrayref ("select distinct year(date) as year from v_shift_officiating where RCid = ? and gtype in ('challenge', 'full length', 'selected', 'challenge-rs1', 'challenge-rs2') order by year desc", undef, $user->{RCid})}) {
    push @everyone, $h->li ($h->a ({ href=>"/schedule/ohd.pl?year=".$officiating_year->[0] }, "Export your $officiating_year->[0] games in WFTDA OHD Format (CSV file)"));
        }  
}

push @everyone, $h->li ($h->a ({ href=>"/schedule/announcer_shifts.pl" }, "View and Sign Up to Announce Games")) if $user->{department}->{ANN} > 0;
push @everyone, $h->li ($h->a ({ href=>"/schedule/games.pl" }, "View Games"));
push @everyone, $h->li ($h->a ({ href=>"/schedule/personal_time.pl" }, "Block Personal Time"));
push @everyone, $h->li ($h->a ({ href=>"/schedule/view_user.pl?submit=Edit&RCid=$user->{RCid}" }, "Edit your profile"));

my @mvppass;
my $reviews;
if ($user->{MVPid} or $user->{department}->{MVP} >= RollerCon::USER or $user->{department}->{COA} >= RollerCon::USER or $LVL >= RollerCon::SYSADMIN) {
        push @mvppass, $h->li ($h->a ({ href=>"/schedule/classes.pl" }, "View and Sign Up for MVP Classes"));
        
        # Get a list of classes attended to ask for reviews...
  my (@reviews_done, @reviews_tbd);
        foreach my $class (@{$dbh->selectall_arrayref ("select id, date, time, name, coach, count(*) as answers from v_class_signup left join v_survey_answer on id = classid and v_class_signup.RCid = v_survey_answer.RCid where v_class_signup.RCid = ? and year(date) = year(now()) and concat_ws(' ', date, end_time) < date_sub(now(), interval 2 hour) group by id order by date, start_time", undef, $user->{RCid})}) {
          my ($id, $date, $time, $name, $coach, $answers) = @{$class};
          next unless $id;
          $time = convertTime $time;
          
          if ($answers > 1) {
            push @reviews_done, $h->li ("$date $time: ".$h->a ({ href=>"/schedule/survey.pl?classid=$id" }, "$name [".getUserDerbyName ($coach)."]"));
          } else {
            push @reviews_tbd, $h->li ("$date $time: ".$h->a ({ href=>"/schedule/survey.pl?classid=$id" }, "$name [".getUserDerbyName ($coach)."]"));       
          }       
        }
  $reviews = $h->li (["Please submit feedback:", $h->ul ([@reviews_tbd])]) unless !scalar @reviews_tbd;
  $reviews .= $h->li (["View the feedback you've submitted:", $h->ul ([@reviews_done])]) unless !scalar @reviews_done;
}

my @leads = ();
if ($LVL > 1) {
        push @leads, $h->li ($h->a ({ href=>"/schedule/users.pl" }, "View Users in your Department(s)."));
        push @leads, $h->li ($h->a ({ href=>"/schedule/password_reset.pl" }, "Reset a Password."));

        # Officiating Leads:
        if ($user->{department}->{OFF} > 1) {
                unshift @leads, $h->li ($h->a ({ href=>"/schedule/scores.pl" }, "View / Update Game Scores"));
#                push @leads, $h->li ($h->a ({ href=>"daily_print.pl" }, "Daily Print Report"));
                push @leads, $h->li (["What's happening right now on...", $h->ul ([
                        $h->li ($h->a ({ href=>"right_now.pl?t=C1" }, "Track C1")),
                        $h->li ($h->a ({ href=>"right_now.pl?t=C2" }, "Track C2")),
                        $h->li ($h->a ({ href=>"right_now.pl?t=C3" }, "Track C3")),
                        $h->li ($h->a ({ href=>"right_now.pl?t=C5" }, "Track C5")),
                        $h->li ($h->a ({ href=>"right_now.pl?t=BT"  }, "Banked Track")),
                ])]);
        }
}
        
my @managers;
if ($LVL >= 3) {
        my $manager_departments = join " or ", map { "department like '%$_-0%'" } grep { $user->{department}->{$_} > 2 } keys %{$user->{department}};
        if ($manager_departments) {
        my ($count) = $dbh->selectrow_array ("select count(*) from official where $manager_departments");
        my $counttxt = $count == 1 ? "is 1 user" : "are $count users";
        push @managers, $h->li ($h->a ({ href=>"users.pl?autoload=1&RCid=true&derby_name=true&email=true&real_name=true&access=true&department=true&added=true&filter-RCid=&filter-derby_name=&filter-email=&filter-real_name=&filter-access=0&filter-department=&filter-added=&sortby=derby_name&limit=25&page=1" }, "There $counttxt waiting to be activated")) if $count;
        }
        push @managers, $h->li ($h->a ({ href=>"/schedule/log.pl" }, "Activity Log"));
  push @managers, $h->li ($h->a ({ href=>"/schedule/volhours.pl" }, "View Volunteer Hours by Department"));
  
  foreach (grep { $user->{department}->{$_} > 2 } keys %{$user->{department}}) {
    push @managers, $h->li ($h->a ({ href=>"/schedule/shifts.pl?autoload=1&dept=true&role=true&dayofweek=true&location=true&time=true&note=true&derby_name=true&filter-dept=$_&sortby=dayofweek&limit=All&page=1" }, "$DEPTS->{$_} Staff Schedule"));
  }
  
  if ($user->{department}->{VCI} > 2 or $user->{department}->{MVP} > 2 or $LVL > 4) {
    push @managers, $h->li ($h->a ({ href=>"/schedule/classes.pl" }, "View MVP Classes"));
    push @managers, $h->li ($h->a ({ href=>"/schedule/mvp_class_report.pl", target=>"_new" }, "Daily MVP Class Report (for print)"));
    push @managers, $h->li ($h->a ({ href=>"/schedule/mvp_class_report_without_skaters.pl", target=>"_new" }, "Daily MVP Class Report without Skaters (for print)"));
    push @managers, $h->li ($h->a ({ href=>"/schedule/daily_print.pl", target=>"_new" }, "Daily Officiating Report (for print)"));
    push @managers, $h->li ($h->a ({ href=>"/schedule/daily_print_announcers.pl", target=>"_new" }, "Daily Announcers Report (for print)"));
    push @managers, $h->li ($h->a ({ href=>"/schedule/print_dept_by_day.pl", target=>"_new" }, "BETA: Daily Shift Report (for print)"));
  }
  
        # Shift Report: select dayofweek, count(RCid) as filled_shifts, count(*) - count(RCid) as open_shifts, count(*) as total_shifts from v_shift group by date order by date
}

my (@sysadmins, @mvpcounts);
if ($LVL >= 5) {
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/bulk_upload.pl" }, "Upload a CSV of Department Shifts"));
        push @sysadmins, $h->li ($h->a ({ href=>"/schedule/shifts.pl" }, "Update department shift schedule"));
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/tickets.pl" }, "Manage MVP Ticket Matches"));
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/classes.pl" }, "Manage MVP Classes"));
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/games.pl" }, "Manage Games"));
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/departments.pl" }, "Manage Department Settings"));
  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/settings.pl" }, "System Settings"));
        push @sysadmins, $h->li ($h->a ({ href=>"/schedule/volhours_report.pl?limit=All" }, "YEAR END VOLUNTEER HOURS REPORT"));


        
        my ($unclaimed_tix) = $dbh->selectrow_array ("select count(*) from v_ticket where isnull(RCid) = 1");
        my ($mvpcount)      = $dbh->selectrow_array ("select count(*) from v_ticket where isnull(RCid) = 0");
        $mvpcount = 1 unless $mvpcount;
        my $class_limit = getSetting ("MAX_CLASS_SIGNUP");
        
  push @mvpcounts, $h->li ($mvpcount." MVP Tickets have been matched in VORC. ($unclaimed_tix remain unmatched.)");
  push @mvpcounts, $h->li ("They could (in theory) sign up for ".$mvpcount*$class_limit." class spots.");
  
        
        my ($signupcount, $total_class_count, $available_count) = $dbh->selectrow_array ("select sum(count), sum(capacity), sum(available) from v_class where year(date) = year(now())");
        
        $total_class_count //= 0;
        push @mvpcounts, $h->li ($total_class_count." Total Class Spots");
        push @mvpcounts, $h->li ($signupcount." Filled Class Spots (".sprintf("%.2f", ($signupcount / $total_class_count) * 100)."\%)") unless !$total_class_count;
        push @mvpcounts, $h->li ($available_count." Available Class Spots (".sprintf("%.2f", ($available_count / $total_class_count) * 100)."\%)") unless !$total_class_count;
        
        
#       push @sysadmins, $h->li ($mvpcount." MVP Passholders have signed up for ".$signupcount." spots (".sprintf("%.2f", ($signupcount / ($mvpcount*getSetting("MAX_CLASS_SIGNUP"))) * 100)."\% of allowable signups).");
#       push @sysadmins, $h->li (sprintf("%.2f", ($signupcount / $total_class_count) * 100)."\% of total class spaces are filled.");
        
        my ($active) = $dbh->selectrow_array ("select count(*) from official where last_active > (now() - interval 30 minute)");
        #my ($active) = $dbh->selectrow_array ("select * from official where last_login > (now() - interval 150 minute) order by last_login desc");
        push @sysadmins, $h->li ("There seem to be about $active user session(s) right now.");
#  push @sysadmins, $h->li ($h->a ({ href=>"/schedule/volhours.pl" }, "View Volunteer Hours by Department"));
}

my @activity_log;
my $alog = $dbh->prepare("select timestamp, event from v_log where RCid = ? limit 10");
$alog->execute($user->{RCid});
while (my @logs = $alog->fetchrow_array) {
        my ($d, $t) = split /\s+/, $logs[0];
        push @activity_log, $h->li ({ class=>"shaded" }, join " ", @logs);
}

my @reference;
push @reference, $h->li ($h->a ({ href=>"/info.html" }, "Information about using this tool"));
push @reference, $h->li ($h->a ({ href=>"http://rollercon.com/help-wanted/officiating/" }, "RollerCon Officiating Details"));

printRCHeader("Home");
print $h->close ("table");

print $h->form ({ name => "Req", action => url });

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Announcement:"), $h->ul ([ @announcements ]) ]) if (scalar @announcements);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Note:"), "<b>Your account is being reviewed.</b>", $h->br, "You won't have access to view or sign-up for things until you've been approved / added to a department.", $h->br, "Please watch your email for notifications." ]) unless $activated;

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Your up-coming schedule (as of $dt):"), $schedule, $h->h5 ("[".$h->a ({ href=>"export_ics.pl?RCid=$user->{RCid}" }, "use this link for iCal")."]") ]) if $schedule;

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "MVP Classes:"), $h->ul ([ @mvppass, $reviews ]) ]) if (scalar @mvppass);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do:"), $h->ul ([ @everyone ]) ]);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Lead:"), $h->ul ([ @leads ]) ]) if ($LVL > 1);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a Manager:"), $h->ul ([ @managers ]) ]) if ($LVL > 2);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Things you can do as a SysAdmin:"), $h->ul ([ @sysadmins ]) ]) if ($LVL >= 5);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "MVP Class and Ticket Status:"), $h->ul ([ @mvpcounts ]) ]) if (scalar @mvpcounts);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Your Latest Activity:"), $h->ul ([ @activity_log ]), $h->h5 ($h->a ({ href=>"log.pl?excel=0&autoload=1&eventid=true&timestamp=true&event=true&RCid=true&derby_name=true&filter-timestamp=&filter-event=&filter-RCid=".$user->{RCid}."&filter-derby_name=&sortby=eventid&limit=25&page=1" }, "[Your entire log history]")) ]);

print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Reference:"), $h->ul ([ @reference ]) ]);

print $h->close ("body"), $h->close ("html");