exercice_submit.php 46 KB

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