tagging as ATutor 1.5.4-release
[atutor.git] / tools / tests / edit_question_long.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 $qid = intval($_GET['qid']);
22 if ($qid == 0){
23         $qid = intval($_POST['qid']);
24 }
25
26 if (isset($_POST['cancel'])) {
27         $msg->addFeedback('CANCELLED');
28         if ($_POST['tid']) {
29                 header('Location: questions.php?tid='.$_POST['tid']);                   
30         } else {
31                 header('Location: question_db.php');
32         }
33         exit;
34 } else if (isset($_POST['submit'])) {
35         $_POST['feedback']    = trim($_POST['feedback']);
36         $_POST['question']    = trim($_POST['question']);
37         $_POST['category_id'] = intval($_POST['category_id']);
38         $_POST['properties']  = intval($_POST['properties']);
39
40         if ($_POST['question'] == ''){
41                 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
42         }
43
44         if (!$msg->containsErrors()) {
45                 $_POST['question'] = $addslashes($_POST['question']);
46
47                 for ($i=0; $i<10; $i++) {
48                         $_POST['choice'][$i] = trim($_POST['choice'][$i]);
49                         $_POST['answer'][$i] = intval($_POST['answer'][$i]);
50
51                         if ($_POST['choice'][$i] == '') {
52                                 /* an empty option can't be correct */
53                                 $_POST['answer'][$i] = 0;
54                         }
55                 }
56
57                 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET      category_id=$_POST[category_id],
58                         feedback='$_POST[feedback]',
59                         question='$_POST[question]',
60                         properties=$_POST[properties]
61                 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
62
63                 $result = mysql_query($sql, $db);
64
65                 $msg->addFeedback('QUESTION_UPDATED');
66                 if ($_POST['tid']) {
67                         header('Location: questions.php?tid='.$_POST['tid']);                   
68                 } else {
69                         header('Location: question_db.php');
70                 }
71                 exit;
72         }
73 }
74
75 require(AT_INCLUDE_PATH.'header.inc.php');
76
77 if (!isset($_POST['submit'])) {
78         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=3";
79         $result = mysql_query($sql, $db);
80         if (!($row = mysql_fetch_assoc($result))){
81                 $msg->printErrors('ITEM_NOT_FOUND');
82                 require (AT_INCLUDE_PATH.'footer.inc.php');
83                 exit;
84         }
85
86         $_POST  = $row;
87 }
88
89 $msg->printErrors();
90 ?>
91 <form action="tools/tests/edit_question_long.php" method="post" name="form">
92 <input type="hidden" name="required" value="1" />
93 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
94 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
95
96 <div class="input-form">
97         <div class="row">
98                 <label for="cats"><?php echo _AT('category'); ?></label>
99                 <select name="category_id" id="cats">
100                         <?php print_question_cats($_POST['category_id']); ?>
101                 </select>
102         </div>
103
104         <div class="row">
105                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label> 
106                 <?php print_VE('optional_feedback'); ?>
107
108                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
109         </div>
110
111         <div class="row">
112                 <div class="required" title="<?php echo _AT('required_field'); ?>">*</div><label for="question"><?php echo _AT('question'); ?></label> 
113                 <?php print_VE('question'); ?>
114
115                 <textarea id="question" cols="50" rows="6" name="question"><?php 
116                 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
117         </div>
118         
119         <div class="row">
120                 <?php echo _AT('answer_size'); ?><br />
121                 <input type="radio" name="properties" value="1" id="az1" <?php if ($_POST['properties'] == 1) { echo 'checked="checked"'; } ?> /><label for="az1"><?php echo _AT('one_word'); ?></label><br />
122                 <input type="radio" name="properties" value="2" id="az2" <?php if ($_POST['properties'] == 2) { echo 'checked="checked"'; } ?> /><label for="az2"><?php echo _AT('one_sentence'); ?></label><br />
123                 <input type="radio" name="properties" value="3" id="az3" <?php if ($_POST['properties'] == 3) { echo 'checked="checked"'; } ?> /><label for="az3"><?php echo _AT('short_paragraph'); ?></label><br />
124                 <input type="radio" name="properties" value="4" id="az4" <?php if ($_POST['properties'] == 4) { echo 'checked="checked"'; } ?> /><label for="az4"><?php echo _AT('one_page'); ?></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'); ?>