exercise_show.php 27 KB

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