exercise_show.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948
  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. * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  9. * @package chamilo.exercise
  10. * @todo remove the debug code and use the general debug library
  11. * @todo small letters for table variables
  12. *
  13. */
  14. require_once '../inc/global.inc.php';
  15. $debug = false;
  16. if (empty($origin)) {
  17. $origin = isset($_REQUEST['origin']) ? $_REQUEST['origin'] : null;
  18. }
  19. if ($origin == 'learnpath') {
  20. api_protect_course_script(false, false, true);
  21. } else {
  22. api_protect_course_script(true, false, true);
  23. }
  24. // Database table definitions
  25. $TBL_EXERCISE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  26. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  27. $TBL_TRACK_EXERCISES = Database::get_main_table(TABLE_STATISTIC_TRACK_E_EXERCISES);
  28. $TBL_TRACK_ATTEMPT = Database::get_main_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  29. // General parameters passed via POST/GET
  30. if ($debug) {
  31. error_log('Entered exercise_result.php: ' . print_r($_POST, 1));
  32. }
  33. if (empty($formSent)) {
  34. $formSent = isset($_REQUEST['formSent']) ? $_REQUEST['formSent'] : null;
  35. }
  36. if (empty($exerciseResult)) {
  37. $exerciseResult = isset($_SESSION['exerciseResult']) ? $_SESSION['exerciseResult'] : null;
  38. }
  39. if (empty($questionId)) {
  40. $questionId = isset($_REQUEST['questionId']) ? $_REQUEST['questionId'] : null;
  41. }
  42. if (empty($choice)) {
  43. $choice = isset($_REQUEST['choice']) ? $_REQUEST['choice'] : null;
  44. }
  45. if (empty($questionNum)) {
  46. $questionNum = isset($_REQUEST['num']) ? $_REQUEST['num'] : null;
  47. }
  48. if (empty($nbrQuestions)) {
  49. $nbrQuestions = isset($_REQUEST['nbrQuestions']) ? $_REQUEST['nbrQuestions'] : null;
  50. }
  51. if (empty($questionList)) {
  52. $questionList = isset($_SESSION['questionList']) ? $_SESSION['questionList'] : null;
  53. }
  54. if (empty($objExercise)) {
  55. $objExercise = isset($_SESSION['objExercise']) ? $_SESSION['objExercise'] : null;
  56. }
  57. if (empty($exeId)) {
  58. $exeId = isset($_REQUEST['id']) ? $_REQUEST['id'] : null;
  59. }
  60. if (empty($action)) {
  61. $action = isset($_REQUEST['action']) ? $_REQUEST['action'] : null;
  62. }
  63. $id = intval($_REQUEST['id']); //exe id
  64. if (empty($id)) {
  65. api_not_allowed(true);
  66. }
  67. if (api_is_course_session_coach(
  68. api_get_user_id(),
  69. api_get_course_int_id(),
  70. api_get_session_id()
  71. )) {
  72. if (!api_coach_can_edit_view_results(api_get_course_int_id(), api_get_session_id())) {
  73. api_not_allowed(true);
  74. }
  75. }
  76. $allowCoachFeedbackExercises = api_get_setting('allow_coach_feedback_exercises') === 'true';
  77. $maxEditors = intval(api_get_setting('exercise_max_ckeditors_in_page'));
  78. $is_allowedToEdit = api_is_allowed_to_edit(null, true) || $is_courseTutor || api_is_session_admin() || api_is_drh() || api_is_student_boss();
  79. $isCoachAllowedToEdit = api_is_allowed_to_edit(false, true);
  80. $isFeedbackAllowed = false;
  81. //Getting results from the exe_id. This variable also contain all the information about the exercise
  82. $track_exercise_info = ExerciseLib::get_exercise_track_exercise_info($id);
  83. //No track info
  84. if (empty($track_exercise_info)) {
  85. api_not_allowed(true);
  86. }
  87. $exercise_id = $track_exercise_info['id'];
  88. $exercise_date = $track_exercise_info['start_date'];
  89. $student_id = $track_exercise_info['exe_user_id'];
  90. $learnpath_id = $track_exercise_info['orig_lp_id'];
  91. $learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
  92. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  93. $current_user_id = api_get_user_id();
  94. if (api_is_excluded_user_type(true, $student_id)) {
  95. api_not_allowed(true);
  96. }
  97. $locked = api_resource_is_locked_by_gradebook($exercise_id, LINK_EXERCISE);
  98. if (empty($objExercise)) {
  99. $objExercise = new Exercise();
  100. $objExercise->read($exercise_id);
  101. }
  102. $feedback_type = $objExercise->feedback_type;
  103. //Only users can see their own results
  104. if (!$is_allowedToEdit) {
  105. if ($student_id != $current_user_id) {
  106. api_not_allowed(true);
  107. }
  108. }
  109. if (isset($_SESSION['gradebook'])) {
  110. $gradebook = Security::remove_XSS($_SESSION['gradebook']);
  111. }
  112. if (!empty($gradebook) && $gradebook == 'view') {
  113. $interbreadcrumb[] = array('url' => '../gradebook/' . $_SESSION['gradebook_dest'], 'name' => get_lang('ToolGradebook'));
  114. }
  115. $fromlink = '';
  116. $interbreadcrumb[] = array("url" => "exercise.php?" . api_get_cidreq(), "name" => get_lang('Exercises'));
  117. $interbreadcrumb[] = array("url" => "overview.php?exerciseId=" . $exercise_id . '&' . api_get_cidreq(), "name" => $objExercise->name);
  118. $interbreadcrumb[] = array("url" => "#", "name" => get_lang('Result'));
  119. $this_section = SECTION_COURSES;
  120. $htmlHeadXtra[] = '<link rel="stylesheet" href="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'hotspot/css/hotspot.css">';
  121. $htmlHeadXtra[] = '<script src="' . api_get_path(WEB_LIBRARY_JS_PATH) . 'hotspot/js/hotspot.js"></script>';
  122. if ($origin != 'learnpath') {
  123. Display::display_header('');
  124. } else {
  125. $htmlHeadXtra[] = "
  126. <style>
  127. body { background: none;}
  128. </style>
  129. ";
  130. Display::display_reduced_header();
  131. }
  132. ?>
  133. <script>
  134. var maxEditors = <?php echo intval($maxEditors); ?>;
  135. function showfck(sid, marksid) {
  136. document.getElementById(sid).style.display = 'block';
  137. document.getElementById(marksid).style.display = 'block';
  138. var comment = 'feedback_' + sid;
  139. document.getElementById(comment).style.display = 'none';
  140. }
  141. function getFCK(vals, marksid) {
  142. var f = document.getElementById('myform');
  143. var m_id = marksid.split(',');
  144. for (var i = 0; i < m_id.length; i++) {
  145. var oHidn = document.createElement("input");
  146. oHidn.type = "hidden";
  147. var selname = oHidn.name = "marks_" + m_id[i];
  148. var selid = document.forms['marksform_' + m_id[i]].marks.selectedIndex;
  149. oHidn.value = document.forms['marksform_' + m_id[i]].marks.options[selid].text;
  150. f.appendChild(oHidn);
  151. }
  152. var ids = vals.split(',');
  153. for (var k = 0; k < ids.length; k++) {
  154. var oHidden = document.createElement("input");
  155. oHidden.type = "hidden";
  156. oHidden.name = "comments_" + ids[k];
  157. if (CKEDITOR.instances[oHidden.name]) {
  158. oHidden.value = CKEDITOR.instances[oHidden.name].getData();
  159. } else {
  160. oHidden.value = $("textarea[name='" + oHidden.name + "']").val();
  161. }
  162. f.appendChild(oHidden);
  163. }
  164. }
  165. </script>
  166. <?php
  167. $show_results = true;
  168. $show_only_total_score = false;
  169. $showTotalScoreAndUserChoicesInLastAttempt = true;
  170. // Avoiding the "Score 0/0" message when the exe_id is not set
  171. if (!empty($track_exercise_info)) {
  172. // if the results_disabled of the Quiz is 1 when block the script
  173. $result_disabled = $track_exercise_info['results_disabled'];
  174. if (true) {
  175. //if (!(api_is_platform_admin() || api_is_course_admin() || api_is_course_coach()) ) {
  176. if ($result_disabled == RESULT_DISABLE_NO_SCORE_AND_EXPECTED_ANSWERS) {
  177. $show_results = false;
  178. if ($origin != 'learnpath') {
  179. /*echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
  180. <tr>
  181. <td colspan="2">';
  182. Display::display_warning_message(
  183. get_lang('ThankYouForPassingTheTest') . '<br /><br /><a href="exercise.php">' . (get_lang('BackToExercisesList')) . '</a>',
  184. false
  185. );
  186. echo '</td>
  187. </tr>
  188. </table>';*/
  189. }
  190. } elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ONLY) {
  191. $show_results = false;
  192. $show_only_total_score = true;
  193. if ($origin != 'learnpath') {
  194. echo '<table width="100%" border="0" cellspacing="0" cellpadding="0">
  195. <tr>
  196. <td colspan="2">';
  197. Display::display_warning_message(get_lang('ThankYouForPassingTheTest'), false);
  198. echo '</td>
  199. </tr>
  200. </table>';
  201. }
  202. } elseif ($result_disabled == RESULT_DISABLE_SHOW_SCORE_ATTEMPT_SHOW_ANSWERS_LAST_ATTEMPT) {
  203. $attempts = Event::getExerciseResultsByUser(
  204. api_get_user_id(),
  205. $objExercise->id,
  206. api_get_course_int_id(),
  207. api_get_session_id(),
  208. $track_exercise_info['orig_lp_id'],
  209. $track_exercise_info['orig_lp_item_id'],
  210. 'desc'
  211. );
  212. $numberAttempts = count($attempts);
  213. if ($numberAttempts >= $track_exercise_info['max_attempt']) {
  214. $show_results = true;
  215. $show_only_total_score = true;
  216. $showTotalScoreAndUserChoicesInLastAttempt = true;
  217. } else {
  218. $show_results = true;
  219. $show_only_total_score = true;
  220. $showTotalScoreAndUserChoicesInLastAttempt = false;
  221. }
  222. }
  223. }
  224. } else {
  225. Display::display_warning_message(get_lang('CantViewResults'));
  226. $show_results = false;
  227. }
  228. if ($origin == 'learnpath' && !isset($_GET['fb_type'])) {
  229. $show_results = false;
  230. }
  231. if ($is_allowedToEdit && in_array($action, ['qualify', 'edit'])) {
  232. $show_results = true;
  233. }
  234. if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
  235. $user_info = api_get_user_info($student_id);
  236. //Shows exercise header
  237. echo $objExercise->show_exercise_result_header(
  238. $user_info,
  239. api_convert_and_format_date($exercise_date),
  240. null,
  241. $track_exercise_info['user_ip']
  242. );
  243. }
  244. $i = $totalScore = $totalWeighting = 0;
  245. if ($debug > 0) {
  246. error_log("ExerciseResult: " . print_r($exerciseResult, 1));
  247. error_log("QuestionList: " . print_r($questionList, 1));
  248. }
  249. $arrques = array();
  250. $arrans = array();
  251. $user_restriction = $is_allowedToEdit ? '' : "AND user_id=" . intval($student_id) . " ";
  252. $sql = "SELECT attempts.question_id, answer
  253. FROM $TBL_TRACK_ATTEMPT as attempts
  254. INNER JOIN " . $TBL_TRACK_EXERCISES . " AS stats_exercises
  255. ON stats_exercises.exe_id=attempts.exe_id
  256. INNER JOIN $TBL_EXERCISE_QUESTION AS quizz_rel_questions
  257. ON
  258. quizz_rel_questions.exercice_id=stats_exercises.exe_exo_id AND
  259. quizz_rel_questions.question_id = attempts.question_id AND
  260. quizz_rel_questions.c_id=" . api_get_course_int_id() . "
  261. INNER JOIN " . $TBL_QUESTIONS . " AS questions
  262. ON
  263. questions.id=quizz_rel_questions.question_id AND
  264. questions.c_id = " . api_get_course_int_id() . "
  265. WHERE
  266. attempts.exe_id = " . intval($id) . " $user_restriction
  267. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  268. $result = Database::query($sql);
  269. $question_list_from_database = array();
  270. $exerciseResult = array();
  271. while ($row = Database::fetch_array($result)) {
  272. $question_list_from_database[] = $row['question_id'];
  273. $exerciseResult[$row['question_id']] = $row['answer'];
  274. }
  275. //Fixing #2073 Fixing order of questions
  276. if (!empty($track_exercise_info['data_tracking'])) {
  277. $temp_question_list = explode(',', $track_exercise_info['data_tracking']);
  278. // Getting question list from data_tracking
  279. if (!empty($temp_question_list)) {
  280. $questionList = $temp_question_list;
  281. }
  282. // If for some reason data_tracking is empty we select the question list from db
  283. if (empty($questionList)) {
  284. $questionList = $question_list_from_database;
  285. }
  286. } else {
  287. $questionList = $question_list_from_database;
  288. }
  289. // Display the text when finished message if we are on a LP #4227
  290. $end_of_message = $objExercise->selectTextWhenFinished();
  291. if (!empty($end_of_message) && ($origin == 'learnpath')) {
  292. Display::display_normal_message($end_of_message, false);
  293. echo "<div class='clear'>&nbsp;</div>";
  294. }
  295. // for each question
  296. $total_weighting = 0;
  297. foreach ($questionList as $questionId) {
  298. $objQuestionTmp = Question::read($questionId);
  299. $total_weighting += $objQuestionTmp->selectWeighting();
  300. }
  301. $counter = 1;
  302. $exercise_content = null;
  303. $category_list = array();
  304. $useAdvancedEditor = true;
  305. if (!empty($maxEditors) && count($questionList) > $maxEditors) {
  306. $useAdvancedEditor = false;
  307. }
  308. foreach ($questionList as $questionId) {
  309. $choice = isset($exerciseResult[$questionId]) ? $exerciseResult[$questionId] : '';
  310. // destruction of the Question object
  311. unset($objQuestionTmp);
  312. // creates a temporary Question object
  313. $objQuestionTmp = Question::read($questionId);
  314. $questionWeighting = $objQuestionTmp->selectWeighting();
  315. $answerType = $objQuestionTmp->selectType();
  316. // Start buffer
  317. ob_start();
  318. if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  319. $choice = array();
  320. }
  321. switch ($answerType) {
  322. case MULTIPLE_ANSWER_COMBINATION:
  323. //no break
  324. case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
  325. //no break
  326. case UNIQUE_ANSWER:
  327. //no break;
  328. case UNIQUE_ANSWER_NO_OPTION:
  329. //no break
  330. case MULTIPLE_ANSWER:
  331. //no break
  332. case MULTIPLE_ANSWER_TRUE_FALSE:
  333. //no break
  334. case FILL_IN_BLANKS:
  335. //no break
  336. case CALCULATED_ANSWER:
  337. //no break
  338. case GLOBAL_MULTIPLE_ANSWER:
  339. //no break
  340. case FREE_ANSWER:
  341. //no break
  342. case ORAL_EXPRESSION:
  343. //no break
  344. case MATCHING:
  345. //no break
  346. case DRAGGABLE:
  347. //no break
  348. case MATCHING_DRAGGABLE:
  349. $question_result = $objExercise->manage_answer(
  350. $id,
  351. $questionId,
  352. $choice,
  353. 'exercise_show',
  354. array(),
  355. false,
  356. true,
  357. $show_results,
  358. $objExercise->selectPropagateNeg(),
  359. [],
  360. $showTotalScoreAndUserChoicesInLastAttempt
  361. );
  362. $questionScore = $question_result['score'];
  363. $totalScore += $question_result['score'];
  364. break;
  365. case HOT_SPOT:
  366. if ($show_results || $showTotalScoreAndUserChoicesInLastAttempt) {
  367. echo '<table width="500" border="0"><tr>
  368. <td valign="top" align="center" style="padding-left:0px;" >
  369. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  370. }
  371. $question_result = $objExercise->manage_answer(
  372. $id,
  373. $questionId,
  374. $choice,
  375. 'exercise_show',
  376. array(),
  377. false,
  378. true,
  379. $show_results,
  380. $objExercise->selectPropagateNeg(),
  381. [],
  382. $showTotalScoreAndUserChoicesInLastAttempt
  383. );
  384. $questionScore = $question_result['score'];
  385. $totalScore += $question_result['score'];
  386. if ($show_results) {
  387. $relPath = api_get_path(REL_PATH);
  388. echo '</table></td></tr>';
  389. echo "
  390. <tr>
  391. <td colspan=\"2\">
  392. <div id=\"hotspot-solution\"></div>
  393. <script>
  394. $(document).on('ready', function () {
  395. new HotspotQuestion({
  396. questionId: $questionId,
  397. exerciseId: $id,
  398. selector: '#hotspot-solution',
  399. for: 'solution',
  400. relPath: '$relPath'
  401. });
  402. });
  403. </script>
  404. </td>
  405. </tr>
  406. </table>
  407. <br>
  408. ";
  409. }
  410. break;
  411. case HOT_SPOT_DELINEATION:
  412. $question_result = $objExercise->manage_answer(
  413. $id,
  414. $questionId,
  415. $choice,
  416. 'exercise_show',
  417. array(),
  418. false,
  419. true,
  420. $show_results,
  421. $objExercise->selectPropagateNeg(),
  422. 'database',
  423. [],
  424. $showTotalScoreAndUserChoicesInLastAttempt
  425. );
  426. $questionScore = $question_result['score'];
  427. $totalScore += $question_result['score'];
  428. $final_overlap = $question_result['extra']['final_overlap'];
  429. $final_missing = $question_result['extra']['final_missing'];
  430. $final_excess = $question_result['extra']['final_excess'];
  431. $overlap_color = $question_result['extra']['overlap_color'];
  432. $missing_color = $question_result['extra']['missing_color'];
  433. $excess_color = $question_result['extra']['excess_color'];
  434. $threadhold1 = $question_result['extra']['threadhold1'];
  435. $threadhold2 = $question_result['extra']['threadhold2'];
  436. $threadhold3 = $question_result['extra']['threadhold3'];
  437. if ($show_results) {
  438. if ($overlap_color) {
  439. $overlap_color = 'green';
  440. } else {
  441. $overlap_color = 'red';
  442. }
  443. if ($missing_color) {
  444. $missing_color = 'green';
  445. } else {
  446. $missing_color = 'red';
  447. }
  448. if ($excess_color) {
  449. $excess_color = 'green';
  450. } else {
  451. $excess_color = 'red';
  452. }
  453. if (!is_numeric($final_overlap)) {
  454. $final_overlap = 0;
  455. }
  456. if (!is_numeric($final_missing)) {
  457. $final_missing = 0;
  458. }
  459. if (!is_numeric($final_excess)) {
  460. $final_excess = 0;
  461. }
  462. if ($final_excess > 100) {
  463. $final_excess = 100;
  464. }
  465. $table_resume = '<table class="data_table">
  466. <tr class="row_odd" >
  467. <td></td>
  468. <td ><b>' . get_lang('Requirements') . '</b></td>
  469. <td><b>' . get_lang('YourAnswer') . '</b></td>
  470. </tr>
  471. <tr class="row_even">
  472. <td><b>' . get_lang('Overlap') . '</b></td>
  473. <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td>
  474. <td><div style="color:' . $overlap_color . '">' . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '</div></td>
  475. </tr>
  476. <tr>
  477. <td><b>' . get_lang('Excess') . '</b></td>
  478. <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td>
  479. <td><div style="color:' . $excess_color . '">' . (($final_excess < 0) ? 0 : intval($final_excess)) . '</div></td>
  480. </tr>
  481. <tr class="row_even">
  482. <td><b>' . get_lang('Missing') . '</b></td>
  483. <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td>
  484. <td><div style="color:' . $missing_color . '">' . (($final_missing < 0) ? 0 : intval($final_missing)) . '</div></td>
  485. </tr></table>';
  486. if ($answerType != HOT_SPOT_DELINEATION) {
  487. $item_list = explode('@@', $destination);
  488. $try = $item_list[0];
  489. $lp = $item_list[1];
  490. $destinationid = $item_list[2];
  491. $url = $item_list[3];
  492. $table_resume = '';
  493. } else {
  494. if ($next == 0) {
  495. $try = $try_hotspot;
  496. $lp = $lp_hotspot;
  497. $destinationid = $select_question_hotspot;
  498. $url = $url_hotspot;
  499. } else {
  500. //show if no error
  501. $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers);
  502. $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers);
  503. }
  504. }
  505. echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1>';
  506. if ($answerType == HOT_SPOT_DELINEATION) {
  507. if ($organs_at_risk_hit > 0) {
  508. $message = '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
  509. $message .= '<p style="color:#DC0A0A;"><b>' . get_lang('OARHit') . '</b></p>';
  510. } else {
  511. $message = '<p>' . get_lang('YourDelineation') . '</p>';
  512. $message .= $table_resume;
  513. $message .= '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
  514. }
  515. $message .= '<p>' . $comment . '</p>';
  516. echo $message;
  517. } else {
  518. echo '<p>' . $comment . '</p>';
  519. }
  520. //showing the score
  521. $queryfree = "select marks from " . $TBL_TRACK_ATTEMPT . " WHERE exe_id = " . intval($id) . " and question_id= " . intval($questionId) . "";
  522. $resfree = Database::query($queryfree);
  523. $questionScore = Database::result($resfree, 0, "marks");
  524. $totalScore += $questionScore;
  525. $relPath = api_get_path(REL_PATH);
  526. echo '</table></td></tr>';
  527. echo "
  528. <tr>
  529. <td colspan=\"2\">
  530. <div id=\"hotspot-solution\"></div>
  531. <script>
  532. $(document).on('ready', function () {
  533. new HotspotQuestion({
  534. questionId: $questionId,
  535. exerciseId: $id,
  536. selector: '#hotspot-solution',
  537. for: 'solution',
  538. relPath: '$relPath'
  539. });
  540. });
  541. </script>
  542. </td>
  543. </tr>
  544. </table>
  545. ";
  546. }
  547. break;
  548. }
  549. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  550. echo '</table>';
  551. }
  552. if ($show_results && $answerType != HOT_SPOT) {
  553. echo '</table>';
  554. }
  555. $comnt = null;
  556. if ($show_results) {
  557. if (
  558. $is_allowedToEdit &&
  559. $locked == false &&
  560. !api_is_drh() &&
  561. !api_is_student_boss() &&
  562. $isCoachAllowedToEdit
  563. ) {
  564. $isFeedbackAllowed = true;
  565. } else if (!$isCoachAllowedToEdit && $allowCoachFeedbackExercises) {
  566. $isFeedbackAllowed = true;
  567. }
  568. $marksname = '';
  569. if ($isFeedbackAllowed) {
  570. $name = "fckdiv" . $questionId;
  571. $marksname = "marksName" . $questionId;
  572. if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
  573. $url_name = get_lang('EditCommentsAndMarks');
  574. } else {
  575. if ($action == 'edit') {
  576. $url_name = get_lang('EditIndividualComment');
  577. } else {
  578. $url_name = get_lang('AddComments');
  579. }
  580. }
  581. echo '<br />';
  582. echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick' => "showfck('" . $name . "', '" . $marksname . "');"));
  583. echo '<br />';
  584. echo '<div id="feedback_' . $name . '" style="width:100%">';
  585. $comnt = trim(Event::get_comments($id, $questionId));
  586. if (empty($comnt)) {
  587. echo '<br />';
  588. } else {
  589. echo '<div id="question_feedback">' . $comnt . '</div>';
  590. }
  591. echo '</div>';
  592. echo '<div id="' . $name . '" style="display:none">';
  593. $arrid[] = $questionId;
  594. $feedback_form = new FormValidator('frmcomments' . $questionId, 'post', '');
  595. $feedback_form->addElement('html', '<br>');
  596. $renderer =& $feedback_form->defaultRenderer();
  597. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  598. $renderer->setCustomElementTemplate('<div align="left">{element}</div>');
  599. $comnt = Event::get_comments($id, $questionId);
  600. $default = array('comments_' . $questionId => $comnt);
  601. if ($useAdvancedEditor) {
  602. $feedback_form->addElement(
  603. 'html_editor',
  604. 'comments_' . $questionId,
  605. null,
  606. null,
  607. array(
  608. 'ToolbarSet' => 'TestAnswerFeedback',
  609. 'Width' => '100%',
  610. 'Height' => '120'
  611. )
  612. );
  613. } else {
  614. $feedback_form->addElement('textarea', 'comments_' . $questionId);
  615. }
  616. $feedback_form->addElement('html', '<br>');
  617. $feedback_form->setDefaults($default);
  618. $feedback_form->display();
  619. echo '</div>';
  620. } else {
  621. $comnt = Event::get_comments($id, $questionId);
  622. echo '<br />';
  623. if (!empty($comnt)) {
  624. echo '<b>' . get_lang('Feedback') . '</b>';
  625. echo '<div id="question_feedback">' . $comnt . '</div>';
  626. }
  627. }
  628. if ($is_allowedToEdit && $isFeedbackAllowed) {
  629. if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
  630. $marksname = "marksName" . $questionId;
  631. echo '<div id="' . $marksname . '" style="display:none">';
  632. echo '<form name="marksform_' . $questionId . '" method="post" action="">';
  633. $arrmarks[] = $questionId;
  634. echo get_lang("AssignMarks");
  635. echo "&nbsp;<select name='marks' id='marks'>";
  636. for ($i = 0; $i <= $questionWeighting; $i++) {
  637. echo '<option ' . (($i == $questionScore) ? "selected='selected'" : '') . '>' . $i . '</option>';
  638. }
  639. echo '</select>';
  640. echo '</form><br /></div>';
  641. if ($questionScore == -1) {
  642. $questionScore = 0;
  643. echo Display::return_message(get_lang('notCorrectedYet'));
  644. }
  645. } else {
  646. $arrmarks[] = $questionId;
  647. echo '<div id="' . $marksname . '" style="display:none"><form name="marksform_' . $questionId . '" method="post" action="">
  648. <select name="marks" id="marks" style="display:none;"><option>' . $questionScore . '</option></select></form><br/ ></div>';
  649. }
  650. } else {
  651. if ($questionScore == -1) {
  652. $questionScore = 0;
  653. }
  654. }
  655. }
  656. $my_total_score = $questionScore;
  657. $my_total_weight = $questionWeighting;
  658. $totalWeighting += $questionWeighting;
  659. $category_was_added_for_this_test = false;
  660. if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
  661. if (!isset($category_list[$objQuestionTmp->category]['score'])) {
  662. $category_list[$objQuestionTmp->category]['score'] = 0;
  663. }
  664. if (!isset($category_list[$objQuestionTmp->category]['total'])) {
  665. $category_list[$objQuestionTmp->category]['total'] = 0;
  666. }
  667. $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
  668. $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
  669. $category_was_added_for_this_test = true;
  670. }
  671. if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
  672. foreach ($objQuestionTmp->category_list as $category_id) {
  673. $category_list[$category_id]['score'] += $my_total_score;
  674. $category_list[$category_id]['total'] += $my_total_weight;
  675. $category_was_added_for_this_test = true;
  676. }
  677. }
  678. // No category for this question!
  679. if (!isset($category_list['none']['score'])) {
  680. $category_list['none']['score'] = 0;
  681. }
  682. if (!isset($category_list['none']['total'])) {
  683. $category_list['none']['total'] = 0;
  684. }
  685. if ($category_was_added_for_this_test == false) {
  686. $category_list['none']['score'] += $my_total_score;
  687. $category_list['none']['total'] += $my_total_weight;
  688. }
  689. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
  690. $my_total_score = 0;
  691. }
  692. $score = array();
  693. if ($show_results) {
  694. $score['result'] = get_lang('Score') . " : " . ExerciseLib::show_score(
  695. $my_total_score,
  696. $my_total_weight,
  697. false,
  698. false
  699. );
  700. $score['pass'] = $my_total_score >= $my_total_weight ? true : false;
  701. $score['type'] = $answerType;
  702. $score['score'] = $my_total_score;
  703. $score['weight'] = $my_total_weight;
  704. $score['comments'] = isset($comnt) ? $comnt : null;
  705. }
  706. unset($objAnswerTmp);
  707. $i++;
  708. $contents = ob_get_clean();
  709. $question_content = '<div class="question_row">';
  710. if ($show_results) {
  711. //Shows question title an description
  712. $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
  713. }
  714. $counter++;
  715. $question_content .= $contents;
  716. $question_content .= '</div>';
  717. $exercise_content .= $question_content;
  718. } // end of large foreach on questions
  719. $total_score_text = null;
  720. //Total score
  721. if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  722. if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt) {
  723. $total_score_text .= '<div class="question_row">';
  724. $my_total_score_temp = $totalScore;
  725. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
  726. $my_total_score_temp = 0;
  727. }
  728. $total_score_text .= ExerciseLib::get_question_ribbon(
  729. $objExercise,
  730. $my_total_score_temp,
  731. $totalWeighting,
  732. true
  733. );
  734. $total_score_text .= '</div>';
  735. }
  736. }
  737. if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoicesInLastAttempt)) {
  738. // Adding total
  739. $category_list['total'] = array(
  740. 'score' => $my_total_score_temp,
  741. 'total' => $totalWeighting
  742. );
  743. echo TestCategory::get_stats_table_by_attempt($objExercise->id, $category_list);
  744. }
  745. echo $total_score_text;
  746. echo $exercise_content;
  747. echo $total_score_text;
  748. if ($isFeedbackAllowed) {
  749. if (is_array($arrid) && is_array($arrmarks)) {
  750. $strids = implode(",", $arrid);
  751. $marksid = implode(",", $arrmarks);
  752. }
  753. }
  754. if ($isFeedbackAllowed) {
  755. if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
  756. $formUrl = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&';
  757. $formUrl .= http_build_query([
  758. 'exerciseId' => $exercise_id,
  759. 'filter' => 2,
  760. 'comments' => 'update',
  761. 'exeid' => $id,
  762. 'origin' => $origin,
  763. 'details' => 'true',
  764. 'course' => Security::remove_XSS($_GET['cidReq'])
  765. ]);
  766. $formUrl .= $fromlink;
  767. echo '<form name="myform" id="myform" action="' . $formUrl . '" method="post">';
  768. echo '<input type = "hidden" name="lp_item_id" value="' . $learnpath_id . '">';
  769. echo '<input type = "hidden" name="lp_item_view_id" value="' . $lp_item_view_id . '">';
  770. echo '<input type = "hidden" name="student_id" value="' . $student_id . '">';
  771. echo '<input type = "hidden" name="total_score" value="' . $totalScore . '"> ';
  772. echo '<input type = "hidden" name="my_exe_exo_id" value="' . $exercise_id . '"> ';
  773. } else {
  774. $formUrl = api_get_path(WEB_CODE_PATH) . 'exercice/exercise_report.php?' . api_get_cidreq() . '&';
  775. $formUrl .= http_build_query([
  776. 'exerciseId' => $exercise_id,
  777. 'filter' => 1,
  778. 'comments' => 'update',
  779. 'exeid' => $id
  780. ]);
  781. echo ' <form name="myform" id="myform" action="' . $formUrl . '" method="post">';
  782. }
  783. if ($origin != 'learnpath' && $origin != 'student_progress') {
  784. echo '<label><input type= "checkbox" name="send_notification"> ' . get_lang('SendEmail') . '</label>';
  785. ?>
  786. <br/>
  787. <button type="submit" class="btn btn-primary" value="<?php echo get_lang('Ok'); ?>"
  788. onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
  789. <?php echo get_lang('CorrectTest'); ?>
  790. </button>
  791. </form>
  792. <?php
  793. }
  794. }
  795. //Came from lpstats in a lp
  796. if ($origin == 'student_progress') { ?>
  797. <button type="button" class="back" onclick="window.history.go(-1);" value="<?php echo get_lang('Back'); ?>">
  798. <?php echo get_lang('Back'); ?></button>
  799. <?php
  800. } else if ($origin == 'myprogress') {
  801. ?>
  802. <button type="button" class="save"
  803. onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id() ?>'"
  804. value="<?php echo get_lang('Finish'); ?>">
  805. <?php echo get_lang('Finish'); ?>
  806. </button>
  807. <?php
  808. }
  809. if ($origin != 'learnpath') {
  810. //we are not in learnpath tool
  811. Display::display_footer();
  812. } else {
  813. if (!isset($_GET['fb_type'])) {
  814. $lp_mode = $_SESSION['lp_mode'];
  815. $url = '../newscorm/lp_controller.php?' . api_get_cidreq() . '&';
  816. $url .= http_build_url([
  817. 'action' => 'view',
  818. 'lp_id' => $learnpath_id,
  819. 'lp_item_id' => $learnpath_item_id,
  820. 'exeId' => $exeId,
  821. 'fb_type' => $feedback_type
  822. ]);
  823. $href = ($lp_mode == 'fullscreen') ? ' window.opener.location.href="' . $url . '" ' : ' top.location.href="' . $url . '" ';
  824. echo '<script type="text/javascript">' . $href . '</script>';
  825. // Record the results in the learning path, using the SCORM interface (API)
  826. echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
  827. echo '</body></html>';
  828. } else {
  829. Display::display_normal_message(get_lang('ExerciseFinished') . ' ' . get_lang('ToContinueUseMenu'));
  830. echo '<br />';
  831. }
  832. }
  833. // Destroying the session
  834. Session::erase('questionList');
  835. unset ($questionList);
  836. Session::erase('exerciseResult');
  837. unset ($exerciseResult);