exercise_show.php 40 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126
  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. $studentChoice=$choice[$answerId];
  541. if ($studentChoice) {
  542. $questionScore+=$answerWeighting;
  543. $totalScore+=$answerWeighting;
  544. }
  545. echo '<tr><td>';
  546. if ($answerId==1) {
  547. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  548. } else {
  549. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  550. }
  551. echo '</td></tr>';
  552. $i++;
  553. }
  554. echo '</table>';
  555. } elseif ($answerType == UNIQUE_ANSWER) {
  556. ?>
  557. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  558. <tr>
  559. <td>&nbsp;</td>
  560. </tr>
  561. <tr>
  562. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  563. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  564. <td><i><?php echo get_lang("Answer"); ?></i></td>
  565. <td><i><?php echo get_lang("Comment"); ?></i></td>
  566. </tr>
  567. <tr>
  568. <td>&nbsp;</td>
  569. </tr>
  570. <?php
  571. $objAnswerTmp=new Answer($questionId);
  572. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  573. $questionScore=0;
  574. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  575. $answer=$objAnswerTmp->selectAnswer($answerId);
  576. $answerComment=$objAnswerTmp->selectComment($answerId);
  577. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  578. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  579. $queryans = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  580. $resultans = Database::query($queryans, __FILE__, __LINE__);
  581. $choice = Database::result($resultans,0,"answer");
  582. $studentChoice=($choice == $answerId)?1:0;
  583. if ($studentChoice) {
  584. $questionScore+=$answerWeighting;
  585. $totalScore+=$answerWeighting;
  586. }
  587. echo '<tr><td>';
  588. if ($answerId==1) {
  589. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  590. } else {
  591. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  592. }
  593. echo '</td></tr>';
  594. $i++;
  595. }
  596. echo '</table>';
  597. } elseif ($answerType == FILL_IN_BLANKS) {
  598. ?>
  599. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  600. <tr>
  601. <td>&nbsp;</td>
  602. </tr>
  603. <tr>
  604. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  605. </tr>
  606. <tr>
  607. <td>&nbsp;</td>
  608. </tr>
  609. <?php
  610. $objAnswerTmp=new Answer($questionId);
  611. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  612. $questionScore=0;
  613. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  614. $answer = $objAnswerTmp->selectAnswer($answerId);
  615. $answerComment = $objAnswerTmp->selectComment($answerId);
  616. $answerCorrect = $objAnswerTmp->isCorrect($answerId);
  617. $answerWeighting = $objAnswerTmp->selectWeighting($answerId);
  618. // the question is encoded like this
  619. // [A] B [C] D [E] F::10,10,10@1
  620. // number 1 before the "@" means that is a switchable fill in blank question
  621. // [A] B [C] D [E] F::10,10,10@ or [A] B [C] D [E] F::10,10,10
  622. // means that is a normal fill blank question
  623. $pre_array = explode('::', $answer);
  624. // is switchable fill blank or not
  625. $is_set_switchable = explode('@', $pre_array[1]);
  626. $switchable_answer_set=false;
  627. if ($is_set_switchable[1]==1) {
  628. $switchable_answer_set=true;
  629. }
  630. $answer = $pre_array[0];
  631. // splits weightings that are joined with a comma
  632. $answerWeighting = explode(',',$is_set_switchable[0]);
  633. //list($answer,$answerWeighting)=explode('::',$multiple[0]);
  634. //$answerWeighting=explode(',',$answerWeighting);
  635. // we save the answer because it will be modified
  636. $temp=$answer;
  637. // TeX parsing
  638. // 1. find everything between the [tex] and [/tex] tags
  639. $startlocations=api_strpos($temp,'[tex]');
  640. $endlocations=api_strpos($temp,'[/tex]');
  641. if ($startlocations !== false && $endlocations !== false) {
  642. $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
  643. // 2. replace this by {texcode}
  644. $temp=str_replace($texstring,'{texcode}',$temp);
  645. }
  646. $j=0;
  647. // the loop will stop at the end of the text
  648. $i=0;
  649. //normal fill in blank
  650. if (!$switchable_answer_set) {
  651. while (1) {
  652. // quits the loop if there are no more blanks
  653. if (($pos = api_strpos($temp,'[')) === false) {
  654. // adds the end of the text
  655. $answer.=$temp;
  656. // TeX parsing
  657. $texstring = api_parse_tex($texstring);
  658. break;
  659. }
  660. $temp=api_substr($temp,$pos+1);
  661. // quits the loop if there are no more blanks
  662. if (($pos = api_strpos($temp,']')) === false) {
  663. break;
  664. }
  665. $queryfill = "select answer from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  666. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  667. $str = Database::result($resfill,0,"answer");
  668. preg_match_all('#\[([^[]*)\]#', $str, $arr);
  669. $choice = $arr[1];
  670. $tmp=strrpos($choice[$j],' / ');
  671. $choice[$j]=substr($choice[$j],0,$tmp);
  672. $choice[$j]=trim($choice[$j]);
  673. // if the word entered by the student IS the same as the one defined by the professor
  674. if (api_strtolower(api_substr($temp,0,$pos)) == api_strtolower($choice[$j])) {
  675. // gives the related weighting to the student
  676. $questionScore+=$answerWeighting[$j];
  677. // increments total score
  678. $totalScore+=$answerWeighting[$j];
  679. }
  680. // else if the word entered by the student IS NOT the same as the one defined by the professor
  681. $j++;
  682. $temp=api_substr($temp,$pos+1);
  683. $i=$i+1;
  684. }
  685. $answer = stripslashes($str);
  686. $answer = str_replace('rn', '', $answer);
  687. } else {
  688. //multiple fill in blank
  689. while (1) {
  690. // quits the loop if there are no more blanks
  691. if (($pos = api_strpos($temp,'[')) === false) {
  692. // adds the end of the text
  693. $answer.=$temp;
  694. // TeX parsing
  695. $texstring = api_parse_tex($texstring);
  696. //$answer=str_replace("{texcode}",$texstring,$answer);
  697. break;
  698. }
  699. // adds the piece of text that is before the blank and ended by [
  700. $real_text[]=api_substr($temp,0,$pos+1);
  701. $answer.=api_substr($temp,0,$pos+1);
  702. $temp=api_substr($temp,$pos+1);
  703. // quits the loop if there are no more blanks
  704. if (($pos = api_strpos($temp,']')) === false) {
  705. // adds the end of the text
  706. //$answer.=$temp;
  707. break;
  708. }
  709. $queryfill = "SELECT answer FROM ".$TBL_TRACK_ATTEMPT." WHERE exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  710. $resfill = Database::query($queryfill, __FILE__, __LINE__);
  711. $str=Database::result($resfill,0,"answer");
  712. preg_match_all ('#\[([^[/]*)/#', $str, $arr);
  713. $choice = $arr[1];
  714. $choice[$j]=trim($choice[$j]);
  715. $user_tags[]=api_strtolower($choice[$j]);
  716. $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
  717. $j++;
  718. $temp=api_substr($temp,$pos+1);
  719. $i=$i+1;
  720. }
  721. $answer='';
  722. for ($i=0;$i<count($correct_tags);$i++) {
  723. if (in_array($user_tags[$i],$correct_tags)) {
  724. // gives the related weighting to the student
  725. $questionScore+=$answerWeighting[$i];
  726. // increments total score
  727. $totalScore+=$answerWeighting[$i];
  728. }
  729. }
  730. $answer = stripslashes($str);
  731. $answer = str_replace('rn', '', $answer);
  732. }
  733. //echo $questionScore."-".$totalScore;
  734. echo '<tr><td>';
  735. display_fill_in_blanks_answer($answer,$id,$questionId);
  736. echo '</td></tr>';
  737. $i++;
  738. }
  739. echo '</table>';
  740. } elseif ($answerType == FREE_ANSWER) {$answer = $str;
  741. ?>
  742. <table width="100%" border="0" cellspacing="3" cellpadding="3">
  743. <tr>
  744. <td>&nbsp;</td>
  745. </tr>
  746. <tr>
  747. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  748. </tr>
  749. <tr>
  750. <td>&nbsp;</td>
  751. </tr>
  752. <?php
  753. $objAnswerTmp = new Answer($questionId);
  754. $nbrAnswers = $objAnswerTmp->selectNbrAnswers();
  755. $questionScore = 0;
  756. $query = "select answer, marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  757. $resq = Database::query($query);
  758. $choice = Database::result($resq,0,"answer");
  759. $choice = stripslashes($choice);
  760. $choice = str_replace('rn', '', $choice);
  761. $questionScore = Database::result($resq,0,"marks");
  762. if ($questionScore==-1) {
  763. $totalScore+=0;
  764. } else {
  765. $totalScore+=$questionScore;
  766. }
  767. echo '<tr>
  768. <td valign="top">'.display_free_answer($choice, $id, $questionId).'</td>
  769. </tr>
  770. </table>';
  771. } elseif ($answerType == MATCHING) {
  772. $objAnswerTmp=new Answer($questionId);
  773. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  774. $TBL_TRACK_ATTEMPT= Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  775. $sql_select_answer = 'SELECT id, answer, correct, position FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct<>0';
  776. $sql_answer = 'SELECT position, answer FROM '.$table_ans.' WHERE question_id="'.Database::escape_string($questionId).'" AND correct=0';
  777. $res_answer = Database::query($sql_answer, __FILE__, __LINE__);
  778. // getting the real answer
  779. $real_list =array();
  780. while ($real_answer = Database::fetch_array($res_answer)) {
  781. $real_list[$real_answer['position']]= $real_answer['answer'];
  782. }
  783. $res_answers = Database::query($sql_select_answer, __FILE__, __LINE__);
  784. echo '<table width="100%" height="71" border="0" cellspacing="3" cellpadding="3" >';
  785. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  786. echo '<tr>
  787. <td><span style="font-style: italic;">'.get_lang("ElementList").'</span> </td>
  788. <td><span style="font-style: italic;">'.get_lang("CorrespondsTo").'</span></td>
  789. </tr>';
  790. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  791. $questionScore=0;
  792. while ($a_answers = Database::fetch_array($res_answers)) {
  793. $i_answer_id = $a_answers['id']; //3
  794. $s_answer_label = $a_answers['answer']; // your dady - you mother
  795. $i_answer_correct_answer = $a_answers['correct']; //1 - 2
  796. $i_answer_position = $a_answers['position']; // 3 - 4
  797. $sql_user_answer =
  798. 'SELECT answers.answer
  799. FROM '.$TBL_TRACK_ATTEMPT.' as track_e_attempt
  800. INNER JOIN '.$table_ans.' as answers
  801. ON answers.position = track_e_attempt.answer
  802. AND track_e_attempt.question_id=answers.question_id
  803. WHERE answers.correct = 0
  804. AND track_e_attempt.exe_id = "'.Database::escape_string($id).'"
  805. AND track_e_attempt.question_id = "'.Database::escape_string($questionId).'"
  806. AND track_e_attempt.position="'.Database::escape_string($i_answer_position).'"';
  807. $res_user_answer = Database::query($sql_user_answer, __FILE__, __LINE__);
  808. if (Database::num_rows($res_user_answer)>0 ) {
  809. $s_user_answer = Database::result($res_user_answer,0,0); // rich - good looking
  810. } else {
  811. $s_user_answer = '';
  812. }
  813. //$s_correct_answer = $s_answer_label; // your ddady - your mother
  814. $s_correct_answer = $real_list[$i_answer_correct_answer];
  815. $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
  816. //if($s_user_answer == $s_correct_answer) // rich == your ddady?? wrong
  817. //echo $s_user_answer.' - '.$real_list[$i_answer_correct_answer];
  818. if ($s_user_answer == $real_list[$i_answer_correct_answer]) { // rich == your ddady?? wrong
  819. $questionScore+=$i_answerWeighting;
  820. $totalScore+=$i_answerWeighting;
  821. } else {
  822. $s_user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$s_user_answer.'</span>';
  823. }
  824. echo '<tr>';
  825. echo '<td>'.$s_answer_label.'</td><td>'.$s_user_answer.' / <b><span style="color: #008000;">'.$s_correct_answer.'</span></b></td>';
  826. echo '</tr>';
  827. }
  828. echo '</table>';
  829. } elseif ($answerType == HOT_SPOT) {
  830. ?>
  831. <table width="500" border="0">
  832. <?php
  833. $objAnswerTmp=new Answer($questionId);
  834. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  835. $questionScore=0;
  836. ?>
  837. <tr>
  838. <td valign="top" align="center" style="padding-left:0px;" >
  839. <table border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;" width="552">
  840. <?php
  841. for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
  842. $answer=$objAnswerTmp->selectAnswer($answerId);
  843. $answerComment=$objAnswerTmp->selectComment($answerId);
  844. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  845. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  846. $TBL_TRACK_HOTSPOT = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  847. $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)."'";
  848. $resq=Database::query($query);
  849. $choice = Database::result($resq,0,"hotspot_correct");
  850. display_hotspot_answer($answerId,$answer,$choice,$answerComment);
  851. $i++;
  852. }
  853. $queryfree = "select marks from ".$TBL_TRACK_ATTEMPT." where exe_id = '".Database::escape_string($id)."' and question_id= '".Database::escape_string($questionId)."'";
  854. $resfree = Database::query($queryfree, __FILE__, __LINE__);
  855. $questionScore= Database::result($resfree,0,"marks");
  856. $totalScore+=$questionScore;
  857. echo '</table></td></tr>';
  858. echo '<tr>
  859. <td colspan="2">'.
  860. //<object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'&exe_id='.$id.'&from_db=1" width="556" height="421">
  861. '<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">
  862. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.Security::remove_XSS($questionId).'&exe_id='.$id.'&from_db=1" />
  863. </object>
  864. </td>
  865. </tr>
  866. </table><br/>';
  867. }
  868. echo '<table width="100%" border="0" cellspacing="3" cellpadding="0">';
  869. if ($is_allowedToEdit) {
  870. echo '<tr><td>';
  871. $name = "fckdiv".$questionId;
  872. $marksname = "marksName".$questionId;
  873. ?>
  874. <br />
  875. <a href="javascript://" onclick="showfck('<?php echo $name; ?>','<?php echo $marksname; ?>');">
  876. <?php
  877. if ($answerType == FREE_ANSWER) {
  878. echo get_lang('EditCommentsAndMarks');
  879. } else {
  880. if ($action=='edit') {
  881. echo '<img src="../img/edit.gif"/>'.get_lang('EditIndividualComment');
  882. } else {
  883. echo get_lang('AddComments');
  884. }
  885. }
  886. echo '</a><br /><div id="feedback_'.$name.'" style="width:100%">';
  887. $comnt = trim(get_comments($id,$questionId));
  888. if (empty($comnt)) {
  889. echo '<br />';
  890. } else {
  891. echo '<div id="question_feedback">'.$comnt.'</div>';
  892. }
  893. echo '</div><div id="'.$name.'" style="display:none">';
  894. $arrid[] = $questionId;
  895. $feedback_form = new FormValidator('frmcomments'.$questionId,'post','');
  896. $feedback_form->addElement('html','<br>');
  897. $renderer =& $feedback_form->defaultRenderer();
  898. $renderer->setFormTemplate('<form{attributes}><div align="left">{content}</div></form>');
  899. $renderer->setElementTemplate('<div align="left">{element}</div>');
  900. $comnt = get_comments($id,$questionId);
  901. ${user.$questionId}['comments_'.$questionId] = $comnt;
  902. $feedback_form->addElement('html_editor', 'comments_'.$questionId, null, null, array('ToolbarSet' => 'TestAnswerFeedback', 'Width' => '100%', 'Height' => '120'));
  903. $feedback_form->addElement('html','<br>');
  904. //$feedback_form->addElement('submit','submitQuestion',get_lang('Ok'));
  905. $feedback_form->setDefaults(${user.$questionId});
  906. $feedback_form->display();
  907. echo '</div>';
  908. } else {
  909. $comnt = get_comments($id,$questionId);
  910. echo '<tr><td><br />';
  911. if (!empty($comnt)) {
  912. echo '<b>'.get_lang('Feedback').'</b>';
  913. echo '<div id="question_feedback">'.$comnt.'</div>';
  914. }
  915. echo '</td><td>';
  916. }
  917. if ($is_allowedToEdit) {
  918. if ($answerType == FREE_ANSWER) {
  919. $marksname = "marksName".$questionId;
  920. ?>
  921. <div id="<?php echo $marksname; ?>" style="display:none">
  922. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  923. <?php
  924. $arrmarks[] = $questionId;
  925. echo get_lang("AssignMarks");
  926. echo "&nbsp;<select name='marks' id='marks'>";
  927. for ($i=0;$i<=$questionWeighting;$i++) {
  928. echo '<option '.(($i==$questionScore)?"selected='selected'":'').'>'.$i.'</option>';
  929. }
  930. echo '</select>';
  931. echo '</form><br/ ></div>';
  932. if ($questionScore==-1) {
  933. $questionScore=0;
  934. echo '<br />'.get_lang('notCorrectedYet');
  935. }
  936. } else {
  937. $arrmarks[] = $questionId;
  938. echo '<div id="'.$marksname.'" style="display:none"><form name="marksform_'.$questionId.'" method="post" action="">
  939. <select name="marks" id="marks" style="display:none;"><option>'.$questionScore.'</option></select></form><br/ ></div>';
  940. }
  941. } else {
  942. if ($questionScore==-1) {
  943. $questionScore=0;
  944. }
  945. }
  946. ?>
  947. </td>
  948. </tr>
  949. </table>
  950. <div id="question_score">
  951. <?php
  952. $my_total_score = float_format($questionScore,1);
  953. $my_total_weight = float_format($questionWeighting,1);
  954. echo get_lang('Score')." : $my_total_score/$my_total_weight";
  955. echo '</div>';
  956. unset($objAnswerTmp);
  957. $i++;
  958. $totalWeighting+=$questionWeighting;
  959. } // end of large foreach on questions
  960. } //end of condition if $show_results
  961. if ($origin!='learnpath' || ($origin == 'learnpath' && isset($_GET['fb_type']))) {
  962. //$query = "update ".$TBL_TRACK_EXERCICES." set exe_result = $totalScore where exe_id = '$id'";
  963. //Database::query($query,__FILE__,__LINE__);
  964. if ($show_results) {
  965. echo '<div id="question_score">'.get_lang('YourTotalScore')." ";
  966. if($dsp_percent == true) {
  967. $my_result = number_format(($totalScore/$totalWeighting)*100,1,'.','');
  968. $my_result = float_format($my_result,1);
  969. echo $my_result."%";
  970. } else {
  971. $my_total_score = float_format($totalScore,1);
  972. $my_total_weight = float_format($totalWeighting,1);
  973. echo $my_total_score."/".$my_total_weight;
  974. }
  975. echo '!</div>';
  976. }
  977. }
  978. if (is_array($arrid) && is_array($arrmarks)) {
  979. $strids = implode(",",$arrid);
  980. $marksid = implode(",",$arrmarks);
  981. }
  982. if ($is_allowedToEdit) {
  983. if (in_array($origin, array('tracking_course','user_course'))) {
  984. 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">';
  985. echo ' <input type = "hidden" name="totalWeighting" value="'.$totalWeighting.'">';
  986. if (isset($_GET['myid']) && isset($_GET['my_lp_id']) && isset($_GET['student'])) {
  987. ?>
  988. <input type = "hidden" name="lp_item_id" value="<?php echo Security::remove_XSS($_GET['myid']); ?>">
  989. <input type = "hidden" name="lp_item_view_id" value="<?php echo Security::remove_XSS($_GET['my_lp_id']); ?>">
  990. <input type = "hidden" name="student_id" value="<?php echo Security::remove_XSS($_GET['student']);?>">
  991. <input type = "hidden" name="total_score" value="<?php echo $totalScore; ?>">
  992. <input type = "hidden" name="total_time" value="<?php echo Security::remove_XSS($_GET['total_time']);?>">
  993. <input type = "hidden" name="my_exe_exo_id" value="<?php echo Security::remove_XSS($_GET['my_exe_exo_id']); ?>">
  994. <?php
  995. }
  996. } else {
  997. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&totalWeighting='.$totalWeighting.'" method="post">';
  998. }
  999. if ($origin!='learnpath' && $origin!='student_progress') {
  1000. ?>
  1001. <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>
  1002. </form>
  1003. <?php
  1004. }
  1005. }
  1006. if ($origin=='student_progress') {?>
  1007. <button type="button" class="back" onclick="window.back();" value="<?php echo get_lang('Back'); ?>" ><?php echo get_lang('Back');?></button>
  1008. <?php
  1009. } else if($origin=='myprogress') {
  1010. ?>
  1011. <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>
  1012. <?php
  1013. }
  1014. if ($origin != 'learnpath') {
  1015. //we are not in learnpath tool
  1016. Display::display_footer();
  1017. } else {
  1018. if (!isset($_GET['fb_type'])) {
  1019. $lp_mode = $_SESSION['lp_mode'];
  1020. $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;
  1021. $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';
  1022. echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
  1023. //record the results in the learning path, using the SCORM interface (API)
  1024. echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  1025. echo '</body></html>';
  1026. } else {
  1027. Display::display_normal_message(get_lang('ExerciseFinished').' '.get_lang('ToContinueUseMenu'));
  1028. }
  1029. }
  1030. //destroying the session
  1031. api_session_unregister('questionList');
  1032. unset ($questionList);
  1033. api_session_unregister('exerciseResult');
  1034. unset ($exerciseResult);