Rev 226 | 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 qw/inArray/;use CGI qw/param cookie header start_html url url_param/;use Email::Valid;use WebDB;use HTML::Tiny;use DateTime;our $h = HTML::Tiny->new( mode => 'html' );my $cookie_string = authenticate (RollerCon::USER);our ($EML, $PWD, $LVL) = split /&/, $cookie_string;my $RCAUTH_cookie = cookie (-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");print header (-cookie=>$RCAUTH_cookie);printRCHeader ("Coach Details");print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Coach Details:")]);ERRORandEXIT ("You don't have access to see Coach details.") unless $ORCUSER->{MVPid} or$LVL >= RollerCon::ADMIN or$ORCUSER->{department}->{VCI} >= RollerCon::USER or$ORCUSER->{department}->{MVP} >= RollerCon::USER or$ORCUSER->{department}->{COA} >= RollerCon::USER;my $coachRCid = param "RCid"; $coachRCid //= url_param "RCid";ERRORandEXIT ("No Coach specified. [Invalid RCid: '$coachRCid']") unless $coachRCid =~ /^\d+$/;my $coach = getUser ($coachRCid);ERRORandEXIT ("No Coach specified. [RCid Not Found: '$coachRCid']") unless $coach;$coach->{department} = convertDepartments ($coach->{department});ERRORandEXIT ("No Coach specified. [RCid Not a Coach: '$coachRCid']") unless $coach->{department}->{COA} >= 1;# Might want to check to make sure the coach is ok sharing their schedule and/or star-scores...my $edit_bio = ' ';$edit_bio .= $h->input ({type=>"button", value=>"Edit Bio", onClick=>"window.location.href='view_coach_bio.pl?RCid=$coach->{RCid}&choice=Update'; return false;"}) unless $ORCUSER->{RCid} != $coach->{RCid} and $ORCUSER->{access} < RollerCon::ADMIN;print $h->div ({ class=>"indent" }, $coach->{derby_name}.($coach->{pronouns} ? " ($coach->{pronouns})" : "").$edit_bio, ' ');my $dbh = getRCDBH ();($coach->{bio}) = $dbh->selectrow_array ("select bio from coach_bio where RCid = ?", undef, $coachRCid);$coach->{bio} =~ s/\n/<br>/g;print $h->div ({ class=>"bio" }, $coach->{bio}).$h->div (' ') if $coach->{bio};# First display the list of classes for this year...my $class_list_sql = <<class_list_sql;select v_class_new.id, name, v_class_new.dayofweek, v_class_new.date, v_class_new.time, v_class_new.start_time, v_class_new.location, level, available from v_class_newleft join v_shift onv_class_new.date = v_shift.date andtime(v_class_new.start_time) = time(v_shift.start_time) andv_class_new.location = v_shift.location andv_shift.dept = "COA"where RCid = ? and year(v_class_new.date) = year(now())order by v_class_new.date, v_class_new.start_timeclass_list_sqlmy @keys = qw(id class day date time start_time location level available);my @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(Class Day Date Time Location Level SignUp) ) ]));foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {my $classhash;@$classhash{@keys} = @{$class};$classhash->{available} = modify_available ($classhash);$classhash->{time} = convertTime ($classhash->{time});@{$class} = ($classhash->{class}, $classhash->{day}, $classhash->{date}, $classhash->{time}, $classhash->{location}, $classhash->{level}, $classhash->{available});my $classid = $classhash->{id};# my $class_bio = ' ';# $class_bio .= $h->input ({type=>"button", value=>"Edit Summary", onClick=>"window.location.href='view_class_summary.pl?id=$classid&choice=Update'; return false;"}) unless $ORCUSER->{RCid} != $coach->{RCid} or $ORCUSER->{access} < RollerCon::ADMIN;# print $h->div ({ class=>"indent" }, $coach->{derby_name}.($coach->{pronouns} ? " ($coach->{pronouns})" : "").$edit_bio, ' ');# my ($summary) = $dbh->selectrow_array ("select summary from class_summary where id = ?", undef, $classid);# $summary =~ s/\n/<br>/g;push @classes, $h->div ({ class=>"rTableRow ".($classhash->{signedup} ? "highlighted" : "shaded"), onClick=>"window.location.href='view_class.pl?id=$classid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;" }, @{$class}) ]);# push @classes, $h->div ({ class=>"rTableRow" }, $h->div ({ class=>"rTableCellr" }, $summary)) if $summary;}print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], ' ') if scalar @classes > 1;# Then get all of the prior year classes...my $class_list_sql = <<class_list_sql;select v_class_new.id, name, v_class_new.dayofweek, v_class_new.date, v_class_new.time, v_class_new.location, level, stars, responses from v_class_newleft join v_shift onv_class_new.date = v_shift.date andtime(v_class_new.start_time) = time(v_shift.start_time) andv_class_new.location = v_shift.location andv_shift.dept = "COA"where RCid = ? and year(v_class_new.date) < year(now())order by v_class_new.date desc, v_class_new.start_time descclass_list_sqlmy @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, "Prior Year Classes", qw(Day Date Time Location Level Stars Responses) ) ]));foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {my $classid = shift @{$class};${$class}[3] = convertTime (${$class}[3]);push @classes, $h->div ({ class=>"rTableRow shaded", onClick=>"window.location.href='view_class.pl?id=$classid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;" }, @{$class}) ]);}print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], ' ') if scalar @classes > 1;print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });sub ERRORandEXIT {my $error = shift // "Unknown Error";print $h->div ({ class=>"error" }, $error);exit;}sub modify_available {my $t = shift;my $now = DateTime->now (time_zone => 'America/Los_Angeles');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');return "CLOSED" unless $now < $cutoff;my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $t->{id} );my $droplink = $h->button ({ onClick=>"if (confirm('Really? You want to drop this class?')==true) { window.open('make_shift_change.pl?change=del&RCid=$ORCUSER->{RCid}&id=$t->{id}&role=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "DROP");if (!$t->{available}) {my $full = "FULL";$full .= " | ".$droplink unless !$t->{signedup};return $full;}$t->{available} .= " Open";$t->{available} .= ' '.$droplink unless !$t->{signedup};if (findConflict ($ORCUSER->{RCid}, $t->{id}, "class")) {$t->{available} .= " | *schedule conflict*" unless $t->{signedup};} elsif (signUpEligible ($ORCUSER, $t, "class")) {# SIGN UP$t->{available} .= ' '.$h->button ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=add&RCid=$ORCUSER->{RCid}&id=$classkey','Confirm Class Change','resizable,height=260,width=370'); return false;" }, "SIGN UP");}if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {# ADD USER$t->{available} ? $t->{available} .= ' ' : {};$t->{available} .= $h->button ({ onClick=>"event.stopPropagation(); window.open('make_shift_change.pl?change=lookup&RCid=$ORCUSER->{RCid}&id=$classkey','Confirm Class Change','resizable,height=260,width=370'); return false;" }, "ADD USER");}return $t->{available};}