exercise_show.php 31 KB

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