exercise_show.php 34 KB

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