exercise_show.php 25 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. /**
  4. * Shows the exercise results
  5. *
  6. * @package chamilo.exercise
  7. * @author Julio Montoya Armas Added switchable fill in blank option added
  8. * @version $Id: exercise_show.php 22256 2009-07-20 17:40:20Z ivantcholakov $
  9. * @package chamilo.exercise
  10. * @todo remove the debug code and use the general debug library
  11. * @todo small letters for table variables
  12. * */
  13. // name of the language file that needs to be included
  14. $language_file=array('exercice');
  15. // including additional libraries
  16. require_once 'exercise.class.php';
  17. require_once 'exercise.lib.php';
  18. require_once 'question.class.php'; //also defines answer type constants
  19. require_once 'answer.class.php';
  20. require_once '../inc/global.inc.php';
  21. require_once api_get_path(LIBRARY_PATH).'course.lib.php';
  22. require_once api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php';
  23. require_once api_get_path(LIBRARY_PATH).'mail.lib.inc.php';
  24. if ( empty ( $origin ) ) {
  25. $origin = $_REQUEST['origin'];
  26. }
  27. if ($origin == 'learnpath')
  28. api_protect_course_script();
  29. else
  30. api_protect_course_script(true);
  31. // Database table definitions
  32. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  33. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  34. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  35. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  36. $main_user_table = Database::get_main_table(TABLE_MAIN_USER);
  37. $main_course_user_table = Database::get_main_table(TABLE_MAIN_COURSE_USER);
  38. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  39. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  40. $dsp_percent = false;
  41. $debug=0;
  42. // General parameters passed via POST/GET
  43. if($debug>0) { error_log('Entered exercise_result.php: '.print_r($_POST,1)); }
  44. if ( empty ( $formSent ) ) { $formSent = $_REQUEST['formSent']; }
  45. if ( empty ( $exerciseResult ) ) { $exerciseResult = $_SESSION['exerciseResult'];}
  46. if ( empty ( $questionId ) ) { $questionId = $_REQUEST['questionId'];}
  47. if ( empty ( $choice ) ) { $choice = $_REQUEST['choice'];}
  48. if ( empty ( $questionNum ) ) { $questionNum = $_REQUEST['questionNum'];}
  49. if ( empty ( $nbrQuestions ) ) { $nbrQuestions = $_REQUEST['nbrQuestions'];}
  50. if ( empty ( $questionList ) ) { $questionList = $_SESSION['questionList'];}
  51. if ( empty ( $objExercise ) ) { $objExercise = $_SESSION['objExercise'];}
  52. if ( empty ( $exeId ) ) { $exeId = $_REQUEST['id'];}
  53. if ( empty ( $action ) ) { $action = $_REQUEST['action']; }
  54. //$emailId = $_REQUEST['email'];
  55. $id = intval($_REQUEST['id']); //exe id
  56. $current_time = time();
  57. if (empty($id)) {
  58. api_not_allowed();
  59. }
  60. $is_allowedToEdit = api_is_allowed_to_edit(null,true) || $is_courseTutor;
  61. //Getting results from the exe_id. This variable also contain all the information about the exercise
  62. $track_exercise_info = get_exercise_track_exercise_info($id);
  63. //No track info
  64. if (empty($track_exercise_info)) {
  65. api_not_allowed();
  66. }
  67. $exercise_id = $track_exercise_info['id'];
  68. $exercise_date = $track_exercise_info['exe_date'];
  69. $student_id = $track_exercise_info['exe_user_id'];
  70. $learnpath_id = $track_exercise_info['orig_lp_id'];
  71. $learnpath_item_id = $track_exercise_info['orig_lp_item_id'];
  72. $lp_item_view_id = $track_exercise_info['orig_lp_item_view_id'];
  73. $course_code = api_get_course_id();
  74. $current_user_id = api_get_user_id();
  75. if (empty($objExercise)) {
  76. $objExercise = new Exercise();
  77. $objExercise->read($exercise_id);
  78. }
  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. $nameTools=get_lang('CorrectTest');
  94. if (isset($_SESSION['gradebook'])) {
  95. $gradebook= Security::remove_XSS($_SESSION['gradebook']);
  96. }
  97. if (!empty($gradebook) && $gradebook=='view') {
  98. $interbreadcrumb[]= array ('url' => '../gradebook/'.$_SESSION['gradebook_dest'],'name' => get_lang('ToolGradebook'));
  99. }
  100. $fromlink = '';
  101. if($origin=='user_course') {
  102. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
  103. $interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=".$student_id."&course=".$_course['id']."&details=true&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("DetailsStudentInCourse"));
  104. } else if($origin=='tracking_course') {
  105. //$interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
  106. //$interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($student_id).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  107. $interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
  108. $interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$cidReq.'&studentlist=true&id_session='.$_SESSION['id_session'], "name" => get_lang("Tracking"));
  109. $interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".$student_id.'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  110. $interbreadcrumb[] = array ("url" => "../mySpace/lp_tracking.php?action=stats&course=".$cidReq."&student_id=".$student_id."&lp_id=".Security::remove_XSS($_GET['my_lp_id'])."&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("LearningPathDetails"));
  111. $from_myspace = false;
  112. if (isset ($_GET['from']) && $_GET['from'] == 'myspace') {
  113. $fromlink = '&from=myspace';
  114. $this_section = SECTION_TRACKING;
  115. } else {
  116. $this_section = SECTION_COURSES;
  117. }
  118. } elseif($origin=='student_progress') {
  119. $this_section = SECTION_TRACKING;
  120. $interbreadcrumb[] = array ("url" => "../auth/my_progress.php?id_session".Security::remove_XSS($_GET['id_session'])."&course=".$_cid, "name" => get_lang('MyProgress'));
  121. unset($_cid);
  122. } else {
  123. $interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  124. $this_section=SECTION_COURSES;
  125. }
  126. if ($origin != 'learnpath') {
  127. Display::display_header($nameTools,get_lang('Exercise'));
  128. } else {
  129. Display::display_reduced_header();
  130. }
  131. ?>
  132. <style type="text/css">
  133. <!--
  134. #comments {
  135. position:absolute;
  136. left:795px;
  137. top:0px;
  138. width:200px;
  139. height:75px;
  140. z-index:1;
  141. }
  142. -->
  143. </style>
  144. <script language="javascript">
  145. function showfck(sid,marksid) {
  146. document.getElementById(sid).style.display='block';
  147. document.getElementById(marksid).style.display='block';
  148. var comment = 'feedback_'+sid;
  149. document.getElementById(comment).style.display='none';
  150. }
  151. function getFCK(vals,marksid) {
  152. var f=document.getElementById('myform');
  153. var m_id = marksid.split(',');
  154. for(var i=0;i<m_id.length;i++){
  155. var oHidn = document.createElement("input");
  156. oHidn.type = "hidden";
  157. var selname = oHidn.name = "marks_"+m_id[i];
  158. var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
  159. oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
  160. f.appendChild(oHidn);
  161. }
  162. var ids = vals.split(',');
  163. for(var k=0;k<ids.length;k++){
  164. var oHidden = document.createElement("input");
  165. oHidden.type = "hidden";
  166. oHidden.name = "comments_"+ids[k];
  167. oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
  168. oHidden.value = oEditor.GetXHTML(true);
  169. f.appendChild(oHidden);
  170. }
  171. //f.submit();
  172. }
  173. </script>
  174. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  175. <tr>
  176. <td colspan="2">
  177. <?php
  178. $show_results = true;
  179. // Avoiding the "Score 0/0" message when the exe_id is not set
  180. if (!empty($track_exercise_info)) {
  181. $exerciseTitle = text_filter($track_exercise_info['title']);
  182. $exerciseDescription = $track_exercise_info['description'];
  183. // if the results_disabled of the Quiz is 1 when block the script
  184. $result_disabled = $track_exercise_info['results_disabled'];
  185. if (!(api_is_platform_admin() || api_is_course_admin()) ) {
  186. if ($result_disabled == 1) {
  187. //api_not_allowed();
  188. $show_results = false;
  189. //Display::display_warning_message(get_lang('CantViewResults'));
  190. if ($origin != 'learnpath') {
  191. Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
  192. echo '</td>
  193. </tr>
  194. </table>';
  195. }
  196. }
  197. }
  198. } else {
  199. Display::display_warning_message(get_lang('CantViewResults'));
  200. $show_results = false;
  201. echo '</td>
  202. </tr>
  203. </table>';
  204. }
  205. if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
  206. $show_results = false;
  207. }
  208. if ($show_results) {
  209. ?>
  210. <table width="100%">
  211. <tr>
  212. <td colspan="2">
  213. <h2><?php echo Display::return_icon('quiz_big.png', get_lang('Result')).' '.$exerciseTitle.' : '.get_lang('Result');?></h2>
  214. </td>
  215. </tr>
  216. <tr>
  217. <td style="font-weight:bold" width="80px"><?php echo '&nbsp;'.get_lang('User')?> : </td>
  218. <td>
  219. <?php
  220. $user_info = api_get_user_info($student_id);
  221. echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
  222. ?>
  223. </td>
  224. </tr>
  225. <tr>
  226. <td style="font-weight:bold" width="80px"><?php echo '&nbsp;'.get_lang('Date')?> : </td>
  227. <td>
  228. <?php
  229. echo api_get_local_time($exercise_date);
  230. ?>
  231. </td>
  232. </tr>
  233. <?php if (!empty($exerciseDescription)) { ?>
  234. <tr>
  235. <td style="font-weight:bold" width="10%" class="actions-message">
  236. <?php echo '&nbsp;'.get_lang("Description").' :'; ?>
  237. </td>
  238. <td width="90%">
  239. <?php echo $exerciseDescription; ?>
  240. </td>
  241. </tr>
  242. <?php } ?>
  243. </table>
  244. <br />
  245. </table>
  246. <?php
  247. $i=$totalScore=$totalWeighting=0;
  248. if($debug>0){error_log("ExerciseResult: ".print_r($exerciseResult,1)); error_log("QuestionList: ".print_r($questionList,1));}
  249. $arrques = array();
  250. $arrans = array();
  251. $user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($student_id)." ";
  252. $query = "SELECT attempts.question_id, answer from ".$TBL_TRACK_ATTEMPT." as attempts
  253. INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
  254. INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id AND quizz_rel_questions.question_id = attempts.question_id
  255. INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
  256. WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
  257. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  258. //GROUP BY questions.position, attempts.question_id";
  259. $result =Database::query($query);
  260. $questionList = array();
  261. $exerciseResult = array();
  262. while ($row = Database::fetch_array($result)) {
  263. $questionList[] = $row['question_id'];
  264. $exerciseResult[$row['question_id']] = $row['answer'];
  265. }
  266. //Fixing #2073 Fixing order of questions
  267. if (!empty($track_exercise_info['data_tracking']) && !empty($track_exercise_info['random']) ) {
  268. $tempquestionList = explode(',',$track_exercise_info['data_tracking']);
  269. if (is_array($tempquestionList) && count($tempquestionList) == count($questionList)) {
  270. $questionList = $tempquestionList;
  271. }
  272. }
  273. // for each question
  274. $counter=0;
  275. //var_dump($exerciseResult);
  276. foreach ($questionList as $questionId) {
  277. $counter++;
  278. $choice=$exerciseResult[$questionId];
  279. // creates a temporary Question object
  280. $objQuestionTmp = Question::read($questionId);
  281. $questionName = $objQuestionTmp->selectTitle();
  282. $questionDescription= $objQuestionTmp->selectDescription();
  283. $questionWeighting = $objQuestionTmp->selectWeighting();
  284. $answerType = $objQuestionTmp->selectType();
  285. $quesId = $objQuestionTmp->selectId(); //added by priya saini
  286. // destruction of the Question object
  287. unset($objQuestionTmp);
  288. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  289. $colspan=2;
  290. }
  291. if($answerType == MATCHING || $answerType == FREE_ANSWER) {
  292. $colspan=2;
  293. } else {
  294. $colspan=2;
  295. }
  296. echo '<div id="question_title" class="sectiontitle">';
  297. echo get_lang("Question").' '.($counter).' : '.$questionName;
  298. echo '</div>';
  299. echo '<div id="question_description">';
  300. echo $questionDescription;
  301. echo '</div>';
  302. if ($answerType == MULTIPLE_ANSWER) {
  303. ?>
  304. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  305. <tr>
  306. <td>&nbsp;</td>
  307. </tr>
  308. <tr>
  309. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  310. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  311. <td><i><?php echo get_lang("Answer"); ?></i></td>
  312. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  313. <td><i><?php echo get_lang("Comment"); ?></i></td>
  314. <?php } else { ?>
  315. <td>&nbsp;</td>
  316. <?php } ?>
  317. </tr>
  318. <tr>
  319. <td>&nbsp;</td>
  320. </tr>
  321. <?php
  322. // construction of the Answer object
  323. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  324. //var_dump($question_result);
  325. $questionScore = $question_result['score'];
  326. $totalScore += $question_result['score'];
  327. echo '</table>';
  328. } elseif ($answerType == MULTIPLE_ANSWER_COMBINATION) {
  329. $choice=array();
  330. ?>
  331. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  332. <tr>
  333. <td>&nbsp;</td>
  334. </tr>
  335. <tr>
  336. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  337. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  338. <td><i><?php echo get_lang("Answer"); ?></i></td>
  339. <td><i><?php echo get_lang("Comment"); ?></i></td>
  340. </tr>
  341. <tr>
  342. <td>&nbsp;</td>
  343. </tr>
  344. <?php
  345. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  346. $questionScore = $question_result['score'];
  347. $totalScore += $question_result['score'];
  348. echo '</table>';
  349. } elseif ($answerType == UNIQUE_ANSWER) {
  350. ?>
  351. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  352. <tr>
  353. <td>&nbsp;</td>
  354. </tr>
  355. <tr>
  356. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  357. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  358. <td><i><?php echo get_lang("Answer"); ?></i></td>
  359. <?php if ($feedback_type != EXERCISE_FEEDBACK_TYPE_EXAM) { ?>
  360. <td><i><?php echo get_lang("Comment"); ?></i></td>
  361. <?php } else { ?>
  362. <td>&nbsp;</td>
  363. <?php } ?>
  364. </tr>
  365. <tr>
  366. <td>&nbsp;</td>
  367. </tr>
  368. <?php
  369. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  370. $questionScore = $question_result['score'];
  371. $totalScore += $question_result['score'];
  372. echo '</table>';
  373. } elseif ($answerType == FILL_IN_BLANKS) {
  374. ?>
  375. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  376. <tr>
  377. <td>&nbsp;</td>
  378. </tr>
  379. <tr>
  380. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  381. </tr>
  382. <tr>
  383. <td>&nbsp;</td>
  384. </tr>
  385. <?php
  386. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  387. $questionScore = $question_result['score'];
  388. $totalScore += $question_result['score'];
  389. echo '</table>';
  390. } elseif ($answerType == FREE_ANSWER) {
  391. $answer = $str;
  392. ?>
  393. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  394. <tr>
  395. <td>&nbsp;</td>
  396. </tr>
  397. <tr>
  398. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  399. </tr>
  400. <tr>
  401. <td>&nbsp;</td>
  402. </tr>
  403. <?php
  404. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  405. $questionScore = $question_result['score'];
  406. $totalScore += $question_result['score'];
  407. } elseif ($answerType == MATCHING) {
  408. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  409. $questionScore = $question_result['score'];
  410. $totalScore += $question_result['score'];
  411. echo '</table>';
  412. } elseif ($answerType == HOT_SPOT) {
  413. echo '<table width="500" border="0">
  414. <tr>
  415. <td valign="top" align="center" style="padding-left:0px;" >
  416. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">';
  417. $question_result = $objExercise->manage_answer($id, $questionId, $choice,'exercise_show', false, true);
  418. $questionScore = $question_result['score'];
  419. $totalScore += $question_result['score'];
  420. echo '</table></td></tr>';
  421. echo '<tr>
  422. <td colspan="2">'.
  423. '<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">
  424. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  425. </object>
  426. </td>
  427. </tr>
  428. </table><br/>';
  429. }
  430. echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
  431. if ($is_allowedToEdit) {
  432. echo '<tr><td>';
  433. $name = "fckdiv".$questionId;
  434. $marksname = "marksName".$questionId;
  435. ?>
  436. <br />
  437. <a href="javascript://" onclick="showfck('<?php echo $name; ?>','<?php echo $marksname; ?>');">
  438. <?php
  439. if ($answerType == FREE_ANSWER) {
  440. echo get_lang('EditCommentsAndMarks');
  441. } else {
  442. if ($action=='edit') {
  443. echo '<img src="../img/edit.gif"/>'.get_lang('EditIndividualComment');
  444. } else {
  445. echo get_lang('AddComments');
  446. }
  447. }
  448. echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
  449. $comnt = trim(get_comments($id,$questionId));
  450. if (empty($comnt)) {
  451. echo '<br />';
  452. } else {
  453. echo '<div id="question_feedback">'.$comnt.'</div>';
  454. }
  455. echo '</div><div id="'.$name.'" style="display:none">';
  456. $arrid[] = $questionId;
  457. $feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
  458. $feedback_form->addElement('html','<br>');
  459. $renderer =& $feedback_form->defaultRenderer();
  460. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  461. $renderer->setElementTemplate('<div align="left">{element}</div>');
  462. $comnt = get_comments($id,$questionId);
  463. ${user.$questionId}['comments_'.$questionId] = $comnt;
  464. $feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
  465. $feedback_form->addElement('html','<br>');
  466. //$feedback_form->addElement('submit','submitQuestion',get_lang('Ok'));
  467. $feedback_form->setDefaults(${user.$questionId});
  468. $feedback_form->display();
  469. echo '</div>';
  470. } else {
  471. $comnt = get_comments($id,$questionId);
  472. echo '<tr><td><br />';
  473. if (!empty($comnt)) {
  474. echo '<b>'.get_lang('Feedback').'</b>';
  475. echo '<div id="question_feedback">'.$comnt.'</div>';
  476. }
  477. echo '</td><td>';
  478. }
  479. if ($is_allowedToEdit) {
  480. if ($answerType == FREE_ANSWER) {
  481. $marksname = "marksName".$questionId;
  482. ?>
  483. <div id="<?php echo $marksname; ?>" style="display:none">
  484. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  485. <?php
  486. $arrmarks[] = $questionId;
  487. echo get_lang("AssignMarks");
  488. echo "&nbsp;<select name='marks' id='marks'>";
  489. for ($i=0;$i<=$questionWeighting;$i++) {
  490. echo '<option '.(($i==$questionScore)?"selected='selected'":'').'>'.$i.'</option>';
  491. }
  492. echo '</select>';
  493. echo '</form><br/ ></div>';
  494. if ($questionScore==-1 ) {
  495. $questionScore=0;
  496. echo '<br />'.get_lang('notCorrectedYet');
  497. }
  498. } else {
  499. $arrmarks[] = $questionId;
  500. echo '<div id="'.$marksname.'" style="display:none"><form name="marksform_'.$questionId.'" method="post" action="">
  501. <select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form><br/ ></div>';
  502. }
  503. } else {
  504. if ($questionScore==-1) {
  505. $questionScore=0;
  506. }
  507. }
  508. ?>
  509. </td>
  510. </tr>
  511. </table>
  512. <?php
  513. $my_total_score = float_format($questionScore,1);
  514. $my_total_weight = float_format($questionWeighting,1);
  515. echo '<div id="question_score">';
  516. echo get_lang('Score')." : $my_total_score/$my_total_weight";
  517. echo '</div>';
  518. unset($objAnswerTmp);
  519. $i++;
  520. $totalWeighting+=$questionWeighting;
  521. } // end of large foreach on questions
  522. } //end of condition if $show_results
  523. if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  524. //$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
  525. //Database::query($query);
  526. if ($show_results) {
  527. echo '<div id="question_score">'.get_lang('YourTotalScore')." ";
  528. if ($dsp_percent) {
  529. $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
  530. $my_result = float_format($my_result,1);
  531. echo $my_result."%";
  532. } else {
  533. $my_total_score = float_format($totalScore,1);
  534. $my_total_weight = float_format($totalWeighting,1);
  535. echo $my_total_score."/".$my_total_weight;
  536. }
  537. echo '</div>';
  538. }
  539. }
  540. if (is_array($arrid) && is_array($arrmarks)) {
  541. $strids = implode(",",$arrid);
  542. $marksid = implode(",",$arrmarks);
  543. }
  544. if ($is_allowedToEdit) {
  545. if (in_array($origin, array('tracking_course','user_course','correct_exercise_in_lp'))) {
  546. echo ' <form name="myform" id="myform" action="exercice.php?show=result&filter=2&comments=update&exeid='.$id.'&origin='.$origin.'&details=true&course='.Security::remove_XSS($_GET['cidReq']).$fromlink.'" method="post">';
  547. echo ' <input type = "hidden" name="totalWeighting" value="'.$totalWeighting.'">';
  548. echo '<input type = "hidden" name="lp_item_id" value="'.$lp_id.'">';
  549. echo '<input type = "hidden" name="lp_item_view_id" value="'.$lp_item_view_id.'">';
  550. echo '<input type = "hidden" name="student_id" value="'.$student_id.'">';
  551. echo '<input type = "hidden" name="total_score" value="'.$totalScore.'"> ';
  552. echo '<input type = "hidden" name="my_exe_exo_id" value="'.$exercise_id.'"> ';
  553. } else {
  554. echo ' <form name="myform" id="myform" action="exercice.php?show=result&action=qualify&filter=2&comments=update&exeid='.$id.'&totalWeighting='.$totalWeighting.'" method="post">';
  555. }
  556. if ($origin!='learnpath' && $origin!='student_progress') {
  557. ?>
  558. <button type="submit" class="save" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"><?php echo get_lang('FinishTest'); ?></button>
  559. </form>
  560. <?php
  561. }
  562. }
  563. //Came from lpstats in a lp
  564. if ($origin =='student_progress') {?>
  565. <button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back');?></button>
  566. <?php
  567. } else if($origin=='myprogress') {
  568. ?>
  569. <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'); ?>" ><?php echo get_lang('Finish');?></button>
  570. <?php
  571. }
  572. if ($origin != 'learnpath') {
  573. //we are not in learnpath tool
  574. Display::display_footer();
  575. } else {
  576. if (!isset($_GET['fb_type'])) {
  577. $lp_mode = $_SESSION['lp_mode'];
  578. $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;
  579. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  580. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  581. //record the results in the learning path, using the SCORM interface (API)
  582. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  583. echo '</body></html>';
  584. } else {
  585. if (!$is_allowedToEdit) {
  586. $objExercise->send_notification($arrques, $arrans);
  587. }
  588. Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
  589. echo '<br />';
  590. }
  591. }
  592. if (!$is_allowedToEdit) {
  593. if ($origin != 'learnpath') {
  594. $objExercise->send_notification($arrques, $arrans);
  595. }
  596. }
  597. //destroying the session
  598. api_session_unregister('questionList');
  599. unset ($questionList);
  600. api_session_unregister('exerciseResult');
  601. unset ($exerciseResult);