Browse Source

Added time control for exercice tool

Isaac Flores 15 years ago
parent
commit
0194530143

+ 26 - 0
main/css/public_admin/default.css

@@ -2373,6 +2373,32 @@ span.radio {
 	background: url(images/close_highlight.gif) no-repeat;
 	padding-left: 20px;
 }
+/*Exercice timer*/
+#square{
+  padding:15px;
+  background-color:#EEEEEE;
+  border:1px solid #CCCCCC;
+  margin-right : 25px;
+  width : 260px;margin-bottom:10px;
+}
+#wrapper-clock{
+  width:100%;
+  margin:0;
+}
+.count_down{
+  padding: 3px;
+  font-family:Georgia, "Times New Roman", Times, serif;
+  font-size:38px;
+  font-weight:bold;
+  color:#222;
+}
+.count_down sup{
+  font-family:"Lucida Grande", "Lucida Sans Unicode", Verdana, Arial, Helvetica, sans-serif;
+  font-size:12px;
+  color:#555;
+  padding:0px 10px 0 0;
+  font-weight:normal;
+}
 /*SOCIAL TOOL*/
 div.image-social-content {
 	float:left;

+ 1 - 1
main/exercice/answer_admin.inc.php

@@ -1397,7 +1397,7 @@ if($modifyAnswers)
 			</script>
 		</td>
 		<td valign="top">
-			<form method="post" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>" name="frm_exercise">
+			<form method="post" id="frm_exercise" action="<?php echo api_get_self(); ?>?modifyAnswers=<?php echo $modifyAnswers; ?>" name="frm_exercise">
 				<input type="hidden" name="formSent" value="1" />
 				<input type="hidden" name="nbrAnswers" value="<?php echo $nbrAnswers; ?>" />
 				<table border="0" cellpadding="3" cellspacing="0" style="border: 1px solid #4271b5; border-left:none; width: 100%; ">

+ 119 - 13
main/exercice/exercice_submit.php

@@ -70,10 +70,14 @@ require_once '../inc/global.inc.php';
 $this_section = SECTION_COURSES;
 $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>'; //jQuery
 $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.corners.min.js" type="text/javascript"></script>';
+
 if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
   $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/glossary.js" type="text/javascript" language="javascript"></script>'; //Glossary
   $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.highlight.js" type="text/javascript" language="javascript"></script>'; 
 }
+//This library is necessary for the time control feature
+$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.epiclock.min.js" type="text/javascript" language="javascript"></script>'; //jQuery
+
 /* ------------	ACCESS RIGHTS ------------ */
 // notice for unauthorized people.
 api_protect_course_script(true);
