exercise_result.php 6.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise result
  5. * This script gets information 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 switchable fill in blank option added
  13. *
  14. * @todo split more code up in functions, move functions to library?
  15. */
  16. use \ChamiloSession as Session;
  17. $debug = false;
  18. require_once '../inc/global.inc.php';
  19. $this_section = SECTION_COURSES;
  20. /* ACCESS RIGHTS */
  21. api_protect_course_script(true);
  22. if ($debug) {
  23. error_log('Entering exercise_result.php: '.print_r($_POST, 1));
  24. }
  25. // general parameters passed via POST/GET
  26. if (empty($origin)) {
  27. $origin = Security::remove_XSS($_REQUEST['origin']);
  28. }
  29. if (empty($objExercise)) {
  30. $objExercise = $_SESSION['objExercise'];
  31. }
  32. if (empty($remind_list)) {
  33. $remind_list = isset($_REQUEST['remind_list']) ? $_REQUEST['remind_list'] : null;
  34. }
  35. $exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;
  36. if (empty($objExercise)) {
  37. // Redirect to the exercise overview
  38. // Check if the exe_id exists
  39. $objExercise = new Exercise();
  40. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  41. if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
  42. header("Location: overview.php?exerciseId=".$exercise_stat_info['exe_exo_id']);
  43. exit;
  44. }
  45. api_not_allowed();
  46. }
  47. $gradebook = '';
  48. if (isset($_SESSION['gradebook'])) {
  49. $gradebook= $_SESSION['gradebook'];
  50. }
  51. if (!empty($gradebook) && $gradebook=='view') {
  52. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook'));
  53. }
  54. $nameTools = get_lang('Exercises');
  55. $interbreadcrumb[]= array("url" => "exercise.php?gradebook=$gradebook","name" => get_lang('Exercises'));
  56. if ($origin != 'learnpath') {
  57. // So we are not in learnpath tool
  58. Display::display_header($nameTools,get_lang('Exercise'));
  59. } else {
  60. Display::display_reduced_header();
  61. }
  62. /* DISPLAY AND MAIN PROCESS */
  63. // I'm in a preview mode as course admin. Display the action menu.
  64. if (api_is_course_admin() && $origin != 'learnpath') {
  65. echo '<div class="actions">';
  66. echo '<a href="admin.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.Display::return_icon('back.png', get_lang('GoBackToQuestionList'), array(), 32).'</a>';
  67. 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>';
  68. echo '</div>';
  69. }
  70. $feedback_type = $objExercise->feedback_type;
  71. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  72. if (!empty($exercise_stat_info['data_tracking'])) {
  73. $question_list = explode(',', $exercise_stat_info['data_tracking']);
  74. }
  75. $learnpath_id = $exercise_stat_info['orig_lp_id'];
  76. $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
  77. $learnpath_item_view_id = $exercise_stat_info['orig_lp_item_view_id'];
  78. if ($origin == 'learnpath') {
  79. ?>
  80. <form method="GET" action="exercise.php?<?php echo api_get_cidreq() ?>">
  81. <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
  82. <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
  83. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  84. <input type="hidden" name="learnpath_item_view_id" value="<?php echo $learnpath_item_view_id; ?>" />
  85. <?php
  86. }
  87. $i = $total_score = $max_score = 0;
  88. //We check if the user attempts before sending to the exercise_result.php
  89. if ($objExercise->selectAttempts() > 0) {
  90. $attempt_count = Event::get_attempt_count(
  91. api_get_user_id(),
  92. $objExercise->id,
  93. $learnpath_id,
  94. $learnpath_item_id,
  95. $learnpath_item_view_id
  96. );
  97. if ($attempt_count >= $objExercise->selectAttempts()) {
  98. Display :: display_warning_message(
  99. sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()),
  100. false
  101. );
  102. if ($origin != 'learnpath') {
  103. //we are not in learnpath tool
  104. Display::display_footer();
  105. }
  106. exit;
  107. }
  108. }
  109. $total_score = 0;
  110. if (!empty($exercise_stat_info)) {
  111. $total_score = $exercise_stat_info['exe_result'];
  112. }
  113. $max_score = $objExercise->get_max_score();
  114. Display :: display_normal_message(get_lang('Saved').'<br />',false);
  115. // Display and save questions
  116. ExerciseLib::display_question_list_by_attempt($objExercise, $exe_id, true);
  117. //Unset session for clock time
  118. ExerciseLib::exercise_time_control_delete(
  119. $objExercise->id,
  120. $learnpath_id,
  121. $learnpath_item_id
  122. );
  123. ExerciseLib::delete_chat_exercise_session($exe_id);
  124. if ($origin != 'learnpath') {
  125. echo '<hr>';
  126. echo Display::url(
  127. get_lang('ReturnToCourseHomepage'),
  128. api_get_course_url(),
  129. array('class' => 'btn btn-primary')
  130. );
  131. if (api_is_allowed_to_session_edit()) {
  132. Session::erase('objExercise');
  133. Session::erase('exe_id');
  134. }
  135. Display::display_footer();
  136. } else {
  137. $lp_mode = isset($_SESSION['lp_mode']) ? $_SESSION['lp_mode'] : null;
  138. $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exercise_stat_info['exe_id'].'&fb_type='.$objExercise->feedback_type;
  139. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'"';
  140. if (api_is_allowed_to_session_edit()) {
  141. Session::erase('objExercise');
  142. Session::erase('exe_id');
  143. }
  144. // Record the results in the learning path, using the SCORM interface (API)
  145. echo "<script>window.parent.API.void_save_asset('$total_score', '$max_score', 0, 'completed');</script>";
  146. echo '<script type="text/javascript">'.$href.'</script>';
  147. echo '</body></html>';
  148. }