exercise_show.php 31 KB

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