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']);
40 $_POST['answer'] = intval($_POST['answer']);
42 if ($_POST['question'] == ''){
43 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
46 if (!$msg->containsErrors()) {
47 $answers = array_fill(0, 10, 0);
48 $answers[$_POST['answer']] = 1;
50 for ($i=0; $i<10; $i++) {
51 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
54 $_POST['feedback'] = $addslashes($_POST['feedback']);
55 $_POST['question'] = $addslashes($_POST['question']);
57 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
58 category_id=$_POST[category_id],
59 feedback='$_POST[feedback]',
60 question='$_POST[question]',
61 choice_0='{$_POST[choice][0]}',
62 choice_1='{$_POST[choice][1]}',
63 choice_2='{$_POST[choice][2]}',
64 choice_3='{$_POST[choice][3]}',
65 choice_4='{$_POST[choice][4]}',
66 choice_5='{$_POST[choice][5]}',
67 choice_6='{$_POST[choice][6]}',
68 choice_7='{$_POST[choice][7]}',
69 choice_8='{$_POST[choice][8]}',
70 choice_9='{$_POST[choice][9]}',
71 answer_0={$answers[0]},
72 answer_1={$answers[1]},
73 answer_2={$answers[2]},
74 answer_3={$answers[3]},
75 answer_4={$answers[4]},
76 answer_5={$answers[5]},
77 answer_6={$answers[6]},
78 answer_7={$answers[7]},
79 answer_8={$answers[8]},
80 answer_9={$answers[9]}
82 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
84 $result = mysql_query($sql, $db);
86 $msg->addFeedback('QUESTION_UPDATED');
88 header('Location: questions.php?tid='.$_POST['tid']);
90 header('Location: question_db.php');
96 if (!isset($_POST['submit'])) {
97 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=1";
98 $result = mysql_query($sql, $db);
100 if (!($row = mysql_fetch_array($result))){
101 require(AT_INCLUDE_PATH.'header.inc.php');
102 $msg->printErrors('ITEM_NOT_FOUND');
103 require (AT_INCLUDE_PATH.'footer.inc.php');
106 $_POST['category_id'] = $row['category_id'];
107 $_POST['feedback'] = $row['feedback'];
108 $_POST['required'] = $row['required'];
109 $_POST['weight'] = $row['weight'];
110 $_POST['question'] = $row['question'];
112 for ($i=0; $i<10; $i++) {
113 $_POST['choice'][$i] = $row['choice_'.$i];
114 $_POST['answer'][$i] = $row['answer_'.$i];
118 require(AT_INCLUDE_PATH.'header.inc.php');
121 <form action="mods/_standard/tests/edit_question_multi.php" method="post" name="form">
122 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
123 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
124 <input type="hidden" name="required" value="1" />
126 <div class="input-form">
127 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_mc'); ?></legend>
129 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label>
130 <select name="category_id" id="cats">
131 <?php print_question_cats($_POST['category_id']); ?>
136 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
137 <?php print_VE('optional_feedback'); ?>
139 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
143 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
144 <?php print_VE('question'); ?>
145 <textarea id="question" cols="50" rows="4" name="question"><?php
146 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
150 for ($i=0; $i<10; $i++) { ?>
152 <label for="choice_<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label>
153 <?php print_VE('choice_' . $i); ?>
155 <small><input type="radio" name="answer" id="answer_<?php echo $i; ?>" value="<?php echo $i; ?>" <?php if($_POST['answer'][$i]) { echo 'checked="checked"';} ?>><label for="answer_<?php echo $i; ?>"><?php echo _AT('correct_answer'); ?></label></small>
158 <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>
162 <div class="row buttons">
163 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
164 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
170 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>