Subversion Repositories VORC

Rev

Rev 223 | Go to most recent revision | Details | 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
60
    v_class_new.start_time = v_shift.start_time and
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;
84
 
85
  push @classes, $h->div ({ class=>"rTableRow", onClick=>"window.location.href='view_class.pl?id=$classid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, @{$class}) ]);
86
 
87
#  push @classes, $h->div ({ class=>"rTableRow" }, $h->div ({ class=>"rTableCellr" }, $summary)) if $summary;
88
}
89
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], '&nbsp;') if scalar @classes > 1;
90
 
91
 
92
# Then get all of the prior year classes...
93
my $class_list_sql = <<class_list_sql;
94
  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
95
  left join v_shift on
96
  	v_class_new.date = v_shift.date and
97
    v_class_new.start_time = v_shift.start_time and
98
    v_class_new.location = v_shift.location and
99
    v_shift.dept = "COA"
100
  where RCid = ? and year(v_class_new.date) < year(now())
101
  order by v_class_new.date desc, v_class_new.start_time desc
102
class_list_sql
103
 
104
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) ) ]));
105
foreach my $class (@{$dbh->selectall_arrayref ($class_list_sql, undef, $coachRCid)}) {
106
  my $classid = shift @{$class};
107
  ${$class}[3] = convertTime (${$class}[3]);
108
  push @classes, $h->div ({ class=>"rTableRow", onClick=>"window.location.href='view_class.pl?id=$classid'" },[ $h->div ({ class=>"rTableCellr", style=>"font-size: unset;" }, @{$class}) ]);
109
}
110
print $h->div ({ class=>"rTable", style=>"min-width: 0%;" }, [@classes], '&nbsp;') if scalar @classes > 1;
111
 
112
print $h->input ({ type=>"button", name=>"back", value=>"Back", onClick=>"history.back(); return false;" });
113
 
114
 
115
sub ERRORandEXIT {
116
  my $error = shift // "Unknown Error";
117
  print $h->div ({ class=>"error" }, $error);
118
  exit;
119
}
120
 
121
sub modify_available {
122
  my $t = shift;
123
  my $now = DateTime->now (time_zone => 'America/Los_Angeles');
124
 
125
  my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
126
  my $cutoff = DateTime->new(
127
        year => $yyyy,
128
        month => $mm,
129
        day => $dd,
130
        hour => 5,
131
        minute => 0,
132
        second => 0,
133
        time_zone => 'America/Los_Angeles'
134
  );
135
 
136
  return "CLOSED" unless $now < $cutoff;
137
 
138
  my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
139
 
140
  ($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $t->{id} );
141
  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");
142
 
143
  if (!$t->{available}) {
144
    my $full = "FULL";
145
    $full .= " | ".$droplink unless !$t->{signedup};
146
    return $full;
147
  }
148
 
149
  $t->{available} .= " Open";
150
  $t->{available} .= '&nbsp;'.$droplink unless !$t->{signedup};
151
  if (findConflict ($ORCUSER->{RCid}, $t->{id}, "class")) {
152
    $t->{available} .= " | *schedule conflict*" unless $t->{signedup};
153
  } elsif (signUpEligible ($ORCUSER, $t, "class")) {
154
    # SIGN UP
155
    $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");
156
  }
157
  if ($LVL > 4 or $ORCUSER->{department}->{VCI} >= 2) {
158
    # ADD USER
159
    $t->{available} ? $t->{available} .= '&nbsp;' : {};
160
    $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");
161
  }
162
 
163
  return $t->{available};
164
}