2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg */
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');
18 authenticate(AT_PRIV_TESTS);
19 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
21 if (isset($_POST['cancel'])) {
22 $msg->addFeedback('CANCELLED');
23 header('Location: question_db.php');
25 } else if ($_POST['submit']) {
26 $_POST['feedback'] = trim($_POST['feedback']);
27 $_POST['instructions'] = trim($_POST['instructions']);
28 $_POST['category_id'] = intval($_POST['category_id']);
30 for ($i = 0 ; $i < 10; $i++) {
31 $_POST['question'][$i] = trim($_POST['question'][$i]);
32 $_POST['question_answer'][$i] = (int) $_POST['question_answer'][$i];
33 $_POST['answer'][$i] = trim($_POST['answer'][$i]);
36 if (!$_POST['question'][0]
37 || !$_POST['question'][1]
38 || !$_POST['answer'][0]
39 || !$_POST['answer'][1]) {
41 $msg->addError('QUESTION_EMPTY');
45 if (!$msg->containsErrors()) {
46 $_POST['feedback'] = $addslashes($_POST['feedback']);
47 $_POST['instructions'] = $addslashes($_POST['instructions']);
49 $sql = "INSERT INTO ".TABLE_PREFIX."tests_questions VALUES ( NULL,
54 '$_POST[instructions]',
55 '{$_POST[question][0]}',
56 '{$_POST[question][1]}',
57 '{$_POST[question][2]}',
58 '{$_POST[question][3]}',
59 '{$_POST[question][4]}',
60 '{$_POST[question][5]}',
61 '{$_POST[question][6]}',
62 '{$_POST[question][7]}',
63 '{$_POST[question][8]}',
64 '{$_POST[question][9]}',
65 {$_POST[question_answer][0]},
66 {$_POST[question_answer][1]},
67 {$_POST[question_answer][2]},
68 {$_POST[question_answer][3]},
69 {$_POST[question_answer][4]},
70 {$_POST[question_answer][5]},
71 {$_POST[question_answer][6]},
72 {$_POST[question_answer][7]},
73 {$_POST[question_answer][8]},
74 {$_POST[question_answer][9]},
75 '{$_POST[answer][0]}',
76 '{$_POST[answer][1]}',
77 '{$_POST[answer][2]}',
78 '{$_POST[answer][3]}',
79 '{$_POST[answer][4]}',
80 '{$_POST[answer][5]}',
81 '{$_POST[answer][6]}',
82 '{$_POST[answer][7]}',
83 '{$_POST[answer][8]}',
84 '{$_POST[answer][9]}',
88 $result = mysql_query($sql, $db);
90 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
91 header('Location: question_db.php');
96 $onload = 'document.form.category_id.focus();';
98 require(AT_INCLUDE_PATH.'header.inc.php');
100 // for matching test questions
101 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
104 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
105 <input type="hidden" name="required" value="1" />
106 <div class="input-form">
108 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cats"><?php echo _AT('category'); ?></label><br />
109 <select name="category_id" id="cats">
110 <?php print_question_cats($_POST['category_id']); ?>
115 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
116 <?php print_VE('optional_feedback'); ?>
118 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
122 <label for="instructions"><?php echo _AT('instructions'); ?></label>
123 <?php print_VE('instructions'); ?>
124 <textarea id="instructions" cols="50" rows="3" name="instructions"><?php
125 echo htmlspecialchars(stripslashes($_POST['instructions'])); ?></textarea>
129 <h2><?php echo _AT('questions');?></h2>
131 <?php for ($i=0; $i<10; $i++): ?>
133 <?php if ($i < 2) :?>
134 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
136 <?php echo _AT('question'); ?> <?php echo ($i+1); ?>
138 <?php print_VE('question_' . $i); ?>
142 <select name="question_answer[<?php echo $i; ?>]">
143 <option value="-1">-</option>
144 <?php foreach ($_letters as $key => $value): ?>
145 <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
149 <textarea id="question_<?php echo $i; ?>" cols="50" rows="2" name="question[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['question'][$i])); ?></textarea>
154 <h2><?php echo _AT('answers');?></h2>
156 <?php for ($i=0; $i<10; $i++): ?>
158 <?php if ($i < 2) :?>
159 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
161 <?php echo _AT('answer'); ?> <?php echo $_letters[$i]; ?>
162 <?php print_VE('answer_' . $i); ?>
164 <textarea id="answer_<?php echo $i; ?>" cols="50" rows="2" name="answer[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['answer'][$i])); ?></textarea>
168 <div class="row buttons">
169 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
170 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
175 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>