exercise_show.php 30 KB

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