@@ -115,7 +119,7 @@ if (empty ($exerciseType)) {
 	$exerciseType = $_REQUEST['exerciseType'];
 }
 if (empty ($exerciseId)) {
-	$exerciseId = Database::escape_string(intval($_REQUEST['exerciseId']));
+  	$exerciseId = Database::escape_string(intval($_REQUEST['exerciseId']));	
 }
 if (empty ($choice)) {
 	$choice = $_REQUEST['choice'];
@@ -200,11 +204,83 @@ $condition = ' WHERE ' .
 	'session_id = ' . "'" . (int) $_SESSION['id_session'] . "'";
 
 $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
-$result = Database::query("SELECT type,feedback_type FROM $TBL_EXERCICES WHERE id=$exerciseId", __FILE__, __LINE__);
+
+$result = Database::query("SELECT type,feedback_type,expired_time FROM $TBL_EXERCICES WHERE id=$exerciseId", __FILE__, __LINE__);
 $exercise_row = Database :: fetch_array($result);
 $exerciseType = $exercise_row['type'];
 $exerciseFeedbackType = $exercise_row['feedback_type'];
 
+//Timer - Get expired_time for a student
+$condition = ' WHERE ' .
+'exe_exo_id =   '."'".Database::escape_string($exerciseId)."'".' AND ' .
+'exe_user_id =  '."'".api_get_user_id()."'".' AND ' .
+'exe_cours_id = '."'".api_get_course_id()."'".' AND ' .
+'status = '."'incomplete'".' AND '.
+'session_id = '."'".api_get_session_id()."'";
+$sql_track = 'SELECT exe_id,expired_time_control FROM '.$stat_table.$condition;
+
+$rs_sql = Database::query($sql_track,__FILE__,__LINE__);
+$exists_into_database = Database::num_rows($rs_sql);
+$exercise_row1 = Database::fetch_array($rs_sql);
+
+if ($exists_into_database == 0) {
+  //Get info of database
+  $total_minutes = $exercise_row["expired_time"];
+  if ($total_minutes >= 60) {
+      $new_total_hours = ($total_minutes/60);
+      $db_new_only_hours = floor($new_total_hours); //Hours
+      $db_new_total_minutes = round(($new_total_hours - $db_new_only_hours)*60,0); //Minutes
+
+  } else {
+  	$total_minutes = $exercise_row["expired_time"];
+  }
+
+  //Get info of server
+  $my_expired_hour = date('H',time());
+  $my_expired_minutes = date('i',time());
+
+  //Sum minutes
+  $my_total_minutes = $my_expired_minutes +$total_minutes;
+
+  if ($my_total_minutes >= 60) {
+  	  $new_total_hours = ($my_total_minutes/60);
+      $new_only_hours = floor($new_total_minutes);
+      $new_total_minutes = round(($new_total_hours - $new_only_hours)*60,0); 
+  } else {
+  	 $new_only_hours = 0;
+     $new_total_minutes = $my_total_minutes;
+  }
+
+  $add_new_hours = $new_only_hours + $db_new_only_hours+$my_expired_hour;
+  $add_new_minutes = $db_new_total_minutes+$new_total_minutes;
+  $expired_time = date('M d, Y H:i:s',time());//Add quiz configuration
+  $datetime = new DateTime($expired_time);
+
+  $datetime->setTime($add_new_hours, $add_new_minutes, 0);
+  $plugin_expired_time = $datetime->format('M d, Y H:i:s');
+  $expired_time = $datetime->format('Y-m-d H:i:s');
+  $start_time = date('Y-m-d H:i:s',time()); 
+  
+} else {
+  $plugin_expired_time = date('M d, Y H:i:s',strtotime($exercise_row1["expired_time_control"]));
+  $expired_time = date('Y-m-d H:i:s',strtotime($exercise_row1["expired_time_control"]));    
+}
+if ($exerciseType == 1) {
+    if (!isset($_SESSION['expired_time'])) {
+    		$_SESSION['expired_time'] = $expired_time;
+    }
+
+}
+//Time control - core
+if ($exercise_row['expired_time'] != 0) {   
+    $htmlHeadXtra[] = "<script type=\"text/javascript\">
+    $(document).ready(function(){
+       jQuery('#text-content').epiclock({mode: EC_COUNTDOWN, format: 'x{<sup>".get_lang('Hours')."</sup>} i{<sup>".get_lang('Minutes')."</sup>} s{<sup>".get_lang('Seconds')."</sup>}',target: '".$plugin_expired_time."',onTimer: function(){ $('form#my_frm_exercise').submit() }}).clocks(EC_RUN);
+       $('.rounded').corners('transparent');
+    });
+    </script>";
+}
+
 if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $exerciseFeedbackType != 1) {
 	$query = 'SELECT * FROM ' . $stat_table . $condition;
 	$result_select = Database::query($query, __FILE__, __LINE__);
@@ -231,6 +307,7 @@ if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $
 }
 
 // if the user has submitted the form
