exercise_submit.php 47 KB

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