exercise_show.php 30 KB

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