exercise_show.php 44 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. use ChamiloSession as Session;
  4. /**
  5. * Shows the exercise results.
  6. *
  7. * @author Julio Montoya - Added switchable fill in blank option added
  8. *
  9. * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  10. *
  11. * @package chamilo.exercise
  12. *
  13. * @todo remove the debug code and use the general debug library
  14. * @todo small letters for table variables
  15. */
  16. require_once __DIR__.'/../inc/global.inc.php';
  17. $origin = api_get_origin();
  18. $currentUserId = api_get_user_id();
  19. $printHeaders = $origin === 'learnpath';
  20. $id = isset($_REQUEST['id']) ? (int) $_REQUEST['id'] : 0; //exe id
  21. if (empty($id)) {
  22. api_not_allowed(true);
  23. }
  24. // Getting results from the exe_id. This variable also contain all the information about the exercise
  25. $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  26. //No track info
  27. if (empty($track_exercise_info)) {
  28. api_not_allowed($printHeaders);
  29. }
  30. $exercise_id = $track_exercise_info['id'];
  31. $student_id = $track_exercise_info['exe_user_id'];
  32. $learnpath_id = $track_exercise_info['orig_lp_id'];
  33. $learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
  34. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  35. $isBossOfStudent = false;
  36. if (api_is_student_boss()) {
  37. // Check if boss has access to user info.
  38. if (UserManager::userIsBossOfStudent($currentUserId, $student_id)) {
  39. $isBossOfStudent = true;
  40. } else {
  41. api_not_allowed($printHeaders);
  42. }
  43. } else {
  44. api_protect_course_script($printHeaders, false, true);
  45. }
  46. // Database table definitions
  47. $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  48. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  49. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  50. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  51. if (empty($formSent)) {
  52. $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
  53. }
  54. if (empty($exerciseResult)) {
  55. $exerciseResult = Session::read('exerciseResult');
  56. }
  57. if (empty($choiceDegreeCertainty)) {
  58. $choiceDegreeCertainty = isset($_REQUEST['choiceDegreeCertainty']) ? $_REQUEST['choiceDegreeCertainty'] : null;
  59. }
  60. $questionId = isset($_REQUEST['questionId']) ? (int) $_REQUEST['questionId'] : null;
  61. if (empty($choice)) {
  62. $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
  63. }
  64. if (empty($questionNum)) {
  65. $questionNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;
  66. }
  67. if (empty($nbrQuestions)) {
  68. $nbrQuestions = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null;
  69. }
  70. if (empty($questionList)) {
  71. $questionList = Session::read('questionList');
  72. }
  73. if (empty($objExercise)) {
  74. $objExercise = Session::read('objExercise');
  75. }
  76. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  77. $courseInfo = api_get_course_info();
  78. $sessionId = api_get_session_id();
  79. $is_allowedToEdit =
  80. api_is_allowed_to_edit(null, true) ||
  81. api_is_course_tutor() ||
  82. api_is_session_admin() ||
  83. api_is_drh() ||
  84. api_is_student_boss();
  85. if (!empty($sessionId) && !$is_allowedToEdit) {
  86. if (api_is_course_session_coach(
  87. $currentUserId,
  88. api_get_course_int_id(),
  89. $sessionId
  90. )) {
  91. if (!api_coach_can_edit_view_results(api_get_course_int_id(), $sessionId)) {
  92. api_not_allowed($printHeaders);
  93. }
  94. }
  95. } else {
  96. if (!$is_allowedToEdit) {
  97. api_not_allowed($printHeaders);
  98. }
  99. }
  100. $allowCoachFeedbackExercises = api_get_setting('allow_coach_feedback_exercises') === 'true';
  101. $maxEditors = (int) api_get_setting('exercise_max_ckeditors_in_page');
  102. $isCoachAllowedToEdit = api_is_allowed_to_edit(false, true);
  103. $isFeedbackAllowed = false;
  104. if (api_is_excluded_user_type(true, $student_id)) {
  105. api_not_allowed($printHeaders);
  106. }
  107. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  108. if (empty($objExercise)) {
  109. $objExercise = new Exercise();
  110. $objExercise->read($exercise_id);
  111. }
  112. $feedback_type = $objExercise->getFeedbackType();
  113. // Only users can see their own results
  114. if (!$is_allowedToEdit) {
  115. if ($student_id != $currentUserId) {
  116. api_not_allowed($printHeaders);
  117. }
  118. }
  119. $allowRecordAudio = api_get_setting('enable_record_audio') === 'true';
  120. $allowTeacherCommentAudio = api_get_configuration_value('allow_teacher_comment_audio') === true;
  121. $js = '<script>'.api_get_language_translate_html().'</script>';
  122. $htmlHeadXtra[] = $js;
  123. if (api_is_in_gradebook()) {
  124. $interbreadcrumb[] = [
  125. 'url' => Category::getUrl(),
  126. 'name' => get_lang('ToolGradebook'),
  127. ];
  128. }
  129. $interbreadcrumb[] = [
  130. 'url' => 'exercise.php?'.api_get_cidreq(),
  131. 'name' => get_lang('Exercises'),
  132. ];
  133. $interbreadcrumb[] = [
  134. 'url' => 'overview.php?exerciseId='.$exercise_id.'&'.api_get_cidreq(),
  135. 'name' => $objExercise->selectTitle(true),
  136. ];
  137. $interbreadcrumb[] = ['url' => '#', 'name' => get_lang('Result')];
  138. $this_section = SECTION_COURSES;
  139. $htmlHeadXtra[] = '<link rel="stylesheet" href="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/css/hotspot.css">';
  140. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'hotspot/js/hotspot.js"></script>';
  141. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'annotation/js/annotation.js"></script>';
  142. if ($allowRecordAudio && $allowTeacherCommentAudio) {
  143. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_JS_PATH).'rtc/RecordRTC.js"></script>';
  144. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/recorder.js"></script>';
  145. $htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'wami-recorder/gui.js"></script>';
  146. $htmlHeadXtra[] = '<script type="text/javascript" src="'.api_get_path(WEB_LIBRARY_PATH).'swfobject/swfobject.js"></script>';
  147. $htmlHeadXtra[] = api_get_js('record_audio/record_audio.js');
  148. }
  149. if ($action != 'export') {
  150. $scoreJsCode = ExerciseLib::getJsCode();
  151. if ($origin != 'learnpath') {
  152. Display::display_header('');
  153. } else {
  154. $htmlHeadXtra[] = "<style>body { background: none; } </style>";
  155. Display::display_reduced_header();
  156. }
  157. echo Display::toolbarAction('toolbar', [
  158. Display::url(
  159. Display::return_icon('pdf.png', get_lang('Export')),
  160. api_get_self().'?'.api_get_cidreq().'&id='.$id.'&action=export&'
  161. ),
  162. ]); ?>
  163. <script>
  164. <?php echo $scoreJsCode; ?>
  165. var maxEditors = <?php echo $maxEditors; ?>;
  166. function showfck(sid, marksid) {
  167. $('#' + sid).toggleClass('hidden');
  168. $('#' + marksid).toggleClass('hidden');
  169. $('#feedback_' + sid).toggleClass('hidden', !$('#' + sid).is('.hidden'));
  170. }
  171. function openEmailWrapper() {
  172. $('#email_content_wrapper').toggle();
  173. }
  174. function getFCK(vals, marksid) {
  175. var f = document.getElementById('form-email');
  176. var m_id = marksid.split(',');
  177. for (var i = 0; i < m_id.length; i++) {
  178. var oHidn = document.createElement("input");
  179. oHidn.type = "hidden";
  180. var selname = oHidn.name = "marks_" + m_id[i];
  181. var selid = document.forms['marksform_' + m_id[i]].marks.selectedIndex;
  182. oHidn.value = document.forms['marksform_' + m_id[i]].marks.options[selid].value;
  183. f.appendChild(oHidn);
  184. }
  185. var ids = vals.split(',');
  186. for (var k = 0; k < ids.length; k++) {
  187. var oHidden = document.createElement("input");
  188. oHidden.type = "hidden";
  189. oHidden.name = "comments_" + ids[k];
  190. if (CKEDITOR.instances[oHidden.name]) {
  191. oHidden.value = CKEDITOR.instances[oHidden.name].getData();
  192. } else {
  193. oHidden.value = $("textarea[name='" + oHidden.name + "']").val();
  194. }
  195. f.appendChild(oHidden);
  196. }
  197. }
  198. </script>
  199. <?php
  200. }
  201. $show_results = true;
  202. $show_only_total_score = false;
  203. $showTotalScoreAndUserChoicesInLastAttempt = true;
  204. // Avoiding the "Score 0/0" message when the exe_id is not set
  205. if (!empty($track_exercise_info)) {
  206. // if the results_disabled of the Quiz is 1 when block the script
  207. $result_disabled = $track_exercise_info['results_disabled'];
  208. switch ($result_disabled) {
  209. case RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS:
  210. $show_results = false;
  211. break;
  212. case RESULT_DISABLE_SHOW_SCORE_ONLY:
  213. $show_results = false;
  214. $show_only_total_score = true;
  215. if ($origin != 'learnpath') {
  216. if ($currentUserId == $student_id) {
  217. echo Display::return_message(
  218. get_lang('ThankYouForPassingTheTest'),
  219. 'warning',
  220. false
  221. );
  222. }
  223. }
  224. break;
  225. case RESULT_DISABLE_DONT_SHOW_SCORE_ONLY_IF_USER_FINISHES_ATTEMPTS_SHOW_ALWAYS_FEEDBACK:
  226. case RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT:
  227. $attempts = Event::getExerciseResultsByUser(
  228. $currentUserId,
  229. $objExercise->id,
  230. api_get_course_int_id(),
  231. api_get_session_id(),
  232. $track_exercise_info['orig_lp_id'],
  233. $track_exercise_info['orig_lp_item_id'],
  234. 'desc'
  235. );
  236. $numberAttempts = count($attempts);
  237. if ($numberAttempts >= $track_exercise_info['max_attempt']) {
  238. $show_results = true;
  239. $show_only_total_score = true;
  240. // Attempt reach max so show score/feedback now
  241. $showTotalScoreAndUserChoicesInLastAttempt = true;
  242. } else {
  243. $show_results = true;
  244. $show_only_total_score = true;
  245. // Last attempt not reach don't show score/feedback
  246. $showTotalScoreAndUserChoicesInLastAttempt = false;
  247. }
  248. break;
  249. }
  250. } else {
  251. echo Display::return_message(get_lang('CantViewResults'), 'warning');
  252. $show_results = false;
  253. }
  254. if ($origin == 'learnpath' && !isset($_GET['fb_type'])) {
  255. $show_results = false;
  256. }
  257. if ($is_allowedToEdit && in_array($action, ['qualify', 'edit', 'export'])) {
  258. $show_results = true;
  259. }
  260. if ($action == 'export') {
  261. ob_start();
  262. }
  263. $user_info = api_get_user_info($student_id);
  264. if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
  265. // Shows exercise header
  266. echo $objExercise->showExerciseResultHeader(
  267. $user_info,
  268. $track_exercise_info
  269. );
  270. }
  271. $i = $totalScore = $totalWeighting = 0;
  272. $arrques = [];
  273. $arrans = [];
  274. $user_restriction = $is_allowedToEdit ? '' : " AND user_id= $student_id ";
  275. $sql = "SELECT attempts.question_id, answer
  276. FROM $TBL_TRACK_ATTEMPT as attempts
  277. INNER JOIN $TBL_TRACK_EXERCISES AS stats_exercises
  278. ON stats_exercises.exe_id = attempts.exe_id
  279. INNER JOIN $TBL_EXERCISE_QUESTION AS quizz_rel_questions
  280. ON
  281. quizz_rel_questions.exercice_id=stats_exercises.exe_exo_id AND
  282. quizz_rel_questions.question_id = attempts.question_id AND
  283. quizz_rel_questions.c_id=".api_get_course_int_id()."
  284. INNER JOIN $TBL_QUESTIONS AS questions
  285. ON
  286. questions.id = quizz_rel_questions.question_id AND
  287. questions.c_id = ".api_get_course_int_id()."
  288. WHERE
  289. attempts.exe_id = $id $user_restriction
  290. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  291. $result = Database::query($sql);
  292. $question_list_from_database = [];
  293. $exerciseResult = [];
  294. while ($row = Database::fetch_array($result)) {
  295. $question_list_from_database[] = $row['question_id'];
  296. $exerciseResult[$row['question_id']] = $row['answer'];
  297. }
  298. // Fixing #2073 Fixing order of questions
  299. if (!empty($track_exercise_info['data_tracking'])) {
  300. $temp_question_list = explode(',', $track_exercise_info['data_tracking']);
  301. // Getting question list from data_tracking
  302. if (!empty($temp_question_list)) {
  303. $questionList = $temp_question_list;
  304. }
  305. // If for some reason data_tracking is empty we select the question list from db
  306. if (empty($questionList)) {
  307. $questionList = $question_list_from_database;
  308. }
  309. } else {
  310. $questionList = $question_list_from_database;
  311. }
  312. // Display the text when finished message if we are on a LP #4227
  313. $end_of_message = $objExercise->getTextWhenFinished();
  314. if (!empty($end_of_message) && ($origin === 'learnpath')) {
  315. echo Display::return_message($end_of_message, 'normal', false);
  316. echo "<div class='clear'>&nbsp;</div>";
  317. }
  318. // for each question
  319. $total_weighting = 0;
  320. foreach ($questionList as $questionId) {
  321. $objQuestionTmp = Question::read($questionId);
  322. if ($objQuestionTmp) {
  323. $total_weighting += $objQuestionTmp->selectWeighting();
  324. }
  325. }
  326. $counter = 1;
  327. $exercise_content = '';
  328. $category_list = [];
  329. $useAdvancedEditor = true;
  330. if (!empty($maxEditors) && count($questionList) > $maxEditors) {
  331. $useAdvancedEditor = false;
  332. }
  333. $objExercise->export = $action === 'export';
  334. $arrid = [];
  335. $arrmarks = [];
  336. $strids = '';
  337. $marksid = '';
  338. $countPendingQuestions = 0;
  339. foreach ($questionList as $questionId) {
  340. $choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : '';
  341. // destruction of the Question object
  342. unset($objQuestionTmp);
  343. $questionWeighting = 0;
  344. $answerType = 0;
  345. $questionScore = 0;
  346. // Creates a temporary Question object
  347. $objQuestionTmp = Question::read($questionId);
  348. if (empty($objQuestionTmp)) {
  349. continue;
  350. }
  351. $questionWeighting = $objQuestionTmp->selectWeighting();
  352. $answerType = $objQuestionTmp->selectType();
  353. // Start buffer
  354. ob_start();
  355. if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  356. $choice = [];
  357. }
  358. $relPath = api_get_path(WEB_CODE_PATH);
  359. switch ($answerType) {
  360. case MULTIPLE_ANSWER_COMBINATION:
  361. case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
  362. case UNIQUE_ANSWER:
  363. case UNIQUE_ANSWER_NO_OPTION:
  364. case UNIQUE_ANSWER_IMAGE:
  365. case MULTIPLE_ANSWER:
  366. case MULTIPLE_ANSWER_TRUE_FALSE:
  367. case FILL_IN_BLANKS:
  368. case CALCULATED_ANSWER:
  369. case GLOBAL_MULTIPLE_ANSWER:
  370. case FREE_ANSWER:
  371. case ORAL_EXPRESSION:
  372. case MATCHING:
  373. case DRAGGABLE:
  374. case READING_COMPREHENSION:
  375. case MATCHING_DRAGGABLE:
  376. $question_result = $objExercise->manage_answer(
  377. $id,
  378. $questionId,
  379. $choice,
  380. 'exercise_show',
  381. [],
  382. false,
  383. true,
  384. $show_results,
  385. $objExercise->selectPropagateNeg(),
  386. [],
  387. $showTotalScoreAndUserChoicesInLastAttempt
  388. );
  389. $questionScore = $question_result['score'];
  390. $totalScore += $question_result['score'];
  391. break;
  392. case MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY:
  393. $choiceTmp = [];
  394. $choiceTmp['choice'] = $choice;
  395. $choiceTmp['choiceDegreeCertainty'] = $choiceDegreeCertainty;
  396. $questionResult = $objExercise->manage_answer(
  397. $id,
  398. $questionId,
  399. $choiceTmp,
  400. 'exercise_show',
  401. [],
  402. false,
  403. true,
  404. $show_results,
  405. $objExercise->selectPropagateNeg()
  406. );
  407. $questionScore = $questionResult['score'];
  408. $totalScore += $questionResult['score'];
  409. break;
  410. case HOT_SPOT:
  411. if ($show_results || $showTotalScoreAndUserChoicesInLastAttempt) {
  412. echo '<table width="500" border="0"><tr>
  413. <td valign="top" align="center" style="padding-left:0px;" >
  414. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  415. }
  416. $question_result = $objExercise->manage_answer(
  417. $id,
  418. $questionId,
  419. $choice,
  420. 'exercise_show',
  421. [],
  422. false,
  423. true,
  424. $show_results,
  425. $objExercise->selectPropagateNeg(),
  426. [],
  427. $showTotalScoreAndUserChoicesInLastAttempt
  428. );
  429. $questionScore = $question_result['score'];
  430. $totalScore += $question_result['score'];
  431. if ($show_results) {
  432. echo '</table></td></tr>';
  433. echo "
  434. <tr>
  435. <td colspan=\"2\">
  436. <div id=\"hotspot-solution-$questionId-$id\"></div>
  437. <script>
  438. $(function() {
  439. new HotspotQuestion({
  440. questionId: $questionId,
  441. exerciseId: {$objExercise->id},
  442. exeId: $id,
  443. selector: '#hotspot-solution-$questionId-$id',
  444. for: 'solution',
  445. relPath: '$relPath'
  446. });
  447. });
  448. </script>
  449. </td>
  450. </tr>
  451. </table>
  452. <br>
  453. ";
  454. }
  455. break;
  456. case HOT_SPOT_DELINEATION:
  457. $question_result = $objExercise->manage_answer(
  458. $id,
  459. $questionId,
  460. $choice,
  461. 'exercise_show',
  462. [],
  463. false,
  464. true,
  465. $show_results,
  466. $objExercise->selectPropagateNeg(),
  467. 'database',
  468. [],
  469. $showTotalScoreAndUserChoicesInLastAttempt
  470. );
  471. $questionScore = $question_result['score'];
  472. $totalScore += $question_result['score'];
  473. $final_overlap = $question_result['extra']['final_overlap'];
  474. $final_missing = $question_result['extra']['final_missing'];
  475. $final_excess = $question_result['extra']['final_excess'];
  476. $overlap_color = $question_result['extra']['overlap_color'];
  477. $missing_color = $question_result['extra']['missing_color'];
  478. $excess_color = $question_result['extra']['excess_color'];
  479. $threadhold1 = $question_result['extra']['threadhold1'];
  480. $threadhold2 = $question_result['extra']['threadhold2'];
  481. $threadhold3 = $question_result['extra']['threadhold3'];
  482. if ($show_results) {
  483. if ($overlap_color) {
  484. $overlap_color = 'green';
  485. } else {
  486. $overlap_color = 'red';
  487. }
  488. $missing_color = 'red';
  489. if ($missing_color) {
  490. $missing_color = 'green';
  491. }
  492. $excess_color = 'red';
  493. if ($excess_color) {
  494. $excess_color = 'green';
  495. }
  496. if (!is_numeric($final_overlap)) {
  497. $final_overlap = 0;
  498. }
  499. if (!is_numeric($final_missing)) {
  500. $final_missing = 0;
  501. }
  502. if (!is_numeric($final_excess)) {
  503. $final_excess = 0;
  504. }
  505. if ($final_excess > 100) {
  506. $final_excess = 100;
  507. }
  508. $table_resume = '
  509. <table class="data_table">
  510. <tr class="row_odd" >
  511. <td>&nbsp;</td>
  512. <td><b>'.get_lang('Requirements').'</b></td>
  513. <td><b>'.get_lang('YourAnswer').'</b></td>
  514. </tr>
  515. <tr class="row_even">
  516. <td><b>'.get_lang('Overlap').'</b></td>
  517. <td>'.get_lang('Min').' '.$threadhold1.'</td>
  518. <td>
  519. <div style="color:'.$overlap_color.'">
  520. '.(($final_overlap < 0) ? 0 : intval($final_overlap)).'
  521. </div>
  522. </td>
  523. </tr>
  524. <tr>
  525. <td><b>'.get_lang('Excess').'</b></td>
  526. <td>'.get_lang('Max').' '.$threadhold2.'</td>
  527. <td>
  528. <div style="color:'.$excess_color.'">
  529. '.(($final_excess < 0) ? 0 : intval($final_excess)).'
  530. </div>
  531. </td>
  532. </tr>
  533. <tr class="row_even">
  534. <td><b>'.get_lang('Missing').'</b></td>
  535. <td>'.get_lang('Max').' '.$threadhold3.'</td>
  536. <td>
  537. <div style="color:'.$missing_color.'">
  538. '.(($final_missing < 0) ? 0 : intval($final_missing)).'
  539. </div>
  540. </td>
  541. </tr>
  542. </table>
  543. ';
  544. if ($answerType != HOT_SPOT_DELINEATION) {
  545. $item_list = explode('@@', $destination);
  546. $try = $item_list[0];
  547. $lp = $item_list[1];
  548. $destinationid = $item_list[2];
  549. $url = $item_list[3];
  550. $table_resume = '';
  551. } else {
  552. if ($next == 0) {
  553. $try = $try_hotspot;
  554. $lp = $lp_hotspot;
  555. $destinationid = $select_question_hotspot;
  556. $url = $url_hotspot;
  557. } else {
  558. //show if no error
  559. $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers);
  560. $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers);
  561. }
  562. }
  563. echo '<h1><div style="color:#333;">'.get_lang('Feedback').'</div></h1>';
  564. if ($answerType == HOT_SPOT_DELINEATION) {
  565. if ($organs_at_risk_hit > 0) {
  566. $message = '<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  567. $message .= '<p style="color:#DC0A0A;"><b>'.get_lang('OARHit').'</b></p>';
  568. } else {
  569. $message = '<p>'.get_lang('YourDelineation').'</p>';
  570. $message .= $table_resume;
  571. $message .= '<br />'.get_lang('ResultIs').' <b>'.$result_comment.'</b><br />';
  572. }
  573. $message .= '<p>'.$comment.'</p>';
  574. echo $message;
  575. } else {
  576. echo '<p>'.$comment.'</p>';
  577. }
  578. // Showing the score
  579. $queryfree = "SELECT marks FROM $TBL_TRACK_ATTEMPT
  580. WHERE exe_id = $id AND question_id= ".intval($questionId);
  581. $resfree = Database::query($queryfree);
  582. $questionScore = Database::result($resfree, 0, "marks");
  583. $totalScore += $questionScore;
  584. $relPath = api_get_path(REL_PATH);
  585. echo '</table></td></tr>';
  586. echo "
  587. <tr>
  588. <td colspan=\"2\">
  589. <div id=\"hotspot-solution\"></div>
  590. <script>
  591. $(function() {
  592. new HotspotQuestion({
  593. questionId: $questionId,
  594. exerciseId: {$objExercise->id},
  595. exeId: $id,
  596. selector: '#hotspot-solution',
  597. for: 'solution',
  598. relPath: '$relPath'
  599. });
  600. });
  601. </script>
  602. </td>
  603. </tr>
  604. </table>
  605. ";
  606. }
  607. break;
  608. case ANNOTATION:
  609. $question_result = $objExercise->manage_answer(
  610. $id,
  611. $questionId,
  612. $choice,
  613. 'exercise_show',
  614. [],
  615. false,
  616. true,
  617. $show_results,
  618. $objExercise->selectPropagateNeg(),
  619. [],
  620. $showTotalScoreAndUserChoicesInLastAttempt
  621. );
  622. $questionScore = $question_result['score'];
  623. $totalScore += $question_result['score'];
  624. if ($show_results) {
  625. echo '
  626. <div id="annotation-canvas-'.$questionId.'"></div>
  627. <script>
  628. AnnotationQuestion({
  629. questionId: '.(int) $questionId.',
  630. exerciseId: '.(int) $id.',
  631. relPath: \''.$relPath.'\',
  632. courseId: '.(int) $courseInfo['real_id'].'
  633. });
  634. </script>
  635. ';
  636. }
  637. break;
  638. }
  639. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  640. echo '</table>';
  641. }
  642. if ($show_results && $answerType != HOT_SPOT) {
  643. echo '</table>';
  644. }
  645. $comnt = null;
  646. if ($show_results) {
  647. if ($is_allowedToEdit && $locked == false && !api_is_drh() && $isCoachAllowedToEdit) {
  648. $isFeedbackAllowed = true;
  649. } elseif (!$isCoachAllowedToEdit && $allowCoachFeedbackExercises) {
  650. $isFeedbackAllowed = true;
  651. }
  652. // Boss cannot edit exercise result
  653. if ($isBossOfStudent) {
  654. $isFeedbackAllowed = false;
  655. }
  656. $marksname = '';
  657. if ($isFeedbackAllowed && $action != 'export') {
  658. $name = 'fckdiv'.$questionId;
  659. $marksname = 'marksName'.$questionId;
  660. if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
  661. $url_name = get_lang('EditCommentsAndMarks');
  662. } else {
  663. $url_name = get_lang('AddComments');
  664. if ($action === 'edit') {
  665. $url_name = get_lang('EditIndividualComment');
  666. }
  667. }
  668. echo '<p>';
  669. echo Display::button(
  670. 'show_ck',
  671. $url_name,
  672. [
  673. 'type' => 'button',
  674. 'class' => 'btn btn-default',
  675. 'onclick' => "showfck('".$name."', '".$marksname."');",
  676. ]
  677. );
  678. echo '</p>';
  679. echo '<div id="feedback_'.$name.'" class="show">';
  680. $comnt = Event::get_comments($id, $questionId);
  681. if (!empty($comnt)) {
  682. echo ExerciseLib::getFeedbackText($comnt);
  683. }
  684. echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id);
  685. echo '</div>';
  686. echo '<div id="'.$name.'" class="row hidden">';
  687. echo '<div class="col-sm-'.($allowTeacherCommentAudio ? 7 : 12).'">';
  688. $arrid[] = $questionId;
  689. $feedback_form = new FormValidator('frmcomments'.$questionId);
  690. $renderer = &$feedback_form->defaultRenderer();
  691. $renderer->setFormTemplate('<form{attributes}><div>{content}</div></form>');
  692. $renderer->setCustomElementTemplate('<div>{element}</div>');
  693. $comnt = Event::get_comments($id, $questionId);
  694. $default = ['comments_'.$questionId => $comnt];
  695. if ($useAdvancedEditor) {
  696. $feedback_form->addElement(
  697. 'html_editor',
  698. 'comments_'.$questionId,
  699. null,
  700. null,
  701. [
  702. 'ToolbarSet' => 'TestAnswerFeedback',
  703. 'Width' => '100%',
  704. 'Height' => '120',
  705. ]
  706. );
  707. } else {
  708. $feedback_form->addElement('textarea', 'comments_'.$questionId);
  709. }
  710. $feedback_form->setDefaults($default);
  711. $feedback_form->display();
  712. echo '</div>';
  713. if ($allowRecordAudio && $allowTeacherCommentAudio) {
  714. echo '<div class="col-sm-5">';
  715. echo ExerciseLib::getOralFeedbackForm($id, $questionId, $student_id);
  716. echo '</div>';
  717. }
  718. echo '</div>';
  719. } else {
  720. $comnt = Event::get_comments($id, $questionId);
  721. echo '<br />';
  722. if (!empty($comnt)) {
  723. echo '<b>'.get_lang('Feedback').'</b>';
  724. echo ExerciseLib::getFeedbackText($comnt);
  725. echo ExerciseLib::getOralFeedbackAudio($id, $questionId, $student_id);
  726. }
  727. }
  728. if ($is_allowedToEdit && $isFeedbackAllowed && $action != 'export') {
  729. if (in_array($answerType, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
  730. $marksname = 'marksName'.$questionId;
  731. $arrmarks[] = $questionId;
  732. echo '<div id="'.$marksname.'" class="hidden">';
  733. $formMark = new FormValidator('marksform_'.$questionId, 'post');
  734. $formMark->addHeader(get_lang('AssignMarks'));
  735. $select = $formMark->addSelect('marks', get_lang('AssignMarks'), [], ['disable_js' => true]);
  736. $model = ExerciseLib::getCourseScoreModel();
  737. if (empty($model)) {
  738. for ($i = 0; $i <= $questionWeighting; $i++) {
  739. $attributes = [];
  740. if ($questionScore == $i) {
  741. $attributes['selected'] = 'selected';
  742. }
  743. $select->addOption($i, $i, $attributes);
  744. }
  745. } else {
  746. foreach ($model['score_list'] as $item) {
  747. $i = api_number_format($item['score_to_qualify'] / 100 * $questionWeighting, 2);
  748. $model = ExerciseLib::getModelStyle($item, $i);
  749. $attributes = ['class' => $item['css_class']];
  750. if ($questionScore == $i) {
  751. $attributes['selected'] = 'selected';
  752. }
  753. $select->addOption($model, $i, $attributes);
  754. }
  755. $select->updateSelectWithSelectedOption($formMark);
  756. }
  757. $formMark->display();
  758. echo '</div>';
  759. if ($questionScore == -1) {
  760. $questionScore = 0;
  761. echo ExerciseLib::getNotCorrectedYetText();
  762. }
  763. } else {
  764. $arrmarks[] = $questionId;
  765. echo '
  766. <div id="'.$marksname.'" class="hidden">
  767. <form name="marksform_'.$questionId.'" method="post" action="">
  768. <select name="marks" id="select_marks_'.$questionId.'" style="display:none;" class="exercise_mark_select">
  769. <option value="'.$questionScore.'" >'.$questionScore.'</option>
  770. </select>
  771. </form>
  772. <br/>
  773. </div>
  774. ';
  775. }
  776. } else {
  777. if ($questionScore == -1) {
  778. $questionScore = 0;
  779. }
  780. }
  781. }
  782. $my_total_score = $questionScore;
  783. $my_total_weight = $questionWeighting;
  784. $totalWeighting += $questionWeighting;
  785. $category_was_added_for_this_test = false;
  786. if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
  787. if (!isset($category_list[$objQuestionTmp->category]['score'])) {
  788. $category_list[$objQuestionTmp->category]['score'] = 0;
  789. }
  790. if (!isset($category_list[$objQuestionTmp->category]['total'])) {
  791. $category_list[$objQuestionTmp->category]['total'] = 0;
  792. }
  793. $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
  794. $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
  795. $category_was_added_for_this_test = true;
  796. }
  797. if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
  798. foreach ($objQuestionTmp->category_list as $category_id) {
  799. $category_list[$category_id]['score'] += $my_total_score;
  800. $category_list[$category_id]['total'] += $my_total_weight;
  801. $category_was_added_for_this_test = true;
  802. }
  803. }
  804. // No category for this question!
  805. if (!isset($category_list['none']['score'])) {
  806. $category_list['none']['score'] = 0;
  807. }
  808. if (!isset($category_list['none']['total'])) {
  809. $category_list['none']['total'] = 0;
  810. }
  811. if ($category_was_added_for_this_test == false) {
  812. $category_list['none']['score'] += $my_total_score;
  813. $category_list['none']['total'] += $my_total_weight;
  814. }
  815. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
  816. $my_total_score = 0;
  817. }
  818. $score = [];
  819. if ($show_results) {
  820. $scorePassed = $my_total_score >= $my_total_weight;
  821. if (function_exists('bccomp')) {
  822. $compareResult = bccomp($my_total_score, $my_total_weight, 3);
  823. $scorePassed = $compareResult === 1 || $compareResult === 0;
  824. }
  825. $score['result'] = ExerciseLib::show_score(
  826. $my_total_score,
  827. $my_total_weight,
  828. false,
  829. false
  830. );
  831. $score['pass'] = $scorePassed;
  832. $score['type'] = $answerType;
  833. $score['score'] = $my_total_score;
  834. $score['weight'] = $my_total_weight;
  835. $score['comments'] = isset($comnt) ? $comnt : null;
  836. if (isset($question_result['user_answered'])) {
  837. $score['user_answered'] = $question_result['user_answered'];
  838. }
  839. }
  840. if (in_array($objQuestionTmp->type, [FREE_ANSWER, ORAL_EXPRESSION, ANNOTATION])) {
  841. $scoreToReview = [
  842. 'score' => $my_total_score,
  843. 'comments' => isset($comnt) ? $comnt : null,
  844. ];
  845. $check = $objQuestionTmp->isQuestionWaitingReview($scoreToReview);
  846. if ($check === false) {
  847. $countPendingQuestions++;
  848. }
  849. }
  850. unset($objAnswerTmp);
  851. $i++;
  852. $contents = ob_get_clean();
  853. $question_content = '<div class="question_row">';
  854. if ($show_results && $objQuestionTmp) {
  855. $objQuestionTmp->export = $action == 'export';
  856. // Shows question title an description
  857. $question_content .= $objQuestionTmp->return_header(
  858. $objExercise,
  859. $counter,
  860. $score
  861. );
  862. }
  863. $counter++;
  864. $question_content .= $contents;
  865. $question_content .= '</div>';
  866. $exercise_content .= Display::panel($question_content);
  867. } // end of large foreach on questions
  868. $totalScoreText = '';
  869. if ($answerType != MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
  870. $pluginEvaluation = QuestionOptionsEvaluationPlugin::create();
  871. if ('true' === $pluginEvaluation->get(QuestionOptionsEvaluationPlugin::SETTING_ENABLE)) {
  872. $formula = $pluginEvaluation->getFormulaForExercise($objExercise->selectId());
  873. if (!empty($formula)) {
  874. $totalScore = $pluginEvaluation->getResultWithFormula($id, $formula);
  875. $totalWeighting = $pluginEvaluation->getMaxScore();
  876. }
  877. }
  878. }
  879. // Total score
  880. $myTotalScoreTemp = $totalScore;
  881. if ($origin != 'learnpath' || ($origin === 'learnpath' && isset($_GET['fb_type']))) {
  882. if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
  883. $totalScoreText .= '<div class="question_row">';
  884. if ($objExercise->selectPropagateNeg() == 0 && $myTotalScoreTemp < 0) {
  885. $myTotalScoreTemp = 0;
  886. }
  887. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
  888. $totalScoreText .= ExerciseLib::getQuestionDiagnosisRibbon(
  889. $objExercise,
  890. $myTotalScoreTemp,
  891. $totalWeighting,
  892. true
  893. );
  894. } else {
  895. $totalScoreText .= ExerciseLib::getTotalScoreRibbon(
  896. $objExercise,
  897. $myTotalScoreTemp,
  898. $totalWeighting,
  899. true,
  900. $countPendingQuestions
  901. );
  902. }
  903. $totalScoreText .= '</div>';
  904. }
  905. }
  906. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE_DEGREE_CERTAINTY) {
  907. $chartMultiAnswer = MultipleAnswerTrueFalseDegreeCertainty::displayStudentsChartResults($id, $objExercise);
  908. echo $chartMultiAnswer;
  909. }
  910. if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt)) {
  911. // Adding total
  912. $category_list['total'] = [
  913. 'score' => $myTotalScoreTemp,
  914. 'total' => $totalWeighting,
  915. ];
  916. echo TestCategory::get_stats_table_by_attempt(
  917. $objExercise->id,
  918. $category_list
  919. );
  920. }
  921. if (in_array(
  922. $track_exercise_info['results_disabled'],
  923. [RESULT_DISABLE_RANKING, RESULT_DISABLE_SHOW_SCORE_AND_EXPECTED_ANSWERS_AND_RANKING]
  924. )) {
  925. echo Display::page_header(get_lang('Ranking'), null, 'h4');
  926. echo ExerciseLib::displayResultsInRanking(
  927. $objExercise->iId,
  928. $student_id,
  929. $courseInfo['real_id'],
  930. $sessionId
  931. );
  932. }
  933. echo $totalScoreText;
  934. echo $exercise_content;
  935. // only show "score" in bottom of page if there's exercise content
  936. if ($show_results) {
  937. echo $totalScoreText;
  938. }
  939. if ($action === 'export') {
  940. $content = ob_get_clean();
  941. // needed in order to mpdf to work
  942. ob_clean();
  943. $params = [
  944. 'filename' => api_replace_dangerous_char(
  945. $objExercise->name.' '.
  946. $user_info['complete_name'].' '.
  947. api_get_local_time()
  948. ),
  949. 'course_code' => api_get_course_id(),
  950. 'session_info' => api_get_session_info(api_get_session_id()),
  951. 'course_info' => '',
  952. 'pdf_date' => '',
  953. 'show_real_course_teachers' => false,
  954. 'show_teacher_as_myself' => false,
  955. 'orientation' => 'P',
  956. ];
  957. $pdf = new PDF('A4', $params['orientation'], $params);
  958. $pdf->html_to_pdf_with_template($content, false, false, true);
  959. exit;
  960. }
  961. if ($isFeedbackAllowed) {
  962. if (is_array($arrid) && is_array($arrmarks)) {
  963. $strids = implode(',', $arrid);
  964. $marksid = implode(',', $arrmarks);
  965. }
  966. }
  967. if ($isFeedbackAllowed && $origin != 'learnpath' && $origin != 'student_progress') {
  968. if (in_array($origin, ['tracking_course', 'user_course', 'correct_exercise_in_lp'])) {
  969. $formUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&';
  970. $formUrl .= http_build_query([
  971. 'exerciseId' => $exercise_id,
  972. 'filter' => 2,
  973. 'comments' => 'update',
  974. 'exeid' => $id,
  975. 'origin' => $origin,
  976. 'details' => 'true',
  977. 'course' => Security::remove_XSS($_GET['cidReq']),
  978. ]);
  979. $emailForm = new FormValidator('form-email', 'post', $formUrl, '', ['id' => 'form-email']);
  980. $emailForm->addHidden('lp_item_id', $learnpath_id);
  981. $emailForm->addHidden('lp_item_view_id', $lp_item_view_id);
  982. $emailForm->addHidden('student_id', $student_id);
  983. $emailForm->addHidden('total_score', $totalScore);
  984. $emailForm->addHidden('my_exe_exo_id', $exercise_id);
  985. } else {
  986. $formUrl = api_get_path(WEB_CODE_PATH).'exercise/exercise_report.php?'.api_get_cidreq().'&';
  987. $formUrl .= http_build_query([
  988. 'exerciseId' => $exercise_id,
  989. 'filter' => 1,
  990. 'comments' => 'update',
  991. 'exeid' => $id,
  992. ]);
  993. $emailForm = new FormValidator(
  994. 'form-email',
  995. 'post',
  996. $formUrl,
  997. '',
  998. ['id' => 'form-email']
  999. );
  1000. }
  1001. if ($objExercise->results_disabled != RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS) {
  1002. $emailForm->addCheckBox(
  1003. 'send_notification',
  1004. get_lang('SendEmail'),
  1005. get_lang('SendEmail'),
  1006. ['onclick' => 'openEmailWrapper();']
  1007. );
  1008. $emailForm->addHtml('<div id="email_content_wrapper" style="display:none; margin-bottom: 20px;">');
  1009. $emailForm->addHtmlEditor(
  1010. 'notification_content',
  1011. get_lang('Content'),
  1012. false
  1013. );
  1014. $emailForm->addHtml('</div>');
  1015. }
  1016. if (empty($track_exercise_info['orig_lp_id']) || empty($track_exercise_info['orig_lp_item_id'])) {
  1017. // Default url
  1018. $url = api_get_path(WEB_CODE_PATH).'exercise/result.php?id='.$track_exercise_info['exe_id'].'&'.api_get_cidreq()
  1019. .'&show_headers=1&id_session='.api_get_session_id();
  1020. } else {
  1021. $url = api_get_path(WEB_CODE_PATH).'lp/lp_controller.php?action=view&item_id='
  1022. .$track_exercise_info['orig_lp_item_id'].'&lp_id='.$track_exercise_info['orig_lp_id'].'&'.api_get_cidreq()
  1023. .'&id_session='.api_get_session_id();
  1024. }
  1025. Skill::addSkillsToUserForm(
  1026. $emailForm,
  1027. ITEM_TYPE_EXERCISE,
  1028. $exercise_id,
  1029. $student_id,
  1030. $track_exercise_info['exe_id'],
  1031. true
  1032. );
  1033. $content = ExerciseLib::getEmailNotification(
  1034. $currentUserId,
  1035. api_get_course_info(),
  1036. $track_exercise_info['title'],
  1037. $url
  1038. );
  1039. $emailForm->setDefaults(['notification_content' => $content]);
  1040. $emailForm->addButtonSend(
  1041. get_lang('CorrectTest'),
  1042. 'submit',
  1043. false,
  1044. ['onclick' => "getFCK('$strids', '$marksid')"]
  1045. );
  1046. echo $emailForm->returnForm();
  1047. }
  1048. //Came from lpstats in a lp
  1049. if ($origin == 'student_progress') {
  1050. ?>
  1051. <button type="button" class="back" onclick="window.history.go(-1);" value="<?php echo get_lang('Back'); ?>">
  1052. <?php echo get_lang('Back'); ?>
  1053. </button>
  1054. <?php
  1055. } elseif ($origin == 'myprogress') {
  1056. ?>
  1057. <button type="button" class="save"
  1058. onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id(); ?>'"
  1059. value="<?php echo get_lang('Finish'); ?>">
  1060. <?php echo get_lang('Finish'); ?>
  1061. </button>
  1062. <?php
  1063. }
  1064. if ($origin != 'learnpath') {
  1065. //we are not in learnpath tool
  1066. Display::display_footer();
  1067. } else {
  1068. if (!isset($_GET['fb_type'])) {
  1069. $lp_mode = Session::read('lp_mode');
  1070. $url = '../lp/lp_controller.php?'.api_get_cidreq().'&';
  1071. $url .= http_build_query([
  1072. 'action' => 'view',
  1073. 'lp_id' => $learnpath_id,
  1074. 'lp_item_id' => $learnpath_item_id,
  1075. 'exeId' => $id,
  1076. 'fb_type' => $feedback_type,
  1077. ]);
  1078. $href = ($lp_mode == 'fullscreen')
  1079. ? ' window.opener.location.href="'.$url.'" '
  1080. : ' top.location.href="'.$url.'" ';
  1081. echo '<script type="text/javascript">'.$href.'</script>';
  1082. // Record the results in the learning path, using the SCORM interface (API)
  1083. echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
  1084. echo '</body></html>';
  1085. } else {
  1086. echo Display::return_message(
  1087. get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'),
  1088. 'normal'
  1089. );
  1090. echo '<br />';
  1091. }
  1092. }
  1093. // Destroying the session
  1094. Session::erase('questionList');
  1095. unset($questionList);
  1096. Session::erase('exerciseResult');
  1097. unset($exerciseResult);
  1098. Session::erase('calculatedAnswerId');