exercise_submit.php 47 KB

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