-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcreatePool.php
396 lines (380 loc) · 19.5 KB
/
createPool.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
<?php
include("cas.php");
include("database_connect.php");
include("quizPhp.php");
$title = "QuizSplash: Create a Pool";
// PREPARE THE TEMPLATE
$template = file_get_contents('./template.html');
// REPLACE THE TITLE
$template = str_replace('<!--XXXTITLEXXX-->', $title, $template);
// REPLACE INSTANCES OF USERNAME
$username = $_SESSION['user'];
$template = str_replace('<!--XXXUSERNAMEXXX-->', $username, $template);
// ADD ADMINISTRATION LINK TO TOPNAV IF ADMINISTRATOR
$sql_adminCheck = "SELECT DISTINCT *
FROM classes
WHERE (instructor = '".$username."')
OR (assistant = '".$username."');";
$res_adminCheck = mysql_query($sql_adminCheck);
$cnt_adminCheck = mysql_num_rows($res_adminCheck);
$adminLink = "<li><a href =\"./classAdmin.php\">Administration</a></li>";
if ($cnt_adminCheck > 0) {
$template = str_replace('<!--XXXADMINISTRATIONXXX-->', $adminLink, $template);
}
// FIND THE SPLITPOINT
$splitpoint = strpos($template,'<!--XXXSPLITPOINTXXX-->');
// ECHO THE TOP BUN
echo substr($template, 0, $splitpoint);
$targetClass = htmlspecialchars($_GET["classId"]);
$currentTime = $_SERVER['REQUEST_TIME'];
// CHECK TO SEE THAT THE CLASS IS INSTRUCTED OR
// ASSISTED BY THE USER, AND THAT THE CLASS IS
// NOT EXPIRED
$canManage = 0; // ASSUME NOT
while ($row=mysql_fetch_array($res_adminCheck)) {
if ($row["classId"] == $targetClass) {
if ($row['expireDate'] < $currentTime) {
$canManage = 1;
$className = $row['className'];
}
}
if ($targetClass == "") {
printf("<script>location.href='classAdmin.php'</script>");
}
}
// define variables and initialize with empty values
$errorMessage = "";
$inp_poolname = $inp_pooldesc = "";
$inp_fdy = $inp_ddy = $inp_ody = $inp_cdy = "";
$inp_fdm = $inp_ddm = $inp_odm = $inp_cdm = "";
$inp_fdd = $inp_ddd = $inp_odd = $inp_cdd = "";
$inp_fdmin = $inp_ddmin = $inp_odmin = $inp_cdmin = "";
$inp_questioncnt = $inp_unlockquizcnt = $inp_responsecnt = "0";
$inp_reqExpl = "1";
$inp_defaulttags = "";
if ($canManage) {
// VALIDATE, SANITIZE, AND INSERT THE POSTED FORM
// check contents if form submitted
if ($_SERVER["REQUEST_METHOD"] == "POST") {
$inp_poolname = $_POST["inp_poolname"];
$inp_poolname = trim($inp_poolname);
$inp_pooldesc = $_POST["inp_pooldesc"];
$inp_pooldesc = trim($inp_pooldesc);
$inp_fdy = htmlspecialchars($_POST["inp_fdy"]);
$inp_fdm = htmlspecialchars($_POST["inp_fdm"]);
$inp_fdd = htmlspecialchars($_POST["inp_fdd"]);
$inp_fdh = htmlspecialchars($_POST["inp_fdh"]);
$inp_fdmin = htmlspecialchars($_POST["inp_fdmin"]);
$inp_ddy = htmlspecialchars($_POST["inp_ddy"]);
$inp_ddm = htmlspecialchars($_POST["inp_ddm"]);
$inp_ddd = htmlspecialchars($_POST["inp_ddd"]);
$inp_ddh = htmlspecialchars($_POST["inp_ddh"]);
$inp_ddmin = htmlspecialchars($_POST["inp_ddmin"]);
$inp_ody = htmlspecialchars($_POST["inp_ody"]);
$inp_odm = htmlspecialchars($_POST["inp_odm"]);
$inp_odd = htmlspecialchars($_POST["inp_odd"]);
$inp_odh = htmlspecialchars($_POST["inp_odh"]);
$inp_odmin = htmlspecialchars($_POST["inp_odmin"]);
$inp_cdy = htmlspecialchars($_POST["inp_cdy"]);
$inp_cdm = htmlspecialchars($_POST["inp_cdm"]);
$inp_cdd = htmlspecialchars($_POST["inp_cdd"]);
$inp_cdh = htmlspecialchars($_POST["inp_cdh"]);
$inp_cdmin = htmlspecialchars($_POST["inp_cdmin"]);
$inp_questioncnt = htmlspecialchars($_POST["inp_questioncnt"]);
$inp_unlockquizcnt = htmlspecialchars($_POST["inp_unlockquizcnt"]);
$inp_responsecnt = htmlspecialchars($_POST["inp_responsecnt"]);
$inp_reqExpl = htmlspecialchars($_POST["inp_reqExpl"]);
if ($inp_reqExpl != "1") {
$inp_reqExpl = "0";
}
$inp_defaulttags = htmlspecialchars($_POST["inp_defaulttags"]);
$tags = explode("\n", trim($inp_defaulttags));
$tagAr = array_filter($tags, 'trim');
if (empty($inp_poolname)) {
$errorMessage = $errorMessage."<li>Your pool must have a name.</li>";
}
$inp_filldate = htmlspecialchars($_POST["inp_fdy"]).'-'.htmlspecialchars($_POST["inp_fdm"]).'-'.htmlspecialchars($_POST["inp_fdd"]).' '.htmlspecialchars($_POST["inp_fdh"]).':'.htmlspecialchars($_POST["inp_fdmin"]);
$inp_duedate = htmlspecialchars($_POST["inp_ddy"]).'-'.htmlspecialchars($_POST["inp_ddm"]).'-'.htmlspecialchars($_POST["inp_ddd"]).' '.htmlspecialchars($_POST["inp_ddh"]).':'.htmlspecialchars($_POST["inp_ddmin"]);
$inp_opendate = htmlspecialchars($_POST["inp_ody"]).'-'.htmlspecialchars($_POST["inp_odm"]).'-'.htmlspecialchars($_POST["inp_odd"]).' '.htmlspecialchars($_POST["inp_odh"]).':'.htmlspecialchars($_POST["inp_odmin"]);
$inp_closedate = htmlspecialchars($_POST["inp_cdy"]).'-'.htmlspecialchars($_POST["inp_cdm"]).'-'.htmlspecialchars($_POST["inp_cdd"]).' '.htmlspecialchars($_POST["inp_cdh"]).':'.htmlspecialchars($_POST["inp_cdmin"]);
if (($inp_closedate != "-- :") && validateDate($inp_closedate) && ($inp_duedate == "-- :")) {
$inp_duedate = $inp_closedate;
}
if ($inp_filldate == "-- :") {
$inp_filldate = "";
} elseif (!validateDate($inp_filldate)) {
$errorMessage = $errorMessage."<li>The datetime you entered for when students can begin submitting questions (".$inp_filldate.") is not valid. Please enter a valid date and time, or leave all fields blank if students can begin submitting questions immediately.</li>";
}
if ($inp_duedate == "-- :") {
$inp_duedate = "";
} elseif (!validateDate($inp_duedate)) {
$errorMessage = $errorMessage."<li>The datetime you entered for when submitted questions are due (".$inp_duedate.") is not valid. Please enter a valid date and time, or leave all fields blank if there is no deadline for submission.</li>";
} elseif ($inp_duedate <= date('Y-m-d H:i')) {
$errorMessage = $errorMessage."<li>The datetime when submitted questions are due (you entered: ".$inp_duedate.") must be in the future. Please enter a valid date and time (in Eastern time), or leave all fields blank if there is no deadline for submission.</li>";
}
if (($inp_filldate != "-- :") && ($inp_duedate != "-- :") && (validateDate($inp_filldate)) && validateDate($inp_duedate) && ($inp_filldate >= $inp_duedate)) {
$errorMessage = $errorMessage."<li>The datetime when submitted questions are due (you entered: ".$inp_duedate.") must be after the time when students can submit their questions (you entered: ".$inp_filldate.").</li>";
}
if ($inp_opendate == "-- :") {
$inp_opendate = "";
} elseif (!validateDate($inp_opendate)) {
$errorMessage = $errorMessage."<li>The datetime you entered for when students can begin taking quizzes (".$inp_opendate.") is not valid. Please enter a valid date and time, or leave all fields blank if students can begin taking quizzes immediately.</li>";
}
if ((validateDate($inp_opendate)) && validateDate($inp_filldate) && ($inp_opendate < $inp_filldate)) {
$errorMessage = $errorMessage."<li>The datetime when students can begin taking quizzes (you entered: ".$inp_opendate.") must be after (or the same as) the time when students can submit their questions (you entered: ".$inp_filldate.").</li>";
}
if ($inp_closedate == "-- :") {
$inp_closedate = "";
} elseif (!validateDate($inp_closedate)) {
$errorMessage = $errorMessage."<li>The datetime you entered for when students can no longer take quizzes (".$inp_closedate.") is not valid. Please enter a valid date and time, or leave all fields blank if quizzes should remain available indefinitely.</li>";
} elseif ($inp_closedate <= date('Y-m-d H:i')) {
$errorMessage = $errorMessage."<li>The datetime when this pool becomes unavailable for students to take quizzes (you entered: ".$inp_closedate.") must be in the future. Please enter a valid date and time (in Eastern time), or leave all fields blank if quizzes should remain available indefinitely.</li>";
}
if (($inp_opendate != "-- :") && ($inp_closedate != "-- :") && (validateDate($inp_opendate)) && validateDate($inp_closedate) && ($inp_opendate >= $inp_closedate)) {
$errorMessage = $errorMessage."<li>The datetime when this pool becomes unavailable for students to take quizzes (you entered: ".$inp_closedate.") must be after the time when students can begin taking quizzes (you entered: ".$inp_opendate.").</li>";
}
if (($inp_filldate != "-- :") && ($inp_closedate != "-- :") && (validateDate($inp_filldate)) && validateDate($inp_closedate) && ($inp_filldate >= $inp_closedate)) {
$errorMessage = $errorMessage."<li>The datetime when this pool becomes unavailable for students to take quizzes (you entered: ".$inp_closedate.") must be after the time when students can begin submitting questions (you entered: ".$inp_filldate.").</li>";
}
if (($inp_duedate != "-- :") && ($inp_closedate != "-- :") && (validateDate($inp_duedate)) && validateDate($inp_closedate) && ($inp_duedate > $inp_closedate)) {
$errorMessage = $errorMessage."<li>The datetime when this pool becomes unavailable for students to take quizzes (you entered: ".$inp_closedate.") must be after the time when submitted questions are due (you entered: ".$inp_duedate.").</li>";
}
if ((!is_numeric($inp_questioncnt)) || (strpos($inp_questioncnt,'.') !== false)) {
$errorMessage = $errorMessage."<li>The number of questions each student is expected to submit to the pool must be a number without decimals (you entered: ".$inp_questioncnt.")</li>";
}
if ((!is_numeric($inp_unlockquizcnt)) || (strpos($inp_unlockquizcnt,'.') !== false)) {
$errorMessage = $errorMessage."<li>The number of questions each student must submit before taking quizzes must be a number without decimals (you entered: ".$inp_unlockquizcnt.")</li>";
}
if ((!is_numeric($inp_responsecnt)) || (strpos($inp_responsecnt,'.') !== false)) {
$errorMessage = $errorMessage."<li>The number of questions each student is expected to answer must be a number without decimals (you entered: ".$inp_responsecnt.")</li>";
}
if ((is_numeric($inp_questioncnt)) && (strpos($inp_questioncnt,'.') == false) && (is_numeric($inp_unlockquizcnt)) && (strpos($inp_unlockquizcnt,'.') == false) && ($inp_questioncnt < $inp_unlockquizcnt)) {
$errorMessage = $errorMessage."<li>The number of questions students must submit to take a quiz (you entered: ".$inp_unlockquizcnt.") should be less than or equal to the number of questions you expect students to submit (you entered: ".$inp_questioncnt.").</li>";
}
if (empty($errorMessage)) {
// no errors; submit, and redirect
if ($inp_filldate == "") {
$inp_filldate = date('Y-m-d H:i');
}
$inp_filldate = "'".$inp_filldate."'";
if ($inp_opendate == "") {
$inp_opendate = date('Y-m-d H:i');
}
$inp_opendate = "'".$inp_opendate."'";
if ($inp_duedate == "") {
$inp_duedate = "NULL";
} else {
$inp_duedate = "'".$inp_duedate."'";
}
if ($inp_closedate == "") {
$inp_closedate = "NULL";
} else {
$inp_closedate = "'".$inp_closedate."'";
}
$sql_insertPool = "INSERT INTO pools
(classId,
poolName,
poolDesc,
fillDate,
dueDate,
openDate,
closeDate,
questionCnt,
unlockCnt,
responseCnt,
requireExplanation)
VALUES
(".$targetClass.",
'".$inp_poolname."',
'".$inp_pooldesc."',
".$inp_filldate.",
".$inp_duedate.",
".$inp_opendate.",
".$inp_closedate.",
".$inp_questioncnt.",
".$inp_unlockquizcnt.",
".$inp_responsecnt.",
".$inp_reqExpl.");";
$res_poolInsert = mysql_query($sql_insertPool);
$thisPoolId = mysql_insert_id();
if (!empty($inp_defaulttags)) {
$sql_insertTags = "INSERT INTO tags
(classId,
poolId,
questionId,
tag,
username)
VALUES ";
foreach ($tagAr as $value) {
$sql_insertTags = $sql_insertTags."
(".$targetClass.",
".$thisPoolId.",
NULL,
'".$value."',
'".$username."'),";
}
$sql_insertTags = rtrim($sql_insertTags, ",");
$sql_insertTags = $sql_insertTags.";";
$res_tagInsert = mysql_query($sql_insertTags);
}
printf("<script>location.href='createPoolSuccess.php'</script>");
}
}
// SPIT OUT THE FORM
echo '<h2>Create a New Quiz Pool for '.$className.'</h2>
<p>A quiz pool is a repository where students can submit questions, and take practice quizzes made from their classmates\' questions. By setting a deadline for students to submit questions to this pool and a minimum number of contributions, you can treat this pool as an assignment.</p>';
if(!empty($errorMessage)){
echo "<div id=\"errMessage\">ERROR:<ul>".$errorMessage."</ul></div>";
}
echo '<p> </p>
<form method="POST" action="'.htmlspecialchars($_SERVER["PHP_SELF"]).'?classId='.$targetClass.'">
<table width="100%" border="0">
<tr>
<td width="250" style="padding-bottom:20px;vertical-align:top;">Pool Name:</td>
<td style="padding-bottom:20px;"><input type="text" name="inp_poolname" maxlength="75" size="40" value="'.stripslashes($inp_poolname).'"></td>
</tr>
<tr>
<td width="250" style="padding-bottom:20px;vertical-align:top;">Pool Description:</td>
<td style="padding-bottom:20px;vertical-align:top;"><textarea name="inp_pooldesc" cols="40" rows="3" maxlength="255">'.stripslashes($inp_pooldesc).'</textarea></td>
</tr>
<tr>
<td width="250" style="padding-bottom:25px;">When can students begin submitting questions to this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;">
<select name="inp_fdy">';
makeOptions("year",$inp_fdy);
echo '</select> -
<select name="inp_fdm">';
makeOptions("month",$inp_fdm);
echo '</select> -
<select name="inp_fdd">';
makeOptions("day",$inp_fdd);
echo '</select>
<select name="inp_fdh">';
makeOptions("hour",$inp_fdh);
echo '</select> :
<select name="inp_fdmin">';
makeOptions("min",$inp_fdmin);
echo '</select>
<span class="datetimeformat">(Eastern Time)</span>
<br />
Leave all fields blank to allow immediate submission.
</td>
</tr>
<tr>
<td width="250" style="padding-bottom:25px;vertical-align:top;">When is the deadline for submitting questions to this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;">
<select name="inp_ddy">';
makeOptions("year",$inp_ddy);
echo '</select> -
<select name="inp_ddm">';
makeOptions("month",$inp_ddm);
echo '</select> -
<select name="inp_ddd">';
makeOptions("day",$inp_ddd);
echo '</select>
<select name="inp_ddh">';
makeOptions("hour",$inp_ddh);
echo '</select> :
<select name="inp_ddmin">';
makeOptions("min",$inp_ddmin);
echo '</select>
<span class="datetimeformat">(Eastern Time)</span>
<br />
Leave all fields blank if there is no deadline for submission.
</td>
</tr>
<tr>
<td width="250" style="padding-bottom:25px;vertical-align:top;">When can students begin taking quizzes from this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;">
<select name="inp_ody">';
makeOptions("year",$inp_ody);
echo '</select> -
<select name="inp_odm">';
makeOptions("month",$inp_odm);
echo '</select> -
<select name="inp_odd">';
makeOptions("day",$inp_odd);
echo '</select>
<select name="inp_odh">';
makeOptions("hour",$inp_odh);
echo '</select> :
<select name="inp_odmin">';
makeOptions("min",$inp_odmin);
echo '</select>
<span class="datetimeformat">(Eastern Time)</span>
<br />
Leave all fields blank to allow students to take quizzes immediately. If you do provide a date here, it should be after (or the same as) the time when students can begin submitting questions.
</td>
</tr>
<tr>
<td width="250" style="padding-bottom:25px;vertical-align:top;">When will this pool become unavailable for students to take quizzes?</td>
<td style="padding-bottom:20px;vertical-align:top;">
<select name="inp_cdy">';
makeOptions("year",$inp_cdy);
echo '</select> -
<select name="inp_cdm">';
makeOptions("month",$inp_cdm);
echo '</select> -
<select name="inp_cdd">';
makeOptions("day",$inp_cdd);
echo '</select>
<select name="inp_cdh">';
makeOptions("hour",$inp_cdh);
echo '</select> :
<select name="inp_cdmin">';
makeOptions("min",$inp_cdmin);
echo '</select>
<span class="datetimeformat">(Eastern Time)</span>
<br />
Leave all fields blank if this pool should be available for quizzing indefinitely. If you do provide a date here, it should be after all other dates. Also, this date will become the due date for question submission if you left it blank above.
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;">How many questions, at minimum, do you expect each student to contribute to this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;"><input type="text" name="inp_questioncnt" maxlength="2" size="2" value="'.$inp_questioncnt.'"><br />
Set this value to "0" if you have no minimum contribution requirement for this pool.
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;">How many questions must each student submit before they can take a quiz from this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;"><input type="text" name="inp_unlockquizcnt" maxlength="2" size="2" value="'.$inp_unlockquizcnt.'"><br />
Set this value to "0" to allow quiz access without question submission.
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;">How many questions, at minimum, do you expect each student to answer in this pool?</td>
<td style="padding-bottom:20px;vertical-align:top;"><input type="text" name="inp_responsecnt" maxlength="2" size="2" value="'.$inp_responsecnt.'"><br />
Set this value to "0" if you have no minimum response requirement for this pool.
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;">Require submitted questions to include explanations?</td>
<td style="padding-bottom:20px;vertical-align:top;"><input type="checkbox" name="inp_reqExpl" value="1"';
if ($inp_reqExpl) {
echo ' checked';
}
echo '>
Require students to include explanations with each submitted question.
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;">Default question tags</td>
<td style="padding-bottom:20px;vertical-align:top;">In the space below, type some keywords or key phrases that students can use to label the questions that they submit to this pool. Each tag should be on a separate line. Students will be able to add their own tags to questions, so it\'s okay if you don\'t include all possible topics or just leave this blank.<br /><textarea name="inp_defaulttags" cols="30" rows="8" maxlength="255">'.stripslashes($inp_defaulttags).'</textarea>
</td>
</tr>
<tr>
<td width="200" style="padding-bottom:20px;vertical-align:top;"><input type="submit" value="Submit"></td>
<td style="padding-bottom:20px;vertical-align:top;">
</td>
</tr>
</table>
</form>
';
}
else{
echo "<h2>You can't create a new pool here.</h2>
<p>Either you are not the administrator for this class, or this class is expired.</p>";
}
// ECHO THE BOTTOM BUN
echo substr($template, $splitpoint);
?>