exercise_result.php 9.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise result
  5. * This script gets informations from the script "exercise_submit.php",
  6. * through the session, and calculates the score of the student for
  7. * that exercise.
  8. * Then it shows the results on the screen.
  9. * @package chamilo.exercise
  10. * @author Olivier Brouckaert, main author
  11. * @author Roan Embrechts, some refactoring
  12. * @author Julio Montoya Armas switchable fill in blank option added
  13. *
  14. * @todo split more code up in functions, move functions to library?
  15. */
  16. /**
  17. * Code
  18. */
  19. require_once 'exercise.class.php';
  20. require_once 'question.class.php';
  21. require_once 'answer.class.php';
  22. // Name of the language file that needs to be included
  23. $language_file = 'exercice';
  24. require_once '../inc/global.inc.php';
  25. require_once 'exercise.lib.php';
  26. if ($_GET['origin']=='learnpath') {
  27. require_once '../newscorm/learnpath.class.php';
  28. require_once '../newscorm/learnpathItem.class.php';
  29. require_once '../newscorm/scorm.class.php';
  30. require_once '../newscorm/scormItem.class.php';
  31. require_once '../newscorm/aicc.class.php';
  32. require_once '../newscorm/aiccItem.class.php';
  33. }
  34. require_once api_get_path(LIBRARY_PATH).'exercise_show_functions.lib.php';
  35. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  36. $this_section = SECTION_COURSES;
  37. /* ACCESS RIGHTS */
  38. api_protect_course_script(true);
  39. // Database table definitions
  40. $main_admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  41. if($debug>0){error_log('Entered exercise_result.php: '.print_r($_POST,1));}
  42. // general parameters passed via POST/GET
  43. if ( empty ( $origin ) ) { $origin = Security::remove_XSS($_REQUEST['origin']);}
  44. if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];}
  45. if ( empty ( $remind_list ) ) { $remind_list = $_REQUEST['remind_list'];}
  46. $exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;
  47. if (empty($objExercise)) {
  48. //Redirect to the exercise overview
  49. //Check if the exe_id exists
  50. $objExercise = new Exercise();
  51. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  52. if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
  53. header("Location: overview.php?exerciseId=".$exercise_stat_info['exe_exo_id']);
  54. exit;
  55. }
  56. api_not_allowed();
  57. }
  58. $gradebook = '';
  59. if (isset($_SESSION['gradebook'])) {
  60. $gradebook= $_SESSION['gradebook'];
  61. }
  62. if (!empty($gradebook) && $gradebook=='view') {
  63. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook'));
  64. }
  65. $nameTools = get_lang('Exercice');
  66. $interbreadcrumb[]= array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  67. if ($origin != 'learnpath') {
  68. //so we are not in learnpath tool
  69. Display::display_header($nameTools,get_lang('Exercise'));
  70. } else {
  71. Display::display_reduced_header();
  72. }
  73. //Hide results
  74. $show_results = false;
  75. $show_only_score = false;
  76. if ($objExercise->results_disabled == 0) {
  77. $show_results = true;
  78. }
  79. if ($objExercise->results_disabled == 2) {
  80. $show_only_score = true;
  81. }
  82. /* DISPLAY AND MAIN PROCESS */
  83. // I'm in a preview mode as course admin. Display the action menu.
  84. if (api_is_course_admin() && $origin != 'learnpath') {
  85. echo '<div class="actions">';
  86. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).'</a>';
  87. echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.Display::return_icon('edit.png', get_lang('ModifyExercise'), array(), 32).'</a>';
  88. echo '</div>';
  89. }
  90. $feedback_type = $objExercise->feedbacktype;
  91. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  92. if (!empty($exercise_stat_info['data_tracking'])) {
  93. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  94. }
  95. $safe_lp_id = $exercise_stat_info['orig_lp_id'];
  96. $safe_lp_item_id = $exercise_stat_info['orig_lp_item_id'];
  97. $safe_lp_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
  98. if ($origin == 'learnpath') {
  99. ?>
  100. <form method="get" action="exercice.php?<?php echo api_get_cidreq() ?>">
  101. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  102. <input type="hidden" name="learnpath_id" value="<?php echo $safe_lp_id; ?>" />
  103. <input type="hidden" name="learnpath_item_id" value="<?php echo $safe_lp_item_id; ?>" />
  104. <input type="hidden" name="learnpath_item_view_id" value="<?php echo $safe_lp_item_view_id; ?>" />
  105. <?php
  106. }
  107. $i = $total_score = $total_weight = 0;
  108. //We check if the user attempts before sending to the exercise_result.php
  109. if ($objExercise->selectAttempts() > 0) {
  110. $attempt_count = get_attempt_count(api_get_user_id(), $objExercise->id, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
  111. if ($attempt_count >= $objExercise->selectAttempts()) {
  112. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()), false);
  113. if ($origin != 'learnpath') {
  114. //we are not in learnpath tool
  115. Display::display_footer();
  116. }
  117. exit;
  118. }
  119. }
  120. $user_info = api_get_user_info(api_get_user_id());
  121. if ($show_results || $show_only_score) {
  122. echo $exercise_header = $objExercise->show_exercise_result_header(api_get_person_name($user_info['firstName'], $user_info['lastName']));
  123. }
  124. Display :: display_confirmation_message(get_lang('Saved').'<br />',false);
  125. // Display text when test is finished #4074
  126. $end_of_message = $objExercise->selectTextWhenFinished();
  127. if (!empty($end_of_message)) {
  128. Display::display_message($end_of_message);
  129. echo "<div class='clear'>&nbsp;</div>";
  130. }
  131. $counter = 1;
  132. // Loop over all question to show results for each of them, one by one
  133. if (!empty($question_list)) {
  134. foreach ($question_list as $questionId) {
  135. // destruction of the Question object
  136. unset($objQuestionTmp);
  137. // gets the student choice for this question
  138. $choice = $exerciseResult[$questionId];
  139. // creates a temporary Question object
  140. $objQuestionTmp = Question :: read($questionId);
  141. //this variable commes from exercise_submit_modal.php
  142. //$hotspot_delineation_result = $_SESSION['hotspot_delineation_result'][$objExercise->selectId()][$quesId];
  143. if ($show_results) {
  144. // show category
  145. Testcategory::displayCategoryAndTitle($objQuestionTmp->id);
  146. // show titles
  147. echo $objQuestionTmp->return_header($objExercise->feedback_type, $counter);
  148. $counter++;
  149. }
  150. // We're inside *one* question. Go through each possible answer for this question
  151. $result = $objExercise->manage_answer($exercise_stat_info['exe_id'], $questionId, null ,'exercise_result', array(), false, true, $show_results, $objExercise->selectPropagateNeg(), $hotspot_delineation_result);
  152. $total_score += $result['score'];
  153. $total_weight += $result['weight'];
  154. } // end foreach() block that loops over all questions
  155. }
  156. if ($origin != 'learnpath') {
  157. if ($show_results || $show_only_score) {
  158. echo '<div id="question_score">';
  159. echo get_lang('YourTotalScore')." ";
  160. if ($objExercise->selectPropagateNeg() == 0 && $total_score < 0) {
  161. $total_score = 0;
  162. }
  163. echo show_score($total_score, $total_weight, false);
  164. echo '</div>';
  165. }
  166. /* <button type="submit" class="save"><?php echo get_lang('Finish');?></button> */
  167. }
  168. // Tracking of results
  169. // Updates the empty exercise
  170. $quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
  171. $feed = $objExercise->feedbacktype;
  172. if (api_is_allowed_to_session_edit()) {
  173. update_event_exercice($exercise_stat_info['exe_id'], $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quiz_duration, $question_list, '');
  174. }
  175. //If is not valid
  176. $session_control_key = get_session_time_control_key($objExercise->id);
  177. if (isset($session_control_key) && !exercise_time_control_is_valid($objExercise->id)) {
  178. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  179. $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position=0 WHERE exe_id = $exe_id ";
  180. Database::query($sql_fraud);
  181. }
  182. //Unset session for clock time
  183. exercise_time_control_delete($objExercise->id);
  184. if ($origin != 'learnpath') {
  185. Display::display_footer();
  186. } else {
  187. $lp_mode = $_SESSION['lp_mode'];
  188. $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$safe_lp_id.'&lp_item_id='.$safe_lp_item_id.'&exeId='.$exercise_stat_info['exe_id'].'&fb_type='.$feed;
  189. //echo $total_score.','.$total_weight; exit;
  190. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  191. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  192. //record the results in the learning path, using the SCORM interface (API)
  193. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$total_score.','.$total_weight.');</script>'."\n";
  194. echo '</body></html>';
  195. }
  196. // Send notification..
  197. if (!api_is_allowed_to_edit(null,true)) {
  198. $objExercise->send_notification($arrques, $arrans, $origin);
  199. }
  200. if (api_is_allowed_to_session_edit()) {
  201. api_session_unregister('objExercise');
  202. api_session_unregister('exe_id');
  203. }