exercise_submit.php 47 KB

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