exercise_show.php 40 KB

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