tagging as ATutor 1.5.4-release
[atutor.git] / tools / tests / create_question_tf.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['required']     = 1; //intval($_POST['required']);
27         $_POST['feedback']     = trim($_POST['feedback']);
28         $_POST['question']     = trim($_POST['question']);
29         $_POST['category_id']  = intval($_POST['category_id']);
30         $_POST['answer']       = intval($_POST['answer']);
31
32         if ($_POST['question'] == ''){
33                 $msg->addError(array('EMPTY_FIELDS', _AT('statement')));
34         }
35
36         if (!$msg->containsErrors()) {
37                 $_POST['feedback'] = $addslashes($_POST['feedback']);
38                 $_POST['question'] = $addslashes($_POST['question']);
39
40                 /*
41                 $sql = 'SELECT content_id FROM '.TABLE_PREFIX."tests WHERE test_id=$_POST[tid]";
42                 $result = mysql_query($sql, $db);                       
43                 $row = mysql_fetch_assoc($result);
44                 */
45
46                 $sql = "INSERT INTO ".TABLE_PREFIX."tests_questions VALUES ( NULL,
47                         $_POST[category_id],
48                         $_SESSION[course_id],
49                         2,
50                         '$_POST[feedback]',
51                         '$_POST[question]',
52                         '',
53                         '',
54                         '',
55                         '',
56                         '',
57                         '',
58                         '',
59                         '',
60                         '',
61                         '',
62                         $_POST[answer],
63                         0,
64                         0,
65                         0,
66                         0,
67                         0,
68                         0,
69                         0,
70                         0,
71                         0,
72                         '',
73                         '',
74                         '',
75                         '',
76                         '',
77                         '',
78                         '',
79                         '',
80                         '',
81                         '',
82                         5,
83                         0)";
84                 $result = mysql_query($sql, $db);
85                 
86                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
87                 header('Location: question_db.php');
88         }
89 }
90
91 $onload = 'document.form.category_id.focus();';
92 require(AT_INCLUDE_PATH.'header.inc.php');
93
94 ?>
95 <form action="tools/tests/create_question_tf.php" method="post" name="form">
96 <div class="input-form">
97
98         <div class="row">
99                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="cats"><?php echo _AT('category'); ?></label><br />
100                 <select name="category_id" id="cats">
101                         <?php print_question_cats($_POST['category_id']); ?>
102                 </select>
103         </div>
104
105         <div class="row">
106                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label>          
107                 <?php print_VE('optional_feedback'); ?>
108                 <br />
109         
110                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars($stripslashes($_POST['feedback'])); ?></textarea>
111         </div>
112         
113         <div class="row">
114                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('statement'); ?></label>
115                 <?php print_VE('statement'); ?>
116                 <br />
117
118                 <textarea id="question" cols="50" rows="6" name="question" style="width:90%;"><?php echo htmlspecialchars($stripslashes($_POST['question'])); ?></textarea>
119         </div>
120         
121         <div class="row">
122                 <?php echo _AT('answer'); ?><br />
123                 <input type="radio" name="answer" value="1" id="answer1" /><label for="answer1"><?php echo _AT('true'); ?></label>, 
124                 <input type="radio" name="answer" value="2" id="answer2" checked="checked" /><label for="answer2"><?php echo _AT('false'); ?></label>
125         </div>
126
127         <div class="row buttons">
128                 <input type="submit" value="<?php echo _AT('save'); ?>"   name="submit" accesskey="s" />
129                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
130         </div>
131 </div>
132 </form>
133
134 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>