exercise_show.php 27 KB

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