exercise_submit.php 48 KB

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