Browse Source

[svn r17972] Added the max_item_allowed option in Tests and in the LP(developed by Nicolas Raynaud (Cyim) added/modified by jmontoya) FS#3515

Julio Montoya 16 years ago
parent
commit
68ace5837f

+ 6 - 4
main/exercice/exercice.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice.php 17909 2009-01-21 21:06:39Z cfasanando $
+<?php // $Id: exercice.php 17972 2009-01-23 20:11:22Z juliomontoya $
 
 /*
 ==============================================================================
@@ -985,7 +985,7 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 			}
 
 			$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,user_id
+						 te.exe_weighting, UNIX_TIMESTAMP(te.exe_date), te.exe_id, email, UNIX_TIMESTAMP(te.start_date), steps_counter,user_id,te.exe_duration
 				  FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
 				  WHERE  te.exe_exo_id = ce.id AND te.status != 'incomplete' AND user_id=te.exe_user_id AND te.exe_cours_id='".Database::escape_string($_cid)."'
 				  AND user.status<>1 $user_id_and $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 
@@ -1002,7 +1002,7 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 				$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,user_id
+						te.exe_weighting, UNIX_TIMESTAMP(te.exe_date),te.exe_id,email,UNIX_TIMESTAMP(te.start_date),steps_counter,user_id,te.exe_duration
 				  FROM $TBL_EXERCICES AS ce , $TBL_TRACK_EXERCICES AS te, $TBL_USER AS user
 				  WHERE  te.exe_exo_id = ce.id AND te.status != 'incomplete' AND user_id=te.exe_user_id AND te.exe_cours_id='".Database::escape_string($_cid)."'
 				  AND user.status<>1 $user_id_and  $session_id_and AND ce.active <>-1 AND orig_lp_id = 0 AND orig_lp_item_id = 0 
@@ -1016,7 +1016,7 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 
 		}
 
-		$results=getManyResultsXCol($sql,10);
+		$results=getManyResultsXCol($sql,11);
 		$hpresults=getManyResultsXCol($hpsql,5);
 
 		$NoTestRes = 0;
@@ -1063,6 +1063,7 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 				$test = $results[$i][1];
 				$dt = strftime($dateTimeFormatLong,$results[$i][4]);
 				$res = $results[$i][2];
+				$duration = intval($results[$i][11]);
 				echo '<tr';
 				if ($i%2==0) {
 					echo 'class="row_odd"';
@@ -1090,6 +1091,7 @@ if ($_configuration['tracking_enabled'] AND ($show == 'result') )
 				echo '</td>';
 
 				echo '<td>'.$add_start_date.format_locale_date('%b %d, %Y %H:%M',$results[$i][4]).'</td>';//get_lang('dateTimeFormatLong')
+				echo '<td>'.sprintf(get_lang('DurationFormat'), $duration).'</td>';
 		  		echo '<td>'.round(($res/($results[$i][3]!=0?$results[$i][3]:1))*100).'% ('.$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'>".

+ 6 - 4
main/exercice/exercice_submit.php

@@ -1,4 +1,4 @@
-<?php // $Id: exercice_submit.php 17944 2009-01-22 20:41:25Z juliomontoya $
+<?php // $Id: exercice_submit.php 17972 2009-01-23 20:11:22Z 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 17944 2009-01-22 20:41:25Z juliomontoya $
+* 	@version $Id: exercice_submit.php 17972 2009-01-23 20:11:22Z juliomontoya $
 */
 
 
@@ -98,7 +98,7 @@ if ( empty ( $learnpath_item_id ) ) {
     $learnpath_item_id  = Database::escape_string($_REQUEST['learnpath_item_id']);
 }
 if ( empty ( $formSent ) ) {
-    $formSent       = $_REQUEST['formSent'];
+    $formSent = $_REQUEST['formSent'];
 }
 if ( empty ( $exerciseResult ) ) {
     $exerciseResult = $_REQUEST['exerciseResult'];
@@ -950,9 +950,11 @@ if(!isset($_SESSION['questionList']) || $origin == 'learnpath')
 }
 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

+ 99 - 108
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 17605 2009-01-08 22:29:28Z cfasanando $
+* 	@version $Id: exercise_result.php 17972 2009-01-23 20:11:22Z juliomontoya $
 *
 *	@todo	split more code up in functions, move functions to library?
 */
