exercise_show.php 33 KB

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