Browse Source

Fixing bug when using LP + exercises see #3965

Julio Montoya 13 years ago
parent
commit
e6bbcf83af

+ 3 - 3
main/exercice/exercice.php

@@ -349,7 +349,8 @@ if ($origin != 'learnpath') {
 		}
 	}
 } else {
-	echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
+	//echo '<link rel="stylesheet" type="text/css" href="' . api_get_path(WEB_CODE_PATH) . 'css/default.css"/>';
+	Display :: display_reduced_header();
 }
 
 event_access_tool(TOOL_QUIZ);
@@ -581,8 +582,7 @@ if ($is_allowedToEdit && $origin != 'learnpath') {
                 $filter = 1;
             } else {
             	$filter = 2;
-            } 
-            
+            }
 			echo '<a id="export_opener" href="'.api_get_self().'?export_report=1&show=result&export_filter='.$filter.'&hotpotato_name='.Security::remove_XSS($_GET['path']).'&exerciseId='.intval($_GET['exerciseId']).'" >'.
 				  Display::return_icon('save.png',   get_lang('Export'),'',32).'</a>';			
 		}

+ 6 - 3
main/exercice/exercise.class.php

@@ -3182,8 +3182,7 @@ class Exercise {
 			$email_admin = api_get_setting('emailAdministrator');
 			$subject = get_lang('ExerciseAttempted');
 			$result = @api_mail_html('', $to, $subject, $mail_content, $sender_name, $email_admin, array('charset'=>$mycharset));
-		}
-		var_dump($result);exit;
+		}		
 	}
 
 	function show_exercise_result_header($user_data, $date = null) {
@@ -3303,11 +3302,14 @@ class Exercise {
 		//1. By default the exercise is visible
 		$is_visible = true;
 		
+		
 		//1.1 Admins and teachers can access to the exercise
+		
 		if (api_is_platform_admin() || api_is_course_admin()) {
-			return true;
+			$is_visible = true;
 		}
 		
+		
 		//2. If the exercise is not active 
 		if ($this->active == 0) {
 			return false;
@@ -3347,6 +3349,7 @@ class Exercise {
 			}
 		}
 		
+	
 		return $is_visible;
 	}
 	

+ 96 - 93
main/exercice/exercise_submit.php

@@ -58,18 +58,18 @@ if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
 $htmlHeadXtra[] = api_get_js('jquery.epiclock.min.js');
 
 // General parameters passed via POST/GET
-if (empty ($origin)) {
-    $origin = Security::remove_XSS($_REQUEST['origin']);
-}
-if (empty ($learnpath_id)) {
-    $learnpath_id = intval($_REQUEST['learnpath_id']);
-}
-if (empty ($learnpath_item_id)) {
-    $learnpath_item_id = intval($_REQUEST['learnpath_item_id']);
-}
-if (empty ($learnpath_item_view_id)) {
-    $learnpath_item_view_id = intval($_REQUEST['learnpath_item_view_id']);
-}
+
+$learnpath_id 			= isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0;
+$learnpath_item_id 		= isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0;
+$learnpath_item_view_id	= isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0;
+$origin 				= isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
+
+$reminder 				= isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
+$remind_question_id 	= isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
+
+$exerciseId				= isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
+
+
 if (empty ($formSent)) {
     $formSent = $_REQUEST['formSent'];
 }
@@ -79,28 +79,16 @@ if (empty($exerciseResult)) {
 if (empty ($exerciseResultCoordinates)) {
 	$exerciseResultCoordinates = $_REQUEST['exerciseResultCoordinates'];
 }
-if (empty ($exerciseId)) {
-    $exerciseId = intval($_REQUEST['exerciseId']);
-}
-if (empty($choice)) {	
-    $choice = $_REQUEST['choice'];    
-}
-if (empty($_REQUEST['choice'])) {	
-    $choice = $_REQUEST['choice2'];    
-}
-if (empty ($questionNum)) {
-    $questionNum = intval($_REQUEST['questionNum']);
-}
-if (empty ($current_question)) {
-    $current_question = intval($_REQUEST['num']);
-}
+
+$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
+$choice = empty($choice) ? $_REQUEST['choice2'] : null;
+
+$questionNum				= isset($_REQUEST['questionNum']) ? intval($_REQUEST['questionNum']) : null;
+$current_question			= isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null;
 
 //Error message
 $error = '';
 
-$reminder 			= isset($_GET['reminder']) ? intval($_GET['reminder']) : 0;
-$remind_question_id = isset($_GET['remind_question_id']) ? intval($_GET['remind_question_id']) : 0;
-
 $safe_lp_id             = ($learnpath_id == '')             ? 0 : $learnpath_id;
 $safe_lp_item_id        = ($learnpath_item_id == '')        ? 0 : $learnpath_item_id;
 $safe_lp_item_view_id   = ($learnpath_item_view_id == '')   ? 0 : $learnpath_item_view_id;
@@ -168,16 +156,82 @@ if ($objExercise->expired_time != 0 && $origin != 'learnpath') {
 
 if ($time_control) {
 	//Get the expired time of the current exercice in track_e_exercices
-	$total_seconds 			= $objExercise->expired_time*60;
+	$total_seconds 			  = $objExercise->expired_time*60;
 	
 	//Generating the time control key for the user
 	$current_expired_time_key = generate_time_control_key($objExercise->id);
 }
 
+
+
+
+
+$show_clock = true;
+$user_id = api_get_user_id();
+if ($objExercise->selectAttempts() > 0) {
+	$attempt_html = '';
+	$attempt_count = get_attempt_count($user_id, $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
+
+	if ($attempt_count >= $objExercise->selectAttempts()) {
+		$show_clock = false;
+		if (!api_is_allowed_to_edit(null,true)) {
+
+			if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
+
+				//Showing latest attempt according with task BT#1628
+				$exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
+
+				if (!empty($exercise_stat_info)) {
+					$max_exe_id = max(array_keys($exercise_stat_info));
+					$last_attempt_info = $exercise_stat_info[$max_exe_id];
+					$attempt_html .= Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>''));
+
+					$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
+
+					if (!empty($last_attempt_info['question_list'])) {
+						foreach($last_attempt_info['question_list'] as $question_data) {
+							$question_id = $question_data['question_id'];
+							$marks       = $question_data['marks'];
+
+							$question_info = Question::read($question_id);
+							$attempt_html .= Display::div($question_info->question, array('class'=>'question_title'));
+							$attempt_html .= Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score'));
+						}
+					}
+					$score =  show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
+					$attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
+				} else {
+					$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
+				}
+			} else {
+				$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
+			}
+		} else {
+			$attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
+			//Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exercise_title, $objExercise->selectAttempts()), false);
+		}		
+		
+		if ($origin == 'learnpath') {
+			Display :: display_reduced_header();			
+		} else {
+			Display :: display_header($nameTools,'Exercises');			
+		}
+		
+		echo $attempt_html;
+		if ($origin != 'learnpath')
+			Display :: display_footer();
+		exit;
+	}
+}
+
+
+
 if ($debug) { error_log("4. Setting the exe_id $exe_id");} ;
 
 //5. Getting user exercise info (if the user took the exam before) - generating exe_id
+//var_dump($safe_lp_id.' - '.$safe_lp_item_id.' - '.$safe_lp_item_view_id);
 $exercise_stat_info = $objExercise->get_stat_track_exercise_info($safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
+//var_dump($exercise_stat_info);
 
 if (empty($exercise_stat_info)) {
 	$total_weight = 0;
@@ -479,6 +533,7 @@ if ($question_count != 0) {
 	            
 	            //We check if the user attempts before sending to the exercise_result.php
 	            if ($objExercise->selectAttempts() > 0) {
+	            	
 	                $attempt_count = get_attempt_count(api_get_user_id(), $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);                
 	                if ($attempt_count >= $objExercise->selectAttempts()) {
 	                    Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);                        
@@ -578,53 +633,6 @@ if (!empty($exercise_description)) {
 }
 echo Display::div($exercise_header, array('class'=>'exercise_header'));*/
 
-$show_clock = true;
-$user_id = api_get_user_id();
-if ($objExercise->selectAttempts() > 0) {	
-	$attempt_count = get_attempt_count($user_id, $exerciseId, $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id);
-	
-    if ($attempt_count >= $objExercise->selectAttempts()) {
-    	$show_clock = false;
-        if (!api_is_allowed_to_edit(null,true)) {
-            
-            if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
-                
-                //Showing latest attempt according with task BT#1628
-                $exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
-                
-                if (!empty($exercise_stat_info)) {
-                    $max_exe_id = max(array_keys($exercise_stat_info));
-                    $last_attempt_info = $exercise_stat_info[$max_exe_id];
-                    echo Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>''));
-                    
-                    Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);                    
-                    
-                    if (!empty($last_attempt_info['question_list'])) {               
-                        foreach($last_attempt_info['question_list'] as $question_data) {
-                            $question_id = $question_data['question_id'];
-                            $marks       = $question_data['marks'];
-                            
-                            $question_info = Question::read($question_id);                                                        
-                            echo Display::div($question_info->question, array('class'=>'question_title'));                            
-                            echo Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score'));
-                        }
-                    }                    
-                    $score =  show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
-                    echo Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));                    
-                } else {
-                    Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);	
-                }
-            } else {
-                Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), false);
-            }            
-            if ($origin != 'learnpath')
-                Display :: display_footer();
-            exit;
-        } else {            
-            Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exercise_title, $objExercise->selectAttempts()), false);
-        }
-    }
-}
 
 $limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
 
