소스 검색

[svn r17605] Logic Changes - Fixed bug founded in learning path score and when you display a exercise item should show check icon when the exercise is over see FS#3427

Cristian Fasanando 16 년 전
부모
커밋
53cd7b0f26

+ 15 - 3
main/exercice/exercice.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice.php 17516 2009-01-02 22:46:25Z iflorespaz $
+<?php // $Id: exercice.php 17605 2009-01-08 22:29:28Z cfasanando $
 
 /*
 ==============================================================================
@@ -80,6 +80,8 @@ $TBL_TRACK_EXERCICES	= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXE
 $TBL_TRACK_HOTPOTATOES	= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTPOTATOES);
 $TBL_TRACK_ATTEMPT		= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
 $TBL_TRACK_ATTEMPT_RECORDING = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT_RECORDING);
+$TBL_LP_ITEM_VIEW		= Database::get_course_table (TABLE_LP_ITEM_VIEW);
+$TBL_LP_VIEW			= Database::get_course_table (TABLE_LP_VIEW);
 
 // document path
 $documentPath= api_get_path(SYS_COURSE_PATH).$_course['path']."/document";
@@ -268,7 +270,17 @@ api_mail_html($emailid, $emailid, $subject, $mess, $from_name, $from);
 
 
 if (in_array($origin, array('tracking_course','user_course'))){
-		//Redirect to the reporting
+		// update score  when you qualify the exercises in Learning path detail
+		if (isset($_REQUEST['lp_item_id']) && isset($_REQUEST['lp_item_view_id']) && isset($_REQUEST['student_id']) && isset($_REQUEST['total_score'])) {
+			$lp_item_id = Security::remove_XSS($_REQUEST['lp_item_id']);
+			$lp_item_view_id = Security::remove_XSS($_REQUEST['lp_item_view_id']);
+			$student_id = Security::remove_XSS($_REQUEST['student_id']);
+			$score = Security::remove_XSS($_REQUEST['total_score']);			
+			$sql = "UPDATE $TBL_LP_ITEM_VIEW SET score = '$score' WHERE lp_item_id = '$lp_item_id'
+					AND lp_view_id = (SELECT id from $TBL_LP_VIEW  WHERE user_id = '$student_id' and lp_id='$lp_item_view_id')";
+			api_sql_query($sql,__FILE__,__LINE__);	
+		}
+		//Redirect to the reporting		
 		header('location: ../mySpace/myStudents.php?origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['course']);
 	}
 }
@@ -787,7 +799,7 @@ $eid = $row['id'];
 $uid= api_get_user_id();
 //this query might be improved later on by ordering by the new "tms" field rather than by exe_id
 $qry = "SELECT * FROM $TBL_TRACK_EXERCICES " .
-		   "WHERE exe_exo_id = '".Database::escape_string($eid)."' and exe_user_id = '".Database::escape_string($uid)."' AND exe_cours_id = '".api_get_course_id()."' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id =  '".api_get_session_id()."' ORDER BY exe_id DESC";
+		   "WHERE exe_exo_id = '".Database::escape_string($eid)."' and exe_user_id = '".Database::escape_string($uid)."' AND exe_cours_id = '".api_get_course_id()."' AND status <>'incomplete' AND orig_lp_id = 0 AND orig_lp_item_id = 0 AND session_id =  '".api_get_session_id()."' ORDER BY exe_id DESC";
 	$qryres = api_sql_query($qry);
 	$num = Database::num_rows($qryres);
     if ($num>0) {

+ 5 - 6
main/exercice/exercice_submit.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice_submit.php 17484 2008-12-30 21:47:26Z cfasanando $
+<?php // $Id: exercice_submit.php 17605 2009-01-08 22:29:28Z cfasanando $
 
 /*
 ==============================================================================
@@ -42,7 +42,7 @@
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
 * 	@author Julio Montoya multiple fill in blank option added
-* 	@version $Id: exercice_submit.php 17484 2008-12-30 21:47:26Z cfasanando $
+* 	@version $Id: exercice_submit.php 17605 2009-01-08 22:29:28Z cfasanando $
 */
 
 
@@ -575,7 +575,7 @@ if ($formSent) {
 	    } else {
         	//clean incomplete
         	api_sql_query('UPDATE '.$stat_table.' SET '."status = '', data_tracking='', exe_date = '".date('Y-m-d H:i:s')."'".' WHERE exe_id = '.$exe_id,__FILE__,__LINE__);
-        	header("Location: exercise_show.php?id=$exeId");
+        	header("Location: exercise_show.php?id=$exeId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
         }
         exit();
     }
