2 /************************************************************************/
4 /************************************************************************/
5 /* Copyright (c) 2002-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 /************************************************************************/
15 define('AT_INCLUDE_PATH', '../../../include/');
16 require(AT_INCLUDE_PATH.'vitals.inc.php');
18 authenticate(AT_PRIV_TESTS);
20 $tid = intval($_POST['tid']);
22 $_pages['mods/_standard/tests/questions.php?tid='.$tid]['title_var'] = 'questions';
23 $_pages['mods/_standard/tests/questions.php?tid='.$tid]['parent'] = 'mods/_standard/tests/index.php';
24 $_pages['mods/_standard/tests/questions.php?tid='.$tid]['children'] = array('mods/_standard/tests/add_test_questions.php?tid='.$tid);
26 $_pages['mods/_standard/tests/add_test_questions.php?tid='.$tid]['title_var'] = 'add_questions';
27 $_pages['mods/_standard/tests/add_test_questions.php?tid='.$tid]['parent'] = 'mods/_standard/tests/questions.php?tid='.$tid;
29 $_pages['mods/_standard/tests/add_test_questions_confirm.php']['title_var'] = 'add_questions';
30 $_pages['mods/_standard/tests/add_test_questions_confirm.php']['parent'] = 'mods/_standard/tests/questions.php?tid='.$tid;
32 if (isset($_POST['cancel'])) {
33 $msg->addFeedback('CANCELLED');
34 header('Location: questions.php?tid='.$tid);
36 } else if (isset($_POST['submit_yes'])) {
38 $sql = "SELECT MAX(ordering) AS max_ordering FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=".$tid;
39 $result = mysql_query($sql, $db);
40 $order = mysql_fetch_assoc($result);
41 $order = $order['max_ordering'];
43 $sql = "REPLACE INTO ".TABLE_PREFIX."tests_questions_assoc VALUES ";
44 foreach ($_POST['questions'] as $question) {
46 $question = intval($question);
47 $sql .= '('.$tid.', '.$question.', 0, '.$order.', 0),';
49 $sql = substr($sql, 0, -1);
50 $result = mysql_query($sql, $db);
52 $msg->addFeedback('ACTION_COMPLETED_SUCCESSFULLY');
53 header('Location: questions.php?tid='.$tid);
55 } else if (isset($_POST['submit_no'])) {
56 $msg->addFeedback('CANCELLED');
57 header('Location: add_test_questions.php?tid='.$tid);
61 if (!is_array($_POST['questions']) || !count($_POST['questions'])) {
62 $msg->addError('NO_QUESTIONS_SELECTED');
63 header('Location: add_test_questions.php?tid='.$tid);
64 require(AT_INCLUDE_PATH.'footer.inc.php');
68 require(AT_INCLUDE_PATH.'header.inc.php');
70 foreach ($_POST['questions'] as $id => $cat_array) {
71 foreach ($cat_array as $idx => $q) {
72 $_POST['questions'][$id][$idx] = intval($q);
75 foreach ($_POST['questions'] as $cat_array) {
76 $questions .= addslashes(implode(',',$cat_array)).',';
79 $questions = substr($questions, 0, -1);
81 $sql = "SELECT question, question_id FROM ".TABLE_PREFIX."tests_questions WHERE question_id IN ($questions) AND course_id=$_SESSION[course_id] ORDER BY question";
82 $result = mysql_query($sql, $db);
85 while ($row = mysql_fetch_assoc($result)) {
86 $questions .= '<li>'.htmlspecialchars($row['question']).'</li>';
87 $questions_array['questions['.$row['question_id'].']'] = $row['question_id'];
89 $questions_array['tid'] = $_POST['tid'];
90 $msg->addConfirm(array('ADD_TEST_QUESTIONS', $questions), $questions_array);
95 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>