@@ -782,8 +790,7 @@ if (!empty($error)) {
     echo '<script>
     		
     		$(function() {    		
-    			//$(".exercise_save_now_button").hide();
-    			    			
+    			//$(".exercise_save_now_button").hide();    			    			
     		    $(".main_question").mouseover(function() {
     		    	//$(this).find(".exercise_save_now_button").show();
     		    	//$(this).addClass("question_highlight");
@@ -796,9 +803,8 @@ if (!empty($error)) {
     		});		
 
     		
-			function previous_question(question_num) {
-				lp_data = $.param({"exe_id": '.$exe_id.'});
-				url = "exercise_submit.php?origin='.$origin.'&exerciseId='.$exerciseId.'&num="+question_num+"&" + lp_data;																
+			function previous_question(question_num) {				
+				url = "exercise_submit.php?'.$params.'&num="+question_num;																
 				window.location = url;
 			}
     		
@@ -832,13 +838,13 @@ if (!empty($error)) {
                 }    
                             
            		// Only for the first time
-           		lp_data = $.param({"exe_id": '.$exe_id.'});
+           		
            		
            		
           		$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'");                                
                     $.ajax({ 
                         url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
-                        data: "type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+lp_data+"&"+remind_list,                                 
+                        data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,                                 
                         success: function(return_value) {
                         	if (return_value == "ok") {
                         		$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('accept.png', get_lang('Ok'), array(), 22)).'");
@@ -849,9 +855,9 @@ if (!empty($error)) {
 								if ('.$reminder.' == 1 ) {
                         			url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
 								} else if ('.$reminder.' == 2 ) {
-									url = "exercise_submit.php?origin='.$origin.'&exerciseId='.$exerciseId.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2&" + lp_data;
+									url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
 								} else {
-									url = "exercise_submit.php?origin='.$origin.'&exerciseId='.$exerciseId.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&" + lp_data;
+									url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
 								}								
 								window.location = url;
 								
@@ -890,19 +896,17 @@ if (!empty($error)) {
            		});           		
            		//lok+(fgt)= data base
            		free_answers = $.param(free_answers);				
-           		                 		
-           		lp_data = $.param({"exe_id": '.$exe_id.'});    		
            		
           		$("#save_all_reponse").html("'.addslashes(Display::return_icon('loading1.gif')).'");
           		                             
                 $.ajax({ 
                     url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
-                    data: "type=all&"+my_choice+"&"+hotspot+"&"+lp_data+"&"+free_answers+"&"+remind_list,                                 
+                    data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,                                 
                     success: function(return_value) {
                     	if (return_value == "ok") {                                  
                     		//$("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'");
                     		if (validate == "validate") {
-                            	window.location = "'.$script_php.'?'.$params.'&" + lp_data;
+                            	window.location = "'.$script_php.'?'.$params.'";
                             } else {
                             	$("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'");
                             }
@@ -917,8 +921,7 @@ if (!empty($error)) {
             function validate_all() {
    				save_now_all("validate");
                 return false;
-            }
-            
+            }            
 		</script>';	
 
     echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=" . $exerciseId .'" name="frm_exercise" '.$onsubmit.'>

+ 18 - 11
main/exercice/overview.php

@@ -92,12 +92,17 @@ $html .= $message;
 $exercise_url_button = Display::url($label, $exercise_url, array('class'=>'a_button blue bigger round'));
 
 if (!$objExercise->is_visible($learnpath_id, $learnpath_item_id)) {
-	$exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result&exerciseId='.$objExercise->id;
-	$exercise_url_button = Display::url(get_lang('SeeResults'), $exercise_url, array('class'=>'a_button white bigger round no_link'));
+	$exercise_url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result&exerciseId='.$objExercise->id;	
+	//$exercise_url_button = Display::url(get_lang('SeeResults'), $exercise_url, array('class'=>'a_button white bigger round no_link'));
+	if ($origin == 'learnpath') {
+		$exercise_url_button = Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts()), 'warning');
+	}
+	$exercise_url_button = sprintf(get_lang('ReachedMaxAttempts'), $objExercise->title, $objExercise->selectAttempts());
 }
-
 $options  = Display::div('', array('class'=>'left_option'));
-$options .= Display::div($exercise_url_button, array('class'=>'center_option'));
+if (!empty($exercise_url_button)) {
+	$options .= Display::div($exercise_url_button, array('class'=>'center_option'));
+}
 
 $attempts = get_exercise_results_by_user(api_get_user_id(), $objExercise->id, api_get_course_id(), api_get_session_id(), $learnpath_id, $learnpath_item_id);
 
@@ -175,14 +180,16 @@ if (!empty($attempts)) {
 
 if ($objExercise->selectAttempts()) {
 	if ($is_allowed_to_edit) {
-		$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
-	} else {
-		$red_class = '';
-		if ($counter == $objExercise->selectAttempts()) {
-			$class = 'red_alert';
-		}
-		$options.= Display::div(get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts(), array('class'=>"right_option $class"));
+		//$options.= Display::div(get_lang('ExerciseAttempts').' '.$objExercise->selectAttempts(), array('class'=>'right_option'));
+	} else {		
 	}
+	
+	$red_class = '';
+	if ($counter == $objExercise->selectAttempts()) {
+		$class = 'red_alert';
+	}
+	$options.= Display::div(get_lang('Attempts').' '.$counter.' / '.$objExercise->selectAttempts(), array('class'=>"right_option $class"));
+	
 }
 if ($time_control) {
 	$html.=  '<div align="left" id="wrapper-clock"><div id="square" class="rounded"><div id="text-content" align="center" class="count_down"></div></div></div>';

+ 1 - 1
main/inc/ajax/exercise.ajax.php

@@ -173,7 +173,7 @@ switch ($action) {
             	  	
                 $total_score     += $result['score'];    
               	
-                update_event_exercice($exe_id, $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $safe_lp_id, $safe_lp_item_id, $safe_lp_item_view_id, $quizDuration, $question_list, 'incomplete', $remind_list);
+                update_event_exercice($exe_id, $objExercise->selectId(), $total_score, $total_weight, api_get_session_id(), $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id'], $exercise_stat_info['orig_lp_item_view_id'], $exercise_stat_info['exe_duration'], $question_list, 'incomplete', $remind_list);
                 
                  // Destruction of the Question object
             	unset($objQuestionTmp); 

+ 12 - 10
main/inc/lib/events.lib.inc.php

@@ -738,25 +738,27 @@ function get_attempt_count($user_id, $exerciseId, $lp_id, $lp_item_id,$lp_item_v
 	$lp_item_id 	= intval($lp_item_id);
     $lp_item_view_id= intval($lp_item_view_id);
 	
-   	$sql = "SELECT count(*) as count FROM $stat_table WHERE 	
-   				exe_exo_id 			= '$exerciseId' AND 
-   				exe_user_id 		= '$user_id' AND
-   				status 				!= 'incomplete' AND 
-   				orig_lp_id 			= $lp_id AND 
-   				orig_lp_item_id 	= $lp_item_id AND 
-   				orig_lp_item_view_id = $lp_item_view_id AND 
-   				exe_cours_id = '".api_get_course_id()."' AND 
-   				session_id = '" . api_get_session_id() . "'";
+    $sql = "SELECT count(*) as count FROM $stat_table WHERE 	
+   				exe_exo_id 				= $exerciseId AND 
+   				exe_user_id 			= $user_id AND
+   				status 			   	   != 'incomplete' AND 
+   				orig_lp_id 				= $lp_id AND 
+   				orig_lp_item_id 		= $lp_item_id AND 
+   				orig_lp_item_view_id 	= $lp_item_view_id AND 
+   				exe_cours_id 			= '".api_get_course_id()."' AND 
+   				session_id 				= '" . api_get_session_id() . "'";
 
     $query = Database::query($sql);
     if (Database::num_rows($query) > 0 ) {
-    	$attempt = Database :: fetch_array($query,'ASSOC');
+    	$attempt = Database :: fetch_array($query,'ASSOC');    	
     	return $attempt['count'];
     } else {
     	return 0; 
     } 
 }
 
+
+
 function get_attempt_count_not_finished($user_id, $exerciseId, $lp_id, $lp_item_id) {
 	$stat_table 	= Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
 	$user_id 		= intval($user_id);

+ 7 - 6
main/newscorm/lp_view.php

@@ -172,6 +172,7 @@ if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp
     $safe_item_id           = Database::escape_string($_GET['lp_item_id']);
     $safe_id                = $lp_id;
     $safe_exe_id            = intval($_REQUEST['exeId']);
+    $course_id 				= api_get_course_int_id();
 
     if ($safe_id == strval(intval($safe_id)) && $safe_item_id == strval(intval($safe_item_id))) {
 		
@@ -190,13 +191,13 @@ if ($type_quiz && !empty($_REQUEST['exeId']) && isset($lp_id) && isset($_GET['lp
         if ($debug) error_log($sql_upd_max_score);
         Database::query($sql_upd_max_score);
 
-        $sql_last_attempt = "SELECT id FROM $TBL_LP_ITEM_VIEW  WHERE lp_item_id = '$safe_item_id' AND lp_view_id = '".$_SESSION['oLP']->lp_view_id."' order by id desc limit 1";
+        $sql_last_attempt = "SELECT id FROM $TBL_LP_ITEM_VIEW  WHERE c_id = $course_id AND lp_item_id = '$safe_item_id' AND lp_view_id = '".$_SESSION['oLP']->lp_view_id."' order by id desc limit 1";
         $res_last_attempt = Database::query($sql_last_attempt);
-        $row_last_attempt = Database::fetch_row($res_last_attempt);
-        $lp_item_view_id = $row_last_attempt[0];
-
-        if (Database::num_rows($res_last_attempt) > 0) {
-            $sql_upd_score = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' , score = $score, total_time = $mytime WHERE id='".$lp_item_view_id."'";
+        
+        if (Database::num_rows($res_last_attempt)) {
+        	$row_last_attempt = Database::fetch_row($res_last_attempt);
+        	$lp_item_view_id  = $row_last_attempt[0];
+            $sql_upd_score = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' , score = $score, total_time = $mytime WHERE id='".$lp_item_view_id."' AND c_id = $course_id ";
             if ($debug) error_log($sql_upd_score);
             Database::query($sql_upd_score);