exercise_show.php 45 KB

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