exercise_show.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Shows the exercise results
  5. *
  6. * @author Julio Montoya - Added switchable fill in blank option added
  7. * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  8. * @package chamilo.exercise
  9. * @todo remove the debug code and use the general debug library
  10. * @todo small letters for table variables
  11. *
  12. */
  13. use ChamiloSession as Session;
  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. $showTotalScoreAndUserChoices = 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. $showTotalScoreAndUserChoices = false;
  217. } else {
  218. $show_results = true;
  219. $show_only_total_score = true;
  220. $showTotalScoreAndUserChoices = true;
  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 ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) {
  232. $user_info = api_get_user_info($student_id);
  233. //Shows exercise header
  234. echo $objExercise->show_exercise_result_header(
  235. $user_info,
  236. api_convert_and_format_date($exercise_date),
  237. null,
  238. $track_exercise_info['user_ip']
  239. );
  240. }
  241. $i = $totalScore = $totalWeighting = 0;
  242. if ($debug > 0) {
  243. error_log("ExerciseResult: " . print_r($exerciseResult, 1));
  244. error_log("QuestionList: " . print_r($questionList, 1));
  245. }
  246. $arrques = array();
  247. $arrans = array();
  248. $user_restriction = $is_allowedToEdit ? '' : "AND user_id=" . intval($student_id) . " ";
  249. $sql = "SELECT attempts.question_id, answer
  250. FROM $TBL_TRACK_ATTEMPT as attempts
  251. INNER JOIN " . $TBL_TRACK_EXERCISES . " AS stats_exercises
  252. ON stats_exercises.exe_id=attempts.exe_id
  253. INNER JOIN $TBL_EXERCISE_QUESTION AS quizz_rel_questions
  254. ON
  255. quizz_rel_questions.exercice_id=stats_exercises.exe_exo_id AND
  256. quizz_rel_questions.question_id = attempts.question_id AND
  257. quizz_rel_questions.c_id=" . api_get_course_int_id() . "
  258. INNER JOIN " . $TBL_QUESTIONS . " AS questions
  259. ON
  260. questions.id=quizz_rel_questions.question_id AND
  261. questions.c_id = " . api_get_course_int_id() . "
  262. WHERE
  263. attempts.exe_id = " . intval($id) . " $user_restriction
  264. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  265. $result = Database::query($sql);
  266. $question_list_from_database = array();
  267. $exerciseResult = array();
  268. while ($row = Database::fetch_array($result)) {
  269. $question_list_from_database[] = $row['question_id'];
  270. $exerciseResult[$row['question_id']] = $row['answer'];
  271. }
  272. //Fixing #2073 Fixing order of questions
  273. if (!empty($track_exercise_info['data_tracking'])) {
  274. $temp_question_list = explode(',', $track_exercise_info['data_tracking']);
  275. // Getting question list from data_tracking
  276. if (!empty($temp_question_list)) {
  277. $questionList = $temp_question_list;
  278. }
  279. // If for some reason data_tracking is empty we select the question list from db
  280. if (empty($questionList)) {
  281. $questionList = $question_list_from_database;
  282. }
  283. } else {
  284. $questionList = $question_list_from_database;
  285. }
  286. // Display the text when finished message if we are on a LP #4227
  287. $end_of_message = $objExercise->selectTextWhenFinished();
  288. if (!empty($end_of_message) && ($origin == 'learnpath')) {
  289. Display::display_normal_message($end_of_message, false);
  290. echo "<div class='clear'>&nbsp;</div>";
  291. }
  292. // for each question
  293. $total_weighting = 0;
  294. foreach ($questionList as $questionId) {
  295. $objQuestionTmp = Question::read($questionId);
  296. $total_weighting += $objQuestionTmp->selectWeighting();
  297. }
  298. $counter = 1;
  299. $exercise_content = null;
  300. $category_list = array();
  301. $useAdvancedEditor = true;
  302. if (!empty($maxEditors) && count($questionList) > $maxEditors) {
  303. $useAdvancedEditor = false;
  304. }
  305. foreach ($questionList as $questionId) {
  306. $choice = $exerciseResult[$questionId];
  307. // destruction of the Question object
  308. unset($objQuestionTmp);
  309. // creates a temporary Question object
  310. $objQuestionTmp = Question::read($questionId);
  311. $questionWeighting = $objQuestionTmp->selectWeighting();
  312. $answerType = $objQuestionTmp->selectType();
  313. // Start buffer
  314. ob_start();
  315. if ($answerType == MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE) {
  316. $choice = array();
  317. }
  318. switch ($answerType) {
  319. case MULTIPLE_ANSWER_COMBINATION:
  320. //no break
  321. case MULTIPLE_ANSWER_COMBINATION_TRUE_FALSE:
  322. //no break
  323. case UNIQUE_ANSWER:
  324. //no break;
  325. case UNIQUE_ANSWER_NO_OPTION:
  326. //no break
  327. case MULTIPLE_ANSWER:
  328. //no break
  329. case MULTIPLE_ANSWER_TRUE_FALSE:
  330. //no break
  331. case FILL_IN_BLANKS:
  332. //no break
  333. case CALCULATED_ANSWER:
  334. //no break
  335. case GLOBAL_MULTIPLE_ANSWER:
  336. //no break
  337. case FREE_ANSWER:
  338. //no break
  339. case ORAL_EXPRESSION:
  340. //no break
  341. case MATCHING:
  342. //no break
  343. case DRAGGABLE:
  344. //no break
  345. case MATCHING_DRAGGABLE:
  346. $question_result = $objExercise->manage_answer(
  347. $id,
  348. $questionId,
  349. $choice,
  350. 'exercise_show',
  351. array(),
  352. false,
  353. true,
  354. $show_results,
  355. $objExercise->selectPropagateNeg(),
  356. [],
  357. $showTotalScoreAndUserChoices
  358. );
  359. $questionScore = $question_result['score'];
  360. $totalScore += $question_result['score'];
  361. break;
  362. case HOT_SPOT:
  363. if ($show_results || $showTotalScoreAndUserChoices) {
  364. echo '<table width="500" border="0"><tr>
  365. <td valign="top" align="center" style="padding-left:0px;" >
  366. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  367. }
  368. $question_result = $objExercise->manage_answer(
  369. $id,
  370. $questionId,
  371. $choice,
  372. 'exercise_show',
  373. array(),
  374. false,
  375. true,
  376. $show_results,
  377. $objExercise->selectPropagateNeg(),
  378. [],
  379. $showTotalScoreAndUserChoices
  380. );
  381. $questionScore = $question_result['score'];
  382. $totalScore += $question_result['score'];
  383. if ($show_results) {
  384. $relPath = api_get_path(REL_PATH);
  385. echo '</table></td></tr>';
  386. echo "
  387. <tr>
  388. <td colspan=\"2\">
  389. <div id=\"hotspot-solution\"></div>
  390. <script>
  391. $(document).on('ready', function () {
  392. new HotspotQuestion({
  393. questionId: $questionId,
  394. exerciseId: $id,
  395. selector: '#hotspot-solution',
  396. for: 'solution',
  397. relPath: '$relPath'
  398. });
  399. });
  400. </script>
  401. </td>
  402. </tr>
  403. </table>
  404. <br>
  405. ";
  406. }
  407. break;
  408. case HOT_SPOT_DELINEATION:
  409. $question_result = $objExercise->manage_answer(
  410. $id,
  411. $questionId,
  412. $choice,
  413. 'exercise_show',
  414. array(),
  415. false,
  416. true,
  417. $show_results,
  418. $objExercise->selectPropagateNeg(),
  419. 'database',
  420. [],
  421. $showTotalScoreAndUserChoices
  422. );
  423. $questionScore = $question_result['score'];
  424. $totalScore += $question_result['score'];
  425. $final_overlap = $question_result['extra']['final_overlap'];
  426. $final_missing = $question_result['extra']['final_missing'];
  427. $final_excess = $question_result['extra']['final_excess'];
  428. $overlap_color = $question_result['extra']['overlap_color'];
  429. $missing_color = $question_result['extra']['missing_color'];
  430. $excess_color = $question_result['extra']['excess_color'];
  431. $threadhold1 = $question_result['extra']['threadhold1'];
  432. $threadhold2 = $question_result['extra']['threadhold2'];
  433. $threadhold3 = $question_result['extra']['threadhold3'];
  434. if ($show_results) {
  435. if ($overlap_color) {
  436. $overlap_color = 'green';
  437. } else {
  438. $overlap_color = 'red';
  439. }
  440. if ($missing_color) {
  441. $missing_color = 'green';
  442. } else {
  443. $missing_color = 'red';
  444. }
  445. if ($excess_color) {
  446. $excess_color = 'green';
  447. } else {
  448. $excess_color = 'red';
  449. }
  450. if (!is_numeric($final_overlap)) {
  451. $final_overlap = 0;
  452. }
  453. if (!is_numeric($final_missing)) {
  454. $final_missing = 0;
  455. }
  456. if (!is_numeric($final_excess)) {
  457. $final_excess = 0;
  458. }
  459. if ($final_excess > 100) {
  460. $final_excess = 100;
  461. }
  462. $table_resume = '<table class="data_table">
  463. <tr class="row_odd" >
  464. <td></td>
  465. <td ><b>' . get_lang('Requirements') . '</b></td>
  466. <td><b>' . get_lang('YourAnswer') . '</b></td>
  467. </tr>
  468. <tr class="row_even">
  469. <td><b>' . get_lang('Overlap') . '</b></td>
  470. <td>' . get_lang('Min') . ' ' . $threadhold1 . '</td>
  471. <td><div style="color:' . $overlap_color . '">' . (($final_overlap < 0) ? 0 : intval($final_overlap)) . '</div></td>
  472. </tr>
  473. <tr>
  474. <td><b>' . get_lang('Excess') . '</b></td>
  475. <td>' . get_lang('Max') . ' ' . $threadhold2 . '</td>
  476. <td><div style="color:' . $excess_color . '">' . (($final_excess < 0) ? 0 : intval($final_excess)) . '</div></td>
  477. </tr>
  478. <tr class="row_even">
  479. <td><b>' . get_lang('Missing') . '</b></td>
  480. <td>' . get_lang('Max') . ' ' . $threadhold3 . '</td>
  481. <td><div style="color:' . $missing_color . '">' . (($final_missing < 0) ? 0 : intval($final_missing)) . '</div></td>
  482. </tr></table>';
  483. if ($answerType != HOT_SPOT_DELINEATION) {
  484. $item_list = explode('@@', $destination);
  485. $try = $item_list[0];
  486. $lp = $item_list[1];
  487. $destinationid = $item_list[2];
  488. $url = $item_list[3];
  489. $table_resume = '';
  490. } else {
  491. if ($next == 0) {
  492. $try = $try_hotspot;
  493. $lp = $lp_hotspot;
  494. $destinationid = $select_question_hotspot;
  495. $url = $url_hotspot;
  496. } else {
  497. //show if no error
  498. $comment = $answerComment = $objAnswerTmp->selectComment($nbrAnswers);
  499. $answerDestination = $objAnswerTmp->selectDestination($nbrAnswers);
  500. }
  501. }
  502. echo '<h1><div style="color:#333;">' . get_lang('Feedback') . '</div></h1>';
  503. if ($answerType == HOT_SPOT_DELINEATION) {
  504. if ($organs_at_risk_hit > 0) {
  505. $message = '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
  506. $message .= '<p style="color:#DC0A0A;"><b>' . get_lang('OARHit') . '</b></p>';
  507. } else {
  508. $message = '<p>' . get_lang('YourDelineation') . '</p>';
  509. $message .= $table_resume;
  510. $message .= '<br />' . get_lang('ResultIs') . ' <b>' . $result_comment . '</b><br />';
  511. }
  512. $message .= '<p>' . $comment . '</p>';
  513. echo $message;
  514. } else {
  515. echo '<p>' . $comment . '</p>';
  516. }
  517. //showing the score
  518. $queryfree = "select marks from " . $TBL_TRACK_ATTEMPT . " WHERE exe_id = " . intval($id) . " and question_id= " . intval($questionId) . "";
  519. $resfree = Database::query($queryfree);
  520. $questionScore = Database::result($resfree, 0, "marks");
  521. $totalScore += $questionScore;
  522. $relPath = api_get_path(REL_PATH);
  523. echo '</table></td></tr>';
  524. echo "
  525. <tr>
  526. <td colspan=\"2\">
  527. <div id=\"hotspot-solution\"></div>
  528. <script>
  529. $(document).on('ready', function () {
  530. new HotspotQuestion({
  531. questionId: $questionId,
  532. exerciseId: $id,
  533. selector: '#hotspot-solution',
  534. for: 'solution',
  535. relPath: '$relPath'
  536. });
  537. });
  538. </script>
  539. </td>
  540. </tr>
  541. </table>
  542. ";
  543. }
  544. break;
  545. }
  546. if ($answerType == MULTIPLE_ANSWER_TRUE_FALSE) {
  547. echo '</table>';
  548. }
  549. if ($show_results && $answerType != HOT_SPOT) {
  550. echo '</table>';
  551. }
  552. $comnt = null;
  553. if ($show_results) {
  554. if (
  555. $is_allowedToEdit &&
  556. $locked == false &&
  557. !api_is_drh() &&
  558. !api_is_student_boss() &&
  559. $isCoachAllowedToEdit
  560. ) {
  561. $isFeedbackAllowed = true;
  562. } else if (!$isCoachAllowedToEdit && $allowCoachFeedbackExercises) {
  563. $isFeedbackAllowed = true;
  564. }
  565. $marksname = '';
  566. if ($isFeedbackAllowed) {
  567. $name = "fckdiv" . $questionId;
  568. $marksname = "marksName" . $questionId;
  569. if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
  570. $url_name = get_lang('EditCommentsAndMarks');
  571. } else {
  572. if ($action == 'edit') {
  573. $url_name = get_lang('EditIndividualComment');
  574. } else {
  575. $url_name = get_lang('AddComments');
  576. }
  577. }
  578. echo '<br />';
  579. echo Display::url($url_name, 'javascript://', array('class' => 'btn', 'onclick' => "showfck('" . $name . "', '" . $marksname . "');"));
  580. echo '<br />';
  581. echo '<div id="feedback_' . $name . '" style="width:100%">';
  582. $comnt = trim(Event::get_comments($id, $questionId));
  583. if (empty($comnt)) {
  584. echo '<br />';
  585. } else {
  586. echo '<div id="question_feedback">' . $comnt . '</div>';
  587. }
  588. echo '</div>';
  589. echo '<div id="' . $name . '" style="display:none">';
  590. $arrid[] = $questionId;
  591. $feedback_form = new FormValidator('frmcomments' . $questionId, 'post', '');
  592. $feedback_form->addElement('html', '<br>');
  593. $renderer =& $feedback_form->defaultRenderer();
  594. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  595. $renderer->setCustomElementTemplate('<div align="left">{element}</div>');
  596. $comnt = Event::get_comments($id, $questionId);
  597. $default = array('comments_' . $questionId => $comnt);
  598. if ($useAdvancedEditor) {
  599. $feedback_form->addElement(
  600. 'html_editor',
  601. 'comments_' . $questionId,
  602. null,
  603. null,
  604. array(
  605. 'ToolbarSet' => 'TestAnswerFeedback',
  606. 'Width' => '100%',
  607. 'Height' => '120'
  608. )
  609. );
  610. } else {
  611. $feedback_form->addElement('textarea', 'comments_' . $questionId);
  612. }
  613. $feedback_form->addElement('html', '<br>');
  614. $feedback_form->setDefaults($default);
  615. $feedback_form->display();
  616. echo '</div>';
  617. } else {
  618. $comnt = Event::get_comments($id, $questionId);
  619. echo '<br />';
  620. if (!empty($comnt)) {
  621. echo '<b>' . get_lang('Feedback') . '</b>';
  622. echo '<div id="question_feedback">' . $comnt . '</div>';
  623. }
  624. }
  625. if ($is_allowedToEdit && $isFeedbackAllowed) {
  626. if (in_array($answerType, array(FREE_ANSWER, ORAL_EXPRESSION))) {
  627. $marksname = "marksName" . $questionId;
  628. echo '<div id="' . $marksname . '" style="display:none">';
  629. echo '<form name="marksform_' . $questionId . '" method="post" action="">';
  630. $arrmarks[] = $questionId;
  631. echo get_lang("AssignMarks");
  632. echo "&nbsp;<select name='marks' id='marks'>";
  633. for ($i = 0; $i <= $questionWeighting; $i++) {
  634. echo '<option ' . (($i == $questionScore) ? "selected='selected'" : '') . '>' . $i . '</option>';
  635. }
  636. echo '</select>';
  637. echo '</form><br /></div>';
  638. if ($questionScore == -1) {
  639. $questionScore = 0;
  640. echo Display::return_message(get_lang('notCorrectedYet'));
  641. }
  642. } else {
  643. $arrmarks[] = $questionId;
  644. echo '<div id="' . $marksname . '" style="display:none"><form name="marksform_' . $questionId . '" method="post" action="">
  645. <select name="marks" id="marks" style="display:none;"><option>' . $questionScore . '</option></select></form><br/ ></div>';
  646. }
  647. } else {
  648. if ($questionScore == -1) {
  649. $questionScore = 0;
  650. }
  651. }
  652. }
  653. $my_total_score = $questionScore;
  654. $my_total_weight = $questionWeighting;
  655. $totalWeighting += $questionWeighting;
  656. $category_was_added_for_this_test = false;
  657. if (isset($objQuestionTmp->category) && !empty($objQuestionTmp->category)) {
  658. if (!isset($category_list[$objQuestionTmp->category]['score'])) {
  659. $category_list[$objQuestionTmp->category]['score'] = 0;
  660. }
  661. if (!isset($category_list[$objQuestionTmp->category]['total'])) {
  662. $category_list[$objQuestionTmp->category]['total'] = 0;
  663. }
  664. $category_list[$objQuestionTmp->category]['score'] += $my_total_score;
  665. $category_list[$objQuestionTmp->category]['total'] += $my_total_weight;
  666. $category_was_added_for_this_test = true;
  667. }
  668. if (isset($objQuestionTmp->category_list) && !empty($objQuestionTmp->category_list)) {
  669. foreach ($objQuestionTmp->category_list as $category_id) {
  670. $category_list[$category_id]['score'] += $my_total_score;
  671. $category_list[$category_id]['total'] += $my_total_weight;
  672. $category_was_added_for_this_test = true;
  673. }
  674. }
  675. // No category for this question!
  676. if (!isset($category_list['none']['score'])) {
  677. $category_list['none']['score'] = 0;
  678. }
  679. if (!isset($category_list['none']['total'])) {
  680. $category_list['none']['total'] = 0;
  681. }
  682. if ($category_was_added_for_this_test == false) {
  683. $category_list['none']['score'] += $my_total_score;
  684. $category_list['none']['total'] += $my_total_weight;
  685. }
  686. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score < 0) {
  687. $my_total_score = 0;
  688. }
  689. $score = array();
  690. if ($show_results) {
  691. $score['result'] = get_lang('Score') . " : " . ExerciseLib::show_score(
  692. $my_total_score,
  693. $my_total_weight,
  694. false,
  695. false
  696. );
  697. $score['pass'] = $my_total_score >= $my_total_weight ? true : false;
  698. $score['type'] = $answerType;
  699. $score['score'] = $my_total_score;
  700. $score['weight'] = $my_total_weight;
  701. $score['comments'] = isset($comnt) ? $comnt : null;
  702. }
  703. unset($objAnswerTmp);
  704. $i++;
  705. $contents = ob_get_clean();
  706. $question_content = '<div class="question_row">';
  707. if ($show_results) {
  708. //Shows question title an description
  709. $question_content .= $objQuestionTmp->return_header(null, $counter, $score);
  710. }
  711. $counter++;
  712. $question_content .= $contents;
  713. $question_content .= '</div>';
  714. $exercise_content .= $question_content;
  715. } // end of large foreach on questions
  716. $total_score_text = null;
  717. //Total score
  718. if ($origin != 'learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  719. if ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices) {
  720. $total_score_text .= '<div class="question_row">';
  721. $my_total_score_temp = $totalScore;
  722. if ($objExercise->selectPropagateNeg() == 0 && $my_total_score_temp < 0) {
  723. $my_total_score_temp = 0;
  724. }
  725. $total_score_text .= ExerciseLib::get_question_ribbon(
  726. $objExercise,
  727. $my_total_score_temp,
  728. $totalWeighting,
  729. true
  730. );
  731. $total_score_text .= '</div>';
  732. }
  733. }
  734. if (!empty($category_list) && ($show_results || $show_only_total_score || $showTotalScoreAndUserChoices)) {
  735. // Adding total
  736. $category_list['total'] = array(
  737. 'score' => $my_total_score_temp,
  738. 'total' => $totalWeighting
  739. );
  740. echo TestCategory::get_stats_table_by_attempt($objExercise->id, $category_list);
  741. }
  742. echo $total_score_text;
  743. echo $exercise_content;
  744. echo $total_score_text;
  745. if ($isFeedbackAllowed) {
  746. if (is_array($arrid) && is_array($arrmarks)) {
  747. $strids = implode(",", $arrid);
  748. $marksid = implode(",", $arrmarks);
  749. }
  750. }
  751. if ($isFeedbackAllowed) {
  752. if (in_array($origin, array('tracking_course', 'user_course', 'correct_exercise_in_lp'))) {
  753. $formUrl = api_get_path(WEB_CODE_PATH) . 'exercise/exercise_report.php?' . api_get_cidreq() . '&';
  754. $formUrl .= http_build_query([
  755. 'exerciseId' => $exercise_id,
  756. 'filter' => 2,
  757. 'comments' => 'update',
  758. 'exeid' => $id,
  759. 'origin' => $origin,
  760. 'details' => 'true',
  761. 'course' => Security::remove_XSS($_GET['cidReq'])
  762. ]);
  763. $formUrl .= $fromlink;
  764. echo '<form name="myform" id="myform" action="' . $formUrl . '" method="post">';
  765. echo '<input type = "hidden" name="lp_item_id" value="' . $learnpath_id . '">';
  766. echo '<input type = "hidden" name="lp_item_view_id" value="' . $lp_item_view_id . '">';
  767. echo '<input type = "hidden" name="student_id" value="' . $student_id . '">';
  768. echo '<input type = "hidden" name="total_score" value="' . $totalScore . '"> ';
  769. echo '<input type = "hidden" name="my_exe_exo_id" value="' . $exercise_id . '"> ';
  770. } else {
  771. $formUrl = api_get_path(WEB_CODE_PATH) . 'exercise/exercise_report.php?' . api_get_cidreq() . '&';
  772. $formUrl .= http_build_query([
  773. 'exerciseId' => $exercise_id,
  774. 'filter' => 1,
  775. 'comments' => 'update',
  776. 'exeid' => $id
  777. ]);
  778. echo ' <form name="myform" id="myform" action="' . $formUrl . '" method="post">';
  779. }
  780. if ($origin != 'learnpath' && $origin != 'student_progress') {
  781. echo '<label><input type= "checkbox" name="send_notification"> ' . get_lang('SendEmail') . '</label>';
  782. ?>
  783. <br/>
  784. <button type="submit" class="btn btn-primary" value="<?php echo get_lang('Ok'); ?>"
  785. onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');">
  786. <?php echo get_lang('CorrectTest'); ?>
  787. </button>
  788. </form>
  789. <?php
  790. }
  791. }
  792. //Came from lpstats in a lp
  793. if ($origin == 'student_progress') { ?>
  794. <button type="button" class="back" onclick="window.history.go(-1);" value="<?php echo get_lang('Back'); ?>">
  795. <?php echo get_lang('Back'); ?></button>
  796. <?php
  797. } else if ($origin == 'myprogress') {
  798. ?>
  799. <button type="button" class="save"
  800. onclick="top.location.href='../auth/my_progress.php?course=<?php echo api_get_course_id() ?>'"
  801. value="<?php echo get_lang('Finish'); ?>">
  802. <?php echo get_lang('Finish'); ?>
  803. </button>
  804. <?php
  805. }
  806. if ($origin != 'learnpath') {
  807. //we are not in learnpath tool
  808. Display::display_footer();
  809. } else {
  810. if (!isset($_GET['fb_type'])) {
  811. $lp_mode = $_SESSION['lp_mode'];
  812. $url = '../lp/lp_controller.php?' . api_get_cidreq() . '&';
  813. $url .= http_build_url([
  814. 'action' => 'view',
  815. 'lp_id' => $learnpath_id,
  816. 'lp_item_id' => $learnpath_item_id,
  817. 'exeId' => $exeId,
  818. 'fb_type' => $feedback_type
  819. ]);
  820. $href = ($lp_mode == 'fullscreen') ? ' window.opener.location.href="' . $url . '" ' : ' top.location.href="' . $url . '" ';
  821. echo '<script type="text/javascript">' . $href . '</script>';
  822. // Record the results in the learning path, using the SCORM interface (API)
  823. echo "<script>window.parent.API.void_save_asset('$totalScore', '$totalWeighting', 0, 'completed'); </script>";
  824. echo '</body></html>';
  825. } else {
  826. Display::display_normal_message(get_lang('ExerciseFinished') . ' ' . get_lang('ToContinueUseMenu'));
  827. echo '<br />';
  828. }
  829. }
  830. // Destroying the session
  831. Session::erase('questionList');
  832. unset ($questionList);
  833. Session::erase('exerciseResult');
  834. unset ($exerciseResult);