exercise_show.php 28 KB

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