PageRenderTime 43ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/mods/_standard/tests/view_results.php

https://github.com/harriswong/ATutor
PHP | 196 lines | 151 code | 26 blank | 19 comment | 35 complexity | 865846e6fb23204692186e1412510a93 MD5 | raw file
  1. <?php
  2. /****************************************************************/
  3. /* ATutor */
  4. /****************************************************************/
  5. /* Copyright (c) 2002-2010 */
  6. /* Inclusive Design Institute */
  7. /* http://atutor.ca */
  8. /* */
  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. /****************************************************************/
  13. // $Id$
  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'));
  19. if (defined('AT_FORCE_GET_FILE') && AT_FORCE_GET_FILE) {
  20. $content_base_href = 'get.php/';
  21. } else {
  22. $course_base_href = 'content/' . $_SESSION['course_id'] . '/';
  23. }
  24. if (isset($_REQUEST['goto_content']))
  25. {
  26. header('Location: '.url_rewrite('content.php?cid='.$cid, AT_PRETTY_URL_IS_HEADER));
  27. exit;
  28. }
  29. if (isset($_REQUEST['back']))
  30. {
  31. header('Location: '.url_rewrite('mods/_standard/tests/my_tests.php', AT_PRETTY_URL_IS_HEADER));
  32. exit;
  33. }
  34. require(AT_INCLUDE_PATH.'header.inc.php');
  35. $tid = intval($_GET['tid']);
  36. $rid = intval($_GET['rid']);
  37. if (isset($_REQUEST['cid'])) $cid = $_REQUEST['cid'];
  38. $sql = "SELECT title, random, passfeedback, failfeedback, passscore, passpercent FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
  39. $result = mysql_query($sql, $db);
  40. $row = mysql_fetch_array($result);
  41. $test_title = $row['title'];
  42. $passfeedback = $row['passfeedback'];
  43. $failfeedback = $row['failfeedback'];
  44. $passscore = $row['passscore'];
  45. $passpercent = $row['passpercent'];
  46. $is_random = $row['random'];
  47. $mark_right = ' <img src="'.$_base_path.'images/checkmark.gif" alt="'._AT('correct_answer').'" title="'._AT('correct_answer').'" />';
  48. $mark_wrong = ' <img src="'.$_base_path.'images/x.gif" alt="'._AT('wrong_answer').'" title="'._AT('wrong_answer').'" />';
  49. $sql = "SELECT * FROM ".TABLE_PREFIX."tests_results WHERE result_id=$rid";
  50. $result = mysql_query($sql, $db);
  51. if (!$row = mysql_fetch_assoc($result)){
  52. $msg->printErrors('ITEM_NOT_FOUND');
  53. require(AT_INCLUDE_PATH.'footer.inc.php');
  54. exit;
  55. }
  56. $final_score= $row['final_score'];
  57. //make sure they're allowed to see results now
  58. $sql = "SELECT result_release, out_of FROM ".TABLE_PREFIX."tests WHERE test_id=$tid AND course_id=$_SESSION[course_id]";
  59. $result = mysql_query($sql, $db);
  60. $row = mysql_fetch_assoc($result);
  61. if ( ($row['result_release']==AT_RELEASE_NEVER) || ($row['result_release']==AT_RELEASE_MARKED && $final_score=='') ) {
  62. $msg->printErrors('RESULTS_NOT_RELEASED');
  63. require(AT_INCLUDE_PATH.'footer.inc.php');
  64. exit;
  65. }
  66. $out_of = $row['out_of'];
  67. /* Retrieve randomly choosed questions */
  68. $sql = "SELECT question_id FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid";
  69. $result = mysql_query($sql, $db);
  70. $row = mysql_fetch_array($result);
  71. $random_id_string = $row[question_id];
  72. $row = mysql_fetch_array($result);
  73. while ($row['question_id'] != '') {
  74. $random_id_string = $random_id_string.','.$row['question_id'];
  75. $row = mysql_fetch_array($result);
  76. }
  77. if (!$random_id_string) {
  78. $random_id_string = 0;
  79. }
  80. if ($is_random) {
  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";
  82. } else {
  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";
  84. }
  85. $result = mysql_query($sql, $db);
  86. if (mysql_num_rows($result) == 0) {
  87. echo '<p>'._AT('no_questions').'</p>';
  88. require(AT_INCLUDE_PATH.'footer.inc.php');
  89. exit;
  90. }
  91. // calculate test/my total score to display pass/fail feedback
  92. $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)";
  93. $result_test_total = mysql_query($sql_test_total, $db);
  94. $row_test_total = mysql_fetch_array($result_test_total);
  95. $test_total_score = $row_test_total["test_total_score"];
  96. while ($row = mysql_fetch_assoc($result)) {
  97. $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]";
  98. $result_this_score = mysql_query($sql_this_score, $db);
  99. $this_score = mysql_fetch_assoc($result_this_score);
  100. $my_score+=$this_score['score'];
  101. $this_total += $row['weight'];
  102. }
  103. ?>
  104. <form method="get" action="<?php echo $_REQUEST['PHP_SELF']; ?>">
  105. <?php if (isset($_REQUEST['cid'])) {?> <input type="hidden" name="cid" value="<?php echo $cid; ?>" /> <?php }?>
  106. <div class="input-form">
  107. <div class="row">
  108. <h2><?php echo AT_print($test_title, 'tests.title'); ?></h2>
  109. </div>
  110. <div class="row">
  111. <h3 align="center">
  112. <?php
  113. // don't display any feedback if test is created as "no pass score"
  114. if (($passscore == 0 && $passpercent == 0) || ($passpercent <> 0 && $this_total == 0))
  115. echo '';
  116. // display pass feedback for passed students
  117. elseif (($passscore<>0 && $my_score>=$passscore) ||
  118. ($passpercent<>0 && ($my_score/$this_total*100)>=$passpercent))
  119. echo '<font color="green">' . $passfeedback . '</font>';
  120. // otherwise, display fail feedback
  121. else
  122. echo '<font color="red">' . $failfeedback . '</font>';
  123. ?>
  124. </h3>
  125. </div>
  126. <?php if ($row['instructions'] != ''): ?>
  127. <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
  128. <strong><?php echo _AT('instructions'); ?></strong>
  129. </div>
  130. <div class="row" style="padding-bottom: 20px"><?php echo $row['instructions']; ?></div>
  131. <?php endif; ?>
  132. <?php
  133. // reset the result cursor to beginning
  134. mysql_data_seek ($result, 0);
  135. while ($row = mysql_fetch_assoc($result)) {
  136. $sql = "SELECT * FROM ".TABLE_PREFIX."tests_answers WHERE result_id=$rid AND question_id=$row[question_id] AND member_id=$_SESSION[member_id]";
  137. $result_a = mysql_query($sql, $db);
  138. $answer_row = mysql_fetch_assoc($result_a);
  139. $obj = TestQuestions::getQuestion($row['type']);
  140. $obj->displayResult($row, $answer_row);
  141. if ($row['feedback']) {
  142. echo '<div class="row"><p><strong>'._AT('feedback').':</strong> ';
  143. echo AT_print(nl2br($row['feedback']), 'tests_questions.feedback').'</p></div>';
  144. }
  145. }
  146. ?>
  147. <?php if ($this_total): ?>
  148. <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
  149. <strong>
  150. <span style="float: right"><?php echo $my_score .' / '.$this_total; ?> <?php echo _AT('points'); ?></span>
  151. <?php echo _AT('final_score'); ?>:
  152. </strong>
  153. </div>
  154. <?php else: ?>
  155. <div style="background-color: #f3f3f3; padding: 5px 10px; margin: 0px; border-top: 1px solid">
  156. <strong>
  157. <?php echo _AT('done'); ?>!
  158. </strong>
  159. </div>
  160. <?php endif; ?>
  161. <div class="row buttons">
  162. <?php if (isset($cid)) {?>
  163. <input type="submit" value="<?php echo _AT('goto_content'); ?>" name="goto_content" />
  164. <?php } else {?>
  165. <input type="submit" value="<?php echo _AT('back'); ?>" name="back" />
  166. <?php }?>
  167. </div>
  168. </div>
  169. </form>
  170. <?php require(AT_INCLUDE_PATH.'footer.inc.php'); ?>