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 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17 require(AT_INCLUDE_PATH.'lib/likert_presets.inc.php');
18 require(AT_INCLUDE_PATH.'lib/test_question_queries.inc.php');
20 authenticate(AT_PRIV_TESTS);
21 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
23 if (isset($_POST['cancel'])) {
24 $msg->addFeedback('CANCELLED');
25 header('Location: question_db.php');
27 } else if (isset($_POST['submit'])) {
28 $_POST['required'] = intval($_POST['required']);
29 $_POST['question'] = trim($_POST['question']);
30 $_POST['category_id'] = intval($_POST['category_id']);
32 $empty_fields = array();
33 if ($_POST['question'] == ''){
34 $empty_fields[] = _AT('question');
36 if ($_POST['choice'][0] == '') {
37 $empty_fields[] = _AT('choice').' 1';
40 if ($_POST['choice'][1] == '') {
41 $empty_fields[] = _AT('choice').' 2';
44 if (!empty($empty_fields)) {
45 $msg->addError(array('EMPTY_FIELDS', implode(', ', $empty_fields)));
48 if (!$msg->containsErrors()) {
49 $_POST['feedback'] = '';
50 $_POST['question'] = $addslashes($_POST['question']);
52 for ($i=0; $i<10; $i++) {
53 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
54 $_POST['answer'][$i] = intval($_POST['answer'][$i]);
56 if ($_POST['choice'][$i] == '') {
57 /* an empty option can't be correct */
58 $_POST['answer'][$i] = 0;
62 $sql_params = array( $_POST['category_id'],
63 $_SESSION['course_id'],
87 $sql = vsprintf(AT_SQL_QUESTION_LIKERT, $sql_params);
88 $result = mysql_query($sql, $db);
90 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
91 header('Location: question_db.php');
94 } else if (isset($_POST['preset'])) {
96 $_POST['preset_num'] = intval($_POST['preset_num']);
98 if (isset($_likert_preset[$_POST['preset_num']])) {
99 $_POST['choice'] = $_likert_preset[$_POST['preset_num']];
100 } else if ($_POST['preset_num']) {
101 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$_POST[preset_num] AND course_id=$_SESSION[course_id]";
102 $result = mysql_query($sql, $db);
103 if ($row = mysql_fetch_assoc($result)){
104 for ($i=0; $i<10; $i++) {
105 $_POST['choice'][$i] = $row['choice_' . $i];
112 $onload = 'document.form.category_id.focus();';
114 require(AT_INCLUDE_PATH.'header.inc.php');
117 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
118 <input type="hidden" name="required" value="1" />
120 <div class="input-form">
121 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('preset_scales'); ?></legend>
124 <select name="preset_num">
125 <optgroup label="<?php echo _AT('presets'); ?>">
128 foreach ($_likert_preset as $val=>$preset) {
129 echo '<option value="'.$val.'">'.$preset[0].' - '.$preset[count($preset)-1].'</option>';
134 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE course_id=$_SESSION[course_id] AND type=4";
135 $result = mysql_query($sql, $db);
136 if ($row = mysql_fetch_assoc($result)) {
137 echo '<optgroup label="'. _AT('prev_used').'">';
138 $used_choices = array();
140 $choices = array_slice($row, 9, 10);
141 if (in_array($choices, $used_choices)) {
145 $used_choices[] = $choices;
147 for ($i=0; $i<=10; $i++) {
148 if ($row['choice_'.$i] == '') {
153 echo '<option value="'.$row['question_id'].'">'.$row['choice_0'].' - '.$row['choice_'.$i].'</option>';
154 } while ($row = mysql_fetch_assoc($result));
161 <div class="row buttons">
162 <input type="submit" name="preset" value="<?php echo _AT('set_preset'); ?>" class="button" />
168 <div class="input-form">
169 <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_lk'); ?></legend>
171 <label for="cats"><?php echo _AT('category'); ?></label><br />
172 <select name="category_id" id="cats">
173 <?php print_question_cats($_POST['category_id']); ?>
178 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label>
179 <?php print_VE('question'); ?>
180 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php
181 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
185 <?php for ($i=0; $i<10; $i++) { ?>
187 <?php if ($i==0 || $i==1) { ?>
188 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
190 <label for="choice_<?php echo $i; ?>">
191 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?></label><br />
192 <input type="text" id="choice_<?php echo $i; ?>" size="40" name="choice[<?php echo $i; ?>]" value="<?php echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?>" />
196 <div class="row buttons">
197 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
198 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
204 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>