moved code up one level to eliminate the docs subdirectory
[acontent.git] / tests / add_test_questions_confirm.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 $page = 'tests';
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');
19
20 global $_course_id;
21 Utility::authenticate(TR_PRIV_ISAUTHOR_OF_CURRENT_COURSE);
22 $testsQuestionsDAO = new TestsQuestionsDAO();
23 $testsQuestionsAssocDAO = new TestsQuestionsAssocDAO();
24
25 $tid = intval($_POST['tid']);
26
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');
30
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;
33
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;
36
37 if (isset($_POST['cancel'])) {
38         $msg->addFeedback('CANCELLED');
39         header('Location: questions.php?tid='.$tid.'&_course_id='.$_course_id);
40         exit;
41 } else if (isset($_POST['submit_yes'])) {
42         //get order
43         $order = $testsQuestionsAssocDAO->getMaxOrderByTestID($tid);
44
45         $sql = "REPLACE INTO ".TABLE_PREFIX."tests_questions_assoc VALUES ";
46         foreach ($_POST['questions'] as $question) {
47                 $order++;
48                 $question = intval($question);
49                 $sql .= '('.$tid.', '.$question.', 0, '.$order.'),';
50         }
51         $sql = substr($sql, 0, -1);
52         
53         if ($testsQuestionsAssocDAO->execute($sql)) {
54                 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
55                 header('Location: questions.php?tid='.$tid.'&_course_id='.$_course_id);
56                 exit;
57         }
58         else {
59                 $msg->addError('DB_NOT_UPDATED');
60         }
61 } else if (isset($_POST['submit_no'])) {
62         $msg->addFeedback('CANCELLED');
63         header('Location: add_test_questions.php?tid='.$tid.'&_course_id='.$_course_id);
64         exit;
65 }
66
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');
71         exit;
72 }
73
74 require_once(TR_INCLUDE_PATH.'header.inc.php');
75
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);
80         }
81 }
82
83 $rows = $testsQuestionsDAO->getByQuestionIDs($questions);
84
85 $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'];
90         }
91 }
92 $questions_array['tid'] = $_POST['tid'];
93 $questions_array['_course_id'] = $_course_id;
94 $msg->addConfirm(array('ADD_TEST_QUESTIONS', $questions), $questions_array);
95
96 $msg->printConfirm();
97 ?>
98
99 <?php require_once(TR_INCLUDE_PATH.'footer.inc.php'); ?>