exercice_submit.php 42 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105
  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();
  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 = api_sql_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 = api_sql_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 = api_sql_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 = api_sql_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. $sql = "select id from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and position='" . Database :: escape_string($choice) . "'";
  515. $res = api_sql_query($sql, __FILE__, __LINE__);
  516. $answer = Database :: result($res, 0, "id");
  517. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  518. } elseif ($answerType == HOT_SPOT) {
  519. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  520. if (is_array($exerciseResultCoordinates[$key])) {
  521. foreach($exerciseResultCoordinates[$key] as $idx => $val) {
  522. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
  523. }
  524. }
  525. } else {
  526. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  527. }
  528. }
  529. }
  530. // end huge foreach() block that loops over all questions
  531. //at loops over all questions
  532. if (isset($exe_id)) {
  533. $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);
  534. api_sql_query($sql_update, __FILE__, __LINE__);
  535. }
  536. //END of saving and qualifying
  537. //------------------------------------------------------------------------------------------
  538. //
  539. }
  540. }
  541. }
  542. if ($debug > 0) {
  543. echo str_repeat('&nbsp;', 0) . '$choice is an array - end' . "<br />\n";
  544. }
  545. }
  546. // the script "exercise_result.php" will take the variable $exerciseResult from the session
  547. api_session_register('exerciseResult');
  548. api_session_register('exerciseResultCoordinates');
  549. define('ALL_ON_ONE_PAGE',1);
  550. define('ONE_PER_PAGE',2);
  551. // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
  552. if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) {
  553. if ($debug > 0) {
  554. echo str_repeat('&nbsp;', 0) . 'Redirecting to exercise_result.php - Remove debug option to let this happen' . "<br />\n";
  555. }
  556. // goes to the script that will show the result of the exercise
  557. if ($exerciseType == ALL_ON_ONE_PAGE) {
  558. header("Location: exercise_result.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  559. } else {
  560. if ($exe_id != '') {
  561. //clean incomplete
  562. $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);
  563. api_sql_query($update_query, __FILE__, __LINE__);
  564. }
  565. header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  566. }
  567. exit ();
  568. }
  569. if ($debug > 0) {
  570. echo str_repeat('&nbsp;', 0) . '$formSent was set - end' . "<br />\n";
  571. }
  572. }
  573. // if the object is not in the session
  574. //why destroying the exercise when a LP is loaded ?
  575. //if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  576. if (!isset ($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  577. if ($debug > 0) {
  578. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset' . "<br />\n";
  579. }
  580. // construction of Exercise
  581. $objExercise = new Exercise();
  582. unset ($_SESSION['questionList']);
  583. // if the specified exercise doesn't exist or is disabled
  584. if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) {
  585. unset ($objExercise);
  586. $error = get_lang('ExerciseNotFound');
  587. //die(get_lang('ExerciseNotFound'));
  588. } else {
  589. // saves the object into the session
  590. api_session_register('objExercise');
  591. if ($debug > 0) {
  592. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset - set now - end' . "<br />\n";
  593. }
  594. }
  595. }
  596. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  597. $objExercise = $_SESSION['objExercise'];
  598. }
  599. if (!is_object($objExercise)) {
  600. header('Location: exercice.php');
  601. exit ();
  602. }
  603. $Exe_starttime = $objExercise->start_time;
  604. $Exe_endtime = $objExercise->end_time;
  605. $quizID = $objExercise->selectId();
  606. $exerciseAttempts = $objExercise->selectAttempts();
  607. $exerciseTitle = $objExercise->selectTitle();
  608. $exerciseDescription = $objExercise->selectDescription();
  609. $exerciseDescription = $exerciseDescription;
  610. $exerciseSound = $objExercise->selectSound();
  611. $randomQuestions = $objExercise->isRandom();
  612. $exerciseType = $objExercise->selectType();
  613. $table_quiz_test = Database :: get_course_table(TABLE_QUIZ_TEST);
  614. //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
  615. //in LP's is enabled the "remember question" feature?
  616. $my_exe_id = Security :: remove_XSS($_GET['exerciseId']);
  617. if (!isset ($_SESSION['questionList'])) {
  618. if ($debug > 0) {
  619. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset' . "<br />\n";
  620. }
  621. // selects the list of question ID
  622. $my_question_list = array ();
  623. $questionList = ($randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList());
  624. // saves the question list into the session
  625. $sql = 'SELECT random FROM ' . $table_quiz_test . ' WHERE id="' . Database :: escape_string($my_exe_id) . '";';
  626. $rs = api_sql_query($sql, __FILE__, __LINE__);
  627. $row_number = Database :: fetch_array($rs);
  628. $z = 0;
  629. if ($row_number['random'] <> 0) {
  630. foreach ($questionList as $infoquestionList) {
  631. if ($z < $row_number['random']) {
  632. $my_question_list[$z] = $infoquestionList;
  633. } else {
  634. break;
  635. }
  636. $z++;
  637. }
  638. // $questionList=array();
  639. $questionList = $my_question_list;
  640. }
  641. api_session_register('questionList');
  642. if ($debug > 0) {
  643. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset - set now - end' . "<br />\n";
  644. }
  645. }
  646. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  647. $questionList = $_SESSION['questionList'];
  648. }
  649. $quizStartTime = time();
  650. api_session_register('quizStartTime');
  651. $nbrQuestions = sizeof($questionList);
  652. // if questionNum comes from POST and not from GET
  653. if (!$questionNum || $_POST['questionNum']) {
  654. // only used for sequential exercises (see $exerciseType)
  655. if (!$questionNum) {
  656. $questionNum = 1;
  657. } else {
  658. $questionNum++;
  659. }
  660. }
  661. if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  662. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  663. $gradebook = $_SESSION['gradebook'];
  664. }
  665. elseif (empty ($_GET['gradebook'])) {
  666. unset ($_SESSION['gradebook']);
  667. $gradebook = '';
  668. }
  669. if (!empty ($gradebook) && $gradebook == 'view') {
  670. $interbreadcrumb[] = array (
  671. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  672. 'name' => get_lang('Gradebook')
  673. );
  674. }
  675. //$nameTools=get_lang('Exercice');
  676. $interbreadcrumb[] = array (
  677. "url" => "exercice.php?gradebook=$gradebook",
  678. "name" => get_lang('Exercices')
  679. );
  680. $interbreadcrumb[] = array (
  681. "url" => api_get_self()."?gradebook=$gradebook",
  682. "name" => $exerciseTitle
  683. );
  684. if ($origin != 'learnpath') { //so we are not in learnpath tool
  685. $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  686. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  687. <script language=\"JavaScript\" type=\"text/javascript\">
  688. <!--
  689. // -----------------------------------------------------------------------------
  690. // Globals
  691. // Major version of Flash required
  692. var requiredMajorVersion = 7;
  693. // Minor version of Flash required
  694. var requiredMinorVersion = 0;
  695. // Minor version of Flash required
  696. var requiredRevision = 0;
  697. // the version of javascript supported
  698. var jsVersion = 1.0;
  699. // -----------------------------------------------------------------------------
  700. // -->
  701. </script>
  702. <script language=\"VBScript\" type=\"text/vbscript\">
  703. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  704. Function VBGetSwfVer(i)
  705. on error resume next
  706. Dim swControl, swVersion
  707. swVersion = 0
  708. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  709. if (IsObject(swControl)) then
  710. swVersion = swControl.GetVariable(\"\$version\")
  711. end if
  712. VBGetSwfVer = swVersion
  713. End Function
  714. // -->
  715. </script>
  716. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  717. <!-- // Detect Client Browser type
  718. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  719. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  720. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  721. jsVersion = 1.1;
  722. // JavaScript helper required to detect Flash Player PlugIn version information
  723. function JSGetSwfVer(i){
  724. // NS/Opera version >= 3 check for Flash plugin in plugin array
  725. if (navigator.plugins != null && navigator.plugins.length > 0) {
  726. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  727. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  728. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  729. descArray = flashDescription.split(\" \");
  730. tempArrayMajor = descArray[2].split(\".\");
  731. versionMajor = tempArrayMajor[0];
  732. versionMinor = tempArrayMajor[1];
  733. if ( descArray[3] != \"\" ) {
  734. tempArrayMinor = descArray[3].split(\"r\");
  735. } else {
  736. tempArrayMinor = descArray[4].split(\"r\");
  737. }
  738. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  739. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  740. } else {
  741. flashVer = -1;
  742. }
  743. }
  744. // MSN/WebTV 2.6 supports Flash 4
  745. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  746. // WebTV 2.5 supports Flash 3
  747. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  748. // older WebTV supports Flash 2
  749. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  750. // Can't detect in all other cases
  751. else {
  752. flashVer = -1;
  753. }
  754. return flashVer;
  755. }
  756. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  757. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  758. {
  759. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  760. // loop backwards through the versions until we find the newest version
  761. for (i=25;i>0;i--) {
  762. if (isIE && isWin && !isOpera) {
  763. versionStr = VBGetSwfVer(i);
  764. } else {
  765. versionStr = JSGetSwfVer(i);
  766. }
  767. if (versionStr == -1 ) {
  768. return false;
  769. } else if (versionStr != 0) {
  770. if(isIE && isWin && !isOpera) {
  771. tempArray = versionStr.split(\" \");
  772. tempString = tempArray[1];
  773. versionArray = tempString .split(\",\");
  774. } else {
  775. versionArray = versionStr.split(\".\");
  776. }
  777. versionMajor = versionArray[0];
  778. versionMinor = versionArray[1];
  779. versionRevision = versionArray[2];
  780. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  781. versionNum = parseFloat(versionString);
  782. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  783. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  784. return true;
  785. } else {
  786. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  787. }
  788. }
  789. }
  790. }
  791. // -->
  792. </script>";
  793. Display :: display_header($nameTools, "Exercise");
  794. } else {
  795. if (empty ($charset)) {
  796. $charset = 'ISO-8859-15';
  797. }
  798. /*
  799. * HTML HEADER
  800. */
  801. Display::display_reduced_header();
  802. echo '<div style="height:10px">&nbsp;</div>';
  803. }
  804. // I'm in a preview mode
  805. if (api_is_course_admin() && $origin != 'learnpath') {
  806. echo '<div class="actions">';
  807. echo Display :: return_icon('quiz.gif', get_lang('GoBackToEx')) . '<a href="admin.php?' . api_get_cidreq() . '&exerciseId=' . $objExercise->id . '">' . get_lang('GoBackToEx') . '</a>';
  808. echo Display :: return_icon('edit.gif', get_lang('ModifyExercise')) . '<a href="exercise_admin.php?modifyExercise=yes&exerciseId=' . $objExercise->id . '">' . get_lang('ModifyExercise') . '</a>';
  809. echo '</div>';
  810. }
  811. $exerciseTitle = api_parse_tex($exerciseTitle);
  812. echo "<h3>" . $exerciseTitle . "</h3>";
  813. if ($exerciseAttempts > 0) {
  814. $user_id = api_get_user_id();
  815. $course_code = api_get_course_id();
  816. $sql = "SELECT count(*) FROM $stat_table WHERE exe_exo_id = '$quizID'
  817. AND exe_user_id = '$user_id'
  818. AND status != 'incomplete'
  819. AND orig_lp_id = $safe_lp_id
  820. AND orig_lp_item_id = $safe_lp_item_id
  821. AND exe_cours_id = '$course_code' AND session_id = '" . (int) $_SESSION['id_session'] . "'";
  822. $aquery = api_sql_query($sql, __FILE__, __LINE__);
  823. $attempt = Database :: fetch_array($aquery);
  824. if ($attempt[0] >= $exerciseAttempts) {
  825. if (!api_is_allowed_to_edit()) {
  826. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $exerciseAttempts), false);
  827. if ($origin != 'learnpath')
  828. Display :: display_footer();
  829. exit;
  830. } else {
  831. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exerciseTitle, $exerciseAttempts), false);
  832. }
  833. }
  834. }
  835. if (!function_exists('convert_date_to_number')) {
  836. function convert_date_to_number($default) {
  837. // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
  838. $parts = split(' ', $default);
  839. list ($d_year, $d_month, $d_day) = split('-', $parts[0]);
  840. list ($d_hour, $d_minute, $d_second) = split(':', $parts[1]);
  841. return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
  842. }
  843. }
  844. $limit_time_exists = (($Exe_starttime != '0000-00-00 00:00:00') || ($Exe_endtime != '0000-00-00 00:00:00')) ? true : false;
  845. if ($limit_time_exists) {
  846. $exercise_start_time = convert_date_to_number($Exe_starttime);
  847. $exercise_end_time = convert_date_to_number($Exe_endtime);
  848. $time_now = convert_date_to_number(date('Y-m-d H:i:s'));
  849. $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
  850. if ($_SERVER['REQUEST_METHOD'] != 'POST')
  851. $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
  852. if ($permission_to_start == false || $exercise_timeover == true) { //
  853. if (!api_is_allowed_to_edit()) {
  854. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedYet') : get_lang('ReachedTimeLimit');
  855. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  856. Display :: display_footer();
  857. exit;
  858. } else {
  859. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedAdmin') : get_lang('ReachedTimeLimitAdmin');
  860. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  861. }
  862. }
  863. }
  864. if (!empty ($error)) {
  865. Display :: display_error_message($error, false);
  866. } else {
  867. if (!empty ($exerciseSound)) {
  868. 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') .
  869. "\" /></a>";
  870. }
  871. // Get number of hotspot questions for javascript validation
  872. $number_of_hotspot_questions = 0;
  873. $onsubmit = '';
  874. $i = 0;
  875. //i have a doubt in this line cvargas
  876. //var_dump($questionList);
  877. if (!strcmp($questionList[0], '') === 0) {
  878. foreach ($questionList as $questionId) {
  879. $i++;
  880. $objQuestionTmp = Question :: read($questionId);
  881. // for sequential exercises
  882. if ($exerciseType == 2) {
  883. // if it is not the right question, goes to the next loop iteration
  884. if ($questionNum != $i) {
  885. continue;
  886. } else {
  887. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  888. $number_of_hotspot_questions++;
  889. }
  890. break;
  891. }
  892. } else {
  893. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  894. $number_of_hotspot_questions++;
  895. }
  896. }
  897. }
  898. }
  899. if ($number_of_hotspot_questions > 0) {
  900. $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\"";
  901. }
  902. $s = "<p>$exerciseDescription</p>";
  903. if ($exerciseType == 2)
  904. {
  905. $s2 = "&exerciseId=" . $exerciseId;
  906. }
  907. $s .= " <form method='post' action='" . api_get_self() . "?autocomplete=off&gradebook=$gradebook" . $s2 . "' name='frm_exercise' $onsubmit>
  908. <input type='hidden' name='formSent' value='1' />
  909. <input type='hidden' name='exerciseType' value='" . $exerciseType . "' />
  910. <input type='hidden' name='exerciseId' value='" . $exerciseId . "' />
  911. <input type='hidden' name='questionNum' value='" . $questionNum . "' />
  912. <input type='hidden' name='nbrQuestions' value='" . $nbrQuestions . "' />
  913. <input type='hidden' name='origin' value='" . $origin . "' />
  914. <input type='hidden' name='learnpath_id' value='" . $learnpath_id . "' />
  915. <input type='hidden' name='learnpath_item_id' value='" . $learnpath_item_id . "' />
  916. <table width='100%' border='0' cellpadding='1' cellspacing='0'>
  917. <tr>
  918. <td>
  919. <table width='100%' cellpadding='3' cellspacing='0' border='0'>";
  920. echo $s;
  921. $i = 1;
  922. foreach ($questionList as $questionId) {
  923. // for sequential exercises
  924. if ($exerciseType == 2) {
  925. // if it is not the right question, goes to the next loop iteration
  926. if ($questionNum != $i) {
  927. $i++;
  928. continue;
  929. } else {
  930. if ($exerciseFeedbackType != 1) {
  931. // if the user has already answered this question
  932. if (isset ($exerciseResult[$questionId])) {
  933. // construction of the Question object
  934. $objQuestionTmp = Question :: read($questionId);
  935. $questionName = $objQuestionTmp->selectTitle();
  936. // destruction of the Question object
  937. unset ($objQuestionTmp);
  938. Display :: display_normal_message(get_lang('AlreadyAnswered'));
  939. $i++;
  940. //echo '<tr><td>'.get_lang('AlreadyAnswered').' &quot;'.$questionName.'&quot;</td></tr>';
  941. break;
  942. }
  943. }
  944. }
  945. }
  946. // shows the question and its answers
  947. showQuestion($questionId, false, $origin, $i, $nbrQuestions);
  948. $i++;
  949. // for sequential exercises
  950. if ($exerciseType == 2) {
  951. // quits the loop
  952. break;
  953. }
  954. }
  955. // end foreach()
  956. echo "<!-- <button type='submit' name='buttonCancel' class='cancel'>" . get_lang('Cancel') . "</button>
  957. &nbsp;&nbsp; //--><br />";
  958. echo '<div style="padding-left:10px; margin-top:-10px;">';
  959. $submit_btn = "<button class='next' type='submit' name='submit'>";
  960. // $submit_btn.=get_lang('ValidateAnswer');
  961. if ($objExercise->selectFeedbackType() == 1 && $_SESSION['objExercise']->selectType() == 2) {
  962. $submit_btn = '';
  963. echo '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js" type="text/javascript"></script>';
  964. echo '<style type="text/css" media="all">@import "' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css";</style>';
  965. $hotspot_get = $_POST['hotspot'];
  966. // Show a hidden div
  967. echo "<script>$(document).ready( function(){
  968. $('.rounded').corners();
  969. $('.rounded_inner').corners();
  970. });</script>";
  971. //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 />';
  972. } else {
  973. if ($exerciseType == 1 || $nbrQuestions == $questionNum) {
  974. $submit_btn .= get_lang('ValidateAnswer');
  975. } else {
  976. $submit_btn .= get_lang('NextQuestion');
  977. }
  978. $submit_btn .= "</button>";
  979. }
  980. echo $submit_btn;
  981. echo "</table>
  982. </td>
  983. </tr>
  984. </table></form>";
  985. $b = 2;
  986. }
  987. echo '</div>';
  988. if ($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType != 1) {
  989. //if($questionNum < 2){
  990. if ($table_recorded_not_exist) {
  991. if ($exerciseType == 2) {
  992. api_sql_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)
  993. 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__);
  994. } else {
  995. api_sql_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)
  996. 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__);
  997. }
  998. }
  999. }
  1000. if ($origin != 'learnpath') {
  1001. //so we are not in learnpath tool
  1002. Display :: display_footer();
  1003. }