exercise_show.php 41 KB

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