Browse Source

[svn r18522] Several bugs fixed see FS#3510 for more details

Julio Montoya 16 years ago
parent
commit
af7fa4f150

+ 55 - 57
main/auth/my_progress.php

@@ -1,6 +1,6 @@
 <?php
 // name of the language file that needs to be included
-$language_file = array('registration','tracking','exercice');
+$language_file = array('registration','tracking','exercice','admin');
 
 $cidReset = true;
 
@@ -67,7 +67,10 @@ $now=date('Y-m-d');
   <th><?php echo get_lang('Course'); ?></th>
   <th><?php echo get_lang('Time'); ?></th>
   <th><?php echo get_lang('Progress'); ?></th>
-  <th><?php echo get_lang('Score'); ?></th>
+  <th><?php 
+  echo get_lang('Score');
+  Display :: display_icon('info3.gif',get_lang('ScormAndLPTestTotalAverage') , array ('style' => 'margin-bottom:-3px;')); 
+  ?></th>
   <th><?php echo get_lang('LastConnexion'); ?></th>
   <th><?php echo get_lang('Details'); ?></th>
 </tr>
@@ -106,8 +109,8 @@ foreach($Courses as $enreg)
 		<?php echo $pourcentageScore.'%'; ?>
   	</td>
 
-  	<td align='center'>
-		<?php echo $lastConnexion; ?>
+  	<td align='center' >
+		<?php echo $lastConnexion ?>
   	</td>
 
   	<td align='center'>
@@ -213,15 +216,11 @@ foreach($Courses as $enreg)
 
 				$resultLearnpath = api_sql_query($sqlLearnpath);
 
