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 $missing_fields = array();
36 $_POST['feedback'] = trim($_POST['feedback']);
37 $_POST['question'] = trim($_POST['question']);
38 $_POST['category_id'] = intval($_POST['category_id']);
40 if ($_POST['question'] == ''){
41 $missing_fields[] = _AT('question');
44 if (trim($_POST['choice'][0]) == '') {
45 $missing_fields[] = _AT('item').' 1';
47 if (trim($_POST['choice'][1]) == '') {
48 $missing_fields[] = _AT('item').' 2';
51 if ($missing_fields) {
52 $missing_fields = implode(', ', $missing_fields);
53 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
55 if (!$msg->containsErrors()) {
56 $_POST['question'] = $addslashes($_POST['question']);
57 $_POST['feedback'] = $addslashes($_POST['feedback']);
59 $choice_new = array(); // stores the non-blank choices
60 $answer_new = array(); // stores the non-blank answers
61 $order = 0; // order count
62 for ($i=0; $i<10; $i++) {
64 * Db defined it to be 255 length, chop strings off it it's less than that
67 $_POST['choice'][$i] = validate_length($_POST['choice'][$i], 255);
68 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
70 if ($_POST['choice'][$i] != '') {
71 /* filter out empty choices/ remove gaps */
72 $choice_new[] = $_POST['choice'][$i];
73 $answer_new[] = $order++;
77 $_POST['choice'] = array_pad($choice_new, 10, '');
78 $answer_new = array_pad($answer_new, 10, 0);
80 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
81 category_id=$_POST[category_id],
82 feedback='$_POST[feedback]',
83 question='$_POST[question]',
84 choice_0='{$_POST[choice][0]}',
85 choice_1='{$_POST[choice][1]}',
86 choice_2='{$_POST[choice][2]}',
87 choice_3='{$_POST[choice][3]}',
88 choice_4='{$_POST[choice][4]}',
89 choice_5='{$_POST[choice][5]}',
90 choice_6='{$_POST[choice][6]}',
91 choice_7='{$_POST[choice][7]}',
92 choice_8='{$_POST[choice][8]}',
93 choice_9='{$_POST[choice][9]}',
94 answer_0=$answer_new[0],
95 answer_1=$answer_new[1],
96 answer_2=$answer_new[2],
97 answer_3=$answer_new[3],
98 answer_4=$answer_new[4],
99 answer_5=$answer_new[5],
100 answer_6=$answer_new[6],
101 answer_7=$answer_new[7],
102 answer_8=$answer_new[8],
103 answer_9=$answer_new[9]
105 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
106 $result = mysql_query($sql, $db);
108 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
110 header('Location: questions.php?tid='.$_POST['tid']);
112 header('Location: question_db.php');
117 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=6";
118 $result = mysql_query($sql, $db);
120 if (!($row = mysql_fetch_assoc($result))){
121 require(AT_INCLUDE_PATH.'header.inc.php');
122 $msg->printErrors('ITEM_NOT_FOUND');
123 require (AT_INCLUDE_PATH.'footer.inc.php');
127 $_POST['required'] = $row['required'];
128 $_POST['question'] = $row['question'];
129 $_POST['category_id'] = $row['category_id'];
130 $_POST['feedback'] = $row['feedback'];
132 for ($i=0; $i<10; $i++) {
133 $_POST['choice'][$i] = $row['choice_'.$i];
136 require(AT_INCLUDE_PATH.'header.inc.php');
139 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
140 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
141 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
143 <div class="input-form">
145 <label for="cats"><?php echo _AT('category'); ?></label><br />
146 <select name="category_id" id="cats">
147 <?php print_question_cats($_POST['category_id']); ?>
152 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
153 <?php print_VE('optional_feedback'); ?>
155 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
159 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
161 <?php print_VE('question'); ?>
163 <textarea id="question" cols="50" rows="6" name="question"><?php echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
166 <?php for ($i=0; $i<10; $i++): ?>
168 <?php if ($i < 2): ?>
169 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
170 <?php endif; ?> <?php echo _AT('item'); ?> <?php echo ($i+1); ?>
172 <?php print_VE('choice_' . $i); ?>
176 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]"><?php
177 echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?></textarea>
181 <div class="row buttons">
182 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
183 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
188 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>