exercise_show.php 32 KB

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