2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2010 */
6 /* Inclusive Design Institute */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../../../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'../mods/_standard/tests/classes/testQuestions.class.php');
18 authenticate(AT_PRIV_TESTS);
19 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
22 header('Location: index.php');
26 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
27 $content_base_href = 'get.php/';
29 $content_base_href = 'content/' . $_SESSION['course_id'] . '/';
32 require(AT_INCLUDE_PATH.'header.inc.php');
34 $tid = intval($_GET['tid']);
36 /* Retrieve the content_id of this test */
37 $sql = "SELECT title, random, num_questions, instructions FROM ".TABLE_PREFIX."tests WHERE test_id=$tid";
38 $result = mysql_query($sql, $db);
39 if (!($test_row = mysql_fetch_assoc($result))) {
40 $msg->printErrors('ITEM_NOT_FOUND');
41 require (AT_INCLUDE_PATH.'footer.inc.php');
44 $num_questions = $test_row['num_questions'];
48 /* !NOTE! this is a really awful way of randomizing questions !NOTE! */
50 /* Retrieve 'num_questions' question_id randomly choosed from
51 those who are related to this content_id*/
52 $sql = "SELECT question_id FROM ".TABLE_PREFIX."tests_questions_assoc WHERE test_id=$tid";
53 $result = mysql_query($sql, $db);
55 $row2 = mysql_fetch_assoc($result);
56 /* Store all related question in cr_questions */
57 while ($row2['question_id'] != '') {
58 $cr_questions[$i] = $row2['question_id'];
59 $row2 = mysql_fetch_assoc($result);
62 if ($i < $num_questions) {
63 /* this if-statement is misleading. */
64 /* one should still be able to preview a test before all its questions have been added. */
65 /* ie. preview as questions are added. */
69 /* Randomly choose only 'num_question' question */
70 $random_idx = rand(0, $i-1);
71 $random_id_string = $cr_questions[$random_idx];
73 $extracted[$j] = $random_idx;
76 while ($num_questions > 0) {
79 $random_idx = rand(0, $i-1);
81 for ($k=0;$k<$j;$k++) {
82 if ($extracted[$k]== $random_idx) {
88 $extracted[$j] = $random_idx;
90 $random_id_string = $random_id_string.','.$cr_questions[$random_idx];
93 $sql = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQ.course_id=$_SESSION[course_id] AND TQA.test_id=$tid AND TQA.question_id IN ($random_id_string) ORDER BY TQA.ordering, TQA.question_id";
96 $sql = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQ.course_id=$_SESSION[course_id] AND TQA.test_id=$tid ORDER BY TQA.ordering, TQA.question_id";
98 $result = mysql_query($sql, $db);
100 echo '<form method="post" action="'.$_SERVER['PHP_SELF'].'" name="preview">';
102 if (($row = mysql_fetch_assoc($result)) && !$rand_err) {
104 <div class="input-form" style="width:95%">
105 <div class="row"><h2><?php echo $test_row['title']; ?></h2></div>
108 <?php if ($test_row['instructions'] != ''): ?>
109 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
110 <strong><?php echo _AT('instructions'); ?></strong>
112 <div class="row" style="padding-bottom: 20px"><?php echo $test_row['instructions']; ?></div>
117 $o = TestQuestions::getQuestion($row['type']);
119 } while ($row = mysql_fetch_assoc($result));
121 <div class="row buttons">
122 <input type="submit" value="<?php echo _AT('back'); ?>" name="back" />
127 <script type="text/javascript">
129 function iframeSetHeight(id, height) {
130 document.getElementById("qframe" + id).style.height = (height + 20) + "px";
136 $msg->printErrors('NO_QUESTIONS');
140 require(AT_INCLUDE_PATH.'footer.inc.php');