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 /************************************************************************/
14 define('TR_INCLUDE_PATH', '../include/');
15 require_once(TR_INCLUDE_PATH.'vitals.inc.php');
16 require_once(TR_INCLUDE_PATH.'classes/Utility.class.php');
17 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsAssocDAO.class.php');
18 require_once(TR_INCLUDE_PATH.'classes/DAO/TestsQuestionsDAO.class.php');
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
23 $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
25 $tid = intval($_POST['tid']);
27 $_pages['tests/questions.php?tid='.$tid.'&_course_id='.$_course_id]['title_var'] = 'questions';
28 $_pages['tests/questions.php?tid='.$tid.'&_course_id='.$_course_id]['parent'] = 'tests/index.php';
29 $_pages['tests/questions.php?tid='.$tid.'&_course_id='.$_course_id]['children'] = array('tests/add_test_questions.php');
31 $_pages['tests/add_test_questions.php']['title_var'] = 'add_questions';
32 $_pages['tests/add_test_questions.php']['parent'] = 'tests/questions.php?tid='.$tid.'&_course_id='.$_course_id;
34 $_pages['tests/add_test_questions_confirm.php']['title_var'] = 'add_questions';
35 $_pages['tests/add_test_questions_confirm.php']['parent'] = 'tests/questions.php?tid='.$tid.'&_course_id='.$_course_id;
37 if (isset($_POST['cancel'])) {
38 $msg->addFeedback('CANCELLED');
39 header('Location: questions.php?tid='.$tid.'&_course_id='.$_course_id);
41 } else if (isset($_POST['submit_yes'])) {
43 $order = $testsQuestionsAssocDAO->getMaxOrderByTestID($tid);
45 $sql = "REPLACE INTO ".TABLE_PREFIX."tests_questions_assoc VALUES ";
46 foreach ($_POST['questions'] as $question) {
48 $question = intval($question);
49 $sql .= '('.$tid.', '.$question.', 0, '.$order.'),';
51 $sql = substr($sql, 0, -1);
53 if ($testsQuestionsAssocDAO->execute($sql)) {
54 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
55 header('Location: questions.php?tid='.$tid.'&_course_id='.$_course_id);
59 $msg->addError('DB_NOT_UPDATED');
61 } else if (isset($_POST['submit_no'])) {
62 $msg->addFeedback('CANCELLED');
63 header('Location: add_test_questions.php?tid='.$tid.'&_course_id='.$_course_id);
67 if (!is_array($_POST['questions']) || !count($_POST['questions'])) {
68 $msg->addError('NO_QUESTIONS_SELECTED');
69 header('Location: add_test_questions.php?tid='.$tid.'&_course_id='.$_course_id);
70 require_once(TR_INCLUDE_PATH.'footer.inc.php');
74 require_once(TR_INCLUDE_PATH.'header.inc.php');
76 foreach ($_POST['questions'] as $id => $cat_array) {
77 foreach ($cat_array as $idx => $q) {
78 $_POST['questions'][$id][$idx] = intval($q);
79 $questions[] = intval($q);
83 $rows = $testsQuestionsDAO->getByQuestionIDs($questions);
86 if (is_array($rows)) {
87 foreach ($rows as $row) {
88 $questions .= '<li>'.htmlspecialchars($row['question']).'</li>';
89 $questions_array['questions['.$row['question_id'].']'] = $row['question_id'];
92 $questions_array['tid'] = $_POST['tid'];
93 $questions_array['_course_id'] = $_course_id;
94 $msg->addConfirm(array('ADD_TEST_QUESTIONS', $questions), $questions_array);
99 <?php require_once(TR_INCLUDE_PATH.'footer.inc.php'); ?>