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 /************************************************************************/
13 define('AT_INCLUDE_PATH', '../../../include/');
14 require(AT_INCLUDE_PATH.'vitals.inc.php');
15 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/likert_presets.inc.php');
17 authenticate(AT_PRIV_TESTS);
18 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
20 $qid = intval($_GET['qid']);
22 $qid = intval($_POST['qid']);
25 if (isset($_POST['cancel'])) {
26 $msg->addFeedback('CANCELLED');
28 header('Location: questions.php?tid='.$_POST['tid']);
30 header('Location: question_db.php');
33 } else if (isset($_POST['submit'])) {
34 $_POST['required'] = intval($_POST['required']);
35 $_POST['question'] = trim($_POST['question']);
36 $_POST['category_id'] = intval($_POST['category_id']);
37 $_POST['alignment'] = intval($_POST['alignment']);
39 $empty_fields = array();
40 if ($_POST['question'] == ''){
41 $empty_fields[] = _AT('question');
43 if ($_POST['choice'][0] == '') {
44 $empty_fields[] = _AT('choice').' 1';
47 if ($_POST['choice'][1] == '') {
48 $empty_fields[] = _AT('choice').' 2';
51 if (!empty($empty_fields)) {
52 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
55 if (!$msg->containsErrors()) {
56 $_POST['question'] = $addslashes($_POST['question']);
58 for ($i=0; $i<10; $i++) {
59 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
60 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
62 if ($_POST['choice'][$i] == '') {
63 /* an empty option can't be correct */
64 $_POST['answer'][$i] = 0;
67 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
68 category_id=$_POST[category_id],
70 question='$_POST[question]',
71 choice_0='{$_POST[choice][0]}',
72 choice_1='{$_POST[choice][1]}',
73 choice_2='{$_POST[choice][2]}',
74 choice_3='{$_POST[choice][3]}',
75 choice_4='{$_POST[choice][4]}',
76 choice_5='{$_POST[choice][5]}',
77 choice_6='{$_POST[choice][6]}',
78 choice_7='{$_POST[choice][7]}',
79 choice_8='{$_POST[choice][8]}',
80 choice_9='{$_POST[choice][9]}',
81 answer_0={$_POST[answer][0]},
82 answer_1={$_POST[answer][1]},
83 answer_2={$_POST[answer][2]},
84 answer_3={$_POST[answer][3]},
85 answer_4={$_POST[answer][4]},
86 answer_5={$_POST[answer][5]},
87 answer_6={$_POST[answer][6]},
88 answer_7={$_POST[answer][7]},
89 answer_8={$_POST[answer][8]},
90 answer_9={$_POST[answer][9]}
92 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
93 $result = mysql_query($sql, $db);
95 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
97 header('Location: questions.php?tid='.$_POST['tid']);
99 header('Location: question_db.php');
103 } else if (isset($_POST['preset'])) {
105 $_POST['preset_num'] = intval($_POST['preset_num']);
107 if (isset($_likert_preset[$_POST['preset_num']])) {
108 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
109 } else if ($_POST['preset_num']) {
110 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_POST[preset_num] AND course_id=$_SESSION[course_id]";
111 $result = mysql_query($sql, $db);
112 if ($row = mysql_fetch_assoc($result)){
113 for ($i=0; $i<10; $i++) {
114 $_POST['choice'][$i] = $row['choice_' . $i];
120 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=4";
121 $result = mysql_query($sql, $db);
123 if (!($row = mysql_fetch_array($result))){
124 require(AT_INCLUDE_PATH.'header.inc.php');
125 $msg->printErrors('ITEM_NOT_FOUND');
126 require (AT_INCLUDE_PATH.'footer.inc.php');
129 $_POST['required'] = $row['required'];
130 $_POST['question'] = $row['question'];
131 $_POST['category_id'] = $row['category_id'];
133 for ($i=0; $i<10; $i++) {
134 $_POST['choice'][$i] = $row['choice_'.$i];
138 require(AT_INCLUDE_PATH.'header.inc.php');
141 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
142 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
143 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
144 <input type="hidden" name="required" value="1" />
145 <fieldset class="group_form" style="width:88%;margin-left:auto;margin-right:auto;"><legend class="group_form"><?php echo _AT('preset_scales'); ?></legend>
146 <table cellspacing="1" cellpadding="0" border="0" class="bodyline" summary="" align="center">
148 <th align="left"><?php echo _AT('preset_scales'); ?> </th>
151 <td class="row1" nowrap="nowrap">
152 <select name="preset_num">
153 <option value="0"></option>
154 <optgroup label="<?php echo _AT('presets'); ?>"><?php
156 foreach ($_likert_preset as $val => $preset) {
157 echo '<option value="'.$val.'">'.$preset[0].' - '.$preset[count($preset)-1].'</option>';
162 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND type=4";
163 $result = mysql_query($sql, $db);
164 if ($row = mysql_fetch_assoc($result)) {
165 echo '<optgroup label="'. _AT('prev_used').'">';
166 $used_choices = array();
168 $choices = array_slice($row, 9, 10);
169 if (in_array($choices, $used_choices)) {
173 $used_choices[] = $choices;
175 for ($i=0; $i<=10; $i++) {
176 if ($row['choice_'.$i] == '') {
181 echo '<option value="'.$row['question_id'].'">'.$row['choice_0'].' - '.$row['choice_'.$i].'</option>';
182 } while ($row = mysql_fetch_assoc($result));
187 <input type="submit" name="preset" value="<?php echo _AT('set_preset'); ?>" class="button" />
194 <div class="input-form">
195 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('question'); ?></legend>
197 <label for="cats"><?php echo _AT('category'); ?></label><br />
198 <select name="category_id" id="cats">
199 <?php print_question_cats($_POST['category_id']); ?>
204 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
206 <?php print_VE('question'); ?>
208 <textarea id="question" cols="50" rows="6" name="question"><?php echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
212 for ($i=0; $i<10; $i++) { ?>
214 <?php if ($i==0 || $i==1) { ?>
215 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
218 <label for="choice_<?php echo $i; ?>">
219 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label><br />
220 <input type="text" id="choice_<?php echo $i; ?>" size="40" name="choice[<?php echo $i; ?>]" value="<?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?>" />
224 <div class="row buttons">
225 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
226 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
232 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>