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.'../tests/lib/likert_presets.inc.php');
16 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
24 // for matching test questions
25 $_letters = array(_AT('a'), _AT('b'), _AT('c'), _AT('d'), _AT('e'), _AT('f'), _AT('g'), _AT('h'), _AT('i'), _AT('j'));
27 $qid = intval($_GET['qid']);
29 $qid = intval($_POST['qid']);
32 if (isset($_POST['cancel'])) {
33 $msg->addFeedback('CANCELLED');
35 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);
37 header('Location: question_db.php?_course_id='.$_course_id);
40 } else if (isset($_POST['submit'])) {
41 $_POST['tid'] = intval($_POST['tid']);
42 $_POST['qid'] = intval($_POST['qid']);
43 $_POST['feedback'] = trim($_POST['feedback']);
44 $_POST['instructions'] = trim($_POST['instructions']);
45 $_POST['category_id'] = intval($_POST['category_id']);
47 for ($i = 0 ; $i < 10; $i++) {
48 $_POST['question'][$i] = $addslashes(trim($_POST['question'][$i]));
49 $_POST['question_answer'][$i] = (int) $_POST['question_answer'][$i];
50 $_POST['answer'][$i] = $addslashes(trim($_POST['answer'][$i]));
53 if (!$_POST['question'][0]
54 || !$_POST['question'][1]
55 || !$_POST['answer'][0]
56 || !$_POST['answer'][1]) {
58 $msg->addError('QUESTION_EMPTY');
61 if (!$msg->containsErrors()) {
62 $_POST['feedback'] = $addslashes($_POST['feedback']);
63 $_POST['instructions'] = $addslashes($_POST['instructions']);
65 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
66 category_id=$_POST[category_id],
67 feedback='$_POST[feedback]',
68 question='$_POST[instructions]',
69 choice_0='{$_POST[question][0]}',
70 choice_1='{$_POST[question][1]}',
71 choice_2='{$_POST[question][2]}',
72 choice_3='{$_POST[question][3]}',
73 choice_4='{$_POST[question][4]}',
74 choice_5='{$_POST[question][5]}',
75 choice_6='{$_POST[question][6]}',
76 choice_7='{$_POST[question][7]}',
77 choice_8='{$_POST[question][8]}',
78 choice_9='{$_POST[question][9]}',
79 answer_0={$_POST[question_answer][0]},
80 answer_1={$_POST[question_answer][1]},
81 answer_2={$_POST[question_answer][2]},
82 answer_3={$_POST[question_answer][3]},
83 answer_4={$_POST[question_answer][4]},
84 answer_5={$_POST[question_answer][5]},
85 answer_6={$_POST[question_answer][6]},
86 answer_7={$_POST[question_answer][7]},
87 answer_8={$_POST[question_answer][8]},
88 answer_9={$_POST[question_answer][9]},
89 option_0='{$_POST[answer][0]}',
90 option_1='{$_POST[answer][1]}',
91 option_2='{$_POST[answer][2]}',
92 option_3='{$_POST[answer][3]}',
93 option_4='{$_POST[answer][4]}',
94 option_5='{$_POST[answer][5]}',
95 option_6='{$_POST[answer][6]}',
96 option_7='{$_POST[answer][7]}',
97 option_8='{$_POST[answer][8]}',
98 option_9='{$_POST[answer][9]}'
100 WHERE question_id=$_POST[qid]";
101 if ($testsQuestionsDAO->execute($sql)) {
102 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
104 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);
106 header('Location: question_db.php?_course_id='.$_course_id);
112 if (!($row = $testsQuestionsDAO->get($qid))){
113 require_once(TR_INCLUDE_PATH.'header.inc.php');
114 $msg->printErrors('ITEM_NOT_FOUND');
115 require (TR_INCLUDE_PATH.'footer.inc.php');
118 $_POST['feedback'] = $row['feedback'];
119 $_POST['instructions'] = $row['question'];
120 $_POST['category_id'] = $row['category_id'];
122 for ($i=0; $i<10; $i++) {
123 $_POST['question'][$i] = $row['choice_'.$i];
124 $_POST['question_answer'][$i] = $row['answer_'.$i];
125 $_POST['answer'][$i] = $row['option_'.$i];
129 $onload = 'document.form.category_id.focus();';
131 require_once(TR_INCLUDE_PATH.'header.inc.php');
133 $savant->assign('qid', $qid);
134 $savant->assign('tid', $_REQUEST['tid']);
135 $savant->assign('letters', $_letters);
136 $savant->assign('course_id', $_course_id);
137 $savant->display('tests/create_edit_question_matchingdd.tmpl.php');
139 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>