exercise_show.php 28 KB

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