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 /************************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/likert_presets.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 (isset($_POST['submit'])) {
27 $_POST['required'] = intval($_POST['required']);
28 $_POST['question'] = trim($_POST['question']);
29 $_POST['category_id'] = intval($_POST['category_id']);
31 $empty_fields = array();
32 if ($_POST['question'] == ''){
33 $empty_fields[] = _AT('question');
35 if ($_POST['choice'][0] == '') {
36 $empty_fields[] = _AT('choice').' 1';
39 if ($_POST['choice'][1] == '') {
40 $empty_fields[] = _AT('choice').' 2';
43 if (!empty($empty_fields)) {
44 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
47 if (!$msg->containsErrors()) {
48 $_POST['feedback'] = '';
49 $_POST['question'] = $addslashes($_POST['question']);
51 for ($i=0; $i<10; $i++) {
52 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
53 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
55 if ($_POST['choice'][$i] == '') {
56 /* an empty option can't be correct */
57 $_POST['answer'][$i] = 0;
61 $sql_params = array( $_POST['category_id'],
62 $_SESSION['course_id'],
86 $sql = vsprintf(AT_SQL_QUESTION_LIKERT, $sql_params);
87 $result = mysql_query($sql, $db);
89 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
90 header('Location: question_db.php');
93 } else if (isset($_POST['preset'])) {
95 $_POST['preset_num'] = intval($_POST['preset_num']);
97 if (isset($_likert_preset[$_POST['preset_num']])) {
98 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
99 } else if ($_POST['preset_num']) {
100 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_POST[preset_num] AND course_id=$_SESSION[course_id]";
101 $result = mysql_query($sql, $db);
102 if ($row = mysql_fetch_assoc($result)){
103 for ($i=0; $i<10; $i++) {
104 $_POST['choice'][$i] = $row['choice_' . $i];
111 $onload = 'document.form.category_id.focus();';
113 require(AT_INCLUDE_PATH.'header.inc.php');
116 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
117 <input type="hidden" name="required" value="1" />
119 <div class="input-form">
120 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('preset_scales'); ?></legend>
123 <select name="preset_num">
124 <optgroup label="<?php echo _AT('presets'); ?>">
127 foreach ($_likert_preset as $val=>$preset) {
128 echo '<option value="'.$val.'">'.$preset[0].' - '.$preset[count($preset)-1].'</option>';
133 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND type=4";
134 $result = mysql_query($sql, $db);
135 if ($row = mysql_fetch_assoc($result)) {
136 echo '<optgroup label="'. _AT('prev_used').'">';
137 $used_choices = array();
139 $choices = array_slice($row, 9, 10);
140 if (in_array($choices, $used_choices)) {
144 $used_choices[] = $choices;
146 for ($i=0; $i<=10; $i++) {
147 if ($row['choice_'.$i] == '') {
152 echo '<option value="'.$row['question_id'].'">'.$row['choice_0'].' - '.$row['choice_'.$i].'</option>';
153 } while ($row = mysql_fetch_assoc($result));
160 <div class="row buttons">
161 <input type="submit" name="preset" value="<?php echo _AT('set_preset'); ?>" class="button" />
167 <div class="input-form">
168 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_lk'); ?></legend>
170 <label for="cats"><?php echo _AT('category'); ?></label><br />
171 <select name="category_id" id="cats">
172 <?php print_question_cats($_POST['category_id']); ?>
177 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
178 <?php print_VE('question'); ?>
179 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php
180 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
184 <?php for ($i=0; $i<10; $i++) { ?>
186 <?php if ($i==0 || $i==1) { ?>
187 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
189 <label for="choice_<?php echo $i; ?>">
190 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label><br />
191 <input type="text" id="choice_<?php echo $i; ?>" size="40" name="choice[<?php echo $i; ?>]" value="<?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?>" />
195 <div class="row buttons">
196 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
197 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
203 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>