exercise_show.php 37 KB

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