12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394 |
- <?php
- /* For licensing terms, see /license.txt */
- use ChamiloSession as Session;
- /**
- * Exercise submission
- * This script allows to run an exercise. According to the exercise type, questions
- * can be on an unique page, or one per page with a Next button.
- *
- * One exercise may contain different types of answers (unique or multiple selection,
- * matching, fill in blanks, free answer, hot-spot).
- *
- * Questions are selected randomly or not.
- *
- * When the user has answered all questions and clicks on the button "Ok",
- * it goes to exercise_result.php
- *
- * Notice : This script is also used to show a question before modifying it by
- * the administrator
- * @package chamilo.exercise
- * @author Olivier Brouckaert
- * @author Julio Montoya <gugli100@gmail.com>
- * Fill in blank option added (2008)
- * Cleaning exercises (2010),
- * Adding hotspot delineation support (2011)
- * Adding reminder + ajax support (2011)
- * Modified by hubert.borderiou (2011-10-21 question category)
- */
- require_once __DIR__.'/../inc/global.inc.php';
- $current_course_tool = TOOL_QUIZ;
- $this_section = SECTION_COURSES;
- $debug = false;
- // Notice for unauthorized people.
- api_protect_course_script(true);
- $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
- $is_allowedToEdit = api_is_allowed_to_edit(null, true);
- $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
- $showGlossary = in_array($glossaryExtraTools, array('true', 'exercise', 'exercise_and_lp'));
- if ($origin == 'learnpath') {
- $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
- }
- if ($showGlossary) {
- $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php?add_ready=1"></script>';
- $htmlHeadXtra[] = api_get_js('jquery.highlight.js');
- }
- $htmlHeadXtra[] = api_get_js('jqueryui-touch-punch/jquery.ui.touch-punch.min.js');
- $htmlHeadXtra[] = api_get_js('jquery.jsPlumb.all.js');
- $htmlHeadXtra[] = api_get_js('d3/jquery.xcolor.js');
- //This library is necessary for the time control feature
- //tmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
- $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
- $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
- $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
- $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
- $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/css/hotspot.css">';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'annotation/js/annotation.js"></script>';
- if (api_get_setting('enable_record_audio') === 'true') {
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
- $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
- $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
- }
- $template = new Template();
- // 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_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0;
- $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;
- $exerciseResultCoordinates = isset($_REQUEST['exerciseResultCoordinates']) ? $_REQUEST['exerciseResultCoordinates'] : null;
- $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
- $choice = empty($choice) ? isset($_REQUEST['choice2']) ? $_REQUEST['choice2'] : null : null;
- //From submit modal
- $current_question = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null;
- $currentAnswer = isset($_REQUEST['num_answer']) ? intval($_REQUEST['num_answer']) : null;
- $endExercise = isset($_REQUEST['end_exercise']) && $_REQUEST['end_exercise'] == 1 ? true : false;
- // Error message
- $error = '';
- //Table calls
- $exercise_attempt_table = Database::get_main_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 */
- if (api_is_allowed_to_edit(null, true) &&
- isset($_GET['preview']) && $_GET['preview'] == 1
- ) {
- Session::erase('objExercise');
- }
- // 1. Loading the $objExercise variable
- /** @var \Exercise $exerciseInSession */
- $exerciseInSession = Session::read('objExercise');
- if (!isset($exerciseInSession) || isset($exerciseInSession) && ($exerciseInSession->id != $_GET['exerciseId'])) {
- // Construction of Exercise
- $objExercise = new Exercise();
- Session::write('firstTime', true);
- if ($debug) {
- error_log('1. Setting the $objExercise variable');
- }
- Session::erase('questionList');
- // if the specified exercise doesn't exist or is disabled
- 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);
- if ($debug) {
- error_log('1.1. $exerciseInSession was unset - set now - end');
- }
- }
- } else {
- Session::write('firstTime', false);
- }
- //2. Checking if $objExercise is set
- if (!isset($objExercise) && isset($exerciseInSession)) {
- if ($debug) {
- error_log('2. Loading $objExercise from session');
- }
- $objExercise = $exerciseInSession;
- }
- //3. $objExercise is not set, then return to the exercise list
- if (!is_object($objExercise)) {
- if ($debug) {
- error_log('3. $objExercise was not set, kill the script');
- }
- header('Location: exercise.php');
- exit;
- }
- // if the user has submitted the form
- $exercise_title = $objExercise->selectTitle();
- $exercise_sound = $objExercise->selectSound();
- // 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.'&'.api_get_cidreq());
- exit;
- }
- }
- $template->assign('shuffle_answers', $objExercise->random_answers);
- $templateName = $template->get_template('exercise/submit.js.tpl');
- $htmlHeadXtra[] = $template->fetch($templateName);
- $current_timestamp = time();
- $my_remind_list = array();
- $time_control = false;
- if ($objExercise->expired_time != 0) {
- $time_control = true;
- }
- // Generating the time control key for the user
- $current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
- $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
- if ($time_control) {
- // Get the expired time of the current exercise in track_e_exercises
- $total_seconds = $objExercise->expired_time * 60;
- }
- $show_clock = true;
- $user_id = api_get_user_id();
- if ($objExercise->selectAttempts() > 0) {
- $attempt_html = '';
- $attempt_count = Event::get_attempt_count(
- $user_id,
- $exerciseId,
- $learnpath_id,
- $learnpath_item_id,
- $learnpath_item_view_id
- );
- if ($attempt_count >= $objExercise->selectAttempts()) {
- $show_clock = false;
- if (!api_is_allowed_to_edit(null, true)) {
- if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
- // Showing latest attempt according with task BT#1628
- $exercise_stat_info = Event::getExerciseResultsByUser(
- $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));
- $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::return_message(
- sprintf(
- get_lang('ReachedMaxAttempts'),
- $exercise_title,
- $objExercise->selectAttempts()
- ),
- 'warning',
- false
- );
- if (!empty($last_attempt_info['question_list'])) {
- foreach ($last_attempt_info['question_list'] as $questions) {
- foreach ($questions as $question_data) {
- $question_id = $question_data['question_id'];
- $marks = $question_data['marks'];
- $question_info = Question::read($question_id);
- $attempt_html .= Display::div(
- $question_info->question,
- array('class' => 'question_title')
- );
- $attempt_html .= Display::div(
- get_lang('Score').' '.$marks,
- array('id' => 'question_question_titlescore')
- );
- }
- }
- }
- $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')
- );
- } else {
- $attempt_html .= Display::return_message(
- sprintf(
- get_lang('ReachedMaxAttempts'),
- $exercise_title,
- $objExercise->selectAttempts()
- ),
- 'warning',
- false
- );
- }
- } else {
- $attempt_html .= Display::return_message(
- sprintf(
- get_lang('ReachedMaxAttempts'),
- $exercise_title,
- $objExercise->selectAttempts()
- ),
- 'warning',
- false
- );
- }
- } else {
- $attempt_html .= Display::return_message(
- sprintf(
- get_lang('ReachedMaxAttempts'),
- $exercise_title,
- $objExercise->selectAttempts()
- ),
- 'warning',
- false
- );
- }
- if ($origin == 'learnpath') {
- Display :: display_reduced_header();
- } else {
- Display :: display_header(get_lang('Exercises'));
- }
- echo $attempt_html;
- if ($origin != 'learnpath') {
- Display:: display_footer();
- }
- exit;
- }
- }
- /* 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
- );
- // Fix in order to get the correct question list.
- $questionListUncompressed = $objExercise->getQuestionListWithMediasUncompressed();
- Session::write('question_list_uncompressed', $questionListUncompressed);
- $clock_expired_time = null;
- if (empty($exercise_stat_info)) {
- if ($debug) {
- error_log('5 $exercise_stat_info is empty ');
- }
- $total_weight = 0;
- $questionList = $objExercise->get_validated_question_list();
- foreach ($questionListUncompressed as $question_id) {
- $objQuestionTmp = Question::read($question_id);
- $total_weight += floatval($objQuestionTmp->weighting);
- }
- if ($time_control) {
- $expected_time = $current_timestamp + $total_seconds;
- if ($debug) {
- error_log('5.1. $current_timestamp '.$current_timestamp);
- }
- if ($debug) {
- error_log('5.2. $expected_time '.$expected_time);
- }
- $clock_expired_time = api_get_utc_datetime($expected_time);
- if ($debug) {
- error_log('5.3. $expected_time '.$clock_expired_time);
- }
- //Sessions that contain the expired time
- $_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
- );
- // Send notification at the start
- if (!api_is_allowed_to_edit(null, true) &&
- !api_is_excluded_user_type()
- ) {
- $objExercise->send_mail_notification_for_exam(
- 'start',
- [],
- $origin,
- $exe_id
- );
- }
- if ($debug) {
- error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
- }
- } else {
- $exe_id = $exercise_stat_info['exe_id'];
- // Remember last question id position.
- $isFirstTime = Session::read('firstTime');
- if ($isFirstTime && $objExercise->type == ONE_PER_PAGE) {
- $resolvedQuestions = Event::getAllExerciseEventByExeId($exe_id);
- if (!empty($resolvedQuestions) &&
- !empty($exercise_stat_info['data_tracking'])
- ) {
- $last = current(end($resolvedQuestions));
- $attemptQuestionList = explode(',', $exercise_stat_info['data_tracking']);
- $count = 1;
- foreach ($attemptQuestionList as $question) {
- if ($last['question_id'] == $question) {
- break;
- }
- $count++;
- }
- $current_question = $count;
- }
- }
- if ($debug) {
- error_log("5 exercise_stat_info[] exists getting exe_id $exe_id ");
- }
- }
- $questionListInSession = Session::read('questionList');
- if (!isset($questionListInSession)) {
- // Selects the list of question ID
- $questionList = $objExercise->getQuestionList();
- // Media questions.
- $media_is_activated = $objExercise->mediaIsActivated();
- //Getting order from random
- if ($media_is_activated == false &&
- $objExercise->isRandom() &&
- isset($exercise_stat_info) &&
- !empty($exercise_stat_info['data_tracking'])
- ) {
- $questionList = explode(',', $exercise_stat_info['data_tracking']);
- }
- Session::write('questionList', $questionList);
- if ($debug > 0) {
- error_log('$_SESSION[questionList] was set');
- }
- } else {
- if (isset($objExercise) && isset($exerciseInSession)) {
- $questionList = Session::read('questionList');
- }
- }
- // Array to check in order to block the chat
- ExerciseLib::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
- )
- );
- };
- if (!empty($exercise_stat_info['questions_to_check'])) {
- $my_remind_list = $exercise_stat_info['questions_to_check'];
- $my_remind_list = explode(',', $my_remind_list);
- $my_remind_list = array_filter($my_remind_list);
- }
- $params = "exe_id=$exe_id&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();
- if ($debug) {
- error_log("6.1 params: -> $params");
- }
- if ($reminder == 2 && empty($my_remind_list)) {
- if ($debug) {
- error_log("6.2 calling the exercise_reminder.php ");
- };
- header('Location: exercise_reminder.php?'.$params);
- exit;
- }
- /*
- * 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);
- 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])) {
- //Timer - Get expired_time for a student
- if (!empty($exercise_stat_info)) {
- 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 exercise
- $last_attempt_date = Event::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 */
- 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);
- } else {
- //Recalculate the time control due #2069
- $diff = $current_timestamp - api_strtotime($last_attempt_date, 'UTC');
- $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); }
- //New expired time - it is due to the possible closure of session
- $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date, 'UTC');
- 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;
- if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
- $clock_expired_time = api_get_utc_datetime($expected_time);
- 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_exercises" table,
- then the last attempt for this student should be changed too */
- $sql = "UPDATE $exercise_attempt_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: '.$sql); }
- Database::query($sql);
- //Sessions that contain the expired time
- $_SESSION['expired_time'][$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]); };
- }
- } else {
- $clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key];
- }
- } else {
- if ($debug) {
- error_log("7 No time control");
- }
- }
- // Get time left for expiring time
- $time_left = api_strtotime($clock_expired_time, 'UTC') - time();
- /*
- * The time control feature is enable here - this feature is enable for a jquery plugin called epiclock
- * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock
- */
- if ($time_control) { //Sends the exercise form when the expired time is finished
- $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
- }
- //in LP's is enabled the "remember question" feature?
- if (!isset($_SESSION['questionList'])) {
- // selects the list of question ID
- $questionList = $objExercise->get_validated_question_list();
- if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
- $questionList = explode(',', $exercise_stat_info['data_tracking']);
- }
- Session::write('questionList', $questionList);
- if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
- } else {
- if (isset($objExercise) && isset($_SESSION['objExercise'])) {
- $questionList = $_SESSION['questionList'];
- }
- }
- if ($debug) {
- error_log('8. Question list loaded '.print_r($questionList, 1));
- }
- //Real question count
- $question_count = 0;
- if (!empty($questionList)) {
- $question_count = count($questionList);
- }
- if ($current_question > $question_count) {
- // If time control then don't change the current question, otherwise there will be a loop.
- // @todo
- if ($time_control == false) {
- $current_question = 0;
- }
- }
- if ($formSent && isset($_POST)) {
- if ($debug) { error_log('9. $formSent was set'); }
- // Initializing
- if (!is_array($exerciseResult)) {
- $exerciseResult = array();
- $exerciseResultCoordinates = array();
- }
- //Only for hotspot
- if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) {
- $hotspot_id = (int) ($_REQUEST['hidden_hotspot_id']);
- $choice = array($hotspot_id => '');
- }
- // if the user has answered at least one question
- if (is_array($choice)) {
- if ($debug) { error_log('9.1. $choice is an array '.print_r($choice, 1)); }
- // Also store hotspot spots in the session ($exerciseResultCoordinates
- // will be stored in the session at the end of this script)
- if (isset($_POST['hotspot'])) {
- $exerciseResultCoordinates = $_POST['hotspot'];
- if ($debug) { error_log('9.2. $_POST[hotspot] data '.print_r($exerciseResultCoordinates, 1)); }
- }
- if ($objExercise->type == ALL_ON_ONE_PAGE) {
- // $exerciseResult receives the content of the form.
- // Each choice of the student is stored into the array $choice
- $exerciseResult = $choice;
- } else {
- // gets the question ID from $choice. It is the key of the array
- list ($key) = array_keys($choice);
- // if the user didn't already answer this question
- if (!isset($exerciseResult[$key])) {
- // stores the user answer into the array
- $exerciseResult[$key] = $choice[$key];
- //saving each question
- if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
- $nro_question = $current_question; // - 1;
- $questionId = $key;
- // gets the student choice for this question
- $choice = $exerciseResult[$questionId];
- if (isset($exe_id)) {
- // Manage the question and answer attempts
- if ($debug) {
- error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice, 1));
- }
- $objExercise->manage_answer(
- $exe_id,
- $questionId,
- $choice,
- 'exercise_show',
- $exerciseResultCoordinates,
- true,
- false,
- false,
- $objExercise->propagate_neg,
- array()
- );
- }
- //END of saving and qualifying
- }
- }
- }
- if ($debug) { error_log('9.3. $choice is an array - end'); }
- 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);
- 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 ($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) {
- if ($debug) { error_log('10. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
- //We check if the user attempts before sending to the exercise_result.php
- if ($objExercise->selectAttempts() > 0) {
- $attempt_count = Event::get_attempt_count(
- api_get_user_id(),
- $exerciseId,
- $learnpath_id,
- $learnpath_item_id,
- $learnpath_item_view_id
- );
- if ($attempt_count >= $objExercise->selectAttempts()) {
- echo Display :: return_message(
- sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
- 'warning',
- false
- );
- if ($origin != 'learnpath') {
- //so we are not in learnpath tool
- echo '</div>'; //End glossary div
- Display :: display_footer();
- } else {
- echo '</body></html>';
- }
- }
- }
- header("Location: 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;
- } else {
- if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
- header("Location: 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;
- }
- } else {
- if ($debug) { error_log('10. Redirecting to exercise_submit.php'); }
- header("Location: exercise_submit.php?".api_get_cidreq()."&exerciseId=$exerciseId&origin=$origin");
- exit;
- }
- }
- if ($debug) { error_log('11. $formSent was set - end'); }
- } else {
- if ($debug) { error_log('9. $formSent was NOT sent'); }
- }
- // If questionNum comes from POST and not from GET
- $latestQuestionId = Event::getLatestQuestionIdFromAttempt($exe_id);
- if (is_null($current_question)) {
- $current_question = 1;
- if ($latestQuestionId) {
- $current_question = $objExercise->getPositionInCompressedQuestionList($latestQuestionId);
- }
- } else {
- $current_question++;
- }
- if ($question_count != 0) {
- 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) {
- if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
- //We check if the user attempts before sending to the exercise_result.php
- if ($objExercise->selectAttempts() > 0) {
- $attempt_count = Event::get_attempt_count(
- api_get_user_id(),
- $exerciseId,
- $learnpath_id,
- $learnpath_item_id,
- $learnpath_item_view_id
- );
- if ($attempt_count >= $objExercise->selectAttempts()) {
- Display::return_message(
- sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
- 'warning',
- false
- );
- if ($origin != 'learnpath') {
- //so we are not in learnpath tool
- echo '</div>'; //End glossary div
- Display :: display_footer();
- } else {
- echo '</body></html>';
- }
- exit;
- }
- }
- } else {
- if ($objExercise->review_answers) {
- header('Location: exercise_reminder.php?'.$params);
- exit;
- } else {
- header("Location: 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;
- }
- }
- } else {
- if ($debug) { error_log('Redirecting to exercise_submit.php'); }
- exit;
- }
- }
- } else {
- $error = get_lang('ThereAreNoQuestionsForThisExercise');
- // if we are in the case where user select random by category, but didn't choose the number of random question
- if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) {
- $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
- }
- }
- if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
- $_SESSION['gradebook'] = Security::remove_XSS($_GET['gradebook']);
- $gradebook = $_SESSION['gradebook'];
- } elseif (empty ($_GET['gradebook'])) {
- unset($_SESSION['gradebook']);
- $gradebook = '';
- }
- if (!empty ($gradebook) && $gradebook == 'view') {
- $interbreadcrumb[] = array('url' => '../gradebook/'.Security::remove_XSS($_SESSION['gradebook_dest']), 'name' => get_lang('ToolGradebook'));
- }
- $interbreadcrumb[] = array("url" => "exercise.php?".api_get_cidreq(), "name" => get_lang('Exercises'));
- $interbreadcrumb[] = array("url" => "#", "name" => $objExercise->selectTitle(true));
- if ($origin != 'learnpath') { //so we are not in learnpath tool
- if (!api_is_allowed_to_session_edit()) {
- Display::addFlash(
- Display::return_message(get_lang('SessionIsReadOnly'), 'warning')
- );
- }
- Display :: display_header(null, 'Exercises');
- } else {
- $htmlHeadXtra[] = "
- <style>
- body { background: none;}
- </style>
- ";
- Display::display_reduced_header();
- echo '<div style="height:10px"> </div>';
- }
- $show_quiz_edition = $objExercise->added_in_lp();
- // I'm in a preview mode
- if (api_is_course_admin() && $origin != 'learnpath') {
- echo '<div class="actions">';
- if ($show_quiz_edition == false) {
- echo '<a href="exercise_admin.php?'.api_get_cidreq().'&modifyExercise=yes&exerciseId='.$objExercise->id.'">'.Display::return_icon('settings.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>';
- } else {
- echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'), '', ICON_SIZE_MEDIUM).'</a>';
- }
- echo '</div>';
- }
- $is_visible_return = $objExercise->is_visible(
- $learnpath_id,
- $learnpath_item_id,
- $learnpath_item_view_id
- );
- if ($is_visible_return['value'] == false) {
- echo $is_visible_return['message'];
- if ($origin != 'learnpath') {
- Display :: display_footer();
- }
- exit;
- }
- $exercise_timeover = false;
- $limit_time_exists = (!empty($objExercise->start_time) || !empty($objExercise->end_time)) ? 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();
- if (!empty($objExercise->start_time)) {
- $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
- } else {
- $permission_to_start = true;
- }
- if ($_SERVER['REQUEST_METHOD'] != 'POST') {
- if (!empty($objExercise->end_time)) {
- $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
- }
- }
- if (!$permission_to_start || $exercise_timeover) {
- if (!api_is_allowed_to_edit(null, true)) {
- $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet');
- echo Display::return_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()), 'warning');
- if ($origin != 'learnpath') {
- Display :: display_footer();
- }
- exit;
- } else {
- $message_warning = $permission_to_start ? get_lang('ReachedTimeLimitAdmin') : get_lang('ExerciseNoStartedAdmin');
- echo Display::return_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()), 'warning');
- }
- }
- }
- // 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 (empty($objExercise->start_time)) {
- echo Display:: return_message(
- sprintf(
- get_lang('ExerciseNoStartedYet'),
- $exercise_title,
- $objExercise->selectAttempts()
- ),
- 'warning'
- );
- if ($origin != 'learnpath') {
- Display :: display_footer();
- }
- }
- }
- //Timer control
- if ($time_control) {
- echo $objExercise->return_time_left_div();
- echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciseExpiredTimeMessage').'</div>';
- }
- if ($origin != 'learnpath') {
- echo '<div id="highlight-plugin" class="glossary-content">';
- }
- if ($reminder == 2) {
- if ($debug) { error_log(' $reminder == 2'); }
- $data_tracking = $exercise_stat_info['data_tracking'];
- $data_tracking = explode(',', $data_tracking);
- $current_question = 1; //set by default the 1st question
- if (!empty($my_remind_list)) {
- //Checking which questions we are going to call from the remind list
- for ($i = 0; $i < count($data_tracking); $i++) {
- for ($j = 0; $j < count($my_remind_list); $j++) {
- if (!empty($remind_question_id)) {
- if ($remind_question_id == $my_remind_list[$j]) {
- if ($remind_question_id == $data_tracking[$i]) {
- if (isset($my_remind_list[$j + 1])) {
- $remind_question_id = $my_remind_list[$j + 1];
- $current_question = $i + 1;
- } else {
- // 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;
- }
- }
- } else {
- if ($my_remind_list[$j] == $data_tracking[$i]) {
- if (isset($my_remind_list[$j + 1])) {
- $remind_question_id = $my_remind_list[$j + 1];
- $current_question = $i + 1; // last question
- } else {
- // 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;
- }
- }
- }
- }
- } else {
- if ($objExercise->review_answers) {
- if ($debug) { error_log('. redirecting to exercise_reminder.php '); }
- header("Location: exercise_reminder.php?$params");
- exit;
- }
- }
- }
- if ($objExercise->review_answers) {
- $script_php = 'exercise_reminder.php';
- } else {
- $script_php = 'exercise_result.php';
- }
- if (!empty($error)) {
- echo Display::return_message($error, 'error', false);
- } else {
- if (!empty ($exercise_sound)) {
- echo "<a href=\"../document/download.php?doc_url=%2Faudio%2F".Security::remove_XSS($exercise_sound)."\" target=\"_blank\">", "<img src=\"../img/sound.gif\" border=\"0\" align=\"absmiddle\" alt=", get_lang('Sound')."\" /></a>";
- }
- // Get number of hotspot questions for javascript validation
- $number_of_hotspot_questions = 0;
- $onsubmit = '';
- $i = 0;
- if (!empty($questionList)) {
- foreach ($questionList as $questionId) {
- $i++;
- $objQuestionTmp = Question::read($questionId);
- // for sequential exercises
- if ($objExercise->type == ONE_PER_PAGE) {
- // if it is not the right question, goes to the next loop iteration
- if ($current_question != $i) {
- continue;
- } else {
- if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) {
- $number_of_hotspot_questions++;
- }
- break;
- }
- } else {
- if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) {
- $number_of_hotspot_questions++;
- }
- }
- }
- }
- if ($number_of_hotspot_questions > 0) {
- $onsubmit = "onsubmit=\"return validateFlashVar('".$number_of_hotspot_questions."', '".get_lang('HotspotValidateError1')."', '".get_lang('HotspotValidateError2')."');\"";
- }
- echo '<script>
- $(function() {
- //This pre-load the save.png icon
- var saveImage = new Image();
- saveImage.src = \'' . Display::return_icon(
- 'save.png',
- get_lang('Saved'),
- array(),
- ICON_SIZE_SMALL,
- false,
- true
- ).'\';
- // Block form submition on enter
- $(".block_on_enter").keypress(function(event) {
- return event.keyCode != 13;
- });
- $(".main_question").mouseover(function() {
- //$(this).find(".exercise_save_now_button").show();
- //$(this).addClass("question_highlight");
- });
- $(".main_question").mouseout(function() {
- //$(this).find(".exercise_save_now_button").hide();
- $(this).removeClass("question_highlight");
- });
- $(".no_remind_highlight").hide();
- // if the users validates the form using return key, prevent form action and simulates click on validation button
- /*$("#exercise_form").submit(function(){
- $(".question-validate-btn").first().trigger("click");
- return false;
- });*/
- $(\'form#exercise_form\').prepend($(\'#exercise-description\'));
- });
- $(document).on(\'ready\', function () {
- $(\'button[name="previous_question_and_save"]\').on(\'click\', function (e) {
- e.preventDefault();
- e.stopPropagation();
-
- var
- $this = $(this),
- previousId = parseInt($this.data(\'prev\')) || 0,
- questionId = parseInt($this.data(\'question\')) || 0;
- previous_question_and_save(previousId, questionId);
- });
- $(\'button[name="save_question_list"]\').on(\'click\', function (e) {
- e.preventDefault();
- e.stopPropagation();
- var
- $this = $(this),
- questionList = $this.data(\'list\').split(",");
- save_question_list(questionList);
- });
- $(\'button[name="save_now"]\').on(\'click\', function (e) {
- e.preventDefault();
- e.stopPropagation();
-
- var
- $this = $(this),
- questionId = parseInt($this.data(\'question\')) || 0,
- urlExtra = $this.data(\'url\') || null;
- save_now(questionId, urlExtra);
- });
- $(\'button[name="validate_all"]\').on(\'click\', function (e) {
- e.preventDefault();
- e.stopPropagation();
-
- validate_all();
- });
- });
- function previous_question(question_num) {
- url = "exercise_submit.php?'.$params.'&num="+question_num;
- window.location = url;
- }
- function previous_question_and_save(previous_question_id, question_id_to_save) {
- url = "exercise_submit.php?'.$params.'&num="+previous_question_id;
- //Save the current question
- save_now(question_id_to_save, url);
- }
- function save_question_list(question_list) {
- $.each(question_list, function(key, question_id) {
- save_now(question_id, null, false);
- });
- var url = "";
- if ('.$reminder.' == 1 ) {
- url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
- } else if ('.$reminder.' == 2 ) {
- url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
- } else {
- url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
- }
- //$("#save_for_now_"+question_id).html(\'' . Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL).'\');
- window.location = url;
- }
- function save_now(question_id, url_extra) {
- //1. Normal choice inputs
- var my_choice = $(\'*[name*="choice[\'+question_id+\']"]\').serialize();
- //2. Reminder checkbox
- var remind_list = $(\'*[name*="remind_list"]\').serialize();
- //3. Hotspots
- var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize();
- // Checking FCK
- if (question_id) {
- if (CKEDITOR.instances["choice["+question_id+"]"]) {
- var ckContent = CKEDITOR.instances["choice["+question_id+"]"].getData();
- my_choice = {};
- my_choice["choice["+question_id+"]"] = ckContent;
- my_choice = $.param(my_choice);
- }
- }
- if ($(\'input[name="remind_list[\'+question_id+\']"]\').is(\':checked\')) {
- $("#question_div_"+question_id).addClass("remind_highlight");
- } else {
- $("#question_div_"+question_id).removeClass("remind_highlight");
- }
- // Only for the first time
- $("#save_for_now_"+question_id).html(\'' . Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin').'\');
- $.ajax({
- type:"post",
- async: false,
- url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
- data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
- success: function(return_value) {
- if (return_value == "ok") {
- $("#save_for_now_"+question_id).html(\'' . Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL).'\');
- } else if (return_value == "error") {
- $("#save_for_now_"+question_id).html(\'' . Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL).'\');
- } else if (return_value == "one_per_page") {
- var url = "";
- if ('.$reminder.' == 1 ) {
- url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
- } else if ('.$reminder.' == 2 ) {
- url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
- } else {
- url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
- }
- if (url_extra) {
- url = url_extra;
- }
- $("#save_for_now_"+question_id).html(\'' . Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL).'\');
- window.location = url;
- }
- },
- error: function() {
- $("#save_for_now_"+question_id).html(\'' . Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL).'\');
- }
- });
- }
- function save_now_all(validate) {
- // 1. Input choice.
- var my_choice = $(\'*[name*="choice"]\').serialize();
- // 2. Reminder.
- var remind_list = $(\'*[name*="remind_list"]\').serialize();
- // 3. Hotspots.
- var hotspot = $(\'*[name*="hotspot"]\').serialize();
- // Question list.
- var question_list = ['.implode(',', $questionList).'];
- var free_answers = {};
- $.each(question_list, function(index, my_question_id) {
- // Checking FCK
- if (my_question_id) {
- if (CKEDITOR.instances["choice["+my_question_id+"]"]) {
- var ckContent = CKEDITOR.instances["choice["+my_question_id+"]"].getData();
- free_answers["free_choice["+my_question_id+"]"] = ckContent;
- }
- }
- });
- free_answers = $.param(free_answers);
- $("#save_all_reponse").html(\'' . Display::returnFontAwesomeIcon('spinner', null, true, 'fa-spin').'\');
- $.ajax({
- type:"post",
- async: false,
- url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?'.api_get_cidreq().'&a=save_exercise_by_now",
- data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,
- success: function(return_value) {
- if (return_value == "ok") {
- //$("#save_all_reponse").html(\'' . Display::return_icon('accept.png').'\');
- if (validate == "validate") {
- window.location = "'.$script_php.'?'.$params.'";
- } else {
- $("#save_all_reponse").html(\'' . Display::return_icon('accept.png').'\');
- }
- } else {
- $("#save_all_reponse").html(\'' . Display::return_icon('wrong.gif').'\');
- }
- }
- });
- return false;
- }
- function validate_all() {
- save_now_all("validate");
- }
- </script>';
- echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&autocomplete=off&&exerciseId='.$exerciseId.'" name="frm_exercise" '.$onsubmit.'>
- <input type="hidden" name="formSent" value="1" />
- <input type="hidden" name="exerciseId" value="'.$exerciseId.'" />
- <input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" />
- <input type="hidden" name="num_answer" value="'.$currentAnswer.'" id="num_current_answer_id" />
- <input type="hidden" name="exe_id" value="'.$exe_id.'" />
- <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.'" />';
- // Show list of questions
- $i = 1;
- $attempt_list = [];
- if (isset($exe_id)) {
- $attempt_list = Event::getAllExerciseEventByExeId($exe_id);
- }
- $remind_list = [];
- if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) {
- $remind_list = explode(',', $exercise_stat_info['questions_to_check']);
- }
- foreach ($questionList as $questionId) {
- // for sequential exercises
- if ($objExercise->type == ONE_PER_PAGE) {
- // if it is not the right question, goes to the next loop iteration
- if ($current_question != $i) {
- $i++;
- continue;
- } else {
- if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
- // if the user has already answered this question
- if (isset($exerciseResult[$questionId])) {
- // construction of the Question object
- $objQuestionTmp = Question::read($questionId);
- $questionName = $objQuestionTmp->selectTitle();
- // destruction of the Question object
- unset($objQuestionTmp);
- echo Display::return_message(get_lang('AlreadyAnswered'));
- $i++;
- break;
- }
- }
- }
- }
- $user_choice = null;
- if (isset($attempt_list[$questionId])) {
- $user_choice = $attempt_list[$questionId];
- } elseif ($objExercise->saveCorrectAnswers) {
- $correctAnswers = $objExercise->getCorrectAnswersInAllAttempts($learnpath_id, $learnpath_item_id);
- if (isset($correctAnswers[$questionId])) {
- $user_choice = $correctAnswers[$questionId];
- }
- }
- $remind_highlight = '';
- //Hides questions when reviewing a ALL_ON_ONE_PAGE exercise see #4542 no_remind_highlight class hide with jquery
- if ($objExercise->type == ALL_ON_ONE_PAGE && isset($_GET['reminder']) && $_GET['reminder'] == 2) {
- $remind_highlight = 'no_remind_highlight';
- }
- $exercise_actions = '';
- $is_remind_on = false;
- $attributes = array('id' =>'remind_list['.$questionId.']');
- if (in_array($questionId, $remind_list)) {
- $is_remind_on = true;
- $attributes['checked'] = 1;
- $remind_question = true;
- $remind_highlight = ' remind_highlight ';
- }
- // Showing the exercise description
- if (!empty($objExercise->description)) {
- if ($objExercise->type == ONE_PER_PAGE || ($objExercise->type != ONE_PER_PAGE && $i == 1)) {
- echo Display::panelCollapse('<span>'.
- get_lang('ExerciseDescriptionLabel').'</span>',
- $objExercise->description,
- 'exercise-description',
- [],
- 'description',
- 'exercise-collapse',
- false,
- true
- );
- }
- }
- echo '<div id="question_div_'.$questionId.'" class="main-question '.$remind_highlight.'" >';
- // Shows the question and its answers
- ExerciseLib::showQuestion(
- $questionId,
- false,
- $origin,
- $i,
- $objExercise->getHideQuestionTitle() ? false : true,
- false,
- $user_choice,
- false,
- null,
- false,
- true
- );
- // Button 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 = [
- Display::button(
- 'save_now',
- get_lang('SaveForNow'),
- ['type' => 'button', 'class' => 'btn btn-info', 'data-question' => $questionId]
- ),
- '<span id="save_for_now_'.$questionId.'"></span> '
- ];
- $exercise_actions .= Display::div(
- implode(PHP_EOL, $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>';
- $i++;
- // for sequential exercises
- if ($objExercise->type == ONE_PER_PAGE) {
- // quits the loop
- break;
- }
- }
- // end foreach()
- if ($objExercise->type == ALL_ON_ONE_PAGE) {
- $exercise_actions = $objExercise->show_button($questionId, $current_question);
- echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
- echo '<br>';
- }
- echo '</form>';
- }
- if ($origin != 'learnpath') {
- // So we are not in learnpath tool
- echo '</div>'; //End glossary div
- }
- Display :: display_footer();
|