tagging as ATutor 1.5.4-release
[atutor.git] / tools / tests / create_question_matching.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay & Joel Kronenberg        */
6 /* Adaptive Technology Resource Centre / University of Toronto  */
7 /* http://atutor.ca                                                                                             */
8 /*                                                              */
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 /****************************************************************/
13 // $Id$
14
15 define('AT_INCLUDE_PATH', '../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
17
18 authenticate(AT_PRIV_TESTS);
19 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php');
20
21 if (isset($_POST['cancel'])) {
22         $msg->addFeedback('CANCELLED');
23         header('Location: question_db.php');
24         exit;
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']);
29
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]);
34         }
35
36         if (!$_POST['question'][0] 
37                 || !$_POST['question'][1] 
38                 || !$_POST['answer'][0] 
39                 || !$_POST['answer'][1]) {
40
41                 $msg->addError('QUESTION_EMPTY');
42         }
43         
44
45         if (!$msg->containsErrors()) {
46                 $_POST['feedback']     = $addslashes($_POST['feedback']);
47                 $_POST['instructions'] = $addslashes($_POST['instructions']);
48         
49                 $sql    = "INSERT INTO ".TABLE_PREFIX."tests_questions VALUES ( NULL,
50                         $_POST[category_id],
51                         $_SESSION[course_id],
52                         5,
53                         '$_POST[feedback]',
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]}',
85                         0,
86                         0)";
87
88                 $result = mysql_query($sql, $db);
89
90                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
91                 header('Location: question_db.php');
92                 exit;
93         }
94 }
95
96 $onload = 'document.form.category_id.focus();';
97
98 require(AT_INCLUDE_PATH.'header.inc.php');
99
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'));
102
103 ?>
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">
107         <div class="row">
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']); ?>
111                 </select>
112         </div>
113
114         <div class="row">
115                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label> 
116                 <?php print_VE('optional_feedback'); ?>
117
118                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
119         </div>
120
121         <div class="row">
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>
126         </div>
127
128         <div class="row">
129                 <h2><?php echo _AT('questions');?></h2>
130         </div>
131 <?php for ($i=0; $i<10; $i++): ?>
132         <div class="row">
133                 <?php if ($i < 2) :?>
134                         <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
135                 <?php endif; ?>
136                 <?php echo _AT('question'); ?> <?php echo ($i+1); ?>
137                 
138                 <?php print_VE('question_' . $i); ?>
139                 
140                 <br />
141
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>
146                         <?php endforeach; ?>
147                 </select>
148                 
149                 <textarea id="question_<?php echo $i; ?>" cols="50" rows="2" name="question[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['question'][$i])); ?></textarea> 
150         </div>
151 <?php endfor; ?>
152         
153         <div class="row">
154                 <h2><?php echo _AT('answers');?></h2>
155         </div>
156         <?php for ($i=0; $i<10; $i++): ?>
157                 <div class="row">
158                         <?php if ($i < 2) :?>
159                                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div>
160                         <?php endif; ?>
161                         <?php echo _AT('answer'); ?> <?php echo $_letters[$i]; ?>
162                         <?php print_VE('answer_' . $i); ?>
163                         <br />
164                         <textarea id="answer_<?php echo $i; ?>" cols="50" rows="2" name="answer[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['answer'][$i])); ?></textarea>
165                 </div>
166         <?php endfor; ?>
167
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" />
171         </div>
172 </div>
173 </form>
174
175 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>