dokeos-exercise
[ class tree: dokeos-exercise ] [ index: dokeos-exercise ] [ all elements ]

Source for file exercise_show.php

Documentation is available at exercise_show.php

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

Documentation generated on Thu, 12 Jun 2008 13:27:10 -0500 by phpDocumentor 1.4.1