Subversion Repositories VORC

Rev

Rev 264 | 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/;
226 - 13
use CGI qw/param cookie header start_html url url_param/;
222 - 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
 
226 - 33
my $coachRCid = param "RCid"; $coachRCid //= url_param "RCid";
222 - 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())
232 - 64
  order by v_class_new.date, v_class_new.start_time
222 - 65
class_list_sql
66
 
67
my @keys = qw(id class day date time start_time location level available);
225 - 68
my @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(Class Day Date Time Location Level SignUp) ) ]));
222 - 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;
225 - 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: smaller;" }, @{$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
 
264 - 91
# Then the list of Seminars for this year...
92
my $seminar_list_sql = <<seminar_list_sql;
93
  select v_seminar_new.id, name, v_seminar_new.dayofweek, v_seminar_new.date, v_seminar_new.time, v_seminar_new.start_time, v_seminar_new.location, available from v_seminar_new
94
  left join v_shift on
95
  	v_seminar_new.date = v_shift.date and
96
    time(v_seminar_new.start_time) = time(v_shift.start_time) and
97
    v_seminar_new.location = v_shift.location and
98
    v_shift.dept = "COA"
99
  where RCid = ? and year(v_seminar_new.date) = year(now())
100
  order by v_seminar_new.date, v_seminar_new.start_time
101
seminar_list_sql
102
 
103
my @keys = qw(id seminar day date time start_time location available);
104
my @seminars = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, qw(Seminar Day Date Time Location SignUp) ) ]));
105
foreach my $seminar (@{$dbh->selectall_arrayref ($seminar_list_sql, undef, $coachRCid)}) {
106
  my $seminarhash;
107
  @$seminarhash{@keys} = @{$seminar};
108
  $seminarhash->{available} = modify_available ($seminarhash);
109
  $seminarhash->{time} = convertTime ($seminarhash->{time});
110
 
111
  @{$seminar} = ($seminarhash->{seminar}, $seminarhash->{day}, $seminarhash->{date}, $seminarhash->{time}, $seminarhash->{location}, $seminarhash->{available});
112
  my $seminarid = $seminarhash->{id};
113
 
114
  push @seminars, $h->div ({ class=>"rTableRow ".($seminarhash->{signedup} ? "highlighted" : "shaded"), onClick=>"window.location.href='view_seminar.pl?id=$seminarid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: smaller;" }, @{$seminar}) ]);
115
}
116
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@seminars], '&nbsp;') if scalar @seminars > 1;
117
 
118
 
222 - 119
# Then get all of the prior year classes...
120
my $class_list_sql = <<class_list_sql;
121
  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
122
  left join v_shift on
123
  	v_class_new.date = v_shift.date and
223 - 124
    time(v_class_new.start_time) = time(v_shift.start_time) and
222 - 125
    v_class_new.location = v_shift.location and
126
    v_shift.dept = "COA"
127
  where RCid = ? and year(v_class_new.date) < year(now())
128
  order by v_class_new.date desc, v_class_new.start_time desc
129
class_list_sql
130
 
225 - 131
my @classes = ($h->div ({ class=>"rTableRow" },[ $h->div ({ class=>"rTableHead", style=>"font-size: smaller;" }, "Prior Year Classes", qw(Day Date Time Location Level Stars Responses) ) ]));
222 - 132
foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {
133
  my $classid = shift @{$class};
134
  ${$class}[3] = convertTime (${$class}[3]);
225 - 135
  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}) ]);
222 - 136
}
137
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], '&nbsp;') if scalar @classes > 1;
138
 
139
print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });
140
 
141
 
142
sub ERRORandEXIT {
143
  my $error = shift // "Unknown Error";
144
  print $h->div ({ class=>"error" }, $error);
145
  exit;
146
}
147
 
148
sub modify_available {
149
  my $t = shift;
150
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
151
 
152
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
153
  my $cutoff = DateTime->new(
154
        year => $yyyy,
155
        month => $mm,
156
        day => $dd,
157
        hour => 5,
158
        minute => 0,
159
        second => 0,
160
        time_zone => 'America/Los_Angeles'
161
  );
162
 
163
  return "CLOSED" unless $now < $cutoff;
164
 
165
  my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
166
 
167
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $t->{id} );
168
  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");
169
 
170
  if (!$t->{available}) {
171
    my $full = "FULL";
172
    $full .= " | ".$droplink unless !$t->{signedup};
173
    return $full;
174
  }
175
 
176
  $t->{available} .= " Open";
177
  $t->{available} .= '&nbsp;'.$droplink unless !$t->{signedup};
178
  if (findConflict ($ORCUSER->{RCid}, $t->{id}, "class")) {
179
    $t->{available} .= " | *schedule conflict*" unless $t->{signedup};
180
  } elsif (signUpEligible ($ORCUSER, $t, "class")) {
181
    # SIGN UP
182
    $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");
183
  }
184
  if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {
185
    # ADD USER
186
    $t->{available} ? $t->{available} .= '&nbsp;' : {};
187
    $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");
188
  }
189
 
190
  return $t->{available};
191
}