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'])) {
23 $msg->addFeedback('CANCELLED');
24 header('Location: question_db.php');
26 } else if ($_POST['submit']) {
27 $missing_fields = array();
29 $_POST['feedback'] = trim($_POST['feedback']);
30 $_POST['question'] = trim($_POST['question']);
31 $_POST['category_id'] = intval($_POST['category_id']);
33 if ($_POST['question'] == ''){
34 $missing_fields[] = _AT('question');
37 if (trim($_POST['choice'][0]) == '') {
38 $missing_fields[] = _AT('item').' 1';
40 if (trim($_POST['choice'][1]) == '') {
41 $missing_fields[] = _AT('item').' 2';
44 if ($missing_fields) {
45 $missing_fields = implode(', ', $missing_fields);
46 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
49 if (!$msg->containsErrors()) {
50 $choice_new = array(); // stores the non-blank choices
51 $answer_new = array(); // stores the non-blank answers
52 $order = 0; // order count
53 for ($i=0; $i<10; $i++) {
55 * Db defined it to be 255 length, chop strings off it it's less than that
58 $_POST['choice'][$i] = validate_length($_POST['choice'][$i], 255);
59 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
61 if ($_POST['choice'][$i] != '') {
62 /* filter out empty choices/ remove gaps */
63 $choice_new[] = $_POST['choice'][$i];
64 $answer_new[] = $order++;
68 $_POST['choice'] = array_pad($choice_new, 10, '');
69 $answer_new = array_pad($answer_new, 10, 0);
70 $_POST['feedback'] = $addslashes($_POST['feedback']);
71 $_POST['question'] = $addslashes($_POST['question']);
73 $sql_params = array( $_POST['category_id'],
74 $_SESSION['course_id'],
97 $sql = vsprintf(AT_SQL_QUESTION_ORDERING, $sql_params);
99 $result = mysql_query($sql, $db);
101 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
102 header('Location: question_db.php');
107 $onload = 'document.form.category_id.focus();';
109 require(AT_INCLUDE_PATH.'header.inc.php');
112 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
113 <input type="hidden" name="required" value="1" />
114 <div class="input-form">
116 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label><br />
117 <select name="category_id" id="cats">
118 <?php print_question_cats($_POST['category_id']); ?>
123 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
124 <?php print_VE('optional_feedback'); ?>
126 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
130 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
131 <?php print_VE('question'); ?>
132 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php
133 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
136 <?php for ($i=0; $i<10; $i++): ?>
138 <?php if ($i < 2): ?>
139 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
140 <?php endif; ?> <?php echo _AT('item'); ?> <?php echo ($i+1); ?>
142 <?php print_VE('choice_' . $i); ?>
146 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?></textarea>
150 <div class="row buttons">
151 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
152 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
157 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>