exercise_show.php 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859
  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. $TABLETRACK_ATTEMPT = $_configuration['statistics_database']."`.`track_e_attempt";
  51. $TABLETRACK_EXERCICES = $_configuration['statistics_database']."`.`track_e_exercices";
  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();
  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 $TABLETRACK_ATTEMPT;
  168. $sql = "select teacher_comment from `".$TABLETRACK_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, `'.$TABLETRACK_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. $query = "select * from `".$TABLETRACK_ATTEMPT."` as attempts
  281. INNER JOIN `".$TABLETRACK_EXERCICES."` as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
  282. INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
  283. INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
  284. WHERE attempts.exe_id='$id'
  285. GROUP BY questions.position";
  286. $result =api_sql_query($query, __FILE__, __LINE__);
  287. ?>
  288. <h3><?php echo stripslashes($test)?> : <?php echo get_lang("Result"); ?></h3>
  289. <?php echo $exerciseDexcription.'<br>'; ?>
  290. </td>
  291. </tr>
  292. <?php
  293. $i=$totalScore=$totalWeighting=0;
  294. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  295. // for each question
  296. $questionList = array();
  297. $exerciseResult = array();
  298. $k=0;
  299. $counter=0;
  300. while ($row = mysql_fetch_array($result))
  301. {
  302. $questionList[] = $row['question_id'];
  303. $exerciseResult[] = $row['answer'];
  304. }
  305. foreach($questionList as $questionId)
  306. {
  307. $counter++;
  308. $k++;
  309. $choice=$exerciseResult[$questionId];
  310. // creates a temporary Question object
  311. $objQuestionTmp = Question::read($questionId);
  312. $questionName=$objQuestionTmp->selectTitle();
  313. $questionDescription=$objQuestionTmp->selectDescription();
  314. $questionWeighting=$objQuestionTmp->selectWeighting();
  315. $answerType=$objQuestionTmp->selectType();
  316. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  317. // destruction of the Question object
  318. unset($objQuestionTmp);
  319. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  320. {
  321. $colspan=2;
  322. }
  323. if($answerType == MATCHING || $answerType == FREE_ANSWER)
  324. {
  325. $colspan=2;
  326. }
  327. else
  328. {
  329. $colspan=2;
  330. }?>
  331. <tr bgcolor="#E6E6E6">
  332. <td colspan="2" > <?php echo get_lang("Question").' '.($counter); ?> </td>
  333. </tr>
  334. <tr>
  335. <td colspan="2"><?php echo $questionName; ?> </td>
  336. </tr>
  337. <tr>
  338. <td colspan="2"><?php echo $questionDescription; ?> </td>
  339. </tr>
  340. <tr>
  341. <td width="200" height="90" valign="top">
  342. <?php
  343. if($answerType == MULTIPLE_ANSWER)
  344. {
  345. $choice=array();
  346. ?>
  347. <table width="355" border="0" cellspacing="3" cellpadding="3">
  348. <tr>
  349. <td>&nbsp;</td>
  350. </tr>
  351. <tr>
  352. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  353. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  354. <td><i><?php echo get_lang("Answer"); ?></i></td>
  355. </tr>
  356. <tr>
  357. <td>&nbsp;</td>
  358. </tr>
  359. <?php
  360. // construction of the Answer object
  361. $objAnswerTmp=new Answer($questionId);
  362. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  363. $questionScore=0;
  364. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  365. {
  366. $answer=$objAnswerTmp->selectAnswer($answerId);
  367. $answerComment=$objAnswerTmp->selectComment($answerId);
  368. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  369. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  370. $queryans = "select * from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  371. $resultans = api_sql_query($queryans, __FILE__, __LINE__);
  372. while ($row = mysql_fetch_array($resultans))
  373. {
  374. $ind = $row['answer'];
  375. $choice[$ind] = 1;
  376. }
  377. $studentChoice=$choice[$answerId];
  378. if($studentChoice)
  379. {
  380. $questionScore+=$answerWeighting;
  381. $totalScore+=$answerWeighting;
  382. }
  383. ?>
  384. <tr>
  385. <td> <?php
  386. if($answerId==1)
  387. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  388. else
  389. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  390. ?>
  391. </td>
  392. </tr>
  393. <?php
  394. $i++;
  395. }?>
  396. </table>
  397. <?php }
  398. else if ($answerType == UNIQUE_ANSWER)
  399. {?>
  400. <table width="355" border="0">
  401. <tr>
  402. <td>&nbsp;</td>
  403. </tr>
  404. <tr>
  405. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  406. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  407. <td><i><?php echo get_lang("Answer"); ?></i></td>
  408. </tr>
  409. <tr>
  410. <td>&nbsp;</td>
  411. </tr>
  412. <?php
  413. $objAnswerTmp=new Answer($questionId);
  414. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  415. $questionScore=0;
  416. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  417. {
  418. $answer=$objAnswerTmp->selectAnswer($answerId);
  419. $answerComment=$objAnswerTmp->selectComment($answerId);
  420. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  421. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  422. $queryans = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  423. $resultans = api_sql_query($queryans, __FILE__, __LINE__);
  424. $choice = mysql_result($resultans,0,"answer");
  425. $studentChoice=($choice == $answerId)?1:0;
  426. if($studentChoice)
  427. {
  428. $questionScore+=$answerWeighting;
  429. $totalScore+=$answerWeighting;
  430. }?>
  431. <tr>
  432. <td><?php if($answerId==1)
  433. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  434. else
  435. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  436. ?>
  437. </td>
  438. </tr><?php
  439. $i++;
  440. }?>
  441. </table>
  442. <?php }
  443. elseif($answerType == FILL_IN_BLANKS)
  444. {?>
  445. <table width="355" border="0">
  446. <tr>
  447. <td>&nbsp;</td>
  448. </tr>
  449. <tr>
  450. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  451. </tr>
  452. <tr>
  453. <td>&nbsp;</td>
  454. </tr>
  455. <?php
  456. $objAnswerTmp=new Answer($questionId);
  457. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  458. $questionScore=0;
  459. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  460. {
  461. $answer=$objAnswerTmp->selectAnswer($answerId);
  462. $answerComment=$objAnswerTmp->selectComment($answerId);
  463. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  464. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  465. list($answer,$answerWeighting)=explode('::',$answer);
  466. // splits weightings that are joined with a comma
  467. $answerWeighting=explode(',',$answerWeighting);
  468. // we save the answer because it will be modified
  469. $temp=$answer;
  470. // TeX parsing
  471. // 1. find everything between the [tex] and [/tex] tags
  472. $startlocations=strpos($temp,'[tex]');
  473. $endlocations=strpos($temp,'[/tex]');
  474. if($startlocations !== false && $endlocations !== false)
  475. {
  476. $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  477. // 2. replace this by {texcode}
  478. $temp=str_replace($texstring,'{texcode}',$temp);
  479. }
  480. $j=0;
  481. // the loop will stop at the end of the text
  482. $i=0;
  483. while(1)
  484. {
  485. // quits the loop if there are no more blanks
  486. if(($pos = strpos($temp,'[')) === false)
  487. {
  488. // adds the end of the text
  489. $answer.=$temp;
  490. // TeX parsing
  491. $texstring = api_parse_tex($texstring);
  492. break;
  493. }
  494. $temp=substr($temp,$pos+1);
  495. // quits the loop if there are no more blanks
  496. if(($pos = strpos($temp,']')) === false)
  497. {
  498. break;
  499. }
  500. $queryfill = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  501. $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
  502. $str=mysql_result($resfill,0,"answer");
  503. preg_match_all ('#\[([^[/]*)/#', $str, $arr);
  504. $choice = $arr[1];
  505. $choice[$j]=trim($choice[$j]);
  506. // if the word entered by the student IS the same as the one defined by the professor
  507. if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  508. {
  509. // gives the related weighting to the student
  510. $questionScore+=$answerWeighting[$j];
  511. // increments total score
  512. $totalScore+=$answerWeighting[$j];
  513. }
  514. // else if the word entered by the student IS NOT the same as the one defined by the professor
  515. $j++;
  516. $temp=substr($temp,$pos+1);
  517. $i=$i+1;
  518. } $answer = $str;
  519. ?>
  520. <tr>
  521. <td> <?php display_fill_in_blanks_answer($answer,$id,$questionId); ?> </td>
  522. </tr><?php
  523. $i++;
  524. }?>
  525. </table>
  526. <?php }
  527. elseif($answerType == FREE_ANSWER)
  528. {?>
  529. <table width="355" border="0" cellspacing="0" cellpadding="0">
  530. <tr>
  531. <td>&nbsp;</td>
  532. </tr>
  533. <tr>
  534. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  535. </tr>
  536. <tr>
  537. <td>&nbsp;</td>
  538. </tr>
  539. <?php
  540. $objAnswerTmp=new Answer($questionId);
  541. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  542. $questionScore=0;
  543. $query = "select answer, marks from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  544. $resq=api_sql_query($query);
  545. $choice = mysql_result($resq,0,"answer");
  546. $questionScore = mysql_result($resq,0,"marks");
  547. if($questionScore==-1){
  548. $totalScore+=0;
  549. }
  550. else{
  551. $totalScore+=$questionScore;
  552. }
  553. ?>
  554. <tr>
  555. <td valign="top"><?php display_free_answer($choice, $id, $questionId);?> </td>
  556. </tr>
  557. </table>
  558. <?php }
  559. elseif($answerType == MATCHING)
  560. {
  561. $objAnswerTmp=new Answer($questionId);
  562. $table_ans = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  563. $TABLETRACK_ATTEMPT = $_configuration['statistics_database']."`.`track_e_attempt";
  564. $sql_select_answer = 'SELECT id, answer, correct, position FROM '.$table_ans.' WHERE question_id="'.$questionId.'" AND correct<>0';
  565. $res_answers = api_sql_query($sql_select_answer, __FILE__, __LINE__);
  566. echo '<table width="355" height="71" border="0">';
  567. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  568. echo '<tr>
  569. <td><span style="font-style: italic;">'.get_lang("ElementList").'</span> </td>
  570. <td><span style="font-style: italic;">'.get_lang("CorrespondsTo").'</span></td>
  571. </tr>';
  572. echo '<tr><td colspan="2">&nbsp;</td></tr>';
  573. $questionScore=0;
  574. while($a_answers = mysql_fetch_array($res_answers)){
  575. $i_answer_id = $a_answers['id'];
  576. $s_answer_label = $a_answers['answer'];
  577. $i_answer_correct_answer = $a_answers['correct'];
  578. $i_answer_position = $a_answers['position'];
  579. $sql_user_answer = 'SELECT answers.answer
  580. FROM `'.$TABLETRACK_ATTEMPT.'` as track_e_attempt, '.$table_ans.' as answers
  581. WHERE track_e_attempt.answer=answers.position
  582. AND track_e_attempt.position="'.$i_answer_position.'"
  583. AND answers.question_id ="'.$questionId.'"
  584. AND exe_id = "'.$id.'"';
  585. $res_user_answer = api_sql_query($sql_user_answer, __FILE__, __LINE__);
  586. $s_user_answer = mysql_result($res_user_answer,0,0);
  587. $sql_correct_answer = 'SELECT answer FROM '.$table_ans.' WHERE position = "'.$i_answer_correct_answer.'" AND question_id="'.$questionId.'"';
  588. $res_correct_answer = api_sql_query($sql_correct_answer, __FILE__, __LINE__);
  589. $s_correct_answer = mysql_result($res_correct_answer,0,0);
  590. $i_answerWeighting=$objAnswerTmp->selectWeighting($i_answer_id);
  591. if($s_user_answer == $s_correct_answer){
  592. $questionScore+=$i_answerWeighting;
  593. $totalScore+=$i_answerWeighting;
  594. }
  595. else{
  596. $s_user_answer = '<span style="color: #FF0000; text-decoration: line-through;">'.$s_user_answer.'</span>';
  597. }
  598. echo '<tr>';
  599. echo '<td>'.$s_answer_label.'</td><td>'.$s_user_answer.' / <span style="color: #008000;">'.$s_correct_answer.'</span></td>';
  600. echo '</tr>';
  601. }
  602. echo '</table>';
  603. }
  604. else if($answerType == HOTSPOT){
  605. ?>
  606. <table width="355" border="0" cellspacing="0" cellpadding="0">
  607. <tr>
  608. <td>&nbsp;</td>
  609. </tr>
  610. <tr>
  611. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  612. </tr>
  613. <tr>
  614. <td>&nbsp;</td>
  615. </tr>
  616. <?php
  617. $objAnswerTmp=new Answer($questionId);
  618. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  619. $questionScore=0;
  620. echo '
  621. <tr>
  622. <td>
  623. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'" width="380" height="400">
  624. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'" />
  625. </object>
  626. </td><td valign="top"><table style="border: 1px solid" width="200">';
  627. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  628. {
  629. $answer=$objAnswerTmp->selectAnswer($answerId);
  630. $answerComment=$objAnswerTmp->selectComment($answerId);
  631. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  632. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  633. $query = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  634. $resq=api_sql_query($query);
  635. $choice = mysql_result($resq,0,"answer");
  636. display_hotspot_answer($answerId,$answer,$choice,$answerComment);
  637. $i++;
  638. }
  639. $queryfree = "select marks from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  640. $resfree = api_sql_query($queryfree, __FILE__, __LINE__);
  641. $questionScore= mysql_result($resfree,0,"marks");
  642. $totalScore+=$questionScore;
  643. ?>
  644. </table></td></tr></table>
  645. <?php
  646. }
  647. ?>
  648. </td>
  649. <td width="346" valign = "top"><i>
  650. <?php echo get_lang("Comment"); ?></i>
  651. <?php if($is_allowedToEdit)
  652. {
  653. //if (isset($_REQUEST['showdiv']) && $questionId==$_REQUEST['ques_id'])
  654. //{
  655. $name = "fckdiv".$questionId;
  656. $marksname = "marksName".$questionId;
  657. ?>
  658. <a href="#" 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>
  659. <?php
  660. $comnt = get_comments($id,$questionId);
  661. echo "<br> <br>".$comnt;
  662. ?>
  663. <div id="<?php echo $name; ?>" style="visibility:hidden">
  664. <?php
  665. $arrid[] = $questionId;
  666. $fck_attribute['Width'] = '400';
  667. $fck_attribute['Height'] = '150';
  668. $fck_attribute['ToolbarSet'] = 'Comment';
  669. $fck_attribute['Config']['IMUploadPath'] = 'upload/test/';
  670. $$questionId = new FormValidator('frmcomments'.$questionId,'post','');
  671. $renderer =& $$questionId->defaultRenderer();
  672. $renderer->setFormTemplate(
  673. '<form{attributes}><div align="left">{content}</div></form>');
  674. $renderer->setElementTemplate(
  675. '<div align="left">{element}</div>'
  676. );
  677. $comnt =get_comments($id,$questionId);
  678. ${user.$questionId}['comments_'.$questionId] = $comnt;
  679. $$questionId->addElement('html_editor','comments_'.$questionId,false);
  680. //$$questionId->addElement('submit','submitQuestion',get_lang('Ok'));
  681. $$questionId->setDefaults(${user.$questionId});
  682. $$questionId->display();
  683. ?>
  684. </div>
  685. <?php
  686. }
  687. else
  688. {
  689. $comnt = get_comments($id,$questionId);
  690. echo "<br> <br>".$comnt;
  691. }
  692. ?>
  693. </td>
  694. </tr>
  695. <tr>
  696. <td></td>
  697. <td align= "left" >
  698. <?php
  699. if($is_allowedToEdit)
  700. {
  701. if ($answerType == FREE_ANSWER)
  702. {
  703. $marksname = "marksName".$questionId;
  704. ?>
  705. <div id="<?php echo $marksname; ?>" style="visibility:hidden">
  706. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  707. <?php
  708. $arrmarks[] = $questionId;
  709. echo get_lang("AssignMarks");
  710. echo "<select name='marks' id='marks'>";
  711. for($i=0;$i<=$questionWeighting;$i++)
  712. {?>
  713. <option <?php if ($i==$questionScore) echo "selected='selected'";?>>
  714. <?php echo $i;
  715. ?></option>
  716. <?php } ?>
  717. </select>
  718. </form></div><?php
  719. if($questionScore==-1){
  720. $questionScore=0;
  721. echo '<br>'.get_lang('notCorrectedYet');
  722. }
  723. }
  724. else{
  725. $arrmarks[] = $questionId;
  726. 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>';
  727. }
  728. }
  729. else{
  730. if($questionScore==-1){
  731. $questionScore=0;
  732. }
  733. }?>
  734. </td><tr><td></td><td align="right"><b><?php echo get_lang('Score')." : $questionScore/$questionWeighting"; ?></b></td>
  735. </tr>
  736. <?php unset($objAnswerTmp);
  737. $i++;
  738. $totalWeighting+=$questionWeighting;
  739. }
  740. ?>
  741. <tr><td></td><td align=right><b><?php
  742. //$query = "update `".$TABLETRACK_EXERCICES."` set exe_result = $totalScore where exe_id = '$id'";
  743. //api_sql_query($query,__FILE__,__LINE__);
  744. echo '<br/>'.get_lang('YourTotalScore')." ";
  745. if($dsp_percent == true)
  746. {
  747. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  748. }
  749. else
  750. {
  751. echo $totalScore."/".$totalWeighting;
  752. }
  753. ?> !</b>
  754. </td></tr>
  755. <tr><td></td>
  756. <td align="right">
  757. <br />
  758. <?php $strids = implode(",",$arrid);
  759. $marksid = implode(",",$arrmarks);
  760. if($is_allowedToEdit)
  761. {
  762. ?>
  763. <?php
  764. if(in_array($origin, array('tracking_course','user_course'))){
  765. 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">';
  766. }
  767. else{
  768. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'" method="post">';
  769. }
  770. ?>
  771. <input type="submit" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"/>
  772. </form>
  773. <?php } ?>
  774. </td>
  775. </tr>
  776. </table>