@ -24,9 +24,6 @@
* Adding reminder + ajax support (2011)
* Modified by hubert.borderiou (2011-10-21 question category)
*/
/**
* Code
*/
use \ChamiloSession as Session;
@ -43,7 +40,10 @@ require_once 'exercise.lib.php';
$this_section = SECTION_COURSES;
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.
api_protect_course_script(true);
@ -51,8 +51,8 @@ api_protect_course_script(true);
$is_allowedToEdit = api_is_allowed_to_edit(null,true);
if (api_get_setting('show_glossary_in_extra_tools') == 'true') {
$htmlHeadXtra[] = api_get_js('glossary.js'); //Glossary
$htmlHeadXtra[] = api_get_js('jquery.highlight.js'); //highlight
$htmlHeadXtra[] = api_get_js('glossary.js');
$htmlHeadXtra[] = api_get_js('jquery.highlight.js');
}
//This library is necessary for the time control feature
@ -64,14 +64,14 @@ $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
// 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;
$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;
$learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0;
$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
$reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
$remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
$exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
$formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
$exerciseResult = isset($_REQUEST['exerciseResult']) ? $_REQUEST['exerciseResult'] : null;
@ -90,7 +90,9 @@ $error = '';
//Table calls
$exercice_attemp_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
/* 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 ) {
Session::erase('objExercise');
}
@ -104,13 +106,15 @@ if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUES
unset($_SESSION['questionList']);
// 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')
) {
if ($debug) {error_log('1.1. Error while reading the exercise'); };
unset ($objExercise);
$error = get_lang('ExerciseNotFound');
} else {
// 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'); };
}
}
@ -128,8 +132,7 @@ if (!is_object($objExercise)) {
exit;
}
//if reminder ends we jump to the exercise_reminder
// If reminder ends we jump to the exercise_reminder
if ($objExercise->review_answers) {
if ($remind_question_id == -1) {
header('Location: exercise_reminder.php?origin='.$origin.'&exerciseId='.$exerciseId);
@ -137,8 +140,8 @@ if ($objExercise->review_answers) {
}
}
$current_timestamp = time();
$my_remind_list = array();
$current_timestamp = time();
$my_remind_list = array();
$time_control = false;
if ($objExercise->expired_time != 0) {
@ -159,7 +162,13 @@ $show_clock = true;
$user_id = api_get_user_id();
if ($objExercise->selectAttempts() > 0) {
$attempt_html = '';
$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
);
if ($attempt_count >= $objExercise->selectAttempts()) {
$show_clock = false;
@ -167,8 +176,13 @@ if ($objExercise->selectAttempts() > 0) {
if ($objExercise->results_disabled == 0 & & $origin != 'learnpath') {
//Showing latest attempt according with task BT#1628
$exercise_stat_info = get_exercise_results_by_user($user_id, $exerciseId, api_get_course_id(), api_get_session_id());
// Showing latest attempt according with task BT#1628
$exercise_stat_info = get_exercise_results_by_user(
$user_id,
$exerciseId,
api_get_course_id(),
api_get_session_id()
);
if (!empty($exercise_stat_info)) {
$max_exe_id = max(array_keys($exercise_stat_info));
@ -213,11 +227,12 @@ if ($objExercise->selectAttempts() > 0) {
}
}
if ($debug) { error_log("4. Setting the exe_id: $exe_id");} ;
if ($debug) {
error_log("4. Setting the exe_id: $exe_id");
}
//5. Getting user exercise info (if the user took the exam before) - generating exe_id
// 5. Getting user exercise info (if the user took the exam before) - generating exe_id
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
$clock_expired_time = null;
if (empty($exercise_stat_info)) {
@ -242,15 +257,26 @@ if (empty($exercise_stat_info)) {
$_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
}
$exe_id = $objExercise->save_stat_track_exercise_info($clock_expired_time, $learnpath_id, $learnpath_item_id, $learnpath_item_view_id, $questionList, $total_weight);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info($learnpath_id, $learnpath_item_id, $learnpath_item_view_id);
$exe_id = $objExercise->save_stat_track_exercise_info(
$clock_expired_time,
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id,
$questionList,
$total_weight
);
$exercise_stat_info = $objExercise->get_stat_track_exercise_info(
$learnpath_id,
$learnpath_item_id,
$learnpath_item_view_id
);
if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
} else {
$exe_id = $exercise_stat_info['exe_id'];
if ($debug) error_log("5 exercise_stat_info[] exists getting exe_id $exe_id ");
}
//Array to check in order to block the chat
// Array to check in order to block the chat
create_chat_exercise_session($exe_id);
if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); };
@ -274,7 +300,6 @@ if ($reminder == 2 && empty($my_remind_list)) {
* 7. Loading Time control parameters
* If the expired time is major that zero(0) then the expired time is compute on this time.
*/
if ($time_control) {
if ($debug) error_log('7.1. Time control is enabled');
if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
@ -286,10 +311,12 @@ if ($time_control) {
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'];
if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
//Get the last attempt of an exercic e
// Get the last attempt of an exercis e
$last_attempt_date = get_last_attempt_date_of_exercise($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)) {
$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);
@ -311,13 +338,14 @@ if ($time_control) {
if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
// First we update the attempt to today
// 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 */
$sql = "UPDATE $exercice_attemp_table SET
tms = '".api_get_utc_datetime()."'
WHERE
exe_id = '".$exercise_stat_info['exe_id']."' AND
tms = '".$last_attempt_date."' ";
if ($debug) {error_log('7.10. $sql_track_e_exe2 : '.$sql_track_e_exe ); }
if ($debug) {error_log('7.10. $sql: '.$sql); }
Database::query($sql);
//Sessions that contain the expired time
@ -437,7 +465,6 @@ if ($formSent && isset($_POST)) {
if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); }
}
// the script "exercise_result.php" will take the variable $exerciseResult from the session
Session::write('exerciseResult', $exerciseResult);
Session::write('remind_list', $remind_list);
@ -502,8 +529,7 @@ if ($formSent && isset($_POST)) {
if ($debug) { error_log('9. $formSent was NOT sent'); }
}
// if questionNum comes from POST and not from GET
// If questionNum comes from POST and not from GET
if (!$current_question || $_REQUEST['num']) {
if (!$current_question) {
$current_question = 1;
@ -513,7 +539,9 @@ if (!$current_question || $_REQUEST['num']) {
}
if ($question_count != 0) {
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()) {
// goes to the script that will show the result of the exercise
if ($objExercise->type == ALL_ON_ONE_PAGE) {
@ -628,9 +656,9 @@ if ($is_visible_return['value'] == false) {
$limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
if ($limit_time_exists) {
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time();
$exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
$exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
$time_now = time();
if ($objExercise->start_time != '0000-00-00 00:00:00') {
$permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
@ -662,9 +690,17 @@ if ($limit_time_exists) {
// Blocking empty start times see BT#2800
global $_custom;
if (isset($_custom['exercises_hidden_when_no_start_date']) & & $_custom['exercises_hidden_when_no_start_date']) {
if (isset($_custom['exercises_hidden_when_no_start_date']) & &
$_custom['exercises_hidden_when_no_start_date']
) {
if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') {
Display :: display_warning_message(sprintf(get_lang('ExerciseNoStartedYet'), $exercise_title, $objExercise->selectAttempts()));
Display:: display_warning_message(
sprintf(
get_lang('ExerciseNoStartedYet'),
$exercise_title,
$objExercise->selectAttempts()
)
);
if ($origin != 'learnpath') {
Display :: display_footer();
}
@ -677,7 +713,6 @@ if ($time_control) {
echo '< div style = "display:none" class = "warning-message" id = "expired-message-id" > '.get_lang('ExerciceExpiredTimeMessage').'< / div > ';
}
if (!empty($objExercise->description)) {
echo "< script >
$(function() {
@ -718,7 +753,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1;
} else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please
// We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1;
$current_question = $i + 1; // last question
}
break 2;
@ -730,7 +766,8 @@ if ($reminder == 2) {
$remind_question_id = $my_remind_list[$j+1];
$current_question = $i + 1; // last question
} else {
$remind_question_id = -1; //We end the remind list we go to the exercise_reminder.php please
// We end the remind list we go to the exercise_reminder.php please
$remind_question_id = -1;
$current_question = $i + 1; // last question
}
break 2;
@ -745,7 +782,6 @@ if ($reminder == 2) {
exit;
}
}
//var_dump($remind_question_id, $my_remind_list, $data_tracking, $current_question);
}
if ($objExercise->review_answers) {
@ -981,7 +1017,7 @@ if (!empty($error)) {
< input type = "hidden" name = "learnpath_item_id" value = "'.$learnpath_item_id . '" / >
< input type = "hidden" name = "learnpath_item_view_id" value = "'.$learnpath_item_view_id . '" / > ';
//Show list of questions
// Show list of questions
$i = 1;
$attempt_list = array();
@ -1040,32 +1076,44 @@ if (!empty($error)) {
$remind_highlight = ' remind_highlight ';
}
//Showing the question
// Showing the question
echo '< div id = "question_div_'.$questionId.'" class = "main_question '.$remind_highlight.'" > ';
// Shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
//BU tton save and continue
switch ($objExercise->type) {
case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question);
break;
case ALL_ON_ONE_PAGE :
$button = '< a href = "javascript://" class = "btn" onclick = "save_now(\''.$questionId.'\'); " > '.get_lang('SaveForNow').'< / a > ';
$button .= '< span id = "save_for_now_'.$questionId.'" > < / span > ';
$exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
break;
}
// Shows the question and its answers
showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
// Bu tton save and continue
switch ($objExercise->type) {
case ONE_PER_PAGE:
$exercise_actions .= $objExercise->show_button($questionId, $current_question);
break;
case ALL_ON_ONE_PAGE :
$button = '< a href = "javascript://" class = "btn" onclick = "save_now(\''.$questionId.'\'); " > '.get_lang('SaveForNow').'< / a > ';
$button .= '< span id = "save_for_now_'.$questionId.'" > < / span > ';
$exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
break;
}
//Checkbox review answers
if ($objExercise->review_answers) {
$remind_question_div = Display::tag('label', Display::input('checkbox', 'remind_list['.$questionId.']', '', $attributes).get_lang('ReviewQuestionLater'), array('class' => 'checkbox', 'for' =>'remind_list['.$questionId.']'));
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
}
echo Display::div($exercise_actions, array('class'=>'form-actions'));
echo '< / div > ';
// Checkbox review answers
if ($objExercise->review_answers) {
$remind_question_div = Display::tag(
'label',
Display::input(
'checkbox',
'remind_list[' . $questionId . ']',
'',
$attributes
) . get_lang('ReviewQuestionLater'),
array(
'class' => 'checkbox',
'for' => 'remind_list[' . $questionId . ']'
)
);
$exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
}
echo Display::div($exercise_actions, array('class'=>'form-actions'));
echo '< / div > ';
$i++;
// for sequential exercises
@ -1083,7 +1131,7 @@ if (!empty($error)) {
}
if ($origin != 'learnpath') {
//s o we are not in learnpath tool
// S o we are not in learnpath tool
echo '< / div > '; //End glossary div
Display :: display_footer();
} else {