exercise_show.php 36 KB

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