2 /****************************************************************/
4 /****************************************************************/
5 /* Copyright (c) 2002-2008 by Greg Gay & Joel Kronenberg */
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 /****************************************************************/
14 define('AT_INCLUDE_PATH', '../include/');
15 require(AT_INCLUDE_PATH.'vitals.inc.php');
16 require(AT_INCLUDE_PATH.'lib/test_result_functions.inc.php'); // for print_result and print_score
17 require(AT_INCLUDE_PATH.'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 require(AT_INCLUDE_PATH.'header.inc.php');
28 $tid = intval($_GET['tid']);
29 $rid = intval($_GET['rid']);
31 $sql = "SELECT title, random, passfeedback, failfeedback, passscore, passpercent FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
32 $result = mysql_query($sql, $db);
33 $row = mysql_fetch_array($result);
34 $test_title = $row['title'];
35 $passfeedback = $row['passfeedback'];
36 $failfeedback = $row['failfeedback'];
37 $passscore = $row['passscore'];
38 $passpercent = $row['passpercent'];
39 $is_random = $row['random'];
41 $mark_right = ' <img src="'.$_base_path.'images/checkmark.gif" alt="'._AT('correct_answer').'" title="'._AT('correct_answer').'" />';
42 $mark_wrong = ' <img src="'.$_base_path.'images/x.gif" alt="'._AT('wrong_answer').'" title="'._AT('wrong_answer').'" />';
44 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_results WHERE result_id=$rid";
45 $result = mysql_query($sql, $db);
46 if (!$row = mysql_fetch_assoc($result)){
47 $msg->printErrors('ITEM_NOT_FOUND');
48 require(AT_INCLUDE_PATH.'footer.inc.php');
51 $final_score= $row['final_score'];
53 //make sure they're allowed to see results now
54 $sql = "SELECT result_release, out_of FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
55 $result = mysql_query($sql, $db);
56 $row = mysql_fetch_assoc($result);
58 if ( ($row['result_release']==AT_RELEASE_NEVER) || ($row['result_release']==AT_RELEASE_MARKED && $final_score=='') ) {
59 $msg->printErrors('RESULTS_NOT_RELEASED');
60 require(AT_INCLUDE_PATH.'footer.inc.php');
64 $out_of = $row['out_of'];
66 /* Retrieve randomly choosed questions */
67 $sql = "SELECT question_id FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid";
68 $result = mysql_query($sql, $db);
69 $row = mysql_fetch_array($result);
70 $random_id_string = $row[question_id];
71 $row = mysql_fetch_array($result);
72 while ($row['question_id'] != '') {
73 $random_id_string = $random_id_string.','.$row['question_id'];
74 $row = mysql_fetch_array($result);
76 if (!$random_id_string) {
77 $random_id_string = 0;
81 $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";
83 $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";
85 $result = mysql_query($sql, $db);
87 if (mysql_num_rows($result) == 0) {
88 echo '<p>'._AT('no_questions').'</p>';
89 require(AT_INCLUDE_PATH.'footer.inc.php');
93 // calculate test/my total score to display pass/fail feedback
94 $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)";
95 $result_test_total = mysql_query($sql_test_total, $db);
96 $row_test_total = mysql_fetch_array($result_test_total);
97 $test_total_score = $row_test_total["test_total_score"];
99 while ($row = mysql_fetch_assoc($result)) {
100 $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]";
101 $result_this_score = mysql_query($sql_this_score, $db);
102 $this_score = mysql_fetch_assoc($result_this_score);
104 $my_score+=$this_score['score'];
105 $this_total += $row['weight'];
108 <form method="get" action="<?php echo AT_BASE_HREF; ?>tools/my_tests.php">
109 <div class="input-form">
111 <h2><?php echo AT_print($test_title, 'tests.title'); ?></h2>
117 // don't display any feedback if test is created as "no pass score"
118 if (($passscore == 0 && $passpercent == 0) || ($passpercent <> 0 && $this_total == 0))
120 // display pass feedback for passed students
121 elseif (($passscore<>0 && $my_score>=$passscore) ||
122 ($passpercent<>0 && ($my_score/$this_total*100)>=$passpercent))
123 echo '<font color="green">' . $passfeedback . '</font>';
124 // otherwise, display fail feedback
126 echo '<font color="red">' . $failfeedback . '</font>';
131 <?php if ($row['instructions'] != ''): ?>
132 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
133 <strong><?php echo _AT('instructions'); ?></strong>
135 <div class="row" style="padding-bottom: 20px"><?php echo $row['instructions']; ?></div>
139 // reset the result cursor to beginning
140 mysql_data_seek ($result, 0);
142 while ($row = mysql_fetch_assoc($result)) {
143 $sql = "SELECT * FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid AND question_id=$row[question_id] AND member_id=$_SESSION[member_id]";
144 $result_a = mysql_query($sql, $db);
145 $answer_row = mysql_fetch_assoc($result_a);
147 $obj = TestQuestions::getQuestion($row['type']);
148 $obj->displayResult($row, $answer_row);
150 if ($row['feedback']) {
151 echo '<div class="row"><p><strong>'._AT('feedback').':</strong> ';
152 echo nl2br($row['feedback']).'</p></div>';
157 <?php if ($this_total): ?>
158 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
160 <span style="float: right"><?php echo $my_score .' / '.$this_total; ?> <?php echo _AT('points'); ?></span>
161 <?php echo _AT('final_score'); ?>:
165 <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
167 <?php echo _AT('done'); ?>!
172 <div class="row buttons">
173 <input type="submit" value="<?php echo _AT('back'); ?>" name="back" />
178 <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>