exercise_submit.php 46 KB

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