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');
17 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['feedback'] = trim($_POST['feedback']);
37 $_POST['question'] = trim($_POST['question']);
38 $_POST['tid'] = intval($_POST['tid']);
39 $_POST['qid'] = intval($_POST['qid']);
40 $_POST['weight'] = intval($_POST['weight']);
41 $_POST['answer'] = intval($_POST['answer']);
43 if ($_POST['question'] == ''){
44 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
47 if (!$msg->containsErrors()) {
48 $answers = array_fill(0, 10, 0);
49 $answers[$_POST['answer']] = 1;
51 for ($i=0; $i<10; $i++) {
52 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
55 $_POST['feedback'] = $addslashes($_POST['feedback']);
56 $_POST['question'] = $addslashes($_POST['question']);
58 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
59 category_id=$_POST[category_id],
60 feedback='$_POST[feedback]',
61 question='$_POST[question]',
62 choice_0='{$_POST[choice][0]}',
63 choice_1='{$_POST[choice][1]}',
64 choice_2='{$_POST[choice][2]}',
65 choice_3='{$_POST[choice][3]}',
66 choice_4='{$_POST[choice][4]}',
67 choice_5='{$_POST[choice][5]}',
68 choice_6='{$_POST[choice][6]}',
69 choice_7='{$_POST[choice][7]}',
70 choice_8='{$_POST[choice][8]}',
71 choice_9='{$_POST[choice][9]}',
72 answer_0={$answers[0]},
73 answer_1={$answers[1]},
74 answer_2={$answers[2]},
75 answer_3={$answers[3]},
76 answer_4={$answers[4]},
77 answer_5={$answers[5]},
78 answer_6={$answers[6]},
79 answer_7={$answers[7]},
80 answer_8={$answers[8]},
81 answer_9={$answers[9]}
83 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
85 $result = mysql_query($sql, $db);
87 $msg->addFeedback('QUESTION_UPDATED');
89 header('Location: questions.php?tid='.$_POST['tid']);
91 header('Location: question_db.php');
97 if (!isset($_POST['submit'])) {
98 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=1";
99 $result = mysql_query($sql, $db);
101 if (!($row = mysql_fetch_array($result))){
102 require(AT_INCLUDE_PATH.'header.inc.php');
103 $msg->printErrors('ITEM_NOT_FOUND');
104 require (AT_INCLUDE_PATH.'footer.inc.php');
107 $_POST['category_id'] = $row['category_id'];
108 $_POST['feedback'] = $row['feedback'];
109 $_POST['required'] = $row['required'];
110 $_POST['weight'] = $row['weight'];
111 $_POST['question'] = $row['question'];
113 for ($i=0; $i<10; $i++) {
114 $_POST['choice'][$i] = $row['choice_'.$i];
115 $_POST['answer'][$i] = $row['answer_'.$i];
119 require(AT_INCLUDE_PATH.'header.inc.php');
122 <form action="tools/tests/edit_question_multi.php" method="post" name="form">
123 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
124 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
125 <input type="hidden" name="required" value="1" />
127 <div class="input-form">
128 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_mc'); ?></legend>
130 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cats"><?php echo _AT('category'); ?></label>
131 <select name="category_id" id="cats">
132 <?php print_question_cats($_POST['category_id']); ?>
137 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
138 <?php print_VE('optional_feedback'); ?>
140 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
144 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label>
145 <?php print_VE('question'); ?>
146 <textarea id="question" cols="50" rows="4" name="question"><?php
147 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
151 for ($i=0; $i<10; $i++) { ?>
153 <label for="choice_<?php echo $i; ?>"><?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label>
154 <?php print_VE('choice_' . $i); ?>
156 <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>
159 <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>
163 <div class="row buttons">
164 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
165 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
171 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>