move code up one directory
[atutor.git] / mods / _standard / tests / create_question_matchingdd.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_MATCHINGDD, $sql_params);
86
87                 $result = mysql_query($sql, $db);
88
89                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
90                 header('Location: question_db.php');
91                 exit;
92         }
93 }
94
95 $onload = 'document.form.category_id.focus();';
96
97 require(AT_INCLUDE_PATH.'header.inc.php');
98
99 // for matching test questions
100 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
101
102 ?>
103 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
104 <input type="hidden" name="required" value="1" />
105 <div class="input-form">
106         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_matchingdd'); ?></legend>
107         <div class="row">
108                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><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 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 
149                 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                                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span>
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 
165                         echo htmlspecialchars(stripslashes($_POST['answer'][$i])); ?></textarea>
166                 </div>
167         <?php endfor; ?>
168
169         <div class="row buttons">
170                 <input type="submit" value="<?php echo _AT('save'); ?>"   name="submit" accesskey="s" />
171                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
172         </div>
173         </fieldset>
174 </div>
175 </form>
176
177 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>