exercise_result.php 7.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197
  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 Armas 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. require_once 'exercise.class.php';
  18. require_once 'question.class.php';
  19. require_once 'answer.class.php';
  20. // Name of the language file that needs to be included
  21. $language_file = 'exercice';
  22. require_once '../inc/global.inc.php';
  23. require_once 'exercise.lib.php';
  24. if ($_GET['origin']=='learnpath') {
  25. require_once '../newscorm/learnpath.class.php';
  26. require_once '../newscorm/learnpathItem.class.php';
  27. require_once '../newscorm/scorm.class.php';
  28. require_once '../newscorm/scormItem.class.php';
  29. require_once '../newscorm/aicc.class.php';
  30. require_once '../newscorm/aiccItem.class.php';
  31. }
  32. require_once api_get_path(LIBRARY_PATH).'exercise_show_functions.lib.php';
  33. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  34. $this_section = SECTION_COURSES;
  35. /* ACCESS RIGHTS */
  36. api_protect_course_script(true);
  37. if ($debug) {
  38. error_log('Entering exercise_result.php: '.print_r($_POST, 1));
  39. }
  40. // general parameters passed via POST/GET
  41. if (empty($origin)) {
  42. $origin = Security::remove_XSS($_REQUEST['origin']);
  43. }
  44. if (empty($objExercise)) {
  45. $objExercise = $_SESSION['objExercise'];
  46. }
  47. if (empty($remind_list)) {
  48. $remind_list = isset($_REQUEST['remind_list']) ? $_REQUEST['remind_list'] : null;
  49. }
  50. $exe_id = isset($_REQUEST['exe_id']) ? intval($_REQUEST['exe_id']) : 0;
  51. if (empty($objExercise)) {
  52. // Redirect to the exercise overview
  53. // Check if the exe_id exists
  54. $objExercise = new Exercise();
  55. $exercise_stat_info = $objExercise->get_stat_track_exercise_info_by_exe_id($exe_id);
  56. if (!empty($exercise_stat_info) && isset($exercise_stat_info['exe_exo_id'])) {
  57. header("Location: overview.php?exerciseId=".$exercise_stat_info['exe_exo_id']);
  58. exit;
  59. }
  60. api_not_allowed();
  61. }
  62. $gradebook = '';
  63. if (isset($_SESSION['gradebook'])) {
  64. $gradebook= $_SESSION['gradebook'];
  65. }
  66. if (!empty($gradebook) && $gradebook=='view') {
  67. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook'));
  68. }
  69. $nameTools = get_lang('Exercice');
  70. $interbreadcrumb[]= array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  71. if ($origin != 'learnpath') {
  72. // So we are not in learnpath tool
  73. Display::display_header($nameTools,get_lang('Exercise'));
  74. } else {
  75. $htmlHeadXtra[] = "
  76. <style>
  77. body { background: none;}
  78. </style>
  79. ";
  80. Display::display_reduced_header();
  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->feedback_type;
  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. $learnpath_id = $exercise_stat_info['orig_lp_id'];
  96. $learnpath_item_id = $exercise_stat_info['orig_lp_item_id'];
  97. $learnpath_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 $learnpath_id; ?>" />
  103. <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
  104. <input type="hidden" name="learnpath_item_view_id" value="<?php echo $learnpath_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(
  111. api_get_user_id(),
  112. $objExercise->id,
  113. $learnpath_id,
  114. $learnpath_item_id,
  115. $learnpath_item_view_id
  116. );
  117. if ($attempt_count >= $objExercise->selectAttempts()) {
  118. Display :: display_warning_message(
  119. sprintf(get_lang('ReachedMaxAttempts'), $objExercise->selectTitle(), $objExercise->selectAttempts()),
  120. false
  121. );
  122. if ($origin != 'learnpath') {
  123. //we are not in learnpath tool
  124. Display::display_footer();
  125. }
  126. exit;
  127. }
  128. }
  129. Display :: display_normal_message(get_lang('Saved').'<br />',false);
  130. // Display and save questions
  131. display_question_list_by_attempt($objExercise, $exe_id, true);
  132. //If is not valid
  133. /*
  134. $session_control_key = get_session_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  135. if (isset($session_control_key) && !exercise_time_control_is_valid($objExercise->id, $learnpath_id, $learnpath_item_id)) {
  136. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  137. $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks = 0, position = 0 WHERE exe_id = $exe_id ";
  138. Database::query($sql_fraud);
  139. }*/
  140. //Unset session for clock time
  141. exercise_time_control_delete($objExercise->id, $learnpath_id, $learnpath_item_id);
  142. delete_chat_exercise_session($exe_id);
  143. if ($origin != 'learnpath') {
  144. echo '<hr>';
  145. echo Display::url(get_lang('ReturnToCourseHomepage'), api_get_course_url(), array('class' => 'btn btn-large'));
  146. if (api_is_allowed_to_session_edit()) {
  147. Session::erase('objExercise');
  148. Session::erase('exe_id');
  149. }
  150. Display::display_footer();
  151. } else {
  152. $lp_mode = isset($_SESSION['lp_mode']) ? $_SESSION['lp_mode'] : null;
  153. $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;
  154. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'"';
  155. if (api_is_allowed_to_session_edit()) {
  156. Session::erase('objExercise');
  157. Session::erase('exe_id');
  158. }
  159. // Record the results in the learning path, using the SCORM interface (API)
  160. echo "<script>window.parent.API.void_save_asset('$total_score', '$total_weight', 0, 'completed');</script>";
  161. echo '<script type="text/javascript">'.$href.'</script>';
  162. echo '</body></html>';
  163. }