@@ -1016,7 +1016,7 @@ else
 	  }
 	  //$s.='\'&gt;';
 	  $s.= '\' />';
-	  $s.="</td></tr></form></table>";
+	  $s.="</td></tr></table></form>";
 
 	$b=2;
 	echo $s;
@@ -1037,5 +1037,4 @@ else
 
 if ($origin != 'learnpath') { //so we are not in learnpath tool
     Display::display_footer();
-}
-?>
+}

+ 6 - 5
main/exercice/exercise_result.php

@@ -29,7 +29,7 @@
 *	@author Olivier Brouckaert, main author
 *	@author Roan Embrechts, some refactoring
 * 	@author Julio Montoya Armas switchable fill in blank option added
-* 	@version $Id: exercise_result.php 17484 2008-12-30 21:47:26Z cfasanando $
+* 	@version $Id: exercise_result.php 17605 2009-01-08 22:29:28Z cfasanando $
 *
 *	@todo	split more code up in functions, move functions to library?
 */
@@ -1057,13 +1057,14 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 		<td>
 		<br />
 			<?php
-			if ($origin != 'learnpath')
-			{
+			if ($origin != 'learnpath') {
 			?>
 			<input type="submit" value="<?php echo get_lang('Finish'); ?>" />
 			<?php
-			}
-			?>
+			} else {							
+			?>							
+				<input type="button" onclick="top.location.href='../newscorm/lp_controller.php?cidReq=<?php echo api_get_course_id()?>&amp;action=view&amp;lp_id=<?php echo $learnpath_id ?>&amp;lp_item_id=<?php echo $learnpath_item_id ?>'" value="<?php echo get_lang('Finish'); ?>" />
+			<?php }?>
 		</td>
 		</tr>
 		</table>

+ 47 - 20
main/exercice/exercise_show.php

@@ -128,8 +128,9 @@ else {
 	$this_section=SECTION_COURSES;
 }
 
-Display::display_header($nameTools,"Exercise");
-
+if ($origin != 'learnpath') {
+	Display::display_header($nameTools,"Exercise");
+}
 $emailId = $_REQUEST['email'];
 $user_name = $_REQUEST['user'];
 $test 	   = $_REQUEST['test'];
@@ -251,7 +252,7 @@ function display_fill_in_blanks_answer($answer,$id,$questionId)
 		<td>
 			<?php echo nl2br($answer); ?>
 		</td><?php
