2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2010 */
6 /* Inclusive Design Institute */
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 /************************************************************************/
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');
20 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
21 $testsQuestionsDAO = new TestsQuestionsDAO();
23 $qid = intval($_GET['qid']);
25 $qid = intval($_POST['qid']);
28 if (isset($_POST['cancel'])) {
29 $msg->addFeedback('CANCELLED');
31 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);
33 header('Location: question_db.php?_course_id='.$_course_id);
36 } else if (isset($_POST['submit'])) {
37 $_POST['feedback'] = trim($_POST['feedback']);
38 $_POST['question'] = trim($_POST['question']);
39 $_POST['tid'] = intval($_POST['tid']);
40 $_POST['qid'] = intval($_POST['qid']);
41 $_POST['weight'] = intval($_POST['weight']);
42 $_POST['answer'] = intval($_POST['answer']);
44 if ($_POST['question'] == ''){
45 $msg->addError(array('EMPTY_FIELDS', _AT('question')));
48 if (!$msg->containsErrors()) {
49 $answers = array_fill(0, 10, 0);
50 $answers[$_POST['answer']] = 1;
52 for ($i=0; $i<10; $i++) {
53 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
56 $_POST['feedback'] = $addslashes($_POST['feedback']);
57 $_POST['question'] = $addslashes($_POST['question']);
59 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
60 category_id=$_POST[category_id],
61 feedback='$_POST[feedback]',
62 question='$_POST[question]',
63 choice_0='{$_POST[choice][0]}',
64 choice_1='{$_POST[choice][1]}',
65 choice_2='{$_POST[choice][2]}',
66 choice_3='{$_POST[choice][3]}',
67 choice_4='{$_POST[choice][4]}',
68 choice_5='{$_POST[choice][5]}',
69 choice_6='{$_POST[choice][6]}',
70 choice_7='{$_POST[choice][7]}',
71 choice_8='{$_POST[choice][8]}',
72 choice_9='{$_POST[choice][9]}',
73 answer_0={$answers[0]},
74 answer_1={$answers[1]},
75 answer_2={$answers[2]},
76 answer_3={$answers[3]},
77 answer_4={$answers[4]},
78 answer_5={$answers[5]},
79 answer_6={$answers[6]},
80 answer_7={$answers[7]},
81 answer_8={$answers[8]},
82 answer_9={$answers[9]}
84 WHERE question_id=$_POST[qid]";
86 if ($testsQuestionsDAO->execute($sql)) {
87 $msg->addFeedback('QUESTION_UPDATED');
89 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);
91 header('Location: question_db.php?_course_id='.$_course_id);
96 $msg->addError('DB_NOT_UPDATED');
100 if (!isset($_POST['submit'])) {
101 if (!($row = $testsQuestionsDAO->get($qid))){
102 require_once(TR_INCLUDE_PATH.'header.inc.php');
103 $msg->printErrors('ITEM_NOT_FOUND');
104 require (TR_INCLUDE_PATH.'footer.inc.php');
107 $_POST['category_id'] = $row['category_id'];
108 $_POST['feedback'] = $row['feedback'];
109 $_POST['weight'] = $row['weight'];
110 $_POST['question'] = $row['question'];
112 for ($i=0; $i<10; $i++) {
113 $_POST['choice'][$i] = $row['choice_'.$i];
114 $_POST['answer'][$i] = $row['answer_'.$i];
118 $onload = 'document.form.category_id.focus();';
119 require_once(TR_INCLUDE_PATH.'header.inc.php');
121 $savant->assign('qid', $qid);
122 $savant->assign('tid', $_REQUEST['tid']);
123 $savant->assign('course_id', $_course_id);
124 $savant->display('tests/create_edit_question_multichoice.tmpl.php');
126 require (TR_INCLUDE_PATH.'footer.inc.php');