3339e3249d2ca163a492884bf313fc7860849856
[atutor.git] / docs / mods / _standard / tests / edit_question_long.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
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         $_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                 $_POST['feedback'] = $addslashes($_POST['feedback']);
47
48                 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET      category_id=$_POST[category_id],
49                         feedback='$_POST[feedback]',
50                         question='$_POST[question]',
51                         properties=$_POST[properties]
52                 WHERE question_id=$_POST[qid] AND course_id=$_SESSION[course_id]";
53
54                 $result = mysql_query($sql, $db);
55
56                 $msg->addFeedback('QUESTION_UPDATED');
57                 if ($_POST['tid']) {
58                         header('Location: questions.php?tid='.$_POST['tid']);                   
59                 } else {
60                         header('Location: question_db.php');
61                 }
62                 exit;
63         }
64 }
65
66 require(AT_INCLUDE_PATH.'header.inc.php');
67
68 if (!isset($_POST['submit'])) {
69         $sql    = "SELECT * FROM ".TABLE_PREFIX."tests_questions WHERE question_id=$qid AND course_id=$_SESSION[course_id] AND type=3";
70         $result = mysql_query($sql, $db);
71         if (!($row = mysql_fetch_assoc($result))){
72                 $msg->printErrors('ITEM_NOT_FOUND');
73                 require (AT_INCLUDE_PATH.'footer.inc.php');
74                 exit;
75         }
76
77         $_POST  = $row;
78 }
79
80 $msg->printErrors();
81 ?>
82 <form action="mods/_standard/tests/edit_question_long.php" method="post" name="form">
83 <input type="hidden" name="required" value="1" />
84 <input type="hidden" name="tid" value="<?php echo $_REQUEST['tid']; ?>" />
85 <input type="hidden" name="qid" value="<?php echo $qid; ?>" />
86
87 <div class="input-form">
88         <fieldset class="group_form"><legend class="group_form"><?php echo _AT('test_open'); ?></legend>
89         <div class="row">
90                 <label for="cats"><?php echo _AT('category'); ?></label>
91                 <select name="category_id" id="cats">
92                         <?php print_question_cats($_POST['category_id']); ?>
93                 </select>
94         </div>
95
96         <div class="row">
97                 <label for="optional_feedback"><?php echo _AT('optional_feedback'); ?></label> 
98                 <?php print_VE('optional_feedback'); ?>
99
100                 <textarea id="optional_feedback" cols="50" rows="3" name="feedback"><?php echo htmlspecialchars(stripslashes($_POST['feedback'])); ?></textarea>
101         </div>
102
103         <div class="row">
104                 <span class="required" title="<?php echo _AT('required_field'); ?>">*</span><label for="question"><?php echo _AT('question'); ?></label> 
105                 <?php print_VE('question'); ?>
106
107                 <textarea id="question" cols="50" rows="6" name="question"><?php 
108                 echo htmlspecialchars(stripslashes($_POST['question'])); ?></textarea>
109         </div>
110         
111         <div class="row">
112                 <?php echo _AT('answer_size'); ?><br />
113                 <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 />
114                 <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 />
115                 <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 />
116                 <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>
117         </div>
118
119         <div class="row buttons">
120                 <input type="submit" value="<?php echo _AT('save'); ?>"   name="submit" accesskey="s" />
121                 <input type="submit" value="<?php echo _AT('cancel'); ?>" name="cancel" />
122         </div>
123         </fieldset>
124 </div>
125 </form>
126
127 <?php require (AT_INCLUDE_PATH.'footer.inc.php'); ?>