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 // for matching test questions
21 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
24 $qid = intval($_GET['qid']);
26 $qid = intval($_POST['qid']);
29 if (isset($_POST['cancel'])) {
30 $msg->addFeedback('CANCELLED');
32 header('Location: questions.php?tid='.$_POST['tid']);
34 header('Location: question_db.php');
37 } else if (isset($_POST['submit'])) {
38 $_POST['tid'] = intval($_POST['tid']);
39 $_POST['qid'] = intval($_POST['qid']);
40 $_POST['feedback'] = trim($_POST['feedback']);
41 $_POST['instructions'] = trim($_POST['instructions']);
42 $_POST['category_id'] = intval($_POST['category_id']);
44 for ($i = 0 ; $i < 10; $i++) {
45 $_POST['question'][$i] = $addslashes(trim($_POST['question'][$i]));
46 $_POST['question_answer'][$i] = (int) $_POST['question_answer'][$i];
47 $_POST['answer'][$i] = $addslashes(trim($_POST['answer'][$i]));
50 if ($_POST['question'][0] == ''
51 || $_POST['question'][1] == ''
52 || $_POST['answer'][0] == ''
53 || $_POST['answer'][1] == '') {
55 $msg->addError('QUESTION_EMPTY');
58 if (!$msg->containsErrors()) {
59 $_POST['feedback'] = $addslashes($_POST['feedback']);
60 $_POST['instructions'] = $addslashes($_POST['instructions']);
62 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
63 category_id=$_POST[category_id],
64 feedback='$_POST[feedback]',
65 question='$_POST[instructions]',
66 choice_0='{$_POST[question][0]}',
67 choice_1='{$_POST[question][1]}',
68 choice_2='{$_POST[question][2]}',
69 choice_3='{$_POST[question][3]}',
70 choice_4='{$_POST[question][4]}',
71 choice_5='{$_POST[question][5]}',
72 choice_6='{$_POST[question][6]}',
73 choice_7='{$_POST[question][7]}',
74 choice_8='{$_POST[question][8]}',
75 choice_9='{$_POST[question][9]}',
76 answer_0={$_POST[question_answer][0]},
77 answer_1={$_POST[question_answer][1]},
78 answer_2={$_POST[question_answer][2]},
79 answer_3={$_POST[question_answer][3]},
80 answer_4={$_POST[question_answer][4]},
81 answer_5={$_POST[question_answer][5]},
82 answer_6={$_POST[question_answer][6]},
83 answer_7={$_POST[question_answer][7]},
84 answer_8={$_POST[question_answer][8]},
85 answer_9={$_POST[question_answer][9]},
86 option_0='{$_POST[answer][0]}',
87 option_1='{$_POST[answer][1]}',
88 option_2='{$_POST[answer][2]}',
89 option_3='{$_POST[answer][3]}',
90 option_4='{$_POST[answer][4]}',
91 option_5='{$_POST[answer][5]}',
92 option_6='{$_POST[answer][6]}',
93 option_7='{$_POST[answer][7]}',
94 option_8='{$_POST[answer][8]}',
95 option_9='{$_POST[answer][9]}'
97 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
98 $result = mysql_query($sql, $db);
100 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
102 header('Location: questions.php?tid='.$_POST['tid']);
104 header('Location: question_db.php');
109 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=5";
110 $result = mysql_query($sql, $db);
112 if (!($row = mysql_fetch_assoc($result))){
113 require(AT_INCLUDE_PATH.'header.inc.php');
114 $msg->printErrors('ITEM_NOT_FOUND');
115 require (AT_INCLUDE_PATH.'footer.inc.php');
118 $_POST['feedback'] = $row['feedback'];
119 $_POST['instructions'] = $row['question'];
120 $_POST['category_id'] = $row['category_id'];
122 for ($i=0; $i<10; $i++) {
123 $_POST['question'][$i] = $row['choice_'.$i];
124 $_POST['question_answer'][$i] = $row['answer_'.$i];
125 $_POST['answer'][$i] = $row['option_'.$i];
130 require(AT_INCLUDE_PATH.'header.inc.php');
133 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
134 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
135 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
138 <div class="input-form">
139 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_matching'); ?></legend>
141 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label><br />
142 <select name="category_id" id="cats">
143 <?php print_question_cats($_POST['category_id']); ?>
148 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
149 <?php print_VE('optional_feedback'); ?>
151 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php
152 echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
156 <label for="instructions"><?php echo _AT('instructions'); ?></label>
157 <?php print_VE('instructions'); ?>
158 <textarea id="instructions" cols="50" rows="3" name="instructions"><?php
159 echo htmlspecialchars(stripslashes($_POST['instructions'])); ?></textarea>
163 <h2><?php echo _AT('questions');?></h2>
165 <?php for ($i=0; $i<10; $i++): ?>
167 <?php if ($i < 2) :?>
168 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
170 <?php echo _AT('question'); ?> <?php echo ($i+1); ?>
172 <?php print_VE('question_' . $i); ?>
176 <select name="question_answer[<?php echo $i; ?>]">
177 <option value="-1">-</option>
178 <?php foreach ($_letters as $key => $value): ?>
179 <option value="<?php echo $key; ?>" <?php if ($key == $_POST['question_answer'][$i]) { echo 'selected="selected"'; }?>><?php echo $value; ?></option>
183 <textarea id="question_<?php echo $i; ?>" cols="50" rows="2" name="question[<?php echo $i; ?>]"><?php
184 echo htmlspecialchars(stripslashes($_POST['question'][$i])); ?></textarea>
189 <h2><?php echo _AT('answers');?></h2>
191 <?php for ($i=0; $i<10; $i++): ?>
193 <?php if ($i < 2) :?>
194 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
196 <?php echo _AT('answer'); ?> <?php echo $_letters[$i]; ?>
197 <?php print_VE('answer' . $i); ?>
199 <textarea id="answer_<?php echo $i; ?>" cols="50" rows="2" name="answer[<?php echo $i; ?>]"><?php
200 echo htmlspecialchars(stripslashes($_POST['answer'][$i])); ?></textarea>
204 <div class="row buttons">
205 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
206 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
212 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>