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/lib/test_result_functions.inc.php'); // for print_result and print_score
17 require(AT_INCLUDE_PATH.'../mods/_standard/tests/classes/testQuestions.class.php');
18 $_letters = array(_AT('A'), _AT('B'), _AT('C'), _AT('D'), _AT('E'), _AT('F'), _AT('G'), _AT('H'), _AT('I'), _AT('J'));
20 if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
21 $content_base_href = 'get.php/';
23 $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
26 if (isset($_REQUEST['goto_content']))
28 header('Location: '.url_rewrite('content.php?cid='.$cid, AT_PRETTY_URL_IS_HEADER));
31 if (isset($_REQUEST['back']))
33 header('Location: '.url_rewrite('mods/_standard/tests/my_tests.php', AT_PRETTY_URL_IS_HEADER));
37 require(AT_INCLUDE_PATH.'header.inc.php');
39 $tid = intval($_GET['tid']);
40 $rid = intval($_GET['rid']);
41 if (isset($_REQUEST['cid'])) $cid = $_REQUEST['cid'];
43 $sql = "SELECT title, random, passfeedback, failfeedback, passscore, passpercent FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
44 $result = mysql_query($sql, $db);
45 $row = mysql_fetch_array($result);
46 $test_title = $row['title'];
47 $passfeedback = $row['passfeedback'];
48 $failfeedback = $row['failfeedback'];
49 $passscore = $row['passscore'];
50 $passpercent = $row['passpercent'];
51 $is_random = $row['random'];
53 $mark_right = ' <img src="'.$_base_path.'images/checkmark.gif" alt="'._AT('correct_answer').'" title="'._AT('correct_answer').'" />';
54 $mark_wrong = ' <img src="'.$_base_path.'images/x.gif" alt="'._AT('wrong_answer').'" title="'._AT('wrong_answer').'" />';
56 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_results WHERE result_id=$rid";
57 $result = mysql_query($sql, $db);
58 if (!$row = mysql_fetch_assoc($result)){
59 $msg->printErrors('ITEM_NOT_FOUND');
60 require(AT_INCLUDE_PATH.'footer.inc.php');
63 $final_score= $row['final_score'];
65 //make sure they're allowed to see results now
66 $sql = "SELECT result_release, out_of FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
67 $result = mysql_query($sql, $db);
68 $row = mysql_fetch_assoc($result);
70 if ( ($row['result_release']==AT_RELEASE_NEVER) || ($row['result_release']==AT_RELEASE_MARKED && $final_score=='') ) {
71 $msg->printErrors('RESULTS_NOT_RELEASED');
72 require(AT_INCLUDE_PATH.'footer.inc.php');
76 $out_of = $row['out_of'];
78 /* Retrieve randomly choosed questions */
79 $sql = "SELECT question_id FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid";
80 $result = mysql_query($sql, $db);
81 $row = mysql_fetch_array($result);
82 $random_id_string = $row[question_id];
83 $row = mysql_fetch_array($result);
84 while ($row['question_id'] != '') {
85 $random_id_string = $random_id_string.','.$row['question_id'];
86 $row = mysql_fetch_array($result);
88 if (!$random_id_string) {
89 $random_id_string = 0;
93 $sql = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQA.test_id=$tid AND TQ.question_id IN ($random_id_string) ORDER BY TQ.question_id";
95 $sql = "SELECT TQ.*, TQA.* FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQA.test_id=$tid AND TQ.question_id IN ($random_id_string) ORDER BY TQA.ordering, TQ.question_id";
97 $result = mysql_query($sql, $db);
99 if (mysql_num_rows($result) == 0) {
100 echo '<p>'._AT('no_questions').'</p>';
101 require(AT_INCLUDE_PATH.'footer.inc.php');
105 // calculate test/my total score to display pass/fail feedback
106 $sql_test_total = "SELECT sum(TQA.weight) test_total_score FROM ".TABLE_PREFIX."tests_questions TQ INNER JOIN ".TABLE_PREFIX."tests_questions_assoc TQA USING (question_id) WHERE TQA.test_id=$tid AND TQ.question_id IN ($random_id_string)";
107 $result_test_total = mysql_query($sql_test_total, $db);
108 $row_test_total = mysql_fetch_array($result_test_total);
109 $test_total_score = $row_test_total["test_total_score"];
111 while ($row = mysql_fetch_assoc($result)) {
112 $sql_this_score = "SELECT * FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid AND question_id=$row[question_id] AND member_id=$_SESSION[member_id]";
113 $result_this_score = mysql_query($sql_this_score, $db);
114 $this_score = mysql_fetch_assoc($result_this_score);
116 $my_score+=$this_score['score'];
117 $this_total += $row['weight'];
120 <form method="get" action="<?php echo $_REQUEST['PHP_SELF']; ?>">
121 <?php if (isset($_REQUEST['cid'])) {?> <input type="hidden" name="cid" value="<?php echo $cid; ?>" /> <?php }?>
123 <div class="input-form">
125 <h2><?php echo AT_print($test_title, 'tests.title'); ?></h2>
131 // don't display any feedback if test is created as "no pass score"
132 if (($passscore == 0 && $passpercent == 0) || ($passpercent <> 0 && $this_total == 0))
134 // display pass feedback for passed students
135 elseif (($passscore<>0 && $my_score>=$passscore) ||
136 ($passpercent<>0 && ($my_score/$this_total*100)>=$passpercent))
137 echo '<font color="green">' . $passfeedback . '</font>';
138 // otherwise, display fail feedback
140 echo '<font color="red">' . $failfeedback . '</font>';
145 <?php if ($row['instructions'] != ''): ?>
146 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
147 <strong><?php echo _AT('instructions'); ?></strong>
149 <div class="row" style="padding-bottom: 20px"><?php echo $row['instructions']; ?></div>
153 // reset the result cursor to beginning
154 mysql_data_seek ($result, 0);
156 while ($row = mysql_fetch_assoc($result)) {
157 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid AND question_id=$row[question_id] AND member_id=$_SESSION[member_id]";
158 $result_a = mysql_query($sql, $db);
159 $answer_row = mysql_fetch_assoc($result_a);
161 $obj = TestQuestions::getQuestion($row['type']);
162 $obj->displayResult($row, $answer_row);
164 if ($row['feedback']) {
165 echo '<div class="row"><p><strong>'._AT('feedback').':</strong> ';
166 echo AT_print(nl2br($row['feedback']), 'tests_questions.feedback').'</p></div>';
171 <?php if ($this_total): ?>
172 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
174 <span style="float: right"><?php echo $my_score .' / '.$this_total; ?> <?php echo _AT('points'); ?></span>
175 <?php echo _AT('final_score'); ?>:
179 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
181 <?php echo _AT('done'); ?>!
186 <div class="row buttons">
187 <?php if (isset($cid)) {?>
188 <input type="submit" value="<?php echo _AT('goto_content'); ?>" name="goto_content" />
190 <input type="submit" value="<?php echo _AT('back'); ?>" name="back" />
196 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>