| 56 |
bgadell |
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 WebDB;
|
|
|
12 |
use HTML::Tiny;
|
|
|
13 |
use RollerCon;
|
| 226 |
- |
14 |
use CGI qw/param header start_html url url_param/;
|
| 56 |
bgadell |
15 |
my $h = HTML::Tiny->new( mode => 'html' );
|
|
|
16 |
|
|
|
17 |
my %F;
|
|
|
18 |
|
| 105 |
bgadell |
19 |
my $cookie_string = authenticate (RollerCon::USER) || die;
|
| 56 |
bgadell |
20 |
our ($EML, $PWD, $LVL) = split /&/, $cookie_string;
|
|
|
21 |
my $user = getUser ($EML);
|
|
|
22 |
$user->{department} = convertDepartments $user->{department};
|
|
|
23 |
my $DepartmentNames = getDepartments ();
|
|
|
24 |
my $username = $user->{derby_name};
|
|
|
25 |
my $RCid = $user->{RCid};
|
|
|
26 |
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCAUTH',-value=>"$cookie_string",-expires=>"+30m");
|
|
|
27 |
my $YEAR = 1900 + (localtime)[5];
|
|
|
28 |
|
| 222 |
- |
29 |
if (!$ORCUSER->{MVPid} and $LVL < RollerCon::ADMIN and $ORCUSER->{department}->{MVP} < RollerCon::USER and $ORCUSER->{department}->{COA} < RollerCon::USER) {
|
|
|
30 |
print header(-cookie=>$RCAUTH_cookie);
|
|
|
31 |
printRCHeader("Unauthorized Page");
|
|
|
32 |
print $h->div ({ class=>"error" }, "No Access");
|
|
|
33 |
print $h->div ("Your user account is not registered to sign up for MVP Classes, so you can't see this page. It's possible that your access is still being reviewed. Please be patient.");
|
|
|
34 |
print $h->a ({ href=>"/schedule/" }, "[Go Home]");
|
|
|
35 |
print $h->close ("body");
|
|
|
36 |
print $h->close ("html");
|
|
|
37 |
exit;
|
|
|
38 |
}
|
| 56 |
bgadell |
39 |
|
|
|
40 |
my $pageTitle = "View MVP Class";
|
|
|
41 |
my $homeURL = "/schedule/";
|
|
|
42 |
my $DBTable = "class";
|
|
|
43 |
my %FIELDS = (
|
| 208 |
- |
44 |
id => [qw(ClassID 5 auto static )],
|
|
|
45 |
name => [qw(ClassName 10 text required )],
|
|
|
46 |
coach => [qw(Coach 15 placeholder )],
|
|
|
47 |
assistant => [qw(Assistant 17 placeholder )],
|
|
|
48 |
date => [qw(Date 20 date required )],
|
|
|
49 |
location => [qw(Location 25 text required )],
|
|
|
50 |
level => [qw(Level 27 text required )],
|
|
|
51 |
start_time => [qw(Start 30 time required )],
|
|
|
52 |
end_time => [qw(End 35 time required )],
|
|
|
53 |
capacity => [qw(Capacity 40 number required )],
|
|
|
54 |
note => [qw(Notes 45 textarea )],
|
| 56 |
bgadell |
55 |
);
|
|
|
56 |
|
|
|
57 |
|
|
|
58 |
my %fieldDisplayName = map { $_ => $FIELDS{$_}->[0] } keys %FIELDS;
|
|
|
59 |
my %fieldType = map { $_ => $FIELDS{$_}->[2] } keys %FIELDS;
|
|
|
60 |
my @requiredFields = sort fieldOrder grep { defined $FIELDS{$_}->[3] } keys %FIELDS;
|
|
|
61 |
my @DBFields = sort fieldOrder grep { $fieldType{$_} =~ /^(text|select|number|switch|date|time|auto)/ } keys %FIELDS;
|
|
|
62 |
my @ROFields = sort fieldOrder grep { $fieldType{$_} =~ /^(readonly)/ } keys %FIELDS;
|
|
|
63 |
my $primary = $DBFields[0];
|
|
|
64 |
|
|
|
65 |
sub fieldOrder {
|
| 208 |
- |
66 |
$FIELDS{$a}->[1] <=> $FIELDS{$b}->[1];
|
| 56 |
bgadell |
67 |
}
|
|
|
68 |
|
|
|
69 |
sub saveForm {
|
|
|
70 |
my $FTS = shift;
|
| 208 |
- |
71 |
my $context = shift // "";
|
| 56 |
bgadell |
72 |
|
| 208 |
- |
73 |
error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN or ($context eq "Save Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
|
|
|
74 |
|
| 56 |
bgadell |
75 |
my $dbh = WebDB::connect ();
|
|
|
76 |
if ($FTS->{$DBFields[0]} eq "NEW") {
|
|
|
77 |
$dbh->do (
|
|
|
78 |
"INSERT INTO $DBTable
|
| 208 |
- |
79 |
(name,date,location,level,start_time,end_time,capacity,note)
|
| 56 |
bgadell |
80 |
VALUES(?,?,?,?,?,?,?,?)",
|
| 208 |
- |
81 |
undef,
|
|
|
82 |
$FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{level}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity}, $FTS->{note}
|
| 56 |
bgadell |
83 |
);
|
| 208 |
- |
84 |
($FTS->{id}) = $dbh-> selectrow_array ("select max(id) from $DBTable where name = ? and date = ? and location = ? and start_time = ? and end_time = ?", undef, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time});
|
| 56 |
bgadell |
85 |
logit ($RCid, "$username created new class ($FTS->{id}, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity})");
|
|
|
86 |
|
| 208 |
- |
87 |
# Coach and Asst Coach need to be added after the class is created so that we have the class id...
|
|
|
88 |
if ($FTS->{coach}) { change_coach ("save", "coach", $FTS->{id}, $FTS->{coach}); }
|
|
|
89 |
if ($FTS->{assistant}) { change_coach ("save", "assistant", $FTS->{id}, $FTS->{assistant}); }
|
| 167 |
- |
90 |
|
| 208 |
- |
91 |
} elsif ($context eq "Save Note") {
|
|
|
92 |
# We're just updating the Note...
|
|
|
93 |
$dbh->do ("update class set note = ? where id = ?", undef, $FTS->{note}, $FTS->{id});
|
|
|
94 |
logit ($RCid, "$username updated class ($FTS->{id}) with Note: $FTS->{note})");
|
| 56 |
bgadell |
95 |
} else {
|
| 208 |
- |
96 |
# Update the Coach and Asst Coach volunteer shifts first (so that the original date, time, location still matches...)
|
| 56 |
bgadell |
97 |
$dbh->do (
|
| 208 |
- |
98 |
"update shift set
|
|
|
99 |
start_time = ?,
|
|
|
100 |
end_time = ?,
|
|
|
101 |
date = ?,
|
|
|
102 |
location = ?,
|
|
|
103 |
note = ?
|
|
|
104 |
where
|
|
|
105 |
dept = ? and
|
|
|
106 |
date = (select date from class where id = ?) and
|
|
|
107 |
location = (select location from class where id = ?) and
|
|
|
108 |
start_time = (select start_time from class where id = ?)",
|
|
|
109 |
undef,
|
|
|
110 |
$FTS->{start_time}, $FTS->{end_time}, $FTS->{date}, $FTS->{location}, $FTS->{name}, "COA", $FTS->{id}, $FTS->{id}, $FTS->{id}
|
|
|
111 |
);
|
|
|
112 |
# Now update the class.
|
|
|
113 |
$dbh->do (
|
| 56 |
bgadell |
114 |
"UPDATE $DBTable
|
| 208 |
- |
115 |
SET name=?, date=?, location=?, level=?, start_time=?, end_time=?, capacity=?, note=?
|
| 56 |
bgadell |
116 |
WHERE id = ?",
|
|
|
117 |
undef,
|
| 208 |
- |
118 |
$FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{level}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity}, $FTS->{note}, $FTS->{id}
|
| 56 |
bgadell |
119 |
);
|
| 91 |
bgadell |
120 |
logit ($RCid, "$username updated class ($FTS->{id}, $FTS->{name}, $FTS->{date}, $FTS->{location}, $FTS->{level}, $FTS->{start_time}, $FTS->{end_time}, $FTS->{capacity})");
|
| 208 |
- |
121 |
}
|
|
|
122 |
|
|
|
123 |
$dbh->disconnect (); # stored into database successfully.
|
|
|
124 |
return $FTS->{id};
|
| 56 |
bgadell |
125 |
}
|
|
|
126 |
|
|
|
127 |
sub delete_item {
|
|
|
128 |
error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN;
|
|
|
129 |
|
|
|
130 |
my $X = shift;
|
|
|
131 |
my $dbh = WebDB::connect ();
|
|
|
132 |
|
| 208 |
- |
133 |
# Delete the Coach and Asst Coach first while we can still do a subselect with the class id...
|
|
|
134 |
$dbh->do ("delete from shift
|
|
|
135 |
where
|
|
|
136 |
dept = ? and
|
|
|
137 |
date = (select date from class where id = ?) and
|
|
|
138 |
location = (select location from class where id = ?) and
|
|
|
139 |
start_time = (select start_time from class where id = ?)",
|
|
|
140 |
undef,
|
|
|
141 |
"COA", $X->{$primary}, $X->{$primary}, $X->{$primary}
|
|
|
142 |
);
|
| 56 |
bgadell |
143 |
$dbh->do ("delete from $DBTable where $primary = ?", undef, $X->{$primary});
|
|
|
144 |
## If we're deleting a class, we need to also delete all of the sign-ups
|
|
|
145 |
## TBD: Maybe email all of the attendees that their class is being deleted first?
|
|
|
146 |
$dbh->do ("delete from assignment where Gid = ? and role like ?", undef, $X->{$primary}, "CLA".'%');
|
| 208 |
- |
147 |
|
| 56 |
bgadell |
148 |
$dbh->disconnect ();
|
|
|
149 |
logit ($RCid, "$username deleted Class ($X->{$primary})");
|
|
|
150 |
print "Class Deleted: $X->{$primary}", $h->br;
|
|
|
151 |
print &formField ("Cancel", "Back", "POSTSAVE");
|
|
|
152 |
}
|
|
|
153 |
|
|
|
154 |
|
|
|
155 |
sub select_coach {
|
| 208 |
- |
156 |
my $selection = shift // "";
|
| 56 |
bgadell |
157 |
|
|
|
158 |
return $h->select ({ name=>"coach" }, [ $h->option (""), fetchDerbyNameWithRCid ("COA", $selection) ]);
|
|
|
159 |
};
|
|
|
160 |
|
| 167 |
- |
161 |
sub select_assistant {
|
| 208 |
- |
162 |
my $selection = shift // "";
|
| 167 |
- |
163 |
|
|
|
164 |
return $h->select ({ name=>"assistant" }, [ $h->option (""), fetchDerbyNameWithRCid ("COA", $selection) ]);
|
|
|
165 |
};
|
| 56 |
bgadell |
166 |
|
| 208 |
- |
167 |
sub change_coach {
|
|
|
168 |
my $change = shift // "";
|
|
|
169 |
my $role = shift // "";
|
|
|
170 |
my $class_id = shift // "";
|
|
|
171 |
my $coach_id = shift // "";
|
|
|
172 |
|
|
|
173 |
error ("SECURITY: You're not allowed to change the class coaches!") unless ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::MANAGER or $user->{department}->{VCI} >= RollerCon::MANAGER);
|
|
|
174 |
|
|
|
175 |
my $dbh = WebDB::connect ();
|
|
|
176 |
|
|
|
177 |
if ($change eq "delete") {
|
|
|
178 |
my ($r1, $r2);
|
|
|
179 |
if ($role eq "assistant") {
|
|
|
180 |
$r1 = "Assistant (TA)";
|
|
|
181 |
$r2 = "Assistant Coach";
|
|
|
182 |
} else {
|
|
|
183 |
$r1 = "Coach";
|
|
|
184 |
$r2 = "Coach";
|
|
|
185 |
}
|
|
|
186 |
$dbh->do ("delete from shift where
|
|
|
187 |
assignee_id = ? and
|
|
|
188 |
dept = ? and
|
|
|
189 |
role in (?, ?) and
|
|
|
190 |
date = (select date from class where id = ?) and
|
|
|
191 |
start_time = (select start_time from class where id = ?) and
|
|
|
192 |
location = (select location from class where id = ?)", undef,
|
|
|
193 |
$coach_id, "COA", $r1, $r2, $class_id, $class_id, $class_id);
|
|
|
194 |
} elsif ($change eq "save") {
|
| 215 |
- |
195 |
my $r1 = ($role eq "assistant") ? "Assistant (TA)" : "Coach";
|
| 208 |
- |
196 |
$dbh->do ("insert into shift (dept, role, type, date, location, start_time, end_time, doubletime, note, assignee_id)
|
|
|
197 |
select ?, ?, ?, date, location, start_time, end_time, 1, name, ? from class where id = ?", undef,
|
|
|
198 |
"COA", $r1, "selected", $coach_id, $class_id);
|
|
|
199 |
}
|
|
|
200 |
|
|
|
201 |
logit ($RCid, "Class Coach Change: $change $role for class $class_id with RCid $coach_id");
|
|
|
202 |
|
|
|
203 |
$dbh->disconnect ();
|
|
|
204 |
}
|
| 167 |
- |
205 |
|
| 204 |
- |
206 |
print header ( -cookie=> [ $RCAUTH_cookie ] ),
|
| 208 |
- |
207 |
start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
|
| 56 |
bgadell |
208 |
|
|
|
209 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
210 |
$h->h1 ($pageTitle),
|
|
|
211 |
$h->div ({ class=>"sp0" }, [
|
|
|
212 |
$h->div ({ class=>"spLeft" }, [
|
|
|
213 |
]),
|
|
|
214 |
$h->div ({ class=>"spRight" }, [
|
|
|
215 |
$h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
|
|
|
216 |
]),
|
|
|
217 |
]),
|
|
|
218 |
]);
|
|
|
219 |
|
| 208 |
- |
220 |
my $coaching_change = param ("coachchange") // "";
|
|
|
221 |
if ($coaching_change =~ /^(save|delete)_/) {
|
|
|
222 |
my ($change, $role, $class, $coach);
|
|
|
223 |
$class = param ("id");
|
|
|
224 |
($change, $role) = split /_/, $coaching_change;
|
|
|
225 |
if ($change eq "save") {
|
|
|
226 |
$coach = param ($role);
|
|
|
227 |
} elsif ($change eq "delete") {
|
|
|
228 |
($role, $coach) = split /:/, $role;
|
|
|
229 |
}
|
|
|
230 |
change_coach ($change, $role, $class, $coach);
|
|
|
231 |
}
|
|
|
232 |
|
| 56 |
bgadell |
233 |
my $choice = param ("choice") // "";
|
| 208 |
- |
234 |
if ($choice =~ /^Save/) {
|
|
|
235 |
process_form ($choice);
|
| 226 |
- |
236 |
} elsif (defined (param ($primary) || url_param ($primary))) {
|
|
|
237 |
my $thing = param ($primary); $thing //= url_param ($primary);
|
| 56 |
bgadell |
238 |
if ($choice eq "Delete") {
|
|
|
239 |
delete_item ({ $primary => $thing });
|
|
|
240 |
} else {
|
| 208 |
- |
241 |
display_form ({ $primary => $thing }, $choice);
|
|
|
242 |
}
|
| 56 |
bgadell |
243 |
} else {
|
| 208 |
- |
244 |
display_form (); # blank form
|
| 56 |
bgadell |
245 |
}
|
|
|
246 |
|
|
|
247 |
print $h->close ("html");
|
|
|
248 |
|
|
|
249 |
sub display_form {
|
|
|
250 |
my $R = shift;
|
|
|
251 |
my $view = shift // "";
|
| 208 |
- |
252 |
my $actionbutton;
|
| 105 |
bgadell |
253 |
my $coachRCid;
|
| 208 |
- |
254 |
my (@CoachRCids, @AsstCoachRCids);
|
| 56 |
bgadell |
255 |
|
| 208 |
- |
256 |
$view = "View" unless $LVL >= RollerCon::ADMIN or ($view eq "Add Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
|
| 56 |
bgadell |
257 |
|
|
|
258 |
if ($view eq "POSTSAVE" and $R->{$primary} eq "NEW") {
|
|
|
259 |
print &formField ("Cancel", "Back", "POSTSAVE");
|
|
|
260 |
return;
|
|
|
261 |
}
|
|
|
262 |
|
|
|
263 |
if ($R) {
|
|
|
264 |
# we're dealing with an existing thing. Get the current values out of the DB...
|
|
|
265 |
my $dbh = WebDB::connect ();
|
|
|
266 |
|
| 208 |
- |
267 |
@F{@DBFields} = $dbh->selectrow_array (
|
| 56 |
bgadell |
268 |
"SELECT ". join (", ", @DBFields) ." FROM $DBTable WHERE $primary = ?",
|
|
|
269 |
undef, $R->{$primary});
|
|
|
270 |
|
| 208 |
- |
271 |
# Get the Coach and Assistant Coach shifts...
|
|
|
272 |
my (@CoachShifts, @AsstCoachShifts);
|
|
|
273 |
my $shifthand = $dbh->prepare ("select id from shift where dept = ? and role = ? and date = ? and start_time = ? and location = ?");
|
|
|
274 |
|
|
|
275 |
$shifthand->execute ("COA", "Coach", $F{date}, $F{start_time}, $F{location});
|
|
|
276 |
while (my ($classshiftid) = $shifthand->fetchrow_array ()) {
|
|
|
277 |
push @CoachShifts, $classshiftid;
|
|
|
278 |
}
|
|
|
279 |
|
|
|
280 |
$shifthand->execute ("COA", "Assistant Coach", $F{date}, $F{start_time}, $F{location});
|
|
|
281 |
while (my ($classshiftid) = $shifthand->fetchrow_array ()) {
|
|
|
282 |
push @AsstCoachShifts, $classshiftid;
|
|
|
283 |
}
|
|
|
284 |
$shifthand->execute ("COA", "Assistant (TA)", $F{date}, $F{start_time}, $F{location});
|
|
|
285 |
while (my ($classshiftid) = $shifthand->fetchrow_array ()) {
|
|
|
286 |
push @AsstCoachShifts, $classshiftid;
|
|
|
287 |
}
|
|
|
288 |
|
|
|
289 |
$dbh->disconnect ();
|
|
|
290 |
|
|
|
291 |
# did we find a record?
|
|
|
292 |
error ("Cannot find a database entry for Class with id: '$R->{$primary}'") unless defined $F{$DBFields[0]};
|
|
|
293 |
|
| 56 |
bgadell |
294 |
# If the DB returns a null value, HTML::Tiny doesn't like it, so make sure nulls are converted to empty strings.
|
|
|
295 |
map { $F{$_} = "" unless $F{$_} } @DBFields;
|
| 208 |
- |
296 |
|
| 56 |
bgadell |
297 |
if ($view eq "Update") {
|
|
|
298 |
# We'd like to update that thing, give the user a form...
|
|
|
299 |
print $h->p ("Updating Class: $R->{$primary}...");
|
|
|
300 |
|
|
|
301 |
foreach (@DBFields) {
|
|
|
302 |
$F{$_} = formField ($_, $F{$_});
|
|
|
303 |
}
|
|
|
304 |
$F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
|
|
|
305 |
|
|
|
306 |
$actionbutton = formField ("choice", "Save");
|
|
|
307 |
$actionbutton .= formField ("Cancel");
|
| 208 |
- |
308 |
} elsif ($view eq "Add Note") {
|
|
|
309 |
# Leads may add a note to the class (to include an Asst Coach that doesn't have Coach access yet)
|
|
|
310 |
print $h->p ("Add a Note to Class: $R->{$primary}...");
|
|
|
311 |
|
|
|
312 |
$F{note} = formField ("note", $F{note});
|
|
|
313 |
$F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
|
|
|
314 |
|
|
|
315 |
$actionbutton = formField ("choice", "Save Note");
|
|
|
316 |
$actionbutton .= formField ("Cancel");
|
| 56 |
bgadell |
317 |
} elsif ($view eq "Copy") {
|
|
|
318 |
# We'd like to copy that thing, give the user a form...
|
|
|
319 |
print $h->p ("Copying Class: $R->{$primary}...");
|
|
|
320 |
|
|
|
321 |
foreach (@DBFields) {
|
|
|
322 |
$F{$_} = formField ($_, $F{$_});
|
|
|
323 |
}
|
|
|
324 |
$F{$DBFields[0]} = "COPY".$h->input ({ type=>"hidden", name=>$DBFields[0], value=> "NEW" });
|
|
|
325 |
|
|
|
326 |
$actionbutton = formField ("choice", "Save");
|
|
|
327 |
$actionbutton .= formField ("Cancel");
|
|
|
328 |
} else {
|
|
|
329 |
# We're just looking at it...
|
|
|
330 |
print $h->p ("Viewing Class: $R->{$primary}...");
|
| 222 |
- |
331 |
|
|
|
332 |
if ($ORCUSER->{MVPid}) {
|
|
|
333 |
my $dbh = WebDB::connect ();
|
|
|
334 |
($F{available}) = $dbh->selectrow_array ("select available from v_class_new where id = ?", undef, $R->{id});
|
|
|
335 |
$dbh->disconnect;
|
|
|
336 |
$F{capacity} = $F{available} . " / " . modify_capacity (\%F);
|
|
|
337 |
}
|
|
|
338 |
|
| 56 |
bgadell |
339 |
$F{$DBFields[0]} .= $h->input ({ type=>"hidden", name=>$DBFields[0], value=> $F{$DBFields[0]} });
|
| 208 |
- |
340 |
|
|
|
341 |
my $coachEditor = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::MANAGER or $user->{department}->{VCI} >= RollerCon::MANAGER) ? 1 : 0;
|
| 105 |
bgadell |
342 |
$coachRCid = $F{coach};
|
| 208 |
- |
343 |
$F{coach} = "";
|
|
|
344 |
foreach (@CoachShifts) {
|
|
|
345 |
my $sr = getShiftRef ($_);
|
| 222 |
- |
346 |
$F{coach} .= $h->a ({ href=>"/schedule/view_coach.pl?RCid=$sr->{assignee_id}" }, getUserDerbyName ($sr->{assignee_id}));
|
| 208 |
- |
347 |
$F{coach} .= ' ' . $h->button ({name => "coachchange", value => "delete_coach:$sr->{assignee_id}"}, "Remove") if $coachEditor;
|
|
|
348 |
$F{coach} .= $h->br;
|
|
|
349 |
push @CoachRCids, $sr->{assignee_id};
|
|
|
350 |
}
|
|
|
351 |
if ($coachEditor) {
|
|
|
352 |
my $context = param ("coachchange");
|
|
|
353 |
if ($context eq "add_coach") {
|
|
|
354 |
$F{coach} .= select_coach () . $h->button ({name => "coachchange", value => "save_coach"}, "Save");
|
|
|
355 |
} else {
|
|
|
356 |
$F{coach} .= $h->button ({name => "coachchange", value => "add_coach"}, "Add Coach");
|
|
|
357 |
}
|
|
|
358 |
}
|
| 56 |
bgadell |
359 |
|
| 208 |
- |
360 |
$F{assistant} = "";
|
|
|
361 |
foreach (@AsstCoachShifts) {
|
|
|
362 |
my $sr = getShiftRef ($_);
|
| 222 |
- |
363 |
$F{assistant} .= $h->a ({ href=>"/schedule/view_coach.pl?RCid=$sr->{assignee_id}" }, getUserDerbyName $sr->{assignee_id});
|
| 208 |
- |
364 |
$F{assistant} .= ' ' . $h->button ({name => "coachchange", value => "delete_assistant:$sr->{assignee_id}"}, "Remove") if $coachEditor;
|
|
|
365 |
$F{assistant} .= $h->br;
|
|
|
366 |
push @AsstCoachRCids, $sr->{assignee_id};
|
|
|
367 |
}
|
|
|
368 |
if ($coachEditor) {
|
|
|
369 |
my $context = param ("coachchange");
|
|
|
370 |
if ($context eq "add_assistant") {
|
|
|
371 |
$F{assistant} .= select_assistant () . $h->button ({name => "coachchange", value => "save_assistant"}, "Save");
|
|
|
372 |
} else {
|
|
|
373 |
$F{assistant} .= $h->button ({name => "coachchange", value => "add_assistant"}, "Add Assistant");
|
|
|
374 |
}
|
|
|
375 |
}
|
| 222 |
- |
376 |
|
| 56 |
bgadell |
377 |
$F{start_time} = convertTime $F{start_time};
|
|
|
378 |
$F{end_time} = convertTime $F{end_time};
|
|
|
379 |
|
|
|
380 |
$actionbutton = formField ("choice", "Update") unless $LVL < RollerCon::ADMIN;
|
| 208 |
- |
381 |
$actionbutton .= formField ("choice", "Add Note") if $user->{department}->{MVP} >= RollerCon::LEAD;
|
| 56 |
bgadell |
382 |
if ($view eq "POSTSAVE" or $choice eq "View") {
|
|
|
383 |
$actionbutton .= formField ("Cancel", "Back", "POSTSAVE");
|
|
|
384 |
} else {
|
|
|
385 |
$actionbutton .= formField ("Cancel", "Back");
|
|
|
386 |
}
|
|
|
387 |
}
|
|
|
388 |
} else {
|
|
|
389 |
error ("No Game id provided.") unless $LVL >= RollerCon::ADMIN;
|
|
|
390 |
|
|
|
391 |
print $h->p ("Adding a new Class...");
|
|
|
392 |
|
|
|
393 |
foreach (@DBFields) {
|
|
|
394 |
$F{$_} = formField ($_);
|
|
|
395 |
}
|
| 208 |
- |
396 |
$F{$DBFields[0]} = "NEW".$h->input ({ type=>"hidden", name=>$DBFields[0], value=> "NEW" });
|
|
|
397 |
|
|
|
398 |
$F{coach} = select_coach ();
|
|
|
399 |
$F{assistant} = select_assistant ();
|
|
|
400 |
|
| 56 |
bgadell |
401 |
$actionbutton = formField ("choice", "Save");
|
|
|
402 |
$actionbutton .= formField ("Cancel");
|
|
|
403 |
}
|
|
|
404 |
|
|
|
405 |
|
| 208 |
- |
406 |
print $h->open ("form", { action => url (), name=>"Req", method=>"POST" });
|
|
|
407 |
print $h->div ({ class=>"sp0" },
|
|
|
408 |
$h->div ({ class=>"rTable" }, [ map ({
|
| 56 |
bgadell |
409 |
$h->div ({ class=>"rTableRow" }, [
|
|
|
410 |
$h->div ({ class=>"rTableCell right top", style=>"font-size:unset;" }, "$fieldDisplayName{$_}: "),
|
|
|
411 |
$h->div ({ class=>"rTableCell", style=>"font-size:unset;" }, $F{$_})
|
|
|
412 |
])
|
|
|
413 |
} sort fieldOrder keys %FIELDS),
|
|
|
414 |
])
|
|
|
415 |
);
|
|
|
416 |
|
|
|
417 |
print $actionbutton;
|
|
|
418 |
print $h->close ("form");
|
| 169 |
- |
419 |
|
|
|
420 |
print $h->p ($h->input ({ type=>"button", onClick=>"window.location.href='email_users.pl?type=class&ID=$R->{$primary}';", value=>"Email Users" })) unless $LVL < RollerCon::ADMIN;
|
|
|
421 |
|
| 105 |
bgadell |
422 |
my $dbh = WebDB::connect ();
|
|
|
423 |
|
| 208 |
- |
424 |
my ($class_is_over) = $dbh->selectrow_array ("select 1 from v_class_new where $primary = ? and concat_ws(' ', date, end_time) < date_sub(now(), interval 2 hour)", undef, $R->{$primary});
|
|
|
425 |
|
|
|
426 |
# View the list of people signed up for the class...
|
| 112 |
- |
427 |
if ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) {
|
| 208 |
- |
428 |
my ($count) = $dbh->selectrow_array ("select count from v_class_new where $primary = ?", undef, $R->{$primary});
|
|
|
429 |
|
| 56 |
bgadell |
430 |
if ($F{$DBFields[0]} !~ /^(NEW|COPY)/) {
|
| 233 |
- |
431 |
my @A = @{$dbh->selectall_arrayref ("select role, official.RCid, derby_name from v_class_signup_new join official on v_class_signup_new.RCid = official.RCid where $primary = ? order by cast(right(role, if(char_length(role) = 5, 1, 2)) as UNSIGNED) asc", undef, $R->{$primary})};
|
| 56 |
bgadell |
432 |
|
|
|
433 |
my $classkey = join '|', $F{date}, $F{start_time}, $F{location};
|
| 112 |
- |
434 |
my $adduserlink = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? $h->a ({ style=>"color:unset;font-size:x-small;", onClick=>"window.open('make_shift_change.pl?change=lookup&RCid=$RCid&id=$classkey','Confirm Shift Change','resizable,height=260,width=370'); return false;" }, "[ADD USER]") : "";
|
| 56 |
bgadell |
435 |
|
|
|
436 |
print $h->br, $h->br;
|
|
|
437 |
print $h->div ({ class=>"index", style=>"max-width:610px" }, [ $h->p ({ class=>"heading" }, [ "Sign-ups: ", $adduserlink ]),
|
|
|
438 |
$h->ul ( [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
|
| 208 |
- |
439 |
$h->div ({ class=>"lisp0" }, [
|
| 56 |
bgadell |
440 |
$h->div ({ class=>"liLeft" }, [ $$_[0], ": ", $h->a ({ href=>"/schedule/view_user.pl?RCid=$$_[1]" }, $$_[2]) ]),
|
|
|
441 |
$h->div ({ class=>"liRight" }, ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? $h->a ({ style=>"font-size:small", onClick=>"if (confirm('Really? Delete $$_[2] from this class?')==true) { window.open('make_shift_change.pl?change=del&RCid=$$_[1]&id=$R->{$primary}&role=$$_[0]','Confirm Shift Change','resizable,height=260,width=370'); return false; }" }, "[DROP]") : "")
|
|
|
442 |
])
|
|
|
443 |
) } @A ])
|
|
|
444 |
]);
|
|
|
445 |
}
|
|
|
446 |
}
|
| 208 |
- |
447 |
|
|
|
448 |
# View the survey results...
|
|
|
449 |
use tableViewer qw/inArray/;
|
|
|
450 |
if (($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD or inArray ($ORCUSER->{RCid}, \@CoachRCids)) and $class_is_over) {
|
| 105 |
bgadell |
451 |
my ($response_count) = $dbh->selectrow_array ("select count(distinct(RCid)) from v_survey_answer where classid = ?", undef, $R->{$primary});
|
|
|
452 |
my $exclude_private = ($LVL >= RollerCon::ADMIN or $user->{department}->{MVP} >= RollerCon::LEAD) ? "" : "and private = 0";
|
|
|
453 |
|
| 108 |
bgadell |
454 |
my @RESPONSES = @{$dbh->selectall_arrayref ("select qorder, type, question, average, qid from v_survey_results where classid = ? $exclude_private order by qorder", undef, $R->{$primary})};
|
| 105 |
bgadell |
455 |
|
|
|
456 |
print $h->br, $h->br;
|
|
|
457 |
print $h->div ({ class=>"index", style=>"max-width:610px" }, [ $h->p ({ class=>"heading" }, [ "Survey Results: ", $response_count." Response".(($response_count > 1) ? "s" : "") ]),
|
|
|
458 |
$h->ul ( [ map { $h->li ({ class=>"shaded", style=>"margin:4px;" },
|
|
|
459 |
$h->div ({ class=>"lisp0" }, [
|
|
|
460 |
$h->div ({ class=>"liLeft" }, [ $$_[0], ": ", $$_[2] ]),
|
|
|
461 |
$h->div ({ class=>"liRight" }, [ $$_[1] eq "text" ?
|
|
|
462 |
$h->a ({ href=>"view_survey_comments.pl?classid=$R->{$primary}&qid=$$_[4]" }, [ $$_[3], (($$_[3] == 1) ? " comment" : " comments") ]) :
|
|
|
463 |
$$_[3] ])
|
|
|
464 |
])
|
|
|
465 |
) } @RESPONSES ])
|
|
|
466 |
]);
|
|
|
467 |
}
|
|
|
468 |
$dbh->disconnect;
|
| 56 |
bgadell |
469 |
}
|
|
|
470 |
|
|
|
471 |
sub process_form {
|
| 208 |
- |
472 |
my $context = shift // "";
|
|
|
473 |
error ("ERROR: Only SysAdmins can change games.") unless $LVL >= RollerCon::ADMIN or ($context eq "Save Note" and $user->{department}->{MVP} >= RollerCon::LEAD);
|
| 56 |
bgadell |
474 |
|
|
|
475 |
my %FORM;
|
|
|
476 |
foreach (keys %FIELDS) {
|
| 208 |
- |
477 |
if ($fieldType{$_} =~ /^text/) {
|
|
|
478 |
$FORM{$_} = WebDB::trim param ($_) // "";
|
|
|
479 |
} else {
|
|
|
480 |
$FORM{$_} = param ($_) // "";
|
|
|
481 |
}
|
| 56 |
bgadell |
482 |
}
|
| 208 |
- |
483 |
|
|
|
484 |
# check for required fields
|
|
|
485 |
my @errors = ();
|
|
|
486 |
foreach (@requiredFields) {
|
|
|
487 |
push @errors, "$fieldDisplayName{$_} is missing." if ($FORM{$_} eq "" and $context ne "Save Note");
|
|
|
488 |
}
|
|
|
489 |
push @errors, "Capacity should be a whole number." unless ($FORM{capacity} =~ /^\d+$/ or $context eq "Save Note");
|
|
|
490 |
|
|
|
491 |
if (@errors) {
|
| 56 |
bgadell |
492 |
print $h->div ({ class=>"error" }, [
|
| 208 |
- |
493 |
$h->p ("The following errors occurred:"),
|
|
|
494 |
$h->ul ($h->li (@errors)),
|
|
|
495 |
$h->p ("Please click your Browser's Back button to\n"
|
|
|
496 |
. "return to the previous page and correct the problem.")
|
|
|
497 |
]);
|
|
|
498 |
return;
|
|
|
499 |
} # Form was okay.
|
| 56 |
bgadell |
500 |
|
| 208 |
- |
501 |
$FORM{id} = saveForm (\%FORM, $context);
|
|
|
502 |
|
|
|
503 |
print $h->p ({ class=>"success" }, "Class successfully saved.");
|
| 56 |
bgadell |
504 |
|
|
|
505 |
display_form ({ $primary=>$FORM{id} }, "POSTSAVE");
|
|
|
506 |
}
|
|
|
507 |
|
| 222 |
- |
508 |
sub modify_capacity {
|
|
|
509 |
my $t = shift;
|
|
|
510 |
|
|
|
511 |
my $classid = $t->{id};
|
|
|
512 |
$classid =~ s/^(\d+).*/$1/;
|
|
|
513 |
|
|
|
514 |
use DateTime;
|
|
|
515 |
my $now = DateTime->now (time_zone => 'America/Los_Angeles');
|
|
|
516 |
my ($yyyy, $mm, $dd) = split /\-/, $t->{date};
|
|
|
517 |
my $cutoff = DateTime->new(
|
|
|
518 |
year => $yyyy,
|
|
|
519 |
month => $mm,
|
|
|
520 |
day => $dd,
|
|
|
521 |
hour => 5,
|
|
|
522 |
minute => 0,
|
|
|
523 |
second => 0,
|
|
|
524 |
time_zone => 'America/Los_Angeles'
|
|
|
525 |
);
|
|
|
526 |
|
|
|
527 |
return $t->{capacity} . " | CLOSED" unless $now < $cutoff;
|
|
|
528 |
|
|
|
529 |
my $classkey = join '|', $t->{date}, $t->{start_time}, $t->{location};
|
|
|
530 |
|
|
|
531 |
my $dbh = WebDB::connect;
|
|
|
532 |
($t->{signedup}) = $dbh->selectrow_array ("select role from v_class_signup_new where RCid = ? and id = ?", undef, $ORCUSER->{RCid}, $classid );
|
|
|
533 |
$dbh->disconnect;
|
|
|
534 |
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=$classid&role=$t->{signedup}','Confirm Change','resizable,height=260,width=370'); return false; }" }, "DROP");
|
|
|
535 |
if (!$t->{available}) {
|
|
|
536 |
my $full = " | FULL";
|
|
|
537 |
$full .= ' '.$droplink unless !$t->{signedup};
|
|
|
538 |
return $t->{capacity} . $full;
|
|
|
539 |
}
|
|
|
540 |
|
|
|
541 |
# $t->{capacity} .= " | Open";
|
|
|
542 |
$t->{capacity} .= ' '.$droplink unless !$t->{signedup};
|
|
|
543 |
if (findConflict ($ORCUSER->{RCid}, $classid, "class")) {
|
|
|
544 |
$t->{capacity} .= " | *schedule conflict*" unless $t->{signedup};
|
|
|
545 |
} elsif (signUpEligible ($ORCUSER, $t, "class")) {
|
|
|
546 |
# SIGN UP
|
|
|
547 |
$t->{capacity} .= ' '.$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");
|
|
|
548 |
}
|
|
|
549 |
|
|
|
550 |
return $t->{capacity};
|
|
|
551 |
}
|
|
|
552 |
|
| 56 |
bgadell |
553 |
sub error {
|
| 208 |
- |
554 |
my $msg = shift;
|
|
|
555 |
print $h->p ({ class=>"error" }, "Error: $msg");
|
| 56 |
bgadell |
556 |
print $h->close("html");
|
| 208 |
- |
557 |
exit (0);
|
| 56 |
bgadell |
558 |
}
|
|
|
559 |
|
|
|
560 |
sub formField {
|
| 208 |
- |
561 |
my $name = shift;
|
|
|
562 |
my $value = shift // '';
|
|
|
563 |
my $context = shift // '';
|
|
|
564 |
my $type = $fieldType{$name} // "button";
|
| 56 |
bgadell |
565 |
|
|
|
566 |
if ($type eq "button") {
|
| 208 |
- |
567 |
if ($name eq "Cancel") {
|
|
|
568 |
if ($context eq "POSTSAVE") {
|
|
|
569 |
return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"window.location.href = \"classes.pl\"; return false;" });
|
|
|
570 |
} else {
|
|
|
571 |
return $h->input ({ type=>"button", value => $value ne '' ? $value : "Cancel" , onClick=>"history.back(); return false;" });
|
|
|
572 |
}
|
|
|
573 |
} else {
|
|
|
574 |
return $h->input ({ type=>"submit", value => $value, name=>$name })
|
|
|
575 |
}
|
| 56 |
bgadell |
576 |
|
| 208 |
- |
577 |
} elsif ($type eq "textarea") {
|
|
|
578 |
return $h->tag ("textarea", {
|
|
|
579 |
name => $name,
|
|
|
580 |
override => 1,
|
|
|
581 |
cols => 30,
|
|
|
582 |
rows => 4
|
|
|
583 |
}, $value);
|
| 56 |
bgadell |
584 |
|
|
|
585 |
} elsif ($type eq "select") {
|
|
|
586 |
no strict;
|
|
|
587 |
return &{"select_".$name} ($value);
|
| 208 |
- |
588 |
} elsif ($type eq "auto") {
|
|
|
589 |
return $name eq "assignee_id" ? getUserDerbyName ($value) : $value;
|
|
|
590 |
} elsif ($type eq "time") {
|
|
|
591 |
return $h->input ({
|
|
|
592 |
name => $name,
|
|
|
593 |
type => $type,
|
|
|
594 |
value => $value,
|
|
|
595 |
step => 900,
|
|
|
596 |
required => [],
|
|
|
597 |
override => 1,
|
|
|
598 |
size => 30
|
|
|
599 |
});
|
|
|
600 |
} elsif ($type eq "number") {
|
| 56 |
bgadell |
601 |
return $h->input ({ name=>$name, type=>"number", value=>$value, step=>1 });
|
| 208 |
- |
602 |
} elsif ($type eq "switch") {
|
| 56 |
bgadell |
603 |
if ($value) {
|
|
|
604 |
return $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>$name, value=>1, checked=>[] }), $h->span ({ class=>"slider round" })]);
|
|
|
605 |
} else {
|
|
|
606 |
return $h->label ({ class=>"switch" }, [$h->input ({ type=>"checkbox", name=>$name, value=>1 }), $h->span ({ class=>"slider round" })]);
|
|
|
607 |
}
|
| 208 |
- |
608 |
} elsif ($type eq "placeholder") {
|
|
|
609 |
} else {
|
|
|
610 |
use tableViewer qw/inArray/;
|
|
|
611 |
if (inArray ($name, \@requiredFields)) {
|
|
|
612 |
return $h->input ({
|
|
|
613 |
name => $name,
|
|
|
614 |
type => $type,
|
|
|
615 |
value => $value,
|
|
|
616 |
required => [],
|
|
|
617 |
override => 1,
|
|
|
618 |
size => 30
|
|
|
619 |
});
|
|
|
620 |
} else {
|
|
|
621 |
return $h->input ({
|
|
|
622 |
name => $name,
|
|
|
623 |
type => $type,
|
|
|
624 |
value => $value,
|
|
|
625 |
override => 1,
|
|
|
626 |
size => 30
|
|
|
627 |
});
|
|
|
628 |
}
|
|
|
629 |
}
|
| 56 |
bgadell |
630 |
}
|
|
|
631 |
|