exercise_show.php 40 KB

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