exercise_show.php 27 KB

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