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 $missing_fields = array();
39 $_POST['feedback'] = trim($_POST['feedback']);
40 $_POST['question'] = trim($_POST['question']);
41 $_POST['category_id'] = intval($_POST['category_id']);
43 if ($_POST['question'] == ''){
44 $missing_fields[] = _AT('question');
47 if (trim($_POST['choice'][0]) == '') {
48 $missing_fields[] = _AT('item').' 1';
50 if (trim($_POST['choice'][1]) == '') {
51 $missing_fields[] = _AT('item').' 2';
54 if ($missing_fields) {
55 $missing_fields = implode(', ', $missing_fields);
56 $msg->addError(array('EMPTY_FIELDS', $missing_fields));
58 if (!$msg->containsErrors()) {
59 $_POST['question'] = $addslashes($_POST['question']);
60 $_POST['feedback'] = $addslashes($_POST['feedback']);
62 $choice_new = array(); // stores the non-blank choices
63 $answer_new = array(); // stores the non-blank answers
64 $order = 0; // order count
65 for ($i=0; $i<10; $i++) {
67 * Db defined it to be 255 length, chop strings off it it's less than that
70 $_POST['choice'][$i] = Utility::validateLength($_POST['choice'][$i], 255);
71 $_POST['choice'][$i] = $addslashes(trim($_POST['choice'][$i]));
73 if ($_POST['choice'][$i] != '') {
74 /* filter out empty choices/ remove gaps */
75 $choice_new[] = $_POST['choice'][$i];
76 $answer_new[] = $order++;
80 $_POST['choice'] = array_pad($choice_new, 10, '');
81 $answer_new = array_pad($answer_new, 10, 0);
83 $sql = "UPDATE ".TABLE_PREFIX."tests_questions SET
84 category_id=$_POST[category_id],
85 feedback='$_POST[feedback]',
86 question='$_POST[question]',
87 choice_0='{$_POST[choice][0]}',
88 choice_1='{$_POST[choice][1]}',
89 choice_2='{$_POST[choice][2]}',
90 choice_3='{$_POST[choice][3]}',
91 choice_4='{$_POST[choice][4]}',
92 choice_5='{$_POST[choice][5]}',
93 choice_6='{$_POST[choice][6]}',
94 choice_7='{$_POST[choice][7]}',
95 choice_8='{$_POST[choice][8]}',
96 choice_9='{$_POST[choice][9]}',
97 answer_0=$answer_new[0],
98 answer_0=$answer_new[1],
99 answer_0=$answer_new[2],
100 answer_0=$answer_new[3],
101 answer_0=$answer_new[4],
102 answer_0=$answer_new[5],
103 answer_0=$answer_new[6],
104 answer_0=$answer_new[7],
105 answer_0=$answer_new[8],
106 answer_0=$answer_new[9]
108 WHERE question_id=$_POST[qid]";
110 if ($testsQuestionsDAO->execute($sql)) {
111 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
113 header('Location: questions.php?tid='.$_POST['tid'].'&_course_id='.$_course_id);
115 header('Location: question_db.php?_course_id='.$_course_id);
120 $msg->addError('DB_NOT_UPDATED');
123 if (!($row = $testsQuestionsDAO->get($qid))){
124 require_once(TR_INCLUDE_PATH.'header.inc.php');
125 $msg->printErrors('ITEM_NOT_FOUND');
126 require (TR_INCLUDE_PATH.'footer.inc.php');
130 $_POST['required'] = $row['required'];
131 $_POST['question'] = $row['question'];
132 $_POST['category_id'] = $row['category_id'];
133 $_POST['feedback'] = $row['feedback'];
135 for ($i=0; $i<10; $i++) {
136 $_POST['choice'][$i] = $row['choice_'.$i];
140 $onload = 'document.form.category_id.focus();';
141 require_once(TR_INCLUDE_PATH.'header.inc.php');
143 $savant->assign('qid', $qid);
144 $savant->assign('tid', $_REQUEST['tid']);
145 $savant->assign('course_id', $_course_id);
146 $savant->display('tests/create_edit_question_ordering.tmpl.php');
148 require (TR_INCLUDE_PATH.'footer.inc.php'); ?>