exercice_submit.php 46 KB

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