exercise_show.php 26 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874
  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=$is_courseAdmin;
  94. $nameTools=get_lang('CorrectTest');
  95. if($origin=='' || $origin!='tests'){
  96. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  97. $this_section=SECTION_COURSES;
  98. }
  99. else{
  100. unset($_cid);
  101. $interbreadcrumb[] = array ("url" => "../mySpace/index.php", "name" => get_lang('MySpace'));
  102. $interbreadcrumb[] = array ("url" => "../mySpace/student.php", "name" => get_lang("MyStudents"));
  103. $interbreadcrumb[] = array ("url" => "../mySpace/myStudents.php?student=".$_GET['student'].'&details=true&course='.$_GET['cidReq'].'', "name" => get_lang("StudentDetails"));
  104. $this_section = "session_my_space";
  105. }
  106. Display::display_header($nameTools,"Exercise");
  107. //echo "<pre>";
  108. //print_r($_SESSION);
  109. //echo "</pre>";
  110. $emailId = $_REQUEST['email'];
  111. $user_name = $_REQUEST['user'];
  112. $test = $_REQUEST['test'];
  113. $dt = $_REQUEST['dt'];
  114. $marks = $_REQUEST['res'];
  115. $id = $_REQUEST['id'];
  116. ?>
  117. <style type="text/css">
  118. <!--
  119. #comments {
  120. position:absolute;
  121. left:795px;
  122. top:0px;
  123. width:200px;
  124. height:75px;
  125. z-index:1;
  126. }
  127. -->
  128. </style>
  129. <script language="javascript">
  130. function showfck(sid,marksid)
  131. {
  132. document.getElementById(sid).style.visibility='visible';
  133. document.getElementById(marksid).style.visibility='visible';
  134. }
  135. function getFCK(vals,marksid){
  136. var f=document.getElementById('myform');
  137. var m_id = marksid.split(',');
  138. for(var i=0;i<m_id.length;i++){
  139. var oHidn = document.createElement("input");
  140. oHidn.type = "hidden";
  141. var selname = oHidn.name = "marks_"+m_id[i];
  142. var selid = document.forms['marksform_'+m_id[i]].marks.selectedIndex;
  143. oHidn.value = document.forms['marksform_'+m_id[i]].marks.options[selid].text;
  144. f.appendChild(oHidn);
  145. }
  146. var ids = vals.split(',');
  147. for(var k=0;k<ids.length;k++){
  148. var oHidden = document.createElement("input");
  149. oHidden.type = "hidden";
  150. oHidden.name = "comments_"+ids[k];
  151. oEditor = FCKeditorAPI.GetInstance(oHidden.name) ;
  152. oHidden.value = oEditor.GetXHTML(true);
  153. f.appendChild(oHidden);
  154. }
  155. //f.submit();
  156. }
  157. </script>
  158. <?php
  159. //functions
  160. function get_comments($id,$question_id)
  161. {
  162. global $TABLETRACK_ATTEMPT;
  163. $sql = "select teacher_comment from `".$TABLETRACK_ATTEMPT."` where exe_id=$id and question_id = '$question_id' order by question_id";
  164. $sqlres = api_sql_query($sql, __FILE__, __LINE__);
  165. $comm = mysql_result($sqlres,0,"teacher_comment");
  166. return $comm;
  167. }
  168. function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$ans)
  169. {
  170. ?>
  171. <tr valign="top">
  172. <td width="5%" align="center">
  173. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
  174. border="0" alt="" />
  175. </td>
  176. <td width="5%" align="center">
  177. <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
  178. border="0" alt=" " />
  179. </td>
  180. <td width="45%">
  181. <?php
  182. $answer=api_parse_tex($answer);
  183. echo $answer; ?><hr style="border-top: 0.5px solid #4171B5;">
  184. </td>
  185. <?php if($ans==1)
  186. {$comm = get_comments($id,$questionId);
  187. //echo $comm;
  188. }?>
  189. </tr>
  190. <?php
  191. }
  192. function display_fill_in_blanks_answer($answer,$id,$questionId)
  193. {
  194. ?>
  195. <tr>
  196. <td>
  197. <?php echo nl2br($answer); ?>
  198. </td><?php
  199. if(!$is_allowedToEdit) {?>
  200. <td>
  201. <?php
  202. $comm = get_comments($id,$questionId);
  203. //echo $comm;
  204. ?>
  205. </td>
  206. </tr>
  207. <?php }
  208. }
  209. function display_free_answer($answer,$id,$questionId)
  210. {
  211. ?>
  212. <tr>
  213. <td>
  214. <?php echo nl2br(stripslashes($answer)); ?>
  215. </td> <?php if(!$is_allowedToEdit) {?>
  216. <td>
  217. <?php
  218. $comm = get_comments($id,$questionId);
  219. /*if ($comm!='')
  220. echo $comm;
  221. else
  222. echo get_lang('notCorrectedYet');
  223. */?>
  224. </td> <?php }?>
  225. </tr>
  226. <?php
  227. }
  228. function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
  229. {
  230. //global $hotspot_colors;
  231. $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
  232. "#4271B5",
  233. "#FE8E16",
  234. "#3B3B3B",
  235. "#BCD631",
  236. "#D63173",
  237. "#D7D7D7",
  238. "#90AFDD",
  239. "#AF8640",
  240. "#4F9242",
  241. "#F4EB24",
  242. "#ED2024",
  243. "#45C7F0",
  244. "#F7BDE2");
  245. ?>
  246. <tr>
  247. <td width="50%" valign="top">
  248. <div style="width:100%;">
  249. <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; float:left; margin:3px;"></div>
  250. <div><?php echo $answer ?></div>
  251. </div>
  252. </td>
  253. <td width="25%" valign="top"><?php echo $answerId; ?></td>
  254. <td width="25%" valign="top">
  255. <?php $studentChoice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $studentChoice; ?>
  256. </td>
  257. </tr>
  258. <?php
  259. }
  260. /*
  261. ==============================================================================
  262. MAIN CODE
  263. ==============================================================================
  264. */
  265. ?>
  266. <table width="100%" border="0" cellspacing=0 cellpadding=0>
  267. <tr>
  268. <td colspan="2">
  269. <?php
  270. $sql_test_name='SELECT title FROM '.$TBL_EXERCICES.' WHERE id="'.$id.'"';
  271. $result=api_sql_query($sql_test_name);
  272. $test=mysql_result($result,0,0);
  273. $exerciseTitle=api_parse_tex($test);
  274. $query = "select * from `".$TABLETRACK_ATTEMPT."` as attempts
  275. INNER JOIN `".$TABLETRACK_EXERCICES."` as stats_exercices ON stats_exercices.exe_id=attempts.exe_id
  276. INNER JOIN ".$TBL_EXERCICE_QUESTION." as quizz_rel_questions ON quizz_rel_questions.exercice_id=stats_exercices.exe_exo_id
  277. INNER JOIN ".$TBL_QUESTIONS." as questions ON questions.id=quizz_rel_questions.question_id
  278. WHERE attempts.exe_id='$id'
  279. GROUP BY questions.position";
  280. $result =api_sql_query($query, __FILE__, __LINE__);
  281. ?>
  282. <h3><?php echo stripslashes($test)?>: <?php echo get_lang("Result"); ?></h3>
  283. </td>
  284. </tr>
  285. <?php
  286. $i=$totalScore=$totalWeighting=0;
  287. if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
  288. // for each question
  289. $questionList = array();
  290. $exerciseResult = array();
  291. $k=0;
  292. $counter=0;
  293. while ($row = mysql_fetch_array($result))
  294. {
  295. $questionList[] = $row['question_id'];
  296. $exerciseResult[] = $row['answer'];
  297. }
  298. foreach($questionList as $questionId)
  299. {
  300. $counter++;
  301. $k++;
  302. $choice=$exerciseResult[$questionId];
  303. // creates a temporary Question object
  304. $objQuestionTmp = Question::read($questionId);
  305. $questionName=$objQuestionTmp->selectTitle();
  306. $questionWeighting=$objQuestionTmp->selectWeighting();
  307. $answerType=$objQuestionTmp->selectType();
  308. $quesId =$objQuestionTmp->selectId(); //added by priya saini
  309. // destruction of the Question object
  310. unset($objQuestionTmp);
  311. if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  312. {
  313. $colspan=2;
  314. }
  315. if($answerType == MATCHING || $answerType == FREE_ANSWER)
  316. {
  317. $colspan=2;
  318. }
  319. else
  320. {
  321. $colspan=2;
  322. }?>
  323. <tr bgcolor="#E6E6E6">
  324. <td colspan="2" > <?php echo get_lang("Question").' '.($counter); ?> </td>
  325. </tr>
  326. <tr>
  327. <td colspan="2"><?php echo $questionName; ?> </td>
  328. </tr>
  329. <tr>
  330. <td width="200" height="90" valign="top">
  331. <?php
  332. if($answerType == MULTIPLE_ANSWER)
  333. {
  334. $choice=array();
  335. ?>
  336. <table width="355" border="0" cellspacing="3" cellpadding="3">
  337. <tr>
  338. <td>&nbsp;</td>
  339. </tr>
  340. <tr>
  341. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  342. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  343. <td><i><?php echo get_lang("Answer"); ?></i></td>
  344. </tr>
  345. <tr>
  346. <td>&nbsp;</td>
  347. </tr>
  348. <?php
  349. // construction of the Answer object
  350. $objAnswerTmp=new Answer($questionId);
  351. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  352. $questionScore=0;
  353. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  354. {
  355. $answer=$objAnswerTmp->selectAnswer($answerId);
  356. $answerComment=$objAnswerTmp->selectComment($answerId);
  357. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  358. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  359. $queryans = "select * from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  360. $resultans = api_sql_query($queryans, __FILE__, __LINE__);
  361. while ($row = mysql_fetch_array($resultans))
  362. {
  363. $ind = $row['answer'];
  364. $choice[$ind] = 1;
  365. }
  366. $studentChoice=$choice[$answerId];
  367. if($studentChoice)
  368. {
  369. $questionScore+=$answerWeighting;
  370. $totalScore+=$answerWeighting;
  371. }
  372. ?>
  373. <tr>
  374. <td> <?php
  375. if($answerId==1)
  376. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  377. else
  378. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  379. ?>
  380. </td>
  381. </tr>
  382. <?php
  383. $i++;
  384. }?>
  385. </table>
  386. <?php }
  387. else if ($answerType == UNIQUE_ANSWER)
  388. {?>
  389. <table width="355" border="0">
  390. <tr>
  391. <td>&nbsp;</td>
  392. </tr>
  393. <tr>
  394. <td><i><?php echo get_lang("Choice"); ?></i> </td>
  395. <td><i><?php echo get_lang("ExpectedChoice"); ?></i></td>
  396. <td><i><?php echo get_lang("Answer"); ?></i></td>
  397. </tr>
  398. <tr>
  399. <td>&nbsp;</td>
  400. </tr>
  401. <?php
  402. $objAnswerTmp=new Answer($questionId);
  403. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  404. $questionScore=0;
  405. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  406. {
  407. $answer=$objAnswerTmp->selectAnswer($answerId);
  408. $answerComment=$objAnswerTmp->selectComment($answerId);
  409. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  410. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  411. $queryans = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  412. $resultans = api_sql_query($queryans, __FILE__, __LINE__);
  413. $choice = mysql_result($resultans,0,"answer");
  414. $studentChoice=($choice == $answerId)?1:0;
  415. if($studentChoice)
  416. {
  417. $questionScore+=$answerWeighting;
  418. $totalScore+=$answerWeighting;
  419. }?>
  420. <tr>
  421. <td><?php if($answerId==1)
  422. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,$answerId);
  423. else
  424. display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect,$id,$questionId,"");
  425. ?>
  426. </td>
  427. </tr><?php
  428. $i++;
  429. }?>
  430. </table>
  431. <?php }
  432. elseif($answerType == FILL_IN_BLANKS)
  433. {?>
  434. <table width="355" border="0">
  435. <tr>
  436. <td>&nbsp;</td>
  437. </tr>
  438. <tr>
  439. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  440. </tr>
  441. <tr>
  442. <td>&nbsp;</td>
  443. </tr>
  444. <?php
  445. $objAnswerTmp=new Answer($questionId);
  446. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  447. $questionScore=0;
  448. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  449. {
  450. $answer=$objAnswerTmp->selectAnswer($answerId);
  451. $answerComment=$objAnswerTmp->selectComment($answerId);
  452. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  453. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  454. list($answer,$answerWeighting)=explode('::',$answer);
  455. // splits weightings that are joined with a comma
  456. $answerWeighting=explode(',',$answerWeighting);
  457. // we save the answer because it will be modified
  458. $temp=$answer;
  459. // TeX parsing
  460. // 1. find everything between the [tex] and [/tex] tags
  461. $startlocations=strpos($temp,'[tex]');
  462. $endlocations=strpos($temp,'[/tex]');
  463. if($startlocations !== false && $endlocations !== false)
  464. {
  465. $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  466. // 2. replace this by {texcode}
  467. $temp=str_replace($texstring,'{texcode}',$temp);
  468. }
  469. $j=0;
  470. // the loop will stop at the end of the text
  471. $i=0;
  472. while(1)
  473. {
  474. // quits the loop if there are no more blanks
  475. if(($pos = strpos($temp,'[')) === false)
  476. {
  477. // adds the end of the text
  478. $answer.=$temp;
  479. // TeX parsing
  480. $texstring = api_parse_tex($texstring);
  481. break;
  482. }
  483. $temp=substr($temp,$pos+1);
  484. // quits the loop if there are no more blanks
  485. if(($pos = strpos($temp,']')) === false)
  486. {
  487. break;
  488. }
  489. $queryfill = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  490. $resfill = api_sql_query($queryfill, __FILE__, __LINE__);
  491. $str=mysql_result($resfill,0,"answer");
  492. preg_match_all ('#\[([^[/]*)/#', $str, $arr);
  493. $choice = $arr[1];
  494. $choice[$j]=trim($choice[$j]);
  495. // if the word entered by the student IS the same as the one defined by the professor
  496. if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  497. {
  498. // gives the related weighting to the student
  499. $questionScore+=$answerWeighting[$j];
  500. // increments total score
  501. $totalScore+=$answerWeighting[$j];
  502. }
  503. // else if the word entered by the student IS NOT the same as the one defined by the professor
  504. $j++;
  505. $temp=substr($temp,$pos+1);
  506. $i=$i+1;
  507. } $answer = $str;
  508. ?>
  509. <tr>
  510. <td> <?php display_fill_in_blanks_answer($answer,$id,$questionId); ?> </td>
  511. </tr><?php
  512. $i++;
  513. }?>
  514. </table>
  515. <?php }
  516. elseif($answerType == FREE_ANSWER)
  517. {?>
  518. <table width="355" border="0" cellspacing="0" cellpadding="0">
  519. <tr>
  520. <td>&nbsp;</td>
  521. </tr>
  522. <tr>
  523. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  524. </tr>
  525. <tr>
  526. <td>&nbsp;</td>
  527. </tr>
  528. <?php
  529. $objAnswerTmp=new Answer($questionId);
  530. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  531. $questionScore=0;
  532. $query = "select answer, marks from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  533. $resq=api_sql_query($query);
  534. $choice = mysql_result($resq,0,"answer");
  535. $questionScore = mysql_result($resq,0,"marks");
  536. if($questionScore==-1){
  537. $totalScore+=0;
  538. }
  539. else{
  540. $totalScore+=$questionScore;
  541. }
  542. ?>
  543. <tr>
  544. <td valign="top"><?php display_free_answer($choice, $id, $questionId);?> </td>
  545. </tr>
  546. </table>
  547. <?php }
  548. elseif($answerType == MATCHING)
  549. {?>
  550. <table width="355" height="71" border="0">
  551. <tr>
  552. <td>&nbsp;</td>
  553. </tr>
  554. <tr>
  555. <td><i><?php echo get_lang("ElementList"); ?></i> </td>
  556. <td><i><?php echo get_lang("CorrespondsTo"); ?></i></td>
  557. </tr>
  558. <tr>
  559. <td>&nbsp;</td>
  560. </tr>
  561. <?php
  562. $objAnswerTmp=new Answer($questionId);
  563. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  564. $questionScore=0;
  565. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  566. {
  567. $answer=$objAnswerTmp->selectAnswer($answerId);
  568. $answerComment=$objAnswerTmp->selectComment($answerId);
  569. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  570. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  571. $querymatch = "select * from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  572. $resmatch = api_sql_query($querymatch, __FILE__, __LINE__);
  573. while ($row = mysql_fetch_array($resmatch))
  574. {
  575. $ind = $row['position'];
  576. $answ = $row['answer'];
  577. $choice[$ind] = $answ;
  578. }
  579. if($answerCorrect)
  580. {
  581. if($answerCorrect == $choice[$answerId])
  582. {
  583. $questionScore+=$answerWeighting;
  584. $totalScore+=$answerWeighting;
  585. $choice[$answerId]=$matching[$choice[$answerId]];
  586. }
  587. elseif(!$choice[$answerId])
  588. {
  589. $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  590. }
  591. else
  592. {
  593. $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  594. }
  595. }
  596. else
  597. {
  598. $matching[$answerId]=$answer;
  599. }
  600. ?>
  601. <tr>
  602. <?php
  603. $answer=api_parse_tex($answer);
  604. //echo $answer; ?>
  605. <?php
  606. $query = "select position from `".$TABLETRACK_ATTEMPT."` where question_id = $questionId and exe_id=$id";
  607. $resapp = api_sql_query($query, __FILE__, __LINE__);
  608. while($row = mysql_fetch_array($resapp))
  609. {
  610. $tp = $row['position'];
  611. }
  612. foreach($choice as $key => $v)
  613. {
  614. if($key==$answerId)
  615. {
  616. echo "<td>".$answer."</td>";
  617. echo "<td>";
  618. echo $v.'/';
  619. }
  620. }
  621. ?> <font color="green"><b>
  622. <?php
  623. $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  624. echo $matching[$answerCorrect]; ?></b></font>
  625. </td>
  626. </tr><?php
  627. $i++;
  628. }?>
  629. </table>
  630. <?php }
  631. else if($answerType == HOTSPOT){
  632. ?>
  633. <table width="355" border="0" cellspacing="0" cellpadding="0">
  634. <tr>
  635. <td>&nbsp;</td>
  636. </tr>
  637. <tr>
  638. <td><i><?php echo get_lang("Answer"); ?></i> </td>
  639. </tr>
  640. <tr>
  641. <td>&nbsp;</td>
  642. </tr>
  643. <?php
  644. $objAnswerTmp=new Answer($questionId);
  645. $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  646. $questionScore=0;
  647. echo '
  648. <tr>
  649. <td>
  650. <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'" width="380" height="400">
  651. <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers='.$questionId.'" />
  652. </object>
  653. </td><td valign="top"><table style="border: 1px solid" width="200">';
  654. for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  655. {
  656. $answer=$objAnswerTmp->selectAnswer($answerId);
  657. $answerComment=$objAnswerTmp->selectComment($answerId);
  658. $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  659. $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  660. $query = "select answer from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  661. $resq=api_sql_query($query);
  662. $choice = mysql_result($resq,0,"answer");
  663. display_hotspot_answer($answerId,$answer,$choice,$answerComment);
  664. $i++;
  665. }
  666. $queryfree = "select marks from `".$TABLETRACK_ATTEMPT."` where exe_id = $id and question_id= $questionId";
  667. $resfree = api_sql_query($queryfree, __FILE__, __LINE__);
  668. $questionScore= mysql_result($resfree,0,"marks");
  669. $totalScore+=$questionScore;
  670. ?>
  671. </table></td></tr></table>
  672. <?php
  673. }
  674. ?>
  675. </td>
  676. <td width="346" valign = "top"><i>
  677. <?php echo get_lang("Comment"); ?></i>
  678. <?php if($is_allowedToEdit)
  679. {
  680. //if (isset($_REQUEST['showdiv']) && $questionId==$_REQUEST['ques_id'])
  681. //{
  682. $name = "fckdiv".$questionId;
  683. $marksname = "marksName".$questionId;
  684. ?>
  685. <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>
  686. <?php
  687. $comnt = get_comments($id,$questionId);
  688. echo "<br> <br>".$comnt;
  689. ?>
  690. <div id="<?php echo $name; ?>" style="visibility:hidden">
  691. <?php
  692. $arrid[] = $questionId;
  693. $fck_attribute['Width'] = '400';
  694. $fck_attribute['Height'] = '150';
  695. $fck_attribute['ToolbarSet'] = 'Comment';
  696. $fck_attribute['Config']['IMUploadPath'] = 'upload/test/';
  697. $$questionId = new FormValidator('frmcomments'.$questionId,'post','');
  698. $renderer =& $$questionId->defaultRenderer();
  699. $renderer->setFormTemplate(
  700. '<form{attributes}><div align="left">{content}</div></form>');
  701. $renderer->setElementTemplate(
  702. '<div align="left">{element}</div>'
  703. );
  704. $comnt =get_comments($id,$questionId);
  705. ${user.$questionId}['comments_'.$questionId] = $comnt;
  706. $$questionId->addElement('html_editor','comments_'.$questionId,false);
  707. //$$questionId->addElement('submit','submitQuestion',get_lang('Ok'));
  708. $$questionId->setDefaults(${user.$questionId});
  709. $$questionId->display();
  710. ?>
  711. </div>
  712. <?php
  713. }
  714. else
  715. {
  716. $comnt = get_comments($id,$questionId);
  717. echo "<br> <br>".$comnt;
  718. }
  719. ?>
  720. </td>
  721. </tr>
  722. <tr>
  723. <td></td>
  724. <td align= "left" >
  725. <?php
  726. if($is_allowedToEdit)
  727. {
  728. if ($answerType == FREE_ANSWER)
  729. {
  730. $marksname = "marksName".$questionId;
  731. ?>
  732. <div id="<?php echo $marksname; ?>" style="visibility:hidden">
  733. <form name="marksform_<?php echo $questionId; ?>" method="post" action="">
  734. <?php
  735. $arrmarks[] = $questionId;
  736. echo get_lang("AssignMarks");
  737. echo "<select name='marks' id='marks'>";
  738. for($i=0;$i<=$questionWeighting;$i++)
  739. {?>
  740. <option <?php if ($i==$questionScore) echo "selected='selected'";?>>
  741. <?php echo $i;
  742. ?></option>
  743. <?php } ?>
  744. </select>
  745. </form></div><?php
  746. if($questionScore==-1){
  747. $questionScore=0;
  748. echo '<br>'.get_lang('notCorrectedYet');
  749. }
  750. }
  751. else{
  752. $arrmarks[] = $questionId;
  753. 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>';
  754. }
  755. }?>
  756. </td><tr><td></td><td align="right"><b><?php echo get_lang('Score')." : $questionScore/$questionWeighting"; ?></b></td>
  757. </tr>
  758. <?php unset($objAnswerTmp);
  759. $i++;
  760. $totalWeighting+=$questionWeighting;
  761. }
  762. ?>
  763. <tr><td></td><td align=right><b><?php
  764. //$query = "update `".$TABLETRACK_EXERCICES."` set exe_result = $totalScore where exe_id = '$id'";
  765. //api_sql_query($query,__FILE__,__LINE__);
  766. echo '<br/>'.get_lang('YourTotalScore')." ";
  767. if($dsp_percent == true)
  768. {
  769. echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  770. }
  771. else
  772. {
  773. echo $totalScore."/".$totalWeighting;
  774. }
  775. ?> !</b>
  776. </td></tr>
  777. <tr><td></td>
  778. <td align="right">
  779. <br />
  780. <?php $strids = implode(",",$arrid);
  781. $marksid = implode(",",$arrmarks);
  782. if($is_allowedToEdit)
  783. {
  784. ?>
  785. <?php
  786. if($origin=='tests'){
  787. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'&origin=tests&student='.$_GET['student'].'&details=true&course='.$_GET['cidReq'].'" method="post">';
  788. }
  789. else{
  790. echo ' <form name="myform" id="myform" action="exercice.php?show=result&comments=update&exeid='.$id.'&test='.$test.'&emailid='.$emailId.'" method="post">';
  791. }
  792. ?>
  793. <input type="submit" value="<?php echo get_lang('Ok'); ?>" onclick="getFCK('<?php echo $strids; ?>','<?php echo $marksid; ?>');"/>
  794. </form>
  795. <?php } ?>
  796. </td>
  797. </tr>
  798. </table>