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

Source for file exercise_result.php

Documentation is available at exercise_result.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 du Corbeau, 108
  16.         B-1030 Brussels - Belgium
  17.         info@dokeos.com
  18. */
  19. /**
  20. *    Exercise result
  21. *    This script gets informations from the script "exercise_submit.php",
  22. *    through the session, and calculates the score of the student for
  23. *    that exercise.
  24. *    Then it shows the results on the screen.
  25. *    @package dokeos.exercise
  26. *    @author Olivier Brouckaert, main author
  27. *    @author Roan Embrechts, some refactoring
  28. *     @version $Id: exercise_result.php 15438 2008-05-27 06:46:30Z elixir_inter $
  29. *
  30. *    @todo    split more code up in functions, move functions to library?
  31. */
  32. /*
  33. ==============================================================================
  34.         INIT SECTION
  35. ==============================================================================
  36. */
  37. include('exercise.class.php');
  38. include('question.class.php');
  39. include('answer.class.php');
  40. if($_GET['origin']=='learnpath')
  41. {
  42.     require_once ('../newscorm/learnpath.class.php');
  43.     require_once ('../newscorm/learnpathItem.class.php');
  44.     require_once ('../newscorm/scorm.class.php');
  45.     require_once ('../newscorm/scormItem.class.php');
  46.     require_once ('../newscorm/aicc.class.php');
  47.     require_once ('../newscorm/aiccItem.class.php');
  48. }
  49.  
  50. // answer types
  51. define('UNIQUE_ANSWER',    1);
  52. define('MULTIPLE_ANSWER',    2);
  53. define('FILL_IN_BLANKS',    3);
  54. define('MATCHING',        4);
  55. define('FREE_ANSWER'5);
  56. define('HOT_SPOT'6);
  57. define('HOT_SPOT_ORDER',     7);
  58.  
  59. global $_cid;
  60. // name of the language file that needs to be included
  61. $language_file='exercice';
  62.  
  63. include('../inc/global.inc.php');
  64. $this_section=SECTION_COURSES;
  65.  
  66. /* ------------    ACCESS RIGHTS ------------ */
  67. // notice for unauthorized people.
  68.  
  69. include_once(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  70. include_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  71. include_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  72.  
  73. // Database table definitions
  74. $TBL_EXERCICE_QUESTION     Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  75. $TBL_EXERCICES             Database::get_course_table(TABLE_QUIZ_TEST);
  76. $TBL_QUESTIONS             Database::get_course_table(TABLE_QUIZ_QUESTION);
  77. $TBL_REPONSES              Database::get_course_table(TABLE_QUIZ_ANSWER);
  78. $TBL_TRACK_ATTEMPT        Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  79. $main_user_table         Database :: get_main_table(TABLE_MAIN_USER);
  80. $main_course_user_table Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  81. $table_ans                 Database :: get_course_table(TABLE_QUIZ_ANSWER);
  82.  
  83. //temp values to move to AWACS
  84. $dsp_percent false//false to display total score as absolute values
  85. //debug param. 0: no display - 1: debug display
  86. $debug=0;
  87. if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  88. // general parameters passed via POST/GET
  89. if empty $origin ) ) {
  90.      $origin $_REQUEST['origin'];
  91. }
  92. if empty $learnpath_id ) ) {
  93.      $learnpath_id       mysql_real_escape_string($_REQUEST['learnpath_id']);
  94. }
  95. if empty $learnpath_item_id ) ) {
  96.      $learnpath_item_id  mysql_real_escape_string($_REQUEST['learnpath_item_id']);
  97. }
  98. if empty $formSent ) ) {
  99.     $formSent       $_REQUEST['formSent'];
  100. }
  101. if empty $exerciseResult ) ) {
  102.      $exerciseResult $_SESSION['exerciseResult'];
  103. }
  104. if empty $questionId ) ) {
  105.     $questionId $_REQUEST['questionId'];
  106. }
  107. if empty $choice ) ) {
  108.     $choice $_REQUEST['choice'];
  109. }
  110. if empty $questionNum ) ) {
  111.    $questionNum    mysql_real_escape_string($_REQUEST['questionNum']);
  112. }
  113. if empty $nbrQuestions ) ) {
  114.     $nbrQuestions   mysql_real_escape_string($_REQUEST['nbrQuestions']);
  115. }
  116. if empty $questionList ) ) {
  117.     $questionList $_SESSION['questionList'];
  118. }
  119. if empty $objExercise ) ) {
  120.     $objExercise $_SESSION['objExercise'];
  121. }
  122. $main_user_table Database :: get_main_table(TABLE_MAIN_USER);
  123. $main_admin_table Database :: get_main_table(TABLE_MAIN_ADMIN);
  124. $courseName $_SESSION['_course']['name'];
  125. $query "select user_id from $main_admin_table";
  126. $admin_id mysql_result(api_sql_query($query),0,"user_id");
  127. $uinfo api_get_user_info($admin_id);
  128. $from $uinfo['mail'];
  129. $from_name $uinfo['firstname'].' '.$uinfo['lastname'];
  130. $str $_SERVER['REQUEST_URI'];
  131. $arr explode('/',$str);
  132. $url api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
  133.  
  134. //$url =  $_SERVER['SERVER_NAME'].'/'.$arr[1].'/';
  135.  // if the above variables are empty or incorrect, stops the script
  136. if(!is_array($exerciseResult|| !is_array($questionList|| !is_object($objExercise))
  137. {
  138.  
  139.     header('Location: exercice.php');
  140.     exit();
  141. }
  142. $exerciseTitle=$objExercise->selectTitle();
  143. $exerciseDescription=$objExercise->selectDescription();
  144. $exerciseDescription=stripslashes($exerciseDescription);
  145.  
  146.  
  147. $nameTools=get_lang('Exercice');
  148.  
  149. $interbreadcrumb[]=array("url" => "exercice.php","name" => get_lang('Exercices'));
  150.  
  151.  
  152. if ($origin != 'learnpath')
  153. {
  154.     //so we are not in learnpath tool
  155.     Display::display_header($nameTools,"Exercise");
  156. }
  157. else
  158. {
  159.  
  160.     if(empty($charset))
  161.     {
  162.         $charset 'ISO-8859-15';
  163.     }
  164.     header('Content-Type: text/html; charset='$charset);
  165.  
  166.     @$document_language Database::get_language_isocode($language_interface);
  167.     if(empty($document_language))
  168.     {
  169.       //if there was no valid iso-code, use the english one
  170.       $document_language 'en';
  171.     }
  172.  
  173.     /*
  174.      * HTML HEADER
  175.      */
  176.  
  177. ?>
  178. <!DOCTYPE html
  179.      PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
  180.      "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
  181. <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language?>" lang="<?php echo $document_language?>">
  182. <head>
  183. <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1" />
  184. </head>
  185.  
  186. <body>
  187. <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/frames.css'?>" />
  188.  
  189. <?php
  190. }
  191.  
  192.  
  193. if($objExercise->results_disabled)
  194. {
  195.     ob_start();
  196. }
  197.  
  198. /*
  199. ==============================================================================
  200.         FUNCTIONS
  201. ==============================================================================
  202. */
  203.  
  204. function display_unique_or_multiple_answer($answerType$studentChoice$answer$answerComment$answerCorrect)
  205. {
  206.     ?>
  207.     <tr>
  208.     <td width="5%" align="center">
  209.         <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'echo $studentChoice?'_on':'_off'?>.gif"
  210.         border="0" alt="" />
  211.     </td>
  212.     <td width="5%" align="center">
  213.         <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'echo $answerCorrect?'_on':'_off'?>.gif"
  214.         border="0" alt=" " />
  215.     </td>
  216.     <td width="45%" style="border-bottom: 1px solid #4171B5;">
  217.         <?php
  218.         $answer=api_parse_tex($answer);
  219.         echo $answer?>
  220.     </td>
  221.     <td width="45%" style="border-bottom: 1px solid #4171B5;">
  222.         <?php
  223.         $answerComment=api_parse_tex($answerComment);
  224.         if($studentChoiceecho nl2br(make_clickable(stripslashes($answerComment)))else echo '&nbsp;'?>
  225.     </td>
  226.     </tr>
  227.     <?php
  228. }
  229.  
  230. {
  231.     ?>
  232.         <tr>
  233.         <td>
  234.             <?php echo nl2br($answer)?>
  235.         </td>
  236.         </tr>
  237.     <?php
  238. }
  239.  
  240. function display_free_answer($answer)
  241. {
  242.     ?>
  243.         <tr>
  244.         <td width="55%">
  245.             <?php echo nl2br(stripslashes($answer))?>
  246.         </td>
  247.    <td width="45%">
  248.     <?php echo get_lang('notCorrectedYet');?>
  249.  
  250.    </td>
  251.         </tr>
  252.     <?php
  253. }
  254.  
  255. function display_hotspot_answer($answerId$answer$studentChoice$answerComment)
  256. {
  257.     //global $hotspot_colors;
  258.     $hotspot_colors array(""// $i starts from 1 on next loop (ugly fix)
  259.                                     "#4271B5",
  260.                                     "#FE8E16",
  261.                                     "#3B3B3B",
  262.                                     "#BCD631",
  263.                                     "#D63173",
  264.                                     "#D7D7D7",
  265.                                     "#90AFDD",
  266.                                     "#AF8640",
  267.                                     "#4F9242",
  268.                                     "#F4EB24",
  269.                                     "#ED2024",
  270.                                     "#45C7F0",
  271.                                     "#F7BDE2");
  272.     ?>
  273.         <tr>
  274.                 <td valign="top">
  275.                     <div style="float:left; padding-left:5px;">
  276.                         <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
  277.                         <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]?>; display:inline; float:left; margin-top:3px;"></div>
  278.                     </div>
  279.                 </td>
  280.                 <td valign="top"><?php echo $answerId?></td>
  281.                 <td valign="top">
  282.                     <?php $studentChoice ($studentChoice)?get_lang('Correct'):get_lang('Fault')echo $studentChoice?>
  283.                 </td>
  284.                 <td valign="top">
  285.                     <?php echo stripslashes($answerComment)?>
  286.                 </td>
  287.         </tr>
  288.     <?php
  289. }
  290.  
  291. /*
  292. ==============================================================================
  293.         MAIN CODE
  294. ==============================================================================
  295. */
  296. $exerciseTitle=api_parse_tex($exerciseTitle);
  297.  
  298. ?>
  299.     <h3><?php echo $exerciseTitle ?><?php echo get_lang("Result")?></h3>
  300.     <?php echo $exerciseDescription?>
  301.     <form method="get" action="exercice.php">
  302.     <input type="hidden" name="origin" value="<?php echo $origin?>" />
  303.     <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id?>" />
  304.     <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id?>" />
  305.  
  306. <?php
  307.     $i=$totalScore=$totalWeighting=0;
  308.     if($debug>0){echo "ExerciseResult: "var_dump($exerciseResult)echo "QuestionList: ";var_dump($questionList);}
  309.  
  310.  
  311.     // added by Priya Saini
  312.     $sql "select max(exe_Id) as id from ".$TBL_TRACK_EXERCICES;
  313.     $res api_sql_query($sql__FILE____LINE__);
  314.     $exeId =mysql_result($res,0,"id");
  315.     $exeId=$exeId+1;
  316.     
  317.     $counter=0;
  318.     foreach($questionList as $questionId)
  319.     {
  320.         $counter++;
  321.         // gets the student choice for this question
  322.         $choice=$exerciseResult[$questionId];
  323.         // creates a temporary Question object
  324.  
  325.         $objQuestionTmp Question :: read($questionId);
  326.  
  327.         $questionName=$objQuestionTmp->selectTitle();
  328.         $questionDescription=$objQuestionTmp->selectDescription();
  329.         $questionWeighting=$objQuestionTmp->selectWeighting();
  330.         $answerType=$objQuestionTmp->selectType();
  331.         $quesId =$objQuestionTmp->selectId()//added by priya saini
  332.  
  333.         // destruction of the Question object
  334.         unset($objQuestionTmp);
  335.  
  336.         if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  337.         {
  338.             $colspan=4;
  339.         }
  340.         elseif($answerType == MATCHING || $answerType == FREE_ANSWER)
  341.         {
  342.             $colspan=2;
  343.         }
  344.         elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  345.         {
  346.             $colspan=4;
  347.             $rowspan=$nbrAnswers+1;
  348.         }
  349.         else
  350.         {
  351.             $colspan=1;
  352.         }
  353.         ?>
  354.             <table width="100%" border="0" cellpadding="3" cellspacing="2">
  355.             <tr bgcolor="#E6E6E6">
  356.             <td colspan="<?php echo $colspan?>">
  357.                 <?php echo get_lang("Question").' '.($counter).' : '.$questionName?>
  358.             </td>
  359.             </tr>
  360.             <tr>
  361.             <td colspan="<?php echo $colspan?>">
  362.                 <i>
  363.                 <?php echo $questionDescription?>
  364.                 </i>
  365.             </td>
  366.             </tr>
  367.         <?php
  368.         if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  369.         {
  370.             ?>
  371.                 <tr>
  372.                 <td width="5%" valign="top" align="center" nowrap="nowrap">
  373.                     <i><?php echo get_lang("Choice")?></i>
  374.                 </td>
  375.                 <td width="5%" valign="top" nowrap="nowrap">
  376.                     <i><?php echo get_lang("ExpectedChoice")?></i>
  377.                 </td>
  378.                 <td width="45%" valign="top">
  379.                     <i><?php echo get_lang("Answer")?></i>
  380.                 </td>
  381.                 <td width="45%" valign="top">
  382.                     <i><?php echo get_lang("Comment")?></i>
  383.                 </td>
  384.                 </tr>
  385.             <?php
  386.         }
  387.         elseif($answerType == FILL_IN_BLANKS)
  388.         {
  389.             ?>
  390.                 <tr>
  391.                 <td>
  392.                     <i><?php echo get_lang("Answer")?></i>
  393.                 </td>
  394.                 </tr>
  395.             <?php
  396.         }
  397.         elseif($answerType == FREE_ANSWER)
  398.         {
  399.             ?>
  400.                 <tr>
  401.                 <td width="55%">
  402.                     <i><?php echo get_lang("Answer")?></i>
  403.                 </td>
  404.                 <td width="45%" valign="top">
  405.                     <i><?php echo get_lang("Comment")?></i>
  406.                 </td>
  407.                 </tr>
  408.             <?php
  409.         }
  410.         elseif($answerType == HOT_SPOT)
  411.         {
  412.             ?>
  413.                 <tr>
  414.                     <td valign="top" colspan="2">
  415.                         <table width="556" border="0">
  416.                             <tr>
  417.                                 <td width="40%" valign="top">
  418.                                     <i><?php echo get_lang("CorrectAnswer")?></i><br /><br />
  419.                                 </td>
  420.                                 <td width="15%" valign="top">
  421.                                     <i><?php echo get_lang("ClickNumber")?></i><br /><br />
  422.                                 </td>
  423.                                 <td width="20%" valign="top">
  424.                                     <i><?php echo get_lang('HotspotHit')?></i><br /><br />
  425.                                 </td>
  426.                                 <td width="25%" valign="top">
  427.                                     <i><?php echo get_lang("Comment")?></i><br /><br />
  428.                                 </td>
  429.                             </tr>
  430.             <?php
  431.         }
  432.         else
  433.         {
  434.             ?>
  435.                 <tr>
  436.                 <td width="50%">
  437.                     <i><?php echo get_lang("ElementList")?></i>
  438.                 </td>
  439.                 <td width="50%">
  440.                     <i><?php echo get_lang("CorrespondsTo")?></i>
  441.                 </td>
  442.                 </tr>
  443.             <?php
  444.         }
  445.  
  446.         // construction of the Answer object
  447.         $objAnswerTmp=new Answer($questionId);
  448.         $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
  449.         $questionScore=0;
  450.         if($answerType == FREE_ANSWER)
  451.             $nbrAnswers 1;
  452.         for($answerId=1;$answerId <= $nbrAnswers;$answerId++)
  453.         {
  454.             $answer=$objAnswerTmp->selectAnswer($answerId);
  455.             $answerComment=$objAnswerTmp->selectComment($answerId);
  456.             $answerCorrect=$objAnswerTmp->isCorrect($answerId);
  457.             $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
  458.  
  459.             switch($answerType)
  460.             {
  461.                 // for unique answer
  462.                 case UNIQUE_ANSWER :
  463.                                         $studentChoice=($choice == $answerId)?1:0;
  464.  
  465.                                         if($studentChoice)
  466.                                         {
  467.                                               $questionScore+=$answerWeighting;
  468.                                             $totalScore+=$answerWeighting;
  469.                                         }
  470.  
  471.  
  472.                                         break;
  473.                 // for multiple answers
  474.                 case MULTIPLE_ANSWER :
  475.  
  476.                                         $studentChoice=$choice[$answerId];
  477.  
  478.                                         if($studentChoice)
  479.                                         {
  480.                                             $questionScore+=$answerWeighting;
  481.                                             $totalScore+=$answerWeighting;
  482.                                         }
  483.  
  484.                                         break;
  485.                 // for fill in the blanks
  486.                 case FILL_IN_BLANKS :    // splits text and weightings that are joined with the character '::'
  487.  
  488.                                         list($answer,$answerWeighting)=explode('::',$answer);
  489.  
  490.                                         // splits weightings that are joined with a comma
  491.                                         $answerWeighting=explode(',',$answerWeighting);
  492.  
  493.                                         // we save the answer because it will be modified
  494.  
  495.                                         $temp=$answer;
  496.  
  497.                                         // TeX parsing
  498.                                         // 1. find everything between the [tex] and [/tex] tags
  499.                                          $startlocations=strpos($temp,'[tex]');
  500.                                         $endlocations=strpos($temp,'[/tex]');
  501.  
  502.                                         if($startlocations !== false && $endlocations !== false)
  503.                                         {
  504.  
  505.                                             $texstring=substr($temp,$startlocations,$endlocations-$startlocations+6);
  506.                                             // 2. replace this by {texcode}
  507.                                             $temp=str_replace($texstring,'{texcode}',$temp);
  508.                                         }
  509.  
  510.                                         $answer='';
  511.  
  512.  
  513.                                         $j=0;
  514.  
  515.                                         // the loop will stop at the end of the text
  516.                                         while(1)
  517.                                         {
  518.  
  519.                                             // quits the loop if there are no more blanks
  520.                                             if(($pos strpos($temp,'[')) === false)
  521.                                             {
  522.                                                 // adds the end of the text
  523.                                                  $answer.=$temp;
  524.                                                 // TeX parsing
  525.                                                 $texstring api_parse_tex($texstring);
  526.                                                 $answer=str_replace("{texcode}",$texstring,$answer);
  527.                                                 break;
  528.                                             }
  529.  
  530.                                             // adds the piece of text that is before the blank and ended by [
  531.                                             $answer.=substr($temp,0,$pos+1);
  532.                                             $temp=substr($temp,$pos+1);
  533.  
  534.                                             // quits the loop if there are no more blanks
  535.                                             if(($pos strpos($temp,']')) === false)
  536.                                             {
  537.  
  538.                                                 // adds the end of the text
  539.                                                 $answer.=$temp;
  540.                                                 break;
  541.                                             }
  542.  
  543.                                             $choice[$j]=trim($choice[$j]);
  544.  
  545.                                             // if the word entered by the student IS the same as the one defined by the professor
  546.                                             if(strtolower(substr($temp,0,$pos)) == stripslashes(strtolower($choice[$j])))
  547.                                             {
  548.                                                 // gives the related weighting to the student
  549.                                                 $questionScore+=$answerWeighting[$j];
  550.  
  551.                                                 // increments total score
  552.                                                 $totalScore+=$answerWeighting[$j];
  553.  
  554.                                                 // adds the word in green at the end of the string
  555.                                                 $answer.=stripslashes($choice[$j]);
  556.                                             }
  557.                                             // else if the word entered by the student IS NOT the same as the one defined by the professor
  558.                                             elseif(!empty($choice[$j]))
  559.                                             {
  560.                                                 // adds the word in red at the end of the string, and strikes it
  561.                                                 $answer.='<font color="red"><s>'.stripslashes($choice[$j]).'</s></font>';
  562.                                             }
  563.                                             else
  564.                                             {
  565.                                                 // adds a tabulation if no word has been typed by the student
  566.                                                 $answer.='&nbsp;&nbsp;&nbsp;';
  567.                                             }
  568.  
  569.                                             // adds the correct word, followed by ] to close the blank
  570.                                             $answer.=' / <font color="green"><b>'.substr($temp,0,$pos).'</b></font>]';
  571.  
  572.                                             $j++;
  573.  
  574.                                             $temp=substr($temp,$pos+1);
  575.                                         }
  576.  
  577.                                         break;
  578.                 // for free answer
  579.                 case FREE_ANSWER :
  580.                                         $studentChoice=$choice;
  581.  
  582.                                         if($studentChoice)
  583.                                         {
  584.                                             //Score is at -1 because the question has'nt been corected
  585.                                               $questionScore=-1;
  586.                                             $totalScore+=0;
  587.                                         }
  588.  
  589.  
  590.                                         break;
  591.                 // for matching
  592.                 case MATCHING :
  593.                                         if($answerCorrect)
  594.                                         {
  595.                                             if($answerCorrect == $choice[$answerId])
  596.                                             {
  597.                                                 $questionScore+=$answerWeighting;
  598.                                                 $totalScore+=$answerWeighting;
  599.                                                 $choice[$answerId]=$matching[$choice[$answerId]];
  600.                                             }
  601.                                             elseif(!$choice[$answerId])
  602.                                             {
  603.                                                 $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
  604.                                             }
  605.                                             else
  606.                                             {
  607.                                                 $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
  608.                                             }
  609.                                         }
  610.                                         else
  611.                                         {
  612.                                             $matching[$answerId]=$answer;
  613.                                         }
  614.                                         break;
  615.                 // for hotspot with no order
  616.                 case HOT_SPOT :            $studentChoice=$choice[$answerId];
  617.  
  618.                                         if($studentChoice)
  619.                                         {
  620.                                             $questionScore+=$answerWeighting;
  621.                                             $totalScore+=$answerWeighting;
  622.                                         }
  623.  
  624.                                         break;
  625.                 // for hotspot with fixed order
  626.                 case HOT_SPOT_ORDER :    $studentChoice=$choice['order'][$answerId];
  627.  
  628.                                         if($studentChoice == $answerId)
  629.                                         {
  630.                                             $questionScore+=$answerWeighting;
  631.                                             $totalScore+=$answerWeighting;
  632.                                             $studentChoice true;
  633.                                         }
  634.                                         else
  635.                                         {
  636.                                             $studentChoice false;
  637.                                         }
  638.  
  639.                                         break;
  640.             // end switch Answertype
  641.             
  642.             if($answerType != MATCHING || $answerCorrect)
  643.             {
  644.                 if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER)
  645.                 {
  646.                     display_unique_or_multiple_answer($answerType$studentChoice$answer$answerComment$answerCorrect);
  647.                 }
  648.                 elseif($answerType == FILL_IN_BLANKS)
  649.                 {
  650.                     display_fill_in_blanks_answer($answer);
  651.                 }
  652.                 elseif($answerType == FREE_ANSWER)
  653.                 {
  654.                     // to store the details of open questions in an array to be used in mail
  655.  
  656.                     $arrques[$questionName;
  657.                     $arrans[]  $choice;
  658.                     $firstName =   $_SESSION['_user']['firstName'];
  659.                     $lastName =   $_SESSION['_user']['lastName'];
  660.                     $mail =  $_SESSION['_user']['mail'];
  661.                     $coursecode =  $_SESSION['_course']['id'];
  662.                     $to '';
  663.                     $teachers array();
  664.                     if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
  665.                     {
  666.                         $teachers CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
  667.                     }
  668.                     else
  669.                     {
  670.                         $teachers CourseManager::get_teacher_list_from_course_code($coursecode);
  671.                     }
  672.                     $num count($teachers);
  673.                     if($num>1)
  674.                     {
  675.                         $to array();
  676.                         foreach($teachers as $teacher)
  677.                         {
  678.                             $to[$teacher['email'];
  679.                         }
  680.                     }elseif($num>0){
  681.                         foreach($teachers as $teacher)
  682.                         {
  683.                             $to $teacher['email'];
  684.                         }
  685.                     }else{
  686.                         //this is a problem (it means that there is no admin for this course)
  687.                     }
  688.                     display_free_answer($choice);
  689.                 }
  690.                 elseif($answerType == HOT_SPOT)
  691.                 {
  692.                     
  693.                     $tbl_track_e_hotspot Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_HOTSPOT);
  694.                     // Save into db
  695.                     $sql "INSERT INTO $tbl_track_e_hotspot (`hotspot_user_id` , `hotspot_course_code` , `hotspot_exe_id` , `hotspot_question_id` , `hotspot_answer_id` , `hotspot_correct` , `hotspot_coordinate` ) 
  696.                             VALUES ('".$_user['user_id']."', '".$_course['id']."', '$exeId', '$questionId', '$answerId', '$studentChoice', '".$_SESSION['exerciseResultCoordinates'][$questionId][$answerId]."')";
  697.                 
  698.                     $result api_sql_query($sql,__FILE__,__LINE__);
  699.                     
  700.                     display_hotspot_answer($answerId$answer$studentChoice$answerComment);
  701.                 }
  702.                 elseif($answerType == HOT_SPOT_ORDER)
  703.                 {
  704.                     display_hotspot_order_answer($answerId$answer$studentChoice$answerComment);
  705.                 }
  706.                 else
  707.                 {
  708.                     ?>
  709.                         <tr>
  710.                         <td width="50%">
  711.                             <?php
  712.                             $answer=api_parse_tex($answer);
  713.                             echo $answer?>
  714.                         </td>
  715.                         <td width="50%">
  716.                             <?php echo $choice[$answerId]?> / <font color="green"><b>
  717.                             <?php
  718.                             $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
  719.                             echo $matching[$answerCorrect]?></b></font>
  720.                         </td>
  721.                         </tr>
  722.                     <?php
  723.                 }
  724.             }
  725.         // end for that loops over all answers of the current question
  726.  
  727.         if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER)
  728.             {
  729.                 // We made an extra table for the answers
  730.                 echo "</table></td></tr>";
  731.                 ?>
  732.                 
  733.                 <tr>
  734.                     <td colspan="2">
  735.                         <i><?php echo get_lang('Hotspot')?></i><br /><br />
  736.                         <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" width="556" height="421">
  737.                             <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo $questionId ?>&exe_id=&from_db=0" />
  738.                         </object>
  739.                     </td>
  740.                 </tr>
  741.                 <?php 
  742.             }
  743.         ?>
  744.             <tr>
  745.             <td colspan="<?php echo $colspan?>" align="left">
  746.                 <b>
  747.                 <?php
  748.                 if($questionScore==-1)
  749.                     echo get_lang('Score')." : 0/$questionWeighting";
  750.                 }
  751.                 else{
  752.                     echo get_lang('Score')." : $questionScore/$questionWeighting";
  753.                 }
  754.                 ?></b><br /><br />
  755.             </td>
  756.             </tr>
  757.             </table>
  758.         <?php
  759.         // destruction of Answer
  760.         unset($objAnswerTmp);
  761.  
  762.         $i++;
  763.  
  764.         $totalWeighting+=$questionWeighting;
  765.         //added by priya saini
  766.         if($_configuration['tracking_enabled'])
  767.         {
  768.             if(empty($choice)){
  769.                 $choice 0;
  770.             }
  771.             if ($answerType==MULTIPLE_ANSWER )
  772.             {
  773.                 $reply array_keys($choice);
  774.                 for ($i=0;$i<sizeof($reply);$i++)
  775.                 {
  776.                     $ans $reply[$i];
  777.                     exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
  778.                 }
  779.             }
  780.             elseif ($answerType==MATCHING)
  781.             {
  782.                 $j=sizeof($matching)+1;
  783.  
  784.                 for ($i=0;$i<sizeof($choice);$i++,$j++)
  785.                 {
  786.                     $val $choice[$j];
  787.                     if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#'$val$arr1))
  788.                         $val $arr1[1][0];
  789.                     $val=addslashes($val);
  790.                     $val=strip_tags($val);
  791.                     $sql "select position from $table_ans where question_id=$questionId and answer='$val' AND correct=0";
  792.                     $res api_sql_query($sql__FILE____LINE__);
  793.                     $answer mysql_result($res,0,"position");                
  794.                     
  795.                     exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
  796.  
  797.                 }
  798.             }
  799.             elseif ($answerType==FREE_ANSWER)
  800.             {
  801.                 $answer $choice;
  802.                 exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  803.             }
  804.             elseif ($answerType==UNIQUE_ANSWER)
  805.             {
  806.                 $sql "select id from $table_ans where question_id=$questionId and position=$choice";
  807.                 $res api_sql_query($sql__FILE____LINE__);
  808.                 $answer mysql_result($res,0,"id");
  809.                 exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  810.             }
  811.             else
  812.             {
  813.                 exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
  814.             }
  815.         }
  816.     // end huge foreach() block that loops over all questions
  817.     ?>
  818.         <table width="100%" border="0" cellpadding="3" cellspacing="2">
  819.         <tr>
  820.         <td>
  821.             <b><?php echo get_lang('YourTotalScore')." ";
  822.             if($dsp_percent == true){
  823.               echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
  824.             }else{
  825.               echo $totalScore."/".$totalWeighting;
  826.             }
  827.                         ?></b>
  828.         </td>
  829.         </tr>
  830.         <tr>
  831.         <td>
  832.         <br />
  833.             <?php
  834.             if ($origin != 'learnpath')
  835.             {
  836.             ?>
  837.             <input type="submit" value="<?php echo get_lang('Finish')?>" />
  838.             <?php
  839.             }
  840.             ?>
  841.         </td>
  842.         </tr>
  843.         </table>
  844.  
  845.         </form>
  846.  
  847.         <br />
  848.     <?php
  849. /*
  850. ==============================================================================
  851.         Tracking of results
  852. ==============================================================================
  853. */
  854.  
  855. if($_configuration['tracking_enabled'])
  856. {
  857.     //include(api_get_path(LIBRARY_PATH).'events.lib.inc.php');
  858.     event_exercice($objExercise->selectId(),$totalScore,$totalWeighting,$answer,$question_id);
  859.  
  860. }
  861.  
  862. if($objExercise->results_disabled)
  863. {
  864.     ob_end_clean();
  865.     Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
  866. }
  867.  
  868. if ($origin != 'learnpath')
  869. {
  870.     //we are not in learnpath tool
  871. }else{
  872.     //record the results in the learning path, using the SCORM interface (API)
  873.     echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
  874.     echo '</body></html>';
  875. }
  876. $send_email api_get_course_setting('email_alert_manager_on_new_quiz');
  877. if ($send_email && count($arrques)>0)
  878. {
  879. $mycharset api_get_setting('platform_charset')
  880. $msg '<html><head>
  881.     <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
  882.     <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
  883. $msg .= '</head>
  884. <body><br />
  885. <p>'.get_lang('OpenQuestionsAttempted').' : 
  886. </p>
  887. <p>'.get_lang('AttemptDetails').' : ><br />
  888. </p>
  889. <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
  890.                     <tr>
  891.     <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
  892.     <td width="469" valign="top"><h2>#course#</h2></td>
  893.   </tr>
  894.   <tr>
  895.     <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
  896.     <td width="469" valign="top" class="outerframe">#exercise#</td>
  897.   </tr>
  898.   <tr>
  899.     <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
  900.     <td valign="top" >#firstName# #lastName#</td>
  901.   </tr>
  902.   <tr>
  903.     <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
  904.     <td valign="top"> #mail#</td>
  905. </tr></table>
  906. <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
  907.  <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
  908.   for($i=0;$i<sizeof($arrques);$i++)
  909.   {
  910.       $msg.='
  911.         <tr>
  912.         <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
  913.         <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
  914.           </tr>
  915.           <tr>
  916.         <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
  917.         <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
  918.           </tr>';
  919.     
  920.         $msg1str_replace("#exercise#",$exerciseTitle,$msg);
  921.         $msgstr_replace("#firstName#",$firstName,$msg1);
  922.         $msg1str_replace("#lastName#",$lastName,$msg);
  923.         $msgstr_replace("#mail#",$mail,$msg1);
  924.         $msg1str_replace("#questionName#",$arrques[$i],$msg);
  925.         $msgstr_replace("#answer#",$arrans[$i],$msg1);
  926.         $msg1str_replace("#i#",$i,$msg);
  927.         $msgstr_replace("#course#",$courseName,$msg1);
  928.     }
  929.     $msg.='</table><br>
  930.      <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
  931. <a href="#url#">#url#</a></span></body></html>';
  932.  
  933.     $msg1str_replace("#url#",$url,$msg);
  934.     $mail_content stripslashes($msg1);
  935.     $student_name $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
  936.     $subject get_lang('OpenQuestionsAttempted');
  937.     api_mail_html($student_name$to$subject$mail_content$from_name$fromarray('encoding'=>$mycharset,'charset'=>$mycharset));
  938. }
  939. ?>

Documentation generated on Thu, 12 Jun 2008 13:26:41 -0500 by phpDocumentor 1.4.1