result.php 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379
  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 'question.class.php'; //also defines answer type constants
  17. require_once 'answer.class.php';
  18. require_once '../inc/global.inc.php';
  19. require_once 'exercise.lib.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. $display_category_name = 1;
  65. // Avoiding the "Score 0/0" message when the exe_id is not set
  66. if (!empty($track_exercise_info)) {
  67. $exerciseTitle = $track_exercise_info['title'];
  68. $exerciseDescription = $track_exercise_info['description'];
  69. // if the results_disabled of the Quiz is 1 when block the script
  70. $result_disabled = $track_exercise_info['results_disabled'];
  71. $display_category_name = $track_exercise_info['display_category_name'];
  72. if (!(api_is_platform_admin() || api_is_course_admin()) ) {
  73. if ($result_disabled == EXERCISE_FEEDBACK_TYPE_DIRECT) {
  74. $show_results = false;
  75. Display::display_warning_message(get_lang('CantViewResults'));
  76. } elseif ($result_disabled == EXERCISE_FEEDBACK_TYPE_EXAM) {
  77. $show_results = false;
  78. $show_only_total_score = true;
  79. }
  80. }
  81. }
  82. if ($show_results || $show_only_total_score) {
  83. $user_info = api_get_user_info($student_id);
  84. //Shows exercise header
  85. $objExercise->description = '';
  86. 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));
  87. }
  88. $i = $totalScore = $totalWeighting = 0;
  89. $result = get_exercise_results_by_attempt($id);
  90. $question_list = $result[$id]['question_list'];
  91. // for each question
  92. $total_weighting = 0;
  93. $counter = 1;
  94. if (!empty($question_list)) {
  95. foreach ($question_list as $question_item) {
  96. $objQuestionTmp = Question::read($question_item['question_id'], api_get_course_int_id());
  97. $total_weighting += $objQuestionTmp->selectWeighting();
  98. }
  99. foreach ($question_list as $question_item) {
  100. $choice = $question_item['answer'];
  101. // creates a temporary Question object
  102. $questionId = $question_item['question_id'];
  103. $objQuestionTmp = Question::read($questionId, api_get_course_int_id());
  104. $questionName = $objQuestionTmp->selectTitle();
  105. $questionDescription= $objQuestionTmp->selectDescription();
  106. $questionWeighting = $objQuestionTmp->selectWeighting();
  107. $answerType = $objQuestionTmp->selectType();
  108. $quesId = $objQuestionTmp->selectId();
  109. if ($show_results) {
  110. // display question category, if any
  111. Testcategory::displayCategoryAndTitle($questionId, $display_category_name );
  112. echo $objQuestionTmp->return_header($objExercise->feedbacktype, $counter);
  113. }
  114. $counter++;
  115. if ($answerType == MULTIPLE_ANSWER || $answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  116. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  117. $questionScore = $question_result['score'];
  118. $totalScore += $question_result['score'];
  119. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION || $answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  120. $choice = array();
  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 == UNIQUE_ANSWER || $answerType == UNIQUE_ANSWER_NO_OPTION) {
  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 == FILL_IN_BLANKS) {
  129. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  130. $questionScore = $question_result['score'];
  131. $totalScore += $question_result['score'];
  132. } elseif ($answerType == FREE_ANSWER) {
  133. $answer = $str;
  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 == MATCHING) {
  138. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  139. $questionScore = $question_result['score'];
  140. $totalScore += $question_result['score'];
  141. } elseif ($answerType == HOT_SPOT) {
  142. //@todo move this in the manage_answer function
  143. if ($show_results) {
  144. echo '<table width="500" border="0"><tr>
  145. <td valign="top" align="center" style="padding-left:0px;" >
  146. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  147. }
  148. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg());
  149. $questionScore = $question_result['score'];
  150. $totalScore += $question_result['score'];
  151. if ($show_results) {
  152. echo '</table></td></tr>';
  153. echo '<tr>
  154. <td colspan="2">'.
  155. '<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">
  156. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  157. </object>
  158. </td>
  159. </tr>
  160. </table><br/>';
  161. }
  162. } else if($answerType == HOT_SPOT_DELINEATION) {
  163. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), 'database');
  164. $questionScore = $question_result['score'];
  165. $totalScore += $question_result['score'];
  166. $final_overlap = $question_result['extra']['final_overlap'];
  167. $final_missing = $question_result['extra']['final_missing'];
  168. $final_excess = $question_result['extra']['final_excess'];
  169. $overlap_color = $question_result['extra']['overlap_color'];
  170. $missing_color = $question_result['extra']['missing_color'];
  171. $excess_color = $question_result['extra']['excess_color'];
  172. $threadhold1 = $question_result['extra']['threadhold1'];
  173. $threadhold2 = $question_result['extra']['threadhold2'];
  174. $threadhold3 = $question_result['extra']['threadhold3'];
  175. if ($show_results) {
  176. if ($overlap_color) {
  177. $overlap_color='green';
  178. } else {
  179. $overlap_color='red';
  180. }
  181. if ($missing_color) {
  182. $missing_color='green';
  183. } else {
  184. $missing_color='red';
  185. }
  186. if ($excess_color) {
  187. $excess_color='green';
  188. } else {
  189. $excess_color='red';
  190. }
  191. if (!is_numeric($final_overlap)) {
  192. $final_overlap = 0;
  193. }
  194. if (!is_numeric($final_missing)) {
  195. $final_missing = 0;
  196. }
  197. if (!is_numeric($final_excess)) {
  198. $final_excess = 0;
  199. }
  200. if ($final_excess>100) {
  201. $final_excess = 100;
  202. }
  203. $table_resume='<table class="data_table">
  204. <tr class="row_odd" >
  205. <td></td>
  206. <td ><b>'.get_lang('Requirements').'</b></td>
  207. <td><b>'.get_lang('YourAnswer').'</b></td>
  208. </tr>
  209. <tr class="row_even">
  210. <td><b>'.get_lang('Overlap').'</b></td>
  211. <td>'.get_lang('Min').' '.$threadhold1.'</td>
  212. <td><div style="color:'.$overlap_color.'">'.(($final_overlap < 0)?0:intval($final_overlap)).'</div></td>
  213. </tr>
  214. <tr>
  215. <td><b>'.get_lang('Excess').'</b></td>
  216. <td>'.get_lang('Max').' '.$threadhold2.'</td>
  217. <td><div style="color:'.$excess_color.'">'.(($final_excess < 0)?0:intval($final_excess)).'</div></td>
  218. </tr>
  219. <tr class="row_even">
  220. <td><b>'.get_lang('Missing').'</b></td>
  221. <td>'.get_lang('Max').' '.$threadhold3.'</td>
  222. <td><div style="color:'.$missing_color.'">'.(($final_missing < 0)?0:intval($final_missing)).'</div></td>
  223. </tr></table>';
  224. if ($answerType!= HOT_SPOT_DELINEATION) {
  225. $item_list=explode('@@',$destination);
  226. //print_R($item_list);
  227. $try = $item_list[0];
  228. $lp = $item_list[1];
  229. $destinationid= $item_list[2];
  230. $url=$item_list[3];
  231. $table_resume='';
  232. } else {
  233. if ($next==0) {
  234. $try = $try_hotspot;
  235. $lp = $lp_hotspot;
  236. $destinationid= $select_question_hotspot;
  237. $url=$url_hotspot;
  238. } else {
  239. //show if no error
  240. //echo 'no error';
  241. $comment=$answerComment=$objAnswerTmp->selectComment($nbrAnswers);
  242. $answerDestination=$objAnswerTmp->selectDestination($nbrAnswers);
  243. }
  244. }
  245. echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
  246. if ($answerType == HOT_SPOT_DELINEATION) {
  247. if ($organs_at_risk_hit>0) {
  248. $message='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  249. $message.='<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
  250. } else {
  251. $message='<p>'.get_lang('YourDelineation').'</p>';
  252. $message.=$table_resume;
  253. $message.='<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  254. }
  255. $message.='<p>'.$comment.'</p>';
  256. echo $message;
  257. } else {
  258. echo '<p>'.$comment.'</p>';
  259. }
  260. //showing the score
  261. /*
  262. $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  263. $resfree = Database::query($queryfree);
  264. $questionScore= Database::result($resfree,0,"marks");
  265. $totalScore+=$questionScore;*/
  266. ?>
  267. </table>
  268. </td></tr>
  269. <?php
  270. echo '<tr>
  271. <td colspan="2">
  272. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="350">
  273. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" />
  274. </object>
  275. </td>
  276. </tr>
  277. </table>';
  278. }
  279. }
  280. if ($show_results) {
  281. if ($answerType != HOT_SPOT) {
  282. echo '</table>';
  283. }
  284. }
  285. if ($show_results) {
  286. $comnt = get_comments($id, $questionId);
  287. if (!empty($comnt)) {
  288. echo '<b>'.get_lang('Feedback').'</b>';
  289. echo '<div id="question_feedback">'.$comnt.'</div>';
  290. }
  291. }
  292. $my_total_score = $questionScore;
  293. $my_total_weight = $questionWeighting;
  294. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
  295. $my_total_score = 0;
  296. }
  297. if ($show_results) {
  298. echo '<div id="question_score">';
  299. echo get_lang('Score')." : ".show_score($my_total_score, $my_total_weight, false, false);
  300. echo '</div>';
  301. }
  302. unset($objAnswerTmp);
  303. unset($objQuestionTmp);
  304. $i++;
  305. $totalWeighting += $questionWeighting;
  306. } // end of large foreach on questions
  307. }
  308. //Total score
  309. if ($show_results || $show_only_total_score) {
  310. echo '<div id="question_score">'.get_lang('YourTotalScore').": ";
  311. $my_total_score_temp = $totalScore;
  312. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
  313. $my_total_score_temp = 0;
  314. }
  315. echo show_score($my_total_score_temp, $totalWeighting, false);
  316. echo '</div>';
  317. }
  318. if ($show_headers) {
  319. Display::display_footer();
  320. }