exercise_show.php 41 KB

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