AC_4897, AC_4898, AC_4899: Multifile uploader fixes.
[acontent.git] / docs / tests / edit_question_long.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 define('TR_INCLUDE_PATH', '../include/');
14 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
15 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
16 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
17
18 global $_course_id;
19 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
20 $testsQuestionsDAO = new TestsQuestionsDAO();
21
22 $qid = intval($_GET['qid']);
23 if ($qid == 0){
24         $qid = intval($_POST['qid']);
25 }
26
27 if (isset($_POST['cancel'])) {
28         $msg->addFeedback('CANCELLED');
29         if ($_POST['tid']) {
30                 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);                        
31         } else {
32                 header('Location: question_db.php?_course_id='.$_course_id);
33         }
34         exit;
35 } else if (isset($_POST['submit'])) {
36         $_POST['feedback']    = trim($_POST['feedback']);
37         $_POST['question']    = trim($_POST['question']);
38         $_POST['category_id'] = intval($_POST['category_id']);
39         $_POST['properties']  = intval($_POST['properties']);
40
41         if ($_POST['question'] == ''){
42                 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
43         }
44
45         if (!$msg->containsErrors()) {
46                 $_POST['question'] = $addslashes($_POST['question']);
47                 $_POST['feedback'] = $addslashes($_POST['feedback']);
48
49                 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET      category_id=$_POST[category_id],
50                         feedback='$_POST[feedback]',
51                         question='$_POST[question]',
52                         properties=$_POST[properties]
53                 WHERE question_id=$_POST[qid]";
54
55                 $testsQuestionsDAO->execute($sql);
56
57                 $msg->addFeedback('QUESTION_UPDATED');
58                 if ($_POST['tid']) {
59                         header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);                        
60                 } else {
61                         header('Location: question_db.php?_course_id='.$_course_id);
62                 }
63                 exit;
64         }
65 }
66
67 if (!isset($_POST['submit'])) {
68         if (!($row = $testsQuestionsDAO->get($qid))){
69                 $msg->printErrors('ITEM_NOT_FOUND');
70                 require (TR_INCLUDE_PATH.'footer.inc.php');
71                 exit;
72         }
73
74         $_POST  = $row;
75 }
76
77 require_once(TR_INCLUDE_PATH.'header.inc.php');
78
79 $msg->printErrors();
80
81 $savant->assign('qid', $qid);
82 $savant->assign('tid', $_REQUEST['tid']);
83 $savant->assign('course_id', $_course_id);
84 $savant->display('tests/create_edit_question_long.tmpl.php');
85
86 require (TR_INCLUDE_PATH.'footer.inc.php'); 
87 ?>