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