@@ -138,8 +138,8 @@ if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){
 $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
 $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
 $courseName = $_SESSION['_course']['name'];
-$query = "select user_id from $main_admin_table";
-$admin_id = mysql_result(api_sql_query($query),0,"user_id");
+$query = "SELECT user_id FROM $main_admin_table";
+$admin_id = Database::result(api_sql_query($query),0,"user_id");
 $uinfo = api_get_user_info($admin_id);
 $from = $uinfo['mail'];
 $from_name = $uinfo['firstname'].' '.$uinfo['lastname'];
@@ -1016,26 +1016,24 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 					$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");				
+					$answer = Database::result($res,0,"position");				
 					
 					exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
 
 				}
 			}
-			elseif ($answerType==FREE_ANSWER)
-			{
+			elseif ($answerType==FREE_ANSWER) {
 				$answer = $choice;
 				exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
 			}
-			elseif ($answerType==UNIQUE_ANSWER)
-			{
-				$sql = "select id from $table_ans where question_id='".Database::escape_string($questionId)."' and position='".Database::escape_string($choice)."'";
+			elseif ($answerType==UNIQUE_ANSWER) {
+				$sql = "SELECT id FROM $table_ans WHERE question_id='".Database::escape_string($questionId)."' and position='".Database::escape_string($choice)."'";
 				$res = api_sql_query($sql, __FILE__, __LINE__);
-				$answer = mysql_result($res,0,"id");
-				exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
-			}
-			else
-			{
+				if (Database::num_rows($res)>0) {			
+					$answer = Database::result($res,0,"id");
+					exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
+				}
+			} else {
 				exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
 			}
 		}
@@ -1079,117 +1077,110 @@ $exerciseTitle=api_parse_tex($exerciseTitle);
 ==============================================================================
 */
 
-if($_configuration['tracking_enabled'])
-{
+if($_configuration['tracking_enabled']) {
 	//	Updates the empty exercise  
 	$safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
 	$safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
-	update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id);
+	$quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
+	update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$quizDuration);
 }
 
