remove old readme
[atutor.git] / mods / _standard / tests / create_question_matching.php
1 <?php
2 /****************************************************************/
3 /* ATutor                                                                                                               */
4 /****************************************************************/
5 /* Copyright (c) 2002-2010                                      */
6 /* Inclusive Design Institute                                   */
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 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_question_queries.inc.php');
18
19 authenticate(AT_PRIV_TESTS);
20 require(AT_INCLUDE_PATH.'../mods/_standard/tests/lib/test_result_functions.inc.php');
21
22 if (isset($_POST['cancel'])) {
23         $msg->addFeedback('CANCELLED');
24         header('Location: question_db.php');
25         exit;
26 } else if ($_POST['submit']) {
27         $_POST['feedback']    = trim($_POST['feedback']);
28         $_POST['instructions'] = trim($_POST['instructions']);
29         $_POST['category_id'] = intval($_POST['category_id']);
30
31         for ($i = 0 ; $i < 10; $i++) {
32                 $_POST['question'][$i]        = $addslashes(trim($_POST['question'][$i]));
33                 $_POST['question_answer'][$i] = (int) $_POST['question_answer'][$i];
34                 $_POST['answer'][$i]          = $addslashes(trim($_POST['answer'][$i]));
35         }
36
37         if ($_POST['question'][0] == ''
38                 || $_POST['question'][1] == ''
39                 || $_POST['answer'][0] == ''
40                 || $_POST['answer'][1] == '') {
41
42                 $msg->addError('QUESTION_EMPTY');
43         }
44         
45
46         if (!$msg->containsErrors()) {
47                 $_POST['feedback']     = $addslashes($_POST['feedback']);
48                 $_POST['instructions'] = $addslashes($_POST['instructions']);
49                 
50                 $sql_params = array(    $_POST['category_id'], 
51                                                                 $_SESSION['course_id'],
52                                                                 $_POST['feedback'], 
53                                                                 $_POST['instructions'], 
54                                                                 $_POST['question'][0],
55                                                                 $_POST['question'][1],
56                                                                 $_POST['question'][2],
57                                                                 $_POST['question'][3],
58                                                                 $_POST['question'][4],
59                                                                 $_POST['question'][5],
60                                                                 $_POST['question'][6],
61                                                                 $_POST['question'][7],
62                                                                 $_POST['question'][8],
63                                                                 $_POST['question'][9],
64                                                                 $_POST['question_answer'][0], 
65                                                                 $_POST['question_answer'][1], 
66                                                                 $_POST['question_answer'][2], 
67                                                                 $_POST['question_answer'][3], 
68                                                                 $_POST['question_answer'][4], 
69                                                                 $_POST['question_answer'][5], 
70                                                                 $_POST['question_answer'][6], 
71                                                                 $_POST['question_answer'][7], 
72                                                                 $_POST['question_answer'][8], 
73                                                                 $_POST['question_answer'][9], 
74                                                                 $_POST['answer'][0], 
75                                                                 $_POST['answer'][1], 
76                                                                 $_POST['answer'][2], 
77                                                                 $_POST['answer'][3], 
78                                                                 $_POST['answer'][4], 
79                                                                 $_POST['answer'][5], 
80                                                                 $_POST['answer'][6], 
81                                                                 $_POST['answer'][7], 
82                                                                 $_POST['answer'][8], 
83                                                                 $_POST['answer'][9]);
84
85                 $sql = vsprintf(AT_SQL_QUESTION_MATCHING, $sql_params); 
86                 $result = mysql_query($sql, $db);
87
88                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
89                 header('Location: question_db.php');
90                 exit;
91         }
92 }
93
94 $onload = 'document.form.category_id.focus();';
95
96 require(AT_INCLUDE_PATH.'header.inc.php');
97
98 // for matching test questions
99 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
100
101 ?>
102 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
103 <input type="hidden" name="required" value="1" />
104 <div class="input-form">
105         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_matching'); ?></legend>
106         <div class="row">
107                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label><br />
108                 <select name="category_id" id="cats">
109                         <?php print_question_cats($_POST['category_id']); ?>
110                 </select>
111         </div>
112
113         <div class="row">
114                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label> 
115                 <?php print_VE('optional_feedback'); ?>
116
117                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
118         </div>
119
120         <div class="row">
121                 <label for="instructions"><?php echo _AT('instructions'); ?></label> 
122                 <?php print_VE('instructions'); ?>
123                 <textarea id="instructions" cols="50" rows="3" name="instructions"><?php 
124                 echo htmlspecialchars(stripslashes($_POST['instructions'])); ?></textarea>
125         </div>
126
127         <div class="row">
128                 <h2><?php echo _AT('questions');?></h2>
129         </div>
130 <?php for ($i=0; $i<10; $i++): ?>
131         <div class="row">
132                 <?php if ($i < 2) :?>
133                         <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
134                 <?php endif; ?>
135                 <?php echo _AT('question'); ?> <?php echo ($i+1); ?>
136                 
137                 <?php print_VE('question_' . $i); ?>
138                 
139                 <br />
140
141                 <select name="question_answer[<?php echo $i; ?>]">
142                         <option value="-1">-</option>
143                         <?php foreach ($_letters as $key => $value): ?>
144                                 <option value="<?php echo $key; ?>"><?php echo $value; ?></option>
145                         <?php endforeach; ?>
146                 </select>
147                 
148                 <textarea id="question_<?php echo $i; ?>" cols="50" rows="2" name="question[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['question'][$i])); ?></textarea> 
149         </div>
150 <?php endfor; ?>
151         
152         <div class="row">
153                 <h2><?php echo _AT('answers');?></h2>
154         </div>
155         <?php for ($i=0; $i<10; $i++): ?>
156                 <div class="row">
157                         <?php if ($i < 2) :?>
158                                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
159                         <?php endif; ?>
160                         <?php echo _AT('answer'); ?> <?php echo $_letters[$i]; ?>
161                         <?php print_VE('answer_' . $i); ?>
162                         <br />
163                         <textarea id="answer_<?php echo $i; ?>" cols="50" rows="2" name="answer[<?php echo $i; ?>]"><?php echo htmlspecialchars(stripslashes($_POST['answer'][$i])); ?></textarea>
164                 </div>
165         <?php endfor; ?>
166
167         <div class="row buttons">
168                 <input type="submit" value="<?php echo _AT('save'); ?>"   name="submit" accesskey="s" />
169                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
170         </div>
171         </fieldset>
172 </div>
173 </form>
174
175 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>