2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
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');
17 require(AT_INCLUDE_PATH.'lib/likert_presets.inc.php');
19 authenticate(AT_PRIV_TESTS);
20 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
22 if (isset($_POST['cancel'])) {
23 $msg->addFeedback('CANCELLED');
24 header('Location: question_db.php');
26 } else if (isset($_POST['submit'])) {
27 $_POST['required'] = intval($_POST['required']);
28 $_POST['question'] = trim($_POST['question']);
29 $_POST['category_id'] = intval($_POST['category_id']);
31 $empty_fields = array();
32 if ($_POST['question'] == ''){
33 $empty_fields[] = _AT('question');
35 if ($_POST['choice'][0] == '') {
36 $empty_fields[] = _AT('choice').' 1';
39 if ($_POST['choice'][1] == '') {
40 $empty_fields[] = _AT('choice').' 2';
43 if (!empty($empty_fields)) {
44 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
47 if (!$msg->containsErrors()) {
48 $_POST['feedback'] = '';
49 $_POST['question'] = $addslashes($_POST['question']);
51 for ($i=0; $i<10; $i++) {
52 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
53 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
55 if ($_POST['choice'][$i] == '') {
56 /* an empty option can't be correct */
57 $_POST['answer'][$i] = 0;
61 $sql = "INSERT INTO ".TABLE_PREFIX."tests_questions VALUES ( 0,
67 '{$_POST[choice][0]}',
68 '{$_POST[choice][1]}',
69 '{$_POST[choice][2]}',
70 '{$_POST[choice][3]}',
71 '{$_POST[choice][4]}',
72 '{$_POST[choice][5]}',
73 '{$_POST[choice][6]}',
74 '{$_POST[choice][7]}',
75 '{$_POST[choice][8]}',
76 '{$_POST[choice][9]}',
99 $result = mysql_query($sql, $db);
101 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
102 header('Location: question_db.php');
105 } else if (isset($_POST['preset'])) {
107 $_POST['preset_num'] = intval($_POST['preset_num']);
109 if (isset($_likert_preset[$_POST['preset_num']])) {
110 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
111 } else if ($_POST['preset_num']) {
112 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_POST[preset_num] AND course_id=$_SESSION[course_id]";
113 $result = mysql_query($sql, $db);
114 if ($row = mysql_fetch_assoc($result)){
115 for ($i=0; $i<10; $i++) {
116 $_POST['choice'][$i] = $row['choice_' . $i];
123 $onload = 'document.form.category_id.focus();';
125 require(AT_INCLUDE_PATH.'header.inc.php');
128 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
129 <input type="hidden" name="required" value="1" />
131 <div class="input-form">
133 <h3><?php echo _AT('preset_scales'); ?></h3>
137 <select name="preset_num">
138 <optgroup label="<?php echo _AT('presets'); ?>">
141 foreach ($_likert_preset as $val=>$preset) {
142 echo '<option value="'.$val.'">'.$preset[0].' - '.$preset[count($preset)-1].'</option>';
147 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND type=4";
148 $result = mysql_query($sql, $db);
149 if ($row = mysql_fetch_assoc($result)) {
150 echo '<optgroup label="'. _AT('prev_used').'">';
151 $used_choices = array();
153 $choices = array_slice($row, 9, 10);
154 if (in_array($choices, $used_choices)) {
158 $used_choices[] = $choices;
160 for ($i=0; $i<=10; $i++) {
161 if ($row['choice_'.$i] == '') {
166 echo '<option value="'.$row['question_id'].'">'.$row['choice_0'].' - '.$row['choice_'.$i].'</option>';
167 } while ($row = mysql_fetch_assoc($result));
174 <div class="row buttons">
175 <input type="submit" name="preset" value="<?php echo _AT('set_preset'); ?>" class="button" />
180 <div class="input-form">
182 <label for="cats"><?php echo _AT('category'); ?></label><br />
183 <select name="category_id" id="cats">
184 <?php print_question_cats($_POST['category_id']); ?>
189 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label>
190 <?php print_VE('question'); ?>
191 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php
192 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
196 <?php for ($i=0; $i<10; $i++) { ?>
198 <?php if ($i==0 || $i==1) { ?>
199 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
201 <label for="choice_<?php echo $i; ?>">
202 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label><br />
203 <input type="text" id="choice_<?php echo $i; ?>" size="40" name="choice[<?php echo $i; ?>]" value="<?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?>" />
207 <div class="row buttons">
208 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
209 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
214 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>