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