-if($objExercise->results_disabled)
-{
+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')
-{
+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>';
 }
 
-if(count($arrques)>0)
-{
-$mycharset = api_get_setting('platform_charset');
-$msg = '<html><head>
-	<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
-	<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
-$msg .= '</head>
-<body><br />
-<p>'.get_lang('OpenQuestionsAttempted').' : 
-</p>
-<p>'.get_lang('AttemptDetails').' : ><br />
-</p>
-<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
-					<tr>
-    <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
-    <td width="469" valign="top"><h2>#course#</h2></td>
-  </tr>
-  <tr>
-    <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
-    <td width="469" valign="top" class="outerframe">#exercise#</td>
-  </tr>
-  <tr>
-    <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
-    <td valign="top" >#firstName# #lastName#</td>
-  </tr>
-  <tr>
-    <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
-    <td valign="top"> #mail#</td>
-</tr></table>
-<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
- <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
-  for($i=0;$i<sizeof($arrques);$i++)
-  {
-	  $msg.='
-		<tr>
-	    <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
-	    <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
-	  	</tr>
-	  	<tr>
-	    <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
-	    <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
-	  	</tr>';
-	
-		$msg1= str_replace("#exercise#",$exerciseTitle,$msg);
-		$msg= str_replace("#firstName#",$firstName,$msg1);
-		$msg1= str_replace("#lastName#",$lastName,$msg);
-		$msg= str_replace("#mail#",$mail,$msg1);
-		$msg1= str_replace("#questionName#",$arrques[$i],$msg);
-		$msg= str_replace("#answer#",$arrans[$i],$msg1);
-		$msg1= str_replace("#i#",$i,$msg);
-		$msg= str_replace("#course#",$courseName,$msg1);
-	}
-	$msg.='</table><br>
- 	<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
-<a href="#url#">#url#</a></span></body></html>';
-
-	$msg1= str_replace("#url#",$url,$msg);
-	$mail_content = stripslashes($msg1);
-	$student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
-	$subject = get_lang('OpenQuestionsAttempted');
-	
-	$from = api_get_setting('noreply_email_address');
-	if($from == ''){
-		if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
-			$sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user 
-					WHERE session.id_coach = user.user_id
-					AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
-					';
-			$result=api_sql_query($sql,__FILE__,__LINE__);
-			$from = mysql_result($result,0,'email');
-			$from_name = mysql_result($result,0,'firstname').' '.mysql_result($result,0,'lastname');
-		}
-		else{
-			$array = explode(' ',$_SESSION['_course']['titular']);
-			$firstname = $array[1];
-			$lastname = $array[0];
-			$sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
-					WHERE firstname = "'.Database::escape_string($firstname).'"
-					AND lastname = "'.Database::escape_string($lastname).'"
-			';
-			$result=api_sql_query($sql,__FILE__,__LINE__);
-			$from = mysql_result($result,0,'email');
-			$from_name = mysql_result($result,0,'firstname').' '.mysql_result($result,0,'lastname');
-		}
+if(count($arrques)>0) {
+	$mycharset = api_get_setting('platform_charset');
+	$msg = '<html><head>
+		<link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
+		<meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
+	$msg .= '</head>
+	<body><br />
+	<p>'.get_lang('OpenQuestionsAttempted').' : 
+	</p>
+	<p>'.get_lang('AttemptDetails').' : ><br />
+	</p>
+	<table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
+						<tr>
+	    <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
+	    <td width="469" valign="top"><h2>#course#</h2></td>
+	  </tr>
+	  <tr>
+	    <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
+	    <td width="469" valign="top" class="outerframe">#exercise#</td>
+	  </tr>
+	  <tr>
+	    <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
+	    <td valign="top" >#firstName# #lastName#</td>
+	  </tr>
+	  <tr>
+	    <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
+	    <td valign="top"> #mail#</td>
+	</tr></table>
+	<p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
+	 <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
+	for($i=0;$i<sizeof($arrques);$i++) {
+		  $msg.='
+			<tr>
+		    <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
+		    <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
+		  	</tr>
+		  	<tr>
+		    <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
+		    <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
+		  	</tr>';
+		
+			$msg1= str_replace("#exercise#",$exerciseTitle,$msg);
+			$msg= str_replace("#firstName#",$firstName,$msg1);
+			$msg1= str_replace("#lastName#",$lastName,$msg);
+			$msg= str_replace("#mail#",$mail,$msg1);
+			$msg1= str_replace("#questionName#",$arrques[$i],$msg);
+			$msg= str_replace("#answer#",$arrans[$i],$msg1);
+			$msg1= str_replace("#i#",$i,$msg);
+			$msg= str_replace("#course#",$courseName,$msg1);
 	}
+		$msg.='</table><br>
+	 	<span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
+	<a href="#url#">#url#</a></span></body></html>';
 	
+		$msg1= str_replace("#url#",$url,$msg);
+		$mail_content = stripslashes($msg1);
+		$student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
+		$subject = get_lang('OpenQuestionsAttempted');
+		
+		$from = api_get_setting('noreply_email_address');
+		if($from == '') {
+			if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
+				$sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user 
+						WHERE session.id_coach = user.user_id
+						AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
+						';
+				$result=api_sql_query($sql,__FILE__,__LINE__);
+				$from = Database::result($result,0,'email');
+				$from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
+			} else {
+				$array = explode(' ',$_SESSION['_course']['titular']);
+				$firstname = $array[1];
+				$lastname = $array[0];
+				$sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
+						WHERE firstname = "'.Database::escape_string($firstname).'"
+						AND lastname = "'.Database::escape_string($lastname).'"
+				';
+				$result=api_sql_query($sql,__FILE__,__LINE__);
+				$from = Database::result($result,0,'email');
+				$from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
+			}
+		}	
 	api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
 }
-?>
-
+?>

+ 4 - 3
main/exercice/question.class.php

@@ -1,4 +1,4 @@
-<?php // $Id: question.class.php 17969 2009-01-23 19:20:33Z cvargas1 $
+<?php // $Id: question.class.php 17972 2009-01-23 20:11:22Z juliomontoya $
  
 /*
 ==============================================================================
@@ -28,7 +28,7 @@
 *	File containing the Question class.
 *	@package dokeos.exercise
 * 	@author Olivier Brouckaert
-* 	@version $Id: question.class.php 17969 2009-01-23 19:20:33Z cvargas1 $
+* 	@version $Id: question.class.php 17972 2009-01-23 20:11:22Z juliomontoya $
 */
 
 
@@ -993,7 +993,8 @@ abstract class Question
 		$form->addElement('hidden','answerType',$_REQUEST['answerType']);
 
 		// question level
-		$form->addElement('text','questionLevel',get_lang('Level'));
+		$select_level = array (0,1,2,3,4,5,6); 
+		$form->addElement('select','questionLevel',get_lang('Level'),$select_level);		
 		$renderer->setElementTemplate('<div class="row"><div class="label">{label}</div><div class="formw">{element}</div></div>','questionLevel');
 
 		// html editor

+ 41 - 51
main/exercice/question_list_admin.inc.php

@@ -1,4 +1,4 @@
-<?php // $Id: question_list_admin.inc.php 17948 2009-01-22 21:39:22Z juliomontoya $
+<?php // $Id: question_list_admin.inc.php 17972 2009-01-23 20:11:22Z juliomontoya $
  
 /*
 ==============================================================================
@@ -28,7 +28,7 @@
 *	Code library for HotPotatoes integration.
 *	@package dokeos.exercise
 * 	@author
-* 	@version $Id: question_list_admin.inc.php 17948 2009-01-22 21:39:22Z juliomontoya $
+* 	@version $Id: question_list_admin.inc.php 17972 2009-01-23 20:11:22Z juliomontoya $
 */
 
 
@@ -100,58 +100,48 @@ echo '</div></div>';
 	</tr>
 
 <?php
-if($nbrQuestions)
-	{
+if($nbrQuestions) {
 	$questionList=$objExercise->selectQuestionList();
-
 	$i=1;
-	foreach($questionList as $id)
-	{
-
-		$objQuestionTmp = Question :: read($id);
-		//showQuestion($id);
-
-?>
-
-<tr <?php if($i%2==0) echo 'class="row_odd"'; else echo 'class="row_even"'; ?>>
-  <td><?php echo "$i. ".$objQuestionTmp->selectTitle(); ?></td>
-  <td><?php eval('echo get_lang('.get_class($objQuestionTmp).'::$explanationLangVar);'); ?></td>
-  <td align="center"><?php echo $objQuestionTmp->selectLevel(); ?></td>
-  <td align="center"><a href="<?php echo api_get_self(); ?>?action=exportqti2&questionId=<?php echo $id; ?>"><img src="../img/export.png" border="0" align="absmiddle" alt="IMS/QTI" /></a></td>
-  <td> <a href="<?php echo api_get_self(); ?>?myid=1&editQuestion=<?php echo $id; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>" /></a> <a href="<?php echo api_get_self(); ?>?deleteQuestion=<?php echo $id; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;"><img src="../img/delete.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Delete'); ?>" /></a>
-
-	<?php
-		if($i != 1)
-		{
-    ?>
-
-	<a href="<?php echo api_get_self(); ?>?moveUp=<?php echo $id; ?>"><img src="../img/up.gif" border="0" align="absmiddle" alt="<?php echo get_lang('MoveUp'); ?>"></a>
-
-    <?php
-    if($i == $nbrQuestions) echo '<img src="../img/down_na.gif" align="absmiddle">';
-    
-		}
-
-		if($i != $nbrQuestions)
-		{
-			if($i == 1) echo '<img src="../img/up_na.gif" align="absmiddle">';
-    ?>
-		
-	<a href="<?php echo api_get_self(); ?>?moveDown=<?php echo $id; ?>"><img src="../img/down.gif" border="0" align="absmiddle" alt="<?php echo get_lang('MoveDown'); ?>"></a>
-
-    <?php
+	if (is_array($questionList)) {
+		foreach($questionList as $id) {
+			$objQuestionTmp = Question :: read($id);
+			//showQuestion($id);
+		?>
+	
+			<tr <?php if($i%2==0) echo 'class="row_odd"'; else echo 'class="row_even"'; ?>>
+				<td><?php echo "$i. ".$objQuestionTmp->selectTitle(); ?></td>
+				<td><?php eval('echo get_lang('.get_class($objQuestionTmp).'::$explanationLangVar);'); ?></td>
+			  	<td align="center"><?php echo $objQuestionTmp->selectLevel(); ?></td>
+			  	<td align="center"><a href="<?php echo api_get_self(); ?>?action=exportqti2&questionId=<?php echo $id; ?>"><img src="../img/export.png" border="0" align="absmiddle" alt="IMS/QTI" /></a></td>
+			  	<td> <a href="<?php echo api_get_self(); ?>?myid=1&ed
+					itQuestion=<?php echo $id; ?>"><img src="../img/edit.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Modify'); ?>" /></a> <a href="<?php echo api_get_self(); ?>?deleteQuestion=<?php echo $id; ?>" onclick="javascript:if(!confirm('<?php echo addslashes(htmlentities(get_lang('ConfirmYourChoice'))); ?>')) return false;"><img src="../img/delete.gif" border="0" align="absmiddle" alt="<?php echo get_lang('Delete'); ?>" /></a>
+				<?php
+				if($i != 1) {
+				    ?>		
+					<a href="<?php echo api_get_self(); ?>?moveUp=<?php echo $id; ?>"><img src="../img/up.gif" border="0" align="absmiddle" alt="<?php echo get_lang('MoveUp'); ?>"></a>		
+				    <?php
+			    	if($i == $nbrQuestions) 
+			    		echo '<img src="../img/down_na.gif" align="absmiddle">';		    
+				}		
+				
+				if($i != $nbrQuestions) {
+					if($i == 1) 
+						echo '<img src="../img/up_na.gif" align="absmiddle">';
+			    	?>				
+					<a href="<?php echo api_get_self(); ?>?moveDown=<?php echo $id; ?>"><img src="../img/down.gif" border="0" align="absmiddle" alt="<?php echo get_lang('MoveDown'); ?>"></a>
+				
+				    <?php
+				}
+				?>			    
+			    </td>		
+			    <?php
+				$i++;
+				unset($objQuestionTmp);
+			    ?>
+			</tr>
+				<?php 
 		}
-    ?>
-    
-    </td>
-
-    <?php
-		$i++;
-
-		unset($objQuestionTmp);
-    ?>
-    </tr>
-	<?php 
 	}
 }
 ?>

+ 9 - 7
main/inc/lib/events.lib.inc.php

@@ -1,4 +1,4 @@
-<?php // $Id: events.lib.inc.php 17484 2008-12-30 21:47:26Z cfasanando $
+<?php // $Id: events.lib.inc.php 17972 2009-01-23 20:11:22Z juliomontoya $
 /* See license terms in /dokeos_license.txt */
 /**
 ==============================================================================
@@ -172,7 +172,7 @@ function event_access_course()
 	                    SET access_date = FROM_UNIXTIME($reallyNow)
 						WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool IS NULL AND access_session_id=".$id_session;
 	$res = api_sql_query($sql,__FILE__,__LINE__);
-	if (mysql_affected_rows() == 0)
+	if (Database::affected_rows() == 0)
 	{
 		$sql = "	INSERT INTO $TABLETRACK_LASTACCESS
 		                	    (access_user_id,access_cours_code,access_date, access_session_id)
@@ -250,7 +250,7 @@ function event_access_tool($tool, $id_session=0)
 						SET access_date = FROM_UNIXTIME($reallyNow)
 						WHERE access_user_id = ".$user_id." AND access_cours_code = '".$_cid."' AND access_tool = '".htmlspecialchars($tool, ENT_QUOTES)."' AND access_session_id=".$id_session;
 	$res = api_sql_query($sql,__FILE__,__LINE__);
-	if (mysql_affected_rows() == 0)
+	if (Database::affected_rows() == 0)
 	{
 		$sql = "INSERT INTO $TABLETRACK_LASTACCESS
 							(access_user_id,access_cours_code,access_tool, access_date, access_session_id)
@@ -417,14 +417,15 @@ function event_link($link_id)
  * @param exo_id ( id in courseDb exercices table )
  * @param result ( score @ exercice )
  * @param weighting ( higher score )
+ * @param duration ( duration of the attempt, in seconds )
  * @param session_id
  * @param learnpath_id (id of the learnpath)
  * @param learnpath_item_id (id of the learnpath_item)
  * @author Sebastien Piraux <piraux_seb@hotmail.com>
- * @author Julio Montoya <gugli100@gmail.com>
+ * @author Julio Montoya Armas <gugli100@gmail.com>
  * @desc Record result of user when an exercice was done
 */
-function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0)
+function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$learnpath_id=0,$learnpath_item_id=0, $duration)
 {
 	if ($exeid!='')
 	{
@@ -436,7 +437,8 @@ function update_event_exercice($exeid,$exo_id, $score, $weighting,$session_id,$l
 				   exe_weighting = '".$weighting."',
 				   session_id		= '".$session_id."',
 				   orig_lp_id = '".$learnpath_id."',		
-				   orig_lp_item_id = '".$learnpath_item_id."',		
+				   orig_lp_item_id = '".$learnpath_item_id."',
+				   exe_duration = '".$duration."',
 				   exe_date= FROM_UNIXTIME(".$reallyNow."),status = '', data_tracking='',start_date ='".$_SESSION['exercice_start_date']."'
 				 WHERE exe_id = '".$exeid."'";
 		$res = @api_sql_query($sql,__FILE__,__LINE__);
@@ -475,7 +477,7 @@ function create_event_exercice($exo_id)
 				'status = '."'incomplete'".' AND '.
 				'session_id = '."'".api_get_session_id()."'";
 		$sql = api_sql_query('SELECT exe_id FROM '.$TABLETRACK_EXERCICES.$condition,__FILE__,__LINE__);
-		$row = mysql_fetch_array($sql);
+		$row = Database::fetch_array($sql);
 		return $row['exe_id'];
 	}
 

+ 53 - 49
main/newscorm/learnpath.class.php

@@ -357,7 +357,7 @@ class learnpath {
      * @param string $description
      * @return int
      */
-    function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0)
+    function add_item($parent, $previous, $type = 'dokeos_chapter', $id, $title, $description, $prerequisites=0, $maxTimeAllowed=0)
     {
     	global $charset;
     	
@@ -367,7 +367,8 @@ class learnpath {
     	$parent = intval($parent);
     	$previous = intval($previous);
     	$type = $this->escape_string($type);
-    	$id = intval($id);
+    	$id = intval($id);    	
+    	$maxTimeAllowed= $this->escape_string(htmlentities($maxTimeAllowed));
     	
     	$title = $this->escape_string(mb_convert_encoding($title,$this->encoding,$charset));
     	$description = $this->escape_string(mb_convert_encoding($description,$this->encoding,$charset)); 
@@ -384,10 +385,8 @@ class learnpath {
    		
    		$num = $row['num'];
    		
-   		if($num > 0)
-   		{
-	    	if($previous == 0)
-	    	{
+   		if($num > 0) {
+	    	if($previous == 0) {
 	    		$sql = "
 	   				SELECT
 	   					id,
@@ -405,11 +404,8 @@ class learnpath {
 	   			$tmp_previous = 0;
 	   			$next = $row['id'];
 	   			$display_order = 0;
-	    	}
-	    	else
-	    	{
-	   			$previous = (int) $previous;
-	   			
+	    	} else {
+	   			$previous = (int) $previous;	   			
 	   			$sql = "
 	   				SELECT
 	   					id,
@@ -429,9 +425,7 @@ class learnpath {
 	   			
 	   			$display_order = $row['display_order'];
 	    	}
-   		}
-   		else
-    	{
+   		} else {
    			$tmp_previous = 0;
    			$next = 0;
    			$display_order = 0;
@@ -440,8 +434,7 @@ class learnpath {
     	$new_item_id = -1;
     	$id = $this->escape_string($id);
     	
-    	if($type == 'quiz')
-    	{  
+    	if($type == 'quiz') {  
     		$sql = 'SELECT SUM(ponderation) 
 					FROM '.Database :: get_course_table(TABLE_QUIZ_QUESTION).' as quiz_question
 					INNER JOIN  '.Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION).' as quiz_rel_question
@@ -449,14 +442,11 @@ class learnpath {
 					AND quiz_rel_question.exercice_id = '.$id;					
 			$rsQuiz = api_sql_query($sql, __FILE__, __LINE__);			
 			$max_score = Database::result($rsQuiz, 0, 0);
-    	}
-    	else
-    	{
+    	} else {
     		$max_score = 100;    		
     	}
 		
-		if($prerequisites!=0)
-		{
+		if($prerequisites!=0) {
 			$sql_ins = "
 	    		INSERT INTO " . $tbl_lp_item . " (
 	    			lp_id,
@@ -470,7 +460,8 @@ class learnpath {
 	    			previous_item_id,
 	    			next_item_id,
 	    			display_order,	    			 
-					prerequisite
+					prerequisite,
+					max_time_allowed
 							
 	    		) VALUES (
 	    			" . $this->get_id() . ",
@@ -484,11 +475,10 @@ class learnpath {
 	    			" . $previous . ",
 	    			" . $next . ",
 	    			" . ($display_order + 1) . ",	    				    			
-	    			" . $prerequisites . "
+	    			" . $prerequisites . ",
+	    			" . $maxTimeAllowed . "
 	    		)";
-		}		
-		else
-		{
+		} else {
 	    	//insert new item
 	    	$sql_ins = "
 	    		INSERT INTO " . $tbl_lp_item . " (
@@ -502,7 +492,8 @@ class learnpath {
 	    			parent_item_id,
 	    			previous_item_id,
 	    			next_item_id,	    				
-	    			display_order
+	    			display_order,
+	    			max_time_allowed
 	    		) VALUES (
 	    			" . $this->get_id() . ",
 	    			'" . $type . "',
@@ -514,7 +505,8 @@ class learnpath {
 	    			" . $parent . ",
 	    			" . $previous . ",
 	    			" . $next . ",
-	    			" . ($display_order + 1) . "
+	    			" . ($display_order + 1) . ",
+	    			" . $maxTimeAllowed . "	    			
 	    		)";
 		}
     	
@@ -565,14 +557,12 @@ class learnpath {
     	}
     	
 		// upload audio
-		if (!empty($_FILES['mp3']['name']))
-		{
+		if (!empty($_FILES['mp3']['name'])) {
 			// create the audio folder if it does not exist yet
 			global $_course;
 			$filepath = api_get_path('SYS_COURSE_PATH').$_course['path'].'/document/';
 						
-			if(!is_dir($filepath.'audio'))
-			{
+			if(!is_dir($filepath.'audio')) {
 				$perm = api_get_setting('permissions_for_new_directories');
 				$perm = octdec(!empty($perm)?$perm:'0770');
 				mkdir($filepath.'audio',$perm);
@@ -592,8 +582,7 @@ class learnpath {
 			// store the mp3 file in the lp_item table
 			$sql_insert_audio = "UPDATE $tbl_lp_item SET audio = '".Database::escape_string($file)."' WHERE id = '".Database::escape_string($new_item_id)."'";
 			api_sql_query($sql_insert_audio, __FILE__, __LINE__);
-		}		
-
+		}
     	return $new_item_id;
     }
    
@@ -962,7 +951,7 @@ class learnpath {
      * @param   array   The array resulting of the $_FILES[mp3] element
      * @return	boolean	True on success, false on error
      */
-    function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL) {
+    function edit_item($id, $parent, $previous, $title, $description, $prerequisites=0, $audio=NULL, $maxTimeAllowed=0) {
     	if($this->debug > 0){error_log('New LP - In learnpath::edit_item()', 0);}
 
     	if(empty($id) or ($id != strval(intval($id))) or empty($title)){ return false; }
@@ -996,23 +985,25 @@ class learnpath {
     	if($same_parent && $same_previous)
     	{
     		//only update title and description
-    		$sql_update = "
-    			UPDATE " . $tbl_lp_item . "
-    			SET
+    		echo $sql_update = "
+    			UPDATE " . $tbl_lp_item . " 
+    			SET 
     				title = '" . $this->escape_string(htmlentities($title)) . "',
 					prerequisite = '".$prerequisites."',
     				description = '" . $this->escape_string(htmlentities($description)) . "'
-                    ". $audio_update_sql . "
+                    ". $audio_update_sql . ",
+                    max_time_allowed = '" . $this->escape_string(htmlentities($maxTimeAllowed)) . "'
     			WHERE id = " . $id;
     		$res_update = api_sql_query($sql_update, __FILE__, __LINE__);
     	}
     	else
     	{
-    		$old_parent		 = $row_select['parent_item_id'];
-    		$old_previous	 = $row_select['previous_item_id'];
-    		$old_next		 = $row_select['next_item_id'];
-    		$old_order		 = $row_select['display_order'];
-    		$old_prerequisite= $row_select['prerequisite'];
+    		$old_parent		 	= $row_select['parent_item_id'];
+    		$old_previous	 	= $row_select['previous_item_id'];
+    		$old_next		 	= $row_select['next_item_id'];
+    		$old_order		 	= $row_select['display_order'];
+    		$old_prerequisite	= $row_select['prerequisite'];
+    		$old_maxTimeAllowed	= $row_select['max_time_allowed'];
     		
     		/* BEGIN -- virtually remove the current item id */
     		/* for the next and previous item it is like the current item doesn't exist anymore */
@@ -1085,8 +1076,7 @@ class learnpath {
 		    	//echo 'New next_item_id of current item: ' . $new_next . '<br />';
 		    	//echo 'New previous_item_id of current item: ' . $previous . '<br />';
 		    	//echo 'New display_order of current item: ' . $new_order . '<br />';
-	    		
-		    	
+	
     		}
     		else
     		{
@@ -1155,6 +1145,15 @@ class learnpath {
 		    	$res_update_next = api_sql_query($sql_update_next, __FILE__, __LINE__);
     		}
     		
+    		if($old_maxTimeAllowed!=$maxTimeAllowed){
+    			$sql_update_maxTimeAllowed = "
+		    		UPDATE " . $tbl_lp_item . "
+		    		SET max_time_allowed = " . $maxTimeAllowed . "
+		    		WHERE id = " . $id;
+		    	$res_update_maxTimeAllowed = api_sql_query($sql_update_maxTimeAllowed, __FILE__, __LINE__);
+    		}
+
+    		
     		//update all the items with the same or a bigger display_order than 
     		//the current item
 	    	$sql_update_order = "
@@ -5098,7 +5097,8 @@ class learnpath {
                     'max_score' => $row['max_score'],
                     'min_score' => $row['min_score'],
                     'mastery_score' => $row['mastery_score'],
-					'prerequisite' => $row['prerequisite']);
+					'prerequisite' => $row['prerequisite'],
+					'max_time_allowed' => $row['max_time_allowed']);
 			}
 			
 			$this->tree_array($arrLP);
@@ -5257,10 +5257,13 @@ class learnpath {
 							}
 							
 							$return .= "</select></td>";
-						
+
 						$return .= "\t\t" . '</tr>' . "\n";
 						
 						$return .= "\t\t" . '<tr>' . "\n";
+						
+						$return .= "\t\t\t" . '<td class="label"><label for="maxTimeAllowed">'.get_lang('MaxTimeAllowed').'&nbsp;:</label></td>' . "\n";
+						$return .= "\t\t\t" . '<td class="input"><input name="maxTimeAllowed" id="maxTimeAllowed" value="' . $extra_info['max_time_allowed'] . '" /></td>';
 							
 							//Remove temporaly the test description
 							//$return .= "\t\t\t" . '<td class="label"><label for="idDescription">'.get_lang("Description").' :</label></td>' . "\n";
@@ -5376,7 +5379,8 @@ class learnpath {
                     'max_score' => $row['max_score'],
                     'min_score' => $row['min_score'],
                     'mastery_score' => $row['mastery_score'],
-					'prerequisite' => $row['prerequisite']);
+					'prerequisite' => $row['prerequisite'],
+					'max_time_allowed' => $row['max_time_allowed']);
 			}
 
 			$this->tree_array($arrLP);

+ 21 - 32
main/newscorm/lp_controller.php

@@ -192,41 +192,31 @@ switch($action)
 		
 		if($debug > 0) error_log('New LP - add item action triggered', 0);
 		
-		if(!$lp_found)
-		{	//check if the learnpath ID was defined, otherwise send back to list
+		if(!$lp_found){	
+			//check if the learnpath ID was defined, otherwise send back to list
 			error_log('New LP - No learnpath given for add item', 0); 
 			require('lp_list.php'); 
-		}
-		else
-		{
+		} else {
 			$_SESSION['refresh'] = 1;
 			
-			if(isset($_POST['submit_button']) && !empty($_POST['title']))
-			{	//if a title was sumbitted 				
-				if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time'])
-				{	//check post_time to ensure ??? (counter-hacking measure?)
+			if(isset($_POST['submit_button']) && !empty($_POST['title'])) {	
+				//if a title was sumbitted 				
+				if(isset($_SESSION['post_time']) && $_SESSION['post_time'] == $_POST['post_time']) {
+					//check post_time to ensure ??? (counter-hacking measure?)
 					require('lp_add_item.php');
-				}
-				else
-				{
+				} else {
 					$_SESSION['post_time'] = $_POST['post_time'];
 					
-					if($_POST['type'] == TOOL_DOCUMENT)
-					{
-						if(isset($_POST['path']) && $_GET['edit'] != 'true')
-						{
+					if($_POST['type'] == TOOL_DOCUMENT) {
+						if(isset($_POST['path']) && $_GET['edit'] != 'true') {
 							$document_id = $_POST['path'];
-						}
-						else
-						{
+						} else {
 							$document_id = $_SESSION['oLP']->create_document($_course);
-						}
-								
+						}								
 						$new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $document_id, $_POST['title'], $_POST['description'], $_POST['prerequisites']);
-					}
-					else
-					{	//for all other item types than documents, load the item using the item type and path rather than its ID
-						$new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
+					} else {	
+						//for all other item types than documents, load the item using the item type and path rather than its ID
+						$new_item_id = $_SESSION['oLP']->add_item($_POST['parent'], $_POST['previous'], $_POST['type'], $_POST['path'], $_POST['title'], $_POST['description'], $_POST['prerequisites'],$_POST['maxTimeAllowed']);
 					}
 					//display 					
 					require('lp_add_item.php');
@@ -364,15 +354,14 @@ switch($action)
 		{
 			$_SESSION['refresh'] = 1;
 			
-			if(isset($_POST['submit_button']) && !empty($_POST['title']))
-			{
-				$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
+			if(isset($_POST['submit_button']) && !empty($_POST['title'])) { 
+				//$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites']);
+				//todo mp3 edit  
+				$_SESSION['oLP']->edit_item($_GET['id'], $_POST['parent'], $_POST['previous'], $_POST['title'], $_POST['description'], $_POST['prerequisites'],'', $_POST['maxTimeAllowed']);
 				
-				if(isset($_POST['content_lp']))
-				{
+				if(isset($_POST['content_lp'])) {
 					$_SESSION['oLP']->edit_document($_course);
-				}
-				
+				}				
 				$is_success = true;
 			}