2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_question_queries.inc.php');
19 authenticate(AT_PRIV_TESTS);
20 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
22 if (isset($_POST['cancel']) || isset($_POST['submit_no'])) {
23 $msg->addFeedback('CANCELLED');
24 header('Location: question_db.php');
26 } else if ($_POST['submit'] || $_POST['submit_yes']) {
27 $_POST['required'] = intval($_POST['required']);
28 $_POST['feedback'] = trim($_POST['feedback']);
29 $_POST['question'] = trim($_POST['question']);
30 $_POST['category_id'] = intval($_POST['category_id']);
32 if ($_POST['question'] == ''){
33 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
36 if (!$msg->containsErrors()) {
37 $choice_new = array(); // stores the non-blank choices
38 $answer_new = array(); // stores the associated "answer" for the choices
39 for ($i=0; $i<10; $i++) {
41 * Db defined it to be 255 length, chop strings off it it's less than that
44 $_POST['choice'][$i] = validate_length($_POST['choice'][$i], 255);
45 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
46 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
48 if ($_POST['choice'][$i] == '') {
49 /* an empty option can't be correct */
50 $_POST['answer'][$i] = 0;
52 /* filter out empty choices/ remove gaps */
53 $choice_new[] = $_POST['choice'][$i];
54 $answer_new[] = $_POST['answer'][$i];
56 if ($_POST['answer'][$i] != 0)
61 if ($has_answer != TRUE && !$_POST['submit_yes']) {
63 $hidden_vars['required'] = htmlspecialchars($_POST['required']);
64 $hidden_vars['feedback'] = htmlspecialchars($_POST['feedback']);
65 $hidden_vars['question'] = htmlspecialchars($_POST['question']);
66 $hidden_vars['category_id'] = htmlspecialchars($_POST['category_id']);
68 for ($i = 0; $i < count($choice_new); $i++) {
69 $hidden_vars['answer['.$i.']'] = htmlspecialchars($answer_new[$i]);
70 $hidden_vars['choice['.$i.']'] = htmlspecialchars($choice_new[$i]);
73 $msg->addConfirm('NO_ANSWER', $hidden_vars);
76 //add slahes throughout - does that fix it?
77 $_POST['answer'] = $answer_new;
78 $_POST['choice'] = $choice_new;
79 $_POST['answer'] = array_pad($_POST['answer'], 10, 0);
80 $_POST['choice'] = array_pad($_POST['choice'], 10, '');
82 $_POST['feedback'] = $addslashes($_POST['feedback']);
83 $_POST['question'] = $addslashes($_POST['question']);
85 $sql_params = array( $_POST['category_id'],
86 $_SESSION['course_id'],
108 $_POST['answer'][9]);
109 $sql = vsprintf(AT_SQL_QUESTION_MULTIANSWER, $sql_params);
111 $result = mysql_query($sql, $db);
113 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
114 header('Location: question_db.php');
120 $onload = 'document.form.category_id.focus();';
122 require(AT_INCLUDE_PATH.'header.inc.php');
124 $msg->printConfirm();
126 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
127 <input type="hidden" name="required" value="1" />
128 <div class="input-form">
129 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_ma'); ?></legend>
131 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label><br />
132 <select name="category_id" id="cats">
133 <?php print_question_cats($_POST['category_id']); ?>
138 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
139 <?php print_VE('optional_feedback'); ?>
140 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
144 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
145 <?php print_VE('question'); ?>
146 <textarea id="question" cols="50" rows="4" name="question" style="width:90%;"><?php echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
150 for ($i=0; $i<10; $i++) {
153 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?>
155 <?php print_VE('choice_' . $i); ?>
159 <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>
161 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]"><?php
162 echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?></textarea>
166 <div class="row buttons">
167 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
168 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
174 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>