Dokeos PHP Cross Reference Learning Management Systems

Source: /main/exercice/exercise_result.php - 1517 lines - 51968 bytes - Summary - Text - Print

Description: Exercise result This script gets informations from the script "exercise_submit.php", through the session, and calculates the score of the student for that exercise. Then it shows the results on the screen.

   1  <?php
   2  /*
   3  ==============================================================================
   4      Dokeos - elearning and course management software
   5  
   6      Copyright (c) 2008 Dokeos SPRL
   7  
   8      For a full list of contributors, see "credits.txt".
   9      The full license can be read in "license.txt".
  10  
  11      This program is free software; you can redistribute it and/or
  12      modify it under the terms of the GNU General Public License
  13      as published by the Free Software Foundation; either version 2
  14      of the License, or (at your option) any later version.
  15  
  16      See the GNU General Public License for more details.
  17  
  18      Contact address: Dokeos, rue du Corbeau, 108, B-1030 Brussels, Belgium
  19      Mail: info@dokeos.com
  20  ==============================================================================
  21  */
  22  /**
  23  *    Exercise result
  24  *    This script gets informations from the script "exercise_submit.php",
  25  *    through the session, and calculates the score of the student for
  26  *    that exercise.
  27  *    Then it shows the results on the screen.
  28  *    @package dokeos.exercise
  29  *    @author Olivier Brouckaert, main author
  30  *    @author Roan Embrechts, some refactoring
  31  *     @author Julio Montoya Armas switchable fill in blank option added
  32  *     @version $Id: exercise_result.php 22201 2009-07-17 19:57:03Z cfasanando $
  33  *
  34  *    @todo    split more code up in functions, move functions to library?
  35  */
  36  /*
  37  ==============================================================================
  38          INIT SECTION
  39  ==============================================================================
  40  */
  41  require_once ('exercise.class.php');
  42  require_once ('question.class.php');
  43  require_once ('answer.class.php');
  44  if ($_GET['origin']=='learnpath') {
  45      require_once  ('../newscorm/learnpath.class.php');
  46      require_once  ('../newscorm/learnpathItem.class.php');
  47      require_once  ('../newscorm/scorm.class.php');
  48      require_once  ('../newscorm/scormItem.class.php');
  49      require_once  ('../newscorm/aicc.class.php');
  50      require_once  ('../newscorm/aiccItem.class.php');
  51  }
  52  global $_cid;
  53  // name of the language file that needs to be included
  54  $language_file=array('exercice','tracking');
  55  
  56  require ('../inc/global.inc.php');
  57  $this_section=SECTION_COURSES;
  58  
  59  /* ------------    ACCESS RIGHTS ------------ */
  60  // notice for unauthorized people.
  61  api_protect_course_script(true);
  62  
  63  require_once(api_get_path(LIBRARY_PATH).'mail.lib.inc.php');
  64  require_once(api_get_path(LIBRARY_PATH).'course.lib.php');
  65  //$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.js" type="text/javascript" language="javascript"></script>';
  66  //$htmlHeadXtra[] = '<script src="'.api_get_path(WEB_LIBRARY_PATH).'javascript/jquery.corners.min.js" type="text/javascript"></script>';
  67  
  68  // Database table definitions
  69  $TBL_EXERCICE_QUESTION     = Database::get_course_table(TABLE_QUIZ_TEST_QUESTION);
  70  $TBL_EXERCICES             = Database::get_course_table(TABLE_QUIZ_TEST);
  71  $TBL_QUESTIONS             = Database::get_course_table(TABLE_QUIZ_QUESTION);
  72  $TBL_REPONSES              = Database::get_course_table(TABLE_QUIZ_ANSWER);
  73  $TBL_TRACK_EXERCICES    = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_EXERCICES);
  74  $TBL_TRACK_ATTEMPT        = Database::get_statistic_table(TABLE_STATISTIC_TRACK_E_ATTEMPT);
  75  $main_user_table         = Database :: get_main_table(TABLE_MAIN_USER);
  76  $main_course_user_table = Database :: get_main_table(TABLE_MAIN_COURSE_USER);
  77  $table_ans                 = Database :: get_course_table(TABLE_QUIZ_ANSWER);
  78  
  79  //temp values to move to admin settings
  80  $dsp_percent = false; //false to display total score as absolute values
  81  //debug param. 0: no display - 1: debug display
  82  $debug=0;
  83  if($debug>0){echo str_repeat('&nbsp;',0).'Entered exercise_result.php'."<br />\n";var_dump($_POST);}
  84  // general parameters passed via POST/GET
  85  if ( empty ( $origin ) ) {
  86       $origin = Security::remove_XSS($_REQUEST['origin']);
  87  }
  88  if ( empty ( $learnpath_id ) ) {
  89       $learnpath_id       = Security::remove_XSS($_REQUEST['learnpath_id']);
  90  }
  91  if ( empty ( $learnpath_item_id ) ) {
  92       $learnpath_item_id  = Security::remove_XSS($_REQUEST['learnpath_item_id']);
  93  }
  94  if ( empty ( $formSent ) ) {
  95      $formSent       = $_REQUEST['formSent'];
  96  }
  97  if ( empty ( $exerciseResult ) ) {
  98       $exerciseResult = $_SESSION['exerciseResult'];
  99  }
 100  if ( empty ( $exerciseResultCoordinates ) ) {
 101       $exerciseResultCoordinates = $_SESSION['exerciseResultCoordinates'];
 102  }
 103  if ( empty ( $questionId ) ) {
 104      $questionId = $_REQUEST['questionId'];
 105  }
 106  if ( empty ( $choice ) ) {
 107      $choice = $_REQUEST['choice'];
 108  }
 109  if ( empty ( $questionNum ) ) {
 110     $questionNum    = $_REQUEST['questionNum'];
 111  }
 112  if ( empty ( $nbrQuestions ) ) {
 113      $nbrQuestions   = $_REQUEST['nbrQuestions'];
 114  }
 115  if ( empty ( $questionList ) ) {
 116      $questionList = $_SESSION['questionList'];
 117  }
 118  if ( empty ( $objExercise ) ) {
 119      $objExercise = $_SESSION['objExercise'];
 120  }
 121  if ( empty ( $exerciseType ) ) {
 122      $exerciseType = $_REQUEST['exerciseType'];
 123  }
 124  
 125  $course_code = api_get_course_id();
 126  if(isset($_SESSION['expired_time'][$course_code][intval($_SESSION['id_session'])][$objExercise->id][$learnpath_id]))
 127  {
 128      unset($_SESSION['expired_time'][$course_code][intval($_SESSION['id_session'])][$objExercise->id][$learnpath_id]);
 129  }
 130  
 131  $_configuration['live_exercise_tracking'] = false;
 132  if($_configuration['live_exercise_tracking']) define('ENABLED_LIVE_EXERCISE_TRACKING',1);
 133  
 134  if($_configuration['live_exercise_tracking'] == true && $exerciseType == 1){
 135      $_configuration['live_exercise_tracking'] = false;
 136  }
 137  
 138  // set admin name as person who sends the results e-mail (lacks policy about whom should really send the results)
 139  $main_user_table = Database :: get_main_table(TABLE_MAIN_USER);
 140  $main_admin_table = Database :: get_main_table(TABLE_MAIN_ADMIN);
 141  $courseName = $_SESSION['_course']['name'];
 142  $query = "SELECT user_id FROM $main_admin_table LIMIT 1"; //get all admins from admin table
 143  $admin_id = Database::result(api_sql_query($query),0,"user_id");
 144  $uinfo = api_get_user_info($admin_id);
 145  $from = $uinfo['mail'];
 146  $from_name = $uinfo['firstname'].' '.$uinfo['lastname'];
 147  $str = $_SERVER['REQUEST_URI'];
 148  $url = api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'&show=result';
 149  
 150   // if the above variables are empty or incorrect, we don't have any result to show, so stop the script
 151  if(!is_array($exerciseResult) || !is_array($questionList) || !is_object($objExercise)) {
 152  
 153      header('Location: exercice.php');
 154      exit();
 155  }
 156  
 157  $sql_fb_type='SELECT feedback_type FROM '.$TBL_EXERCICES.' WHERE id ="'.Database::escape_string($objExercise->selectId()).'"';
 158  
 159  $res_fb_type=Database::query($sql_fb_type,__FILE__,__LINE__);
 160  $row_fb_type=Database::fetch_row($res_fb_type);
 161  $feedback_type = $row_fb_type[0];
 162  
 163  // define basic exercise info to print on screen
 164  $exerciseTitle=$objExercise->selectTitle();
 165  $exerciseDescription=$objExercise->selectDescription();
 166  
 167  $gradebook = '';
 168  if (isset($_SESSION['gradebook'])){
 169      $gradebook=    $_SESSION['gradebook'];
 170  }
 171  
 172  if (!empty($gradebook) && $gradebook=='view') {    
 173      $interbreadcrumb[]= array (
 174              'url' => '../gradebook/'.$_SESSION['gradebook_dest'],
 175              'name' => get_lang('Gradebook')
 176          );
 177  }
 178  
 179  $nameTools=get_lang('Exercice');
 180  
 181  $interbreadcrumb[]=array("url" => "exercice.php?gradebook=$gradebook","name" => get_lang('Exercices'));
 182  $htmlHeadXtra[] = "<script type=\"text/javascript\" src=\"../plugin/hotspot/JavaScriptFlashGateway.js\"></script>
 183                      <script src=\"../plugin/hotspot/hotspot.js\" type=\"text/javascript\"></script>
 184                      <script language=\"JavaScript\" type=\"text/javascript\">
 185                      <!--
 186                      // -----------------------------------------------------------------------------
 187                      // Globals
 188                      // Major version of Flash required
 189                      var requiredMajorVersion = 7;
 190                      // Minor version of Flash required
 191                      var requiredMinorVersion = 0;
 192                      // Minor version of Flash required
 193                      var requiredRevision = 0;
 194                      // the version of javascript supported
 195                      var jsVersion = 1.0;
 196                      // -----------------------------------------------------------------------------
 197                      // -->
 198                      </script>
 199                      <script language=\"VBScript\" type=\"text/vbscript\">
 200                      <!-- // Visual basic helper required to detect Flash Player ActiveX control version information
 201                      Function VBGetSwfVer(i)
 202                        on error resume next
 203                        Dim swControl, swVersion
 204                        swVersion = 0
 205  
 206                        set swControl = CreateObject(\"ShockwaveFlash.ShockwaveFlash.\" + CStr(i))
 207                        if (IsObject(swControl)) then
 208                          swVersion = swControl.GetVariable(\"\$version\")
 209                        end if
 210                        VBGetSwfVer = swVersion
 211                      End Function
 212                      // -->
 213                      </script>
 214  
 215                      <script language=\"JavaScript1.1\" type=\"text/javascript\">
 216                      <!-- // Detect Client Browser type
 217                      var isIE  = (navigator.appVersion.indexOf(\"MSIE\") != -1) ? true : false;
 218                      var isWin = (navigator.appVersion.toLowerCase().indexOf(\"win\") != -1) ? true : false;
 219                      var isOpera = (navigator.userAgent.indexOf(\"Opera\") != -1) ? true : false;
 220                      jsVersion = 1.1;
 221                      // JavaScript helper required to detect Flash Player PlugIn version information
 222  					function JSGetSwfVer(i){
 223                          // NS/Opera version >= 3 check for Flash plugin in plugin array
 224                          if (navigator.plugins != null && navigator.plugins.length > 0) {
 225                              if (navigator.plugins[\"Shockwave Flash 2.0\"] || navigator.plugins[\"Shockwave Flash\"]) {
 226                                  var swVer2 = navigator.plugins[\"Shockwave Flash 2.0\"] ? \" 2.0\" : \"\";
 227                                    var flashDescription = navigator.plugins[\"Shockwave Flash\" + swVer2].description;
 228                                  descArray = flashDescription.split(\" \");
 229                                  tempArrayMajor = descArray[2].split(\".\");
 230                                  versionMajor = tempArrayMajor[0];
 231                                  versionMinor = tempArrayMajor[1];
 232                                  if ( descArray[3] != \"\" ) {
 233                                      tempArrayMinor = descArray[3].split(\"r\");
 234                                  } else {
 235                                      tempArrayMinor = descArray[4].split(\"r\");
 236                                  }
 237                                    versionRevision = tempArrayMinor[1] > 0 ? tempArrayMinor[1] : 0;
 238                                  flashVer = versionMajor + \".\" + versionMinor + \".\" + versionRevision;
 239                                } else {
 240                                  flashVer = -1;
 241                              }
 242                          }
 243                          // MSN/WebTV 2.6 supports Flash 4
 244                          else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.6\") != -1) flashVer = 4;
 245                          // WebTV 2.5 supports Flash 3
 246                          else if (navigator.userAgent.toLowerCase().indexOf(\"webtv/2.5\") != -1) flashVer = 3;
 247                          // older WebTV supports Flash 2
 248                          else if (navigator.userAgent.toLowerCase().indexOf(\"webtv\") != -1) flashVer = 2;
 249                          // Can't detect in all other cases
 250                          else {
 251  
 252                              flashVer = -1;
 253                          }
 254                          return flashVer;
 255                      }
 256                      // When called with reqMajorVer, reqMinorVer, reqRevision returns true if that version or greater is available
 257  					function DetectFlashVer(reqMajorVer, reqMinorVer, reqRevision)
 258                      {
 259                           reqVer = parseFloat(reqMajorVer + \".\" + reqRevision);
 260                             // loop backwards through the versions until we find the newest version
 261                          for (i=25;i>0;i--) {
 262                              if (isIE && isWin && !isOpera) {
 263                                  versionStr = VBGetSwfVer(i);
 264                              } else {
 265                                  versionStr = JSGetSwfVer(i);
 266                              }
 267                              if (versionStr == -1 ) {
 268                                  return false;
 269                              } else if (versionStr != 0) {
 270                                  if(isIE && isWin && !isOpera) {
 271                                      tempArray         = versionStr.split(\" \");
 272                                      tempString        = tempArray[1];
 273                                      versionArray      = tempString .split(\",\");
 274                                  } else {
 275                                      versionArray      = versionStr.split(\".\");
 276                                  }
 277                                  versionMajor      = versionArray[0];
 278                                  versionMinor      = versionArray[1];
 279                                  versionRevision   = versionArray[2];
 280  
 281                                  versionString     = versionMajor + \".\" + versionRevision;   // 7.0r24 == 7.24
 282                                  versionNum        = parseFloat(versionString);
 283                                  // is the major.revision >= requested major.revision AND the minor version >= requested minor
 284                                  if ( (versionMajor > reqMajorVer) && (versionNum >= reqVer) ) {
 285                                      return true;
 286                                  } else {
 287                                      return ((versionNum >= reqVer && versionMinor >= reqMinorVer) ? true : false );
 288                                  }
 289                              }
 290                          }
 291                      }
 292                      // -->
 293                      </script>";
 294  
 295  if ($origin != 'learnpath') {
 296      //so we are not in learnpath tool
 297      Display::display_tool_header($nameTools,"Exercise");
 298  } else {
 299  
 300      if (empty($charset)) {
 301          $charset = 'ISO-8859-15';
 302      }
 303      header('Content-Type: text/html; charset='. $charset);
 304  
 305      @$document_language = Database::get_language_isocode($language_interface);
 306      if(empty($document_language))
 307      {
 308        //if there was no valid iso-code, use the english one
 309        $document_language = 'en';
 310      }
 311  
 312      /*
 313       * HTML HEADER
 314       */
 315  
 316  ?>
 317  <!DOCTYPE html
 318       PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 319       "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 320  <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="<?php echo $document_language; ?>" lang="<?php echo $document_language; ?>">
 321  <head>
 322  <meta http-equiv="Content-Type" content="text/html; charset=<?php echo $charset; ?>" />
 323  </head>
 324  
 325  <body>
 326  <link rel="stylesheet" type="text/css" href="<?php echo api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css'; ?>" />
 327  <?php
 328  }
 329  
 330  
 331  if ($objExercise->results_disabled) {
 332      ob_start();
 333  }
 334  
 335  /*
 336  FUNCTIONS
 337  */
 338  
 339  
 340  function display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect)
 341  {
 342      ?>
 343      <tr>
 344      <td width="5%" align="center">
 345          <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
 346          border="0" alt="" />
 347      </td>
 348      <td width="5%" align="center">
 349          <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
 350          border="0" alt=" " />
 351      </td>
 352      <td width="45%" style="border-bottom: 1px solid #4171B5;">
 353          <?php        
 354          $answer=api_parse_tex($answer);
 355          echo $answer; 
 356          ?>
 357      </td>
 358      <!--<td width="45%" style="border-bottom: 1px solid #4171B5;">
 359          <?php
 360          $answerComment=api_parse_tex($answerComment);
 361          if($studentChoice)
 362          {
 363              if(!$answerCorrect)
 364              {
 365                  echo '<span style="font-weight: bold; color: #FF0000;">'.nl2br(make_clickable($answerComment)).'</span>';
 366              }
 367              else{
 368                  echo '<span style="font-weight: bold; color: #008000;">'.nl2br(make_clickable($answerComment)).'</span>';
 369              }
 370          }
 371          else
 372          {
 373              echo '&nbsp;';
 374          } 
 375          ?>
 376      </td>-->
 377      </tr>
 378      <?php    
 379  }
 380  
 381  /**
 382   * Display the answers to a reasoning question
 383   *
 384   * @param integer Answer type
 385   * @param integer Student choice
 386   * @param string  Textual answer
 387   * @param string  Comment on answer
 388   * @param string  Correct answer comment
 389   * @param integer Exercise ID
 390   * @param integer Question ID
 391   * @param boolean Whether to show the answer comment or not 
 392   * @return void
 393   */
 394  function display_reasoning_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect, $id, $questionId, $ans)
 395  {
 396      ?>
 397      <tr>
 398      <td width="5%" align="center">
 399          <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $studentChoice?'_on':'_off'; ?>.gif"
 400          border="0" alt="" />
 401      </td>
 402      <td width="5%" align="center">
 403          <img src="../img/<?php echo ($answerType == UNIQUE_ANSWER)?'radio':'checkbox'; echo $answerCorrect?'_on':'_off'; ?>.gif"
 404          border="0" alt=" " />
 405      </td>    
 406      <td width="45%" style="border-bottom: 1px solid #4171B5;">
 407          <?php        
 408          $answer=api_parse_tex($answer);
 409          echo $answer; 
 410          ?>
 411      </td>
 412          <?php 
 413          if ($ans==1) {
 414              $comm = get_comments($id,$questionId);
 415          }
 416          ?>    
 417      </tr>
 418      <?php
 419  }
 420  
 421  function display_fill_in_blanks_answer($answer,$correctChoice,$answerWrong,$feedback_true,$feedback_false)
 422  {
 423      ?>
 424          <tr>
 425          <td>
 426              <?php echo Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY); ?>
 427          </td>
 428          </tr>
 429          <tr>
 430          <td>
 431              <?php echo get_lang('Feedback'); ?>
 432          </td>
 433          </tr>
 434          <tr>        
 435              <?php 
 436              if($correctChoice == 'Y' && $answerWrong == 'N')
 437              {
 438                  echo '<td>'.$feedback_true;
 439              }
 440              else
 441              {
 442                  echo '<td>'.$feedback_false;
 443              }
 444              ?>
 445          </td>
 446          </tr>
 447      <?php
 448  }
 449  
 450  function display_free_answer($answer)
 451  {
 452      ?>
 453          <tr>
 454          <td width="55%">
 455              <?php echo nl2br(Security::remove_XSS($answer,COURSEMANAGERLOWSECURITY)); ?>
 456          </td>
 457     <td width="45%">
 458      <?php echo get_lang('notCorrectedYet');?>
 459  
 460     </td>
 461          </tr>
 462      <?php
 463  }
 464  
 465  function display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment)
 466  {
 467      //global $hotspot_colors;
 468      $hotspot_colors = array("", // $i starts from 1 on next loop (ugly fix)
 469                                      "#4271B5",
 470                                      "#FE8E16",
 471                                      "#3B3B3B",
 472                                      "#BCD631",
 473                                      "#D63173",
 474                                      "#D7D7D7",
 475                                      "#90AFDD",
 476                                      "#AF8640",
 477                                      "#4F9242",
 478                                      "#F4EB24",
 479                                      "#ED2024",
 480                                      "#45C7F0",
 481                                      "#F7BDE2");
 482  
 483              $s .= '<tr>';
 484              $s .= '<td valign="top">';
 485              $s .= '    <div style="height:11px; width:11px; background-color:'.$hotspot_colors[$answerId].'; display:inline; float:left; margin-top:3px;"></div>
 486                          <div style="float:left; padding-left:5px;">'.$answerId.'</div>
 487                              <div style="float:left; padding-left:5px;">
 488                                  <div style="display:inline; float:left; width:80px;">'.$answer.'</div>
 489                              </div>';
 490              $s .= '</td>
 491                     <td valign="top">';
 492              $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault');
 493              $s .= $my_choice;
 494              $s .= '</td>
 495                     </tr>';
 496      ?>
 497      
 498          <!--<tr>
 499                  <td valign="top">
 500                  <div style="height:11px; width:11px; background-color:<?php echo $hotspot_colors[$answerId]; ?>; display:inline; float:left; margin-top:3px;"></div>
 501                  <div style="float:left; padding-left:5px;">
 502                  <?php echo $answerId; ?>
 503                  </div>
 504                      <div style="float:left; padding-left:5px;">
 505                          
 506                          <div style="display:inline; float:left; width:80px;"><?php echo $answer ?></div>
 507                          
 508                      </div>
 509                  </td>
 510                  <td valign="top">
 511                      <?php $my_choice = ($studentChoice)?get_lang('Correct'):get_lang('Fault'); echo $my_choice; ?>
 512                  </td>
 513                  <td valign="top">                
 514                      <?php
 515                      if ($studentChoice) {
 516                          echo '<span>';                            
 517                      } else {
 518                          echo '<span>';                                                
 519                      }                    
 520                      echo $answerComment;
 521                      echo '</span>';                 
 522                      ?>
 523                  </td>
 524          </tr>-->
 525          
 526      <?php
 527          return $s;
 528  }
 529  
 530  /*
 531  DISPLAY AND MAIN PROCESS
 532  */
 533  
 534  // I'm in a preview mode as course admin. Display the action menu.
 535  if ($origin != 'learnpath') {
 536      echo '<div class="actions">';
 537      if (api_is_course_admin()) {
 538          echo '<a href="exercice.php?'.api_get_cidreq().'&exerciseId='.$objExercise->id.'">'.Display::return_icon('pixel.gif', get_lang('GoBackToEx'),array('class'=>'toolactionplaceholdericon toolactionback')).get_lang('GoBackToEx'). '</a>';
 539      echo '<a href="exercise_admin.php?scenario=yes&modifyExercise=yes&' . api_get_cidreq() . '&exerciseId='.$objExercise->id.'">' . Display :: return_icon('pixel.gif', get_lang('Scenario'),array('class'=>'toolactionplaceholdericon toolactionscenario')) . get_lang('Scenario') . '</a>';
 540      } else {
 541          echo '<a href="'.api_get_path(WEB_CODE_PATH).'exercice/exercice.php?'.api_get_cidreq().'">' . Display::return_icon('pixel.gif', get_lang('GoBackToEx'), array('class' => 'toolactionplaceholdericon toolactionback')) . get_lang('GoBackToEx').'</a>';
 542      }
 543      echo '</div>';                            
 544  }
 545  
 546  echo '<div id="content">';
 547  echo '<div class="actions"><table width="100%">';
 548  $exerciseTitle=api_parse_tex($exerciseTitle);
 549  $user_id=api_get_user_id();
 550  $course_code = api_get_course_id();
 551  $status_info=CourseManager::get_user_in_course_status($user_id,$course_code);
 552              if (STUDENT==$status_info) {
 553                  $user_info=api_get_user_info($user_id); 
 554                  $user_name =  $user_info['firstName'].' '.$user_info['lastName'];
 555              } elseif(COURSEMANAGER==$status_info && !isset($_GET['user'])) {
 556                  $user_info=api_get_user_info($user_id); 
 557                  $user_name =  $user_info['firstName'].' '.$user_info['lastName'];
 558              } else {
 559                  echo $user_name;
 560              }
 561  
 562  //show exercise title
 563  ?>
 564      <?php if($origin != 'learnpath') {
 565          echo '<tr><td width="10%" align="right"><b>'.get_lang('CourseTitle').'</b> :</td><td>'.api_get_course_id().'</td></tr>';
 566          echo '<tr><td width="10%" align="right"><b>'.get_lang('User').'</b> :</td><td>'.$user_name.'</td></tr>';
 567          echo '<tr><td width="10%" align="right"><b>'.get_lang('Exercise').'</b> :</td><td>'.$exerciseTitle.'<br/>'.$exerciseDescription.'</td></tr>';
 568      } ?>
 569      </table></div><br/>
 570      <form method="get" action="exercice.php">
 571      <input type="hidden" name="origin" value="<?php echo $origin; ?>" />
 572      <input type="hidden" name="learnpath_id" value="<?php echo $learnpath_id; ?>" />
 573      <input type="hidden" name="learnpath_item_id" value="<?php echo $learnpath_item_id; ?>" />
 574  
 575  <?php
 576  
 577  $i=$totalScore=$totalWeighting=0;
 578  if($debug>0){echo "ExerciseResult: "; var_dump($exerciseResult); echo "QuestionList: ";var_dump($questionList);}
 579  
 580  if ($_configuration['tracking_enabled']) {
 581      // Create an empty exercise  
 582      $exeId= create_event_exercice($objExercise->selectId());
 583  }     
 584  $counter=0;
 585  
 586  // Loop over all question to show results for each of them, one by one
 587  foreach ($questionList as $questionId) {
 588      $counter++;
 589      // gets the student choice for this question
 590      $choice=$exerciseResult[$questionId];
 591      // creates a temporary Question object
 592      $objQuestionTmp = Question :: read($questionId);
 593      // initialize question information
 594      $questionName=$objQuestionTmp->selectTitle();
 595      $questionDescription=$objQuestionTmp->selectDescription();
 596      $questionWeighting=$objQuestionTmp->selectWeighting();
 597      $answerType=$objQuestionTmp->selectType();
 598      $quesId =$objQuestionTmp->selectId(); //added by priya saini
 599  
 600      // destruction of the Question object
 601      unset($objQuestionTmp);
 602  
 603      // decide how many columns we want to use to show the results of each type
 604      if($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER || $answerType == REASONING) {
 605          $colspan=4;
 606      } elseif($answerType == MATCHING || $answerType == FREE_ANSWER) {
 607          $colspan=2;
 608      } elseif($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
 609          $colspan=4;
 610          $rowspan=$nbrAnswers+1;
 611      } else {
 612          $colspan=1;
 613      }
 614      // show titles
 615      if ($origin != 'learnpath') {?>
 616          <div style="padding:0px 0px 20px 0px;"><div class="rounded" style="width: 100%; padding: 1px; background-color:#ccc;"><table class="rounded_inner" style="width: 100%; background-color:#fff;"><tr><td>
 617          <div id="question_title" class="quiz_content_actions" style="font-weight:bold;margin: 0px 10px 10px 10px;padding: 5px 15px;top:-10px;position: relative;border: 1px solid #ED9438;">
 618              <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
 619          </div>       
 620          <div id="question_description" class="scroll_feedback">
 621              <?php echo $questionDescription; ?>
 622          </div>
 623      <!--    <tr bgcolor="#E6E6E6">
 624          <td colspan="<?php echo $colspan; ?>">
 625              <?php echo get_lang("Question").' '.($counter).' : '.$questionName; ?>
 626          </td>
 627          </tr>
 628          <tr>
 629          <td colspan="<?php echo $colspan; ?>">                
 630              <i><?php echo $questionDescription; ?></i>                
 631          </td>
 632          </tr>-->
 633          <table width="100%" border="0" cellpadding="3" cellspacing="2" class="feedback_actions">
 634          <?php
 635          if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {
 636              ?>            
 637                  <tr>
 638                  <td width="5%" valign="top" align="center" nowrap="nowrap">
 639                      <i><?php echo get_lang("Choice"); ?></i>
 640                  </td>
 641                  <td width="5%"  align="center" nowrap="nowrap">
 642                      <i><?php echo get_lang("ExpectedChoice"); ?></i>
 643                  </td>
 644                  <td width="45%" valign="top">
 645                      <i><?php echo get_lang("Answer"); ?></i>
 646                  </td>
 647              <!--<td width="45%" valign="top">
 648                      <i><?php echo get_lang("Comment"); ?></i>
 649                  </td>-->
 650                  </tr>
 651              <?php
 652          } elseif ($answerType == REASONING) {
 653              ?>
 654                  <tr>
 655                  <td width="5%" valign="top" align="center" nowrap="nowrap">
 656                      <i><?php echo get_lang("Choice"); ?></i>
 657                  </td>
 658                  <td width="5%"  align="center" nowrap="nowrap">
 659                      <i><?php echo get_lang("ExpectedChoice"); ?></i>
 660                  </td>
 661                  <td width="45%" valign="top">
 662                      <i><?php echo get_lang("Answer"); ?></i>
 663                  </td>                
 664                  </tr>
 665              <?php
 666          } elseif ($answerType == FILL_IN_BLANKS) {
 667              ?>
 668                  <tr>
 669                  <td>
 670                      <i><?php echo get_lang("Answer"); ?></i>
 671                  </td>
 672                  </tr>
 673              <?php
 674          } elseif ($answerType == FREE_ANSWER) {
 675              ?>
 676                  <tr>
 677                  <td width="55%">
 678                      <i><?php echo get_lang("Answer"); ?></i>
 679                  </td>
 680                  <td width="45%" valign="top">
 681                      <i><?php echo get_lang("Comment"); ?></i>
 682                  </td>
 683                  </tr>
 684              <?php
 685          } elseif ($answerType == HOT_SPOT) {
 686              ?>
 687                  <tr>
 688                      <td valign="top" colspan="2">
 689                          <table width="552" border="1" bordercolor="#A4A4A4" style="border-collapse: collapse;">
 690                          <!--    <tr>
 691                                  <td width="152" valign="top">
 692                                      <i><?php echo get_lang("CorrectAnswer"); ?></i><br /><br />
 693                                  </td>
 694                          
 695                                  <td width="100" valign="top">
 696                                      <i><?php echo get_lang('HotspotHit'); ?></i><br /><br />
 697                                  </td>
 698                                  <td width="300" valign="top">
 699                                      <i><?php echo get_lang("Comment"); ?></i><br /><br />
 700                                  </td>
 701                              </tr>-->
 702              <?php
 703          } else { //matching type
 704              ?>
 705                  <tr>
 706                  <td width="50%">
 707                      <i><?php echo get_lang("ElementList"); ?></i>
 708                  </td>
 709                  <td width="50%">
 710                      <i><?php echo get_lang("CorrespondsTo"); ?></i>
 711                  </td>
 712                  </tr>
 713              <?php
 714          }
 715      } 
 716  
 717      // construction of the Answer object
 718      $objAnswerTmp=new Answer($questionId);
 719      $nbrAnswers=$objAnswerTmp->selectNbrAnswers();
 720      $questionScore=0;
 721      $correctChoice='Y';
 722      $noStudentChoice='N';
 723      $correctComment = array();
 724      if ($answerType == FREE_ANSWER) {
 725          $nbrAnswers = 1;
 726      }
 727      if ($answerType == FILL_IN_BLANKS) {
 728      $feedback_data = unserialize($objAnswerTmp -> comment[1]);
 729      $feedback_true = $feedback_data['comment[1]'];
 730      $feedback_false = $feedback_data['comment[2]'];
 731      }
 732      $correctChoice_unique = 'N';
 733      $correctChoice_multiple = 'N';
 734      $correctChoice_reasoning = 'N';
 735      $correctChoice = 'N';
 736      $answerWrong = 'N';
 737      // We're inside *one* question. Go through each possible answer for this question
 738      for ($answerId=1;$answerId <= $nbrAnswers;$answerId++) {
 739          
 740          //select answer of *position*=$answerId
 741          $answer=$objAnswerTmp->selectAnswer($answerId);
 742          $answerComment=$objAnswerTmp->selectComment($answerId);
 743          $correctComment[] =$objAnswerTmp->selectComment($answerId);
 744          $answerCorrect=$objAnswerTmp->isCorrect($answerId);
 745          $answerWeighting=$objAnswerTmp->selectWeighting($answerId);
 746          
 747          switch ($answerType) {
 748              // for unique answer
 749              case UNIQUE_ANSWER :
 750                      // if the student choice is equal to the answer ID
 751                      // then give him the corresponding score
 752                      // (maybe a negative score, positive score or 0)
 753                      // Positive score should only be given when we are going over the right answer
 754                      $studentChoice=($choice == $answerId)?1:0;
 755                      if($studentChoice) {
 756                            $questionScore+=$answerWeighting;
 757                          $totalScore+=$answerWeighting;
 758                          if($studentChoice == $answerCorrect)
 759                          {                                
 760                          $correctChoice_unique = 'Y';
 761                          }
 762                      }                    
 763                      break;
 764              // for multiple answers
 765              case MULTIPLE_ANSWER :
 766                      $studentChoice=$choice[$answerId];
 767                      if($studentChoice) {
 768                          $questionScore+=$answerWeighting;
 769                          $totalScore+=$answerWeighting;
 770                          if($studentChoice == $answerCorrect)
 771                          {                    
 772                          $correctChoice_multiple = 'Y';
 773                          $feedback_if_true = $objAnswerTmp->selectComment($answerId);
 774                          }
 775                          else
 776                          {        
 777                          $answerWrong = 'Y';
 778                          $feedback_if_false = $objAnswerTmp->selectComment($answerId);
 779                          }    
 780                      }
 781                      break;
 782              case REASONING :
 783                      $studentChoice=$choice[$answerId];                    
 784                      if($answerCorrect)
 785                      {
 786                         $feedback_if_true = $objAnswerTmp->selectComment($answerId);
 787                      }
 788                      else
 789                      {
 790                         $feedback_if_false = $objAnswerTmp->selectComment($answerId);
 791                      }
 792  
 793                      if($answerId == '2')
 794                      {
 795                          $wrongAnswerWeighting = $answerWeighting;
 796                      }
 797                      if($answerCorrect && $studentChoice == '1' && $correctChoice_reasoning == 'N')
 798                      {                    
 799                          $correctChoice_reasoning = 'Y';
 800                          $noStudentChoice = 'Y';
 801                      }
 802                      elseif($answerCorrect && !$studentChoice)
 803                      {                    
 804                          $correctChoice_reasoning = 'N';
 805                          $noStudentChoice = 'Y';
 806                          $answerWrong = 'Y';    
 807                          break;
 808                      }
 809                      elseif(!$answerCorrect && $studentChoice == '1')
 810                      {                    
 811                          $correctChoice_reasoning = 'N';
 812                          $noStudentChoice = 'Y';
 813                          $answerWrong = 'Y';    
 814                          break;
 815                      }                    
 816                      break;
 817              // for fill in the blanks
 818              case FILL_IN_BLANKS :                    
 819                      // the question is encoded like this
 820                      // [A] B [C] D [E] F::10,10,10@1
 821                      // number 1 before the "@" means that is a switchable fill in blank question
 822                      // [A] B [C] D [E] F::10,10,10@ or  [A] B [C] D [E] F::10,10,10
 823                      // means that is a normal fill blank question            
 824  
 825                      // first we explode the "::"
 826                      $pre_array = explode('::', $answer);    
 827  
 828                      // is switchable fill blank or not
 829                      $last = count($pre_array)-1;        
 830                      $is_set_switchable = explode('@', $pre_array[$last]);
 831                      
 832                      $switchable_answer_set=false;
 833                      if (isset($is_set_switchable[1]) && $is_set_switchable[1]==1)
 834                      {
 835                          $switchable_answer_set=true;
 836                      }                                
 837                      
 838                      $answer = '';
 839                      for ($k=0; $k<$last; $k++)
 840                      {
 841                        $answer .= $pre_array[$k];
 842                      }
 843                      
 844                      // splits weightings that are joined with a comma
 845                      $answerWeighting = explode(',',$is_set_switchable[0]);                
 846  
 847                      // we save the answer because it will be modified
 848                      $temp=$answer;
 849  
 850                      // TeX parsing
 851                      // 1. find everything between the [tex] and [/tex] tags
 852                      $startlocations=api_strpos($temp,'[tex]');
 853                      $endlocations=api_strpos($temp,'[/tex]');
 854  
 855                      if($startlocations !== false && $endlocations !== false)
 856                      {
 857                          $texstring=api_substr($temp,$startlocations,$endlocations-$startlocations+6);
 858                          // 2. replace this by {texcode}
 859                          $temp=str_replace($texstring,'{texcode}',$temp);
 860                      }
 861  
 862                      $answer='';
 863                      $j=0;
 864                      
 865                      //initialise answer tags
 866                      $user_tags=array();
 867                      $correct_tags=array();
 868                      $real_text=array();
 869                      // the loop will stop at the end of the text
 870                      while(1)
 871                      {
 872                          // quits the loop if there are no more blanks (detect '[')
 873                          if(($pos = api_strpos($temp,'[')) === false)
 874                          {
 875                              // adds the end of the textsolution
 876                              $answer=$temp;
 877                              // TeX parsing - replacement of texcode tags
 878                              $texstring = api_parse_tex($texstring);
 879                              $answer=str_replace("{texcode}",$texstring,$answer);
 880                              $real_text[] = $answer;
 881                              break; //no more "blanks", quit the loop
 882                          }
 883                          // adds the piece of text that is before the blank 
 884                          //and ends with '[' into a general storage array
 885                          $real_text[]=api_substr($temp,0,$pos+1);
 886                          $answer.=api_substr($temp,0,$pos+1);
 887                          //take the string remaining (after the last "[" we found)
 888                          $temp=api_substr($temp,$pos+1);
 889                          // quit the loop if there are no more blanks, and update $pos to the position of next ']'
 890                          if(($pos = api_strpos($temp,']')) === false)
 891                          {
 892                              // adds the end of the text
 893                              $answer.=$temp;
 894                              break;
 895                          }
 896                          $choice[$j]=trim($choice[$j]);
 897                          $user_tags[]=api_strtolower($choice[$j]);
 898                          //put the contents of the [] answer tag into correct_tags[]
 899                          $correct_tags[]=api_strtolower(api_substr($temp,0,$pos));
 900                          $j++;
 901                          $temp=api_substr($temp,$pos+1);
 902                          //$answer .= ']';
 903                      }
 904                                                          
 905                      $answer='';            
 906                      $real_correct_tags = $correct_tags;                            
 907                      $chosen_list=array();
 908                      
 909                      for($i=0;$i<count($real_correct_tags);$i++) {
 910                          if ($i==0)
 911                          {
 912                              $answer.=$real_text[0];
 913                          }
 914                          
 915                          if (!$switchable_answer_set)
 916                          {                        
 917                              if ($correct_tags[$i]==$user_tags[$i])
 918                              {
 919                                  // gives the related weighting to the student
 920                                  $questionScore+=$answerWeighting[$i]; 
 921                                  // increments total score
 922                                  $totalScore+=$answerWeighting[$i];
 923                                  // adds the word in green at the end of the string
 924                                  $answer.=$correct_tags[$i]; 
 925                                  if($answerWrong == 'N'){
 926                                      $correctChoice = 'Y';
 927                                  }
 928                              }
 929                              // else if the word entered by the student IS NOT the same as the one defined by the professor                                            
 930                              elseif(!empty($user_tags[$i]))
 931                              {
 932                                  $answerWrong = 'Y';
 933                                  // adds the word in red at the end of the string, and strikes it
 934                                  $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>'; 
 935                              }
 936                              else
 937                              {
 938                                  $answerWrong = 'Y';
 939                                  // adds a tabulation if no word has been typed by the student
 940                                  $answer.='&nbsp;&nbsp;&nbsp;';
 941                              }                                                
 942                          } else {     
 943                              // switchable fill in the blanks
 944                              if (in_array($user_tags[$i],$correct_tags)) {
 945                                  $chosen_list[]=$user_tags[$i];                                                    
 946                                  $correct_tags=array_diff($correct_tags,$chosen_list);
 947                                                  
 948                                  // gives the related weighting to the student                                                
 949                                  $questionScore+=$answerWeighting[$i];
 950                                  // increments total score
 951                                  $totalScore+=$answerWeighting[$i];
 952                                  // adds the word in green at the end of the string
 953                                  $answer.=$user_tags[$i];
 954                                  if($answerWrong == 'N'){
 955                                      $correctChoice = 'Y';
 956                                  }
 957                              }                                                    // else if the word entered by the student IS NOT the same as the one defined by the professor                                            
 958                              elseif(!empty($user_tags[$i]))
 959                              {
 960                                  $answerWrong = 'Y';
 961                                  // adds the word in red at the end of the string, and strikes it
 962                                  $answer.='<font color="red"><s>'.$user_tags[$i].'</s></font>'; 
 963                              }
 964                              else
 965                              {
 966                                  $answerWrong = 'Y';
 967                                  // adds a tabulation if no word has been typed by the student
 968                                  $answer.='&nbsp;&nbsp;&nbsp;';
 969                              }                                                
 970                          }
 971                          // adds the correct word, followed by ] to close the blank
 972                          $answer.=' / <font color="green"><b>'.$real_correct_tags[$i].'</b></font>]';
 973                          if ( isset( $real_text[$i+1] ) ) {
 974                              $answer.=$real_text[$i+1];
 975                          }
 976                      }
 977                      break;
 978              // for free answer
 979              case FREE_ANSWER :
 980                      $studentChoice=$choice;
 981  
 982                      if($studentChoice)
 983                      {
 984                          //Score is at -1 because the question has'nt been corected
 985                            $questionScore=-1;
 986                          $totalScore+=0;
 987                      }
 988  
 989  
 990                      break;
 991              // for matching
 992              case MATCHING :
 993                      if($answerCorrect)
 994                      {
 995                          if($answerCorrect == $choice[$answerId])
 996                          {
 997                              $questionScore+=$answerWeighting;
 998                              $totalScore+=$answerWeighting;
 999                              $choice[$answerId]=$matching[$choice[$answerId]];
1000                          }
1001                          elseif(!$choice[$answerId])
1002                          {
1003                              $choice[$answerId]='&nbsp;&nbsp;&nbsp;';
1004                          }
1005                          else
1006                          {
1007                          //    $choice[$answerId]='<font color="red"><s>'.$matching[$choice[$answerId]].'</s></font>';
1008                              $choice[$answerId]=$matching[$choice[$answerId]];
1009                          }
1010                      }
1011                      else
1012                      {
1013                          $matching[$answerId]=$answer;
1014                      }
1015                      if($questionScore == $questionWeighting)
1016                      {
1017                          $correctChoice = 'Y';
1018                      }
1019                      break;
1020              // for hotspot with no order
1021              case HOT_SPOT :            
1022                      $studentChoice=$choice[$answerId];
1023                      if ($studentChoice) { //the answer was right
1024                          $questionScore+=$answerWeighting;
1025                          $totalScore+=$answerWeighting;
1026                          $correctChoice = 'Y';
1027                      }
1028                      break;
1029              // for hotspot with fixed order
1030              case HOT_SPOT_ORDER :
1031                      $studentChoice=$choice['order'][$answerId];
1032  
1033                      if($studentChoice == $answerId)
1034                      {
1035                          $questionScore+=$answerWeighting;
1036                          $totalScore+=$answerWeighting;
1037                          $studentChoice = true;
1038                          if($answerWrong == 'N'){
1039                          $correctChoice = 'Y';
1040                          }
1041                      }
1042                      else
1043                      {
1044                          $answerWrong = 'Y';
1045                          $studentChoice = false;
1046                      }
1047  
1048                      break;
1049          } // end switch Answertype
1050          
1051          //display answers (if not matching type, or if the answer is correct)
1052          if ($answerType != MATCHING || $answerCorrect) {
1053              if ($answerType == UNIQUE_ANSWER || $answerType == MULTIPLE_ANSWER) {    
1054                  if ($origin!='learnpath') {
1055                      display_unique_or_multiple_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);                    
1056                  }
1057              } elseif ($answerType == REASONING) {    
1058                  if ($origin!='learnpath') {                    
1059                      display_reasoning_answer($answerType, $studentChoice, $answer, $answerComment, $answerCorrect);                    
1060                  }
1061              } elseif($answerType == FILL_IN_BLANKS) {
1062                  if ($origin!='learnpath') {
1063                      display_fill_in_blanks_answer($answer);
1064                  }
1065              } elseif($answerType == FREE_ANSWER) {
1066                  // to store the details of open questions in an array to be used in mail
1067  
1068                  $arrques[] = $questionName;
1069                  $arrans[]  = $choice;
1070                  $firstName =   $_SESSION['_user']['firstName'];
1071                  $lastName =   $_SESSION['_user']['lastName'];
1072                  $mail =  $_SESSION['_user']['mail'];
1073                  $coursecode =  $_SESSION['_course']['id'];
1074                  $to = '';
1075                  $teachers = array();
1076                  if(api_get_setting('use_session_mode')=='true' && !empty($_SESSION['id_session']))
1077                  {
1078                      $teachers = CourseManager::get_coach_list_from_course_code($coursecode,$_SESSION['id_session']);
1079                  }
1080                  else
1081                  {
1082                      $teachers = CourseManager::get_teacher_list_from_course_code($coursecode);
1083                  }
1084                  $num = count($teachers);
1085                  if($num>1)
1086                  {
1087                      $to = array();
1088                      foreach($teachers as $teacher)
1089                      {
1090                          $to[] = $teacher['email'];
1091                      }
1092                  }elseif($num>0){
1093                      foreach($teachers as $teacher)
1094                      {
1095                          $to = $teacher['email'];
1096                      }
1097                  }else{
1098                      //this is a problem (it means that there is no admin for this course)
1099                  }
1100                  if($origin != 'learnpath') {
1101                      display_free_answer($choice);
1102                  }
1103                  
1104              }
1105              elseif($answerType == HOT_SPOT)
1106              {                    
1107                  if ($origin != 'learnpath') {
1108                      if($studentChoice){
1109                      $answerOk = 'Y';
1110                      }
1111                      else {
1112                      $answerOk = 'N';
1113                      $answerWrong = 'Y';
1114                      }
1115                      $s .= display_hotspot_answer($answerId, $answer, $studentChoice, $answerComment);
1116                  }
1117              }
1118              elseif($answerType == HOT_SPOT_ORDER)
1119              {
1120                  display_hotspot_order_answer($answerId, $answer, $studentChoice, $answerComment);
1121              }
1122              else
1123              {
1124                  if ($origin != 'learnpath') {
1125                  ?>
1126                      <tr>
1127                      <td width="50%">
1128                          <?php
1129                          $answer=api_parse_tex($answer);
1130                          echo $answer; ?>
1131                      </td>
1132                      <td width="50%">
1133                          <?php echo $choice[$answerId]; ?> / <font color="green"><b>
1134                          <?php
1135                          $matching[$answerCorrect]=api_parse_tex($matching[$answerCorrect]);
1136                          echo $matching[$answerCorrect]; ?></b></font>
1137                      </td>
1138                      </tr>
1139                  <?php
1140                  }
1141              }
1142          }
1143      } // end for that loops over all answers of the current question
1144  
1145      if ($answerType == REASONING && $noStudentChoice == 'Y'){                        
1146                      if($correctChoice_reasoning == 'Y')                
1147                      {
1148                          $questionScore += $questionWeighting;
1149                          $totalScore += $questionWeighting;
1150                      }
1151                      else
1152                      {
1153                          $questionScore += $wrongAnswerWeighting;
1154                          $totalScore += $wrongAnswerWeighting;
1155                      }
1156      }
1157  
1158      // if answer is hotspot. To the difference of exercise_show.php, we use the results from the session (from_db=0)
1159      // TODO Change this, because it is wrong to show the user some results that haven't been stored in the database yet
1160      if ($answerType == HOT_SPOT || $answerType == HOT_SPOT_ORDER) {
1161              // We made an extra table for the answers
1162              if($origin != 'learnpath') {
1163              echo "</table></td></tr>";    //echo Security::remove_XSS($questionId);
1164              ?>
1165          
1166              <tr>
1167                  <table width="100%" border="0"><tr>
1168                  <td colspan="2">                    
1169                      <object type="application/x-shockwave-flash" data="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo Security::remove_XSS($questionId); ?>&exe_id=&from_db=0" width="610" height="410">
1170                          <param name="movie" value="../plugin/hotspot/hotspot_solution.swf?modifyAnswers=<?php echo Security::remove_XSS($questionId); ?>&exe_id=&from_db=0" />
1171                      </object>
1172                  </td>
1173                  <td colspan="2" width="40%" valign="top"><div class="quiz_content_actions" style="height:380px;"><div class="quiz_header"><?php echo get_lang('Feedback'); ?></div><div align="center"><img src="../img/MouseHotspots64.png"></div><br/>
1174                  <table class="data_table" width="100%" border="1">
1175                  <?php echo $s;?>
1176                  </table><br/>
1177                  <div align="center">
1178                  <?php 
1179                  if($answerOk == 'Y' && $answerWrong == 'N'){
1180                      if($nbrAnswers == 1){
1181                          $correctComment = explode("~", $objAnswerTmp->selectComment(1));
1182                          $feedback = $correctComment[0];
1183                      }
1184                      else {
1185                          $feedback = $objAnswerTmp->selectComment(1);
1186                      }
1187                  }
1188                  else {
1189                      if($nbrAnswers == 1){
1190                          $correctComment = explode("~", $objAnswerTmp->selectComment(1));
1191                          $feedback = $correctComment[1];
1192                      }
1193                      else {
1194                          $feedback = $objAnswerTmp->selectComment(2);
1195                      }                
1196                  }
1197                  if(!empty($feedback)){
1198                  echo get_lang('Feedback').' : '.$feedback ;
1199                  }
1200                  ?>
1201                  </div>
1202                  </div>
1203                  </td>
1204                  </tr></table>
1205              </tr>
1206              <?php 
1207              } 
1208          }
1209      ?>
1210      <?php if($origin != 'learnpath') { 
1211          echo '<tr><td colspan="3">';
1212          if($answerType == MATCHING)
1213          {
1214                      if($questionScore == $questionWeighting)
1215                      {
1216                          echo '<b>'.get_lang('Feedback').' </b><br /><span>'.nl2br(make_clickable($correctComment[0])).'</span><br />';    
1217                      }
1218                      else
1219                      {
1220                          echo '<b>'.get_lang('Feedback').' </b><br /><span>'.nl2br(make_clickable($correctComment[1])).'</span><br />';
1221                      }
1222          }
1223          elseif($answerType != FILL_IN_BLANKS && $answerType != FREE_ANSWER)
1224          {
1225              
1226                      if($answerType == UNIQUE_ANSWER)
1227                      {                            
1228                          if($correctChoice_unique == 'Y')
1229                          {
1230                              echo '<b>'.get_lang('Feedback').' </b><br /><span>'.nl2br(make_clickable($correctComment[0])).'</span><br />';    
1231                          }
1232                          else
1233                          {
1234                              echo '<b>'.get_lang('Feedback').' </b><br /><span>'.nl2br(make_clickable($correctComment[1])).'</span><br />';
1235                          }
1236                      }
1237                      if($answerType == MULTIPLE_ANSWER)
1238                      {                        
1239                          if($correctChoice_multiple == 'Y' && $answerWrong == 'N')
1240                          {
1241                              echo '<b>'.get_lang('Feedback').'  </b><span>'.nl2br(make_clickable($feedback_if_true)).'</span>';    
1242                          }
1243                          else
1244                          {
1245                              echo '<b>'.get_lang('Feedback').'  </b><span>'.nl2br(make_clickable($feedback_if_false)).'</span>';
1246                          }
1247                      }
1248                      if($answerType == REASONING)
1249                      {                            
1250                          if($correctChoice_reasoning == 'Y' && $answerWrong == 'N')
1251                          {
1252                              echo '<b>'.get_lang('Feedback').' - '.get_lang('FeedbackReason').'  </b><span>'.nl2br(make_clickable($feedback_if_true)).'</span>';    
1253                          }
1254                          else
1255                          {
1256                              echo '<b>'.get_lang('Feedback').' - '.get_lang('FeedbackReason').'  </b><span>'.nl2br(make_clickable($feedback_if_false)).'</span>';
1257                          }
1258                      }    
1259          }
1260                      echo '</td></tr>';
1261      ?>        
1262          <tr>
1263          <td colspan="<?php echo $colspan; ?>" align="left"><br /><div class="sectiontitle">
1264              <b>
1265              <?php
1266              if($questionScore==-1){ 
1267                  echo get_lang('Score').": 0 /".float_format($questionWeighting);
1268              } else {                    
1269                  echo get_lang('Score').": ".round(float_format($questionScore,1))."/".float_format($questionWeighting,1);
1270              }
1271              ?></b>
1272          </div></td>
1273          </tr>
1274          </table>
1275          <?php } ?>
1276      <?php
1277      // destruction of Answer
1278      unset($objAnswerTmp);
1279  
1280      $i++;
1281  
1282      $totalWeighting+=$questionWeighting;
1283      //added by priya saini
1284      if($_configuration['tracking_enabled']) {
1285          if(empty($choice)){
1286              $choice = 0;
1287          }
1288          if ($answerType==MULTIPLE_ANSWER ) {                
1289              if ($choice != 0) {                    
1290                  $reply = array_keys($choice);                                                                                                    
1291                  for ($i=0;$i<sizeof($reply);$i++) {
1292                      $ans = $reply[$i];
1293                      exercise_attempt($questionScore,$ans,$quesId,$exeId,$i);
1294                  }
1295              } else {
1296                  exercise_attempt($questionScore, 0 ,$quesId,$exeId,0);
1297              }
1298          }  elseif ($answerType == REASONING) {            
1299              if ($choice != 0) {
1300                  $reply = array_keys($choice);
1301  
1302                  for ($i = 0; $i < sizeof($reply); $i++) {
1303                      $ans = $reply[$i];            
1304  
1305                      exercise_attempt($questionScore, $ans, $quesId, $exeId, $i);
1306                  }
1307              } else {            
1308                  exercise_attempt($questionScore, 0, $quesId, $exeId, 0);
1309              }
1310          } elseif ($answerType==MATCHING) {
1311              $j=sizeof($matching)+1;
1312              $sql1 = "SELECT * FROM $table_ans WHERE question_id ='".Database::escape_string($questionId)."' AND ponderation = 0.00";
1313              $res1 = api_sql_query($sql1, __FILE__, __LINE__);
1314              $numrows = Database::num_rows($res1);            
1315                  for ($i=0;$i<sizeof($choice);$i++) {
1316                  $val = $choice[$j];
1317                  
1318                  if (preg_match_all ('#<font color="red"><s>([0-9a-z ]*)</s></font>#', $val, $arr1))
1319                  {
1320                      $val = $arr1[1][0];
1321                  }
1322                  
1323              //    $val=strip_tags($val);
1324                  $sql = "SELECT position from $table_ans where question_id='".Database::escape_string($questionId)."' and answer LIKE  '".Database::escape_string($val)."' AND correct=0";                
1325                  $res = api_sql_query($sql, __FILE__, __LINE__);
1326                  if (Database::num_rows($res)>0) {                    
1327                      $answer = Database::result($res,0,"position");                    
1328                  } else {                    
1329                      $answer = 0;                    
1330                  }    
1331                  
1332                  exercise_attempt($questionScore,$answer,$quesId,$exeId,$j);
1333                  if($numrows < sizeof($matching))
1334                  {
1335                      $j--;
1336                  }
1337                  else
1338                  {
1339                      $j++;
1340                  }
1341              }
1342          }
1343          elseif ($answerType==FREE_ANSWER) {
1344              $answer = $choice;
1345              exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
1346          }
1347          elseif ($answerType==UNIQUE_ANSWER) {
1348              // exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
1349              // In fact, we are not storing the results by answer ID, but by *position*, which is stored in $choice
1350              exercise_attempt($questionScore,$choice,$quesId,$exeId,0);
1351          } elseif ($answerType == HOT_SPOT) {
1352              exercise_attempt($questionScore, $answer, $quesId, $exeId, 0);
1353              if (is_array($exerciseResultCoordinates[$quesId])) {
1354                  foreach($exerciseResultCoordinates[$quesId] as $idx => $val) {
1355                      exercise_attempt_hotspot($exeId,$quesId,$idx,$choice[$idx],$val);
1356                  }
1357              }
1358          } else {
1359              exercise_attempt($questionScore,$answer,$quesId,$exeId,0);
1360          }
1361      }
1362      echo '</td></tr></table></div></div>';
1363  } // end huge foreach() block that loops over all questions
1364  ?>
1365  
1366      </form>
1367  
1368      <br /><br />
1369  <?php 
1370  if ($origin == 'learnpath') {    
1371      //Display::display_normal_message(get_lang('ExerciseFinished'));
1372      $lp_mode =  $_SESSION['lp_mode'];    
1373      $url = '../newscorm/lp_controller.php?cidReq='.api_get_course_id().'&action=view&lp_id='.$learnpath_id.'&lp_item_id='.$learnpath_item_id.'&exeId='.$exeId.'&fb_type='.$feedback_type;
1374      $href = ($lp_mode == 'fullscreen')?' window.opener.location.href="'.$url.'" ':' top.location.href="'.$url.'" ';     
1375      echo '<script language="javascript" type="text/javascript">'.$href.'</script>'."\n";
1376  }    
1377  /*
1378  ==============================================================================
1379          Tracking of results
1380  ==============================================================================
1381  */
1382  
1383  if ($_configuration['tracking_enabled']) {
1384      //    Updates the empty exercise  
1385      $safe_lp_id = $learnpath_id==''?0:(int)$learnpath_id;
1386      $safe_lp_item_id = $learnpath_item_id==''?0:(int)$learnpath_item_id;
1387      $quizDuration = (!empty($_SESSION['quizStartTime']) ? time() - $_SESSION['quizStartTime'] : 0);
1388      update_event_exercice($exeId, $objExercise->selectId(),$totalScore,$totalWeighting,api_get_session_id(),$safe_lp_id,$safe_lp_item_id,$quizDuration);
1389  }
1390  
1391  if($objExercise->results_disabled) {
1392      ob_end_clean();
1393      if ($origin != 'learnpath') {
1394          echo '<div class="quiz_content_actions">'.get_lang('ExerciseFinished').'<br /><br /><a href="exercice.php" />'.get_lang('Back').'</a></div>';
1395      //    Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><a href="exercice.php" />'.get_lang('Back').'</a>',false);
1396      } else {
1397          echo '<div class="quiz_content_actions">'.get_lang('ExerciseFinished').'<br /><br />'.'</div>';
1398      //    Display :: display_normal_message(get_lang('ExerciseFinished').'<br /><br />',false);
1399      }
1400  }
1401  
1402  if ($origin != 'learnpath') {
1403      //we are not in learnpath tool
1404      if(!$objExercise->results_disabled){
1405      echo '</div>';
1406      }
1407  
1408   echo '<div class="actions">';
1409   if($origin != 'learnpath' && !$objExercise->results_disabled) { 
1410       ?>
1411      <div>    
1412          <b>
1413          <?php echo get_lang('YourTotalScore')." ";
1414          if ($dsp_percent == true) {
1415            echo number_format(($totalScore/$totalWeighting)*100,1,'.','')."%";
1416          } else {
1417            echo round(float_format($totalScore,1))."/".float_format($totalWeighting,1);
1418          }
1419          ?>
1420          </b>        
1421          <!--<button type="submit" class="save"><?php echo get_lang('Finish');?></button>-->            
1422      </div>
1423  <?php } 
1424       echo '</div>';
1425      Display::display_footer();
1426  } else {
1427      //record the results in the learning path, using the SCORM interface (API)
1428      echo '<script language="javascript" type="text/javascript">window.parent.API.void_save_asset('.$totalScore.','.$totalWeighting.');</script>'."\n";
1429      echo '</body></html>';
1430  }
1431  
1432  if(count($arrques)>0) {
1433      $mycharset = api_get_setting('platform_charset');
1434      $msg = '<html><head>
1435          <link rel="stylesheet" href="'.api_get_path(WEB_CODE_PATH).'css/'.api_get_setting('stylesheets').'/default.css" type="text/css">
1436          <meta content="text/html; charset='.$mycharset.'" http-equiv="content-type">';
1437      $msg .= '</head>
1438      <body><br />
1439      <p>'.get_lang('OpenQuestionsAttempted').' : 
1440      </p>
1441      <p>'.get_lang('AttemptDetails').' : ><br />
1442      </p>
1443      <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">
1444                          <tr>
1445          <td width="229" valign="top"><h2>&nbsp;&nbsp;'.get_lang('CourseName').'</h2></td>
1446          <td width="469" valign="top"><h2>#course#</h2></td>
1447        </tr>
1448        <tr>
1449          <td width="229" valign="top" class="outerframe">&nbsp;&nbsp;'.get_lang('TestAttempted').'</span></td>
1450          <td width="469" valign="top" class="outerframe">#exercise#</td>
1451        </tr>
1452        <tr>
1453          <td valign="top">&nbsp;&nbsp;<span class="style10">'.get_lang('StudentName').'</span></td>
1454          <td valign="top" >#firstName# #lastName#</td>
1455        </tr>
1456        <tr>
1457          <td valign="top" >&nbsp;&nbsp;'.get_lang('StudentEmail').' </td>
1458          <td valign="top"> #mail#</td>
1459      </tr></table>
1460      <p><br />'.get_lang('OpenQuestionsAttemptedAre').' :</p>
1461       <table width="730" height="136" border="0" cellpadding="3" cellspacing="3">';
1462      for($i=0;$i<sizeof($arrques);$i++) {
1463            $msg.='
1464              <tr>
1465              <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Question').'</span></td>
1466              <td width="473" valign="top" bgcolor="#F3F3F3"><span class="style16"> #questionName#</span></td>
1467                </tr>
1468                <tr>
1469              <td width="220" valign="top" bgcolor="#E5EDF8">&nbsp;&nbsp;<span class="style10">'.get_lang('Answer').' </span></td>
1470              <td valign="top" bgcolor="#F3F3F3"><span class="style16"> #answer#</span></td>
1471                </tr>';
1472          
1473              $msg1= str_replace("#exercise#",$exerciseTitle,$msg);
1474              $msg= str_replace("#firstName#",$firstName,$msg1);
1475              $msg1= str_replace("#lastName#",$lastName,$msg);
1476              $msg= str_replace("#mail#",$mail,$msg1);
1477              $msg1= str_replace("#questionName#",$arrques[$i],$msg);
1478              $msg= str_replace("#answer#",$arrans[$i],$msg1);
1479              $msg1= str_replace("#i#",$i,$msg);
1480              $msg= str_replace("#course#",$courseName,$msg1);
1481      }
1482          $msg.='</table><br>
1483           <span class="style16">'.get_lang('ClickToCommentAndGiveFeedback').',<br />
1484      <a href="#url#">#url#</a></span></body></html>';
1485      
1486          $msg1= str_replace("#url#",$url,$msg);
1487          $mail_content = $msg1;
1488          $student_name = $_SESSION['_user']['firstName'].' '.$_SESSION['_user']['lastName'];
1489          $subject = get_lang('OpenQuestionsAttempted');
1490          
1491          $from = api_get_setting('noreply_email_address');
1492          if($from == '') {
1493              if(isset($_SESSION['id_session']) && $_SESSION['id_session'] != ''){
1494                  $sql = 'SELECT user.email,user.lastname,user.firstname FROM '.TABLE_MAIN_SESSION.' as session, '.TABLE_MAIN_USER.' as user 
1495                          WHERE session.id_coach = user.user_id
1496                          AND session.id = "'.Database::escape_string($_SESSION['id_session']).'"
1497                          ';
1498                  $result=api_sql_query($sql,__FILE__,__LINE__);
1499                  $from = Database::result($result,0,'email');
1500                  $from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
1501              } else {
1502                  $array = explode(' ',$_SESSION['_course']['titular']);
1503                  $firstname = $array[1];
1504                  $lastname = $array[0];
1505                  $sql = 'SELECT email,lastname,firstname FROM '.TABLE_MAIN_USER.'
1506                          WHERE firstname = "'.Database::escape_string($firstname).'"
1507                          AND lastname = "'.Database::escape_string($lastname).'"
1508                  ';
1509                  $result=api_sql_query($sql,__FILE__,__LINE__);
1510                  $from = Database::result($result,0,'email');
1511                  $from_name = Database::result($result,0,'firstname').' '.Database::result($result,0,'lastname');
1512              }
1513          }    
1514      api_mail_html($student_name, $to, $subject, $mail_content, $from_name, $from, array('encoding'=>$mycharset,'charset'=>$mycharset));
1515  }
1516  
1517  ?>

title

Description

title

Description

title

Description

title

title

Body