a062b982770c38094659778a156579abb574d84c
[acontent.git] / docs / tests / edit_question_truefalse.php
1 <?php
2 /************************************************************************/
3 /* AContent                                                             */
4 /************************************************************************/
5 /* Copyright (c) 2010                                                   */
6 /* Inclusive Design Institute                                           */
7 /*                                                                      */
8 /* This program is free software. You can redistribute it and/or        */
9 /* modify it under the terms of the GNU General Public License          */
10 /* as published by the Free Software Foundation.                        */
11 /************************************************************************/
12
13 $page = 'tests';
14 define('TR_INCLUDE_PATH', '../include/');
15 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
16 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
18
19 global $_course_id;
20
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
23
24 $qid = intval($_GET['qid']);
25 if ($qid == 0){
26         $qid = intval($_POST['qid']);
27 }
28
29 if (isset($_POST['cancel'])) {
30         $msg->addFeedback('CANCELLED');
31         if ($_POST['tid']) {
32                 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);                        
33         } else {
34                 header('Location: question_db.php?_course_id='.$_course_id);
35         }
36         exit;
37 } else if (isset($_POST['submit'])) {
38
39         $_POST['question'] = trim($_POST['question']);
40
41         if ($_POST['question'] == ''){
42                 $msg->addError(array('EMPTY_FIELDS', _AT('statement')));
43         }
44
45         if (!$msg->containsErrors()) {
46                 $_POST['feedback']    = $addslashes(trim($_POST['feedback']));
47                 $_POST['question']    = $addslashes($_POST['question']);
48                 $_POST['qid']         = intval($_POST['qid']);
49                 $_POST['category_id'] = intval($_POST['category_id']);
50                 $_POST['answer']      = intval($_POST['answer']);
51
52                 $sql    = "UPDATE ".TABLE_PREFIX."tests_questions SET   category_id=$_POST[category_id],
53                         feedback='$_POST[feedback]',
54                         question='$_POST[question]',
55                         answer_0={$_POST[answer]}
56                         WHERE question_id=$_POST[qid]";
57
58                 if ($testsQuestionsDAO->execute($sql)) {
59                         $msg->addFeedback('QUESTION_UPDATED');
60                         if ($_POST['tid']) {
61                                 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);                        
62                         } else {
63                                 header('Location: question_db.php?_course_id='.$_course_id);
64                         }
65                         exit;
66                 }
67                 else
68                         $msg->addError('DB_NOT_UPDATED');
69         }
70 }
71
72 if (!$_POST['submit']) {
73         if (!($row = $testsQuestionsDAO->get($qid))){
74                 $msg->printErrors('ITEM_NOT_FOUND');
75                 require (TR_INCLUDE_PATH.'footer.inc.php');
76                 exit;
77         }
78
79         $_POST  = $row;
80 }
81
82 if ($_POST['answer'] == '') {
83         if ($_POST['answer_0'] == 1) {
84                 $ans_yes = ' checked="checked"';
85         } else if ($_POST['answer_0'] == 2){
86                 $ans_no  = ' checked="checked"';
87         } else if ($_POST['answer_0'] == 3) {
88                 $ans_yes1 = ' checked="checked"';
89         } else {
90                 $ans_no1  = ' checked="checked"';
91         }
92 } else {
93         if ($_POST['answer'] == 1) {
94                 $ans_yes = ' checked="checked"';
95         } else if($_POST['answer'] == 2){
96                 $ans_no  = ' checked="checked"';
97         } else if ($_POST['answer'] == 3) {
98                 $ans_yes1 = ' checked="checked"';
99         } else {
100                 $ans_no1  = ' checked="checked"';
101         }
102 }
103
104 $onload = 'document.form.category_id.focus();';
105
106 require_once(TR_INCLUDE_PATH.'header.inc.php'); 
107
108 $savant->assign('qid', $qid);
109 $savant->assign('tid', $_REQUEST['tid']);
110 $savant->assign('ans_yes', $ans_yes);
111 $savant->assign('ans_no', $ans_no);
112 $savant->assign('course_id', $_course_id);
113 $savant->display('tests/create_edit_question_truefalse.tmpl.php');
114
115 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>