exercise_show.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123
  1. <?php //$id: $
  2. /* For licensing terms, see /dokeos_license.txt */
  3. /**
  4. *
  5. * @package dokeos.exercise
  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. *
  9. * @todo remove the debug code and use the general debug library
  10. * @todo use the Database:: functions
  11. * @todo small letters for table variables
  12. */
  13. // name of the language file that needs to be included
  14. $language_file=array('exercice','tracking');
  15. // including the global dokeos file
  16. include_once '../inc/global.inc.php';
  17. include_once '../inc/lib/course.lib.php';
  18. // including additional libraries
  19. include_once 'exercise.class.php';
  20. include_once 'question.class.php'; //also defines answer type constants
  21. include_once 'answer.class.php';
  22. include_once(api_get_path(LIBRARY_PATH).'formvalidator/FormValidator.class.php');
  23. if ( empty ( $origin ) ) {
  24. $origin = $_REQUEST['origin'];
  25. }
  26. if ($origin == 'learnpath')
  27. api_protect_course_script();
  28. else
  29. api_protect_course_script(true);
  30. // Database table definitions
  31. $TBL_EXERCICE_QUESTION = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  32. $TBL_EXERCICES = Database::get_course_table(TABLE_QUIZ_TEST);
  33. $TBL_QUESTIONS = Database::get_course_table(TABLE_QUIZ_QUESTION);
  34. $TBL_REPONSES = Database::get_course_table(TABLE_QUIZ_ANSWER);
  35. $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
  36. $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  37. $TBL_TRACK_EXERCICES = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  38. $TBL_TRACK_ATTEMPT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  39. $dsp_percent = false;
  40. $debug=0;
  41. if($debug>0) {
  42. echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);
  43. }
  44. // general parameters passed via POST/GET
  45. if ( empty ( $learnpath_id ) ) {
  46. $learnpath_id = $_REQUEST['learnpath_id'];
  47. }
  48. if ( empty ( $learnpath_item_id ) ) {
  49. $learnpath_item_id = $_REQUEST['learnpath_item_id'];
  50. }
  51. if ( empty ( $formSent ) ) {
  52. $formSent= $_REQUEST['formSent'];
  53. }
  54. if ( empty ( $exerciseResult ) ) {
  55. $exerciseResult = $_SESSION['exerciseResult'];
  56. }
  57. if ( empty ( $questionId ) ) {
  58. $questionId = $_REQUEST['questionId'];
  59. }
  60. if ( empty ( $choice ) ) {
  61. $choice = $_REQUEST['choice'];
  62. }
  63. if ( empty ( $questionNum ) ) {
  64. $questionNum = $_REQUEST['questionNum'];
  65. }
  66. if ( empty ( $nbrQuestions ) ) {
  67. $nbrQuestions = $_REQUEST['nbrQuestions'];
  68. }
  69. if ( empty ( $questionList ) ) {
  70. $questionList = $_SESSION['questionList'];
  71. }
  72. if ( empty ( $objExercise ) ) {
  73. $objExercise = $_SESSION['objExercise'];
  74. }
  75. if ( empty ( $exeId ) ) {
  76. $exeId = $_REQUEST['id'];
  77. }
  78. if ( empty ( $action ) ) {
  79. $action = $_GET['action'];
  80. }
  81. $current_user_id = api_get_user_id();
  82. $current_user_id = "'".$current_user_id."'";
  83. $current_attempt = $_SESSION['current_exercice_attempt'][$current_user_id];
  84. //Is fraudulent exercice
  85. $current_time = time();
  86. if (isset($_SESSION['expired_time'])) { //Only for exercice of type "One page"
  87. $expired_date = $_SESSION['expired_time'];
  88. $expired_time = strtotime($expired_date);
  89. //Validation in case of fraud
  90. $total_time_allowed = $expired_time + 30;
  91. if ($total_time_allowed < $current_time) {
  92. $sql_fraud = "UPDATE $TBL_TRACK_ATTEMPT SET answer = 0, marks=0, position=0 WHERE exe_id = '$current_attempt' ";
  93. Database::query($sql_fraud,__FILE__,__LINE__);
  94. }
  95. }
  96. //Unset session for clock time
  97. unset($_SESSION['current_exercice_attempt'][$current_user_id]);
  98. unset($_SESSION['expired_time']);
  99. unset($_SESSION['end_expired_time']);
  100. $is_allowedToEdit=api_is_allowed_to_edit(null,true) || $is_courseTutor;
  101. $nameTools=get_lang('CorrectTest');
  102. if (isset($_SESSION['gradebook'])){
  103. $gradebook= $_SESSION['gradebook'];
  104. }
  105. if (!empty($gradebook) && $gradebook=='view') {
  106. $interbreadcrumb[]= array (
  107. 'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
  108. 'name' => get_lang('Gradebook')
  109. );
  110. }
  111. $fromlink = '';
  112. if($origin=='user_course') {
  113. $interbreadcrumb[] = array ("url" => "../user/user.php?cidReq=".Security::remove_XSS($_GET['course']), "name" => get_lang("Users"));
  114. $interbreadcrumb[] = array("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student'])."&course=".$_course['id']."&details=true&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("DetailsStudentInCourse"));
  115. } else if($origin=='tracking_course') {
  116. //$interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
  117. //$interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student']).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  118. $interbreadcrumb[] = array ("url" => api_get_path(WEB_COURSE_PATH).$_course['directory'], 'name' => $_course['title']);
  119. $interbreadcrumb[] = array ("url" => "../tracking/courseLog.php?cidReq=".$cidReq.'&studentlist=true&id_session='.$_SESSION['id_session'], "name" => get_lang("Tracking"));
  120. $interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".Security::remove_XSS($_GET['student']).'&details=true&origin='.$origin.'&course='.Security::remove_XSS($_GET['cidReq']), "name" => get_lang("DetailsStudentInCourse"));
  121. $interbreadcrumb[] = array ("url" => "../mySpace/lp_tracking.php?action=stats&course=".$cidReq."&student_id=".Security::remove_XSS($_GET['student'])."&lp_id=".$_GET['my_lp_id']."&origin=".Security::remove_XSS($_GET['origin']) , "name" => get_lang("LearningPathDetails"));
  122. $from_myspace = false;
  123. if (isset ($_GET['from']) && $_GET['from'] == 'myspace') {
  124. $fromlink = '&from=myspace';
  125. $this_section = "session_my_space";
  126. } else {
  127. $this_section = SECTION_COURSES;
  128. }
  129. } else if($origin=='student_progress') {
  130. $interbreadcrumb[] = array ("url" => "../auth/my_progress.php?id_session".Security::remove_XSS($_GET['id_session'])."&course=".$_cid, "name" => get_lang('MyProgress'));
  131. unset($_cid);
  132. } else {
  133. $interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
  134. $this_section=SECTION_COURSES;
  135. }
  136. if ($origin != 'learnpath') {
  137. Display::display_header($nameTools,"Exercise");
  138. } else {
  139. Display::display_reduced_header();
  140. }
  141. $emailId = $_REQUEST['email'];
  142. $user_name = $_REQUEST['user'];
  143. $test = $_REQUEST['test'];
  144. $dt = $_REQUEST['dt'];
  145. $marks = $_REQUEST['res'];
  146. $id = $_REQUEST['id'];
  147. $sql_fb_type='SELECT feedback_type FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
  148. $res_fb_type=Database::query($sql_fb_type,__FILE__,__LINE__);
  149. $row_fb_type=Database::fetch_row($res_fb_type);
  150. $feedback_type = $row_fb_type[0];
  151. ?>
  152. <style type="text/css">
  153. <!--
  154. #comments {
  155. position:absolute;
  156. left:795px;
  157. top:0px;
  158. width:200px;
  159. height:75px;
  160. z-index:1;
  161. }
  162. -->
  163. </style>
  164. <script language="javascript">
  165. function showfck(sid,marksid)
  166. {
  167. document.getElementById(sid).style.display='block';
  168. document.getElementById(marksid).style.display='block';
  169. var comment = 'feedback_'+sid;
  170. document.getElementById(comment).style.display='none';
  171. }
  172. function getFCK(vals,marksid)
  173. {
  174. var f=document.getElementById('myform');
  175. var m_id = marksid.split(',');
  176. for(var i=0;i<m_id.length;i++){
  177. var oHidn = document.createElement("input");
  178. oHidn.type = "hidden";
  179. var selname = oHidn.name = "marks_"+m_id[i];
  180. var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
  181. oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
  182. f.appendChild(oHidn);
  183. }
  184. var ids = vals.split(',');
  185. for(var k=0;k<ids.length;k++){
  186. var oHidden = document.createElement("input");
  187. oHidden.type = "hidden";
  188. oHidden.name = "comments_"+ids[k];
  189. oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
  190. oHidden.value = oEditor.GetXHTML(true);
  191. f.appendChild(oHidden);
  192. }
  193. //f.submit();
  194. }
  195. </script>
  196. <?php
  197. /**
  198. * This function gets the comments of an exercise
  199. *
  200. * @param int $id
  201. * @param int $question_id
  202. * @return str the comment
  203. */
  204. function get_comments($id,$question_id)
  205. {
  206. global $TBL_TRACK_ATTEMPT;
  207. $sql = "SELECT teacher_comment FROM ".$TBL_TRACK_ATTEMPT." where exe_id='".Database::escape_string($id)."' and question_id = '".Database::escape_string($question_id)."' ORDER by question_id";
  208. $sqlres = Database::query($sql, __FILE__, __LINE__);
  209. $comm = Database::result($sqlres,0,"teacher_comment");
  210. return $comm;
  211. }
  212. /**
  213. * Display the answers to a multiple choice question
  214. *
  215. * @param integer Answer type
  216. * @param integer Student choice
  217. * @param string Textual answer
  218. * @param string Comment on answer
  219. * @param string Correct answer comment
  220. * @param integer Exercise ID
  221. * @param integer Question ID
  222. * @param boolean Whether to show the answer comment or not
  223. * @return void
  224. */
  225. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
  226. {
  227. ?>
  228. <tr>
  229. <td width="5%" align="center">
  230. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  231. border="0" alt="" />
  232. </td>
  233. <td width="5%" align="center">
  234. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  235. border="0" alt=" " />
  236. </td>
  237. <td width="40%" style="border-bottom: 1px solid #4171B5;">
  238. <?php
  239. $answer=api_parse_tex($answer);
  240. echo $answer;
  241. ?>
  242. </td>
  243. <td width="20%" style="border-bottom: 1px solid #4171B5;">
  244. <?php
  245. $answerComment=api_parse_tex($answerComment);
  246. if($studentChoice)
  247. {
  248. if(!$answerCorrect)
  249. {
  250. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  251. }
  252. else{
  253. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  254. }
  255. }
  256. else
  257. {
  258. echo '&nbsp;';
  259. }
  260. ?>
  261. </td>
  262. <?php
  263. if ($ans==1) {
  264. $comm = get_comments($id,$questionId);
  265. }
  266. ?>
  267. </tr>
  268. <?php
  269. }
  270. /**
  271. * Shows the answer to a fill-in-the-blanks question, as HTML
  272. * @param string Answer text
  273. * @param int Exercise ID
  274. * @param int Question ID
  275. * @return void
  276. */
  277. function display_fill_in_blanks_answer($answer,$id,$questionId)
  278. {
  279. ?>
  280. <tr>
  281. <td>
  282. <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
  283. </td><?php
  284. if(!api_is_allowed_to_edit(null,true)) {?>
  285. <td>
  286. <?php
  287. $comm = get_comments($id,$questionId);
  288. ?>
  289. </td>
  290. </tr>
  291. <?php }
  292. }
  293. /**
  294. * Shows the answer to a free-answer question, as HTML
  295. * @param string Answer text
  296. * @param int Exercise ID
  297. * @param int Question ID
  298. * @return void
  299. */
  300. function display_free_answer($answer,$id,$questionId) {
  301. ?>
  302. <tr>
  303. <td>
  304. <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
  305. </td> <?php if(!api_is_allowed_to_edit(null,true)) {?>
  306. <td>
  307. <?php
  308. $comm = get_comments($id,$questionId);
  309. ?>
  310. </td>
  311. <?php }?>
  312. </tr>
  313. <?php
  314. }
  315. /**
  316. * Displays the answer to a hotspot question
  317. *
  318. * @param int $answerId
  319. * @param string $answer
  320. * @param string $studentChoice
  321. * @param string $answerComment
  322. */
  323. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment) {
  324. //global $hotspot_colors;
  325. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  326. "#4271B5",
  327. "#FE8E16",
  328. "#3B3B3B",
  329. "#BCD631",
  330. "#D63173",
  331. "#D7D7D7",
  332. "#90AFDD",
  333. "#AF8640",
  334. "#4F9242",
  335. "#F4EB24",
  336. "#ED2024",
  337. "#45C7F0",
  338. "#F7BDE2");
  339. ?>
  340. <tr>
  341. <td width="100px" valign="top" align="left">
  342. <div style="width:100%;">
  343. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
  344. <div style="float:left; padding-left:5px;">
  345. <?php echo $answerId; ?>
  346. </div>
  347. <div><?php echo '&nbsp;'.$answer ?></div>
  348. </div>
  349. </td>
  350. <td width="50px" style="padding-right:15px" valign="top" align="left">
  351. <?php
  352. $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $my_choice; ?>
  353. </td>
  354. <td valign="top" align="left" >
  355. <?php
  356. $answerComment=api_parse_tex($answerComment);
  357. if($studentChoice) {
  358. echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
  359. } else {
  360. echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
  361. }
  362. ?>
  363. </td>
  364. </tr>
  365. <?php
  366. }
  367. /*
  368. ==============================================================================
  369. MAIN CODE
  370. ==============================================================================
  371. */
  372. ?>
  373. <table width="100%" border="0" cellspacing="0" cellpadding="0">
  374. <tr>
  375. <td colspan="2">
  376. <?php
  377. $sql_test_name='SELECT title, description, results_disabled FROM '.$TBL_EXERCICES.' as exercises, '.$TBL_TRACK_EXERCICES.' as track_exercises WHERE exercises.id=track_exercises.exe_exo_id AND track_exercises.exe_id="'.Database::escape_string($id).'"';
  378. $result=Database::query($sql_test_name);
  379. $show_results = true;
  380. // Avoiding the "Score 0/0" message when the exe_id is not set
  381. if (Database::num_rows($result)>0 && isset($id)) {
  382. $test=Database::result($result,0,0);
  383. $exerciseTitle=api_parse_tex($test);
  384. $exerciseDescription=Database::result($result,0,1);
  385. // if the results_disabled of the Quiz is 1 when block the script
  386. $result_disabled=Database::result($result,0,2);
  387. if (!(api_is_platform_admin() || api_is_course_admin()) ) {
  388. if ($result_disabled==1) {
  389. //api_not_allowed();
  390. $show_results = false;
  391. //Display::display_warning_message(get_lang('CantViewResults'));
  392. if ($origin!='learnpath') {
  393. Display::display_warning_message(get_lang('ThankYouForPassingTheTest').'<br /><br /><a href="exercice.php">'.(get_lang('BackToExercisesList')).'</a>', false);
  394. echo '</td>
  395. </tr>
  396. </table>';
  397. }
  398. }
  399. }
  400. if ($show_results == true) {
  401. $user_restriction = $is_allowedToEdit ? '' : "AND user_id=".intval($_user['user_id'])." ";
  402. $query = "SELECT attempts.question_id, answer from ".$TBL_TRACK_ATTEMPT." as attempts
  403. INNER JOIN ".$TBL_TRACK_EXERCICES." as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
  404. 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
  405. INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
  406. WHERE attempts.exe_id='".Database::escape_string($id)."' $user_restriction
  407. GROUP BY quizz_rel_questions.question_order, attempts.question_id";
  408. //GROUP BY questions.position, attempts.question_id";
  409. $result =Database::query($query, __FILE__, __LINE__);
  410. }
  411. } else {
  412. Display::display_warning_message(get_lang('CantViewResults'));
  413. $show_results = false;
  414. echo '</td>
  415. </tr>
  416. </table>';
  417. }
  418. if ($origin == 'learnpath' && !isset($_GET['fb_type']) ) {
  419. $show_results = false;
  420. }
  421. if ($show_results == true ) {
  422. ?>
  423. <table width="100%">
  424. <tr>
  425. <td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('CourseTitle')?> : </div></td>
  426. <td><div class="actions-message" width="90%"><?php echo $_course['name'] ?></div></td>
  427. </tr>
  428. <tr>
  429. <td style="font-weight:bold" width="10%"><div class="actions-message"><?php echo '&nbsp;'.get_lang('User')?> : </div></td>
  430. <td><div class="actions-message" width="90%"><?php
  431. if (isset($_GET['cidReq'])) {
  432. $course_code=Security::remove_XSS($_GET['cidReq']);
  433. } else {
  434. $course_code=api_get_course_id();
  435. }
  436. if (isset($_GET['student'])) {
  437. $user_id=Security::remove_XSS($_GET['student']);
  438. }else {
  439. $user_id=api_get_user_id();
  440. }
  441. $status_info=CourseManager::get_user_in_course_status($user_id,$course_code);
  442. if (STUDENT==$status_info) {
  443. $user_info=api_get_user_info($user_id);
  444. echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
  445. } elseif(COURSEMANAGER==$status_info && !isset($_GET['user'])) {
  446. $user_info=api_get_user_info($user_id);
  447. echo api_get_person_name($user_info['firstName'], $user_info['lastName']);
  448. } else {
  449. echo $user_name;
  450. }
  451. ?></div></td>
  452. </tr>
  453. <tr>
  454. <td style="font-weight:bold" width="10%" class="actions-message">
  455. <?php echo '&nbsp;'.get_lang("Exercise").' :'; ?>
  456. </td>
  457. <td width="90%">
  458. <?php echo $test; ?><br />
  459. <?php echo $exerciseDescription; ?>
  460. </td>
  461. </tr>
  462. </table>
  463. <br />
  464. </table>
  465. <?php
  466. }
  467. $i=$totalScore=$totalWeighting=0;
  468. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  469. if ($show_results) {
  470. $questionList = array();
  471. $exerciseResult = array();
  472. $k=0;
  473. $counter=0;
  474. while ($row = Database::fetch_array($result)) {
  475. $questionList[] = $row['question_id'];
  476. $exerciseResult[] = $row['answer'];
  477. }
  478. // for each question
  479. foreach($questionList as $questionId) {
  480. $counter++;
  481. $k++;
  482. $choice=$exerciseResult[$questionId];
  483. // creates a temporary Question object
  484. $objQuestionTmp = Question::read($questionId);
  485. $questionName=$objQuestionTmp->selectTitle();
  486. $questionDescription=$objQuestionTmp->selectDescription();
  487. $questionWeighting=$objQuestionTmp->selectWeighting();
  488. $answerType=$objQuestionTmp->selectType();
  489. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  490. // destruction of the Question object
  491. unset($objQuestionTmp);
  492. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
  493. $colspan=2;
  494. }
  495. if($answerType == MATCHING || $answerType == FREE_ANSWER) {
  496. $colspan=2;
  497. } else {
  498. $colspan=2;
  499. }
  500. ?>
  501. <div id="question_title" class="sectiontitle">
  502. <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
  503. </div>
  504. <div id="question_description">
  505. <?php echo $questionDescription; ?>
  506. </div>
  507. <?php
  508. if ($answerType == MULTIPLE_ANSWER) {
  509. $choice=array();
  510. ?>
  511. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  512. <tr>
  513. <td>&nbsp;</td>
  514. </tr>
  515. <tr>
  516. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  517. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  518. <td><i><?php echo get_lang("Answer"); ?></i></td>
  519. <td><i><?php echo get_lang("Comment"); ?></i></td>
  520. </tr>
  521. <tr>
  522. <td>&nbsp;</td>
  523. </tr>
  524. <?php
  525. // construction of the Answer object
  526. $objAnswerTmp=new Answer($questionId);
  527. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  528. $questionScore=0;
  529. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  530. $answer=$objAnswerTmp->selectAnswer($answerId);
  531. $answerComment=$objAnswerTmp->selectComment($answerId);
  532. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  533. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  534. $queryans = "select * from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  535. $resultans = Database::query($queryans, __FILE__, __LINE__);
  536. while ($row = Database::fetch_array($resultans)) {
  537. $ind = $row['answer'];
  538. $choice[$ind] = 1;
  539. }
  540. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  541. $studentChoice=$choice[$numAnswer];
  542. if ($studentChoice) {
  543. $questionScore+=$answerWeighting;
  544. $totalScore+=$answerWeighting;
  545. }
  546. echo '<tr><td>';
  547. if ($answerId==1) {
  548. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  549. } else {
  550. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  551. }
  552. echo '</td></tr>';
  553. $i++;
  554. }
  555. echo '</table>';
  556. } elseif ($answerType == UNIQUE_ANSWER) {
  557. ?>
  558. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  559. <tr>
  560. <td>&nbsp;</td>
  561. </tr>
  562. <tr>
  563. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  564. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  565. <td><i><?php echo get_lang("Answer"); ?></i></td>
  566. <td><i><?php echo get_lang("Comment"); ?></i></td>
  567. </tr>
  568. <tr>
  569. <td>&nbsp;</td>
  570. </tr>
  571. <?php
  572. $objAnswerTmp=new Answer($questionId);
  573. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  574. $questionScore=0;
  575. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  576. $answer=$objAnswerTmp->selectAnswer($answerId);
  577. $answerComment=$objAnswerTmp->selectComment($answerId);
  578. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  579. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  580. $queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  581. $resultans = Database::query($queryans, __FILE__, __LINE__);
  582. $choice = Database::result($resultans,0,"answer");
  583. $numAnswer=$objAnswerTmp->selectAutoId($answerId);
  584. $studentChoice=($choice == $numAnswer)?1:0;
  585. if ($studentChoice) {
  586. $questionScore+=$answerWeighting;
  587. $totalScore+=$answerWeighting;
  588. }
  589. echo '<tr><td>';
  590. if ($answerId==1) {
  591. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  592. } else {
  593. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  594. }
  595. echo '</td></tr>';
  596. $i++;
  597. }
  598. echo '</table>';
  599. } elseif ($answerType == FILL_IN_BLANKS) {
  600. ?>
  601. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  602. <tr>
  603. <td>&nbsp;</td>
  604. </tr>
  605. <tr>
  606. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  607. </tr>
  608. <tr>
  609. <td>&nbsp;</td>
  610. </tr>
  611. <?php
  612. $objAnswerTmp=new Answer($questionId);
  613. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  614. $questionScore=0;
  615. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  616. $answer = $objAnswerTmp->selectAnswer($answerId);
  617. $answerComment = $objAnswerTmp->selectComment($answerId);
  618. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  619. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  620. // the question is encoded like this
  621. // [A] B [C] D [E] F::10,10,10@1
  622. // number 1 before the "@" means that is a switchable fill in blank question
  623. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  624. // means that is a normal fill blank question
  625. $pre_array = explode('::', $answer);
  626. // is switchable fill blank or not
  627. $is_set_switchable = explode('@', $pre_array[1]);
  628. $switchable_answer_set=false;
  629. if ($is_set_switchable[1]==1) {
  630. $switchable_answer_set=true;
  631. }
  632. $answer = $pre_array[0];
  633. // splits weightings that are joined with a comma
  634. $answerWeighting = explode(',',$is_set_switchable[0]);
  635. //list($answer,$answerWeighting)=explode('::',$multiple[0]);
  636. //$answerWeighting=explode(',',$answerWeighting);
  637. // we save the answer because it will be modified
  638. $temp=$answer;
  639. // TeX parsing
  640. // 1. find everything between the [tex] and [/tex] tags
  641. $startlocations=api_strpos($temp,'[tex]');
  642. $endlocations=api_strpos($temp,'[/tex]');
  643. if ($startlocations !== false && $endlocations !== false) {
  644. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  645. // 2. replace this by {texcode}
  646. $temp=str_replace($texstring,'{texcode}',$temp);
  647. }
  648. $j=0;
  649. // the loop will stop at the end of the text
  650. $i=0;
  651. //normal fill in blank
  652. if (!$switchable_answer_set) {
  653. while (1) {
  654. // quits the loop if there are no more blanks
  655. if (($pos = api_strpos($temp,'[')) === false) {
  656. // adds the end of the text
  657. $answer.=$temp;
  658. // TeX parsing
  659. $texstring = api_parse_tex($texstring);
  660. break;
  661. }
  662. $temp=api_substr($temp,$pos+1);
  663. // quits the loop if there are no more blanks
  664. if (($pos = api_strpos($temp,']')) === false) {
  665. break;
  666. }
  667. $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  668. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  669. $str = Database::result($resfill,0,"answer");
  670. preg_match_all('#\[([^[]*)\]#', $str, $arr);
  671. $choice = $arr[1];
  672. $tmp=strrpos($choice[$j],' / ');
  673. $choice[$j]=substr($choice[$j],0,$tmp);
  674. $choice[$j]=trim($choice[$j]);
  675. // if the word entered by the student IS the same as the one defined by the professor
  676. if (api_strtolower(api_substr($temp,0,$pos)) == api_strtolower($choice[$j])) {
  677. // gives the related weighting to the student
  678. $questionScore+=$answerWeighting[$j];
  679. // increments total score
  680. $totalScore+=$answerWeighting[$j];
  681. }
  682. // else if the word entered by the student IS NOT the same as the one defined by the professor
  683. $j++;
  684. $temp=api_substr($temp,$pos+1);
  685. $i=$i+1;
  686. }
  687. $answer = stripslashes($str);
  688. $answer = str_replace('rn', '', $answer);
  689. } else {
  690. //multiple fill in blank
  691. while (1) {
  692. // quits the loop if there are no more blanks
  693. if (($pos = api_strpos($temp,'[')) === false) {
  694. // adds the end of the text
  695. $answer.=$temp;
  696. // TeX parsing
  697. $texstring = api_parse_tex($texstring);
  698. //$answer=str_replace("{texcode}",$texstring,$answer);
  699. break;
  700. }
  701. // adds the piece of text that is before the blank and ended by [
  702. $real_text[]=api_substr($temp,0,$pos+1);
  703. $answer.=api_substr($temp,0,$pos+1);
  704. $temp=api_substr($temp,$pos+1);
  705. // quits the loop if there are no more blanks
  706. if (($pos = api_strpos($temp,']')) === false) {
  707. // adds the end of the text
  708. //$answer.=$temp;
  709. break;
  710. }
  711. $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  712. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  713. $str=Database::result($resfill,0,"answer");
  714. preg_match_all ('#\[([^[/]*)/#', $str, $arr);
  715. $choice = $arr[1];
  716. $choice[$j]=trim($choice[$j]);
  717. $user_tags[]=api_strtolower($choice[$j]);
  718. $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
  719. $j++;
  720. $temp=api_substr($temp,$pos+1);
  721. $i=$i+1;
  722. }
  723. $answer='';
  724. for ($i=0;$i<count($correct_tags);$i++) {
  725. if (in_array($user_tags[$i],$correct_tags)) {
  726. // gives the related weighting to the student
  727. $questionScore+=$answerWeighting[$i];
  728. // increments total score
  729. $totalScore+=$answerWeighting[$i];
  730. }
  731. }
  732. $answer = stripslashes($str);
  733. $answer = str_replace('rn', '', $answer);
  734. }
  735. //echo $questionScore."-".$totalScore;
  736. echo '<tr><td>';
  737. display_fill_in_blanks_answer($answer,$id,$questionId);
  738. echo '</td></tr>';
  739. $i++;
  740. }
  741. echo '</table>';
  742. } elseif ($answerType == FREE_ANSWER) {$answer = $str;
  743. ?>
  744. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  745. <tr>
  746. <td>&nbsp;</td>
  747. </tr>
  748. <tr>
  749. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  750. </tr>
  751. <tr>
  752. <td>&nbsp;</td>
  753. </tr>
  754. <?php
  755. $objAnswerTmp = new Answer($questionId);
  756. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  757. $questionScore = 0;
  758. $query = "select answer, marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  759. $resq = Database::query($query);
  760. $choice = Database::result($resq,0,"answer");
  761. $choice = stripslashes($choice);
  762. $choice = str_replace('rn', '', $choice);
  763. $questionScore = Database::result($resq,0,"marks");
  764. if ($questionScore==-1) {
  765. $totalScore+=0;
  766. } else {
  767. $totalScore+=$questionScore;
  768. }
  769. echo '<tr>
  770. <td valign="top">'.display_free_answer($choice, $id, $questionId).'</td>
  771. </tr>
  772. </table>';
  773. } elseif ($answerType == MATCHING) {
  774. $objAnswerTmp=new Answer($questionId);
  775. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  776. $TBL_TRACK_ATTEMPT= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  777. $sql_answer = 'SELECT id, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0';
  778. $res_answer = Database::query($sql_answer, __FILE__, __LINE__);
  779. // getting the real answer
  780. $real_list =array();
  781. while ($real_answer = Database::fetch_array($res_answer)) {
  782. $real_list[$real_answer['id']]= $real_answer['answer'];
  783. }
  784. $sql_select_answer = 'SELECT id, answer, correct, id_auto FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct<>0';
  785. $res_answers = Database::query($sql_select_answer, __FILE__, __LINE__);
  786. echo '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
  787. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  788. echo '<tr>
  789. <td><span style="font-style: italic;">'.get_lang("ElementList").'</span> </td>
  790. <td><span style="font-style: italic;">'.get_lang("CorrespondsTo").'</span></td>
  791. </tr>';
  792. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  793. $questionScore=0;
  794. while ($a_answers = Database::fetch_array($res_answers)) {
  795. $i_answer_id = $a_answers['id']; //3
  796. $s_answer_label = $a_answers['answer']; // your dady - you mother
  797. $i_answer_correct_answer = $a_answers['correct']; //1 - 2
  798. $i_answer_id_auto = $a_answers['id_auto']; // 3 - 4
  799. $sql_user_answer = "SELECT answer
  800. FROM $TBL_TRACK_ATTEMPT
  801. WHERE exe_id = '$id' AND question_id = '$questionId' AND position='$i_answer_id_auto'";
  802. $res_user_answer = Database::query($sql_user_answer, __FILE__, __LINE__);
  803. if (Database::num_rows($res_user_answer)>0 ) {
  804. $s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking
  805. } else {
  806. $s_user_answer = 0;
  807. }
  808. $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
  809. $user_answer = '';
  810. if (!empty($s_user_answer)) {
  811. if ($s_user_answer == $i_answer_correct_answer) {
  812. $questionScore+=$i_answerWeighting;
  813. $totalScore+=$i_answerWeighting;
  814. $user_answer = '<span>'.$real_list[$i_answer_correct_answer].'</span>';
  815. } else {
  816. $user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$real_list[$s_user_answer].'</span>';
  817. }
  818. }
  819. echo '<tr>';
  820. echo '<td>'.$s_answer_label.'</td><td>'.$user_answer.' / <b><span style="color: #008000;">'.$real_list[$i_answer_correct_answer].'</span></b></td>';
  821. echo '</tr>';
  822. }
  823. echo '</table>';
  824. } elseif ($answerType == HOT_SPOT) {
  825. ?>
  826. <table width="500" border="0">
  827. <?php
  828. $objAnswerTmp=new Answer($questionId);
  829. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  830. $questionScore=0;
  831. ?>
  832. <tr>
  833. <td valign="top" align="center" style="padding-left:0px;" >
  834. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">
  835. <?php
  836. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  837. $answer=$objAnswerTmp->selectAnswer($answerId);
  838. $answerComment=$objAnswerTmp->selectComment($answerId);
  839. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  840. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  841. $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  842. $query = "select hotspot_correct from ".$TBL_TRACK_HOTSPOT." where hotspot_exe_id = '".Database::escape_string($id)."' and hotspot_question_id= '".Database::escape_string($questionId)."' AND hotspot_answer_id='".Database::escape_string($answerId)."'";
  843. $resq=Database::query($query);
  844. $choice = Database::result($resq,0,"hotspot_correct");
  845. display_hotspot_answer($answerId,$answer,$choice,$answerComment);
  846. $i++;
  847. }
  848. $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  849. $resfree = Database::query($queryfree, __FILE__, __LINE__);
  850. $questionScore= Database::result($resfree,0,"marks");
  851. $totalScore+=$questionScore;
  852. echo '</table></td></tr>';
  853. echo '<tr>
  854. <td colspan="2">'.
  855. //<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="421">
  856. '<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" width="552" height="352">
  857. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  858. </object>
  859. </td>
  860. </tr>
  861. </table><br/>';
  862. }
  863. echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
  864. if ($is_allowedToEdit) {
  865. echo '<tr><td>';
  866. $name = "fckdiv".$questionId;
  867. $marksname = "marksName".$questionId;
  868. ?>
  869. <br />
  870. <a href="javascript://" onclick="showfck('<?php echo $name; ?>','<?php echo $marksname; ?>');">
  871. <?php
  872. if ($answerType == FREE_ANSWER) {
  873. echo get_lang('EditCommentsAndMarks');
  874. } else {
  875. if ($action=='edit') {
  876. echo '<img src="../img/edit.gif"/>'.get_lang('EditIndividualComment');
  877. } else {
  878. echo get_lang('AddComments');
  879. }
  880. }
  881. echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
  882. $comnt = trim(get_comments($id,$questionId));
  883. if (empty($comnt)) {
  884. echo '<br />';
  885. } else {
  886. echo '<div id="question_feedback">'.$comnt.'</div>';
  887. }
  888. echo '</div><div id="'.$name.'" style="display:none">';
  889. $arrid[] = $questionId;
  890. $feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
  891. $feedback_form->addElement('html','<br>');
  892. $renderer =& $feedback_form->defaultRenderer();
  893. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  894. $renderer->setElementTemplate('<div align="left">{element}</div>');
  895. $comnt = get_comments($id,$questionId);
  896. ${user.$questionId}['comments_'.$questionId] = $comnt;
  897. $feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
  898. $feedback_form->addElement('html','<br>');
  899. //$feedback_form->addElement('submit','submitQuestion',get_lang('Ok'));
  900. $feedback_form->setDefaults(${user.$questionId});
  901. $feedback_form->display();
  902. echo '</div>';
  903. } else {
  904. $comnt = get_comments($id,$questionId);
  905. echo '<tr><td><br />';
  906. if (!empty($comnt)) {
  907. echo '<b>'.get_lang('Feedback').'</b>';
  908. echo '<div id="question_feedback">'.$comnt.'</div>';
  909. }
  910. echo '</td><td>';
  911. }
  912. if ($is_allowedToEdit) {
  913. if ($answerType == FREE_ANSWER) {
  914. $marksname = "marksName".$questionId;
  915. ?>
  916. <div id="<?php echo $marksname; ?>" style="display:none">
  917. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  918. <?php
  919. $arrmarks[] = $questionId;
  920. echo get_lang("AssignMarks");
  921. echo "&nbsp;<select name='marks' id='marks'>";
  922. for ($i=0;$i<=$questionWeighting;$i++) {
  923. echo '<option '.(($i==$questionScore)?"selected='selected'":'').'>'.$i.'</option>';
  924. }
  925. echo '</select>';
  926. echo '</form><br/ ></div>';
  927. if ($questionScore==-1) {
  928. $questionScore=0;
  929. echo '<br />'.get_lang('notCorrectedYet');
  930. }
  931. } else {
  932. $arrmarks[] = $questionId;
  933. echo '<div id="'.$marksname.'" style="display:none"><form name="marksform_'.$questionId.'" method="post" action="">
  934. <select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form><br/ ></div>';
  935. }
  936. } else {
  937. if ($questionScore==-1) {
  938. $questionScore=0;
  939. }
  940. }
  941. ?>
  942. </td>
  943. </tr>
  944. </table>
  945. <div id="question_score">
  946. <?php
  947. $my_total_score = float_format($questionScore,1);
  948. $my_total_weight = float_format($questionWeighting,1);
  949. echo get_lang('Score')." : $my_total_score/$my_total_weight";
  950. echo '</div>';
  951. unset($objAnswerTmp);
  952. $i++;
  953. $totalWeighting+=$questionWeighting;
  954. } // end of large foreach on questions
  955. } //end of condition if $show_results
  956. if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  957. //$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
  958. //Database::query($query,__FILE__,__LINE__);
  959. if ($show_results) {
  960. echo '<div id="question_score">'.get_lang('YourTotalScore')." ";
  961. if($dsp_percent == true) {
  962. $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
  963. $my_result = float_format($my_result,1);
  964. echo $my_result."%";
  965. } else {
  966. $my_total_score = float_format($totalScore,1);
  967. $my_total_weight = float_format($totalWeighting,1);
  968. echo $my_total_score."/".$my_total_weight;
  969. }
  970. echo '!</div>';
  971. }
  972. }
  973. if (is_array($arrid) && is_array($arrmarks)) {
  974. $strids = implode(",",$arrid);
  975. $marksid = implode(",",$arrmarks);
  976. }
  977. if ($is_allowedToEdit) {
  978. if (in_array($origin, array('tracking_course','user_course'))) {
  979. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.urlencode($test).'&emailid='.$emailId.'&origin='.$origin.'&student='.$_GET['student'].'&details=true&course='.$_GET['cidReq'].$fromlink.'" method="post">';
  980. echo ' <input type = "hidden" name="totalWeighting" value="'.$totalWeighting.'">';
  981. if (isset($_GET['myid']) && isset($_GET['my_lp_id']) && isset($_GET['student'])) {
  982. ?>
  983. <input type = "hidden" name="lp_item_id" value="<?php echo Security::remove_XSS($_GET['myid']); ?>">
  984. <input type = "hidden" name="lp_item_view_id" value="<?php echo Security::remove_XSS($_GET['my_lp_id']); ?>">
  985. <input type = "hidden" name="student_id" value="<?php echo Security::remove_XSS($_GET['student']);?>">
  986. <input type = "hidden" name="total_score" value="<?php echo $totalScore; ?>">
  987. <input type = "hidden" name="total_time" value="<?php echo Security::remove_XSS($_GET['total_time']);?>">
  988. <input type = "hidden" name="my_exe_exo_id" value="<?php echo Security::remove_XSS($_GET['my_exe_exo_id']); ?>">
  989. <?php
  990. }
  991. } else {
  992. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&totalWeighting='.$totalWeighting.'" method="post">';
  993. }
  994. if ($origin!='learnpath' && $origin!='student_progress') {
  995. ?>
  996. <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>
  997. </form>
  998. <?php
  999. }
  1000. }
  1001. if ($origin=='student_progress') {?>
  1002. <button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back');?></button>
  1003. <?php
  1004. } else if($origin=='myprogress') {
  1005. ?>
  1006. <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>
  1007. <?php
  1008. }
  1009. if ($origin != 'learnpath') {
  1010. //we are not in learnpath tool
  1011. Display::display_footer();
  1012. } else {
  1013. if (!isset($_GET['fb_type'])) {
  1014. $lp_mode = $_SESSION['lp_mode'];
  1015. $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
  1016. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  1017. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  1018. //record the results in the learning path, using the SCORM interface (API)
  1019. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  1020. echo '</body></html>';
  1021. } else {
  1022. Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
  1023. }
  1024. }
  1025. //destroying the session
  1026. api_session_unregister('questionList');
  1027. unset ($questionList);
  1028. api_session_unregister('exerciseResult');
  1029. unset ($exerciseResult);