exercice_submit.php 45 KB

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