exercise_submit.php 47 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Exercise submission
  5. * This script allows to run an exercise. According to the exercise type, questions
  6. * can be on an unique page, or one per page with a Next button.
  7. *
  8. * One exercise may contain different types of answers (unique or multiple selection,
  9. * matching, fill in blanks, free answer, hot-spot).
  10. *
  11. * Questions are selected randomly or not.
  12. *
  13. * When the user has answered all questions and clicks on the button "Ok",
  14. * it goes to exercise_result.php
  15. *
  16. * Notice : This script is also used to show a question before modifying it by
  17. * the administrator
  18. * @package chamilo.exercise
  19. * @author Olivier Brouckaert
  20. * @author Julio Montoya <gugli100@gmail.com>
  21. * Fill in blank option added (2008)
  22. * Cleaning exercises (2010),
  23. * Adding hotspot delineation support (2011)
  24. * Adding reminder + ajax support (2011)
  25. * Modified by hubert.borderiou (2011-10-21 question category)
  26. */
  27. use \ChamiloSession as Session;
  28. // name of the language file that needs to be included
  29. $language_file = 'exercice';
  30. require_once '../inc/global.inc.php';
  31. $current_course_tool = TOOL_QUIZ;
  32. $this_section = SECTION_COURSES;
  33. $debug = false;
  34. // Notice for unauthorized people.
  35. api_protect_course_script(true);
  36. $origin = isset($_REQUEST['origin']) ? Security::remove_XSS($_REQUEST['origin']) : '';
  37. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  38. $glossaryExtraTools = api_get_setting('show_glossary_in_extra_tools');
  39. $showGlossary = in_array($glossaryExtraTools, array('true', 'exercise', 'exercise_and_lp'));
  40. if ($origin == 'learnpath') {
  41. $showGlossary = in_array($glossaryExtraTools, array('true', 'lp', 'exercise_and_lp'));
  42. }
  43. if ($showGlossary) {
  44. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_CODE_PATH).'glossary/glossary.js.php"></script>';
  45. $htmlHeadXtra[] = api_get_js('jquery.highlight.js');
  46. }
  47. //This library is necessary for the time control feature
  48. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/stylesheet/jquery.epiclock.css');
  49. $htmlHeadXtra[] = api_get_css(api_get_path(WEB_LIBRARY_PATH).'javascript/epiclock/renderers/minute/epiclock.minute.css');
  50. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.dateformat.min.js');
  51. $htmlHeadXtra[] = api_get_js('epiclock/javascript/jquery.epiclock.min.js');
  52. $htmlHeadXtra[] = api_get_js('epiclock/renderers/minute/epiclock.minute.js');
  53. // General parameters passed via POST/GET
  54. $learnpath_id = isset($_REQUEST['learnpath_id']) ? intval($_REQUEST['learnpath_id']) : 0;
  55. $learnpath_item_id = isset($_REQUEST['learnpath_item_id']) ? intval($_REQUEST['learnpath_item_id']) : 0;
  56. $learnpath_item_view_id = isset($_REQUEST['learnpath_item_view_id']) ? intval($_REQUEST['learnpath_item_view_id']) : 0;
  57. $reminder = isset($_REQUEST['reminder']) ? intval($_REQUEST['reminder']) : 0;
  58. $remind_question_id = isset($_REQUEST['remind_question_id']) ? intval($_REQUEST['remind_question_id']) : 0;
  59. $exerciseId = isset($_REQUEST['exerciseId']) ? intval($_REQUEST['exerciseId']) : 0;
  60. $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
  61. $exerciseResult = isset($_REQUEST['exerciseResult']) ? $_REQUEST['exerciseResult'] : null;
  62. $exerciseResultCoordinates = isset($_REQUEST['exerciseResultCoordinates']) ? $_REQUEST['exerciseResultCoordinates'] : null;
  63. $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
  64. $choice = empty($choice) ? isset($_REQUEST['choice2']) ? $_REQUEST['choice2'] : null : null;
  65. //From submit modal
  66. $current_question = isset($_REQUEST['num']) ? intval($_REQUEST['num']) : null;
  67. $currentAnswer = isset($_REQUEST['num_answer']) ? intval($_REQUEST['num_answer']) : null;
  68. //Error message
  69. $error = '';
  70. //Table calls
  71. $exercice_attemp_table = Database :: get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  72. /* Teacher takes an exam and want to see a preview,
  73. we delete the objExercise from the session in order to get the latest
  74. changes in the exercise */
  75. if (api_is_allowed_to_edit(null,true) && isset($_GET['preview']) && $_GET['preview'] == 1 ) {
  76. Session::erase('objExercise');
  77. }
  78. // 1. Loading the $objExercise variable
  79. if (!isset($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  80. // Construction of Exercise
  81. $objExercise = new Exercise();
  82. Session::write('firstTime', true);
  83. if ($debug) {error_log('1. Setting the $objExercise variable'); };
  84. unset($_SESSION['questionList']);
  85. // if the specified exercise doesn't exist or is disabled
  86. if (!$objExercise->read($exerciseId) ||
  87. (!$objExercise->selectStatus() && !$is_allowedToEdit && $origin != 'learnpath')
  88. ) {
  89. if ($debug) {error_log('1.1. Error while reading the exercise'); };
  90. unset ($objExercise);
  91. $error = get_lang('ExerciseNotFound');
  92. } else {
  93. // Saves the object into the session
  94. Session::write('objExercise', $objExercise);
  95. if ($debug) {error_log('1.1. $_SESSION[objExercise] was unset - set now - end'); };
  96. }
  97. } else {
  98. Session::write('firstTime', false);
  99. }
  100. //2. Checking if $objExercise is set
  101. if (!isset($objExercise) && isset($_SESSION['objExercise'])) {
  102. if ($debug) { error_log('2. Loading $objExercise from session'); };
  103. $objExercise = $_SESSION['objExercise'];
  104. }
  105. //3. $objExercise is not set, then return to the exercise list
  106. if (!is_object($objExercise)) {
  107. if ($debug) {error_log('3. $objExercise was not set, kill the script'); };
  108. header('Location: exercice.php');
  109. exit;
  110. }
  111. // If reminder ends we jump to the exercise_reminder
  112. if ($objExercise->review_answers) {
  113. if ($remind_question_id == -1) {
  114. header('Location: exercise_reminder.php?origin='.$origin.'&exerciseId='.$exerciseId);
  115. exit;
  116. }
  117. }
  118. $current_timestamp = time();
  119. $my_remind_list = array();
  120. $time_control = false;
  121. if ($objExercise->expired_time != 0) {
  122. $time_control = true;
  123. }
  124. // Generating the time control key for the user
  125. $current_expired_time_key = ExerciseLib::get_time_control_key($objExercise->id, $learnpath_id, $learnpath_item_id);
  126. $_SESSION['duration_time'][$current_expired_time_key] = $current_timestamp;
  127. if ($time_control) {
  128. // Get the expired time of the current exercice in track_e_exercises
  129. $total_seconds = $objExercise->expired_time*60;
  130. }
  131. $show_clock = true;
  132. $user_id = api_get_user_id();
  133. if ($objExercise->selectAttempts() > 0) {
  134. $attempt_html = '';
  135. $attempt_count = Event::get_attempt_count(
  136. $user_id,
  137. $exerciseId,
  138. $learnpath_id,
  139. $learnpath_item_id,
  140. $learnpath_item_view_id
  141. );
  142. if ($attempt_count >= $objExercise->selectAttempts()) {
  143. $show_clock = false;
  144. if (!api_is_allowed_to_edit(null,true)) {
  145. if ($objExercise->results_disabled == 0 && $origin != 'learnpath') {
  146. // Showing latest attempt according with task BT#1628
  147. $exercise_stat_info = Event::getExerciseResultsByUser(
  148. $user_id,
  149. $exerciseId,
  150. api_get_course_id(),
  151. api_get_session_id()
  152. );
  153. if (!empty($exercise_stat_info)) {
  154. $max_exe_id = max(array_keys($exercise_stat_info));
  155. $last_attempt_info = $exercise_stat_info[$max_exe_id];
  156. $attempt_html .= Display::div(get_lang('Date').': '.api_get_local_time($last_attempt_info['exe_date']), array('id'=>''));
  157. $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
  158. if (!empty($last_attempt_info['question_list'])) {
  159. foreach($last_attempt_info['question_list'] as $question_data) {
  160. $question_id = $question_data['question_id'];
  161. $marks = $question_data['marks'];
  162. $question_info = Question::read($question_id);
  163. $attempt_html .= Display::div($question_info->question, array('class'=>'question_title'));
  164. $attempt_html .= Display::div(get_lang('Score').' '.$marks, array('id'=>'question_score'));
  165. }
  166. }
  167. $score = ExerciseLib::show_score($last_attempt_info['exe_result'], $last_attempt_info['exe_weighting']);
  168. $attempt_html .= Display::div(get_lang('YourTotalScore').' '.$score, array('id'=>'question_score'));
  169. } else {
  170. $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
  171. }
  172. } else {
  173. $attempt_html .= Display::return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
  174. }
  175. } else {
  176. $attempt_html .= Display :: return_message(sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()), 'warning', false);
  177. }
  178. if ($origin == 'learnpath') {
  179. Display :: display_reduced_header();
  180. } else {
  181. Display :: display_header($nameTools,'Exercises');
  182. }
  183. echo $attempt_html;
  184. if ($origin != 'learnpath')
  185. Display :: display_footer();
  186. exit;
  187. }
  188. }
  189. if ($debug) {
  190. error_log("4. Setting the exe_id: $exe_id");
  191. }
  192. /* 5. Getting user exercise info (if the user took the exam before)
  193. generating exe_id */
  194. $exercise_stat_info = $objExercise->get_stat_track_exercise_info(
  195. $learnpath_id,
  196. $learnpath_item_id,
  197. $learnpath_item_view_id
  198. );
  199. $clock_expired_time = null;
  200. if (empty($exercise_stat_info)) {
  201. if ($debug) error_log('5 $exercise_stat_info is empty ');
  202. $total_weight = 0;
  203. $questionList = $objExercise->get_validated_question_list();
  204. foreach ($questionList as $question_id) {
  205. $objQuestionTmp = Question::read($question_id);
  206. $total_weight += floatval($objQuestionTmp->weighting);
  207. }
  208. if ($time_control) {
  209. $expected_time = $current_timestamp + $total_seconds;
  210. if ($debug) error_log('5.1. $current_timestamp '.$current_timestamp);
  211. if ($debug) error_log('5.2. $expected_time '.$expected_time);
  212. $clock_expired_time = api_get_utc_datetime($expected_time);
  213. if ($debug) error_log('5.3. $expected_time '.$clock_expired_time);
  214. //Sessions that contain the expired time
  215. $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
  216. if ($debug) { error_log('5.4. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
  217. }
  218. $exe_id = $objExercise->save_stat_track_exercise_info(
  219. $clock_expired_time,
  220. $learnpath_id,
  221. $learnpath_item_id,
  222. $learnpath_item_view_id,
  223. $questionList,
  224. $total_weight
  225. );
  226. $exercise_stat_info = $objExercise->get_stat_track_exercise_info(
  227. $learnpath_id,
  228. $learnpath_item_id,
  229. $learnpath_item_view_id
  230. );
  231. if ($debug) error_log("5.5 exercise_stat_info[] exists getting exe_id $exe_id");
  232. } else {
  233. $exe_id = $exercise_stat_info['exe_id'];
  234. // Remember last question id position.
  235. $isFirstTime = Session::read('firstTime');
  236. if ($isFirstTime && $objExercise->type == ONE_PER_PAGE) {
  237. $resolvedQuestions = Event::getAllExerciseEventByExeId($exe_id);
  238. if (!empty($resolvedQuestions) &&
  239. !empty($exercise_stat_info['data_tracking'])
  240. ) {
  241. $last = current(end($resolvedQuestions));
  242. $attemptQuestionList = explode(',', $exercise_stat_info['data_tracking']);
  243. $count = 1;
  244. foreach ($attemptQuestionList as $question) {
  245. if ($last['question_id'] == $question) {
  246. break;
  247. }
  248. $count++;
  249. }
  250. $current_question = $count;
  251. }
  252. }
  253. if ($debug) error_log("5 exercise_stat_info[] exists getting exe_id $exe_id ");
  254. }
  255. // Array to check in order to block the chat
  256. ExerciseLib::create_chat_exercise_session($exe_id);
  257. if ($debug) { error_log('6. $objExercise->get_stat_track_exercise_info function called:: '.print_r($exercise_stat_info, 1)); };
  258. if (!empty($exercise_stat_info['questions_to_check'])) {
  259. $my_remind_list = $exercise_stat_info['questions_to_check'];
  260. $my_remind_list = explode(',', $my_remind_list);
  261. $my_remind_list = array_filter($my_remind_list);
  262. }
  263. $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();
  264. if ($debug) { error_log("6.1 params: -> $params"); };
  265. if ($reminder == 2 && empty($my_remind_list)) {
  266. if ($debug) { error_log("6.2 calling the exercise_reminder.php "); };
  267. header('Location: exercise_reminder.php?'.$params);
  268. exit;
  269. }
  270. /*
  271. * 7. Loading Time control parameters
  272. * If the expired time is major that zero(0) then the expired time is compute on this time.
  273. */
  274. if ($time_control) {
  275. if ($debug) error_log('7.1. Time control is enabled');
  276. if ($debug) error_log('7.2. $current_expired_time_key '.$current_expired_time_key);
  277. if ($debug) error_log('7.3. $_SESSION[expired_time][$current_expired_time_key] '.$_SESSION['expired_time'][$current_expired_time_key]);
  278. if (!isset($_SESSION['expired_time'][$current_expired_time_key])) {
  279. //Timer - Get expired_time for a student
  280. if (!empty($exercise_stat_info)) {
  281. if ($debug) {error_log('7.4 Seems that the session ends and the user want to retake the exam'); };
  282. $expired_time_of_this_attempt = $exercise_stat_info['expired_time_control'];
  283. if ($debug) {error_log('7.5 $expired_time_of_this_attempt: '.$expired_time_of_this_attempt); }
  284. // Get the last attempt of an exercise
  285. $last_attempt_date = Event::getLastAttemptDateOfExercise($exercise_stat_info['exe_id']);
  286. /* This means that the user enters the exam but do not answer the
  287. first question we get the date from the track_e_exercises not from
  288. the track_et_attempt see #2069 */
  289. if (empty($last_attempt_date)) {
  290. $diff = $current_timestamp - api_strtotime($exercise_stat_info['start_date'], 'UTC');
  291. $last_attempt_date = api_get_utc_datetime(api_strtotime($exercise_stat_info['start_date'],'UTC') + $diff);
  292. } else {
  293. //Recalculate the time control due #2069
  294. $diff = $current_timestamp - api_strtotime($last_attempt_date,'UTC');
  295. $last_attempt_date = api_get_utc_datetime(api_strtotime($last_attempt_date,'UTC') + $diff);
  296. }
  297. if ($debug) {error_log('7.6. $last_attempt_date: '.$last_attempt_date); }
  298. //New expired time - it is due to the possible closure of session
  299. $new_expired_time_in_seconds = api_strtotime($expired_time_of_this_attempt, 'UTC') - api_strtotime($last_attempt_date,'UTC');
  300. if ($debug) {error_log('7.7. $new_expired_time_in_seconds: '.$new_expired_time_in_seconds); }
  301. $expected_time = $current_timestamp + $new_expired_time_in_seconds;
  302. if ($debug) {error_log('7.8. $expected_time1: '.$expected_time); }
  303. $clock_expired_time = api_get_utc_datetime($expected_time);
  304. if ($debug) {error_log('7.9. $clock_expired_time: '.$clock_expired_time); }
  305. // First we update the attempt to today
  306. /* How the expired time is changed into "track_e_exercises" table,
  307. then the last attempt for this student should be changed too */
  308. $sql = "UPDATE $exercice_attemp_table SET
  309. tms = '".api_get_utc_datetime()."'
  310. WHERE
  311. exe_id = '".$exercise_stat_info['exe_id']."' AND
  312. tms = '".$last_attempt_date."' ";
  313. if ($debug) {error_log('7.10. $sql: '.$sql); }
  314. Database::query($sql);
  315. //Sessions that contain the expired time
  316. $_SESSION['expired_time'][$current_expired_time_key] = $clock_expired_time;
  317. if ($debug) {error_log('7.11. Setting the $_SESSION[expired_time]: '.$_SESSION['expired_time'][$current_expired_time_key] ); };
  318. }
  319. } else {
  320. $clock_expired_time = $_SESSION['expired_time'][$current_expired_time_key];
  321. }
  322. } else {
  323. if ($debug) { error_log("7 No time control"); };
  324. }
  325. // Get time left for expiring time
  326. $time_left = api_strtotime($clock_expired_time,'UTC') - time();
  327. /*
  328. * The time control feature is enable here - this feature is enable for a jquery plugin called epiclock
  329. * for more details of how it works see this link : http://eric.garside.name/docs.html?p=epiclock
  330. */
  331. if ($time_control) { //Sends the exercise form when the expired time is finished
  332. $htmlHeadXtra[] = $objExercise->show_time_control_js($time_left);
  333. }
  334. // if the user has submitted the form
  335. $exercise_title = $objExercise->selectTitle();
  336. $exercise_sound = $objExercise->selectSound();
  337. //in LP's is enabled the "remember question" feature?
  338. if (!isset($_SESSION['questionList'])) {
  339. // selects the list of question ID
  340. $questionList = $objExercise->get_validated_question_list();
  341. if ($objExercise->isRandom() && !empty($exercise_stat_info['data_tracking'])) {
  342. $questionList = explode(',', $exercise_stat_info['data_tracking']);
  343. }
  344. Session::write('questionList', $questionList);
  345. if ($debug > 0) { error_log('$_SESSION[questionList] was set'); }
  346. } else {
  347. if (isset($objExercise) && isset($_SESSION['objExercise'])) {
  348. $questionList = $_SESSION['questionList'];
  349. }
  350. }
  351. if ($debug) error_log('8. Question list loaded '.print_r($questionList, 1));
  352. //Real question count
  353. $question_count = 0;
  354. if (!empty($questionList)) {
  355. $question_count = count($questionList);
  356. }
  357. if ($formSent && isset($_POST)) {
  358. if ($debug) { error_log('9. $formSent was set'); }
  359. // Initializing
  360. if (!is_array($exerciseResult)) {
  361. $exerciseResult = array();
  362. $exerciseResultCoordinates = array();
  363. }
  364. //Only for hotspot
  365. if (!isset($choice) && isset($_REQUEST['hidden_hotspot_id'])) {
  366. $hotspot_id = (int)($_REQUEST['hidden_hotspot_id']);
  367. $choice = array($hotspot_id => '');
  368. }
  369. // if the user has answered at least one question
  370. if (is_array($choice)) {
  371. if ($debug) { error_log('9.1. $choice is an array '.print_r($choice, 1)); }
  372. // Also store hotspot spots in the session ($exerciseResultCoordinates
  373. // will be stored in the session at the end of this script)
  374. if (isset($_POST['hotspot'])) {
  375. $exerciseResultCoordinates = $_POST['hotspot'];
  376. if ($debug) { error_log('9.2. $_POST[hotspot] data '.print_r($exerciseResultCoordinates, 1)); }
  377. }
  378. if ($objExercise->type == ALL_ON_ONE_PAGE) {
  379. // $exerciseResult receives the content of the form.
  380. // Each choice of the student is stored into the array $choice
  381. $exerciseResult = $choice;
  382. } else {
  383. // gets the question ID from $choice. It is the key of the array
  384. list ($key) = array_keys($choice);
  385. // if the user didn't already answer this question
  386. if (!isset($exerciseResult[$key])) {
  387. // stores the user answer into the array
  388. $exerciseResult[$key] = $choice[$key];
  389. //saving each question
  390. if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
  391. $nro_question = $current_question; // - 1;
  392. $questionId = $key;
  393. // gets the student choice for this question
  394. $choice = $exerciseResult[$questionId];
  395. if (isset($exe_id)) {
  396. // Manage the question and answer attempts
  397. if ($debug) { error_log('8.3. manage_answer exe_id: '.$exe_id.' - $questionId: '.$questionId.' Choice'.print_r($choice,1)); }
  398. $objExercise->manage_answer(
  399. $exe_id,
  400. $questionId,
  401. $choice,
  402. 'exercise_show',
  403. $exerciseResultCoordinates,
  404. true,
  405. false,
  406. false,
  407. $objExercise->propagate_neg,
  408. array()
  409. );
  410. }
  411. //END of saving and qualifying
  412. }
  413. }
  414. }
  415. if ($debug) { error_log('9.3. $choice is an array - end'); }
  416. if ($debug) { error_log('9.4. $exerciseResult '.print_r($exerciseResult,1)); }
  417. }
  418. // the script "exercise_result.php" will take the variable $exerciseResult from the session
  419. Session::write('exerciseResult', $exerciseResult);
  420. Session::write('remind_list', $remind_list);
  421. Session::write('exerciseResultCoordinates',$exerciseResultCoordinates);
  422. // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
  423. if ($objExercise->type == ALL_ON_ONE_PAGE || $current_question >= $question_count) {
  424. if (api_is_allowed_to_session_edit()) {
  425. // goes to the script that will show the result of the exercise
  426. if ($objExercise->type == ALL_ON_ONE_PAGE) {
  427. if ($debug) { error_log('10. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
  428. //We check if the user attempts before sending to the exercise_result.php
  429. if ($objExercise->selectAttempts() > 0) {
  430. $attempt_count = Event::get_attempt_count(
  431. api_get_user_id(),
  432. $exerciseId,
  433. $learnpath_id,
  434. $learnpath_item_id,
  435. $learnpath_item_view_id
  436. );
  437. if ($attempt_count >= $objExercise->selectAttempts()) {
  438. Display :: display_warning_message(
  439. sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
  440. false
  441. );
  442. if ($origin != 'learnpath') {
  443. //so we are not in learnpath tool
  444. echo '</div>'; //End glossary div
  445. Display :: display_footer();
  446. } else {
  447. echo '</body></html>';
  448. }
  449. }
  450. }
  451. 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");
  452. exit;
  453. } else {
  454. if ($debug) { error_log('10. Redirecting to exercise_show.php'); }
  455. 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");
  456. exit;
  457. }
  458. } else {
  459. if ($debug) { error_log('10. Redirecting to exercise_submit.php'); }
  460. header("Location: exercise_submit.php?".api_get_cidreq()."&exerciseId=$exerciseId&origin=$origin");
  461. exit;
  462. }
  463. }
  464. if ($debug) { error_log('11. $formSent was set - end'); }
  465. } else {
  466. if ($debug) { error_log('9. $formSent was NOT sent'); }
  467. }
  468. // If questionNum comes from POST and not from GET
  469. if (!$current_question || isset($_REQUEST['num']) && $_REQUEST['num']) {
  470. if (!$current_question) {
  471. $current_question = 1;
  472. } else {
  473. $current_question++;
  474. }
  475. }
  476. if ($question_count != 0) {
  477. if (($objExercise->type == ALL_ON_ONE_PAGE ||
  478. $current_question > $question_count)
  479. ) {
  480. if (api_is_allowed_to_session_edit()) {
  481. // goes to the script that will show the result of the exercise
  482. if ($objExercise->type == ALL_ON_ONE_PAGE) {
  483. if ($debug) { error_log('12. Exercise ALL_ON_ONE_PAGE -> Redirecting to exercise_result.php'); }
  484. //We check if the user attempts before sending to the exercise_result.php
  485. if ($objExercise->selectAttempts() > 0) {
  486. $attempt_count = Event::get_attempt_count(
  487. api_get_user_id(),
  488. $exerciseId,
  489. $learnpath_id,
  490. $learnpath_item_id,
  491. $learnpath_item_view_id
  492. );
  493. if ($attempt_count >= $objExercise->selectAttempts()) {
  494. Display :: display_warning_message(
  495. sprintf(get_lang('ReachedMaxAttempts'), $exercise_title, $objExercise->selectAttempts()),
  496. false
  497. );
  498. if ($origin != 'learnpath') {
  499. //so we are not in learnpath tool
  500. echo '</div>'; //End glossary div
  501. Display :: display_footer();
  502. } else {
  503. echo '</body></html>';
  504. }
  505. exit;
  506. }
  507. }
  508. } else {
  509. if ($objExercise->review_answers) {
  510. header('Location: exercise_reminder.php?'.$params);
  511. exit;
  512. } else {
  513. 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");
  514. exit;
  515. }
  516. }
  517. } else {
  518. if ($debug) { error_log('Redirecting to exercise_submit.php'); }
  519. exit;
  520. }
  521. }
  522. } else {
  523. $error = get_lang('ThereAreNoQuestionsForThisExercise');
  524. // if we are in the case where user select random by category, but didn't choose the number of random question
  525. if ($objExercise->selectRandomByCat() > 0 && $objExercise->random <= 0) {
  526. $error .= "<br/>".get_lang('PleaseSelectSomeRandomQuestion');
  527. }
  528. }
  529. if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  530. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  531. $gradebook = $_SESSION['gradebook'];
  532. } elseif (empty ($_GET['gradebook'])) {
  533. unset ($_SESSION['gradebook']);
  534. $gradebook = '';
  535. }
  536. if (!empty ($gradebook) && $gradebook == 'view') {
  537. $interbreadcrumb[] = array ('url' => '../gradebook/' . Security::remove_XSS($_SESSION['gradebook_dest']),'name' => get_lang('ToolGradebook'));
  538. }
  539. $interbreadcrumb[] = array ("url" => "exercice.php?gradebook=$gradebook", "name" => get_lang('Exercices'));
  540. $interbreadcrumb[] = array ("url" => "#","name" => $objExercise->name);
  541. if ($origin != 'learnpath') { //so we are not in learnpath tool
  542. Display :: display_header(null,'Exercises');
  543. if (!api_is_allowed_to_session_edit() ) {
  544. Display :: display_warning_message(get_lang('SessionIsReadOnly'));
  545. }
  546. } else {
  547. Display::display_reduced_header();
  548. echo '<div style="height:10px">&nbsp;</div>';
  549. }
  550. $show_quiz_edition = $objExercise->added_in_lp();
  551. // I'm in a preview mode
  552. if (api_is_course_admin() && $origin != 'learnpath') {
  553. echo '<div class="actions">';
  554. if ($show_quiz_edition == false) {
  555. 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>';
  556. } else {
  557. echo '<a href="#">'.Display::return_icon('settings_na.png', get_lang('ModifyExercise'),'',ICON_SIZE_MEDIUM).'</a>';
  558. }
  559. echo '</div>';
  560. }
  561. $is_visible_return = $objExercise->is_visible(
  562. $learnpath_id,
  563. $learnpath_item_id,
  564. $learnpath_item_view_id
  565. );
  566. if ($is_visible_return['value'] == false) {
  567. echo $is_visible_return['message'];
  568. if ($origin != 'learnpath') {
  569. Display :: display_footer();
  570. }
  571. exit;
  572. }
  573. $limit_time_exists = (($objExercise->start_time != '0000-00-00 00:00:00') || ($objExercise->end_time != '0000-00-00 00:00:00')) ? true : false;
  574. if ($limit_time_exists) {
  575. $exercise_start_time = api_strtotime($objExercise->start_time, 'UTC');
  576. $exercise_end_time = api_strtotime($objExercise->end_time, 'UTC');
  577. $time_now = time();
  578. if ($objExercise->start_time != '0000-00-00 00:00:00') {
  579. $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
  580. } else {
  581. $permission_to_start = true;
  582. }
  583. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  584. if ($objExercise->end_time != '0000-00-00 00:00:00') {
  585. $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
  586. } else {
  587. $exercise_timeover = false;
  588. }
  589. }
  590. if (!$permission_to_start || $exercise_timeover) {
  591. if (!api_is_allowed_to_edit(null,true)) {
  592. $message_warning = $permission_to_start ? get_lang('ReachedTimeLimit') : get_lang('ExerciseNoStartedYet');
  593. Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()));
  594. if ($origin != 'learnpath') {
  595. Display :: display_footer();
  596. }
  597. exit;
  598. } else {
  599. $message_warning = $permission_to_start ? get_lang('ReachedTimeLimitAdmin') : get_lang('ExerciseNoStartedAdmin');
  600. Display :: display_warning_message(sprintf($message_warning, $exercise_title, $objExercise->selectAttempts()));
  601. }
  602. }
  603. }
  604. // Blocking empty start times see BT#2800
  605. global $_custom;
  606. if (isset($_custom['exercises_hidden_when_no_start_date']) &&
  607. $_custom['exercises_hidden_when_no_start_date']
  608. ) {
  609. if (empty($objExercise->start_time) || $objExercise->start_time == '0000-00-00 00:00:00') {
  610. Display:: display_warning_message(
  611. sprintf(
  612. get_lang('ExerciseNoStartedYet'),
  613. $exercise_title,
  614. $objExercise->selectAttempts()
  615. )
  616. );
  617. if ($origin != 'learnpath') {
  618. Display :: display_footer();
  619. }
  620. }
  621. }
  622. //Timer control
  623. if ($time_control) {
  624. echo $objExercise->return_time_left_div();
  625. echo '<div style="display:none" class="warning-message" id="expired-message-id">'.get_lang('ExerciceExpiredTimeMessage').'</div>';
  626. }
  627. if (!empty($objExercise->description)) {
  628. echo "<script>
  629. $(function() {
  630. $('#description_content').accordion({
  631. changestart: function(event, ui) {
  632. //var clicked = $(this).find('.ui-state-active').attr('id');
  633. //$('#'+clicked).load('/widgets/'+clicked);
  634. $('#collapse1').html(".json_encode($objExercise->description).");
  635. }
  636. });
  637. });
  638. </script>";
  639. echo Display::generate_accordion(array(array('title' => get_lang('ExerciseDescriptionLabel'), 'content' => null)), 'jquery', 'description_content');
  640. }
  641. if ($origin != 'learnpath') {
  642. echo '<div id="highlight-plugin" class="glossary-content">';
  643. }
  644. if ($reminder == 2) {
  645. if ($debug) { error_log(' $reminder == 2'); }
  646. $data_tracking = $exercise_stat_info['data_tracking'];
  647. $data_tracking = explode(',', $data_tracking);
  648. $current_question = 1; //set by default the 1st question
  649. if (!empty($my_remind_list)) {
  650. //Checking which questions we are going to call from the remind list
  651. for ($i = 0; $i < count($data_tracking); $i++) {
  652. for($j = 0; $j < count($my_remind_list); $j++) {
  653. if (!empty($remind_question_id)) {
  654. if ($remind_question_id == $my_remind_list[$j]) {
  655. if ($remind_question_id == $data_tracking[$i]) {
  656. if (isset($my_remind_list[$j+1])) {
  657. $remind_question_id = $my_remind_list[$j+1];
  658. $current_question = $i + 1;
  659. } else {
  660. // We end the remind list we go to the exercise_reminder.php please
  661. $remind_question_id = -1;
  662. $current_question = $i + 1; // last question
  663. }
  664. break 2;
  665. }
  666. }
  667. } else {
  668. if ($my_remind_list[$j] == $data_tracking[$i]) {
  669. if (isset($my_remind_list[$j+1])) {
  670. $remind_question_id = $my_remind_list[$j+1];
  671. $current_question = $i + 1; // last question
  672. } else {
  673. // We end the remind list we go to the exercise_reminder.php please
  674. $remind_question_id = -1;
  675. $current_question = $i + 1; // last question
  676. }
  677. break 2;
  678. }
  679. }
  680. }
  681. }
  682. } else {
  683. if ($objExercise->review_answers) {
  684. if ($debug) { error_log('. redirecting to exercise_reminder.php '); }
  685. header("Location: exercise_reminder.php?$params");
  686. exit;
  687. }
  688. }
  689. }
  690. if ($objExercise->review_answers) {
  691. $script_php = 'exercise_reminder.php';
  692. } else {
  693. $script_php = 'exercise_result.php';
  694. }
  695. if (!empty($error)) {
  696. Display :: display_error_message($error, false);
  697. } else {
  698. if (!empty ($exercise_sound)) {
  699. 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>";
  700. }
  701. // Get number of hotspot questions for javascript validation
  702. $number_of_hotspot_questions = 0;
  703. $onsubmit = '';
  704. $i = 0;
  705. if (!empty($questionList)) {
  706. foreach ($questionList as $questionId) {
  707. $i++;
  708. $objQuestionTmp = Question::read($questionId);
  709. // for sequential exercises
  710. if ($objExercise->type == ONE_PER_PAGE) {
  711. // if it is not the right question, goes to the next loop iteration
  712. if ($current_question != $i) {
  713. continue;
  714. } else {
  715. if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) {
  716. $number_of_hotspot_questions++;
  717. }
  718. break;
  719. }
  720. } else {
  721. if ($objQuestionTmp->selectType() == HOT_SPOT || $objQuestionTmp->selectType() == HOT_SPOT_DELINEATION) {
  722. $number_of_hotspot_questions++;
  723. }
  724. }
  725. }
  726. }
  727. if ($number_of_hotspot_questions > 0) {
  728. $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\"";
  729. }
  730. echo '<script>
  731. $(function() {
  732. //$(".exercise_save_now_button").hide();
  733. $(".main_question").mouseover(function() {
  734. //$(this).find(".exercise_save_now_button").show();
  735. //$(this).addClass("question_highlight");
  736. });
  737. $(".main_question").mouseout(function() {
  738. //$(this).find(".exercise_save_now_button").hide();
  739. $(this).removeClass("question_highlight");
  740. });
  741. $(".no_remind_highlight").hide();
  742. // if the users validates the form using return key, prevent form action and simulates click on validation button
  743. /*$("#exercise_form").submit(function(){
  744. $(".question-validate-btn").first().trigger("click");
  745. return false;
  746. });*/
  747. });
  748. function previous_question(question_num) {
  749. url = "exercise_submit.php?'.$params.'&num="+question_num;
  750. window.location = url;
  751. }
  752. function previous_question_and_save(previous_question_id, question_id_to_save) {
  753. url = "exercise_submit.php?'.$params.'&num="+previous_question_id;
  754. //Save the current question
  755. save_now(question_id_to_save, url);
  756. }
  757. function save_question_list(question_list) {
  758. $.each(question_list, function(key, question_id) {
  759. save_now(question_id, null, false);
  760. });
  761. var url = "";
  762. if ('.$reminder.' == 1 ) {
  763. url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
  764. } else if ('.$reminder.' == 2 ) {
  765. url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
  766. } else {
  767. url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
  768. }
  769. //$("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL)).'");
  770. window.location = url;
  771. }
  772. function save_now(question_id, url_extra) {
  773. //1. Normal choice inputs
  774. var my_choice = $(\'*[name*="choice[\'+question_id+\']"]\').serialize();
  775. //2. Reminder checkbox
  776. var remind_list = $(\'*[name*="remind_list"]\').serialize();
  777. //3. Hotspots
  778. var hotspot = $(\'*[name*="hotspot[\'+question_id+\']"]\').serialize();
  779. // Checking FCK
  780. if (question_id) {
  781. if (CKEDITOR.instances["choice["+question_id+"]"]) {
  782. var ckContent = CKEDITOR.instances["choice["+question_id+"]"].getData();
  783. my_choice = {};
  784. my_choice["choice["+question_id+"]"] = ckContent;
  785. my_choice = $.param(my_choice);
  786. }
  787. }
  788. if ($(\'input[name="remind_list[\'+question_id+\']"]\').is(\':checked\')) {
  789. $("#question_div_"+question_id).addClass("remind_highlight");
  790. } else {
  791. $("#question_div_"+question_id).removeClass("remind_highlight");
  792. }
  793. // Only for the first time
  794. $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('loading1.gif')).'");
  795. $.ajax({
  796. type:"post",
  797. async: false,
  798. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
  799. data: "'.$params.'&type=simple&question_id="+question_id+"&"+my_choice+"&"+hotspot+"&"+remind_list,
  800. success: function(return_value) {
  801. if (return_value == "ok") {
  802. $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL)).'");
  803. } else if (return_value == "error") {
  804. $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'");
  805. } else if (return_value == "one_per_page") {
  806. var url = "";
  807. if ('.$reminder.' == 1 ) {
  808. url = "exercise_reminder.php?'.$params.'&num='.$current_question.'";
  809. } else if ('.$reminder.' == 2 ) {
  810. url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'&reminder=2";
  811. } else {
  812. url = "exercise_submit.php?'.$params.'&num='.$current_question.'&remind_question_id='.$remind_question_id.'";
  813. }
  814. if (url_extra) {
  815. url = url_extra;
  816. }
  817. $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('save.png', get_lang('Saved'), array(), ICON_SIZE_SMALL)).'");
  818. window.location = url;
  819. }
  820. },
  821. error: function() {
  822. $("#save_for_now_"+question_id).html("'.addslashes(Display::return_icon('error.png', get_lang('Error'), array(), ICON_SIZE_SMALL)).'");
  823. }
  824. });
  825. return false;
  826. }
  827. function save_now_all(validate) {
  828. // 1. Input choice.
  829. var my_choice = $(\'*[name*="choice"]\').serialize();
  830. // 2. Reminder.
  831. var remind_list = $(\'*[name*="remind_list"]\').serialize();
  832. // 3. Hotspots.
  833. var hotspot = $(\'*[name*="hotspot"]\').serialize();
  834. // Question list.
  835. var question_list = ['.implode(',', $questionList).'];
  836. var free_answers = {};
  837. $.each(question_list, function(index, my_question_id) {
  838. // Checking FCK
  839. if (my_question_id) {
  840. if (CKEDITOR.instances["choice["+my_question_id+"]"]) {
  841. var ckContent = CKEDITOR.instances["choice["+my_question_id+"]"].getData();
  842. free_answers["free_choice["+my_question_id+"]"] = ckContent;
  843. }
  844. }
  845. });
  846. free_answers = $.param(free_answers);
  847. $("#save_all_reponse").html("'.addslashes(Display::return_icon('loading1.gif')).'");
  848. $.ajax({
  849. type:"post",
  850. async: false,
  851. url: "'.api_get_path(WEB_AJAX_PATH).'exercise.ajax.php?a=save_exercise_by_now",
  852. data: "'.$params.'&type=all&"+my_choice+"&"+hotspot+"&"+free_answers+"&"+remind_list,
  853. success: function(return_value) {
  854. if (return_value == "ok") {
  855. //$("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'");
  856. if (validate == "validate") {
  857. window.location = "'.$script_php.'?'.$params.'";
  858. } else {
  859. $("#save_all_reponse").html("'.addslashes(Display::return_icon('accept.png')).'");
  860. }
  861. } else {
  862. $("#save_all_reponse").html("'.addslashes(Display::return_icon('wrong.gif')).'");
  863. }
  864. }
  865. });
  866. return false;
  867. }
  868. function validate_all() {
  869. save_now_all("validate");
  870. return false;
  871. }
  872. </script>';
  873. echo '<form id="exercise_form" method="post" action="'.api_get_self().'?'.api_get_cidreq().'&autocomplete=off&gradebook='.$gradebook."&exerciseId=" . $exerciseId .'" name="frm_exercise" '.$onsubmit.'>
  874. <input type="hidden" name="formSent" value="1" />
  875. <input type="hidden" name="exerciseId" value="'.$exerciseId . '" />
  876. <input type="hidden" name="num" value="'.$current_question.'" id="num_current_id" />
  877. <input type="hidden" name="num_answer" value="'.$currentAnswer.'" id="num_current_answer_id" />
  878. <input type="hidden" name="exe_id" value="'.$exe_id . '" />
  879. <input type="hidden" name="origin" value="'.$origin . '" />
  880. <input type="hidden" name="learnpath_id" value="'.$learnpath_id . '" />
  881. <input type="hidden" name="learnpath_item_id" value="'.$learnpath_item_id . '" />
  882. <input type="hidden" name="learnpath_item_view_id" value="'.$learnpath_item_view_id . '" />';
  883. // Show list of questions
  884. $i = 1;
  885. $attempt_list = array();
  886. if (isset($exe_id)) {
  887. $attempt_list = Event::getAllExerciseEventByExeId($exe_id);
  888. }
  889. $remind_list = array();
  890. if (isset($exercise_stat_info['questions_to_check']) && !empty($exercise_stat_info['questions_to_check'])) {
  891. $remind_list = explode(',', $exercise_stat_info['questions_to_check']);
  892. }
  893. foreach ($questionList as $questionId) {
  894. // for sequential exercises
  895. if ($objExercise->type == ONE_PER_PAGE) {
  896. // if it is not the right question, goes to the next loop iteration
  897. if ($current_question != $i) {
  898. $i++;
  899. continue;
  900. } else {
  901. if ($objExercise->feedback_type != EXERCISE_FEEDBACK_TYPE_DIRECT) {
  902. // if the user has already answered this question
  903. if (isset($exerciseResult[$questionId])) {
  904. // construction of the Question object
  905. $objQuestionTmp = Question::read($questionId);
  906. $questionName = $objQuestionTmp->selectTitle();
  907. // destruction of the Question object
  908. unset ($objQuestionTmp);
  909. Display :: display_normal_message(get_lang('AlreadyAnswered'));
  910. $i++;
  911. break;
  912. }
  913. }
  914. }
  915. }
  916. $user_choice = isset($attempt_list[$questionId]) ? $attempt_list[$questionId] : null;
  917. $remind_highlight = '';
  918. //Hides questions when reviewing a ALL_ON_ONE_PAGE exercise see #4542 no_remind_highlight class hide with jquery
  919. if ($objExercise->type == ALL_ON_ONE_PAGE && isset($_GET['reminder']) && $_GET['reminder'] == 2) {
  920. $remind_highlight = 'no_remind_highlight';
  921. }
  922. $exercise_actions = '';
  923. $is_remind_on = false;
  924. $attributes = array('id' =>'remind_list['.$questionId.']');
  925. if (in_array($questionId, $remind_list)) {
  926. $is_remind_on = true;
  927. $attributes['checked'] = 1;
  928. $remind_question = true;
  929. $remind_highlight = ' remind_highlight ';
  930. }
  931. // Showing the question
  932. echo '<div id="question_div_'.$questionId.'" class="main_question '.$remind_highlight.'" >';
  933. // Shows the question and its answers
  934. ExerciseLib::showQuestion($questionId, false, $origin, $i, true, false, $user_choice, false);
  935. // Button save and continue
  936. switch ($objExercise->type) {
  937. case ONE_PER_PAGE:
  938. $exercise_actions .= $objExercise->show_button($questionId, $current_question);
  939. break;
  940. case ALL_ON_ONE_PAGE :
  941. $button = '<a href="javascript://" class="btn btn-info" onclick="save_now(\''.$questionId.'\'); ">'.get_lang('SaveForNow').'</a>';
  942. $button .= '<span id="save_for_now_'.$questionId.'"></span>&nbsp;';
  943. $exercise_actions .= Display::div($button, array('class'=>'exercise_save_now_button'));
  944. break;
  945. }
  946. // Checkbox review answers
  947. if ($objExercise->review_answers) {
  948. $remind_question_div = Display::tag(
  949. 'label',
  950. Display::input(
  951. 'checkbox',
  952. 'remind_list[' . $questionId . ']',
  953. '',
  954. $attributes
  955. ) . get_lang('ReviewQuestionLater'),
  956. array(
  957. 'class' => 'checkbox',
  958. 'for' => 'remind_list[' . $questionId . ']'
  959. )
  960. );
  961. $exercise_actions .= Display::div($remind_question_div, array('class'=>'exercise_save_now_button'));
  962. }
  963. echo Display::div($exercise_actions, array('class'=>'form-actions'));
  964. echo '</div>';
  965. $i++;
  966. // for sequential exercises
  967. if ($objExercise->type == ONE_PER_PAGE) {
  968. // quits the loop
  969. break;
  970. }
  971. }
  972. // end foreach()
  973. if ($objExercise->type == ALL_ON_ONE_PAGE) {
  974. $exercise_actions = $objExercise->show_button($questionId, $current_question);
  975. echo Display::div($exercise_actions, array('class'=>'exercise_actions'));
  976. }
  977. echo '</form>';
  978. }
  979. if ($origin != 'learnpath') {
  980. // So we are not in learnpath tool
  981. echo '</div>'; //End glossary div
  982. Display :: display_footer();
  983. } else {
  984. echo '</body></html>';
  985. }