2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
8 /* This program is free software. You can redistribute it and/or */
9 /* modify it under the terms of the GNU General Public License */
10 /* as published by the Free Software Foundation. */
11 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_TESTS);
20 $test_type = 'normal';
22 if (isset($_POST['cancel'])) {
23 $msg->addFeedback('CANCELLED');
24 header('Location: index.php');
26 } else if (isset($_POST['submit'])) {
27 $missing_fields = array();
28 $_POST['title'] = $addslashes(trim($_POST['title']));
29 $_POST['description'] = $addslashes(trim($_POST['description']));
30 $_POST['num_questions'] = intval($_POST['num_questions']);
31 $_POST['num_takes'] = intval($_POST['num_takes']);
32 $_POST['content_id'] = intval($_POST['content_id']);
33 $_POST['passpercent'] = intval($_POST['passpercent']);
34 $_POST['passscore'] = intval($_POST['passscore']);
35 $_POST['passfeedback'] = $addslashes(trim($_POST['passfeedback']));
36 $_POST['failfeedback'] = $addslashes(trim($_POST['failfeedback']));
37 $_POST['num_takes'] = intval($_POST['num_takes']);
38 $_POST['anonymous'] = intval($_POST['anonymous']);
39 $_POST['allow_guests'] = $_POST['allow_guests'] ? 1 : 0;
40 $_POST['show_guest_form'] = $_POST['show_guest_form'] ? 1 : 0;
41 $_POST['instructions'] = $addslashes($_POST['instructions']);
42 $_POST['display'] = intval($_POST['display']);
44 // currently these options are ignored for tests:
45 $_POST['result_release'] = intval($_POST['result_release']);
46 $_POST['format'] = intval($_POST['format']);
47 $_POST['order'] = 1; //intval($_POST['order']);
48 $_POST['difficulty'] = 0; //intval($_POST['difficulty']); /* avman */
50 if ($_POST['title'] == '') {
51 $missing_fields[] = _AT('title');
54 if ($_POST['random'] && !$_POST['num_questions']) {
55 $missing_fields[] = _AT('num_questions_per_test');
58 if ($_POST['pass_score']==1 && !$_POST['passpercent']) {
59 $missing_fields[] = _AT('percentage_score');
62 if ($_POST['pass_score']==2 && !$_POST['passscore']) {
63 $missing_fields[] = _AT('points_score');
66 if ($missing_fields) {
67 $missing_fields = implode(', ', $missing_fields);
68 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
71 $day_start = intval($_POST['day_start']);
72 $month_start= intval($_POST['month_start']);
73 $year_start = intval($_POST['year_start']);
74 $hour_start = intval($_POST['hour_start']);
75 $min_start = intval($_POST['min_start']);
77 $day_end = intval($_POST['day_end']);
78 $month_end = intval($_POST['month_end']);
79 $year_end = intval($_POST['year_end']);
80 $hour_end = intval($_POST['hour_end']);
81 $min_end = intval($_POST['min_end']);
83 if (!checkdate($month_start, $day_start, $year_start)) {
84 $msg->addError('START_DATE_INVALID');
87 if (!checkdate($month_end, $day_end, $year_end)) {
88 $msg->addError('END_DATE_INVALID');
91 if (mktime($hour_end, $min_end, 0, $month_end, $day_end, $year_end) <
92 mktime($hour_start, $min_start, 0, $month_start, $day_start, $year_start)) {
93 $msg->addError('END_DATE_INVALID');
96 if (!$msg->containsErrors()) {
97 if (strlen($month_start) == 1){
98 $month_start = "0$month_start";
100 if (strlen($day_start) == 1){
101 $day_start = "0$day_start";
103 if (strlen($hour_start) == 1){
104 $hour_start = "0$hour_start";
106 if (strlen($min_start) == 1){
107 $min_start = "0$min_start";
110 if (strlen($month_end) == 1){
111 $month_end = "0$month_end";
113 if (strlen($day_end) == 1){
114 $day_end = "0$day_end";
116 if (strlen($hour_end) == 1){
117 $hour_end = "0$hour_end";
119 if (strlen($min_end) == 1){
120 $min_end = "0$min_end";
123 $start_date = "$year_start-$month_start-$day_start $hour_start:$min_start:00";
124 $end_date = "$year_end-$month_end-$day_end $hour_end:$min_end:00";
126 //If title exceeded database defined length, truncate it.
127 $_POST['title'] = validate_length($_POST['title'], 100);
129 $sql = "INSERT INTO ".TABLE_PREFIX."tests " .
156 $_SESSION[course_id],
158 '$_POST[description]',
163 $_POST[num_questions],
164 '$_POST[instructions]',
168 '$_POST[passfeedback]',
169 '$_POST[failfeedback]',
170 $_POST[result_release],
176 $_POST[allow_guests],
178 $_POST[show_guest_form])";
180 $result = mysql_query($sql, $db);
181 $tid = mysql_insert_id($db);
183 if (isset($_POST['groups']) && $tid) {
184 $sql = "INSERT INTO ".TABLE_PREFIX."tests_groups VALUES ";
185 foreach ($_POST['groups'] as $group) {
186 $group = intval($group);
187 $sql .= "($tid, $group),";
189 $sql = substr($sql, 0, -1);
190 $result = mysql_query($sql, $db);
193 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
194 header('Location: index.php');
199 if (isset($_POST['num_questions']) && ($_POST['num_questions'] === 0)) {
200 $_POST['num_questions'] = '';
203 $onload = 'document.form.title.focus();';
205 require(AT_INCLUDE_PATH.'header.inc.php');
210 <script language="javascript" type="text/javascript">
211 function disable_texts (name) {
214 document.form['passpercent'].disabled=true;
215 document.form['passscore'].disabled=true;
216 document.form['passpercent'].value=0;
217 document.form['passscore'].value=0;
219 else if (name == 'percentage')
221 document.form['passpercent'].disabled=true;
222 document.form['passpercent'].value=0;
223 document.form['passscore'].disabled=false;
225 else if (name == 'points')
227 document.form['passpercent'].disabled=false;
228 document.form['passscore'].disabled=true;
229 document.form['passscore'].value=0;
234 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
235 <input type="hidden" name="test_type" value="<?php echo $test_type; ?>" />
236 <div class="input-form">
237 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('create_test'); ?></legend>
239 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="title"><?php echo _AT('title'); ?></label><br />
240 <input type="text" name="title" id="title" size="30" value="<?php echo $_POST['title']; ?>" />
244 <label for="description"><?php echo _AT('test_description'); ?></label><br />
245 <textarea name="description" cols="35" rows="3" id="description"><?php echo htmlspecialchars($_POST['description']); ?></textarea>
249 <label for="num_t"><?php echo _AT('num_takes_test'); ?></label><br />
250 <select name="num_takes" id="num_t">
251 <option value="<?php echo AT_TESTS_TAKE_UNLIMITED; ?>" <?php if ($_POST['num_takes'] == AT_TESTS_TAKE_UNLIMITED) { echo 'selected="selected"'; } ?>><?php echo _AT('unlimited'); ?></option>
253 <option value="1"<?php if ($_POST['num_takes'] == 1) { echo ' selected="selected"'; } ?>>1</option>
254 <option value="2"<?php if ($_POST['num_takes'] == 2) { echo ' selected="selected"'; } ?>>2</option>
255 <option value="3"<?php if ($_POST['num_takes'] == 3) { echo ' selected="selected"'; } ?>>3</option>
256 <option value="4"<?php if ($_POST['num_takes'] == 4) { echo ' selected="selected"'; } ?>>4</option>
257 <option value="5"<?php if ($_POST['num_takes'] == 5) { echo ' selected="selected"'; } ?>>5</option>
258 <option value="6"<?php if ($_POST['num_takes'] == 6) { echo ' selected="selected"'; } ?>>6</option>
259 <option value="7"<?php if ($_POST['num_takes'] == 7) { echo ' selected="selected"'; } ?>>7</option>
260 <option value="8"<?php if ($_POST['num_takes'] == 8) { echo ' selected="selected"'; } ?>>8</option>
261 <option value="9"<?php if ($_POST['num_takes'] == 9) { echo ' selected="selected"'; } ?>>9</option>
262 <option value="10"<?php if ($_POST['num_takes'] == 10) { echo ' selected="selected"'; } ?>>10</option>
263 <option value="15"<?php if ($_POST['num_takes'] == 15) { echo ' selected="selected"'; } ?>>15</option>
264 <option value="20"<?php if ($_POST['num_takes'] >= 20) { echo ' selected="selected"'; } ?>>20</option>
269 <?php echo _AT('available_on_my_courses'); ?><br />
271 if ($_POST['format'] == 1) {
272 $y = 'checked="checked"';
276 $n = 'checked="checked"';
279 <input type="radio" name="format" id="formatN" value="0" <?php echo $n; ?> /><label for="formatN"><?php echo _AT('no'); ?></label>
280 <input type="radio" name="format" id="formatY" value="1" <?php echo $y; ?> /><label for="formatY"><?php echo _AT('yes'); ?></label>
284 <?php echo _AT('anonymous_test'); ?><br />
286 if ($_POST['anonymous'] == 1) {
287 $y = 'checked="checked"';
291 $n = 'checked="checked"';
295 <input type="radio" name="anonymous" id="anonN" value="0" <?php echo $n; ?> /><label for="anonN"><?php echo _AT('no'); ?></label>
296 <input type="radio" name="anonymous" value="1" id="anonY" <?php echo $y; ?> /><label for="anonY"><?php echo _AT('yes'); ?></label>
300 <?php echo _AT('allow_guests'); ?><br />
302 if ($_POST['allow_guests'] == 1) {
303 $y = 'checked="checked"';
305 $disable_show_guest_form = '';
308 $n = 'checked="checked"';
309 $disable_show_guest_form = 'disabled="disabled"';
313 <input type="radio" name="allow_guests" id="allow_guestsN" value="0" <?php echo $n; ?> onfocus="document.form.show_guest_form.checked=false; document.form.show_guest_form.disabled=true;" /><label for="allow_guestsN"><?php echo _AT('no'); ?></label>
314 <input type="radio" name="allow_guests" value="1" id="allow_guestsY" <?php echo $y; ?> onfocus="document.form.show_guest_form.disabled=false;" /><label for="allow_guestsY"><?php echo _AT('yes'); ?></label>
317 if ($_POST['show_guest_form'] == 1)
318 $y = 'checked="checked"';
323 <input type="checkbox" name="show_guest_form" id="show_guest_form" value="1" <?php echo $y . ' '. $disable_show_guest_form; ?> /><label for="show_guest_form"><?php echo _AT('show_guest_form'); ?></label>
327 <?php echo _AT('display'); ?><br />
329 if ($_POST['display'] == 1) {
330 $y = 'checked="checked"';
334 $n = 'checked="checked"';
338 <input type="radio" name="display" id="displayN" value="0" <?php echo $n; ?> /><label for="displayN"><?php echo _AT('all_questions_on_page'); ?></label>
339 <input type="radio" name="display" id="displayY" value="1" <?php echo $y; ?> /><label for="displayY"><?php echo _AT('one_question_per_page'); ?></label>
343 <?php echo _AT('pass_score'); ?><br />
344 <input type="radio" name="pass_score" value="0" id="no" <?php if ($_POST['passpercent'] == 0 && $_POST['passscore'] == 0){echo 'checked="true"';} ?>
345 onfocus="disable_texts('both');" />
347 <label for="no" title="<?php echo _AT('pass_score'). ': '. _AT('no_pass_score'); ?>"><?php echo _AT('no_pass_score'); ?></label><br />
349 <input type="radio" name="pass_score" value="1" id="percentage" <?php if ($_POST['passpercent'] <> 0){echo 'checked="true"';} ?>
350 onfocus="disable_texts('points');" />
352 <input type="text" name="passpercent" id="passpercent" size="2" value="<?php echo $_POST['passpercent']; ?>"
353 <?php if ($_POST['passpercent'] == 0){echo 'disabled="true"';} ?> />
354 <label for="percentage" title="<?php echo _AT('pass_score'). ': '. _AT('percentage_score'); ?>"><?php echo '% ' . _AT('percentage_score'); ?></label><br />
356 <input type="radio" name="pass_score" value="2" id="points" <?php if ($_POST['passscore'] <> 0){echo 'checked="true"';} ?>
357 onfocus="disable_texts('percentage');" />
359 <input type="text" name="passscore" id="passscore" size="2" value="<?php echo $_POST['passscore']; ?>"
360 <?php if ($_POST['passscore'] == 0){echo 'disabled="true"';} ?>/>
361 <label for="points" title="<?php echo _AT('pass_score'). ': '. _AT('points_score'); ?>"><?php echo _AT('points_score'); ?></label>
365 <label for="passfeedback"><?php echo _AT('pass_feedback'); ?></label><br />
366 <textarea name="passfeedback" cols="35" rows="1" id="passfeedback"><?php echo htmlspecialchars($_POST['passfeedback']); ?></textarea>
370 <label for="failfeedback"><?php echo _AT('fail_feedback'); ?></label><br />
371 <textarea name="failfeedback" cols="35" rows="1" id="failfeedback"><?php echo htmlspecialchars($_POST['failfeedback']); ?></textarea>
375 <?php echo _AT('result_release'); ?><br />
377 if ($_POST['result_release'] == AT_RELEASE_IMMEDIATE) {
378 $check_marked = $check_never = '';
379 $check_immediate = 'checked="checked"';
381 } else if ($_POST['result_release'] == AT_RELEASE_MARKED) {
382 $check_immediate = $check_never = '';
383 $check_marked = 'checked="checked"';
385 } else if ($_POST['result_release'] == AT_RELEASE_NEVER) {
386 $check_immediate = $check_marked = '';
387 $check_never = 'checked="checked"';
390 <input type="radio" name="result_release" id="release1" value="<?php echo AT_RELEASE_IMMEDIATE; ?>" <?php echo $check_immediate; ?> /><label for="release1"><?php echo _AT('release_immediate'); ?></label><br />
391 <input type="radio" name="result_release" id="release2" value="<?php echo AT_RELEASE_MARKED; ?>" <?php echo $check_marked; ?> /><label for="release2"><?php echo _AT('release_marked'); ?></label><br />
392 <input type="radio" name="result_release" id="release3" value="<?php echo AT_RELEASE_NEVER; ?>" <?php echo $check_never; ?>/><label for="release3"><?php echo _AT('release_never'); ?></label>
396 <?php echo _AT('randomize_questions'); ?><br />
398 if ($_POST['random'] == 1) {
399 $y = 'checked="checked"';
403 $n = 'checked="checked"';
404 $disabled = 'disabled="disabled" ';
407 <input type="radio" name="random" id="random" value="0" checked="checked" onfocus="document.form.num_questions.disabled=true;" /><label for="random"><?php echo _AT('no'); ?></label>. <input type="radio" name="random" value="1" id="ry" onfocus="document.form.num_questions.disabled=false;" <?php echo $y; ?> /><label for="ry"><?php echo _AT('yes'); ?></label>, <input type="text" name="num_questions" id="num_questions" size="2" value="<?php echo $_POST['num_questions']; ?>" <?php echo $disabled . $n; ?> /> <label for="num_questions"><?php echo _AT('num_questions_per_test'); ?></label>
412 <?php echo _AT('start_date'); ?><br />
414 if (!isset($_POST['submit'])) {
415 $today_day = date('d');
416 $today_mon = date('m');
417 $today_year = date('Y');
418 $today_hour = date('H');
421 $today_day = intval($day_start);
422 $today_mon = intval($month_start);
423 $today_year = intval($year_start);
424 $today_hour = intval($hour_start);
425 $today_min = intval($min_start);
429 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
435 <?php echo _AT('end_date'); ?><br />
437 if (!isset($_POST['submit'])) {
438 $today_day = date('d');
439 $today_mon = date('m');
440 $today_year = date('Y');
441 $today_hour = date('H');
444 $today_day = intval($day_end);
445 $today_mon = intval($month_end);
446 $today_year = intval($year_end);
447 $today_hour = intval($hour_end);
448 $today_min = intval($min_end);
452 require(AT_INCLUDE_PATH.'html/release_date.inc.php');
457 <?php echo _AT('limit_to_group'); ?><br />
460 $sql = "SELECT * FROM ".TABLE_PREFIX."groups_types WHERE course_id=$_SESSION[course_id] ORDER BY title";
461 $result = mysql_query($sql, $db);
462 if (mysql_num_rows($result)) {
463 while ($row = mysql_fetch_assoc($result)) {
464 echo '<strong>'.$row['title'].'</strong><br />';
466 $sql = "SELECT * FROM ".TABLE_PREFIX."groups WHERE type_id=$row[type_id] ORDER BY title";
467 $g_result = mysql_query($sql, $db);
468 while ($grow = mysql_fetch_assoc($g_result)) {
469 echo ' <label><input type="checkbox" value="'.$grow['group_id'].'" name="groups['.$grow['group_id'].']" ';
470 if (is_array($current_groups) && in_array($grow['group_id'], $current_groups)) {
471 echo 'checked="checked"';
473 echo '/>'.$grow['title'].'</label><br />';
477 echo _AT('none_found');
483 <label for="inst"><?php echo _AT('instructions'); ?></label><br />
484 <textarea name="instructions" cols="35" rows="3" id="inst"><?php echo htmlspecialchars($_POST['instructions']); ?></textarea>
487 <div class="row buttons">
488 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
489 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
495 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>