-				if(Database::num_rows($resultLearnpath)>0)
-				{
-					while($a_learnpath = Database::fetch_array($resultLearnpath))
-					{
-
+				if(Database::num_rows($resultLearnpath)>0) {
+					while($a_learnpath = Database::fetch_array($resultLearnpath)) {
 
 						$progress = learnpath :: get_db_progress($a_learnpath['id'],$_user['user_id'], '%',$a_infosCours['db_name']);
 
-
 						// calculates last connection time
 						$sql = 'SELECT MAX(start_time)
 									FROM '.$a_infosCours['db_name'].'.'.$tbl_course_lp_view_item.' AS item_view
@@ -248,7 +247,7 @@ foreach($Courses as $enreg)
 							 ";
 						echo 		stripslashes($a_learnpath['name']);
 						echo "	</td>
-								<td>
+								<td align='center'>
 							 ";
 						echo api_time_to_hms($total_time);
 						echo "	</td>
@@ -256,7 +255,7 @@ foreach($Courses as $enreg)
 							 ";
 						echo		$progress;
 						echo "	</td>
-								<td align='center'>
+								<td align='center' width=180px >
 							 ";
 						if($start_time!=''){
 							echo format_locale_date(get_lang('dateFormatLong'),$start_time);
@@ -294,19 +293,15 @@ foreach($Courses as $enreg)
 				
 				$sql='SELECT visibility FROM '.$a_infosCours['db_name'].'.'.TABLE_TOOL_LIST.' WHERE name="quiz"';
 				$resultVisibilityTests = api_sql_query($sql);
-				
-				if(Database::result($resultVisibilityTests,0,'visibility')==1){
-				
-					$sqlExercices = "	SELECT quiz.title,id
+								
+				if (Database::result($resultVisibilityTests,0,'visibility')==1) {				
+					$sqlExercices = "	SELECT quiz.title,id, results_disabled
 									FROM ".$a_infosCours['db_name'].".".$tbl_course_quiz." AS quiz
-									WHERE active='1'
-									";
-	
+									WHERE active='1'";	
 	
 					$resuktExercices = api_sql_query($sqlExercices);
-					if(Database::num_rows($resuktExercices)>0){
-						while($a_exercices = Database::fetch_array($resuktExercices))
-						{
+					if (Database::num_rows($resuktExercices)>0) {						
+						while ($a_exercices = Database::fetch_array($resuktExercices)) {								
 							$sqlEssais = "	SELECT COUNT(ex.exe_id) as essais
 											FROM $tbl_stats_exercices AS ex
 											WHERE ex.exe_user_id='".$_user['user_id']."' AND ex.exe_cours_id = '".$a_infosCours['code']."'
@@ -320,17 +315,15 @@ foreach($Courses as $enreg)
 							$sqlScore = "SELECT exe_id , exe_result,exe_weighting
 										 FROM $tbl_stats_exercices
 										 WHERE exe_user_id = ".$_user['user_id']."
-										 AND exe_cours_id = '".$a_infosCours['code']."'
-										 AND exe_exo_id = ".$a_exercices['id']."
-										 AND orig_lp_id = 0
-										 AND orig_lp_item_id = 0			
-										ORDER BY exe_date DESC LIMIT 1"
-											;
+											 AND exe_cours_id = '".$a_infosCours['code']."'
+											 AND exe_exo_id = ".$a_exercices['id']."
+											 AND orig_lp_id = 0
+											 AND orig_lp_item_id = 0			
+										ORDER BY exe_date DESC LIMIT 1";
 		
 							$resultScore = api_sql_query($sqlScore);
 							$score = 0;
-							while($a_score = Database::fetch_array($resultScore))
-							{
+							while($a_score = Database::fetch_array($resultScore)) {
 								$score = $score + $a_score['exe_result'];
 								$weighting = $weighting + $a_score['exe_weighting'];
 								$exe_id = $a_score['exe_id'];
@@ -339,39 +332,44 @@ foreach($Courses as $enreg)
 							if  ($weighting>0) {
 								// i.e 10.50%							
 								$pourcentageScore = round(($score*100)/$weighting,2);
-							}
-							else
-							{
+							} else {
 								$pourcentageScore=0;			
 							}
 		
 							$weighting = 0;
 		
-							echo "<tr>
-									<td>
-								 ";
-							echo 		$a_exercices['title'];
-							echo "	</td>
-								 ";
-							echo "	<td align='center'>
-								  ";
-							echo $pourcentageScore.'%';
-							echo "	</td>
-		
-									<td align='center'>
-								 ";
-							echo 		$a_essais['essais'];
-							echo '	</td>
-									<td align="center" width="25">
-								 ';
-							if($a_essais['essais']>0)
-								echo '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$a_infosCours['code'].'&id_session='.$_GET['id_session'].'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
-							echo "	</td>
-								  </tr>
-								 ";
+							echo '<tr>
+									<td>';
+							echo $a_exercices['title'];
+							echo '</td>';								 
+																						
+							if ($a_exercices['results_disabled']==0) {								
+								echo '<td align="center">';							 
+								echo $pourcentageScore.'%';
+								echo '</td>';								
+								echo '<td align="center">';
+								echo  $a_essais['essais'];
+								echo '</td>
+										<td align="center" width="25">';
+								if($a_essais['essais']>0)
+									echo '<a href="../exercice/exercise_show.php?origin=myprogress&id='.$exe_id.'&cidReq='.$a_infosCours['code'].'&id_session='.$_GET['id_session'].'"> '.Display::return_icon('quiz.gif', get_lang('Quiz')).' </a>';
+								echo '</td>';
+							} else {
+								// we show or not the results if the teacher wants to									
+								echo '<td align="center">';							 
+								echo get_lang('CantShowResults');
+								echo '</td>';								
+								echo '<td align="center">';
+								echo ' -- ';
+								echo '</td>
+										<td align="center" width="25">';
+								echo ' -- ';
+								echo '</td>';
+								
+							}
+							echo '</tr>';
 						}
-					}
-					else{
+					} else {
 						echo '<tr><td colspan="4">'.get_lang('NoEx').'</td></tr>';
 					}
 				}

+ 199 - 154
main/exercice/exercice.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice.php 18366 2009-02-09 16:43:18Z iflorespaz $
+<?php // $Id: exercice.php 18522 2009-02-16 20:20:29Z juliomontoya $
 
 /*
 ==============================================================================
@@ -586,21 +586,16 @@ echo '<div class="actions">';
 	{
 		echo '<a href="exercise_admin.php?'.api_get_cidreq().'">'.Display::return_icon('new_test.gif',get_lang('NewEx')).get_lang('NewEx').'</a>';
 		echo '<a href="hotpotatoes.php">'.Display::return_icon('jqz.gif',get_lang('ImportHotPotatoesQuiz')).get_lang('ImportHotPotatoesQuiz').'</a>';
-		echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=result').'">'.Display::return_icon('show_test_results.gif',get_lang('Results')).get_lang("Results").'</a>';
+		echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=result').'">'.Display::return_icon('show_test_results.gif',get_lang('Results')).get_lang('Results').'</a>';
 
 		// the actions for the statistics
-		if($show == 'result')
-		{
+		if($show == 'result') {
 			// the form
-			if(api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach())
-			{
-				if($_SESSION['export_user_fields']==false)
-				{
+			if(api_is_platform_admin() || api_is_course_admin() || api_is_course_tutor() || api_is_course_coach()) {
+				if($_SESSION['export_user_fields']==false) {
 					$alt = get_lang('ExportWithUserFields');
 					$extra_user_fields = '<input type="hidden" name="export_user_fields" value="export_user_fields">';
-				}
-				else
-				{
+				} else {
 					$alt = get_lang('ExportWithoutUserFields');
 					$extra_user_fields =  '<input type="hidden" name="export_user_fields" value="do_not_export_user_fields">';
 				}
@@ -619,8 +614,13 @@ echo '<div class="actions">';
 				echo '<form id="form1c" name="form1c" method="post" action="'.api_get_self().'?show='.Security::remove_XSS($_GET['show']).'">';
 				echo $extra_user_fields;
 				echo '</form>';
-
-			}	
+			}
+		}
+	} else {		
+		//the student view
+		echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=result').'">'.Display::return_icon('show_test_results.gif',get_lang('Results')).get_lang('Results').'</a>';
+		if($show == 'result') {
+			echo '<a href="'.api_add_url_param($_SERVER['REQUEST_URI'],'show=test').'">'.Display::return_icon('quiz.gif',get_lang('BackToExercisesList')).get_lang('BackToExercisesList').'</a>';
 		}
 	}
 	
@@ -711,94 +711,95 @@ if ($show == 'test') {
 <table class="data_table">
   <?php
 	if (($is_allowedToEdit) and ($origin != 'learnpath')) {
-	?>
-  <tr class="row_odd">
-    <th colspan="3"><?php  echo get_lang('ExerciseName');?></th>
-     <th><?php echo get_lang('QuantityQuestions');?></th>
-	 <th><?php echo get_lang('Export');?></th>
-	 <th><?php echo get_lang('Modify');?></th>
-
-  </tr>
-  <?php
-} else {
-	 ?> <tr>
-     <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
-     <th><?php echo get_lang('QuantityQuestions');?></th>
-	 <th><?php echo get_lang('State');?></th>
-
-  </tr>
-	<?php
-}
+		?>
+	  <tr class="row_odd">
+	    <th colspan="3"><?php  echo get_lang('ExerciseName');?></th>
+	     <th><?php echo get_lang('QuantityQuestions');?></th>
+		 <th><?php echo get_lang('Export');?></th>
+		 <th><?php echo get_lang('Modify');?></th>
+	
+	  </tr>
+	  <?php
+	} else {
+		 ?> <tr>
+	     <th colspan="3"><?php echo get_lang('ExerciseName');?></th>
+	     <th><?php echo get_lang('QuantityQuestions');?></th>
+		 <th><?php echo get_lang('State');?></th>
+	
+	  </tr>
+		<?php
+	}
+	
 	// show message if no HP test to show
 	if (!($nbrExercises+$nbrHpTests) ) {
-	?>
-  <tr>
-    <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
-  </tr>
-  <?php
+		?>
+	  <tr>
+	    <td <?php echo ($is_allowedToEdit?'colspan="6"':'colspan="5"'); ?>><?php echo get_lang("NoEx"); ?></td>
+	  </tr>
+	  <?php
 	}
 $i=1;
 // while list exercises
-
 if ($origin != 'learnpath') {
-//avoid sending empty parameters
-$myorigin = (empty($origin)?'':'&origin='.$origin);
-$mylpid = (empty($learnpath_id)?'':'&learnpath_id='.$learnpath_id);
-$mylpitemid = (empty($learnpath_item_id)?'':'&learnpath_item_id='.$learnpath_item_id);
-while($row=Database::fetch_array($result)) {
-	if($i%2==0) 
-		$s_class="row_odd"; 
-	else 
-		$s_class="row_even";
-	// prof only
-	if ($is_allowedToEdit) {
-		echo '<tr class="'.$s_class.'">'."\n";
-		?>
-		<td width="30" align="left"><?php Display::display_icon('quiz.gif', get_lang('Exercice'))?></td>
-		<td width="15" valign="left"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
-			<?php $row['title']=api_parse_tex($row['title']); ?>
-		<td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$mylpitemid; ?>&amp;exerciseId=<?php echo $row['id']; ?>" <?php if(!$row['active']) echo 'class="invisible"'; ?>><?php echo $row['title']; ?></a></td>
-		<td> <?php
-		$exid = $row['id'];
-		$sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '".Database::escape_string($exid)."'";
-		$sqlresult =api_sql_query($sqlquery);
-		$rowi = Database::result($sqlresult,0);
-		echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))).'</td>';
-  		echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
-  		?>
-	    <td>
-	    <a href="admin.php?exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" /></a>	      
-		<?php	
-		if($row['results_disabled']) {
-			echo '<a href="exercice.php?choice=enable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('EnableResults').'" alt="'.get_lang('EnableResults').'"><img src="../img/lp_quiz_na.gif" border="0" alt="'.htmlentities(get_lang('EnableResults'),ENT_QUOTES,$charset).'" /></a>';
-		} else {
-			echo '<a href="exercice.php?choice=disable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('DisableResults').'" alt="'.get_lang('DisableResults').'"><img src="../img/lp_quiz.gif" border="0" alt="'.htmlentities(get_lang('DisableResults'),ENT_QUOTES,$charset).'" /></a>';
-		}				
-		?>
-		<a href="exercise_admin.php?modifyExercise=yes&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/edit.gif" border="0" title="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" /></a>	    
-		<a href="exercice.php?choice=delete&exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>					
-		<?php		
-		//if active
-		if ($row['active']) {
+	//avoid sending empty parameters
+	$myorigin = (empty($origin)?'':'&origin='.$origin);
+	$mylpid = (empty($learnpath_id)?'':'&learnpath_id='.$learnpath_id);
+	$mylpitemid = (empty($learnpath_item_id)?'':'&learnpath_item_id='.$learnpath_item_id);
+	while($row=Database::fetch_array($result)) {
+		if($i%2==0) 
+			$s_class="row_odd"; 
+		else 
+			$s_class="row_even";
+		// prof only
+		if ($is_allowedToEdit) {
+			echo '<tr class="'.$s_class.'">'."\n";
 			?>
-      		<a href="exercice.php?choice=disable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/visible.gif" border="0" alt="<?php echo htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
-    		<?php
-		} else {
-			// else if not active
+			<td width="30" align="left"><?php Display::display_icon('quiz.gif', get_lang('Exercice'))?></td>
+			<td width="15" valign="left"><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
+				<?php $row['title']=api_parse_tex($row['title']); ?>
+			<td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$mylpitemid; ?>&amp;exerciseId=<?php echo $row['id']; ?>" <?php if(!$row['active']) echo 'class="invisible"'; ?>><?php echo $row['title']; ?></a></td>
+			<td> <?php
+			$exid = $row['id'];
+			$sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '".Database::escape_string($exid)."'";
+			$sqlresult =api_sql_query($sqlquery);
+			$rowi = Database::result($sqlresult,0);
+			echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))).'</td>';
+	  		echo '<td><a href="exercice.php?choice=exportqti2&exerciseId='.$row['id'].'"><img src="../img/export.png" border="0" title="IMS/QTI" /></a></td>';
+	  		?>
+		    <td>
+		    <a href="admin.php?exerciseId=<?php echo $row['id']; ?>"><img src="../img/wizard_small.gif" border="0" title="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Build'),ENT_QUOTES,$charset); ?>" /></a>	      
+			<?php	
+			if($row['results_disabled']) {
+				echo '<a href="exercice.php?choice=enable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('EnableResults').'" alt="'.get_lang('EnableResults').'"><img src="../img/lp_quiz_na.gif" border="0" alt="'.htmlentities(get_lang('EnableResults'),ENT_QUOTES,$charset).'" /></a>';
+			} else {
+				echo '<a href="exercice.php?choice=disable_results&page='.$page.'&exerciseId='.$row['id'].'" title="'.get_lang('DisableResults').'" alt="'.get_lang('DisableResults').'"><img src="../img/lp_quiz.gif" border="0" alt="'.htmlentities(get_lang('DisableResults'),ENT_QUOTES,$charset).'" /></a>';
+			}				
 			?>
-      		<a href="exercice.php?choice=enable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0" alt="<?php echo htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
-    		<?php
-		}		
-		echo "</td>";
-		echo "</tr>\n";
-} else {// student only
+			<a href="exercise_admin.php?modifyExercise=yes&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/edit.gif" border="0" title="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" alt="<?php echo htmlentities(get_lang('Modify'),ENT_QUOTES,$charset); ?>" /></a>	    
+			<a href="exercice.php?choice=delete&exerciseId=<?php echo $row['id']; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('AreYouSureToDelete'),ENT_QUOTES,$charset)); echo " ".$row['title']; echo "?"; ?>')) return false;"> <img src="../img/delete.gif" border="0" alt="<?php echo htmlentities(get_lang('Delete'),ENT_QUOTES,$charset); ?>" /></a>					
+			<?php		
+			//if active
+			if ($row['active']) {
 				?>
-          <tr>
-            <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
-            <td>&nbsp;</td>
-            <?php $row['title']=api_parse_tex($row['title']);?>
-            <td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></td>
-	 <td align="center"> <?php
+	      		<a href="exercice.php?choice=disable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/visible.gif" border="0" alt="<?php echo htmlentities(get_lang('Deactivate'),ENT_QUOTES,$charset); ?>" /></a>
+	    		<?php
+			} else {
+				// else if not active
+				?>
+	      		<a href="exercice.php?choice=enable&page=<?php echo $page; ?>&exerciseId=<?php echo $row['id']; ?>"> <img src="../img/invisible.gif" border="0" alt="<?php echo htmlentities(get_lang('Activate'),ENT_QUOTES,$charset); ?>" /></a>
+	    		<?php
+			}		
+			echo "</td>";
+			echo "</tr>\n";
+		} else {// student only
+					?>
+	          <tr>
+	            <td><?php echo ($i+($page*$limitExPage)).'.'; ?></td>
+	            <td>&nbsp;</td>
+	            <?php $row['title']=api_parse_tex($row['title']);?>
+	            <td><a href="exercice_submit.php?<?php echo api_get_cidreq().$myorigin.$mylpid.$myllpitemid; ?>&exerciseId=<?php echo $row['id']; ?>"><?php echo $row['title']; ?></a></td>
+				 <td align="center"> <?php
+		 
 $exid = $row['id'];
 $sqlquery = "SELECT count(*) FROM $TBL_EXERCICE_QUESTION WHERE exercice_id = '".Database::escape_string($exid)."'";
 $sqlresult =api_sql_query($sqlquery);
@@ -808,21 +809,30 @@ echo $rowi.' '.strtolower(get_lang(($rowi>1?'Questions':'Question'))); ?> </td>
 $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 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";
+$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 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) {
-    	$row = Database::fetch_array($qryres);
-    	$percentage = 0;
-    	if($row['exe_weighting'] != 0) {
-    		$percentage = ($row['exe_result']/$row['exe_weighting'])*100;
-    	}
-		echo get_lang('Attempted').' ('.get_lang('Score').':';
-		printf("%1.2f\n",$percentage);
-		echo " %)";
-	} else {
-		echo get_lang('NotAttempted');
+	
+	//hide the results 
+	$my_result_disabled = $row['results_disabled'];	
+	if ($my_result_disabled==0) {
+	    if ($num>0) {
+	    	$row = Database::fetch_array($qryres);
+	    	$percentage = 0;
+	    	if($row['exe_weighting'] != 0) {
+	    		$percentage = ($row['exe_result']/$row['exe_weighting'])*100;
+	    	}
+			echo get_lang('Attempted').' ('.get_lang('Score').': ';
+			printf("%1.2f\n",$percentage);
+			echo " %)";
+		} else {
+			echo get_lang('NotAttempted');
+		}
+	}
+	else {
+			echo get_lang('CantShowResults');
 	}
 	?></td>
   </tr>
@@ -951,7 +961,7 @@ $i++;
 /*****************************************/
 
 // if tracking is enabled
-if ($_configuration['tracking_enabled'] AND ($show == 'result') ) 
+if ($_configuration['tracking_enabled'] && ($show == 'result') ) 
 {
 		?>
 		<table class="data_table">
@@ -972,7 +982,6 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 
 		if($is_allowedToEdit || $is_tutor) {
 			$user_id_and='';
-
 			if (!empty($_POST['filter_by_user'])) {
 				if ($_POST['filter_by_user'] =='all') {
 					$user_id_and = " AND user_id like '%'";
@@ -997,29 +1006,30 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 					WHERE  tu.user_id=tth.exe_user_id AND tth.exe_cours_id = '".Database::escape_string($_cid)." $user_id_and '
 					ORDER BY tth.exe_cours_id ASC, tth.exe_date DESC";
 			
-			} else {
-				// get only this user's results
-				$user_id_and = ' AND te.exe_user_id = ' . Database::escape_string ( api_get_user_id() ).' ';
+		} else {
+			// get only this user's results
+			$user_id_and = ' AND te.exe_user_id = ' . Database::escape_string ( api_get_user_id() ).' ';
 
 			$sql="SELECT CONCAT(lastname,' ',firstname) as users, ce.title, te.exe_result ,
-						 te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email, UNIX_TIMESTAMP(te.start_date), steps_counter,cuser.user_id,te.exe_duration
+					 te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email, UNIX_TIMESTAMP(te.start_date), steps_counter,cuser.user_id,te.exe_duration, ce.results_disabled
 				  FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user,$tbl_course_rel_user AS cuser
 				  WHERE  user.user_id=cuser.user_id AND te.exe_exo_id = ce.id AND te.status != 'incomplete' AND cuser.user_id=te.exe_user_id AND te.exe_cours_id='".Database::escape_string($_cid)."'
 				  AND cuser.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 
 				  AND cuser.course_code=te.exe_cours_id ORDER BY users, te.exe_cours_id ASC, ce.title ASC, te.exe_date DESC";
 
-				$hpsql="SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
-					FROM $TBL_TRACK_HOTPOTATOES
-					WHERE exe_user_id = '".$_user['user_id']."' AND exe_cours_id = '".Database::escape_string($_cid)."'
-					ORDER BY exe_cours_id ASC, exe_date DESC";
+			$hpsql="SELECT '',exe_name, exe_result , exe_weighting, UNIX_TIMESTAMP(exe_date)
+				FROM $TBL_TRACK_HOTPOTATOES
+				WHERE exe_user_id = '".$_user['user_id']."' AND exe_cours_id = '".Database::escape_string($_cid)."'
+				ORDER BY exe_cours_id ASC, exe_date DESC";
 		}
-		$results=getManyResultsXCol($sql,11);
+		$results=getManyResultsXCol($sql,12);
 		$hpresults=getManyResultsXCol($hpsql,5);
 
 		$NoTestRes = 0;
 		$NoHPTestRes = 0;
 		//Print the results of tests
 		$lang_nostartdate = get_lang('NoStartDate').' / ';
+				
 		if (is_array($results)) {
 			$users_array_id = array();
 			if ($_GET['gradebook']=='view') {
@@ -1060,46 +1070,81 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 				$res = $results[$i][2];
 				
 				$duration = intval($results[$i][10]);
-				echo '<tr';
-				if ($i%2==0) {
-					echo 'class="row_odd"';
-				} else {
-					echo 'class="row_even"';
-				}
-				echo '>';
-				$add_start_date = $lang_nostartdate;
-				
-				if ($is_allowedToEdit || $is_tutor) {
-					$user = $results[$i][0];
-					echo '<td>'.$user.' </td>';
-				}
-				
-				echo '<td>'.$test.'</td>';
-				echo '<td>';
-				if ($results[$i][7] > 1) {
-					echo ceil((($results[$i][4] - $results[$i][7])/60)).' '.get_lang('MinMinutes');
-					if($results[$i][8] > 1) {
-						echo ' ( '.$results[$i][8].' '.get_lang('Steps').' )';
+				// we filter the results if we have the permission to
+				if (isset($results[$i][11]))
+					$result_disabled = intval($results[$i][11]);
+				else 
+					$result_disabled = 0;
+					
+				if ($result_disabled==0) {
+					echo '<tr';
+					if ($i%2==0) {
+						echo 'class="row_odd"';
+					} else {
+						echo 'class="row_even"';
 					}
-					$add_start_date = format_locale_date('%b %d, %Y %H:%M',$results[$i][7]).' / ';
-				} else {
-					echo get_lang('NoLogOfDuration');
+					echo '>';
+					$add_start_date = $lang_nostartdate;
+					
+					if ($is_allowedToEdit || $is_tutor) {
+						$user = $results[$i][0];
+						echo '<td>'.$user.' </td>';
+					}				
+					echo '<td>'.$test.'</td>';
+					echo '<td>';
+					if ($results[$i][7] > 1) {
+						echo ceil((($results[$i][4] - $results[$i][7])/60)).' '.get_lang('MinMinutes');
+						if($results[$i][8] > 1) {
+							echo ' ( '.$results[$i][8].' '.get_lang('Steps').' )';
+						}
+						$add_start_date = format_locale_date('%b %d, %Y %H:%M',$results[$i][7]).' / ';
+					} else {
+						echo get_lang('NoLogOfDuration');
+					}
+	
+					echo '</td>';
+	
+					echo '<td>'.$add_start_date.format_locale_date('%b %d, %Y %H:%M',$results[$i][4]).'</td>';//get_lang('dateTimeFormatLong')
+					
+					// there are already a duration test period calculated??
+					//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
+			  		echo '<td>'.round(($res/($results[$i][3]!=0?$results[$i][3]:1))*100,2).'% ('.$res.' / '.$results[$i][3].')</td>';
+			  		
+			  		// Is hard to read this!!
+			  		
+					echo '<td>'.(($is_allowedToEdit||$is_tutor)?
+								"<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
+								(($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
+								((api_is_platform_admin() || $is_tutor)?' - <a href="exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result&filter='.$filter.'&delete=delete&did='.$id.'" onclick="javascript:if(!confirm(\''.sprintf(get_lang('DeleteAttempt'),$user,$dt).'\')) return false;">'.get_lang('Delete').'</a>':'')
+								.(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>':'')
+								:(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
+											
+					/*				
+					echo '<td>';
+						if ($is_allowedToEdit||$is_tutor) {
+							echo "<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>";
+							if ($revised)			
+								echo get_lang('Edit');
+							else
+								echo get_lang('Qualify');
+							echo "</a>";				
+								
+							if (api_is_platform_admin() || $is_tutor)
+								echo ' - <a href="exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result&filter='.$filter.'&delete=delete&did='.$id.'" onclick="javascript:if(!confirm(\''.sprintf(get_lang('DeleteAttempt'),$user,$dt).'\')) return false;">'.get_lang('Delete').'</a>';
+							if ($is_allowedToEdit)
+								echo ' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>';
+						} else {
+							if ($revised)
+								echo "<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a> ";
+							else
+							echo '&nbsp;'.get_lang('NoResultsYet'); 
+						}						
+					echo '</td>';
+					*/
+												
+					echo '</tr>';
+					
 				}
-
-				echo '</td>';
-
-				echo '<td>'.$add_start_date.format_locale_date('%b %d, %Y %H:%M',$results[$i][4]).'</td>';//get_lang('dateTimeFormatLong')
-				
-				// there are already a duration test period calculated??
-				//echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
-		  		echo '<td>'.round(($res/($results[$i][3]!=0?$results[$i][3]:1))*100,2).'% ('.$res.' / '.$results[$i][3].')</td>';
-				echo '<td>'.(($is_allowedToEdit||$is_tutor)?
-							"<a href='exercise_show.php?user=$user&dt=$dt&res=$res&id=$id&email=$mailid'>".
-							(($revised)?get_lang('Edit'):get_lang('Qualify'))."</a>".
-							((api_is_platform_admin() || $is_tutor)?' - <a href="exercice.php?cidReq='.htmlentities($_GET['cidReq']).'&show=result&filter='.$filter.'&delete=delete&did='.$id.'" onclick="javascript:if(!confirm(\''.sprintf(get_lang('DeleteAttempt'),$user,$dt).'\')) return false;">'.get_lang('Delete').'</a>':'')
-							.(($is_allowedToEdit)?' - <a href="exercice_history.php?cidReq='.htmlentities($_GET['cidReq']).'&exe_id='.$id.'">'.get_lang('ViewHistoryChange').'</a>':'')
-							:(($revised)?"<a href='exercise_show.php?dt=$dt&res=$res&id=$id'>".get_lang('Show')."</a>":'')).'</td>';
-				echo '</tr>';
 			}
 		} else {
 				$NoTestRes = 1;

+ 96 - 92
main/exercice/exercice_submit.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice_submit.php 18387 2009-02-09 22:05:17Z juliomontoya $
+<?php // $Id: exercice_submit.php 18522 2009-02-16 20:20:29Z juliomontoya $
 
 /*
 ==============================================================================
@@ -42,7 +42,7 @@
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
 * 	@author Julio Montoya multiple fill in blank option added
-* 	@version $Id: exercice_submit.php 18387 2009-02-09 22:05:17Z juliomontoya $
+* 	@version $Id: exercice_submit.php 18522 2009-02-16 20:20:29Z juliomontoya $
 */
 
 
@@ -254,11 +254,8 @@ if ($formSent) {
 						$counter++;
 						// gets the student choice for this question
 						$choice=$exerciseResult[$questionId];
-				
-						//print_r($choice); echo "<br>";
-				
-						// creates a temporary Question object
-				
+								
+						// creates a temporary Question object				
 						$objQuestionTmp = Question :: read($questionId);
 				
 						$questionName=$objQuestionTmp->selectTitle();
@@ -525,10 +522,13 @@ if ($formSent) {
 									}
 									$val=addslashes($val);
 									$val=strip_tags($val);
-									$sql = "select position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
+									$sql = "SELECT position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
 									$res = api_sql_query($sql, __FILE__, __LINE__);
-									$answer = mysql_result($res,0,"position");
-				
+									if (Database::num_rows($res)>0) {
+										$answer = Database::result($res,0,"position");
+									} else {
+										$answer = '';
+									}													
 									exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
 				
 								}
@@ -561,11 +561,8 @@ if ($formSent) {
 						$counter++;
 						// gets the student choice for this question
 						$choice=$exerciseResult[$questionId];
-				
-						//print_r($choice); echo "<br>";
-				
-						// creates a temporary Question object
-				
+						
+						// creates a temporary Question object				
 						$objQuestionTmp = Question :: read($questionId);
 				
 						$questionName=$objQuestionTmp->selectTitle();
@@ -835,8 +832,11 @@ if ($formSent) {
 									$val=strip_tags($val);
 									$sql = "select position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
 									$res = api_sql_query($sql, __FILE__, __LINE__);
-									$answer = mysql_result($res,0,"position");
-				
+									if (Database::num_rows($res)>0) {
+										$answer = Database::result($res,0,"position");
+									} else {
+										$answer = '';
+									}
 									exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
 				
 								}
@@ -901,11 +901,13 @@ if ($formSent) {
 }
 
 // if the object is not in the session
-if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
-	
+
+//why destroying the exercise when a LP is loaded ?
+//if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
+if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {	
     if ($debug>0) {
     	echo str_repeat('&nbsp;',0).'$_SESSION[objExercise] was unset'."<br />\n";
-    }
+    }    
     // construction of Exercise
     $objExercise=new Exercise();
     unset($_SESSION['questionList']);
@@ -942,34 +944,29 @@ $exerciseSound=$objExercise->selectSound();
 $randomQuestions=$objExercise->isRandom();
 $exerciseType=$objExercise->selectType();
 
-if(!isset($_SESSION['questionList']) || $origin == 'learnpath')
-{
-    if($debug>0){echo str_repeat('&nbsp;',0).'$_SESSION[questionList] was unset'."<br />\n";}
+//if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
+//in LP's is enabled the "remember question" feature?
+if (!isset($_SESSION['questionList'])) {
+    if ($debug>0){echo str_repeat('&nbsp;',0).'$_SESSION[questionList] was unset'."<br />\n";}
     // selects the list of question ID
     $questionList = ($randomQuestions?$objExercise->selectRandomList():$objExercise->selectQuestionList());
     // saves the question list into the session
     api_session_register('questionList');
-    if($debug>0){echo str_repeat('&nbsp;',0).'$_SESSION[questionList] was unset - set now - end'."<br />\n";}
+    if ($debug>0){echo str_repeat('&nbsp;',0).'$_SESSION[questionList] was unset - set now - end'."<br />\n";}
 }
-if(!isset($objExcercise) && isset($_SESSION['objExercise'])){
+if(!isset($objExcercise) && isset($_SESSION['objExercise'])) {
 	$questionList = $_SESSION['questionList'];
 }
 
 $quizStartTime = time();
 api_session_register('quizStartTime');
-
 $nbrQuestions=sizeof($questionList);
-
 // if questionNum comes from POST and not from GET
-if(!$questionNum || $_POST['questionNum'])
-{
+if(!$questionNum || $_POST['questionNum']) {
     // only used for sequential exercises (see $exerciseType)
-    if(!$questionNum)
-    {
+    if(!$questionNum) {
         $questionNum=1;
-    }
-    else
-    {
+    } else {
         $questionNum++;
     }
 }
@@ -1132,7 +1129,7 @@ else
 <?php
 }
 
- $exerciseTitle=api_parse_tex($exerciseTitle);
+$exerciseTitle=api_parse_tex($exerciseTitle);
 
 echo "<h3>".$exerciseTitle."</h3>";
 
@@ -1151,23 +1148,24 @@ if( $exerciseAttempts > 0){
 
     if ( $attempt[0] >= $exerciseAttempts ) {
     	if (!api_is_allowed_to_edit()) {
-	    	Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'),$exerciseTitle,$exerciseAttempts));
+	    	Display::display_warning_message(sprintf(get_lang('ReachedMaxAttempts'),$exerciseTitle,$exerciseAttempts),false);
+	    	if ($origin != 'learnpath')
 	 	  	Display::display_footer();
 	 	  	exit;
 	    } else {
-	        Display::display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'),$exerciseTitle,$exerciseAttempts));
+	        Display::display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'),$exerciseTitle,$exerciseAttempts),false);
 		}
 	}
 }
 
 if (!function_exists('convert_date_to_number')) {
-function convert_date_to_number($default){
-	// 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
-	$parts = split(' ',$default);
-	list($d_year,$d_month,$d_day) = split('-',$parts[0]);
-	list($d_hour,$d_minute,$d_second) = split(':',$parts[1]);
-	return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
-}
+	function convert_date_to_number($default){
+		// 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
+		$parts = split(' ',$default);
+		list($d_year,$d_month,$d_day) = split('-',$parts[0]);
+		list($d_hour,$d_minute,$d_second) = split(':',$parts[1]);
+		return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
+	}
 }
 
 $limit_time_exists = (($Exe_starttime!='0000-00-00 00:00:00')||($Exe_endtime!='0000-00-00 00:00:00'))? true : false;
@@ -1245,6 +1243,7 @@ else
 	if($exerciseType==2){
 		$s2 = "&exerciseId=".$exerciseId;
 	}
+	
 	$s.=" <form method='post' action='".api_get_self()."?autocomplete=off".$s2."' name='frm_exercise' $onsubmit>
 	 <input type='hidden' name='formSent' value='1' />
 	 <input type='hidden' name='exerciseType' value='".$exerciseType."' />
@@ -1254,57 +1253,52 @@ else
 	 <input type='hidden' name='origin' value='".$origin."' />
 	 <input type='hidden' name='learnpath_id' value='".$learnpath_id."' />
 	 <input type='hidden' name='learnpath_item_id' value='".$learnpath_item_id."' />
-	<table width='100%' border='0' cellpadding='1' cellspacing='0'>
-	 <tr>
-	  <td>
-	  <table width='100%' cellpadding='3' cellspacing='0' border='0'>";
-	echo $s;
-	$i=0;	
-	foreach($questionList as $questionId) {
-		$i++;		
-		// for sequential exercises
-		if($exerciseType == 2) {
-			// if it is not the right question, goes to the next loop iteration			
-			if($questionNum != $i){
-				continue;
-			} else {			
-				if ($exerciseFeedbackType!=1) {
-					// if the user has already answered this question
-					if(isset($exerciseResult[$questionId])) {
-						// construction of the Question object
-						$objQuestionTmp = Question::read($questionId);				
-						$questionName=$objQuestionTmp->selectTitle();
-						// destruction of the Question object
-						unset($objQuestionTmp);
-						echo '<tr><td>'.get_lang('AlreadyAnswered').' &quot;'.$questionName.'&quot;</td></tr>';	
-						break;
+	 <table width='100%' border='0' cellpadding='1' cellspacing='0'>
+		<tr>
+	 		<td>
+	  			<table width='100%' cellpadding='3' cellspacing='0' border='0'>";
+				echo $s;										
+				$i=1;						 
+				foreach($questionList as $questionId) {		
+					// for sequential exercises
+					if($exerciseType == 2) {
+						// if it is not the right question, goes to the next loop iteration			
+						if ($questionNum != $i ) {
+							$i++;							
+							continue;							
+						} else {			
+							if ($exerciseFeedbackType != 1) {
+								// if the user has already answered this question
+								if (isset($exerciseResult[$questionId])) {
+									// construction of the Question object
+									$objQuestionTmp = Question::read($questionId);				
+									$questionName=$objQuestionTmp->selectTitle();
+									// destruction of the Question object
+									unset($objQuestionTmp);
+									Display::display_normal_message(get_lang('AlreadyAnswered'));
+									$i++;
+									//echo '<tr><td>'.get_lang('AlreadyAnswered').' &quot;'.$questionName.'&quot;</td></tr>';	
+									break;
+								}
+							}
+						}
 					}
+					// shows the question and its answers		
+					showQuestion($questionId, false, $origin,$i,$nbrQuestions);
+					$i++;
+					// for sequential exercises
+					if($exerciseType == 2) {
+						// quits the loop
+						break;
+					}					
 				}
-			}
-		}
-			/*
-		$s="<tr>
-		 <td width='3%' bgcolor='#e6e6e6'><img src=\"".api_get_path(WEB_IMG_PATH)."test.gif\" align=\"absmiddle\"></td>
-		 <td valign='middle' bgcolor='#e6e6e6'>
-			".get_lang('Question')." ";
-		*/
-		
-		// shows the question and its answers		
-		showQuestion($questionId, false, $origin,$i,$nbrQuestions);
-		// for sequential exercises
-		if($exerciseType == 2) {
-			// quits the loop
-			break;
-		}
-	}
-	// end foreach()
-	
+				// end foreach()
 	echo "	  	
 		 <!-- <button type='submit' name='buttonCancel' class='cancel'>".get_lang('Cancel')."</button>
 	   &nbsp;&nbsp; //--><br />";
 		$submit_btn="<button class=\"save\" type='submit' name='submit'>";
 		//	$submit_btn.=get_lang('ValidateAnswer'); 
-		if ($objExercise->selectFeedbackType()==1 && $_SESSION['objExercise']->selectType()==2) {						
+		if ($objExercise->selectFeedbackType()==1 && $_SESSION['objExercise']->selectType()==2) {				
 			$submit_btn='';
 			echo '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.js" type="text/javascript"></script>';						
 			echo '<style type="text/css" media="all">@import "'.api_get_path(WEB_LIBRARY_PATH).'javascript/thickbox.css";</style>';
@@ -1315,7 +1309,12 @@ else
 					  $('.rounded_inner').corners();
 					});</script>";
 			//echo '<br /><span class="rounded" style="width: 300px; margin-top: 10px; padding: 3px; background-color:#ccc;"><span style="width: 300px" class="rounded_inner" ><a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a></span></span><br /><br /><br />';
-			echo '<br /><div class="rounded" style="text-align: center;"><div class="rounded_inner"><a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a></div></div><br /><br /><br />';				
+			echo '<br />
+					<div class="rounded" style="text-align: center;">
+				  		<div class="rounded_inner">
+				  			<a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a>
+				  		</div>
+				  	</div><br /><br /><br />';				
 		} else {
 			if ($exerciseType == 1 || $nbrQuestions == $questionNum)
 			{
@@ -1326,9 +1325,13 @@ else
 				$submit_btn.=get_lang('Next').' &gt;';
 			}
 			$submit_btn.= "</button>"; 
-		}			
+		}	
+		
 	echo $submit_btn;	 
-	echo "</form>";	
+	echo "</table>
+		</td>
+		</tr>
+		</table></form>";	
 	$b=2;
 }
 
@@ -1345,6 +1348,7 @@ else
 		}
     }
 
-if ($origin != 'learnpath') { //so we are not in learnpath tool
+if ($origin != 'learnpath') { 
+	//so we are not in learnpath tool
     Display::display_footer();
 }

+ 11 - 8
main/exercice/exercise.class.php

@@ -25,7 +25,7 @@
 *	Exercise class: This class allows to instantiate an object of type Exercise
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: exercise.class.php 18487 2009-02-13 04:02:46Z ivantcholakov $
+* 	@version $Id: exercise.class.php 18522 2009-02-16 20:20:29Z juliomontoya $
 */
 
 
@@ -287,11 +287,10 @@ class Exercise
      */
 	function selectRandomList()
 	{		
-		$nbQuestions = $this->selectNbrQuestions();
-		$temp_list = $this->questionList;
-		shuffle($temp_list);
-		return array_combine(range(1,$nbQuestions),$temp_list);
-		
+		$nbQuestions = $this->selectNbrQuestions();		
+		$temp_list = $this->questionList;		
+		shuffle($temp_list);		
+		return array_combine(range(1,$nbQuestions),$temp_list);			
 		$nbQuestions = $this->selectNbrQuestions();
 		
 		//Not a random exercise, or if there are not at least 2 questions
@@ -329,7 +328,10 @@ class Exercise
 	 */
 	function isInList($questionId)
 	{
-		return in_array($questionId,$this->questionList);
+		if (is_array($this->questionList))
+			return in_array($questionId,$this->questionList);
+		else
+			return false;
 	}
 
 	/**
@@ -747,7 +749,8 @@ class Exercise
 			}
 			else
 			{
-				$pos=max(array_keys($this->questionList))+1;
+				if (is_array($this->questionList))
+					$pos=max(array_keys($this->questionList))+1;
 			}
 
 			$this->questionList[$pos]=$questionId;

+ 11 - 11
main/exercice/exercise.lib.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercise.lib.php 18478 2009-02-12 21:27:18Z herodoto $
+<?php // $Id: exercise.lib.php 18522 2009-02-16 20:20:29Z juliomontoya $
  
 /*
 ==============================================================================
@@ -29,7 +29,7 @@
 * 	shows a question and its answers
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert <oli.brouckaert@skynet.be>
-* 	@version $Id: exercise.lib.php 18478 2009-02-12 21:27:18Z herodoto $
+* 	@version $Id: exercise.lib.php 18522 2009-02-16 20:20:29Z juliomontoya $
 */
 
 /**
@@ -66,12 +66,12 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
 			$s="<div id=\"question_title\" class=\"sectiontitle\">
 				".get_lang('Question').' ';
 					
-			$s.=$current_item;
-			
-			if($answerType == 2)
-				$s.=' / '.$total_item;			
+			$s.=$current_item;		
+			//@todo I need the get the feedback type	
+			//if($answerType != 1)
+			//$s.=' / '.$total_item;			
 			echo $s;
-			echo ': ';		
+			echo ' : ';		
 			
 			$s =$questionName.'</div>';
 			$s.="<table class='exercise_questions'>
@@ -92,7 +92,7 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
 				</tr>";
 			}
 
-		}  // end if(!$onlyAnswers)
+		}  
 		$s.= '</table>';
 		$s.="<script>$(document).ready( function(){
 			  $('.rounded').corners();
@@ -296,9 +296,9 @@ function showQuestion($questionId, $onlyAnswers=false, $origin=false,$current_it
 				".get_lang('Question').' ';
 					
 			$s.=$current_item;
-			
-			if($answerType == 2)
-				$s.=' / '.$total_item;			
+			//@todo I need to the get the feedback type
+			//if($answerType == 2)
+			//	$s.=' / '.$total_item;			
 			echo $s;
 			echo ': ';		
 			

+ 16 - 20
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 18203 2009-02-03 18:02:16Z ndieschburg $
+* 	@version $Id: exercise_result.php 18522 2009-02-16 20:20:29Z juliomontoya $
 *
 *	@todo	split more code up in functions, move functions to library?
 */
@@ -472,11 +472,7 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 		$counter++;
 		// gets the student choice for this question
 		$choice=$exerciseResult[$questionId];
-		
-		//print_r($choice); echo "<br>";
-		
 		// creates a temporary Question object
-
 		$objQuestionTmp = Question :: read($questionId);
 
 		$questionName=$objQuestionTmp->selectTitle();
@@ -997,29 +993,25 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 						$ans = $reply[$i];
 						exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
 					}
-				}
-				else
-				{
+				} else {
 					exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
 				}
-			}
-			elseif ($answerType==MATCHING)
-			{
+			} elseif ($answerType==MATCHING) {
 				$j=sizeof($matching)+1;
-
-				for ($i=0;$i<sizeof($choice);$i++,$j++)
-				{
+				for ($i=0;$i<sizeof($choice);$i++,$j++) {
 					$val = $choice[$j];
 					if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
 						$val = $arr1[1][0];
 					$val=addslashes($val);
 					$val=strip_tags($val);
-					$sql = "select position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
+					$sql = "SELECT position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer='".Database::escape_string($val)."' AND correct=0";
 					$res = api_sql_query($sql, __FILE__, __LINE__);
-					$answer = Database::result($res,0,"position");				
-					
+					if (Database::num_rows($res)>0) {
+						$answer = Database::result($res,0,"position");
+					} else {
+						$answer = '';
+					}					
 					exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
-
 				}
 			}
 			elseif ($answerType==FREE_ANSWER) {
@@ -1087,7 +1079,11 @@ if($_configuration['tracking_enabled']) {
 
 if($objExercise->results_disabled) {
 	ob_end_clean();
-	Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
+	if ($origin != 'learnpath') {
+		Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
+	} else {
+		Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><br />',false);
+	}
 }
 
 if ($origin != 'learnpath') {
@@ -1183,4 +1179,4 @@ if(count($arrques)>0) {
 		}	
 	api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
 }
-?>
+?>

+ 117 - 99
main/exercice/exercise_show.php

@@ -198,7 +198,7 @@ function get_comments($id,$question_id)
 	//$sql = "select teacher_comment from ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id and question_id)."' = '".Database::escape_string($question_id)."' order by question_id";
 	$sql = "select teacher_comment from ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' order by question_id";
 	$sqlres = api_sql_query($sql, __FILE__, __LINE__);
-	$comm = mysql_result($sqlres,0,"teacher_comment");
+	$comm = Database::result($sqlres,0,"teacher_comment");
 	return $comm;
 	}
 /**
@@ -343,25 +343,41 @@ function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComme
   <tr>
     <td colspan="2">
 	<?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).'"';
+		$sql_test_name='SELECT title, description, results_disabled 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=Database::result($result,0,0);
-		$exerciseTitle=api_parse_tex($test);
-		$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  
-						INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id 
-						INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
-						INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id    
-					WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
-					GROUP BY quizz_rel_questions.question_order, attempts.question_id"; 
-					//GROUP BY questions.position, attempts.question_id";
+		$show_results = true;
+		// Avoiding the "Score 0/0" message  when the exe_id is not set 	
+		if (Database::num_rows($result)>0 && isset($id)) {
+			$test=Database::result($result,0,0);		
+			$exerciseTitle=api_parse_tex($test);
+			$exerciseDexcription=Database::result($result,0,1);
 			
-$result =api_sql_query($query, __FILE__, __LINE__);
-
-?> 
-	
+			// if the results_disabled of the Quiz is 1 when block the script	
+			$result_disabled=Database::result($result,0,2);
+			if (!(api_is_platform_admin() || api_is_course_admin()) ) {			
+				if ($result_disabled==1) {
+					api_not_allowed();
+				}
+			}				
+			$user_restriction = $is_allowedToEdit ? '' :  "AND user_id=".intval($_user['user_id'])." ";
+			$query = "SELECT attempts.question_id, answer  from ".$TBL_TRACK_ATTEMPT." as attempts  
+							INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id 
+							INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
+							INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id    
+						WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
+						GROUP BY quizz_rel_questions.question_order, attempts.question_id"; 
+						//GROUP BY questions.position, attempts.question_id";
+			$result =api_sql_query($query, __FILE__, __LINE__);							
+		} else {
+			Display::display_warning_message(get_lang('CantViewResults'));
+			$show_results = false;
+			echo '</td>
+			</tr>
+			</table>';
+		}		
+		$show_results = true;
+		
+?>	
 	<table>
 		<tr>
 			<td style="font-weight:bold"><?php echo get_lang('CourseTitle')?> : </td>
@@ -384,54 +400,51 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 	 <br />
   <?php
 
-
 	$i=$totalScore=$totalWeighting=0;
- if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
-
-	// for each question
-	$questionList = array();
-	$exerciseResult = array();
-	$k=0;
-	$counter=0;
-	while ($row = mysql_fetch_array($result))
-			{
+	if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
+	
+		// for each question
+		$questionList = array();
+		$exerciseResult = array();
+		$k=0;
+		$counter=0;
+		while ($row = Database::fetch_array($result)) {
 			$questionList[] = $row['question_id'];
 			$exerciseResult[] = $row['answer'];
-			}
+		}
 		//echo '<pre>';print_R($questionList);
-		foreach($questionList as $questionId)
+		if ($show_results)
+		foreach($questionList as $questionId) {
+			
+			$counter++;
+			$k++;
+			$choice=$exerciseResult[$questionId];
+			// creates a temporary Question object
+			$objQuestionTmp = Question::read($questionId);
+			$questionName=$objQuestionTmp->selectTitle();
+			$questionDescription=$objQuestionTmp->selectDescription();
+			$questionWeighting=$objQuestionTmp->selectWeighting();
+			$answerType=$objQuestionTmp->selectType();
+			$quesId =$objQuestionTmp->selectId(); //added by priya saini
+	
+			// destruction of the Question object
+			unset($objQuestionTmp);
+	
+			if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
 			{
-				$counter++;
-				$k++;
-				$choice=$exerciseResult[$questionId];
-				// creates a temporary Question object
-				$objQuestionTmp = Question::read($questionId);
-				$questionName=$objQuestionTmp->selectTitle();
-				$questionDescription=$objQuestionTmp->selectDescription();
-				$questionWeighting=$objQuestionTmp->selectWeighting();
-				$answerType=$objQuestionTmp->selectType();
-				$quesId =$objQuestionTmp->selectId(); //added by priya saini
-
-				// destruction of the Question object
-				unset($objQuestionTmp);
-
-
-
-				if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
-				{
-					$colspan=2;
-				}
-				if($answerType == MATCHING || $answerType == FREE_ANSWER)
-				{
-					$colspan=2;
-				}
-				else
-				{
-					$colspan=2;
-				}?>
+				$colspan=2;
+			}
+			if($answerType == MATCHING || $answerType == FREE_ANSWER)
+			{
+				$colspan=2;
+			}
+			else
+			{
+				$colspan=2;
+			}?>
 
-  <tr bgcolor="#E6E6E6">
-    <td colspan="2" > <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?> </td>
+  <tr>  
+    <td colspan="2" height="24px"><div id="question_title" class="sectiontitle"><?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?> </div></td>
   </tr>
    <tr>
     <td colspan="2"><?php echo $questionDescription; ?> </td>
@@ -460,25 +473,22 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 				$objAnswerTmp=new Answer($questionId);
 				$nbrAnswers=$objAnswerTmp->selectNbrAnswers();
 				$questionScore=0;
-				for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
-					{
-						$answer=$objAnswerTmp->selectAnswer($answerId);
-						$answerComment=$objAnswerTmp->selectComment($answerId);
-						$answerCorrect=$objAnswerTmp->isCorrect($answerId);
-						$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
-						$queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
-						$resultans = api_sql_query($queryans, __FILE__, __LINE__);
-						while ($row = mysql_fetch_array($resultans))
-								{
-								$ind = $row['answer'];
-								$choice[$ind] = 1;
-								}
-						$studentChoice=$choice[$answerId];
-						if($studentChoice)
-							{
-							$questionScore+=$answerWeighting;
-							$totalScore+=$answerWeighting;
-							}
+				for($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
+					$answer=$objAnswerTmp->selectAnswer($answerId);
+					$answerComment=$objAnswerTmp->selectComment($answerId);
+					$answerCorrect=$objAnswerTmp->isCorrect($answerId);
+					$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
+					$queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
+					$resultans = api_sql_query($queryans, __FILE__, __LINE__);
+					while ($row = Database::fetch_array($resultans)) {
+						$ind = $row['answer'];
+						$choice[$ind] = 1;
+					}
+					$studentChoice=$choice[$answerId];
+					if($studentChoice) {
+						$questionScore+=$answerWeighting;
+						$totalScore+=$answerWeighting;
+					}
 
 				?>
 			<tr>
@@ -495,7 +505,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 		 }?>
 			</table>
 	<?php }
-		else if ($answerType == UNIQUE_ANSWER)
+		elseif ($answerType == UNIQUE_ANSWER)
 		{?>
 		<table width="355" border="0">
 			<tr>
@@ -521,7 +531,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 				$answerWeighting=$objAnswerTmp->selectWeighting($answerId);
 				$queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
 				$resultans = api_sql_query($queryans, __FILE__, __LINE__);
-				$choice = mysql_result($resultans,0,"answer");
+				$choice = Database::result($resultans,0,"answer");
 				$studentChoice=($choice == $answerId)?1:0;
 				if($studentChoice)
 					{
@@ -629,7 +639,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 						
 						$queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
 						$resfill = api_sql_query($queryfill, __FILE__, __LINE__);
-						$str=mysql_result($resfill,0,"answer");
+						$str=Database::result($resfill,0,"answer");
 						preg_match_all ('#\[([^[/]*)/#', $str, $arr);
 													
 						$choice = $arr[1];
@@ -678,7 +688,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 
 						$queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
 						$resfill = api_sql_query($queryfill, __FILE__, __LINE__);
-						$str=mysql_result($resfill,0,"answer");
+						$str=Database::result($resfill,0,"answer");
 						preg_match_all ('#\[([^[/]*)/#', $str, $arr);
 						$choice = $arr[1];
 						
@@ -733,8 +743,8 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 			$questionScore=0;
 			$query = "select answer, marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
 			$resq=api_sql_query($query);
-			$choice = mysql_result($resq,0,"answer");
-			$questionScore = mysql_result($resq,0,"marks");
+			$choice = Database::result($resq,0,"answer");
+			$questionScore = Database::result($resq,0,"marks");
 			if($questionScore==-1){
 				$totalScore+=0;
 			}
@@ -759,7 +769,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 		$res_answer = api_sql_query($sql_answer, __FILE__, __LINE__);
 		// getting the real answer
 		$real_list =array();		
-		while($real_answer = mysql_fetch_array($res_answer))
+		while($real_answer = Database::fetch_array($res_answer))
 		{			
 			$real_list[$real_answer['position']]= $real_answer['answer'];
 		}	
@@ -776,7 +786,7 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 		
 		$questionScore=0;
 		
-		while($a_answers = mysql_fetch_array($res_answers))
+		while($a_answers = Database::fetch_array($res_answers))
 		{			
 			$i_answer_id = $a_answers['id']; //3
 			$s_answer_label = $a_answers['answer'];  // your dady - you mother
@@ -798,7 +808,10 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 			
 			
 			$res_user_answer = api_sql_query($sql_user_answer, __FILE__, __LINE__);
-			$s_user_answer = mysql_result($res_user_answer,0,0); //  rich - good looking
+			if (Database::num_rows($res_user_answer)>0 )
+				$s_user_answer = Database::result($res_user_answer,0,0); //  rich - good looking
+			else 
+				$s_user_answer = '';
 			
 			//$s_correct_answer = $s_answer_label; // your ddady - your mother
 			$s_correct_answer = $real_list[$i_answer_correct_answer];
@@ -856,14 +869,14 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 						$TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
 						$query = "select hotspot_correct from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".Database::escape_string($id)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
 						$resq=api_sql_query($query);
-						$choice = mysql_result($resq,0,"hotspot_correct");
+						$choice = Database::result($resq,0,"hotspot_correct");
 						display_hotspot_answer($answerId,$answer,$choice,$answerComment);
 		
 						$i++;
 				 	}
 				 	$queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
 					$resfree = api_sql_query($queryfree, __FILE__, __LINE__);
-					$questionScore= mysql_result($resfree,0,"marks");
+					$questionScore= Database::result($resfree,0,"marks");
 					$totalScore+=$questionScore;
 		 			?>
 		 			</table>
@@ -972,18 +985,17 @@ $result =api_sql_query($query, __FILE__, __LINE__);
 								 	$arrmarks[] = $questionId;
 								 	echo '<div id="'.$marksname.'" style="visibility:hidden"><form name="marksform_'.$questionId.'" method="post" action=""><select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form></div>';
 								 }
-						}
-						else{
-							if($questionScore==-1){
+						} else {
+							if($questionScore==-1) {
 								  	$questionScore=0;
 						}
 						}?>
 
   </td><tr><td align="left"><b><?php echo get_lang('Score')." : $questionScore/$questionWeighting"; ?></b><br /><br /></td>
   </tr>
-	<?php  unset($objAnswerTmp);
+		<?php  unset($objAnswerTmp);
 		$i++;
-$totalWeighting+=$questionWeighting;
+		$totalWeighting+=$questionWeighting;
 		}
 ?>
 <tr><td align="left"><b><?php
@@ -1042,13 +1054,19 @@ $totalWeighting+=$questionWeighting;
 		</tr>
 </table>
 <?php
-if ($origin != 'learnpath')
-{
+if ($origin != 'learnpath') {
 	//we are not in learnpath tool
 	Display::display_footer();
-}else{
+} 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>';
 }
-?>
+//destroying the session 
+api_session_unregister('questionList');
+unset ($questionList);
+
+api_session_unregister('exerciseResult');
+unset ($exerciseResult);
+
+?>

+ 5 - 5
main/exercice/question_list_admin.inc.php

@@ -1,4 +1,4 @@
-<?php // $Id: question_list_admin.inc.php 18411 2009-02-10 17:59:08Z juliomontoya $
+<?php // $Id: question_list_admin.inc.php 18522 2009-02-16 20:20:29Z juliomontoya $
  
 /*
 ==============================================================================
@@ -28,7 +28,7 @@
 *	Code library for HotPotatoes integration.
 *	@package dokeos.exercise
 * 	@author
-* 	@version $Id: question_list_admin.inc.php 18411 2009-02-10 17:59:08Z juliomontoya $
+* 	@version $Id: question_list_admin.inc.php 18522 2009-02-16 20:20:29Z juliomontoya $
 */
 
 
@@ -86,10 +86,9 @@ if($deleteQuestion)
 echo '<div class="actionsbig">';
 //we filter the type of questions we can add
 Question :: display_type_menu ($objExercise->feedbacktype);
-echo '</div></div>';
+echo '</div>';
 ?>
 
-
 <table class="data_table">
 	<tr class="row_odd">
 		<th><?php echo get_lang('Question'); ?></th>
@@ -155,4 +154,5 @@ if(!$i) {
 <?php
 }
 ?>
-</table>
+</table>
+</div>

+ 6 - 5
main/exercice/unique_answer.class.php

@@ -141,11 +141,12 @@ class UniqueAnswer extends Question {
 		require_once('../newscorm/learnpathList.class.php');		
 		require_once(api_get_path(LIBRARY_PATH).'text.lib.php');
 		
-		
-		foreach ($question_list as $key=>$questionid) {				
-			$question = Question::read($questionid);			
-			$select_question[$questionid]='Q'.$key.' :'.cut($question->selectTitle(),20);						
-		}		
+		if (is_array($question_list)) {
+			foreach ($question_list as $key=>$questionid) {				
+				$question = Question::read($questionid);			
+				$select_question[$questionid]='Q'.$key.' :'.cut($question->selectTitle(),20);						
+			}
+		}
 		$select_question[-1]=get_lang('ExitTest');		
 			
 		//LP SELECT