Fixing exercise sessions

skala
Julio Montoya 12 years ago
parent fd7b2bb5e1
commit e4ccd1cff1
  1. 3
      main/exercice/exercise.class.php
  2. 2
      main/exercice/exercise_reminder.php
  3. 162
      main/exercice/exercise_submit.php
  4. 22
      main/inc/ajax/exercise.ajax.php

@ -2658,6 +2658,7 @@ class Exercise
send_form(); send_form();
} }
}); });
$('#clock_warning').dialog('open'); $('#clock_warning').dialog('open');
$('#counter_to_redirect').epiclock({ $('#counter_to_redirect').epiclock({
@ -2674,7 +2675,7 @@ class Exercise
if ($('#exercise_form').length) { if ($('#exercise_form').length) {
$('#exercise_form').submit(); $('#exercise_form').submit();
} else { } else {
//In reminder // In reminder
final_submit(); final_submit();
} }
} }

@ -111,7 +111,7 @@ echo '<script>
lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'}); lp_data = $.param({"learnpath_id": '.$learnpath_id.', "learnpath_item_id" : '.$learnpath_item_id.', "learnpath_item_view_id": '.$learnpath_item_view_id.'});
function final_submit() { function final_submit() {
//Normal inputs // Normal inputs
window.location = "'.$urlMainExercise.'exercise_result.php?origin='.$origin.'&exe_id='.$exe_id.'&" + lp_data; window.location = "'.$urlMainExercise.'exercise_result.php?origin='.$origin.'&exe_id='.$exe_id.'&" + lp_data;
} }

@ -43,8 +43,11 @@ $current_course_tool = TOOL_QUIZ;
$nameTools = get_lang('Quiz'); $nameTools = get_lang('Quiz');
$this_section = SECTION_COURSES; $this_section = SECTION_COURSES;
$debug = true;
if ($debug) { error_log('--- Enter to the exercise_submit.php ---- '); error_log('0. POST variables : '.print_r($_POST,1)); } if ($debug) {
error_log('--- Enter to the exercise_submit.php ---- ');
error_log('0. POST variables : '.print_r($_POST,1));
}
// Notice for unauthorized people. // Notice for unauthorized people.
api_protect_course_script(true); api_protect_course_script(true);
@ -311,35 +314,48 @@ $(function(){
// General parameters passed via POST/GET // General parameters passed via POST/GET
$learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0; /*
$learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0; <input type="hidden" name="formSent" value="1" />
$learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0; <input type="hidden" name="exerciseId" value="'.$exerciseId . '" />
$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : ''; <input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" />
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0; <input type="hidden" name="exe_id" value="'.$exe_id . '" />
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0; <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 . '" />
<input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id . '" />';*/
// @todo check get and posts
$learnpath_id = isset($_GET['learnpath_id']) ? intval($_GET['learnpath_id']) : 0;
$learnpath_item_id = isset($_GET['learnpath_item_id']) ? intval($_GET['learnpath_item_id']) : 0;
$learnpath_item_view_id = isset($_GET['learnpath_item_view_id']) ? intval($_GET['learnpath_item_view_id']) : 0;
$origin = isset($_GET['origin']) ? Security::remove_XSS($_GET['origin']) : '';
$reminder = isset($_GET['reminder']) ? intval($_GET['reminder']) : 0;
$remind_question_id = isset($_GET['remind_question_id']) ? intval($_GET['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0; $exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null; $formSent = isset($_POST['formSent']) ? $_POST['formSent'] : null;
$exerciseResult = isset($_REQUEST['exerciseResult']) ? $_REQUEST['exerciseResult'] : null; $exerciseResult = isset($_GET['exerciseResult']) ? $_GET['exerciseResult'] : null;
$choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null; $choice = isset($_GET['choice']) ? $_GET['choice'] : null;
$choice = empty($choice) ? isset($_REQUEST['choice2']) ? $_REQUEST['choice2'] : null : null; $choice = empty($choice) ? isset($_GET['choice2']) ? $_GET['choice2'] : null : null;
$exerciseResultCoordinates = isset($_REQUEST['exerciseResultCoordinates']) ? $_REQUEST['exerciseResultCoordinates'] : null; $exerciseResultCoordinates = isset($_GET['exerciseResultCoordinates']) ? $_GET['exerciseResultCoordinates'] : null;
$current_question = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null; $current_question = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null;
//Error message //Error message
$error = ''; $error = '';
/* Teacher takes an exam and want to see a preview, we delete the objExercise from the session in order to get the latest changes in the exercise */ /* Teacher takes an exam and want to see a preview,
we delete the objExercise from the session in order to get the latest changes in the exercise */
if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['preview'] == 1) { if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['preview'] == 1) {
Session::erase('objExercise'); Session::erase('objExercise');
} }
$exerciseInSession = Session::read('objExercise');
// 1. Loading the $objExercise variable // 1. Loading the $objExercise variable
if (!isset($_SESSION['objExercise']) || isset($_SESSION['objExercise']) && ($_SESSION['objExercise']->id != $_REQUEST['exerciseId'])) { if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) {
// Construction of Exercise // Construction of Exercise
/** @var Exercise $objExercise */ /** @var Exercise $objExercise */
$objExercise = new Exercise(); $objExercise = new Exercise();
if ($debug) {error_log('1. Setting the $objExercise variable'); }; if ($debug) {error_log('1. Setting the $objExercise variable'); };
unset($_SESSION['questionList']); Session::erase('questionList');
// if the specified exercise doesn't exist or is disabled // if the specified exercise doesn't exist or is disabled
if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) { if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) {
@ -349,21 +365,25 @@ if (!isset($_SESSION['objExercise']) || isset($_SESSION['objExercise']) && ($_SE
} else { } else {
// Saves the object into the session // Saves the object into the session
Session::write('objExercise', $objExercise); Session::write('objExercise', $objExercise);
if ($debug) { error_log('1.1. $_SESSION[objExercise] was unset - set now - end'); }; if ($debug) {
error_log('1.1. $exerciseInSession was unset - set now - end');
};
} }
} }
// $objExercise = new Exercise(); $objExercise->read($exerciseId); // $objExercise = new Exercise(); $objExercise->read($exerciseId);
//2. Checking if $objExercise is set //2. Checking if $objExercise is set
if (!isset($objExercise) && isset($_SESSION['objExercise'])) { if (!isset($objExercise) && isset($exerciseInSession)) {
if ($debug) { error_log('2. Loading $objExercise from session'); }; if ($debug) { error_log('2. Loading $objExercise from session'); };
$objExercise = $_SESSION['objExercise']; $objExercise = $exerciseInSession;
} }
//3. $objExercise is not set, then return to the exercise list //3. $objExercise is not set, then return to the exercise list
if (!is_object($objExercise)) { if (!is_object($objExercise)) {
if ($debug) {error_log('3. $objExercise was not set, kill the script'); }; if ($debug) {
error_log('3. $objExercise was not set, kill the script');
};
header('Location: '.$urlMainExercise.'exercice.php'); header('Location: '.$urlMainExercise.'exercice.php');
exit; exit;
} }
@ -374,7 +394,7 @@ if ($objExercise->review_answers) {
$paramsReminder = "exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq(); $paramsReminder = "exerciseId=$exerciseId&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id&".api_get_cidreq();
header('Location: '.$urlMainExercise.'exercise_reminder.php?'.$paramsReminder); header('Location: '.$urlMainExercise.'exercise_reminder.php?'.$paramsReminder);
exit; exit;
} }
} }
$current_timestamp = time(); $current_timestamp = time();
@ -388,10 +408,15 @@ if ($objExercise->expired_time != 0) {
//Generating the time control key for the user //Generating the time control key for the user
$current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id); $current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
if ($debug) { if ($debug) {
error_log("4. current_expired_time_key: $current_expired_time_key "); error_log("4. current_expired_time_key: $current_expired_time_key");
} }
$_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp; $durationTime = array(
$current_expired_time_key => $current_timestamp
);
Session::write('duration_time', $durationTime);
//$_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
if ($time_control) { if ($time_control) {
// Get the expired time of the current exercise in track_e_exercices. // Get the expired time of the current exercise in track_e_exercices.
@ -407,20 +432,33 @@ if ($objExercise->selectAttempts() > 0) {
$attempt_html = null; $attempt_html = null;
$attempt_count = get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $attempt_count = get_attempt_count($user_id, $exerciseId, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
$warningMessage = Display::return_message(
sprintf(get_lang('ReachedMaxAttempts'),
$exercise_title,
$objExercise->selectAttempts()),
'warning',
false
);
if ($attempt_count >= $objExercise->selectAttempts()) { if ($attempt_count >= $objExercise->selectAttempts()) {
$show_clock = false; $show_clock = false;
if (!api_is_allowed_to_edit(null,true)) { if (!api_is_allowed_to_edit(null,true)) {
if ($objExercise->results_disabled == 0 && $origin != 'learnpath') { if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
//Showing latest attempt according with task BT#1628 // Showing latest attempt according with task BT#1628.
$exercise_stat_info = getExerciseResultsByUser($user_id, $exerciseId, api_get_course_int_id(), api_get_session_id()); $exercise_stat_info = getExerciseResultsByUser(
$user_id,
$exerciseId,
api_get_course_int_id(),
api_get_session_id()
);
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
$max_exe_id = max(array_keys($exercise_stat_info)); $max_exe_id = max(array_keys($exercise_stat_info));
$last_attempt_info = $exercise_stat_info[$max_exe_id]; $last_attempt_info = $exercise_stat_info[$max_exe_id];
$attempt_html .= Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>'')); $attempt_html .= Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>''));
$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); $attempt_html .= $warningMessage;
if (!empty($last_attempt_info['question_list'])) { if (!empty($last_attempt_info['question_list'])) {
foreach($last_attempt_info['question_list'] as $question_data) { foreach($last_attempt_info['question_list'] as $question_data) {
@ -435,13 +473,13 @@ if ($objExercise->selectAttempts() > 0) {
$score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']); $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
$attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score')); $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
} else { } else {
$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); $attempt_html .= $warningMessage;
} }
} else { } else {
$attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); $attempt_html .= $warningMessage;
} }
} else { } else {
$attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false); $attempt_html .= $warningMessage;
} }
if ($origin == 'learnpath') { if ($origin == 'learnpath') {
@ -462,7 +500,8 @@ if ($objExercise->selectAttempts() > 0) {
$exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
//if (1) { //if (1) {
if (!isset($_SESSION['questionList'])) { $questionListInSession = Session::read('questionList');
if (!isset($questionListInSession)) {
// Selects the list of question ID // Selects the list of question ID
$questionList = $objExercise->getQuestionList(); $questionList = $objExercise->getQuestionList();
@ -476,7 +515,7 @@ if (!isset($_SESSION['questionList'])) {
Session::write('questionList', $questionList); Session::write('questionList', $questionList);
if ($debug > 0) { error_log('$_SESSION[questionList] was set'); } if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
} else { } else {
if (isset($objExercise) && isset($_SESSION['objExercise'])) { if (isset($objExercise) && isset($exerciseInSession)) {
$questionList = Session::read('questionList'); $questionList = Session::read('questionList');
} }
} }
@ -503,12 +542,15 @@ if (empty($exercise_stat_info)) {
if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp); if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp);
if ($debug) error_log('5.2. $expected_time '.$expected_time); if ($debug) error_log('5.2. $expected_time '.$expected_time);
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) error_log('5.3. $expected_time '.$clock_expired_time); if ($debug) error_log('5.3. $expected_time '.$clock_expired_time);
//Sessions that contain the expired time //Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $expiredTime = array(
if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; $current_expired_time_key => $clock_expired_time
);
Session::write('expired_time', $expiredTime);
if ($debug) { error_log('5.4. Setting the $expiredTime: '.$expiredTime[$current_expired_time_key] ); };
} }
$exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $questionListUncompressed, $total_weight); $exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $questionListUncompressed, $total_weight);
$exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, $learnpath_item_view_id); $exercise_stat_info = $objExercise->getStatTrackExerciseInfo($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
@ -545,26 +587,28 @@ if ($reminder == 2 && empty($my_remind_list)) {
*/ */
if ($time_control) { if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled'); $expiredTimeInSession = Session::read('expired_time');
if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]);
if (!isset($_SESSION['expired_time'][$current_expired_time_key])) { if ($debug) error_log('7.1. Time control is enabled.');
if ($debug) error_log('7.2. $current_expired_time_key:'.$current_expired_time_key);
if (!isset($expiredTimeInSession[$current_expired_time_key])) {
if ($debug) error_log('7.3. $expiredTimeInSession[$current_expired_time_key] not set.');
//Timer - Get expired_time for a student //Timer - Get expired_time for a student
if (!empty($exercise_stat_info)) { if (!empty($exercise_stat_info)) {
if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); }; if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
$expired_time_of_this_attempt = $exercise_stat_info['expired_time_control']; $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); } if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
//Get the last attempt of an exercice // Get the last attempt of an exercise.
$last_attempt_date = getLastAttemptDateOfExercise($exercise_stat_info['exe_id']); $last_attempt_date = getLastAttemptDateOfExercise($exercise_stat_info['exe_id']);
//This means that the user enters the exam but do not answer the first question we get the date from the track_e_exercises not from the track_et_attempt see #2069 /* This means that the user enters the exam but do not answer the first question we get the date
from the track_e_exercises not from the track_et_attempt see #2069 */
if (empty($last_attempt_date)) { if (empty($last_attempt_date)) {
$diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC'); $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
} else { } else {
//Recalculate the time control due #2069 //Recalculate the time control due #2069
$diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC'); $diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC');
$last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff); $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff);
} }
if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); } if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
@ -574,7 +618,7 @@ if ($time_control) {
if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); } if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
$expected_time = $current_timestamp + $new_expired_time_in_seconds; $expected_time = $current_timestamp + $new_expired_time_in_seconds;
if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); } if ($debug) {error_log('7.8. $expected_time: '.$expected_time); }
$clock_expired_time = api_get_utc_datetime($expected_time); $clock_expired_time = api_get_utc_datetime($expected_time);
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); } if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
@ -583,12 +627,16 @@ if ($time_control) {
// How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so // How the expired time is changed into "track_e_exercices" table,then the last attempt for this student should be changed too,so
ExerciseLib::update_attempt_date($exercise_stat_info['exe_id'], $last_attempt_date); ExerciseLib::update_attempt_date($exercise_stat_info['exe_id'], $last_attempt_date);
//Sessions that contain the expired time // Sessions that contain the expired time
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time; $expiredTimeInSession[$current_expired_time_key] = $clock_expired_time;
if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); }; Session::write('expired_time', $expiredTimeInSession);
if ($debug) {
error_log('7.11. Setting the $expiredTimeInSession: '.$expiredTimeInSession[$current_expired_time_key] );
};
} }
} else { } else {
$clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key]; if ($debug) error_log('7.3. $expiredTimeInSession[$current_expired_time_key]: '.$expiredTimeInSession[$current_expired_time_key]);
$clock_expired_time = $expiredTimeInSession[$current_expired_time_key];
} }
} else { } else {
if ($debug) { error_log("7. No time control"); }; if ($debug) { error_log("7. No time control"); };
@ -622,8 +670,8 @@ if ($formSent && isset($_POST)) {
} }
// Only for hot spot // Only for hot spot
if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) { if (!isset($choice) && isset($_GET['hidden_hotspot_id'])) {
$hotspot_id = (int)($_REQUEST['hidden_hotspot_id']); $hotspot_id = (int)($_GET['hidden_hotspot_id']);
$choice = array($hotspot_id => ''); $choice = array($hotspot_id => '');
} }
@ -664,18 +712,18 @@ if ($formSent && isset($_POST)) {
} }
} }
} }
if ($debug) { error_log('9.3. $choice is an array - end'); } if ($debug) { error_log('9.3. $choice is an array - end'); }
if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); } if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); }
} }
// the script "exercise_result.php" will take the variable $exerciseResult from the session // the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult',$exerciseResult); Session::write('exerciseResult', $exerciseResult);
//Session::write('remind_list', $remind_list); //Session::write('remind_list', $remind_list);
Session::write('exerciseResultCoordinates',$exerciseResultCoordinates); Session::write('exerciseResultCoordinates', $exerciseResultCoordinates);
// if all questions on one page OR if it is the last question (only for an exercise with one question per page) // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question >= $question_count)) { if (($objExercise->type == ALL_ON_ONE_PAGE || $current_question >= $question_count)) {
if (api_is_allowed_to_session_edit()) { if (api_is_allowed_to_session_edit()) {
// goes to the script that will show the result of the exercise // goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) { if ($objExercise->type == ALL_ON_ONE_PAGE) {
@ -698,7 +746,8 @@ if ($formSent && isset($_POST)) {
header("Location: ".$urlMainExercise."exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id"); header("Location: ".$urlMainExercise."exercise_result.php?".api_get_cidreq()."&exe_id=$exe_id&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id&learnpath_item_view_id=$learnpath_item_view_id");
exit; exit;
} else { } else {
//Time control is only enabled for ONE PER PAGE // Time control is only enabled for ONE PER PAGE
if (!empty($exe_id) && is_numeric($exe_id)) { if (!empty($exe_id) && is_numeric($exe_id)) {
//Verify if the current test is fraudulent //Verify if the current test is fraudulent
if (ExerciseLib::exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id)) { if (ExerciseLib::exercise_time_control_is_valid($exerciseId, $learnpath_id, $learnpath_item_id)) {
@ -1006,7 +1055,7 @@ if (!empty($error)) {
} }
if ($number_of_hotspot_questions > 0) { if ($number_of_hotspot_questions > 0) {
$onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\""; $onsubmit = " onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '" .get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."');\"";
} }
echo '<script> echo '<script>
@ -1192,8 +1241,7 @@ if (!empty($error)) {
if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) { if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) {
$remind_list = explode(',', $exercise_stat_info['questions_to_check']); $remind_list = explode(',', $exercise_stat_info['questions_to_check']);
} }
echo '<form id="exercise_form" method="post" action="'.api_get_path(WEB_PUBLIC_PATH).'main/exercice/exercise_submit.php?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=".$exerciseId .'" name="frm_exercise" '.$onsubmit.'>
echo '<form id="exercise_form" method="post" action="'.api_get_path(WEB_CODE_PATH).'exercice/exercise_submit.php?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=".$exerciseId .'" name="frm_exercise" '.$onsubmit.'>
<input type="hidden" name="formSent" value="1" /> <input type="hidden" name="formSent" value="1" />
<input type="hidden" name="exerciseId" value="'.$exerciseId . '" /> <input type="hidden" name="exerciseId" value="'.$exerciseId . '" />
<input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" /> <input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" />

@ -4,9 +4,6 @@
* Responses to AJAX calls * Responses to AJAX calls
*/ */
require_once '../global.inc.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/exercise.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/question.class.php';
require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php'; require_once api_get_path(SYS_CODE_PATH).'exercice/answer.class.php';
@ -517,8 +514,16 @@ switch ($action) {
$key = ExerciseLib::get_time_control_key($exercise_id, $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id']); $key = ExerciseLib::get_time_control_key($exercise_id, $exercise_stat_info['orig_lp_id'], $exercise_stat_info['orig_lp_item_id']);
if (isset($_SESSION['duration_time'][$key]) && !empty($_SESSION['duration_time'][$key])) { /*$durationTime = array(
$duration = $now - $_SESSION['duration_time'][$key]; 'duration_time' => array(
$key => time()
)
);*/
$durationTime = Session::read('duration_time');
if (isset($durationTime[$key]) && !empty($durationTime[$key])) {
$duration = $now - $durationTime[$key];
if (!empty($exercise_stat_info['exe_duration'])) { if (!empty($exercise_stat_info['exe_duration'])) {
$duration += $exercise_stat_info['exe_duration']; $duration += $exercise_stat_info['exe_duration'];
@ -530,7 +535,12 @@ switch ($action) {
} }
} }
$_SESSION['duration_time'][$key] = time(); $durationTime = array(
$key => time()
);
Session::write('duration_time', $durationTime);
// $_SESSION['duration_time'][$key] = time();
update_event_exercise( update_event_exercise(
$exe_id, $exe_id,

Loading…
Cancel
Save