+
 if ($formSent) {
 	if ($debug > 0) {
 		echo str_repeat('&nbsp;', 0) . '$formSent was set' . "<br />\n";
@@ -282,6 +359,7 @@ if ($formSent) {
 					define('ENABLED_LIVE_EXERCISE_TRACKING', 1);
 					require_once 'question.class.php';
 					require_once 'answer.class.php';
+
 					$counter = 0;
 					$main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
 					$table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
@@ -606,6 +684,7 @@ if ($formSent) {
 						$sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . (int) $totalScore . ',exe_weighting = exe_weighting + ' . (int) $totalWeighting . ' WHERE exe_id = ' . Database::escape_string($exe_id);
 						Database::query($sql_update, __FILE__, __LINE__);
 					}
+
 					//END of saving and qualifying
 					//------------------------------------------------------------------------------------------
 					//
@@ -622,11 +701,14 @@ if ($formSent) {
 	api_session_register('exerciseResultCoordinates');
 	define('ALL_ON_ONE_PAGE',1);
 	define('ONE_PER_PAGE',2);
+
 	// if all questions on one page OR if it is the last question (only for an exercise with one question per page)
-	if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) {
+
+    if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) {
 		if ($debug > 0) {
 			echo str_repeat('&nbsp;', 0) . 'Redirecting to exercise_result.php - Remove debug option to let this happen' . "<br />\n";
 		}
+
 		if ( api_is_allowed_to_session_edit() ) {
 			// goes to the script that will show the result of the exercise
 			if ($exerciseType == ALL_ON_ONE_PAGE) {
@@ -634,7 +716,7 @@ if ($formSent) {
 			} else {
 				if ($exe_id != '') {
 					//clean incomplete
-					$update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . date('Y-m-d H:i:s') . "'" . ' WHERE exe_id = ' . Database::escape_string($exe_id);
+					$update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . date('Y-m-d H:i:s') . "' " . ' WHERE exe_id = ' . Database::escape_string($exe_id);
 					Database::query($update_query, __FILE__, __LINE__);
 				}
 				header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
@@ -645,6 +727,7 @@ if ($formSent) {
 			exit;
 		}
 	}
+
 	if ($debug > 0) {
 		echo str_repeat('&nbsp;', 0) . '$formSent was set - end' . "<br />\n";
 	}
@@ -694,6 +777,7 @@ $exerciseSound = $objExercise->selectSound();
 $randomQuestions = $objExercise->isRandom();
 $exerciseType = $objExercise->selectType();
 $table_quiz_test = Database :: get_course_table(TABLE_QUIZ_TEST);
+
 //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
 //in LP's is enabled the "remember question" feature?
 $my_exe_id = Security :: remove_XSS($_GET['exerciseId']);
@@ -906,8 +990,10 @@ if (api_is_course_admin() && $origin != 'learnpath') {
 	echo Display :: return_icon('edit.gif', get_lang('ModifyExercise')) . '<a href="exercise_admin.php?modifyExercise=yes&exerciseId=' . $objExercise->id . '">' . get_lang('ModifyExercise') . '</a>';
 	echo '</div>';
 }
-
-
+//Timer control
+if ($exercise_row['expired_time'] != 0) { 
+  echo '<div align="right" id="wrapper-clock"><div id="square" class="rounded"><div id="text-content" class="count_down"></div></div></div>';
+}
 $exerciseTitle = api_parse_tex($exerciseTitle);
 echo "<h3>" . $exerciseTitle . "</h3>";
 
@@ -1014,7 +1100,7 @@ if (!empty ($error)) {
 		$s2 = "&exerciseId=" . $exerciseId;
 	}
 
-	$s .= " <form method='post' action='" . api_get_self() . "?autocomplete=off&gradebook=$gradebook" . $s2 . "' name='frm_exercise' $onsubmit>
+	$s .= " <form method='post' action='" . api_get_self() . "?autocomplete=off&gradebook=$gradebook" . $s2 . "' id='my_frm_exercise' name='frm_exercise' $onsubmit>
 		 <input type='hidden' name='formSent' value='1' />
 		 <input type='hidden' name='exerciseType' value='" . $exerciseType . "' />
 		 <input type='hidden' name='exerciseId' value='" . $exerciseId . "' />
@@ -1085,11 +1171,18 @@ if (!empty ($error)) {
 		if (api_is_allowed_to_session_edit() ) {
 			if ($exerciseType == 1 || $nbrQuestions == $questionNum) {
 				$submit_btn .= get_lang('ValidateAnswer');
+        $name_btn = get_lang('ValidateAnswer');
 			} else {
 				$submit_btn .= get_lang('NextQuestion');
+        $name_btn = get_lang('NextQuestion');
 			}
 			$submit_btn .= "</button>";
-			echo $submit_btn;
+      if ($exercise_row['expired_time'] != 0) {
+      	   echo $submit_btn ="<input type='submit' value='".$name_btn."' />";
+      } else {
+      	  echo $submit_btn;
+      }
+
 		}
 
 	}
@@ -1102,16 +1195,29 @@ if (!empty ($error)) {
 	$b = 2;
 }
 echo '</div>';
+
 if ($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType != 1) {
 	//if($questionNum < 2){
-	if ($table_recorded_not_exist) {
+	if ($table_recorded_not_exist) { //$table_recorded_not_exist
+    if ($exercise_row['expired_time'] != 0) {
+      $sql_fields = "expired_time_control, ";
+      $sql_fields_values = "'"."$expired_time"."',";     
+    } else {
+      $sql_fields = "";
+      $sql_fields_values = "";
+    }
+
 		if ($exerciseType == 2) {
-			Database::query("INSERT INTO $stat_table(exe_exo_id,exe_user_id,exe_cours_id,status,session_id,data_tracking,start_date,orig_lp_id,orig_lp_item_id)
-										VALUES('$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)", __FILE__, __LINE__);
+    $sql = "INSERT INTO $stat_table($sql_fields exe_exo_id,exe_user_id,exe_cours_id,status,session_id,data_tracking,start_date,orig_lp_id,orig_lp_item_id)
+      VALUES($sql_fields_values '$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)";      
+			Database::query($sql, __FILE__, __LINE__);
+      
 		} else {
-			Database::query("INSERT INTO $stat_table (exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date,orig_lp_id,orig_lp_item_id)
-									   VALUES('$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)", __FILE__, __LINE__);
+    $sql = "INSERT INTO $stat_table ($sql_fields exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date,orig_lp_id,orig_lp_item_id)
+       VALUES($sql_fields_values '$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)";
+         Database::query($sql, __FILE__, __LINE__);
 		}
+
 	}
 }
 

+ 79 - 34
main/exercice/exercise.class.php

@@ -24,10 +24,10 @@ class Exercise
 	var $attempts;
 	var $feedbacktype;
 	var $end_time;
-    var $start_time;
+  var $start_time;
 	var $questionList;  // array with the list of this exercise's questions
 	var $results_disabled;
-
+  var $expired_time;
 	/**
 	 * constructor of the class
 	 *
@@ -45,8 +45,9 @@ class Exercise
 		$this->questionList=array();
 		$this->timeLimit = 0;
 		$this->end_time = '0000-00-00 00:00:00';
-        $this->start_time = '0000-00-00 00:00:00';
-        $this->results_disabled =1;
+    $this->start_time = '0000-00-00 00:00:00';
+    $this->results_disabled =1;
+    $this->expired_time = '0000-00-00 00:00:00';
 	}
 
 	/**
@@ -67,7 +68,7 @@ class Exercise
 	    $TBL_QUESTIONS          = Database::get_course_table(TABLE_QUIZ_QUESTION);
     	#$TBL_REPONSES           = Database::get_course_table(TABLE_QUIZ_ANSWER);
 
-		$sql="SELECT title,description,sound,type,random,active, results_disabled, max_attempt,start_time,end_time,feedback_type FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
+		$sql="SELECT title,description,sound,type,random,active, results_disabled, max_attempt,start_time,end_time,feedback_type,expired_time FROM $TBL_EXERCICES WHERE id='".Database::escape_string($id)."'";
 		$result=Database::query($sql,__FILE__,__LINE__);
 
 		// if the exercise has been found
@@ -84,7 +85,8 @@ class Exercise
 			$this->attempts = $object->max_attempt;
 			$this->feedbacktype = $object->feedback_type;
 			$this->end_time = $object->end_time;
-            $this->start_time = $object->start_time;
+      		$this->start_time = $object->start_time;
+      		$this->expired_time = $object->expired_time;
 			$sql="SELECT question_id, question_order FROM $TBL_EXERCICE_QUESTION,$TBL_QUESTIONS WHERE question_id=id AND exercice_id='".Database::escape_string($id)."' ORDER BY question_order";
 			$result=Database::query($sql,__FILE__,__LINE__);
 
@@ -375,7 +377,16 @@ class Exercise
 	{
 		$this->description=$description;
 	}
-
+  /**
+   * changes the exercise description
+   *
+   * @author - Isaac flores
+   * @param - int The expired time of the quiz
+   */
+  function updateExpiredTime($expired_time)
+  {
+    $this->expired_time = $expired_time;
+  }
 	/**
 	 * changes the exercise sound file
 	 *
@@ -511,7 +522,8 @@ class Exercise
 		$random = $this->random;
 		$active = $this->active;
 		$session_id = api_get_session_id();
-
+    	$expired_time = $this->expired_time;
+    
 		if ($feedbacktype==1){
 			$results_disabled = 1;
 		} else {
@@ -536,8 +548,9 @@ class Exercise
 						active='".Database::escape_string($active)."',
 						feedback_type='".Database::escape_string($feedbacktype)."',
 						start_time='$start_time',end_time='$end_time',
-						max_attempt='".Database::escape_string($attempts)."', " .
-						"results_disabled='".Database::escape_string($results_disabled)."'";
+						max_attempt='".Database::escape_string($attempts)."',
+            			expired_time='".Database::escape_string($expired_time)."',
+						results_disabled='".Database::escape_string($results_disabled)."'";
 				}
 			$sql .= " WHERE id='".Database::escape_string($id)."'";
 
@@ -935,29 +948,44 @@ class Exercise
 			$form -> addGroup($random,null,get_lang('RandomQuestions'),'<br />');
 
 			$attempt_option=range(0,10);
-	        $attempt_option[0]=get_lang('Infinite');
-
-	        $form -> addElement('select', 'exerciseAttempts',get_lang('ExerciseAttempts'),$attempt_option);
+	    $attempt_option[0]=get_lang('Infinite');
 
-	        $form -> addElement('checkbox', 'enabletimelimit',get_lang('EnableTimeLimits'),null,'onclick = "  return timelimit() "');
+	    $form -> addElement('select', 'exerciseAttempts',get_lang('ExerciseAttempts'),$attempt_option);
 
-			$var= Exercise::selectTimeLimit();
-
-			$form -> addElement('html','</div>');
+	    $form -> addElement('checkbox', 'enabletimelimit',get_lang('EnableTimeLimits'),null,'onclick = "  return timelimit() "');
+      $var= Exercise::selectTimeLimit();
 
 			if(($this -> start_time!='0000-00-00 00:00:00')||($this -> end_time!='0000-00-00 00:00:00'))
 				$form -> addElement('html','<div id="options2" style="display:block;">');
 			else
 				$form -> addElement('html','<div id="options2" style="display:none;">');
 
-	        //$form -> addElement('date', 'start_time', get_lang('ExeStartTime'), array('language'=>'es','format' => 'dMYHi'));
-	        //$form -> addElement('date', 'end_time', get_lang('ExeEndTime'), array('language'=>'es','format' => 'dMYHi'));
-	        $form->addElement('datepicker', 'start_time', get_lang('ExeStartTime'), array('form_name'=>'exercise_admin'));
+	    //$form -> addElement('date', 'start_time', get_lang('ExeStartTime'), array('language'=>'es','format' => 'dMYHi'));
+	    //$form -> addElement('date', 'end_time', get_lang('ExeEndTime'), array('language'=>'es','format' => 'dMYHi'));
+	    $form->addElement('datepicker', 'start_time', get_lang('ExeStartTime'), array('form_name'=>'exercise_admin'));
 			$form->addElement('datepicker', 'end_time', get_lang('ExeEndTime'), array('form_name'=>'exercise_admin'));
-
-			//$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));
-			$form -> addElement('html','</div>');
-
+       
+       //Timer control
+      $time_hours_option = range(0,12);
+      $time_minutes_option = range(0,59);
+      $form -> addElement('checkbox', 'enabletimercontrol',get_lang('EnableTimerControl'),null,'onclick = "option_time_expired()"');      
+      $expired_date = (int)$this->selectExpiredTime();
+
+      if(($expired_date!='0')) {
+        $form -> addElement('html','<div id="timercontrol" style="display:block;">');
+      } else {
+        $form -> addElement('html','<div id="timercontrol" style="display:none;">');
+      }
+      $form -> addElement('text', 'enabletimercontroltotalminutes',get_lang('ExerciseTimerControlTotalMinutes'),array('style' => 'width : 35px'));
+      //$form -> addElement('select', 'enabletimercontroltotalminutes',get_lang('ExerciseTimerControlMinutes'),$time_minutes_option);
+      $form -> addElement('html','</div>');
+           
+      $form -> addElement('html','</div>');
+			//$form -> addElement('text', 'exerciseAttempts', get_lang('ExerciseAttempts').' : ',array('size'=>'2'));        
+      
+      $form -> addElement('html','</div>');  //End advanced setting
+  
+               
 	        $defaults = array();
 
 	        if (api_get_setting('search_enabled') === 'true') {
@@ -1020,8 +1048,16 @@ class Exercise
 	            	$defaults['enabletimelimit'] = 1;
 
 			    $defaults['start_time'] = ($this->start_time!='0000-00-00 00:00:00')? $this -> start_time : date('Y-m-d 12:00:00');
-	            $defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00')?$this -> end_time : date('Y-m-d 12:00:00',time()+84600);
-
+	        $defaults['end_time'] = ($this->end_time!='0000-00-00 00:00:00')?$this -> end_time : date('Y-m-d 12:00:00',time()+84600);
+          
+          //Get expired time
+          if($this -> expired_time != '0') {
+            $defaults['enabletimercontrol'] = 1;
+          	$defaults['enabletimercontroltotalminutes'] = $this -> expired_time;
+          } else {
+          	$defaults['enabletimercontroltotalminutes'] = 0;
+          }
+                
 			} else {
 				$defaults['exerciseType'] = 2;
 				$defaults['exerciseAttempts'] = 0;
@@ -1059,20 +1095,27 @@ class Exercise
 		$this -> updateType($form -> getSubmitValue('exerciseType'));
 		$this -> setRandom($form -> getSubmitValue('randomQuestions'));
 		$this -> updateResultsDisabled($form -> getSubmitValue('results_disabled'));
-
-		if($form -> getSubmitValue('enabletimelimit')==1)
-        {
+    $this -> updateExpiredTime($form -> getSubmitValue('enabletimercontroltotalminutes'));
+		if($form -> getSubmitValue('enabletimelimit')==1) {
            $start_time = $form -> getSubmitValue('start_time');
            $this->start_time = $start_time['Y'].'-'.$start_time['F'].'-'.$start_time['d'].' '.$start_time['H'].':'.$start_time['i'].':00';
            $end_time = $form -> getSubmitValue('end_time');
            $this->end_time = $end_time['Y'].'-'.$end_time['F'].'-'.$end_time['d'].' '.$end_time['H'].':'.$end_time['i'].':00';
-        }
-          else
-  		{
+    } else {
            $this->start_time = '0000-00-00 00:00:00';
            $this->end_time = '0000-00-00 00:00:00';
         }
-        //echo $end_time;exit;
+
+    if($form -> getSubmitValue('enabletimercontrol') == 1) {
+           $expired_total_time = $form -> getSubmitValue('enabletimercontroltotalminutes');
+           if ($this->expired_time == 0) {
+               $this->expired_time = $expired_total_time;                    	
+           }
+
+    } else {
+           $this->expired_time = 0;
+        }
+                
         $this -> save($type);
 	}
 
@@ -1248,7 +1291,9 @@ class Exercise
 		    delete_all_values_for_item($course_id, TOOL_QUIZ, $this->id);
 	    }
     }
-
+  function selectExpiredTime() {
+  	   return $this->expired_time;
+  }
 }
 
 endif;

+ 8 - 0
main/exercice/exercise_admin.php

@@ -83,6 +83,14 @@ $htmlHeadXtra[] = '<script>
 				document.exercise_admin.exerciseType[0].disabled=false;
 			}
 		}
+              
+    function option_time_expired() {
+      if(document.getElementById(\'timercontrol\').style.display == \'none\') {
+        document.getElementById(\'timercontrol\').style.display = \'block\';
+      } else {
+        document.getElementById(\'timercontrol\').style.display = \'none\';
+      }
+    }               
 		</script>';
 
 /*********************

+ 1 - 1
main/exercice/hotspot_admin.inc.php

@@ -256,7 +256,7 @@ if($modifyAnswers)
 
 ?>
 
-<form method="post" action="<?php echo api_get_self(); ?>?hotspotadmin=<?php echo $modifyAnswers; ?>" name="frm_exercise">
+<form method="post" action="<?php echo api_get_self(); ?>?hotspotadmin=<?php echo $modifyAnswers; ?>" id="frm_exercise" name="frm_exercise">
 <table border="0" cellpadding="0" cellspacing="2" width="100%">
 	<tr>
 		<td colspan="2" valign="bottom">

+ 1 - 0
main/inc/lib/add_course.lib.inc.php

@@ -628,6 +628,7 @@ function update_Db_course($courseDbName)
 		start_time datetime NOT NULL default '0000-00-00 00:00:00',
 		end_time datetime NOT NULL default '0000-00-00 00:00:00',
 		feedback_type int NOT NULL default 0,
+    expired_time int NOT NULL default '0',
 		session_id smallint default 0,
 		PRIMARY KEY (id)
 		)";

+ 8 - 4
main/inc/lib/events.lib.inc.php

@@ -36,7 +36,6 @@ $TABLETRACK_DEFAULT = $_configuration['statistics_database'].".track_e_default";
 		FUNCTIONS
 ==============================================================================
 */
-
 /**
  * @author Sebastien Piraux <piraux_seb@hotmail.com>
  * @desc Record information for open event (when homepage is opened)
@@ -446,11 +445,16 @@ function create_event_exercice($exo_id)
 		$row = Database::fetch_array($sql);
 		return $row['exe_id'];
 	}
-
-	$sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id )
-			VALUES (  ".$user_id.",  '".$_cid."' )";
+    if (isset($_SESSION['expired_time'])) {
+    	$expired_date = $_SESSION['expired_time'];
+    } else {
+    	$expired_date = '0000-00-00 00:00:00';
+    }
+	$sql = "INSERT INTO $TABLETRACK_EXERCICES ( exe_user_id, exe_cours_id,expired_time_control,exe_exo_id)
+			VALUES (  ".$user_id.",  '".$_cid."' ,'".$expired_date."','".$exo_id."')";
 	$res = @Database::query($sql,__FILE__,__LINE__);
 	$id= Database::insert_id();
+  unset($_SESSION['expired_time']);
 	return $id;
 }
 

File diff suppressed because it is too large
+ 8 - 0
main/inc/lib/javascript/jquery.epiclock.min.js


+ 1 - 1
main/install/dokeos_stats.sql

@@ -113,7 +113,7 @@ ALTER TABLE track_e_exercices ADD INDEX ( session_id ) ;
 ALTER TABLE track_e_exercices ADD orig_lp_id int  NOT NULL default 0;
 ALTER TABLE track_e_exercices ADD orig_lp_item_id int  NOT NULL default 0;
 ALTER TABLE track_e_exercices ADD exe_duration int UNSIGNED NOT NULL default 0;
-  
+ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
 
 CREATE TABLE track_e_attempt (
   exe_id int default NULL,

+ 2 - 0
main/install/migrate-db-1.8.6.1-1.8.6.2-pre.sql

@@ -40,6 +40,7 @@ CREATE TABLE user_rel_tag (id int NOT NULL auto_increment,user_id int NOT NULL,t
 
 
 -- xxSTATSxx
+ALTER TABLE track_e_exercices ADD COLUMN expired_time_control datetime NOT NULL DEFAULT '0000-00-00 00:00:00';
 
 -- xxUSERxx
 
@@ -55,3 +56,4 @@ ALTER TABLE tool ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id
 ALTER TABLE link_category ADD COLUMN session_id smallint DEFAULT 0, ADD INDEX (session_id);
 ALTER TABLE item_property ADD id_session INT NOT NULL DEFAULT 0;
 ALTER TABLE item_property DROP INDEX idx_item_property_toolref, ADD INDEX idx_item_property_toolref (tool, ref, id_session); 
+ALTER TABLE quiz ADD COLUMN expired_time int NOT NULL DEFAULT '0' AFTER feedback_type;

Some files were not shown because too many files changed in this diff