exercise_show.php 40 KB

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