2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2008 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 /************************************************************************/
14 define('AT_INCLUDE_PATH', '../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'lib/likert_presets.inc.php');
18 authenticate(AT_PRIV_TESTS);
19 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
21 $qid = intval($_GET['qid']);
23 $qid = intval($_POST['qid']);
26 if (isset($_POST['cancel'])) {
27 $msg->addFeedback('CANCELLED');
29 header('Location: questions.php?tid='.$_POST['tid']);
31 header('Location: question_db.php');
34 } else if (isset($_POST['submit'])) {
35 $_POST['required'] = intval($_POST['required']);
36 $_POST['question'] = trim($_POST['question']);
37 $_POST['category_id'] = intval($_POST['category_id']);
38 $_POST['alignment'] = intval($_POST['alignment']);
40 $empty_fields = array();
41 if ($_POST['question'] == ''){
42 $empty_fields[] = _AT('question');
44 if ($_POST['choice'][0] == '') {
45 $empty_fields[] = _AT('choice').' 1';
48 if ($_POST['choice'][1] == '') {
49 $empty_fields[] = _AT('choice').' 2';
52 if (!empty($empty_fields)) {
53 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
56 if (!$msg->containsErrors()) {
57 $_POST['question'] = $addslashes($_POST['question']);
59 for ($i=0; $i<10; $i++) {
60 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
61 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
63 if ($_POST['choice'][$i] == '') {
64 /* an empty option can't be correct */
65 $_POST['answer'][$i] = 0;
68 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
69 category_id=$_POST[category_id],
71 question='$_POST[question]',
72 choice_0='{$_POST[choice][0]}',
73 choice_1='{$_POST[choice][1]}',
74 choice_2='{$_POST[choice][2]}',
75 choice_3='{$_POST[choice][3]}',
76 choice_4='{$_POST[choice][4]}',
77 choice_5='{$_POST[choice][5]}',
78 choice_6='{$_POST[choice][6]}',
79 choice_7='{$_POST[choice][7]}',
80 choice_8='{$_POST[choice][8]}',
81 choice_9='{$_POST[choice][9]}',
82 answer_0={$_POST[answer][0]},
83 answer_1={$_POST[answer][1]},
84 answer_2={$_POST[answer][2]},
85 answer_3={$_POST[answer][3]},
86 answer_4={$_POST[answer][4]},
87 answer_5={$_POST[answer][5]},
88 answer_6={$_POST[answer][6]},
89 answer_7={$_POST[answer][7]},
90 answer_8={$_POST[answer][8]},
91 answer_9={$_POST[answer][9]}
93 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
94 $result = mysql_query($sql, $db);
96 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
98 header('Location: questions.php?tid='.$_POST['tid']);
100 header('Location: question_db.php');
104 } else if (isset($_POST['preset'])) {
106 $_POST['preset_num'] = intval($_POST['preset_num']);
108 if (isset($_likert_preset[$_POST['preset_num']])) {
109 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
110 } else if ($_POST['preset_num']) {
111 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_POST[preset_num] AND course_id=$_SESSION[course_id]";
112 $result = mysql_query($sql, $db);
113 if ($row = mysql_fetch_assoc($result)){
114 for ($i=0; $i<10; $i++) {
115 $_POST['choice'][$i] = $row['choice_' . $i];
121 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=4";
122 $result = mysql_query($sql, $db);
124 if (!($row = mysql_fetch_array($result))){
125 require(AT_INCLUDE_PATH.'header.inc.php');
126 $msg->printErrors('ITEM_NOT_FOUND');
127 require (AT_INCLUDE_PATH.'footer.inc.php');
130 $_POST['required'] = $row['required'];
131 $_POST['question'] = $row['question'];
132 $_POST['category_id'] = $row['category_id'];
134 for ($i=0; $i<10; $i++) {
135 $_POST['choice'][$i] = $row['choice_'.$i];
139 require(AT_INCLUDE_PATH.'header.inc.php');
142 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
143 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
144 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
145 <input type="hidden" name="required" value="1" />
146 <fieldset class="group_form" style="width:88%;margin-left:auto;margin-right:auto;"><legend class="group_form"><?php echo _AT('preset_scales'); ?></legend>
147 <table cellspacing="1" cellpadding="0" border="0" class="bodyline" summary="" align="center">
149 <th align="left"><?php echo _AT('preset_scales'); ?> </th>
152 <td class="row1" nowrap="nowrap">
153 <select name="preset_num">
154 <option value="0"></option>
155 <optgroup label="<?php echo _AT('presets'); ?>"><?php
157 foreach ($_likert_preset as $val => $preset) {
158 echo '<option value="'.$val.'">'.$preset[0].' - '.$preset[count($preset)-1].'</option>';
163 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND type=4";
164 $result = mysql_query($sql, $db);
165 if ($row = mysql_fetch_assoc($result)) {
166 echo '<optgroup label="'. _AT('prev_used').'">';
167 $used_choices = array();
169 $choices = array_slice($row, 9, 10);
170 if (in_array($choices, $used_choices)) {
174 $used_choices[] = $choices;
176 for ($i=0; $i<=10; $i++) {
177 if ($row['choice_'.$i] == '') {
182 echo '<option value="'.$row['question_id'].'">'.$row['choice_0'].' - '.$row['choice_'.$i].'</option>';
183 } while ($row = mysql_fetch_assoc($result));
188 <input type="submit" name="preset" value="<?php echo _AT('set_preset'); ?>" class="button" />
195 <div class="input-form">
196 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('question'); ?></legend>
198 <label for="cats"><?php echo _AT('category'); ?></label><br />
199 <select name="category_id" id="cats">
200 <?php print_question_cats($_POST['category_id']); ?>
205 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label>
207 <?php print_VE('question'); ?>
209 <textarea id="question" cols="50" rows="6" name="question"><?php echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
213 for ($i=0; $i<10; $i++) { ?>
215 <?php if ($i==0 || $i==1) { ?>
216 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
219 <label for="choice_<?php echo $i; ?>">
220 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label><br />
221 <input type="text" id="choice_<?php echo $i; ?>" size="40" name="choice[<?php echo $i; ?>]" value="<?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?>" />
225 <div class="row buttons">
226 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
227 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
233 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>