Subversion Repositories VORC

Rev

Rev 223 | Rev 225 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
222 - 1
#!/usr/bin/perl
2
 
3
# Redirect error messages to a log of my choosing. (it's annoying to filter for errors in the shared env)
4
my $error_log_path = $ENV{SERVER_NAME} eq "volunteers.rollercon.com" ? "/home3/rollerco/logs/" : "/tmp/";
5
close STDERR;
6
open STDERR, '>>', $error_log_path.'vorc_error.log' or warn "Failed to open redirected logfile ($0): $!";
7
#warn "Redirecting errors to ${error_log_path}vorc_error.log";
8
 
9
use strict;
10
use cPanelUserConfig;
11
use RollerCon;
12
use tableViewer qw/inArray/;
13
use CGI qw/param cookie header start_html url/;
14
use Email::Valid;
15
use WebDB;
16
use HTML::Tiny;
17
use DateTime;
18
our $h = HTML::Tiny->new( mode => 'html' );
19
 
20
my $cookie_string = authenticate (RollerCon::USER);
21
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
22
my $RCAUTH_cookie = cookie (-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
23
print header (-cookie=>$RCAUTH_cookie);
24
printRCHeader ("Coach Details");
25
print $h->div ({ class=>"index" }, [$h->p ({ class=>"heading" }, "Coach Details:")]);
26
 
27
ERRORandEXIT ("You don't have access to see Coach details.") unless $ORCUSER->{MVPid} or
28
                                                                     $LVL >= RollerCon::ADMIN or
29
                                                                     $ORCUSER->{department}->{VCI} >= RollerCon::USER or
30
                                                                     $ORCUSER->{department}->{MVP} >= RollerCon::USER or
31
                                                                     $ORCUSER->{department}->{COA} >= RollerCon::USER;
32
 
33
my $coachRCid = param "RCid" // "";
34
ERRORandEXIT ("No Coach specified. [Invalid RCid: '$coachRCid']") unless $coachRCid =~ /^\d+$/;
35
 
36
my $coach = getUser ($coachRCid);
37
ERRORandEXIT ("No Coach specified. [RCid Not Found: '$coachRCid']") unless $coach;
38
 
39
$coach->{department} = convertDepartments ($coach->{department});
40
ERRORandEXIT ("No Coach specified. [RCid Not a Coach: '$coachRCid']") unless $coach->{department}->{COA} >= 1;
41
 
42
# Might want to check to make sure the coach is ok sharing their schedule and/or star-scores...
43
 
44
my $edit_bio = ' ';
45
$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;
46
print $h->div ({ class=>"indent" }, $coach->{derby_name}.($coach->{pronouns} ? " ($coach->{pronouns})" : "").$edit_bio, '&nbsp;');
47
 
48
my $dbh = getRCDBH ();
49
 
50
($coach->{bio}) = $dbh->selectrow_array ("select bio from coach_bio where RCid = ?", undef, $coachRCid);
51
$coach->{bio} =~ s/\n/<br>/g;
52
print $h->div ({ class=>"bio" }, $coach->{bio}).$h->div ('&nbsp;') if $coach->{bio};
53
 
54
 
55
# First display the list of classes for this year...
56
my $class_list_sql = <<class_list_sql;
57
  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_new
58
  left join v_shift on
59
  	v_class_new.date = v_shift.date and
223 - 60
    time(v_class_new.start_time) = time(v_shift.start_time) and
222 - 61
    v_class_new.location = v_shift.location and
62
    v_shift.dept = "COA"
63
  where RCid = ? and year(v_class_new.date) = year(now())
64
  order by v_class_new.date desc, v_class_new.start_time desc
65
class_list_sql
66
 
67
my @keys = qw(id class day date time start_time location level available);
68
my @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: unset;" }, qw(Class Day Date Time Location Level SignUp) ) ]));
69
foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {
70
  my $classhash;
71
  @$classhash{@keys} = @{$class};
72
  $classhash->{available} = modify_available ($classhash);
73
  $classhash->{time} = convertTime ($classhash->{time});
74
 
75
  @{$class} = ($classhash->{class}, $classhash->{day}, $classhash->{date}, $classhash->{time}, $classhash->{location}, $classhash->{level}, $classhash->{available});
76
  my $classid = $classhash->{id};
77
 
78
#  my $class_bio = '&nbsp;';
79
#  $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;
80
#  print $h->div ({ class=>"indent" }, $coach->{derby_name}.($coach->{pronouns} ? " ($coach->{pronouns})" : "").$edit_bio, '&nbsp;');
81
 
82
#  my ($summary) = $dbh->selectrow_array ("select summary from class_summary where id = ?", undef, $classid);
83
#  $summary =~ s/\n/<br>/g;
224 - 84
  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: unset;" }, @{$class}) ]);
222 - 85
 
86
#  push @classes, $h->div ({ class=>"rTableRow" }, $h->div ({ class=>"rTableCellr" }, $summary)) if $summary;
87
}
88
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], '&nbsp;') if scalar @classes > 1;
89
 
90
 
91
# Then get all of the prior year classes...
92
my $class_list_sql = <<class_list_sql;
93
  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_new
94
  left join v_shift on
95
  	v_class_new.date = v_shift.date and
223 - 96
    time(v_class_new.start_time) = time(v_shift.start_time) and
222 - 97
    v_class_new.location = v_shift.location and
98
    v_shift.dept = "COA"
99
  where RCid = ? and year(v_class_new.date) < year(now())
100
  order by v_class_new.date desc, v_class_new.start_time desc
101
class_list_sql
102
 
103
my @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: unset;" }, "Prior Year Classes", qw(Day Date Time Location Level Stars Responses) ) ]));
104
foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {
105
  my $classid = shift @{$class};
106
  ${$class}[3] = convertTime (${$class}[3]);
224 - 107
  push @classes, $h->div ({ class=>"rTableRow shaded", onClick=>"window.location.href='view_class.pl?id=$classid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, @{$class}) ]);
222 - 108
}
109
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], '&nbsp;') if scalar @classes > 1;
110
 
111
print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });
112
 
113
 
114
sub ERRORandEXIT {
115
  my $error = shift // "Unknown Error";
116
  print $h->div ({ class=>"error" }, $error);
117
  exit;
118
}
119
 
120
sub modify_available {
121
  my $t = shift;
122
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
123
 
124
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
125
  my $cutoff = DateTime->new(
126
        year => $yyyy,
127
        month => $mm,
128
        day => $dd,
129
        hour => 5,
130
        minute => 0,
131
        second => 0,
132
        time_zone => 'America/Los_Angeles'
133
  );
134
 
135
  return "CLOSED" unless $now < $cutoff;
136
 
137
  my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
138
 
139
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $t->{id} );
140
  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");
141
 
142
  if (!$t->{available}) {
143
    my $full = "FULL";
144
    $full .= " | ".$droplink unless !$t->{signedup};
145
    return $full;
146
  }
147
 
148
  $t->{available} .= " Open";
149
  $t->{available} .= '&nbsp;'.$droplink unless !$t->{signedup};
150
  if (findConflict ($ORCUSER->{RCid}, $t->{id}, "class")) {
151
    $t->{available} .= " | *schedule conflict*" unless $t->{signedup};
152
  } elsif (signUpEligible ($ORCUSER, $t, "class")) {
153
    # SIGN UP
154
    $t->{available} .= '&nbsp;'.$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");
155
  }
156
  if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {
157
    # ADD USER
158
    $t->{available} ? $t->{available} .= '&nbsp;' : {};
159
    $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");
160
  }
161
 
162
  return $t->{available};
163
}