-		if(!$is_allowedToEdit) {?>
+		if(!api_is_allowed_to_edit()) {?>
 		<td>
 		<?php
 		$comm = get_comments($id,$questionId);
@@ -274,7 +275,7 @@ function display_free_answer($answer,$id,$questionId)
 		<tr>
 		<td>
 			<?php echo nl2br(stripslashes($answer)); ?>
-		</td> <?php if(!$is_allowedToEdit) {?>
+		</td> <?php if(!api_is_allowed_to_edit()) {?>
    <td>
     <?php
 
@@ -344,9 +345,9 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme
 	<?php
 		$sql_test_name='SELECT title, description FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
 		$result=api_sql_query($sql_test_name);
-		$test=mysql_result($result,0,0);
+		$test=Database::result($result,0,0);
 		$exerciseTitle=api_parse_tex($test);
-		$exerciseDexcription=mysql_result($result,0,1);
+		$exerciseDexcription=Database::result($result,0,1);
 
 $user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($_user['user_id'])." ";
 $query = "select attempts.question_id, answer  from ".$TBL_TRACK_ATTEMPT." as attempts  
@@ -1013,24 +1014,50 @@ $totalWeighting+=$questionWeighting;
 	<tr>
 		<td align="left">
 		<br />
-		<?php $strids = implode(",",$arrid);
-			$marksid = implode(",",$arrmarks);
+		<?php 
+			if (is_array($arrid) && is_array($arrmarks)) {
+				$strids = implode(",",$arrid);
+				$marksid = implode(",",$arrmarks);
+			}
 			if($is_allowedToEdit)
 			{
 		?>
 		
-		<?php
-			if(in_array($origin, array('tracking_course','user_course'))){
-				echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['cidReq'].'" method="post">';
-			}
-			else{
-				echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'" method="post">';
-			}
-		?>
-			
-			 <input type="submit" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"/>
-			 </form>
-		<?php } ?>
+				<?php
+					if (in_array($origin, array('tracking_course','user_course'))) {
+						echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['cidReq'].'" method="post">';
+						if (isset($_GET['myid']) && isset($_GET['my_lp_id']) && isset($_GET['student'])) {
+				?>
+						<input type = "hidden" name="lp_item_id" value="<?php echo Security::remove_XSS($_GET['myid']); ?>">
+						<input type = "hidden" name="lp_item_view_id" value="<?php echo Security::remove_XSS($_GET['my_lp_id']); ?>">
+						<input type = "hidden" name="student_id" value="<?php echo Security::remove_XSS($_GET['student']);?>">
+						<input type = "hidden" name="total_score" value="<?php echo $totalScore; ?>">
+				<?php		
+						}
+					} else {
+						echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'" method="post">';
+					}
+					
+					if ($origin!='learnpath' && $origin!='student_progress') {
+				?>					
+					 <input type="submit" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"/>
+					 </form>
+				<?php }
+		 	}  		
+			if ($origin=='learnpath' || $origin=='student_progress') {?>							
+				<input type="button" onclick="top.location.href='../newscorm/lp_controller.php?cidReq=<?php echo api_get_course_id()?>&amp;action=view&amp;lp_id=<?php echo $learnpath_id ?>&amp;lp_item_id=<?php echo $learnpath_item_id ?>'" value="<?php echo get_lang('Finish'); ?>" />
+			<?php }?>
 		</td>
 		</tr>
 </table>
+<?php
+if ($origin != 'learnpath')
+{
+	//we are not in learnpath tool
+	Display::display_footer();
+}else{
+	//record the results in the learning path, using the SCORM interface (API)
+	echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
+	echo '</body></html>';
+}
+?>

+ 18 - 1
main/newscorm/learnpath.class.php

@@ -2477,6 +2477,7 @@ class learnpath {
 				'level'=>$this->items[$item_id]->get_level(),
 				'type' =>$this->items[$item_id]->get_type(),
 				'description'=>$this->items[$item_id]->get_description(),
+				'path'=>$this->items[$item_id]->get_path(),
 				);
     	}
     	if($this->debug>2){error_log('New LP - In learnpath::get_toc() - TOC array: '.print_r($toc,true),0);}
@@ -2724,7 +2725,23 @@ class learnpath {
     			$html .= stripslashes($title);
     		}   		
     		
-    		$html .= "&nbsp;<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />"; 		
+    		$tbl_track_e_exercises = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
+			$tbl_lp_item = Database::get_course_table(TABLE_LP_ITEM);
+			$user_id = api_get_user_id();
+			$course_id = api_get_course_id();
+			$sql = "SELECT path  FROM $tbl_track_e_exercises, $tbl_lp_item
+					WHERE path =   '".$item['path']."' AND exe_user_id =  '$user_id' AND exe_cours_id = '$course_id' AND path = exe_exo_id AND status <> 'incomplete'";
+			$result = api_sql_query($sql,__FILE__,__LINE__);
+			$count = Database::num_rows($result);			
+			if ($item['type']=='quiz') {
+				if ($item['status']=='completed') {
+				$html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
+				}
+			} else {
+					$html .= "<img id='toc_img_".$item['id']."' src='".$icon_name[$item['status']]."' alt='".substr($item['status'],0,1)."' />";
+				
+			}		
+    		 		    		 		
     		$html .= "</div>";
     		
     		if ($scorm_color_background!='')

+ 14 - 3
main/newscorm/learnpathItem.class.php

@@ -1439,7 +1439,8 @@ function get_terms()
 				    					$sql = 'SELECT exe_result, exe_weighting
 												FROM '.Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES).'
 												WHERE exe_exo_id = '.$items[$refs_list[$prereqs_string]]->path.' 
-												AND exe_user_id = '.$user_id.' 
+												AND exe_user_id = '.$user_id.'
+												AND status <> "incomplete"		
 												ORDER BY exe_date DESC
 												LIMIT 0, 1';
 										$rs_quiz = api_sql_query($sql, __FILE__, __LINE__);
@@ -2190,6 +2191,11 @@ function get_terms()
 	     	//now save into DB
 	     	$res = 0;
 	     	if(Database::num_rows($check_res)<1){
+	     		if ($this->type=='quiz') {
+	     				$my_status = ' ';
+	     		}else {
+	     				$my_status = $this->get_status(false);	
+	     		}
 		     	$sql = "INSERT INTO $item_view_table " .
 		     			"(total_time, " .
 		     			"start_time, " .
@@ -2206,7 +2212,7 @@ function get_terms()
 		     			"(".$this->get_total_time()."," .
 		     			"".$this->current_start_time."," .
 		     			"".$this->get_score()."," .
-		     			"'".$this->get_status(false)."'," .
+		     			"'".$my_status."'," .
 		     			"'".$this->get_max()."'," .
 		     			"".$this->db_id."," .
 		     			"".$this->view_id."," .
@@ -2236,11 +2242,16 @@ function get_terms()
 	     		}
 	     		else
 	     		{	//for all other content types...
+	     			if ($this->type=='quiz') {
+	     				$my_status = ' ';
+	     			}else {
+	     				$my_status = " status = '".$this->get_status(false)."' ,";	
+	     			}
 			     	$sql = "UPDATE $item_view_table " .
 			     			"SET total_time = ".$this->get_total_time().", " .
 			     			" start_time = ".$this->get_current_start_time().", " .
 			     			" score = ".$this->get_score().", " .
-			     			" status = '".$this->get_status(false)."'," .
+			     			$my_status.
 			     			" max_score = '".$this->get_max()."'," .
 			     			" suspend_data = '".Database::escape_string($this->current_data)."'," .
 			     			//" max_time_allowed = '".$this->get_max_time_allowed()."'," .

+ 54 - 37
main/newscorm/lp_stats.php

@@ -31,6 +31,8 @@
 require_once('learnpath.class.php');
 //require_once('scorm.class.php');
 require_once ('resourcelinker.inc.php');
+require_once ('../inc/lib/tracking.lib.php');
+require_once ('../inc/lib/course.lib.php');
 
 
 if(empty($_SESSION['_course']['id']) && isset($_GET['course']))
@@ -127,7 +129,7 @@ $sql = "SELECT max(view_count) FROM $TBL_LP_VIEW " .
 "WHERE lp_id = $lp_id AND user_id = '" . $user_id . "'";
 $res = api_sql_query($sql, __FILE__, __LINE__);
 $view = '';
-
+$num = 0;
 if (Database :: num_rows($res) > 0) {
 	$myrow = Database :: fetch_array($res);
 	$view = $myrow[0];
@@ -161,7 +163,7 @@ foreach ($list as $my_item_id) {
 
 	if (!empty ($view)) {
 		$sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
-		"iv.score as myscore, iv.total_time as mytime, i.id as myid, " .
+		"iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid, " .
 		"i.title as mytitle, i.max_score as mymaxscore, " .
 		"iv.max_score as myviewmaxscore, " .
 		"i.item_type as item_type, iv.view_count as iv_view_count, " .
@@ -176,7 +178,7 @@ foreach ($list as $my_item_id) {
 		" ORDER BY iv.view_count $qry_order ";
 	} else {
 		$sql = "SELECT iv.status as mystatus, v.view_count as mycount, " .
-		"iv.score as myscore, iv.total_time as mytime, i.id as myid, " .
+		"iv.score as myscore, iv.total_time as mytime, i.id as myid, i.lp_id as mylpid,  " .
 		"i.title as mytitle, i.max_score as mymaxscore, " .
 		"iv.max_score as myviewmaxscore, " .
 		"i.item_type as item_type, iv.view_count as iv_view_count, " .
@@ -219,9 +221,9 @@ foreach ($list as $my_item_id) {
 			if ($row['item_type'] == 'quiz') 
 			{			
 				if ($origin != 'tracking') {
-					 $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
+					 $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
 				} else {
-					 $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
+					 $sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
 				}
 
 				$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
@@ -235,7 +237,7 @@ foreach ($list as $my_item_id) {
 							if ($origin != 'tracking') {
 								$correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 							} else {
-								$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
+								$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&myid='.$my_id.'&my_lp_id='.$my_lp_id.'&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 							}
 						}
 					} else {
@@ -243,7 +245,7 @@ foreach ($list as $my_item_id) {
 						if ($origin != 'tracking') {
 							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 						} else {
-							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
+							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&myid='.$my_id.'&my_lp_id='.$my_lp_id.'&id=' . $id_last_attempt . '&cidReq=' . $course_code . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 						}
 					}
 				}
@@ -283,7 +285,7 @@ foreach ($list as $my_item_id) {
 			$type;
 			$scoIdentifier = $row['myid'];
 			if ($score == 0) {
-				$maxscore = 0;
+				$maxscore = $row['mymaxscore'];
 			} else {
 				if ($row['item_type'] == 'sco') {
 
@@ -420,9 +422,9 @@ foreach ($list as $my_item_id) {
 		
 		// selecting the exe_id from stats attempts tables in order to look the max score value
 		if ($origin != 'tracking') {
-			$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
+			$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
 		} else {
-			$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date DESC limit 1';
+			$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . $_GET['student_id'] . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date DESC limit 1';
 		}
 
 		$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
@@ -439,7 +441,7 @@ foreach ($list as $my_item_id) {
 	
 		if ($score == 0) 
 		{
-			$maxscore = 0;
+			$maxscore = $row['mymaxscore'];
 		}
 		else 
 		{
@@ -500,14 +502,16 @@ foreach ($list as $my_item_id) {
 				$correct_test_link = '';
 
 				if ($origin != 'tracking' && $origin != 'tracking_course') {
-					$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" ORDER BY exe_date ASC';
+					$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . api_get_user_id() . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . $course_code . '" AND status <> "incomplete" ORDER BY exe_date ASC';
 				} else {
-					$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . Database :: escape_string($_GET['student_id']) . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" ORDER BY exe_date';
+					$sql_last_attempt = 'SELECT exe_id FROM ' . $tbl_stats_exercices . ' WHERE exe_exo_id="' . $row['path'] . '" AND exe_user_id="' . Database :: escape_string($_GET['student_id']) . '" AND orig_lp_id = "'.$lp_id.'" AND orig_lp_item_id = "'.$row['myid'].'" AND exe_cours_id="' . Database :: escape_string($_GET['course']) . '" AND status <> "incomplete" ORDER BY exe_date';
 				}
 
 				$resultLastAttempt = api_sql_query($sql_last_attempt, __FILE__, __LINE__);
 				$num = Database :: num_rows($resultLastAttempt);
 				if ($num > 0) {
+					$my_id = $row['myid'];
+					$my_lp_id = $row['mylpid'];					
 					if ($num > 1) {
 						$i = 1;
 						while ($rowLA = Database :: fetch_array($resultLastAttempt)) {
@@ -515,7 +519,7 @@ foreach ($list as $my_item_id) {
 							if ($origin != 'tracking') {
 								$correct_test_link .= '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $laid . '&cidReq=' . $course_code . '" target="_parent" title="' . get_lang('Attempt') . ' ' . $i . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a> ';
 							} else {
-								$correct_test_link .= '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $laid . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent" title="' . get_lang('Attempt') . ' ' . $i . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a> ';
+								$correct_test_link .= '<a href="../exercice/exercise_show.php?origin=tracking_course&myid='.$my_id.'&my_lp_id='.$my_lp_id.'&id=' . $laid . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent" title="' . get_lang('Attempt') . ' ' . $i . '"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a> ';
 							}
 							$i++;
 						}
@@ -526,7 +530,7 @@ foreach ($list as $my_item_id) {
 						if ($origin != 'tracking') {
 							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=student_progress&id=' . $id_last_attempt . '&cidReq=' . $course_code . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 						} else {
-							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&id=' . $id_last_attempt . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
+							$correct_test_link = '<a href="../exercice/exercise_show.php?origin=tracking_course&myid='.$my_id.'&my_lp_id='.$my_lp_id.'&id=' . $id_last_attempt . '&cidReq=' . Security :: remove_XSS(Database :: escape_string($_GET['course'])) . '&student=' . $_GET['student_id'] . '" target="_parent"><img src="' . api_get_path(WEB_IMG_PATH) . 'quiz.gif"></a>';
 						}
 					}
 				} else {
@@ -538,13 +542,23 @@ foreach ($list as $my_item_id) {
 
 			$output .= "<tr class='$oddclass'>\n" . "<td>$extend_link</td>\n" . '<td colspan="4"><div class="mystatus">' . htmlentities($title, ENT_QUOTES, $lp_charset) . '</div></td>' . "\n"
 			//."<td><font color='$color'><div class='mystatus'>".htmlentities($array_status[$lesson_status],ENT_QUOTES,$lp_charset)."</div></font></td>\n"
-			 . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>\n" . '<td colspan="2"><div class="mystatus" align="center">' . ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore)) . "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td>$correct_test_link</td>\n" . "</tr>\n";
+			 . '<td colspan="2"><font color="' . $color . '"><div class="mystatus">' . $my_lesson_status . "</div></font></td>\n" . '<td colspan="2"><div class="mystatus" align="center">'; 
+			 if ($row['item_type'] == 'quiz') {
+			 	$output .= ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . $maxscore));//$maxscore == 0 ? $score : $score . '/' . $maxscore;
+			 } else {
+			    $output .= ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));	
+			 }			  
+			 $output .= "</div></td>\n" . '<td colspan="2"><div class="mystatus">' . $time . "</div></td><td>$correct_test_link</td>\n" . "</tr>\n";
 
 			if (!empty($export_csv)) {
 				$temp = array ();
 				$temp[] = $title;
 				$temp[] = html_entity_decode($my_lesson_status);
-				$temp[] = ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
+				if ($row['item_type'] == 'quiz') {
+					$temp[] = ($score == 0 ? '0/'.$maxscore : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
+				} else {
+					$temp[] = ($score == 0 ? '-' : ($maxscore == 0 ? $score : $score . '/' . $maxscore));
+				}
 				$temp[] = $time;
 				$csv_content[] = $temp;
 			}
@@ -582,10 +596,28 @@ foreach ($list as $my_item_id) {
 		}
 
 	}
-	//only sum up the latest attempt each time
-	$total_max_score += $maxscore;
-	$total_score += $score;
+
 	$total_time += $time_for_total;
+	//QUIZZ IN LP
+	$a_my_id = array();	
+	if (!empty($my_lp_id)) {
+		$a_my_id[] = $my_lp_id;	
+	}	    
+}
+
+if (!empty($a_my_id)) {
+	$my_studen_id = 0;
+	$my_course_id = '';
+	if ($origin == 'tracking') {
+		$my_studen_id = intval($_GET['student_id']);
+		$my_course_id = Database::escape_string($_GET['course']);
+	} else {
+		$my_studen_id = intval(api_get_user_id());
+		$my_course_id = Database::escape_string(api_get_course_id());
+	}		
+	$total_score = Tracking::get_avg_student_score($my_studen_id, $my_course_id, $a_my_id);			
+} else {
+	$total_score = 0;
 }
 
 $total_time = learnpathItem :: get_scorm_time('js', $total_time);
@@ -593,23 +625,8 @@ $total_time = learnpathItem :: get_scorm_time('js', $total_time);
 $total_time = str_replace('NaN', '00' . $h . '00\'00"', $total_time);
 $lp_type = learnpath :: get_type_static($lp_id);
 $total_percent = 0;
-$final_score = '0%';
-if ($lp_type == 2) //if scorm
-	{
-	if ($total_max_score == 0) {
-		$total_percent = number_format((float) $total_score, 1, '.', '');
-		$final_score = ($total_score == 0 ? '-' : $total_percent);
-	} else {
-		$total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
-		$final_score = ($total_score == 0 ? '-' : $total_percent . '%');
-	}
-} else {
-	if ($total_max_score == 0) {
-		$total_max_score = 1;
-	}
-	$total_percent = number_format((((float) $total_score / (float) $total_max_score) * 100), 1, '.', '');
-	$final_score = ($total_score == 0 ? '-' : $total_percent . '%');
-}
+$final_score = $total_score.'%';
+
 if (($counter % 2) == 0) {
 	$oddclass = "row_odd";
 } else {

+ 12 - 0
main/newscorm/lp_view.php

@@ -123,6 +123,18 @@ switch($lp_type)
 		break;
 }
 
+// update status from lp_item_view table when you finish the exercises in learning path
+if (isset($_GET['lp_id']) && isset($_GET['lp_item_id'])) {
+    $TBL_LP_ITEM_VIEW		= Database::get_course_table(TABLE_LP_ITEM_VIEW);
+	$TBL_LP_VIEW			= Database::get_course_table(TABLE_LP_VIEW);	
+	$learnpath_item_id = Security::remove_XSS($_GET['lp_item_id']);
+    $learnpath_id = Security::remove_XSS($_GET['lp_id']);   	
+	
+	$sql = "UPDATE $TBL_LP_ITEM_VIEW SET status = 'completed' WHERE lp_item_id = '".Database::escape_string($learnpath_item_id)."'
+			 AND lp_view_id = (SELECT lp_view.id FROM $TBL_LP_VIEW lp_view WHERE user_id = '".Database::escape_string($user_id)."' AND lp_id='".Database::escape_string($learnpath_id)."')";
+	api_sql_query($sql,__FILE__,__LINE__);	
+}
+
 $_SESSION['oLP']->set_previous_item($lp_item_id);
 $nameTools = $_SESSION['oLP']->get_name();
 $save_setting = get_setting("show_navigation_menu");