result.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Shows the exercise results
  5. *
  6. * @author Julio Montoya Armas - Simple exercise result page
  7. *
  8. */
  9. /**
  10. * Code
  11. */
  12. // name of the language file that needs to be included
  13. $language_file = array('exercice');
  14. // including additional libraries
  15. require_once 'exercise.class.php';
  16. require_once 'exercise.lib.php';
  17. require_once 'question.class.php'; //also defines answer type constants
  18. require_once 'answer.class.php';
  19. require_once '../inc/global.inc.php';
  20. if (empty($origin) ) {
  21. $origin = $_REQUEST['origin'];
  22. }
  23. api_protect_course_script();
  24. $id = isset($_REQUEST['id']) ? intval($_GET['id']) : null; //exe id
  25. $show_headers = isset($_GET['show_headers']) ? intval($_GET['show_headers']) : null; //exe id
  26. if (empty($id)) {
  27. api_not_allowed();
  28. }
  29. $is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor;
  30. //Getting results from the exe_id. This variable also contain all the information about the exercise
  31. $track_exercise_info = get_exercise_track_exercise_info($id);
  32. //No track info
  33. if (empty($track_exercise_info)) {
  34. api_not_allowed(false);
  35. }
  36. $exercise_id = $track_exercise_info['id'];
  37. $exercise_date = $track_exercise_info['start_date'];
  38. $student_id = $track_exercise_info['exe_user_id'];
  39. $learnpath_id = $track_exercise_info['orig_lp_id'];
  40. $learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
  41. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  42. $course_code = api_get_course_id();
  43. $current_user_id = api_get_user_id();
  44. if (empty($objExercise)) {
  45. $objExercise = new Exercise();
  46. $objExercise->read($exercise_id);
  47. }
  48. //Only users can see their own results
  49. if (!$is_allowedToEdit) {
  50. if ($student_id != $current_user_id) {
  51. api_not_allowed();
  52. }
  53. }
  54. if ($show_headers) {
  55. $interbreadcrumb[] = array("url" => "exercice.php","name" => get_lang('Exercices'));
  56. $interbreadcrumb[] = array("url" => "#","name" => get_lang('Result'));
  57. $this_section = SECTION_COURSES;
  58. Display::display_header();
  59. } else {
  60. Display::display_reduced_header();
  61. }
  62. $show_results = true;
  63. $show_only_total_score = false;
  64. // Avoiding the "Score 0/0" message when the exe_id is not set
  65. if (!empty($track_exercise_info)) {
  66. $exerciseTitle = $track_exercise_info['title'];
  67. $exerciseDescription = $track_exercise_info['description'];
  68. // if the results_disabled of the Quiz is 1 when block the script
  69. $result_disabled = $track_exercise_info['results_disabled'];
  70. if (!(api_is_platform_admin() || api_is_course_admin()) ) {
  71. if ($result_disabled == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  72. $show_results = false;
  73. Display::display_warning_message(get_lang('CantViewResults'));
  74. } elseif ($result_disabled == EXERCISE_FEEDBACK_TYPE_EXAM) {
  75. $show_results = false;
  76. $show_only_total_score = true;
  77. }
  78. }
  79. }
  80. if ($show_results || $show_only_total_score) {
  81. $user_info = api_get_user_info($student_id);
  82. //Shows exercise header
  83. $objExercise->description = '';
  84. echo $objExercise->show_exercise_result_header(api_get_person_name($user_info['firstName'], $user_info['lastName']), api_convert_and_format_date($exercise_date, DATE_TIME_FORMAT_LONG));
  85. }
  86. $i = $totalScore = $totalWeighting = 0;
  87. $result = get_exercise_results_by_attempt($id);
  88. $question_list = $result[$id]['question_list'];
  89. // for each question
  90. $total_weighting = 0;
  91. $counter = 1;
  92. if (!empty($question_list)) {
  93. foreach ($question_list as $question_item) {
  94. $objQuestionTmp = Question::read($question_item['question_id']);
  95. $total_weighting += $objQuestionTmp->selectWeighting();
  96. }
  97. foreach ($question_list as $question_item) {
  98. $choice = $question_item['answer'];
  99. // creates a temporary Question object
  100. $questionId = $question_item['question_id'];
  101. $objQuestionTmp = Question::read($questionId);
  102. $questionName = $objQuestionTmp->selectTitle();
  103. $questionDescription= $objQuestionTmp->selectDescription();
  104. $questionWeighting = $objQuestionTmp->selectWeighting();
  105. $answerType = $objQuestionTmp->selectType();
  106. $quesId = $objQuestionTmp->selectId();
  107. if ($show_results) {
  108. echo $objQuestionTmp->return_header($objExercise->feedbacktype, $counter);
  109. }
  110. $counter++;
  111. if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  112. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  113. $questionScore = $question_result['score'];
  114. $totalScore += $question_result['score'];
  115. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  116. $choice = array();
  117. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  118. $questionScore = $question_result['score'];
  119. $totalScore += $question_result['score'];
  120. } elseif ($answerType == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
  121. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  122. $questionScore = $question_result['score'];
  123. $totalScore += $question_result['score'];
  124. } elseif ($answerType == FILL_IN_BLANKS) {
  125. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  126. $questionScore = $question_result['score'];
  127. $totalScore += $question_result['score'];
  128. } elseif ($answerType == FREE_ANSWER) {
  129. $answer = $str;
  130. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  131. $questionScore = $question_result['score'];
  132. $totalScore += $question_result['score'];
  133. } elseif ($answerType == MATCHING) {
  134. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  135. $questionScore = $question_result['score'];
  136. $totalScore += $question_result['score'];
  137. } elseif ($answerType == HOT_SPOT) {
  138. //@todo move this in the manage_answer function
  139. if ($show_results) {
  140. echo '<table width="500" border="0"><tr>
  141. <td valign="top" align="center" style="padding-left:0px;" >
  142. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  143. }
  144. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  145. $questionScore = $question_result['score'];
  146. $totalScore += $question_result['score'];
  147. if ($show_results) {
  148. echo '</table></td></tr>';
  149. echo '<tr>
  150. <td colspan="2">'.
  151. '<object type="application/x-shockwave-flash" data="'.api_get_path(WEB_CODE_PATH).'plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
  152. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  153. </object>
  154. </td>
  155. </tr>
  156. </table><br/>';
  157. }
  158. } else if($answerType == HOT_SPOT_DELINEATION) {
  159. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
  160. $questionScore = $question_result['score'];
  161. $totalScore += $question_result['score'];
  162. $final_overlap = $question_result['extra']['final_overlap'];
  163. $final_missing = $question_result['extra']['final_missing'];
  164. $final_excess = $question_result['extra']['final_excess'];
  165. $overlap_color = $question_result['extra']['overlap_color'];
  166. $missing_color = $question_result['extra']['missing_color'];
  167. $excess_color = $question_result['extra']['excess_color'];
  168. $threadhold1 = $question_result['extra']['threadhold1'];
  169. $threadhold2 = $question_result['extra']['threadhold2'];
  170. $threadhold3 = $question_result['extra']['threadhold3'];
  171. if ($show_results) {
  172. if ($overlap_color) {
  173. $overlap_color='green';
  174. } else {
  175. $overlap_color='red';
  176. }
  177. if ($missing_color) {
  178. $missing_color='green';
  179. } else {
  180. $missing_color='red';
  181. }
  182. if ($excess_color) {
  183. $excess_color='green';
  184. } else {
  185. $excess_color='red';
  186. }
  187. if (!is_numeric($final_overlap)) {
  188. $final_overlap = 0;
  189. }
  190. if (!is_numeric($final_missing)) {
  191. $final_missing = 0;
  192. }
  193. if (!is_numeric($final_excess)) {
  194. $final_excess = 0;
  195. }
  196. if ($final_excess>100) {
  197. $final_excess = 100;
  198. }
  199. $table_resume='<table class="data_table">
  200. <tr class="row_odd" >
  201. <td></td>
  202. <td ><b>'.get_lang('Requirements').'</b></td>
  203. <td><b>'.get_lang('YourAnswer').'</b></td>
  204. </tr>
  205. <tr class="row_even">
  206. <td><b>'.get_lang('Overlap').'</b></td>
  207. <td>'.get_lang('Min').' '.$threadhold1.'</td>
  208. <td><div style="color:'.$overlap_color.'">'.(($final_overlap < 0)?0:intval($final_overlap)).'</div></td>
  209. </tr>
  210. <tr>
  211. <td><b>'.get_lang('Excess').'</b></td>
  212. <td>'.get_lang('Max').' '.$threadhold2.'</td>
  213. <td><div style="color:'.$excess_color.'">'.(($final_excess < 0)?0:intval($final_excess)).'</div></td>
  214. </tr>
  215. <tr class="row_even">
  216. <td><b>'.get_lang('Missing').'</b></td>
  217. <td>'.get_lang('Max').' '.$threadhold3.'</td>
  218. <td><div style="color:'.$missing_color.'">'.(($final_missing < 0)?0:intval($final_missing)).'</div></td>
  219. </tr></table>';
  220. if ($answerType!= HOT_SPOT_DELINEATION) {
  221. $item_list=explode('@@',$destination);
  222. //print_R($item_list);
  223. $try = $item_list[0];
  224. $lp = $item_list[1];
  225. $destinationid= $item_list[2];
  226. $url=$item_list[3];
  227. $table_resume='';
  228. } else {
  229. if ($next==0) {
  230. $try = $try_hotspot;
  231. $lp = $lp_hotspot;
  232. $destinationid= $select_question_hotspot;
  233. $url=$url_hotspot;
  234. } else {
  235. //show if no error
  236. //echo 'no error';
  237. $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
  238. $answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
  239. }
  240. }
  241. echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
  242. if ($answerType == HOT_SPOT_DELINEATION) {
  243. if ($organs_at_risk_hit>0) {
  244. $message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  245. $message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
  246. } else {
  247. $message='<p>'.get_lang('YourDelineation').'</p>';
  248. $message.=$table_resume;
  249. $message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  250. }
  251. $message.='<p>'.$comment.'</p>';
  252. echo $message;
  253. } else {
  254. echo '<p>'.$comment.'</p>';
  255. }
  256. //showing the score
  257. /*
  258. $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  259. $resfree = Database::query($queryfree);
  260. $questionScore= Database::result($resfree,0,"marks");
  261. $totalScore+=$questionScore;*/
  262. ?>
  263. </table>
  264. </td></tr>
  265. <?php
  266. echo '<tr>
  267. <td colspan="2">
  268. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
  269. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" />
  270. </object>
  271. </td>
  272. </tr>
  273. </table>';
  274. }
  275. }
  276. if ($show_results) {
  277. if ($answerType != HOT_SPOT) {
  278. echo '</table>';
  279. }
  280. }
  281. if ($show_results) {
  282. $comnt = get_comments($id, $questionId);
  283. if (!empty($comnt)) {
  284. echo '<b>'.get_lang('Feedback').'</b>';
  285. echo '<div id="question_feedback">'.$comnt.'</div>';
  286. }
  287. }
  288. $my_total_score = $questionScore;
  289. $my_total_weight = $questionWeighting;
  290. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
  291. $my_total_score = 0;
  292. }
  293. if ($show_results) {
  294. echo '<div id="question_score">';
  295. echo get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);
  296. echo '</div>';
  297. }
  298. unset($objAnswerTmp);
  299. unset($objQuestionTmp);
  300. $i++;
  301. $totalWeighting += $questionWeighting;
  302. } // end of large foreach on questions
  303. }
  304. //Total score
  305. if ($show_results || $show_only_total_score) {
  306. echo '<div id="question_score">'.get_lang('YourTotalScore').": ";
  307. $my_total_score_temp = $totalScore;
  308. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
  309. $my_total_score_temp = 0;
  310. }
  311. echo show_score($my_total_score_temp, $totalWeighting, false);
  312. echo '</div>';
  313. }
  314. if ($show_headers) {
  315. Display::display_footer();
  316. }