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