remove old readme
[atutor.git] / docs / mods / _standard / tests / edit_question_tf.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 $page = 'tests';
16 define('AT_INCLUDE_PATH', '../../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_TESTS);
19 require(AT_INCLUDE_PATH.'../mods/_standard/tests/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
36         $_POST['question'] = trim($_POST['question']);
37
38         if ($_POST['question'] == ''){
39                 $msg->addError(array('EMPTY_FIELDS', _AT('statement')));
40         }
41
42         if (!$msg->containsErrors()) {
43                 $_POST['feedback']    = $addslashes(trim($_POST['feedback']));
44                 $_POST['question']    = $addslashes($_POST['question']);
45                 $_POST['qid']         = intval($_POST['qid']);
46                 $_POST['category_id'] = intval($_POST['category_id']);
47                 $_POST['answer']      = intval($_POST['answer']);
48
49                 $sql    = "UPDATE ".TABLE_PREFIX."tests_questions SET   category_id=$_POST[category_id],
50                         feedback='$_POST[feedback]',
51                         question='$_POST[question]',
52                         answer_0={$_POST[answer]}
53                         WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
54
55                 $result = mysql_query($sql, $db);
56                 
57                 $msg->addFeedback('QUESTION_UPDATED');
58                 if ($_POST['tid']) {
59                         header('Location: questions.php?tid='.$_POST['tid']);                   
60                 } else {
61                         header('Location: question_db.php');
62                 }
63                 exit;
64         }
65 }
66 require(AT_INCLUDE_PATH.'header.inc.php'); 
67
68 if (!$_POST['submit']) {
69         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=2";
70         $result = mysql_query($sql, $db);
71
72         if (!($row = mysql_fetch_array($result))){
73                 $msg->printErrors('ITEM_NOT_FOUND');
74                 require (AT_INCLUDE_PATH.'footer.inc.php');
75                 exit;
76         }
77
78         $_POST  = $row;
79 }
80
81 if ($_POST['required'] == 1) {
82         $req_yes = ' checked="checked"';
83 } else {
84         $req_no  = ' checked="checked"';
85 }
86
87 if ($_POST['answer'] == '') {
88         if ($_POST['answer_0'] == 1) {
89                 $ans_yes = ' checked="checked"';
90         } else if ($_POST['answer_0'] == 2){
91                 $ans_no  = ' checked="checked"';
92         } else if ($_POST['answer_0'] == 3) {
93                 $ans_yes1 = ' checked="checked"';
94         } else {
95                 $ans_no1  = ' checked="checked"';
96         }
97 } else {
98         if ($_POST['answer'] == 1) {
99                 $ans_yes = ' checked="checked"';
100         } else if($_POST['answer'] == 2){
101                 $ans_no  = ' checked="checked"';
102         } else if ($_POST['answer'] == 3) {
103                 $ans_yes1 = ' checked="checked"';
104         } else {
105                 $ans_no1  = ' checked="checked"';
106         }
107 }
108
109 ?>
110 <form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post" name="form">
111 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
112 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
113 <input type="hidden" name="required" value="1" />
114
115 <div class="input-form">
116         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_tf'); ?></legend>
117         <div class="row">
118                 <label for="cats"><?php echo _AT('category'); ?></label>
119                 <select name="category_id" id="cats">
120                         <?php print_question_cats($_POST['category_id']); ?>
121                 </select>
122         </div>
123
124         <div class="row">
125                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label> 
126                 <?php print_VE('optional_feedback'); ?>
127                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
128         </div>
129
130         <div class="row">
131                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('statement'); ?></label> 
132                 <?php print_VE('question'); ?>  
133                 <textarea id="question" cols="50" rows="6" name="question"><?php 
134                         echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
135         </div>
136
137         <div class="row">
138                 <?php echo _AT('answer'); ?><br />
139                 <input type="radio" name="answer" value="1" id="answer1"<?php echo $ans_yes; ?> /><label for="answer1"><?php echo _AT('true'); ?></label>, <input type="radio" name="answer" value="2" id="answer2"<?php echo $ans_no; ?> /><label for="answer2"><?php echo _AT('false'); ?></label>
140         </div>
141
142         <div class="row buttons">
143                 <input type="submit" value="<?php echo _AT('save'); ?>"   name="submit" accesskey="s"/>
144                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
145         </div>
146         </fieldset>
147 </div>
148 </form>
149
150 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>