remove old readme
[atutor.git] / mods / _standard / tests / create_question_multi.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']) || isset($_POST['submit_no'])) {
23         $msg->addFeedback('CANCELLED');
24         header('Location: question_db.php');
25         exit;
26 } else if (isset($_POST['submit'])) {
27         $_POST['required'] = intval($_POST['required']);
28         $_POST['feedback'] = trim($_POST['feedback']);
29         $_POST['question'] = trim($_POST['question']);
30         $_POST['category_id'] = intval($_POST['category_id']);
31         $_POST['answer']      = intval($_POST['answer']);
32
33         if ($_POST['question'] == ''){
34                 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
35         }
36                 
37         if (!$msg->containsErrors()) {
38                 for ($i=0; $i<10; $i++) {
39                         $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
40                 }
41
42                 $answers = array_fill(0, 10, 0);
43                 $answers[$_POST['answer']] = 1;
44
45                 $_POST['feedback']   = $addslashes($_POST['feedback']);
46                 $_POST['question']   = $addslashes($_POST['question']);
47
48                 $sql_params = array(    $_POST['category_id'], 
49                                                                 $_SESSION['course_id'],
50                                                                 $_POST['feedback'], 
51                                                                 $_POST['question'], 
52                                                                 $_POST['choice'][0], 
53                                                                 $_POST['choice'][1], 
54                                                                 $_POST['choice'][2], 
55                                                                 $_POST['choice'][3], 
56                                                                 $_POST['choice'][4], 
57                                                                 $_POST['choice'][5], 
58                                                                 $_POST['choice'][6], 
59                                                                 $_POST['choice'][7], 
60                                                                 $_POST['choice'][8], 
61                                                                 $_POST['choice'][9], 
62                                                                 $answers[0], 
63                                                                 $answers[1], 
64                                                                 $answers[2], 
65                                                                 $answers[3], 
66                                                                 $answers[4], 
67                                                                 $answers[5], 
68                                                                 $answers[6], 
69                                                                 $answers[7], 
70                                                                 $answers[8], 
71                                                                 $answers[9]);
72                 $sql = vsprintf(AT_SQL_QUESTION_MULTI, $sql_params);
73                 
74                 $result = mysql_query($sql, $db);
75
76                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
77                 header('Location: question_db.php');
78                 exit;
79         }
80 } else {
81         $_POST['answer'] = 0;
82 }
83
84 $onload = 'document.form.category_id.focus();';
85
86 require(AT_INCLUDE_PATH.'header.inc.php');
87
88 $msg->printConfirm();
89 ?>
90 <form action="mods/_standard/tests/create_question_multi.php" method="post" name="form">
91 <input type="hidden" name="required" value="1" />
92 <div class="input-form">
93         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_mc'); ?></legend>
94         <div class="row">
95                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="cats"><?php echo _AT('category'); ?></label><br />
96                 <select name="category_id" id="cats">
97                         <?php print_question_cats($_POST['category_id']); ?>
98                 </select>
99         </div>
100
101         <div class="row">
102                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>
103                 <?php print_VE('optional_feedback'); ?> 
104                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
105         </div>
106
107         <div class="row">
108                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label>
109                 <?php print_VE('question'); ?>
110                 <textarea id="question" cols="50" rows="4" name="question" style="width:90%;"><?php 
111                 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
112         </div>
113
114 <?php
115         for ($i=0; $i<10; $i++) {
116 ?>
117         <div class="row">
118                 <?php echo _AT('choice'); ?> <?php echo ($i+1); ?>
119                 
120                 <?php print_VE('choice_' . $i); ?>
121                 
122                 <br />
123
124                 <small><input type="radio" name="answer" id="answer_<?php echo $i; ?>" value="<?php echo $i; ?>" <?php if($_POST['answer'] == $i) { echo 'checked="checked"';} ?>><label for="answer_<?php echo $i; ?>"><?php echo _AT('correct_answer'); ?></label></small>                    
125                 
126                 <textarea id="choice_<?php echo $i; ?>" cols="50" rows="2" name="choice[<?php echo $i; ?>]"><?php 
127                 echo htmlspecialchars(stripslashes($_POST['choice'][$i])); ?></textarea> 
128         </div>
129         <?php } ?>
130
131         <div class="row buttons">
132                 <input type="submit" value="<?php echo _AT('save'); ?>" name="submit" accesskey="s" />
133                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
134         </div>
135         </fieldset>
136 </div>
137 </form>
138
139 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>