| 112 |
- |
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 cookie/;
|
|
|
15 |
my $h = HTML::Tiny->new( mode => 'html' );
|
|
|
16 |
my $dbh = WebDB::connect;
|
|
|
17 |
my $homeURL = '/';
|
| 185 |
- |
18 |
my $pageTitle = "RollerCon 2024 Feedback";
|
| 112 |
- |
19 |
|
|
|
20 |
#my $cookie_string = authenticate (RollerCon::USER) || die;
|
|
|
21 |
my $RCAUTH = cookie('allnewmvpclasses');
|
|
|
22 |
|
|
|
23 |
my $RCAUTH_cookie = CGI::Cookie->new(-name=>'RCSURVEY',-value=>"true");
|
|
|
24 |
my @ERRORS;
|
|
|
25 |
my $DEBUG = 0;
|
|
|
26 |
my $classid;
|
|
|
27 |
my $insert_question = $dbh->prepare ("insert into general_survey_answer (qid, uid, response, added, page, maxpage) values (?, ?, ?, date_sub(now(), interval 2 hour), ?, ?)");
|
|
|
28 |
my $update_maxpage = $dbh->prepare ("update general_survey_answer set maxpage = ? where qid = ? and uid = ?");
|
|
|
29 |
my $UID = param ('uid') // get_unique_id();
|
|
|
30 |
|
|
|
31 |
my $updated = save_survey ($classid) if param("submit") eq "Save";
|
|
|
32 |
|
|
|
33 |
my %question_options;
|
|
|
34 |
$question_options{1} = ["MVP", "Skater", "Off-Skates", "Day Pass", "Child Pass"];
|
|
|
35 |
$question_options{2} = ["MVP Classes", "Skate Park Events", "Roller Derby Events", "Social Events & Parties", "Vendor Village", "Charity Events", "Volunteering", "I love it all!", "Other"];
|
|
|
36 |
$question_options{3} = ["Dance", "Derby", "Skatepark", "Rec", "I don't skate", "Other"];
|
|
|
37 |
$question_options{4} = ["Plaza", "Circa", "Downtown Grand", "Other"];
|
|
|
38 |
|
|
|
39 |
|
|
|
40 |
my ($existing) = $dbh->selectrow_array ("select count(*) from general_survey_answer where uid = ?", undef, $UID);
|
|
|
41 |
my $mode = $existing ? "disabled" : "edit";
|
|
|
42 |
$mode = "edit" if param("submit") eq "Edit";
|
|
|
43 |
|
|
|
44 |
display_survey ($updated);
|
|
|
45 |
|
|
|
46 |
|
|
|
47 |
sub get_query_string_param {
|
|
|
48 |
my $field = shift // "";
|
|
|
49 |
|
|
|
50 |
foreach (split (/&/, $ENV{'QUERY_STRING'})) {
|
|
|
51 |
my ($name, $value) = split (/=/);
|
|
|
52 |
$value =~ tr/+/ /;
|
|
|
53 |
$value =~ s/%([a-fA-F0-9] [a-fA-F0-9])/pack("C", hex($1))/eg;
|
|
|
54 |
$value =~ s/~!/ ~!/g;
|
|
|
55 |
return $value if $name eq $field;
|
|
|
56 |
}
|
|
|
57 |
return "";
|
|
|
58 |
}
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
sub save_survey {
|
|
|
62 |
# my $CID = shift // error ("No ClassID");
|
|
|
63 |
# warn "Saving survey for RCID: $ORCUSER->{RCid}, Class: $CID" if $DEBUG;
|
|
|
64 |
my $changes = 0;
|
|
|
65 |
|
|
|
66 |
foreach (grep { /Question/ } param ()) {
|
|
|
67 |
my ($prefix, $q) = split /_/;
|
|
|
68 |
$changes += save_question ({ q=>$q, a=>WebDB::trim (scalar param ($_)) });
|
|
|
69 |
}
|
|
|
70 |
|
|
|
71 |
return $changes;
|
|
|
72 |
}
|
|
|
73 |
|
|
|
74 |
sub save_question {
|
|
|
75 |
my $Q = shift // error ("No data provided to save.");
|
|
|
76 |
return 0 unless answerChanged ($Q);
|
|
|
77 |
warn "Saving question $Q->{q}: $Q->{a}" if $DEBUG;
|
|
|
78 |
my ($maxpage) = $dbh->selectrow_array ("select ifnull(max(page), 0) from general_survey_answer where uid = ? and qid = ?", undef, $UID, $Q->{q});
|
|
|
79 |
$maxpage++;
|
|
|
80 |
$insert_question->execute ($Q->{q}, $UID, $Q->{a}, $maxpage, $maxpage);
|
|
|
81 |
$update_maxpage->execute ($maxpage, $Q->{q}, $UID);
|
|
|
82 |
return 1;
|
|
|
83 |
}
|
|
|
84 |
|
|
|
85 |
sub get_unique_id {
|
|
|
86 |
my $UID;
|
|
|
87 |
while (!$UID) {
|
|
|
88 |
($UID) = $dbh->selectrow_array ("select floor(1 + rand() * (99998))");
|
|
|
89 |
my ($test_UID) = $dbh->selectrow_array ("select RCid from general_survey_answer where RCid = ?", undef, $UID);
|
|
|
90 |
$UID = "" unless !$test_UID;
|
|
|
91 |
}
|
|
|
92 |
return $UID;
|
|
|
93 |
}
|
|
|
94 |
|
|
|
95 |
sub answerChanged {
|
|
|
96 |
my $A = shift // error ("No answer provided to check.");
|
|
|
97 |
warn "Checking question $A->{q}: $A->{a}" if $DEBUG;
|
|
|
98 |
my ($check) = $dbh->selectrow_array ("select count(*) from general_survey_answer where qid = ? and uid = ? and response = ?", undef, $A->{q}, $UID, $A->{a});
|
|
|
99 |
warn "Answer hasn't changed [$check], not saving." if $check and $DEBUG;
|
|
|
100 |
return $check ? 0 : 1;
|
|
|
101 |
}
|
|
|
102 |
|
|
|
103 |
sub display_survey {
|
|
|
104 |
# my $CID = shift // error ("No ClassID");
|
|
|
105 |
# my $mode = shift // "disabled";
|
|
|
106 |
my $saved = shift // "";
|
|
|
107 |
|
|
|
108 |
print header (-cookie=> [ $RCAUTH_cookie ] ),
|
|
|
109 |
start_html (-title => $pageTitle, -style => [{'src' => "/style.css"},{'src' => "/survey.css"}] );
|
|
|
110 |
print<<JAVASCRIPT;
|
|
|
111 |
<SCRIPT language="JavaScript">
|
|
|
112 |
<!--
|
|
|
113 |
function displayScore(score, targetspan) {
|
|
|
114 |
sliderscore = document.getElementById(score);
|
|
|
115 |
emojis = document.getElementById(targetspan);
|
|
|
116 |
|
|
|
117 |
if (sliderscore.value == 5) {
|
|
|
118 |
emojis.innerHTML = "<img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'>";
|
|
|
119 |
} else if (sliderscore.value >= 4) {
|
|
|
120 |
emojis.innerHTML = "<img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'>";
|
|
|
121 |
} else if (sliderscore.value >= 3) {
|
|
|
122 |
emojis.innerHTML = "<img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'>";
|
|
|
123 |
} else if (sliderscore.value >= 2) {
|
|
|
124 |
emojis.innerHTML = "<img src='/images/star-icon.png' align='middle'><img src='/images/star-icon.png' align='middle'>";
|
|
|
125 |
} else if (sliderscore.value >= 1) {
|
|
|
126 |
emojis.innerHTML = "<img src='/images/star-icon.png' align='middle'>";
|
| 184 |
- |
127 |
} else if (sliderscore.value >= 0) {
|
| 112 |
- |
128 |
emojis.innerHTML = "<img src='/images/meh.png' align='middle'>";
|
|
|
129 |
} else {
|
|
|
130 |
emojis.innerHTML = sliderscore.value;
|
|
|
131 |
}
|
|
|
132 |
}
|
|
|
133 |
//-->
|
|
|
134 |
</SCRIPT>
|
|
|
135 |
JAVASCRIPT
|
|
|
136 |
|
|
|
137 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
138 |
$h->h1 ($pageTitle),
|
|
|
139 |
$h->div ({ class=>"sp0" }, [
|
|
|
140 |
$h->div ({ class=>"spLeft" }, [
|
|
|
141 |
]),
|
|
|
142 |
$h->div ({ class=>"spRight" }, [
|
|
|
143 |
# $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
|
|
|
144 |
]),
|
|
|
145 |
]),
|
|
|
146 |
]);
|
|
|
147 |
|
|
|
148 |
print $h->div ({ id=>"savedmsg", class=>"saved fadeOut"}, "Changes Saved!") unless !$saved;
|
|
|
149 |
|
|
|
150 |
|
|
|
151 |
# print $h->div (["Class Details:",
|
|
|
152 |
# $h->p ("Name: ".$CREF->{name},
|
|
|
153 |
# "Coach: ".$CREF->{coach}
|
|
|
154 |
# ),
|
|
|
155 |
# ]), $h->hr;
|
|
|
156 |
|
|
|
157 |
print $h->open ("form", { method => "POST" });
|
|
|
158 |
print $h->input ({ type=>"hidden", name=>"uid", value=>$UID });
|
|
|
159 |
foreach my $question (@{$dbh->selectall_arrayref ("select qid, question, type, required from general_survey_question order by qorder")}) {
|
|
|
160 |
my ($qid, $text, $type, $required) = @{$question};
|
|
|
161 |
my ($PRIOR_ANSWER) = $dbh->selectrow_array ("select response from general_survey_answer where qid=? and uid=? and page = maxpage", undef, $qid, $UID);
|
|
|
162 |
|
|
|
163 |
no strict;
|
|
|
164 |
&{$type."_input"} ($qid, $text, $required, $PRIOR_ANSWER, $mode);
|
|
|
165 |
print $h->br;
|
|
|
166 |
|
|
|
167 |
}
|
|
|
168 |
|
|
|
169 |
my $leftbutton = $mode eq "disabled" ?
|
|
|
170 |
$h->input ({ type=>"button", name=>"back", value=>"Home", onClick=>"window.location.href='$homeURL'" }) :
|
|
|
171 |
$h->input ({ type=>"reset", name=>"Reset", onClick=>"return confirm('Are you sure you want to reset all of your changes?');" });
|
|
|
172 |
|
|
|
173 |
print $leftbutton,
|
|
|
174 |
' ',
|
|
|
175 |
$h->input ({ type=>"submit", name=>"submit", value=> $mode eq "disabled" ? "Edit" : "Save" });
|
|
|
176 |
|
|
|
177 |
print $h->close ("form", "html");
|
|
|
178 |
exit;
|
|
|
179 |
}
|
|
|
180 |
|
|
|
181 |
|
|
|
182 |
sub range_input {
|
|
|
183 |
my $Q = shift // "";
|
|
|
184 |
my $T = shift // "";
|
|
|
185 |
my $R = shift // "";
|
|
|
186 |
my $V = shift // 0;
|
|
|
187 |
my $M = shift // "disabled";
|
|
|
188 |
|
|
|
189 |
my $question_id = "Question_".$Q;
|
|
|
190 |
|
|
|
191 |
print $h->div ({ class => "slidecontainer"}, [
|
|
|
192 |
$h->label ({ for => $question_id }, $T), $h->br,
|
|
|
193 |
$h->input ({ type => "range",
|
|
|
194 |
id => $question_id,
|
|
|
195 |
name => $question_id,
|
|
|
196 |
tabindex => $Q,
|
| 184 |
- |
197 |
min => "0",
|
| 112 |
- |
198 |
max => "5",
|
|
|
199 |
value => $V,
|
|
|
200 |
step => ".1",
|
|
|
201 |
class => "rangeslider",
|
|
|
202 |
onInput => "displayScore('$question_id', 'question$Q');",
|
|
|
203 |
$M => [],
|
|
|
204 |
}),
|
|
|
205 |
$h->span ({ id => "question".$Q }, $h->img ({ src=>"/images/meh.png", align=>"middle" }))
|
|
|
206 |
]);
|
|
|
207 |
print "<SCRIPT language='JavaScript'>displayScore('$question_id', 'question$Q');</SCRIPT>\n" if $V;
|
|
|
208 |
}
|
|
|
209 |
|
|
|
210 |
sub text_input {
|
|
|
211 |
my $Q = shift // "";
|
|
|
212 |
my $T = shift // "";
|
|
|
213 |
my $R = shift // "";
|
|
|
214 |
my $V = shift // "";
|
|
|
215 |
my $M = shift // "disabled";
|
|
|
216 |
|
|
|
217 |
my $question_id = "Question_".$Q;
|
|
|
218 |
|
|
|
219 |
print $h->div ({ class=>"" }, [
|
|
|
220 |
$h->label ({ for => $question_id }, $T), $h->br,
|
|
|
221 |
$h->textarea ({ style => "width: 610px; height: 85px;",
|
|
|
222 |
name => $question_id,
|
|
|
223 |
tabindex => $Q,
|
|
|
224 |
$M => [],
|
|
|
225 |
}, $V)
|
|
|
226 |
]);
|
|
|
227 |
}
|
|
|
228 |
|
|
|
229 |
|
|
|
230 |
sub list_input {
|
|
|
231 |
my $Q = shift // "";
|
|
|
232 |
my $T = shift // "";
|
|
|
233 |
my $R = shift // "";
|
|
|
234 |
my $V = shift // "";
|
|
|
235 |
my $M = shift // "disabled";
|
|
|
236 |
|
|
|
237 |
my $question_id = "Question_".$Q;
|
|
|
238 |
|
|
|
239 |
print $h->div ({ class=>"" }, [
|
|
|
240 |
$h->label ({ for => $question_id }, $T), $h->br,
|
|
|
241 |
$h->select ({ name => $question_id,
|
|
|
242 |
tabindex => $Q,
|
|
|
243 |
$M => []
|
|
|
244 |
}, [ map { $_ eq $V ? $h->option ({selected=>[]}, $_) : $h->option ($_) } "", @{$question_options{$Q}}]),
|
|
|
245 |
]);
|
|
|
246 |
}
|
|
|
247 |
|
|
|
248 |
|
|
|
249 |
sub error {
|
|
|
250 |
my $msg = shift // "";
|
|
|
251 |
|
|
|
252 |
print header (-cookie=> [ $RCAUTH_cookie ] ),
|
|
|
253 |
start_html (-title => $pageTitle, -style => {'src' => "/style.css"} );
|
|
|
254 |
|
|
|
255 |
print $h->div ({ class => "accent pageheader" }, [
|
|
|
256 |
$h->h1 ($pageTitle),
|
|
|
257 |
$h->div ({ class=>"sp0" }, [
|
|
|
258 |
$h->div ({ class=>"spLeft" }, [
|
|
|
259 |
]),
|
|
|
260 |
$h->div ({ class=>"spRight" }, [
|
|
|
261 |
# $h->input ({ type=>"button", value=>"Home", onClick=>"window.location.href='$homeURL'" }),
|
|
|
262 |
]),
|
|
|
263 |
]),
|
|
|
264 |
]),
|
|
|
265 |
$h->div ({ class => "error" }, $msg),
|
|
|
266 |
$h->close ("html");
|
|
|
267 |
|
|
|
268 |
exit;
|
|
|
269 |
}
|