exercice_submit.php 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106
  1. <?php
  2. // $Id: exercice_submit.php 21656 2009-06-28 01:01:54Z iflorespaz $
  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 21656 2009-06-28 01:01:54Z iflorespaz $
  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. require_once api_get_path(LIBRARY_PATH) . 'events.lib.inc.php';
  249. $counter = 0;
  250. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  251. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  252. //foreach($questionList as $questionId)
  253. if (true) {
  254. $exeId = $exe_id;
  255. $questionId = $key;
  256. $counter++;
  257. // gets the student choice for this question
  258. $choice = $exerciseResult[$questionId];
  259. // creates a temporary Question object
  260. $objQuestionTmp = Question :: read($questionId);
  261. $questionName = $objQuestionTmp->selectTitle();
  262. $questionDescription = $objQuestionTmp->selectDescription();
  263. $questionWeighting = $objQuestionTmp->selectWeighting();
  264. $answerType = $objQuestionTmp->selectType();
  265. $quesId = $objQuestionTmp->selectId(); //added by priya saini
  266. // destruction of the Question object
  267. unset ($objQuestionTmp);
  268. if (isset ($_POST['hotspot']) && isset($_POST['hotspot'][$key])) {
  269. $exerciseResultCoordinates[$key] = $_POST['hotspot'][$key];
  270. }
  271. // construction of the Answer object
  272. $objAnswerTmp = new Answer($questionId);
  273. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  274. $questionScore = 0;
  275. if ($answerType == FREE_ANSWER) {
  276. $nbrAnswers = 1;
  277. }
  278. for ($answerId = 1; $answerId <= $nbrAnswers; $answerId++) {
  279. $answer = $objAnswerTmp->selectAnswer($answerId);
  280. $answerComment = $objAnswerTmp->selectComment($answerId);
  281. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  282. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  283. switch ($answerType) {
  284. // for unique answer
  285. case UNIQUE_ANSWER :
  286. $studentChoice = ($choice == $answerId) ? 1 : 0;
  287. if ($studentChoice) {
  288. $questionScore += $answerWeighting;
  289. $totalScore += $answerWeighting;
  290. }
  291. break;
  292. // for multiple answers
  293. case MULTIPLE_ANSWER :
  294. $studentChoice = $choice[$answerId];
  295. if ($studentChoice) {
  296. $questionScore += $answerWeighting;
  297. $totalScore += $answerWeighting;
  298. }
  299. break;
  300. // for fill in the blanks
  301. case FILL_IN_BLANKS :
  302. // the question is encoded like this
  303. // [A] B [C] D [E] F::10,10,10@1
  304. // number 1 before the "@" means that is a switchable fill in blank question
  305. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  306. // means that is a normal fill blank question
  307. // first we explode the "::"
  308. $pre_array = explode('::', $answer);
  309. // is switchable fill blank or not
  310. $last = count($pre_array) - 1;
  311. $is_set_switchable = explode('@', $pre_array[$last]);
  312. $switchable_answer_set = false;
  313. if (isset ($is_set_switchable[1]) && $is_set_switchable[1] == 1) {
  314. $switchable_answer_set = true;
  315. }
  316. $answer = '';
  317. for ($k = 0; $k < $last; $k++) {
  318. $answer .= $pre_array[$k];
  319. }
  320. // splits weightings that are joined with a comma
  321. $answerWeighting = explode(',', $is_set_switchable[0]);
  322. // we save the answer because it will be modified
  323. $temp = $answer;
  324. // TeX parsing
  325. // 1. find everything between the [tex] and [/tex] tags
  326. $startlocations = strpos($temp, '[tex]');
  327. $endlocations = strpos($temp, '[/tex]');
  328. if ($startlocations !== false && $endlocations !== false) {
  329. $texstring = substr($temp, $startlocations, $endlocations - $startlocations +6);
  330. // 2. replace this by {texcode}
  331. $temp = str_replace($texstring, '{texcode}', $temp);
  332. }
  333. $answer = '';
  334. $j = 0;
  335. //initialise answer tags
  336. $user_tags = array ();
  337. $correct_tags = array ();
  338. $real_text = array ();
  339. // the loop will stop at the end of the text
  340. while (1) {
  341. // quits the loop if there are no more blanks (detect '[')
  342. if (($pos = strpos($temp, '[')) === false) {
  343. // adds the end of the text
  344. $answer = $temp;
  345. // TeX parsing - replacement of texcode tags
  346. $texstring = api_parse_tex($texstring);
  347. $answer = str_replace("{texcode}", $texstring, $answer);
  348. $real_text[] = $answer;
  349. break; //no more "blanks", quit the loop
  350. }
  351. // adds the piece of text that is before the blank
  352. //and ends with '[' into a general storage array
  353. $real_text[] = substr($temp, 0, $pos +1);
  354. $answer .= substr($temp, 0, $pos +1);
  355. //take the string remaining (after the last "[" we found)
  356. $temp = substr($temp, $pos +1);
  357. // quit the loop if there are no more blanks, and update $pos to the position of next ']'
  358. if (($pos = strpos($temp, ']')) === false) {
  359. // adds the end of the text
  360. $answer .= $temp;
  361. break;
  362. }
  363. $choice[$j] = trim($choice[$j]);
  364. $user_tags[] = strtolower($choice[$j]);
  365. //put the contents of the [] answer tag into correct_tags[]
  366. $correct_tags[] = strtolower(substr($temp, 0, $pos));
  367. $j++;
  368. $temp = substr($temp, $pos +1);
  369. //$answer .= ']';
  370. }
  371. $answer = '';
  372. $real_correct_tags = $correct_tags;
  373. $chosen_list = array ();
  374. for ($i = 0; $i < count($real_correct_tags); $i++) {
  375. if ($i == 0) {
  376. $answer .= $real_text[0];
  377. }
  378. if (!$switchable_answer_set) {
  379. if ($correct_tags[$i] == $user_tags[$i]) {
  380. // gives the related weighting to the student
  381. $questionScore += $answerWeighting[$i];
  382. // increments total score
  383. $totalScore += $answerWeighting[$i];
  384. // adds the word in green at the end of the string
  385. $answer .= $correct_tags[$i];
  386. }
  387. // else if the word entered by the student IS NOT the same as the one defined by the professor
  388. elseif (!empty ($user_tags[$i])) {
  389. // adds the word in red at the end of the string, and strikes it
  390. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  391. } else {
  392. // adds a tabulation if no word has been typed by the student
  393. $answer .= '&nbsp;&nbsp;&nbsp;';
  394. }
  395. } else {
  396. // switchable fill in the blanks
  397. if (in_array($user_tags[$i], $correct_tags)) {
  398. $chosen_list[] = $user_tags[$i];
  399. $correct_tags = array_diff($correct_tags, $chosen_list);
  400. // gives the related weighting to the student
  401. $questionScore += $answerWeighting[$i];
  402. // increments total score
  403. $totalScore += $answerWeighting[$i];
  404. // adds the word in green at the end of the string
  405. $answer .= $user_tags[$i];
  406. }
  407. elseif (!empty ($user_tags[$i])) {
  408. // else if the word entered by the student IS NOT the same as the one defined by the professor
  409. // adds the word in red at the end of the string, and strikes it
  410. $answer .= '<font color="red"><s>' . $user_tags[$i] . '</s></font>';
  411. } else {
  412. // adds a tabulation if no word has been typed by the student
  413. $answer .= '&nbsp;&nbsp;&nbsp;';
  414. }
  415. }
  416. // adds the correct word, followed by ] to close the blank
  417. $answer .= ' / <font color="green"><b>' . $real_correct_tags[$i] . '</b></font>]';
  418. if (isset ($real_text[$i +1])) {
  419. $answer .= $real_text[$i +1];
  420. }
  421. }
  422. break;
  423. // for free answer
  424. case FREE_ANSWER :
  425. $studentChoice = $choice;
  426. if ($studentChoice) {
  427. //Score is at -1 because the question has'nt been corected
  428. $questionScore = -1;
  429. $totalScore += 0;
  430. }
  431. break;
  432. // for matching
  433. case MATCHING :
  434. if ($answerCorrect) {
  435. if ($answerCorrect == $choice[$answerId]) {
  436. $questionScore += $answerWeighting;
  437. $totalScore += $answerWeighting;
  438. $choice[$answerId] = $matching[$choice[$answerId]];
  439. }
  440. elseif (!$choice[$answerId]) {
  441. $choice[$answerId] = '&nbsp;&nbsp;&nbsp;';
  442. } else {
  443. $choice[$answerId] = '<font color="red"><s>' . $matching[$choice[$answerId]] . '</s></font>';
  444. }
  445. } else {
  446. $matching[$answerId] = $answer;
  447. }
  448. break;
  449. // for hotspot with no order
  450. case HOT_SPOT :
  451. $studentChoice = $choice[$answerId];
  452. if ($studentChoice) {
  453. $questionScore += $answerWeighting;
  454. $totalScore += $answerWeighting;
  455. }
  456. break;
  457. // for hotspot with fixed order
  458. case HOT_SPOT_ORDER :
  459. $studentChoice = $choice['order'][$answerId];
  460. if ($studentChoice == $answerId) {
  461. $questionScore += $answerWeighting;
  462. $totalScore += $answerWeighting;
  463. $studentChoice = true;
  464. } else {
  465. $studentChoice = false;
  466. }
  467. break;
  468. } // end switch Answertype
  469. } // end for that loops over all answers of the current question
  470. // destruction of Answer
  471. unset ($objAnswerTmp);
  472. $i++;
  473. $totalWeighting += $questionWeighting;
  474. //added by priya saini
  475. // Store results directly in the database
  476. // For all in one page exercises, the results will be
  477. // stored by exercise_results.php (using the session)
  478. if ($_configuration['tracking_enabled']) {
  479. if (empty ($choice)) {
  480. $choice = 0;
  481. }
  482. if ($answerType == MULTIPLE_ANSWER) {
  483. if ($choice != 0) {
  484. $reply = array_keys($choice);
  485. for ($i = 0; $i < sizeof($reply); $i++) {
  486. $ans = $reply[$i];
  487. exercise_attempt($questionScore, $ans, $quesId, $exeId, $i);
  488. }
  489. } else {
  490. exercise_attempt($questionScore, 0, $quesId, $exeId, 0);
  491. }
  492. }
  493. elseif ($answerType == MATCHING) {
  494. $j = sizeof($matching) + 1;
  495. for ($i = 0; $i < sizeof($choice); $i++, $j++) {
  496. $val = $choice[$j];
  497. if (preg_match_all('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1)) {
  498. $val = $arr1[1][0];
  499. }
  500. $val = $val;
  501. $val = strip_tags($val);
  502. $sql = "select position from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and answer='" . Database :: escape_string($val) . "' AND correct=0";
  503. $res = api_sql_query($sql, __FILE__, __LINE__);
  504. if (Database :: num_rows($res) > 0) {
  505. $answer = Database :: result($res, 0, "position");
  506. } else {
  507. $answer = '';
  508. }
  509. exercise_attempt($questionScore, $answer, $quesId, $exeId, $j);
  510. }
  511. } elseif ($answerType == FREE_ANSWER) {
  512. $answer = $choice;
  513. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  514. } elseif ($answerType == UNIQUE_ANSWER) {
  515. $sql = "select id from $table_ans where question_id='" . Database :: escape_string($questionId) . "' and position='" . Database :: escape_string($choice) . "'";
  516. $res = api_sql_query($sql, __FILE__, __LINE__);
  517. $answer = Database :: result($res, 0, "id");
  518. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  519. } elseif ($answerType == HOT_SPOT) {
  520. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  521. if (is_array($exerciseResultCoordinates[$key])) {
  522. foreach($exerciseResultCoordinates[$key] as $idx => $val) {
  523. exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
  524. }
  525. }
  526. } else {
  527. exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
  528. }
  529. }
  530. }
  531. // end huge foreach() block that loops over all questions
  532. //at loops over all questions
  533. if (isset($exe_id)) {
  534. $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);
  535. api_sql_query($sql_update, __FILE__, __LINE__);
  536. }
  537. //END of saving and qualifying
  538. //------------------------------------------------------------------------------------------
  539. //
  540. }
  541. }
  542. }
  543. if ($debug > 0) {
  544. echo str_repeat('&nbsp;', 0) . '$choice is an array - end' . "<br />\n";
  545. }
  546. }
  547. // the script "exercise_result.php" will take the variable $exerciseResult from the session
  548. api_session_register('exerciseResult');
  549. api_session_register('exerciseResultCoordinates');
  550. define('ALL_ON_ONE_PAGE',1);
  551. define('ONE_PER_PAGE',2);
  552. // if all questions on one page OR if it is the last question (only for an exercise with one question per page)
  553. if ($exerciseType == ALL_ON_ONE_PAGE || $questionNum >= $nbrQuestions) {
  554. if ($debug > 0) {
  555. echo str_repeat('&nbsp;', 0) . 'Redirecting to exercise_result.php - Remove debug option to let this happen' . "<br />\n";
  556. }
  557. // goes to the script that will show the result of the exercise
  558. if ($exerciseType == ALL_ON_ONE_PAGE) {
  559. header("Location: exercise_result.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  560. } else {
  561. if ($exe_id != '') {
  562. //clean incomplete
  563. $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);
  564. api_sql_query($update_query, __FILE__, __LINE__);
  565. }
  566. header("Location: exercise_show.php?id=$exe_id&exerciseType=$exerciseType&origin=$origin&learnpath_id=$learnpath_id&learnpath_item_id=$learnpath_item_id");
  567. }
  568. exit ();
  569. }
  570. if ($debug > 0) {
  571. echo str_repeat('&nbsp;', 0) . '$formSent was set - end' . "<br />\n";
  572. }
  573. }
  574. // if the object is not in the session
  575. //why destroying the exercise when a LP is loaded ?
  576. //if (!isset($_SESSION['objExercise']) || $origin == 'learnpath' || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  577. if (!isset ($_SESSION['objExercise']) || $_SESSION['objExercise']->id != $_REQUEST['exerciseId']) {
  578. if ($debug > 0) {
  579. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset' . "<br />\n";
  580. }
  581. // construction of Exercise
  582. $objExercise = new Exercise();
  583. unset ($_SESSION['questionList']);
  584. // if the specified exercise doesn't exist or is disabled
  585. if (!$objExercise->read($exerciseId) || (!$objExercise->selectStatus() && !$is_allowedToEdit && ($origin != 'learnpath'))) {
  586. unset ($objExercise);
  587. $error = get_lang('ExerciseNotFound');
  588. //die(get_lang('ExerciseNotFound'));
  589. } else {
  590. // saves the object into the session
  591. api_session_register('objExercise');
  592. if ($debug > 0) {
  593. echo str_repeat('&nbsp;', 0) . '$_SESSION[objExercise] was unset - set now - end' . "<br />\n";
  594. }
  595. }
  596. }
  597. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  598. $objExercise = $_SESSION['objExercise'];
  599. }
  600. if (!is_object($objExercise)) {
  601. header('Location: exercice.php');
  602. exit ();
  603. }
  604. $Exe_starttime = $objExercise->start_time;
  605. $Exe_endtime = $objExercise->end_time;
  606. $quizID = $objExercise->selectId();
  607. $exerciseAttempts = $objExercise->selectAttempts();
  608. $exerciseTitle = $objExercise->selectTitle();
  609. $exerciseDescription = $objExercise->selectDescription();
  610. $exerciseDescription = $exerciseDescription;
  611. $exerciseSound = $objExercise->selectSound();
  612. $randomQuestions = $objExercise->isRandom();
  613. $exerciseType = $objExercise->selectType();
  614. $table_quiz_test = Database :: get_course_table(TABLE_QUIZ_TEST);
  615. //if (!isset($_SESSION['questionList']) || $origin == 'learnpath') {
  616. //in LP's is enabled the "remember question" feature?
  617. $my_exe_id = Security :: remove_XSS($_GET['exerciseId']);
  618. if (!isset ($_SESSION['questionList'])) {
  619. if ($debug > 0) {
  620. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset' . "<br />\n";
  621. }
  622. // selects the list of question ID
  623. $my_question_list = array ();
  624. $questionList = ($randomQuestions ? $objExercise->selectRandomList() : $objExercise->selectQuestionList());
  625. // saves the question list into the session
  626. $sql = 'SELECT random FROM ' . $table_quiz_test . ' WHERE id="' . Database :: escape_string($my_exe_id) . '";';
  627. $rs = api_sql_query($sql, __FILE__, __LINE__);
  628. $row_number = Database :: fetch_array($rs);
  629. $z = 0;
  630. if ($row_number['random'] <> 0) {
  631. foreach ($questionList as $infoquestionList) {
  632. if ($z < $row_number['random']) {
  633. $my_question_list[$z] = $infoquestionList;
  634. } else {
  635. break;
  636. }
  637. $z++;
  638. }
  639. // $questionList=array();
  640. $questionList = $my_question_list;
  641. }
  642. api_session_register('questionList');
  643. if ($debug > 0) {
  644. echo str_repeat('&nbsp;', 0) . '$_SESSION[questionList] was unset - set now - end' . "<br />\n";
  645. }
  646. }
  647. if (!isset ($objExcercise) && isset ($_SESSION['objExercise'])) {
  648. $questionList = $_SESSION['questionList'];
  649. }
  650. $quizStartTime = time();
  651. api_session_register('quizStartTime');
  652. $nbrQuestions = sizeof($questionList);
  653. // if questionNum comes from POST and not from GET
  654. if (!$questionNum || $_POST['questionNum']) {
  655. // only used for sequential exercises (see $exerciseType)
  656. if (!$questionNum) {
  657. $questionNum = 1;
  658. } else {
  659. $questionNum++;
  660. }
  661. }
  662. if (!empty ($_GET['gradebook']) && $_GET['gradebook'] == 'view') {
  663. $_SESSION['gradebook'] = Security :: remove_XSS($_GET['gradebook']);
  664. $gradebook = $_SESSION['gradebook'];
  665. }
  666. elseif (empty ($_GET['gradebook'])) {
  667. unset ($_SESSION['gradebook']);
  668. $gradebook = '';
  669. }
  670. if (!empty ($gradebook) && $gradebook == 'view') {
  671. $interbreadcrumb[] = array (
  672. 'url' => '../gradebook/' . $_SESSION['gradebook_dest'],
  673. 'name' => get_lang('Gradebook')
  674. );
  675. }
  676. //$nameTools=get_lang('Exercice');
  677. $interbreadcrumb[] = array (
  678. "url" => "exercice.php?gradebook=$gradebook",
  679. "name" => get_lang('Exercices')
  680. );
  681. $interbreadcrumb[] = array (
  682. "url" => api_get_self()."?gradebook=$gradebook",
  683. "name" => $exerciseTitle
  684. );
  685. if ($origin != 'learnpath') { //so we are not in learnpath tool
  686. $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
  687. <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
  688. <script language=\"JavaScript\" type=\"text/javascript\">
  689. <!--
  690. // -----------------------------------------------------------------------------
  691. // Globals
  692. // Major version of Flash required
  693. var requiredMajorVersion = 7;
  694. // Minor version of Flash required
  695. var requiredMinorVersion = 0;
  696. // Minor version of Flash required
  697. var requiredRevision = 0;
  698. // the version of javascript supported
  699. var jsVersion = 1.0;
  700. // -----------------------------------------------------------------------------
  701. // -->
  702. </script>
  703. <script language=\"VBScript\" type=\"text/vbscript\">
  704. <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
  705. Function VBGetSwfVer(i)
  706. on error resume next
  707. Dim swControl, swVersion
  708. swVersion = 0
  709. set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
  710. if (IsObject(swControl)) then
  711. swVersion = swControl.GetVariable(\"\$version\")
  712. end if
  713. VBGetSwfVer = swVersion
  714. End Function
  715. // -->
  716. </script>
  717. <script language=\"JavaScript1.1\" type=\"text/javascript\">
  718. <!-- // Detect Client Browser type
  719. var isIE = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
  720. var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
  721. var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
  722. jsVersion = 1.1;
  723. // JavaScript helper required to detect Flash Player PlugIn version information
  724. function JSGetSwfVer(i){
  725. // NS/Opera version >= 3 check for Flash plugin in plugin array
  726. if (navigator.plugins != null && navigator.plugins.length > 0) {
  727. if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
  728. var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
  729. var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
  730. descArray = flashDescription.split(\" \");
  731. tempArrayMajor = descArray[2].split(\".\");
  732. versionMajor = tempArrayMajor[0];
  733. versionMinor = tempArrayMajor[1];
  734. if ( descArray[3] != \"\" ) {
  735. tempArrayMinor = descArray[3].split(\"r\");
  736. } else {
  737. tempArrayMinor = descArray[4].split(\"r\");
  738. }
  739. versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
  740. flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
  741. } else {
  742. flashVer = -1;
  743. }
  744. }
  745. // MSN/WebTV 2.6 supports Flash 4
  746. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
  747. // WebTV 2.5 supports Flash 3
  748. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
  749. // older WebTV supports Flash 2
  750. else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
  751. // Can't detect in all other cases
  752. else {
  753. flashVer = -1;
  754. }
  755. return flashVer;
  756. }
  757. // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
  758. function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
  759. {
  760. reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
  761. // loop backwards through the versions until we find the newest version
  762. for (i=25;i>0;i--) {
  763. if (isIE && isWin && !isOpera) {
  764. versionStr = VBGetSwfVer(i);
  765. } else {
  766. versionStr = JSGetSwfVer(i);
  767. }
  768. if (versionStr == -1 ) {
  769. return false;
  770. } else if (versionStr != 0) {
  771. if(isIE && isWin && !isOpera) {
  772. tempArray = versionStr.split(\" \");
  773. tempString = tempArray[1];
  774. versionArray = tempString .split(\",\");
  775. } else {
  776. versionArray = versionStr.split(\".\");
  777. }
  778. versionMajor = versionArray[0];
  779. versionMinor = versionArray[1];
  780. versionRevision = versionArray[2];
  781. versionString = versionMajor + \".\" + versionRevision; // 7.0r24 == 7.24
  782. versionNum = parseFloat(versionString);
  783. // is the major.revision >= requested major.revision AND the minor version >= requested minor
  784. if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
  785. return true;
  786. } else {
  787. return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
  788. }
  789. }
  790. }
  791. }
  792. // -->
  793. </script>";
  794. Display :: display_header($nameTools, "Exercise");
  795. } else {
  796. if (empty ($charset)) {
  797. $charset = 'ISO-8859-15';
  798. }
  799. /*
  800. * HTML HEADER
  801. */
  802. Display::display_reduced_header();
  803. echo '<div style="height:10px">&nbsp;</div>';
  804. }
  805. // I'm in a preview mode
  806. if (api_is_course_admin() && $origin != 'learnpath') {
  807. echo '<div class="actions">';
  808. echo Display :: return_icon('quiz.gif', get_lang('GoBackToEx')) . '<a href="admin.php?' . api_get_cidreq() . '&exerciseId=' . $objExercise->id . '">' . get_lang('GoBackToEx') . '</a>';
  809. echo Display :: return_icon('edit.gif', get_lang('ModifyExercise')) . '<a href="exercise_admin.php?modifyExercise=yes&exerciseId=' . $objExercise->id . '">' . get_lang('ModifyExercise') . '</a>';
  810. echo '</div>';
  811. }
  812. $exerciseTitle = api_parse_tex($exerciseTitle);
  813. echo "<h3>" . $exerciseTitle . "</h3>";
  814. if ($exerciseAttempts > 0) {
  815. $user_id = api_get_user_id();
  816. $course_code = api_get_course_id();
  817. $sql = "SELECT count(*) FROM $stat_table WHERE exe_exo_id = '$quizID'
  818. AND exe_user_id = '$user_id'
  819. AND status != 'incomplete'
  820. AND orig_lp_id = $safe_lp_id
  821. AND orig_lp_item_id = $safe_lp_item_id
  822. AND exe_cours_id = '$course_code' AND session_id = '" . (int) $_SESSION['id_session'] . "'";
  823. $aquery = api_sql_query($sql, __FILE__, __LINE__);
  824. $attempt = Database :: fetch_array($aquery);
  825. if ($attempt[0] >= $exerciseAttempts) {
  826. if (!api_is_allowed_to_edit()) {
  827. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttempts'), $exerciseTitle, $exerciseAttempts), false);
  828. if ($origin != 'learnpath')
  829. Display :: display_footer();
  830. exit;
  831. } else {
  832. Display :: display_warning_message(sprintf(get_lang('ReachedMaxAttemptsAdmin'), $exerciseTitle, $exerciseAttempts), false);
  833. }
  834. }
  835. }
  836. if (!function_exists('convert_date_to_number')) {
  837. function convert_date_to_number($default) {
  838. // 2008-10-12 00:00:00 ---to--> 12345672218 (timestamp)
  839. $parts = split(' ', $default);
  840. list ($d_year, $d_month, $d_day) = split('-', $parts[0]);
  841. list ($d_hour, $d_minute, $d_second) = split(':', $parts[1]);
  842. return mktime($d_hour, $d_minute, $d_second, $d_month, $d_day, $d_year);
  843. }
  844. }
  845. $limit_time_exists = (($Exe_starttime != '0000-00-00 00:00:00') || ($Exe_endtime != '0000-00-00 00:00:00')) ? true : false;
  846. if ($limit_time_exists) {
  847. $exercise_start_time = convert_date_to_number($Exe_starttime);
  848. $exercise_end_time = convert_date_to_number($Exe_endtime);
  849. $time_now = convert_date_to_number(date('Y-m-d H:i:s'));
  850. $permission_to_start = (($time_now - $exercise_start_time) > 0) ? true : false;
  851. if ($_SERVER['REQUEST_METHOD'] != 'POST')
  852. $exercise_timeover = (($time_now - $exercise_end_time) > 0) ? true : false;
  853. if ($permission_to_start == false || $exercise_timeover == true) { //
  854. if (!api_is_allowed_to_edit()) {
  855. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedYet') : get_lang('ReachedTimeLimit');
  856. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  857. Display :: display_footer();
  858. exit;
  859. } else {
  860. $message_warning = ($permission_to_start == false) ? get_lang('ExerciseNoStartedAdmin') : get_lang('ReachedTimeLimitAdmin');
  861. Display :: display_warning_message(sprintf($message_warning, $exerciseTitle, $exerciseAttempts));
  862. }
  863. }
  864. }
  865. if (!empty ($error)) {
  866. Display :: display_error_message($error, false);
  867. } else {
  868. if (!empty ($exerciseSound)) {
  869. 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') .
  870. "\" /></a>";
  871. }
  872. // Get number of hotspot questions for javascript validation
  873. $number_of_hotspot_questions = 0;
  874. $onsubmit = '';
  875. $i = 0;
  876. //i have a doubt in this line cvargas
  877. //var_dump($questionList);
  878. if (!strcmp($questionList[0], '') === 0) {
  879. foreach ($questionList as $questionId) {
  880. $i++;
  881. $objQuestionTmp = Question :: read($questionId);
  882. // for sequential exercises
  883. if ($exerciseType == 2) {
  884. // if it is not the right question, goes to the next loop iteration
  885. if ($questionNum != $i) {
  886. continue;
  887. } else {
  888. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  889. $number_of_hotspot_questions++;
  890. }
  891. break;
  892. }
  893. } else {
  894. if ($objQuestionTmp->selectType() == HOT_SPOT) {
  895. $number_of_hotspot_questions++;
  896. }
  897. }
  898. }
  899. }
  900. if ($number_of_hotspot_questions > 0) {
  901. $onsubmit = "onsubmit=\"return validateFlashVar('" . $number_of_hotspot_questions . "', '" . get_lang('HotspotValidateError1') . "', '" . get_lang('HotspotValidateError2') . "');\"";
  902. }
  903. $s = "<p>$exerciseDescription</p>";
  904. if ($exerciseType == 2)
  905. {
  906. $s2 = "&exerciseId=" . $exerciseId;
  907. }
  908. $s .= " <form method='post' action='" . api_get_self() . "?autocomplete=off&gradebook=$gradebook" . $s2 . "' name='frm_exercise' $onsubmit>
  909. <input type='hidden' name='formSent' value='1' />
  910. <input type='hidden' name='exerciseType' value='" . $exerciseType . "' />
  911. <input type='hidden' name='exerciseId' value='" . $exerciseId . "' />
  912. <input type='hidden' name='questionNum' value='" . $questionNum . "' />
  913. <input type='hidden' name='nbrQuestions' value='" . $nbrQuestions . "' />
  914. <input type='hidden' name='origin' value='" . $origin . "' />
  915. <input type='hidden' name='learnpath_id' value='" . $learnpath_id . "' />
  916. <input type='hidden' name='learnpath_item_id' value='" . $learnpath_item_id . "' />
  917. <table width='100%' border='0' cellpadding='1' cellspacing='0'>
  918. <tr>
  919. <td>
  920. <table width='100%' cellpadding='3' cellspacing='0' border='0'>";
  921. echo $s;
  922. $i = 1;
  923. foreach ($questionList as $questionId) {
  924. // for sequential exercises
  925. if ($exerciseType == 2) {
  926. // if it is not the right question, goes to the next loop iteration
  927. if ($questionNum != $i) {
  928. $i++;
  929. continue;
  930. } else {
  931. if ($exerciseFeedbackType != 1) {
  932. // if the user has already answered this question
  933. if (isset ($exerciseResult[$questionId])) {
  934. // construction of the Question object
  935. $objQuestionTmp = Question :: read($questionId);
  936. $questionName = $objQuestionTmp->selectTitle();
  937. // destruction of the Question object
  938. unset ($objQuestionTmp);
  939. Display :: display_normal_message(get_lang('AlreadyAnswered'));
  940. $i++;
  941. //echo '<tr><td>'.get_lang('AlreadyAnswered').' &quot;'.$questionName.'&quot;</td></tr>';
  942. break;
  943. }
  944. }
  945. }
  946. }
  947. // shows the question and its answers
  948. showQuestion($questionId, false, $origin, $i, $nbrQuestions);
  949. $i++;
  950. // for sequential exercises
  951. if ($exerciseType == 2) {
  952. // quits the loop
  953. break;
  954. }
  955. }
  956. // end foreach()
  957. echo "<!-- <button type='submit' name='buttonCancel' class='cancel'>" . get_lang('Cancel') . "</button>
  958. &nbsp;&nbsp; //--><br />";
  959. echo '<div style="padding-left:10px; margin-top:-10px;">';
  960. $submit_btn = "<button class='next' type='submit' name='submit'>";
  961. // $submit_btn.=get_lang('ValidateAnswer');
  962. if ($objExercise->selectFeedbackType() == 1 && $_SESSION['objExercise']->selectType() == 2) {
  963. $submit_btn = '';
  964. echo '<script src="' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.js" type="text/javascript"></script>';
  965. echo '<style type="text/css" media="all">@import "' . api_get_path(WEB_LIBRARY_PATH) . 'javascript/thickbox.css";</style>';
  966. $hotspot_get = $_POST['hotspot'];
  967. // Show a hidden div
  968. echo "<script>$(document).ready( function(){
  969. $('.rounded').corners();
  970. $('.rounded_inner').corners();
  971. });</script>";
  972. //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 />';
  973. } else {
  974. if ($exerciseType == 1 || $nbrQuestions == $questionNum) {
  975. $submit_btn .= get_lang('ValidateAnswer');
  976. } else {
  977. $submit_btn .= get_lang('NextQuestion');
  978. }
  979. $submit_btn .= "</button>";
  980. }
  981. echo $submit_btn;
  982. echo "</table>
  983. </td>
  984. </tr>
  985. </table></form>";
  986. $b = 2;
  987. }
  988. echo '</div>';
  989. if ($_configuration['live_exercise_tracking'] == true && $exerciseFeedbackType != 1) {
  990. //if($questionNum < 2){
  991. if ($table_recorded_not_exist) {
  992. if ($exerciseType == 2) {
  993. 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)
  994. 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__);
  995. } else {
  996. 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)
  997. 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__);
  998. }
  999. }
  1000. }
  1001. if ($origin != 'learnpath') {
  1002. //so we are not in learnpath tool
  1003. Display :: display_footer();
  1004. }