Browse Source

Adding attempt message in result.php see BT#11539

jmontoyaa 8 years ago
parent
commit
6a07743a4a
3 changed files with 31 additions and 16 deletions
  1. 8 2
      main/exercise/exercise_result.php
  2. 2 2
      main/exercise/overview.php
  3. 21 12
      main/exercise/result.php

+ 8 - 2
main/exercise/exercise_result.php

@@ -124,6 +124,7 @@ if ($origin == 'learnpath') {
 }
 
 $i = $total_score = $max_score = 0;
+$remainingMessage = '';
 
 //We check if the user attempts before sending to the exercise_result.php
 if ($objExercise->selectAttempts() > 0) {
@@ -152,15 +153,18 @@ if ($objExercise->selectAttempts() > 0) {
             $attemptButton = Display::toolbarButton(
                 get_lang('AnotherAttempt'),
                 api_get_path(WEB_CODE_PATH) . 'exercise/overview.php?' . api_get_cidreq() . '&' . http_build_query([
-                    'exerciseId' => $objExercise->id
+                    'exerciseId' => $objExercise->id,
+                    'learnpath_id' => $learnpath_id,
+                    'learnpath_item_id' => $learnpath_item_id
                 ]),
                 'pencil-square-o',
                 'info'
             );
             $attemptMessage = sprintf(get_lang('RemainingXAttempts'), $remainingAttempts);
+            $remainingMessage = sprintf("<p>%s</p> %s", $attemptMessage, $attemptButton);
 
             Display::display_normal_message(
-                sprintf("<p>%s</p> %s", $attemptMessage, $attemptButton),
+                $remainingMessage,
                 false
             );
         }
@@ -212,6 +216,8 @@ if ($origin != 'learnpath') {
         Session::erase('exe_id');
     }
 
+    Session::write('attempt_remaining', $remainingMessage);
+
 	// Record the results in the learning path, using the SCORM interface (API)
 	echo "<script>window.parent.API.void_save_asset('$total_score', '$max_score', 0, 'completed');</script>";
     echo '<script type="text/javascript">'.$href.'</script>';

+ 2 - 2
main/exercise/overview.php

@@ -33,7 +33,7 @@ if (!$result) {
 $gradebook = isset($_GET['gradebook']) ? Security :: remove_XSS($_GET['gradebook']) : null;
 $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : null;
 $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : null;
-$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : null;
+$origin = api_get_origin();
 
 $interbreadcrumb[] = array("url" => "exercise.php?gradebook=$gradebook", "name" => get_lang('Exercises'));
 $interbreadcrumb[] = array("url" => "#", "name" => $objExercise->name);
@@ -302,7 +302,7 @@ if ($objExercise->selectAttempts()) {
         $attempt_message = Display::return_message($attempt_message, 'info');
     }
     if ($visible_return['value'] == true) {
-        $message .=   $attempt_message;
+        $message .= $attempt_message;
     }
 }
 

+ 21 - 12
main/exercise/result.php

@@ -1,6 +1,8 @@
 <?php
 /* For licensing terms, see /license.txt */
 
+use ChamiloSession as Session;
+
 /**
  * Shows the exercise results
  *
@@ -17,13 +19,13 @@ $id = isset($_REQUEST['id']) ? intval($_GET['id']) : null; //exe id
 $show_headers = isset($_REQUEST['show_headers']) ? intval($_REQUEST['show_headers']) : null; //exe id
 
 if ($origin == 'learnpath') {
-	$show_headers = false;
+    $show_headers = false;
 }
 
 api_protect_course_script($show_headers);
 
 if (empty($id)) {
-	api_not_allowed($show_headers);
+    api_not_allowed($show_headers);
 }
 
 $is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor;
@@ -49,7 +51,7 @@ if (!empty($exercise_id)) {
 // Only users can see their own results
 if (!$is_allowedToEdit) {
     if ($student_id != $current_user_id) {
-    	api_not_allowed($show_headers);
+        api_not_allowed($show_headers);
     }
 }
 
@@ -59,22 +61,29 @@ $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'hotspot
 if ($show_headers) {
     $interbreadcrumb[] = array(
         "url" => "exercise.php?".api_get_cidreq(),
-        "name" => get_lang('Exercises'),
+        "name" => get_lang('Exercises')
     );
     $interbreadcrumb[] = array("url" => "#", "name" => get_lang('Result'));
-	$this_section = SECTION_COURSES;
-	Display::display_header();
+    $this_section = SECTION_COURSES;
+    Display::display_header();
 } else {
-    $htmlHeadXtra[] = "
-    <style>
-    body { background: none;}
-    </style>
-    ";
+    $htmlHeadXtra[] = '<style>
+        body { background: none;}
+    </style>';
 	Display::display_reduced_header();
 }
 
+$message = Session::read('attempt_remaining');
+if (!empty($message)) {
+    Display::display_normal_message(
+        $message,
+        false
+    );
+}
+Session::erase('attempt_remaining');
+
 ExerciseLib::display_question_list_by_attempt($objExercise, $id, false);
 
 if ($show_headers) {
-	Display::display_footer();
+    Display::display_footer();
 }