exercice_submit.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117
  1. <?php
  2. // $Id: exercice_submit.php 22201 2009-07-17 19:57:03Z cfasanando $
  3. /*
  4. ==============================================================================
  5. Dokeos - elearning and course management software
  6. Copyright (c) 2004-2008 Dokeos SPRL
  7. Copyright (c) 2003 Ghent University (UGent)
  8. Copyright (c) 2001 Universite catholique de Louvain (UCL)
  9. Copyright (c) various contributors
  10. For a full list of contributors, see "credits.txt".
  11. The full license can be read in "license.txt".
  12. This program is free software; you can redistribute it and/or
  13. modify it under the terms of the GNU General Public License
  14. as published by the Free Software Foundation; either version 2
  15. of the License, or (at your option) any later version.
  16. See the GNU General Public License for more details.
  17. Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  18. Mail: info@dokeos.com
  19. ==============================================================================
  20. */
  21. /**
  22. * Exercise submission
  23. * This script allows to run an exercise. According to the exercise type, questions
  24. * can be on an unique page, or one per page with a Next button.
  25. *
  26. * One exercise may contain different types of answers (unique or multiple selection,
  27. * matching, fill in blanks, free answer, hot-spot).
  28. *
  29. * Questions are selected randomly or not.
  30. *
  31. * When the user has answered all questions and clicks on the button "Ok",
  32. * it goes to exercise_result.php
  33. *
  34. * Notice : This script is also used to show a question before modifying it by
  35. * the administrator
  36. * @package dokeos.exercise
  37. * @author Olivier Brouckaert
  38. * @author Julio Montoya multiple fill in blank option added
  39. * @version $Id: exercice_submit.php 22201 2009-07-17 19:57:03Z cfasanando $
  40. */
  41. require_once 'exercise.class.php';
  42. require_once 'question.class.php';
  43. require_once 'answer.class.php';
  44. require_once 'exercise.lib.php';
  45. // debug var. Set to 0 to hide all debug display. Set to 1 to display debug messages.
  46. $debug = 0;
  47. /*
  48. // answer types
  49. define('UNIQUE_ANSWER', 1);
  50. define('MULTIPLE_ANSWER', 2);
  51. define('FILL_IN_BLANKS', 3);
  52. define('MATCHING', 4);
  53. define('FREE_ANSWER', 5);
  54. define('HOT_SPOT', 6);
  55. define('HOT_SPOT_ORDER', 7);
  56. */
  57. // name of the language file that needs to be included
  58. $language_file = 'exercice';
  59. require_once '../inc/global.inc.php';
  60. $this_section = SECTION_COURSES;
  61. /* ------------ ACCESS RIGHTS ------------ */
  62. // notice for unauthorized people.
  63. api_protect_course_script(true);
  64. require_once api_get_path(LIBRARY_PATH) . 'text.lib.php';
  65. $is_allowedToEdit = api_is_allowed_to_edit(null,true);
  66. $_configuration['live_exercise_tracking'] = true;
  67. $stat_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  68. $exercice_attemp_table = Database :: get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  69. $TBL_EXERCICE_QUESTION = Database :: get_course_table(TABLE_QUIZ_TEST_QUESTION);
  70. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  71. $TBL_QUESTIONS = Database :: get_course_table(TABLE_QUIZ_QUESTION);
  72. $TBL_REPONSES = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  73. // general parameters passed via POST/GET
  74. if (empty ($origin)) {
  75. $origin = $_REQUEST['origin'];
  76. }
  77. if (empty ($learnpath_id)) {
  78. $learnpath_id = Security::remove_XSS($_REQUEST['learnpath_id']);
  79. }
  80. if (empty ($learnpath_item_id)) {
  81. $learnpath_item_id = Security::remove_XSS($_REQUEST['learnpath_item_id']);
  82. }
  83. if (empty ($formSent)) {
  84. $formSent = $_REQUEST['formSent'];
  85. }
  86. if (empty ($exerciseResult)) {
  87. $exerciseResult = $_REQUEST['exerciseResult'];
  88. }
  89. if (empty ($exerciseResultCoordinates)) {
  90. $exerciseResultCoordinates = $_REQUEST['exerciseResultCoordinates'];
  91. }
  92. if (empty ($exerciseType)) {
  93. $exerciseType = $_REQUEST['exerciseType'];
  94. }
  95. if (empty ($exerciseId)) {
  96. $exerciseId = Database::escape_string(intval($_REQUEST['exerciseId']));
  97. }
  98. if (empty ($choice)) {
  99. $choice = $_REQUEST['choice'];
  100. }
  101. if (empty ($_REQUEST['choice'])) {
  102. $choice = $_REQUEST['choice2'];
  103. }
  104. if (empty ($questionNum)) {
  105. $questionNum = Database :: escape_string($_REQUEST['questionNum']);
  106. }
  107. if (empty ($nbrQuestions)) {
  108. $nbrQuestions = Database :: escape_string($_REQUEST['nbrQuestions']);
  109. }
  110. if (empty ($buttonCancel)) {
  111. $buttonCancel = $_REQUEST['buttonCancel'];
  112. }
  113. $error = '';
  114. if (!isset ($exerciseType)) {
  115. $exe_start_date = time();
  116. $_SESSION['exercice_start_date'] = $exe_start_date;
  117. }
  118. // if the user has clicked on the "Cancel" button
  119. if ($buttonCancel) {
  120. // returns to the exercise list
  121. header("Location: exercice.php?origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  122. exit ();
  123. }
  124. if ($origin == 'learnpath' && isset ($_GET['not_multiple_attempt']) && $_GET['not_multiple_attempt'] == strval(intval($_GET['not_multiple_attempt']))) {
  125. $not_multiple_attempt = (int) $_GET['not_multiple_attempt'];
  126. if ($not_multiple_attempt === 1) {
  127. require_once '../inc/reduced_header.inc.php';
  128. echo '<div style="height:10px">&nbsp;</div>';
  129. Display :: display_warning_message(get_lang('ReachedOneAttempt'));
  130. exit;
  131. }
  132. }
  133. if ($origin == 'builder') {
  134. /*******************************/
  135. /* Clears the exercise session */
  136. /*******************************/
  137. if (isset ($_SESSION['objExercise'])) {
  138. api_session_unregister('objExercise');
  139. unset ($objExercise);
  140. }
  141. if (isset ($_SESSION['objQuestion'])) {
  142. api_session_unregister('objQuestion');
  143. unset ($objQuestion);
  144. }
  145. if (isset ($_SESSION['objAnswer'])) {
  146. api_session_unregister('objAnswer');
  147. unset ($objAnswer);
  148. }
  149. if (isset ($_SESSION['questionList'])) {
  150. api_session_unregister('questionList');
  151. unset ($questionList);
  152. }
  153. if (isset ($_SESSION['newquestionList'])) {
  154. api_session_unregister('newquestionList');
  155. unset ($newquestionList);
  156. }
  157. if (isset ($_SESSION['exerciseResult'])) {
  158. api_session_unregister('exerciseResult');
  159. unset ($exerciseResult);
  160. }
  161. if (isset ($_SESSION['exerciseResultCoordinates'])) {
  162. api_session_unregister('exerciseResultCoordinates');
  163. unset ($exerciseResultCoordinates);
  164. }
  165. }
  166. $safe_lp_id = ($learnpath_id == '') ? 0 : (int) $learnpath_id;
  167. $safe_lp_item_id = ($learnpath_item_id == '') ? 0 : (int) $learnpath_item_id;
  168. $condition = ' WHERE ' .
  169. 'exe_exo_id = ' . "'" . $exerciseId . "'" . ' AND ' .
  170. 'exe_user_id = ' . "'" . api_get_user_id() . "'" . ' AND ' .
  171. 'exe_cours_id = ' . "'" . $_course['id'] . "'" . ' AND ' .
  172. 'status = ' . "'incomplete'" . ' AND ' .
  173. 'orig_lp_id = ' . "'" . $safe_lp_id . "'" . ' AND ' .
  174. 'orig_lp_item_id = ' . "'" . $safe_lp_item_id . "'" . ' AND ' .
  175. 'session_id = ' . "'" . (int) $_SESSION['id_session'] . "'";
  176. $TBL_EXERCICES = Database :: get_course_table(TABLE_QUIZ_TEST);
  177. $result = Database::query("SELECT type,feedback_type FROM $TBL_EXERCICES WHERE id=$exerciseId", __FILE__, __LINE__);
  178. $exercise_row = Database :: fetch_array($result);
  179. $exerciseType = $exercise_row['type'];
  180. $exerciseFeedbackType = $exercise_row['feedback_type'];
  181. if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $exerciseFeedbackType != 1) {
  182. $query = 'SELECT * FROM ' . $stat_table . $condition;
  183. $result_select = Database::query($query, __FILE__, __LINE__);
  184. if (Database :: num_rows($result_select) > 0) {
  185. $getIncomplete = Database :: fetch_array($result_select);
  186. $exe_id = $getIncomplete['exe_id'];
  187. if ($_SERVER['REQUEST_METHOD'] != 'POST') {
  188. define('QUESTION_LIST_ALREADY_LOGGED', 1);
  189. $recorded['questionList'] = explode(',', $getIncomplete['data_tracking']);
  190. $query = 'SELECT * FROM ' . $exercice_attemp_table . ' WHERE exe_id = ' . $getIncomplete['exe_id'] . ' ORDER BY tms ASC';
  191. $result = Database::query($query, __FILE__, __LINE__);
  192. while ($row = Database :: fetch_array($result)) {
  193. $recorded['exerciseResult'][$row['question_id']] = 1;
  194. }
  195. $exerciseResult = $_SESSION['exerciseResult'] = $recorded['exerciseResult'];
  196. $exerciseType = 2;
  197. $questionNum = count($recorded['exerciseResult']);
  198. $questionNum++;
  199. $questionList = $_SESSION['questionList'] = $recorded['questionList'];
  200. }
  201. } else {
  202. $table_recorded_not_exist = true;
  203. }
  204. }
  205. // if the user has submitted the form
  206. if ($formSent) {
  207. if ($debug > 0) {
  208. echo str_repeat('&nbsp;', 0) . '$formSent was set' . "<br />\n";
  209. }
  210. // initializing
  211. if (!is_array($exerciseResult)) {
  212. $exerciseResult = array ();
  213. $exerciseResultCoordinates = array ();
  214. }
  215. // if the user has answered at least one question
  216. if (is_array($choice)) {
  217. if ($debug > 0) {
  218. echo str_repeat('&nbsp;', 0) . '$choice is an array' . "<br />\n";
  219. }
  220. if ($exerciseType == 1)
  221. {
  222. // $exerciseResult receives the content of the form.
  223. // Each choice of the student is stored into the array $choice
  224. $exerciseResult = $choice;
  225. // Also store hotspot spots in the session ($exerciseResultCoordinates
  226. // will be stored in the session at the end of this script)
  227. // The results will be stored by exercise_result.php if we are in
  228. // an exercise of type 1 (=all on one page)
  229. if (isset ($_POST['hotspot'])) {
  230. $exerciseResultCoordinates = $_POST['hotspot'];
  231. }
  232. } else {
  233. // gets the question ID from $choice. It is the key of the array
  234. list ($key) = array_keys($choice);
  235. // if the user didn't already answer this question
  236. if (!isset ($exerciseResult[$key])) {
  237. // stores the user answer into the array
  238. $exerciseResult[$key] = $choice[$key];
  239. //saving each question
  240. if ($_configuration['live_exercise_tracking'] == true && $exerciseType == 2 && $exerciseFeedbackType != 1) {
  241. $nro_question = $questionNum; // - 1;
  242. //START of saving and qualifying each question submitted
  243. //------------------------------------------------------------------------------------------
  244. //
  245. define('ENABLED_LIVE_EXERCISE_TRACKING', 1);
  246. require_once 'question.class.php';
  247. require_once 'answer.class.php';
  248. $counter = 0;
  249. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  250. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  251. //foreach($questionList as $questionId)
  252. if (true) {
  253. $exeId = $exe_id;
  254. $questionId = $key;
  255. $counter++;
  256. // gets the student choice for this question
  257. $choice = $exerciseResult[$questionId];
  258. // creates a temporary Question object
  259. $objQuestionTmp = Question :: read($questionId);
  260. $questionName = $objQuestionTmp->selectTitle();
  261. $questionDescription = $objQuestionTmp->selectDescription();
  262. $questionWeighting = $objQuestionTmp->selectWeighting();
  263. $answerType = $objQuestionTmp->selectType();
  264. $quesId = $objQuestionTmp->selectId(); //added by priya saini
  265. // destruction of the Question object
  266. unset ($objQuestionTmp);
  267. if (isset ($_POST['hotspot']) && isset($_POST['hotspot'][$key])) {
  268. $exerciseResultCoordinates[$key] = $_POST['hotspot'][$key];
  269. }
  270. // construction of the Answer object
  271. $objAnswerTmp = new Answer($questionId);
  272. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  273. $questionScore = 0;
  274. if ($answerType == FREE_ANSWER) {
  275. $nbrAnswers = 1;
  276. }
  277. for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
  278. $answer = $objAnswerTmp->selectAnswer($answerId);
  279. $answerComment = $objAnswerTmp->selectComment($answerId);
  280. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  281. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  282. switch ($answerType) {
  283. // for unique answer
  284. case UNIQUE_ANSWER :
  285. $studentChoice = ($choice == $answerId) ? 1 : 0;
  286. if ($studentChoice) {
  287. $questionScore += $answerWeighting;
  288. $totalScore += $answerWeighting;
  289. }
  290. break;
  291. // for multiple answers
  292. case MULTIPLE_ANSWER :
  293. $studentChoice = $choice[$answerId];
  294. if ($studentChoice) {
  295. $questionScore += $answerWeighting;
  296. $totalScore += $answerWeighting;
  297. }
  298. break;
  299. // for fill in the blanks
  300. case FILL_IN_BLANKS :
  301. // the question is encoded like this
  302. // [A] B [C] D [E] F::10,10,10@1
  303. // number 1 before the "@" means that is a switchable fill in blank question
  304. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  305. // means that is a normal fill blank question
  306. // first we explode the "::"
  307. $pre_array = explode('::', $answer);
  308. // is switchable fill blank or not
  309. $last = count($pre_array) - 1;
  310. $is_set_switchable = explode('@', $pre_array[$last]);
  311. $switchable_answer_set = false;
  312. if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
  313. $switchable_answer_set = true;
  314. }
  315. $answer = '';
  316. for ($k = 0; $k < $last; $k++) {
  317. $answer .= $pre_array[$k];
  318. }
  319. // splits weightings that are joined with a comma
  320. $answerWeighting = explode(',', $is_set_switchable[0]);
  321. // we save the answer because it will be modified
  322. $temp = $answer;
  323. // TeX parsing
  324. // 1. find everything between the [tex] and [/tex] tags
  325. $startlocations = strpos($temp, '[tex]');
  326. $endlocations = strpos($temp, '[/tex]');
  327. if ($startlocations !== false && $endlocations !== false) {
  328. $texstring = substr($temp, $startlocations, $endlocations - $startlocations +6);
  329. // 2. replace this by {texcode}
  330. $temp = str_replace($texstring, '{texcode}', $temp);
  331. }
  332. $answer = '';
  333. $j = 0;
  334. //initialise answer tags
  335. $user_tags = array ();
  336. $correct_tags = array ();
  337. $real_text = array ();
  338. // the loop will stop at the end of the text
  339. while (1) {
  340. // quits the loop if there are no more blanks (detect '[')
  341. if (($pos = strpos($temp, '[')) === false) {
  342. // adds the end of the text
  343. $answer = $temp;
  344. // TeX parsing - replacement of texcode tags
  345. $texstring = api_parse_tex($texstring);
  346. $answer = str_replace("{texcode}", $texstring, $answer);
  347. $real_text[] = $answer;
  348. break; //no more "blanks", quit the loop
  349. }
  350. // adds the piece of text that is before the blank
  351. //and ends with '[' into a general storage array
  352. $real_text[] = substr($temp, 0, $pos +1);
  353. $answer .= substr($temp, 0, $pos +1);
  354. //take the string remaining (after the last "[" we found)
  355. $temp = substr($temp, $pos +1);
  356. // quit the loop if there are no more blanks, and update $pos to the position of next ']'
  357. if (($pos = strpos($temp, ']')) === false) {
  358. // adds the end of the text
  359. $answer .= $temp;
  360. break;
  361. }
  362. $choice[$j] = trim($choice[$j]);
  363. $user_tags[] = strtolower($choice[$j]);
  364. //put the contents of the [] answer tag into correct_tags[]
  365. $correct_tags[] = strtolower(substr($temp, 0, $pos));
  366. $j++;
  367. $temp = substr($temp, $pos +1);
  368. //$answer .= ']';
  369. }
  370. $answer = '';
  371. $real_correct_tags = $correct_tags;
  372. $chosen_list = array ();
  373. for ($i = 0; $i < count($real_correct_tags); $i++) {
  374. if ($i == 0) {
  375. $answer .= $real_text[0];
  376. }
  377. if (!$switchable_answer_set) {
  378. if ($correct_tags[$i] == $user_tags[$i]) {
  379. // gives the related weighting to the student
  380. $questionScore += $answerWeighting[$i];
  381. // increments total score
  382. $totalScore += $answerWeighting[$i];
  383. // adds the word in green at the end of the string
  384. $answer .= $correct_tags[$i];
  385. }
  386. // else if the word entered by the student IS NOT the same as the one defined by the professor
  387. elseif (!empty ($user_tags[$i])) {
  388. // adds the word in red at the end of the string, and strikes it
  389. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  390. } else {
  391. // adds a tabulation if no word has been typed by the student
  392. $answer .= '&nbsp;&nbsp;&nbsp;';
  393. }
  394. } else {
  395. // switchable fill in the blanks
  396. if (in_array($user_tags[$i], $correct_tags)) {
  397. $chosen_list[] = $user_tags[$i];
  398. $correct_tags = array_diff($correct_tags, $chosen_list);
  399. // gives the related weighting to the student
  400. $questionScore += $answerWeighting[$i];
  401. // increments total score
  402. $totalScore += $answerWeighting[$i];
  403. // adds the word in green at the end of the string
  404. $answer .= $user_tags[$i];
  405. }
  406. elseif (!empty ($user_tags[$i])) {
  407. // else if the word entered by the student IS NOT the same as the one defined by the professor
  408. // adds the word in red at the end of the string, and strikes it
  409. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  410. } else {
  411. // adds a tabulation if no word has been typed by the student
  412. $answer .= '&nbsp;&nbsp;&nbsp;';
  413. }
  414. }
  415. // adds the correct word, followed by ] to close the blank
  416. $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
  417. if (isset ($real_text[$i +1])) {
  418. $answer .= $real_text[$i +1];
  419. }
  420. }
  421. break;
  422. // for free answer
  423. case FREE_ANSWER :
  424. $studentChoice = $choice;
  425. if ($studentChoice) {
  426. //Score is at -1 because the question has'nt been corected
  427. $questionScore = -1;
  428. $totalScore += 0;
  429. }
  430. break;
  431. // for matching
  432. case MATCHING :
  433. if ($answerCorrect) {
  434. if ($answerCorrect == $choice[$answerId]) {
  435. $questionScore += $answerWeighting;
  436. $totalScore += $answerWeighting;
  437. $choice[$answerId] = $matching[$choice[$answerId]];
  438. }
  439. elseif (!$choice[$answerId]) {
  440. $choice[$answerId] = '&nbsp;&nbsp;&nbsp;';
  441. } else {
  442. $choice[$answerId] = '<font color="red"><s>' . $matching[$choice[$answerId]] . '</s></font>';
  443. }
  444. } else {
  445. $matching[$answerId] = $answer;
  446. }
  447. break;
  448. // for hotspot with no order
  449. case HOT_SPOT :
  450. $studentChoice = $choice[$answerId];
  451. if ($studentChoice) {
  452. $questionScore += $answerWeighting;
  453. $totalScore += $answerWeighting;
  454. }
  455. break;
  456. // for hotspot with fixed order
  457. case HOT_SPOT_ORDER :
  458. $studentChoice = $choice['order'][$answerId];
  459. if ($studentChoice == $answerId) {
  460. $questionScore += $answerWeighting;
  461. $totalScore += $answerWeighting;
  462. $studentChoice = true;
  463. } else {
  464. $studentChoice = false;
  465. }
  466. break;
  467. } // end switch Answertype
  468. } // end for that loops over all answers of the current question
  469. // destruction of Answer
  470. unset ($objAnswerTmp);
  471. $i++;
  472. $totalWeighting += $questionWeighting;
  473. //added by priya saini
  474. // Store results directly in the database
  475. // For all in one page exercises, the results will be
  476. // stored by exercise_results.php (using the session)
  477. if ($_configuration['tracking_enabled']) {
  478. if (empty ($choice)) {
  479. $choice = 0;
  480. }
  481. if ($answerType == MULTIPLE_ANSWER) {
  482. if ($choice != 0) {
  483. $reply = array_keys($choice);
  484. for ($i = 0; $i < sizeof($reply); $i++) {
  485. $ans = $reply[$i];
  486. exercise_attempt($questionScore, $ans, $quesId, $exeId, $i);
  487. }
  488. } else {
  489. exercise_attempt($questionScore, 0, $quesId, $exeId, 0);
  490. }
  491. }
  492. elseif ($answerType == MATCHING) {
  493. $j = sizeof($matching) + 1;
  494. for ($i = 0; $i < sizeof($choice); $i++, $j++) {
  495. $val = $choice[$j];
  496. if (preg_match_all('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1)) {
  497. $val = $arr1[1][0];
  498. }
  499. $val = $val;
  500. $val = strip_tags($val);
  501. $sql = "select position from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and answer='" . Database :: escape_string($val) . "' AND correct=0";
  502. $res = Database::query($sql, __FILE__, __LINE__);
  503. if (Database :: num_rows($res) > 0) {
  504. $answer = Database :: result($res, 0, "position");
  505. } else {
  506. $answer = '';
  507. }
  508. exercise_attempt($questionScore, $answer, $quesId, $exeId, $j);
  509. }
  510. } elseif ($answerType == FREE_ANSWER) {
  511. $answer = $choice;
  512. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  513. } elseif ($answerType == UNIQUE_ANSWER) {
  514. $answer = $choice;
  515. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  516. } elseif ($answerType == HOT_SPOT) {
  517. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  518. if (is_array($exerciseResultCoordinates[$key])) {
  519. foreach($exerciseResultCoordinates[$key] as $idx => $val) {
  520. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
  521. }
  522. }
  523. } else {
  524. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  525. }
  526. }
  527. }
  528. // end huge foreach() block that loops over all questions
  529. //at loops over all questions
  530. if (isset($exe_id)) {
  531. $sql_update = 'UPDATE ' . $stat_table . ' SET exe_result = exe_result + ' . (int) $totalScore . ',exe_weighting = exe_weighting + ' . (int) $totalWeighting . ' WHERE exe_id = ' . Database::escape_string($exe_id);
  532. Database::query($sql_update, __FILE__, __LINE__);
  533. }
  534. //END of saving and qualifying
  535. //------------------------------------------------------------------------------------------
  536. //
  537. }
  538. }
  539. }
  540. if ($debug > 0) {
  541. echo str_repeat('&nbsp;', 0) . '$choice is an array - end' . "<br />\n";
  542. }
  543. }
  544. // the script "exercise_result.php" will take the variable $exerciseResult from the session
  545. api_session_register('exerciseResult');
  546. api_session_register('exerciseResultCoordinates');
  547. define('ALL_ON_ONE_PAGE',1);
  548. define('ONE_PER_PAGE',2);
  549. // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
  550. if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) {
  551. if ($debug > 0) {
  552. echo str_repeat('&nbsp;', 0) . 'Redirecting to exercise_result.php - Remove debug option to let this happen' . "<br />\n";
  553. }
  554. if ( api_is_allowed_to_session_edit() ) {
  555. // goes to the script that will show the result of the exercise
  556. if ($exerciseType == ALL_ON_ONE_PAGE) {
  557. header("Location: exercise_result.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  558. } else {
  559. if ($exe_id != '') {
  560. //clean incomplete
  561. $update_query = 'UPDATE ' . $stat_table . ' SET ' . "status = '', data_tracking='', exe_date = '" . date('Y-m-d H:i:s') . "'" . ' WHERE exe_id = ' . Database::escape_string($exe_id);
  562. Database::query($update_query, __FILE__, __LINE__);
  563. }
  564. header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  565. }
  566. exit ();
  567. } else {
  568. header("Location: exercice_submit.php?exerciseId=$exerciseId");
  569. exit;
  570. }
  571. }
  572. if ($debug > 0) {
  573. echo str_repeat('&nbsp;', 0) . '$formSent was set - end' . "<br />\n";
  574. }
  575. }
  576. // if the object is not in the session
  577. //why destroying the exercise when a LP is loaded ?
  578. //if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  579. if (!isset ($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  580. if ($debug > 0) {
  581. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset' . "<br />\n";
  582. }
  583. // construction of Exercise
  584. $objExercise = new Exercise();
  585. unset ($_SESSION['questionList']);
  586. // if the specified exercise doesn't exist or is disabled
  587. if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) {
  588. unset ($objExercise);
  589. $error = get_lang('ExerciseNotFound');
  590. //die(get_lang('ExerciseNotFound'));
  591. } else {
  592. // saves the object into the session
  593. api_session_register('objExercise');
  594. if ($debug > 0) {
  595. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset - set now - end' . "<br />\n";
  596. }
  597. }
  598. }
  599. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  600. $objExercise = $_SESSION['objExercise'];
  601. }
  602. if (!is_object($objExercise)) {
  603. header('Location: exercice.php');
  604. exit ();
  605. }
  606. $Exe_starttime = $objExercise->start_time;
  607. $Exe_endtime = $objExercise->end_time;
  608. $quizID = $objExercise->selectId();
  609. $exerciseAttempts = $objExercise->selectAttempts();
  610. $exerciseTitle = $objExercise->selectTitle();
  611. $exerciseDescription = $objExercise->selectDescription();
  612. $exerciseDescription = $exerciseDescription;
  613. $exerciseSound = $objExercise->selectSound();
  614. $randomQuestions = $objExercise->isRandom();
  615. $exerciseType = $objExercise->selectType();
  616. $table_quiz_test = Database :: get_course_table(TABLE_QUIZ_TEST);
  617. //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
  618. //in LP's is enabled the "remember question" feature?
  619. $my_exe_id = Security :: remove_XSS($_GET['exerciseId']);
  620. if (!isset ($_SESSION['questionList'])) {
  621. if ($debug > 0) {
  622. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset' . "<br />\n";
  623. }
  624. // selects the list of question ID
  625. $my_question_list = array ();
  626. $questionList = ($randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList());
  627. // saves the question list into the session
  628. $sql = 'SELECT random FROM ' . $table_quiz_test . ' WHERE id="' . Database :: escape_string($my_exe_id) . '";';
  629. $rs = Database::query($sql, __FILE__, __LINE__);
  630. $row_number = Database :: fetch_array($rs);
  631. $z = 0;
  632. if ($row_number['random'] <> 0) {
  633. foreach ($questionList as $infoquestionList) {
  634. if ($z < $row_number['random']) {
  635. $my_question_list[$z] = $infoquestionList;
  636. } else {
  637. break;
  638. }
  639. $z++;
  640. }
  641. // $questionList=array();
  642. $questionList = $my_question_list;
  643. }
  644. api_session_register('questionList');
  645. if ($debug > 0) {
  646. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset - set now - end' . "<br />\n";
  647. }
  648. }
  649. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  650. $questionList = $_SESSION['questionList'];
  651. }
  652. $quizStartTime = time();
  653. api_session_register('quizStartTime');
  654. $nbrQuestions = sizeof($questionList);
  655. // if questionNum comes from POST and not from GET
  656. if (!$questionNum || $_POST['questionNum']) {
  657. // only used for sequential exercises (see $exerciseType)
  658. if (!$questionNum) {
  659. $questionNum = 1;
  660. } else {
  661. $questionNum++;
  662. }
  663. }
  664. if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  665. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  666. $gradebook = $_SESSION['gradebook'];
  667. }
  668. elseif (empty ($_GET['gradebook'])) {
  669. unset ($_SESSION['gradebook']);
  670. $gradebook = '';
  671. }
  672. if (!empty ($gradebook) && $gradebook == 'view') {
  673. $interbreadcrumb[] = array (
  674. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  675. 'name' => get_lang('Gradebook')
  676. );
  677. }
  678. //$nameTools=get_lang('Exercice');
  679. $interbreadcrumb[] = array (
  680. "url" => "exercice.php?gradebook=$gradebook",
  681. "name" => get_lang('Exercices')
  682. );
  683. $interbreadcrumb[] = array (
  684. "url" => api_get_self()."?gradebook=$gradebook",
  685. "name" => $exerciseTitle
  686. );
  687. if ($origin != 'learnpath') { //so we are not in learnpath tool
  688. $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  689. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  690. <script language=\"JavaScript\" type=\"text/javascript\">
  691. <!--
  692. // -----------------------------------------------------------------------------
  693. // Globals
  694. // Major version of Flash required
  695. var requiredMajorVersion = 7;
  696. // Minor version of Flash required
  697. var requiredMinorVersion = 0;
  698. // Minor version of Flash required
  699. var requiredRevision = 0;
  700. // the version of javascript supported
  701. var jsVersion = 1.0;
  702. // -----------------------------------------------------------------------------
  703. // -->
  704. </script>
  705. <script language=\"VBScript\" type=\"text/vbscript\">
  706. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  707. Function VBGetSwfVer(i)
  708. on error resume next
  709. Dim swControl, swVersion
  710. swVersion = 0
  711. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  712. if (IsObject(swControl)) then
  713. swVersion = swControl.GetVariable(\"\$version\")
  714. end if
  715. VBGetSwfVer = swVersion
  716. End Function
  717. // -->
  718. </script>
  719. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  720. <!-- // Detect Client Browser type
  721. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  722. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  723. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  724. jsVersion = 1.1;
  725. // JavaScript helper required to detect Flash Player PlugIn version information
  726. function JSGetSwfVer(i){
  727. // NS/Opera version >= 3 check for Flash plugin in plugin array
  728. if (navigator.plugins != null && navigator.plugins.length > 0) {
  729. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  730. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  731. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  732. descArray = flashDescription.split(\" \");
  733. tempArrayMajor = descArray[2].split(\".\");
  734. versionMajor = tempArrayMajor[0];
  735. versionMinor = tempArrayMajor[1];
  736. if ( descArray[3] != \"\" ) {
  737. tempArrayMinor = descArray[3].split(\"r\");
  738. } else {
  739. tempArrayMinor = descArray[4].split(\"r\");
  740. }
  741. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  742. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  743. } else {
  744. flashVer = -1;
  745. }
  746. }
  747. // MSN/WebTV 2.6 supports Flash 4
  748. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  749. // WebTV 2.5 supports Flash 3
  750. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  751. // older WebTV supports Flash 2
  752. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  753. // Can't detect in all other cases
  754. else {
  755. flashVer = -1;
  756. }
  757. return flashVer;
  758. }
  759. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  760. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  761. {
  762. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  763. // loop backwards through the versions until we find the newest version
  764. for (i=25;i>0;i--) {
  765. if (isIE && isWin && !isOpera) {
  766. versionStr = VBGetSwfVer(i);
  767. } else {
  768. versionStr = JSGetSwfVer(i);
  769. }
  770. if (versionStr == -1 ) {
  771. return false;
  772. } else if (versionStr != 0) {
  773. if(isIE && isWin && !isOpera) {
  774. tempArray = versionStr.split(\" \");
  775. tempString = tempArray[1];
  776. versionArray = tempString .split(\",\");
  777. } else {
  778. versionArray = versionStr.split(\".\");
  779. }
  780. versionMajor = versionArray[0];
  781. versionMinor = versionArray[1];
  782. versionRevision = versionArray[2];
  783. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  784. versionNum = parseFloat(versionString);
  785. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  786. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  787. return true;
  788. } else {
  789. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  790. }
  791. }
  792. }
  793. }
  794. // -->
  795. </script>";
  796. Display :: display_header($nameTools, "Exercise");
  797. if (!api_is_allowed_to_session_edit() ) {
  798. Display :: display_warning_message(get_lang('SessionIsReadOnly'));
  799. }
  800. } else {
  801. if (empty ($charset)) {
  802. $charset = 'ISO-8859-15';
  803. }
  804. /*
  805. * HTML HEADER
  806. */
  807. Display::display_reduced_header();
  808. echo '<div style="height:10px">&nbsp;</div>';
  809. }
  810. // I'm in a preview mode
  811. if (api_is_course_admin() && $origin != 'learnpath') {
  812. echo '<div class="actions">';
  813. echo Display :: return_icon('quiz.gif', get_lang('GoBackToEx')) . '<a href="admin.php?' . api_get_cidreq() . '&exerciseId=' . $objExercise->id . '">' . get_lang('GoBackToEx') . '</a>';
  814. echo Display :: return_icon('edit.gif', get_lang('ModifyExercise')) . '<a href="exercise_admin.php?modifyExercise=yes&exerciseId=' . $objExercise->id . '">' . get_lang('ModifyExercise') . '</a>';
  815. echo '</div>';
  816. }
  817. $exerciseTitle = api_parse_tex($exerciseTitle);
  818. echo "<h3>" . $exerciseTitle . "</h3>";
  819. if ($exerciseAttempts > 0) {
  820. $user_id = api_get_user_id();
  821. $course_code = api_get_course_id();
  822. $sql = "SELECT count(*) FROM $stat_table WHERE exe_exo_id = '$quizID'
  823. AND exe_user_id = '$user_id'
  824. AND status != 'incomplete'
  825. AND orig_lp_id = $safe_lp_id
  826. AND orig_lp_item_id = $safe_lp_item_id
  827. AND exe_cours_id = '$course_code' AND session_id = '" . (int) $_SESSION['id_session'] . "'";
  828. $aquery = Database::query($sql, __FILE__, __LINE__);
  829. $attempt = Database :: fetch_array($aquery);
  830. if ($attempt[0] >= $exerciseAttempts) {
  831. if (!api_is_allowed_to_edit(null,true)) {
  832. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $exerciseAttempts), false);
  833. if ($origin != 'learnpath')
  834. Display :: display_footer();
  835. exit;
  836. } else {
  837. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exerciseTitle, $exerciseAttempts), false);
  838. }
  839. }
  840. }
  841. if (!function_exists('convert_date_to_number')) {
  842. function convert_date_to_number($default) {
  843. // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
  844. $parts = split(' ', $default);
  845. list ($d_year, $d_month, $d_day) = split('-', $parts[0]);
  846. list ($d_hour, $d_minute, $d_second) = split(':', $parts[1]);
  847. return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
  848. }
  849. }
  850. $limit_time_exists = (($Exe_starttime != '0000-00-00 00:00:00') || ($Exe_endtime != '0000-00-00 00:00:00')) ? true : false;
  851. if ($limit_time_exists) {
  852. $exercise_start_time = convert_date_to_number($Exe_starttime);
  853. $exercise_end_time = convert_date_to_number($Exe_endtime);
  854. $time_now = convert_date_to_number(date('Y-m-d H:i:s'));
  855. $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
  856. if ($_SERVER['REQUEST_METHOD'] != 'POST')
  857. $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
  858. if ($permission_to_start == false || $exercise_timeover == true) { //
  859. if (!api_is_allowed_to_edit(null,true)) {
  860. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedYet') : get_lang('ReachedTimeLimit');
  861. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  862. Display :: display_footer();
  863. exit;
  864. } else {
  865. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedAdmin') : get_lang('ReachedTimeLimitAdmin');
  866. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  867. }
  868. }
  869. }
  870. if (!empty ($error)) {
  871. Display :: display_error_message($error, false);
  872. } else {
  873. if (!empty ($exerciseSound)) {
  874. echo "<a href=\"../document/download.php?doc_url=%2Faudio%2F" . Security::remove_XSS($exerciseSound) . "\" target=\"_blank\">", "<img src=\"../img/sound.gif\" border=\"0\" align=\"absmiddle\" alt=", get_lang('Sound') .
  875. "\" /></a>";
  876. }
  877. // Get number of hotspot questions for javascript validation
  878. $number_of_hotspot_questions = 0;
  879. $onsubmit = '';
  880. $i = 0;
  881. //i have a doubt in this line cvargas
  882. //var_dump($questionList);
  883. if (!strcmp($questionList[0], '') === 0) {
  884. foreach ($questionList as $questionId) {
  885. $i++;
  886. $objQuestionTmp = Question :: read($questionId);
  887. // for sequential exercises
  888. if ($exerciseType == 2) {
  889. // if it is not the right question, goes to the next loop iteration
  890. if ($questionNum != $i) {
  891. continue;
  892. } else {
  893. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  894. $number_of_hotspot_questions++;
  895. }
  896. break;
  897. }
  898. } else {
  899. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  900. $number_of_hotspot_questions++;
  901. }
  902. }
  903. }
  904. }
  905. if ($number_of_hotspot_questions > 0) {
  906. $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\"";
  907. }
  908. $s = "<p>$exerciseDescription</p>";
  909. if ($exerciseType == 2)
  910. {
  911. $s2 = "&exerciseId=" . $exerciseId;
  912. }
  913. $s .= " <form method='post' action='" . api_get_self() . "?autocomplete=off&gradebook=$gradebook" . $s2 . "' name='frm_exercise' $onsubmit>
  914. <input type='hidden' name='formSent' value='1' />
  915. <input type='hidden' name='exerciseType' value='" . $exerciseType . "' />
  916. <input type='hidden' name='exerciseId' value='" . $exerciseId . "' />
  917. <input type='hidden' name='questionNum' value='" . $questionNum . "' />
  918. <input type='hidden' name='nbrQuestions' value='" . $nbrQuestions . "' />
  919. <input type='hidden' name='origin' value='" . $origin . "' />
  920. <input type='hidden' name='learnpath_id' value='" . $learnpath_id . "' />
  921. <input type='hidden' name='learnpath_item_id' value='" . $learnpath_item_id . "' />
  922. <table width='100%' border='0' cellpadding='1' cellspacing='0'>
  923. <tr>
  924. <td>
  925. <table width='100%' cellpadding='3' cellspacing='0' border='0'>";
  926. echo $s;
  927. $i = 1;
  928. foreach ($questionList as $questionId) {
  929. // for sequential exercises
  930. if ($exerciseType == 2) {
  931. // if it is not the right question, goes to the next loop iteration
  932. if ($questionNum != $i) {
  933. $i++;
  934. continue;
  935. } else {
  936. if ($exerciseFeedbackType != 1) {
  937. // if the user has already answered this question
  938. if (isset ($exerciseResult[$questionId])) {
  939. // construction of the Question object
  940. $objQuestionTmp = Question :: read($questionId);
  941. $questionName = $objQuestionTmp->selectTitle();
  942. // destruction of the Question object
  943. unset ($objQuestionTmp);
  944. Display :: display_normal_message(get_lang('AlreadyAnswered'));
  945. $i++;
  946. //echo '<tr><td>'.get_lang('AlreadyAnswered').' &quot;'.$questionName.'&quot;</td></tr>';
  947. break;
  948. }
  949. }
  950. }
  951. }
  952. // shows the question and its answers
  953. showQuestion($questionId, false, $origin, $i, $nbrQuestions);
  954. $i++;
  955. // for sequential exercises
  956. if ($exerciseType == 2) {
  957. // quits the loop
  958. break;
  959. }
  960. }
  961. // end foreach()
  962. echo "<!-- <button type='submit' name='buttonCancel' class='cancel'>" . get_lang('Cancel') . "</button>
  963. &nbsp;&nbsp; //--><br />";
  964. echo '<div style="padding-left:10px; margin-top:-10px;">';
  965. $submit_btn = "<button class='next' type='submit' name='submit'>";
  966. // $submit_btn.=get_lang('ValidateAnswer');
  967. if ($objExercise->selectFeedbackType() == 1 && $_SESSION['objExercise']->selectType() == 2) {
  968. $submit_btn = '';
  969. echo '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js" type="text/javascript"></script>';
  970. echo '<style type="text/css" media="all">@import "' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css";</style>';
  971. $hotspot_get = $_POST['hotspot'];
  972. // Show a hidden div
  973. echo "<script>$(document).ready( function(){
  974. $('.rounded').corners();
  975. $('.rounded_inner').corners();
  976. });</script>";
  977. //echo '<br /><span class="rounded" style="width: 300px; margin-top: 10px; padding: 3px; background-color:#ccc;"><span style="width: 300px" class="rounded_inner" ><a href="exercise_submit_modal.php?hotspot='.$hotspot_get.'&nbrQuestions='.$nbrQuestions.'&questionnum='.$questionNum.'&exerciseType='.$exerciseType.'&exerciseId='.$exerciseId.'&placeValuesBeforeTB_=savedValues&TB_iframe=true&height=480&width=640&modal=true" title="" class="thickbox" id="validationButton">'.get_lang('ValidateAnswer').'</a></span></span><br /><br /><br />';
  978. } else {
  979. if (api_is_allowed_to_session_edit() ) {
  980. if ($exerciseType == 1 || $nbrQuestions == $questionNum) {
  981. $submit_btn .= get_lang('ValidateAnswer');
  982. } else {
  983. $submit_btn .= get_lang('NextQuestion');
  984. }
  985. $submit_btn .= "</button>";
  986. echo $submit_btn;
  987. }
  988. }
  989. echo "</table>
  990. </td>
  991. </tr>
  992. </table></form>";
  993. $b = 2;
  994. }
  995. echo '</div>';
  996. if ($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType != 1) {
  997. //if($questionNum < 2){
  998. if ($table_recorded_not_exist) {
  999. if ($exerciseType == 2) {
  1000. Database::query("INSERT INTO $stat_table(exe_exo_id,exe_user_id,exe_cours_id,status,session_id,data_tracking,start_date,orig_lp_id,orig_lp_item_id)
  1001. VALUES('$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . implode(',', $questionList) . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)", __FILE__, __LINE__);
  1002. } else {
  1003. Database::query("INSERT INTO $stat_table (exe_exo_id,exe_user_id,exe_cours_id,status,session_id,start_date,orig_lp_id,orig_lp_item_id)
  1004. VALUES('$exerciseId','" . api_get_user_id() . "','" . $_course['id'] . "','incomplete','" . api_get_session_id() . "','" . date('Y-m-d H:i:s') . "',$safe_lp_id,$safe_lp_item_id)", __FILE__, __LINE__);
  1005. }
  1006. }
  1007. }
  1008. if ($origin != 'learnpath') {
  1009. //so we are not in learnpath tool
  1010. Display :: display_footer();
  1011. } else {
  1012. echo '</body></html>';
  1013. }