exercise_show.php 41 KB

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