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');
16 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['feedback'] = trim($_POST['feedback']);
36 $_POST['question'] = trim($_POST['question']);
37 $_POST['tid'] = intval($_POST['tid']);
38 $_POST['qid'] = intval($_POST['qid']);
39 $_POST['weight'] = intval($_POST['weight']);
41 if ($_POST['question'] == ''){
42 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
45 if (!$msg->containsErrors()) {
46 $choice_new = array(); // stores the non-blank choices
47 $answer_new = array(); // stores the associated "answer" for the choices
49 for ($i=0; $i<10; $i++) {
50 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
52 * Db defined it to be 255 length, chop strings off it it's less than that
55 $_POST['choice'][$i] = validate_length($_POST['choice'][$i], 255);
56 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
58 if ($_POST['choice'][$i] == '') {
59 /* an empty option can't be correct */
60 $_POST['answer'][$i] = 0;
62 /* filter out empty choices/ remove gaps */
63 $choice_new[] = $_POST['choice'][$i];
64 $answer_new[] = $_POST['answer'][$i];
68 $_POST['answer'] = $answer_new;
69 $_POST['choice'] = $choice_new;
70 $_POST['answer'] = array_pad($_POST['answer'], 10, 0);
71 $_POST['choice'] = array_pad($_POST['choice'], 10, '');
73 $_POST['feedback'] = $addslashes($_POST['feedback']);
74 $_POST['question'] = $addslashes($_POST['question']);
76 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
77 category_id=$_POST[category_id],
78 feedback='$_POST[feedback]',
79 question='$_POST[question]',
80 choice_0='{$_POST[choice][0]}',
81 choice_1='{$_POST[choice][1]}',
82 choice_2='{$_POST[choice][2]}',
83 choice_3='{$_POST[choice][3]}',
84 choice_4='{$_POST[choice][4]}',
85 choice_5='{$_POST[choice][5]}',
86 choice_6='{$_POST[choice][6]}',
87 choice_7='{$_POST[choice][7]}',
88 choice_8='{$_POST[choice][8]}',
89 choice_9='{$_POST[choice][9]}',
90 answer_0={$_POST[answer][0]},
91 answer_1={$_POST[answer][1]},
92 answer_2={$_POST[answer][2]},
93 answer_3={$_POST[answer][3]},
94 answer_4={$_POST[answer][4]},
95 answer_5={$_POST[answer][5]},
96 answer_6={$_POST[answer][6]},
97 answer_7={$_POST[answer][7]},
98 answer_8={$_POST[answer][8]},
99 answer_9={$_POST[answer][9]}
101 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
103 $result = mysql_query($sql, $db);
105 $msg->addFeedback('QUESTION_UPDATED');
107 header('Location: questions.php?tid='.$_POST['tid']);
109 header('Location: question_db.php');
115 if (!isset($_POST['submit'])) {
116 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=7";
117 $result = mysql_query($sql, $db);
119 if (!($row = mysql_fetch_array($result))){
120 require(AT_INCLUDE_PATH.'header.inc.php');
121 $msg->printErrors('ITEM_NOT_FOUND');
122 require (AT_INCLUDE_PATH.'footer.inc.php');
125 $_POST['category_id'] = $row['category_id'];
126 $_POST['feedback'] = $row['feedback'];
127 $_POST['required'] = $row['required'];
128 $_POST['weight'] = $row['weight'];
129 $_POST['question'] = $row['question'];
131 for ($i=0; $i<10; $i++) {
132 $_POST['choice'][$i] = $row['choice_'.$i];
133 $_POST['answer'][$i] = $row['answer_'.$i];
137 require(AT_INCLUDE_PATH.'header.inc.php');
140 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
141 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
142 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
143 <input type="hidden" name="required" value="1" />
145 <div class="input-form">
146 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_ma'); ?></legend>
148 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label>
149 <select name="category_id" id="cats">
150 <?php print_question_cats($_POST['category_id']); ?>
155 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
156 <?php print_VE('optional_feedback'); ?>
158 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
162 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
163 <?php print_VE('question'); ?>
164 <textarea id="question" cols="50" rows="4" name="question"><?php
165 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
169 for ($i=0; $i<10; $i++) { ?>
171 <label for="choice_<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label>
172 <?php print_VE('choice_'.$i); ?>
174 <small><input type="checkbox" name="answer[<?php echo $i; ?>]" id="answer_<?php echo $i; ?>" value="1" <?php if($_POST['answer'][$i]) { echo 'checked="checked"';} ?>><label for="answer_<?php echo $i; ?>"><?php echo _AT('correct_answer'); ?></label></small>
177 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]" class="formfield"><?php 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" />
189 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>