2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-2006 by Greg Gay, Joel Kronenberg & Heidi Hazelton*/
6 /* Adaptive Technology Resource Centre / University of Toronto */
9 /* This program is free software. You can redistribute it and/or */
10 /* modify it under the terms of the GNU General Public License */
11 /* as published by the Free Software Foundation. */
12 /************************************************************************/
16 define('AT_INCLUDE_PATH', '../../include/');
17 require(AT_INCLUDE_PATH.'vitals.inc.php');
19 authenticate(AT_PRIV_TESTS);
21 $tid = intval($_POST['tid']);
23 $_pages['tools/tests/questions.php?tid='.$tid]['title_var'] = 'questions';
24 $_pages['tools/tests/questions.php?tid='.$tid]['parent'] = 'tools/tests/index.php';
25 $_pages['tools/tests/questions.php?tid='.$tid]['children'] = array('tools/tests/add_test_questions.php?tid='.$tid);
27 $_pages['tools/tests/add_test_questions.php?tid='.$tid]['title_var'] = 'add_questions';
28 $_pages['tools/tests/add_test_questions.php?tid='.$tid]['parent'] = 'tools/tests/questions.php?tid='.$tid;
30 $_pages['tools/tests/add_test_questions_confirm.php']['title_var'] = 'add_questions';
31 $_pages['tools/tests/add_test_questions_confirm.php']['parent'] = 'tools/tests/questions.php?tid='.$tid;
33 if (isset($_POST['cancel'])) {
34 $msg->addFeedback('CANCELLED');
35 header('Location: questions.php?tid='.$tid);
37 } else if (isset($_POST['submit_yes'])) {
39 $sql = "SELECT MAX(ordering) AS max_ordering FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=".$tid;
40 $result = mysql_query($sql, $db);
41 $order = mysql_fetch_assoc($result);
42 $order = $order['max_ordering'];
44 $sql = "REPLACE INTO ".TABLE_PREFIX."tests_questions_assoc VALUES ";
45 foreach ($_POST['questions'] as $question) {
47 $question = intval($question);
48 $sql .= '('.$tid.', '.$question.', 0, '.$order.', 0),';
50 $sql = substr($sql, 0, -1);
51 $result = mysql_query($sql, $db);
53 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
54 header('Location: questions.php?tid='.$tid);
56 } else if (isset($_POST['submit_no'])) {
57 $msg->addFeedback('CANCELLED');
58 header('Location: add_test_questions.php?tid='.$tid);
62 if (!is_array($_POST['questions']) || !count($_POST['questions'])) {
63 $msg->addError('NO_QUESTIONS_SELECTED');
64 header('Location: add_test_questions.php?tid='.$tid);
65 require(AT_INCLUDE_PATH.'footer.inc.php');
69 require(AT_INCLUDE_PATH.'header.inc.php');
71 foreach ($_POST['questions'] as $id => $cat_array) {
72 foreach ($cat_array as $idx => $q) {
73 $_POST['questions'][$id][$idx] = intval($q);
76 foreach ($_POST['questions'] as $cat_array) {
77 $questions .= addslashes(implode(',',$cat_array)).',';
80 $questions = substr($questions, 0, -1);
82 $sql = "SELECT question, question_id FROM ".TABLE_PREFIX."tests_questions WHERE question_id IN ($questions) AND course_id=$_SESSION[course_id] ORDER BY question";
83 $result = mysql_query($sql, $db);
86 while ($row = mysql_fetch_assoc($result)) {
87 $questions .= '<li>'.htmlspecialchars($row['question']).'</li>';
88 $questions_array['questions['.$row['question_id'].']'] = $row['question_id'];
90 $questions_array['tid'] = $_POST['tid'];
91 $msg->addConfirm(array('ADD_TEST_QUESTIONS', $questions), $questions_array);
96 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>