2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg */
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or*/
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /****************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_TESTS);
19 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
21 if (isset($_POST['cancel'])) {
22 $msg->addFeedback('CANCELLED');
23 header('Location: question_db.php');
25 } else if ($_POST['submit']) {
26 $missing_fields = array();
28 $_POST['feedback'] = trim($_POST['feedback']);
29 $_POST['question'] = trim($_POST['question']);
30 $_POST['category_id'] = intval($_POST['category_id']);
32 if ($_POST['question'] == ''){
33 $missing_fields[] = _AT('question');
36 if (trim($_POST['choice'][0]) == '') {
37 $missing_fields[] = _AT('item').' 1';
39 if (trim($_POST['choice'][1]) == '') {
40 $missing_fields[] = _AT('item').' 2';
43 if ($missing_fields) {
44 $missing_fields = implode(', ', $missing_fields);
45 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
48 if (!$msg->containsErrors()) {
49 $choice_new = array(); // stores the non-blank choices
50 $answer_new = array(); // stores the non-blank answers
51 $order = 0; // order count
52 for ($i=0; $i<10; $i++) {
53 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
55 if ($_POST['choice'][$i] != '') {
56 /* filter out empty choices/ remove gaps */
57 $choice_new[] = $_POST['choice'][$i];
58 $answer_new[] = $order++;
62 $_POST['choice'] = array_pad($choice_new, 10, '');
63 $answer_new = array_pad($answer_new, 10, 0);
64 $_POST['feedback'] = $addslashes($_POST['feedback']);
65 $_POST['question'] = $addslashes($_POST['question']);
67 $sql = "INSERT INTO ".TABLE_PREFIX."tests_questions VALUES ( NULL,
73 '{$_POST[choice][0]}',
74 '{$_POST[choice][1]}',
75 '{$_POST[choice][2]}',
76 '{$_POST[choice][3]}',
77 '{$_POST[choice][4]}',
78 '{$_POST[choice][5]}',
79 '{$_POST[choice][6]}',
80 '{$_POST[choice][7]}',
81 '{$_POST[choice][8]}',
82 '{$_POST[choice][9]}',
106 $result = mysql_query($sql, $db);
108 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
109 header('Location: question_db.php');
114 $onload = 'document.form.category_id.focus();';
116 require(AT_INCLUDE_PATH.'header.inc.php');
119 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
120 <input type="hidden" name="required" value="1" />
121 <div class="input-form">
123 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cats"><?php echo _AT('category'); ?></label><br />
124 <select name="category_id" id="cats">
125 <?php print_question_cats($_POST['category_id']); ?>
130 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
131 <?php print_VE('optional_feedback'); ?>
133 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
137 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label>
138 <?php print_VE('question'); ?>
139 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php
140 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
143 <?php for ($i=0; $i<10; $i++): ?>
145 <?php if ($i < 2): ?>
146 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
147 <?php endif; ?> <?php echo _AT('item'); ?> <?php echo ($i+1); ?>
149 <?php print_VE('choice_' . $i); ?>
153 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?></textarea>
157 <div class="row buttons">
158 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
159 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
164 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>