[ Index ]

PHP Cross Reference of Moodle 1.9.3 [Build 15-Oct-2008]

title

Body

[close]

/mod/scorm/ -> report.php (source)

   1  <?php  // $Id: report.php,v 1.46.2.5 2008/08/19 06:59:23 tjhunt Exp $
   2  
   3  // This script uses installed report plugins to print quiz reports
   4  
   5      require_once("../../config.php");
   6      require_once ('locallib.php');
   7  
   8      $id = optional_param('id', '', PARAM_INT);    // Course Module ID, or
   9      $a = optional_param('a', '', PARAM_INT);     // SCORM ID
  10      $b = optional_param('b', '', PARAM_INT);     // SCO ID
  11      $user = optional_param('user', '', PARAM_INT);  // User ID
  12      $attempt = optional_param('attempt', '1', PARAM_INT);  // attempt number
  13  
  14      if (!empty($id)) {
  15          if (! $cm = get_coursemodule_from_id('scorm', $id)) {
  16              error('Course Module ID was incorrect');
  17          }
  18          if (! $course = get_record('course', 'id', $cm->course)) {
  19              error('Course is misconfigured');
  20          }
  21          if (! $scorm = get_record('scorm', 'id', $cm->instance)) {
  22              error('Course module is incorrect');
  23          }
  24      } else {
  25          if (!empty($b)) {
  26              if (! $sco = get_record('scorm_scoes', 'id', $b)) {
  27                  error('Scorm activity is incorrect');
  28              }
  29              $a = $sco->scorm;
  30          }
  31          if (!empty($a)) {
  32              if (! $scorm = get_record('scorm', 'id', $a)) {
  33                  error('Course module is incorrect');
  34              }
  35              if (! $course = get_record('course', 'id', $scorm->course)) {
  36                  error('Course is misconfigured');
  37              }
  38              if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
  39                  error('Course Module ID was incorrect');
  40              }
  41          }
  42      }
  43  
  44      require_login($course->id, false, $cm);
  45  
  46      if (!has_capability('mod/scorm:viewreport', get_context_instance(CONTEXT_MODULE,$cm->id))) {
  47          error('You are not allowed to use this script');
  48      }
  49  
  50      add_to_log($course->id, 'scorm', 'report', 'report.php?id='.$cm->id, $scorm->id, $cm->id);
  51  
  52      if (!empty($user)) {
  53          $userdata = scorm_get_user_data($user);
  54      } else {
  55          $userdata = null;
  56      }
  57  
  58  /// Print the page header
  59      if (empty($noheader)) {
  60  
  61          $strscorms = get_string('modulenameplural', 'scorm');
  62          $strscorm  = get_string('modulename', 'scorm');
  63          $strreport  = get_string('report', 'scorm');
  64          $strattempt  = get_string('attempt', 'scorm');
  65          $strname  = get_string('name');
  66          
  67          if (empty($b)) {
  68              if (empty($a)) {
  69                  $navigation = build_navigation('', $cm);
  70                  print_header("$course->shortname: ".format_string($scorm->name), $course->fullname,$navigation,
  71                               '', '', true);
  72              } else {
  73                  
  74                  $navlinks = array();
  75                  $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');    
  76                  $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => '', 'type' => 'title');
  77                  $navigation = build_navigation($navlinks, $cm);
  78                      
  79                  print_header("$course->shortname: ".format_string($scorm->name), $course->fullname,
  80                               $navigation, '', '', true);
  81              }
  82          } else {
  83  
  84              $navlinks = array();
  85              $navlinks[] = array('name' => $strreport, 'link' => "report.php?id=$cm->id", 'type' => 'title');    
  86              $navlinks[] = array('name' => "$strattempt $attempt - ".fullname($userdata), 'link' => "report.php?a=$a&amp;user=$user&amp;attempt=$attempt", 'type' => 'title');
  87              $navlinks[] = array('name' => $sco->title, 'link' => '', 'type' => 'title');
  88              $navigation = build_navigation($navlinks, $cm);
  89              
  90              print_header("$course->shortname: ".format_string($scorm->name), $course->fullname, $navigation,
  91                       '', '', true);
  92          }
  93          print_heading(format_string($scorm->name));
  94      }
  95  
  96      $scormpixdir = $CFG->modpixpath.'/scorm/pix';
  97  
  98      if (empty($b)) {
  99          if (empty($a)) {
 100              // No options, show the global scorm report
 101              
 102              if (!empty($CFG->enablegroupings) && !empty($cm->groupingid)) {
 103                  $sql = "SELECT st.userid, st.scormid
 104                          FROM {$CFG->prefix}scorm_scoes_track st
 105                              INNER JOIN {$CFG->prefix}groups_members gm ON st.userid = gm.userid
 106                              INNER JOIN {$CFG->prefix}groupings_groups gg ON gm.groupid = gg.groupid 
 107                          WHERE st.scormid = {$scorm->id} AND gg.groupingid = {$cm->groupingid}
 108                          GROUP BY st.userid,st.scormid
 109                          ";
 110              } else {
 111                  $sql = "SELECT st.userid, st.scormid
 112                          FROM {$CFG->prefix}scorm_scoes_track st 
 113                          WHERE st.scormid = {$scorm->id}
 114                          GROUP BY st.userid,st.scormid
 115                          ";
 116              }
 117              
 118              if ($scousers=get_records_sql($sql)) {
 119                  $table = new stdClass();
 120                  $table->head = array('&nbsp;', get_string('name'));
 121                  $table->align = array('center', 'left');
 122                  $table->wrap = array('nowrap', 'nowrap');
 123                  $table->width = '100%';
 124                  $table->size = array(10, '*');
 125  
 126                  $table->head[]= get_string('attempt','scorm');
 127                  $table->align[] = 'center';
 128                  $table->wrap[] = 'nowrap';
 129                  $table->size[] = '*';
 130  
 131                  $table->head[]= get_string('started','scorm');
 132                  $table->align[] = 'center';
 133                  $table->wrap[] = 'nowrap';
 134                  $table->size[] = '*';
 135  
 136                  $table->head[]= get_string('last','scorm');
 137                  $table->align[] = 'center';
 138                  $table->wrap[] = 'nowrap';
 139                  $table->size[] = '*';
 140  
 141                  $table->head[]= get_string('score','scorm');
 142                  $table->align[] = 'center';
 143                  $table->wrap[] = 'nowrap';
 144                  $table->size[] = '*';
 145  
 146                  foreach($scousers as $scouser){
 147                      $userdata = scorm_get_user_data($scouser->userid);
 148                      $attempt = scorm_get_last_attempt($scorm->id,$scouser->userid);    
 149                      for ($a = 1; $a<=$attempt; $a++) {
 150                          $row = array();
 151                          $row[] = print_user_picture($scouser->userid, $course->id, $userdata->picture, false, true);
 152                          $row[] = '<a href="'.$CFG->wwwroot.'/user/view.php?id='.$scouser->userid.'&amp;course='.$course->id.'">'.
 153                                   fullname($userdata).'</a>';
 154                          $row[] = '<a href="report.php?a='.$scorm->id.'&amp;user='.$scouser->userid.'&amp;attempt='.$a.'">'.$a.'</a>';
 155                          $select = 'scormid = '.$scorm->id.' and userid = '.$scouser->userid.' and attempt = '.$a;
 156                          $timetracks = get_record_select('scorm_scoes_track', $select,'min(timemodified) as started, max(timemodified) as last');      
 157                          $row[] = userdate($timetracks->started, get_string('strftimedaydatetime'));
 158                          $row[] = userdate($timetracks->last, get_string('strftimedaydatetime'));
 159   
 160                          $row[] = scorm_grade_user_attempt($scorm, $scouser->userid, $a);
 161                          $table->data[] = $row;
 162                      }
 163                  }
 164              }
 165              print_table($table);
 166          } else {
 167              if (!empty($user)) {
 168                  // User SCORM report
 169                  if ($scoes = get_records_select('scorm_scoes',"scorm='$scorm->id' ORDER BY id")) {
 170                      if (!empty($userdata)) {
 171                          print_simple_box_start('center');
 172                          echo '<div align="center">'."\n";
 173                          print_user_picture($user, $course->id, $userdata->picture, false, false);
 174                          echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
 175                               "$userdata->firstname $userdata->lastname</a><br />";
 176                          echo get_string('attempt','scorm').': '.$attempt;
 177                          echo '</div>'."\n";
 178                          print_simple_box_end();
 179  
 180                          // Print general score data
 181                          $table = new stdClass();
 182                          $table->head = array(get_string('title','scorm'),
 183                                               get_string('status','scorm'),
 184                                               get_string('time','scorm'),
 185                                               get_string('score','scorm'),
 186                                               '');
 187                          $table->align = array('left', 'center','center','right','left');
 188                          $table->wrap = array('nowrap', 'nowrap','nowrap','nowrap','nowrap');
 189                          $table->width = '80%';
 190                          $table->size = array('*', '*', '*', '*', '*');
 191                          foreach ($scoes as $sco) {
 192                              if ($sco->launch!='') {
 193                                  $row = array();
 194                                  $score = '&nbsp;';
 195                                  if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
 196                                      if ($trackdata->score_raw != '') {
 197                                          $score = $trackdata->score_raw;
 198                                      }
 199                                      if ($trackdata->status == '') {
 200                                          $trackdata->status = 'notattempted';
 201                                      }
 202                                      $detailslink = '<a href="report.php?b='.$sco->id.'&amp;user='.$user.'&amp;attempt='.$attempt.'" title="'.
 203                                                      get_string('details','scorm').'">'.get_string('details','scorm').'</a>';
 204                                  } else {
 205                                      $trackdata->status = 'notattempted';
 206                                      $trackdata->total_time = '&nbsp;';
 207                                      $detailslink = '&nbsp;';
 208                                  }
 209                                  $strstatus = get_string($trackdata->status,'scorm');
 210                                  $row[] = '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
 211                                           $strstatus.'" />&nbsp;'.format_string($sco->title);
 212                                  $row[] = get_string($trackdata->status,'scorm');
 213                                  $row[] = $trackdata->total_time;
 214                                  $row[] = $score;
 215                                  $row[] = $detailslink;
 216                              } else {
 217                                  $row = array(format_string($sco->title), '&nbsp;', '&nbsp;', '&nbsp;', '&nbsp;');
 218                              }
 219                              $table->data[] = $row;
 220                          }
 221                          print_table($table);
 222                      }
 223                  }
 224              } else {
 225                  notice('No users to report');
 226              }
 227          }
 228      } else {
 229          // User SCO report
 230          if (!empty($userdata)) {
 231              print_simple_box_start('center');
 232              //print_heading(format_string($sco->title));
 233              print_heading('<a href="'.$CFG->wwwroot.'/mod/scorm/player.php?a='.$scorm->id.'&amp;mode=browse&amp;scoid='.$sco->id.'" target="_new">'.format_string($sco->title).'</a>'); 
 234              echo '<div align="center">'."\n";
 235              print_user_picture($user, $course->id, $userdata->picture, false, false);
 236              echo "<a href=\"$CFG->wwwroot/user/view.php?id=$user&amp;course=$course->id\">".
 237                   "$userdata->firstname $userdata->lastname</a><br />";
 238              $scoreview = '';
 239              if ($trackdata = scorm_get_tracks($sco->id,$user,$attempt)) {
 240                  if ($trackdata->score_raw != '') {
 241                      $scoreview = get_string('score','scorm').':&nbsp;'.$trackdata->score_raw;
 242                  }
 243                  if ($trackdata->status == '') {
 244                      $trackdata->status = 'notattempted';
 245                  }
 246              } else {
 247                  $trackdata->status = 'notattempted';
 248                  $trackdata->total_time = '';
 249              }
 250              $strstatus = get_string($trackdata->status,'scorm');
 251              echo '<img src="'.$scormpixdir.'/'.$trackdata->status.'.gif" alt="'.$strstatus.'" title="'.
 252              $strstatus.'" />&nbsp;'.$trackdata->total_time.'<br />'.$scoreview.'<br />';
 253              echo '</div>'."\n";
 254              echo '<hr /><h2>'.get_string('details','scorm').'</h2>';
 255              
 256              // Print general score data
 257              $table = new stdClass();
 258              $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
 259              $table->align = array('left', 'left');
 260              $table->wrap = array('nowrap', 'nowrap');
 261              $table->width = '100%';
 262              $table->size = array('*', '*');
 263              
 264              $existelements = false;
 265              if ($scorm->version == 'SCORM_1.3') {
 266                  $elements = array('raw' => 'cmi.score.raw',
 267                                    'min' => 'cmi.score.min',
 268                                    'max' => 'cmi.score.max',
 269                                    'status' => 'cmi.completion_status',
 270                                    'time' => 'cmi.total_time');
 271              } else {
 272                  $elements = array('raw' => 'cmi.core.score.raw',
 273                                    'min' => 'cmi.core.score.min',
 274                                    'max' => 'cmi.core.score.max',
 275                                    'status' => 'cmi.core.lesson_status',
 276                                    'time' => 'cmi.core.total_time');
 277              }
 278              $printedelements = array();
 279              foreach ($elements as $key => $element) {
 280                  if (isset($trackdata->$element)) {
 281                      $existelements = true;
 282                      $printedelements[]=$element;
 283                      $row = array();
 284                      $row[] = get_string($key,'scorm');
 285                      $row[] = s($trackdata->$element);
 286                      $table->data[] = $row;
 287                  }
 288              }
 289              if ($existelements) {
 290                  echo '<h3>'.get_string('general','scorm').'</h3>';
 291                  print_table($table);
 292              }                
 293              
 294              // Print Interactions data
 295              $table = new stdClass();
 296              $table->head = array(get_string('identifier','scorm'),
 297                                   get_string('type','scorm'),
 298                                   get_string('result','scorm'),
 299                                   get_string('student_response','scorm'));
 300              $table->align = array('center', 'center', 'center', 'center');
 301              $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap');
 302              $table->width = '100%';
 303              $table->size = array('*', '*', '*', '*', '*');
 304              
 305              $existinteraction = false;
 306              
 307              $i = 0;
 308              $interactionid = 'cmi.interactions.'.$i.'.id';
 309              
 310              while (isset($trackdata->$interactionid)) {
 311                  $existinteraction = true;
 312                  $printedelements[]=$interactionid;
 313                  $elements = array($interactionid,
 314                                    'cmi.interactions.'.$i.'.type',
 315                                    'cmi.interactions.'.$i.'.result',
 316                                    'cmi.interactions.'.$i.'.learner_response');
 317                  $row = array();
 318                  foreach ($elements as $element) {
 319                      if (isset($trackdata->$element)) {
 320                          $row[] = s($trackdata->$element);
 321                          $printedelements[]=$element;
 322                      } else {
 323                          $row[] = '&nbsp;';
 324                      }
 325                  }
 326                  $table->data[] = $row;
 327                  
 328                  $i++;
 329                  $interactionid = 'cmi.interactions.'.$i.'.id';
 330              }
 331              if ($existinteraction) {
 332                  echo '<h3>'.get_string('interactions','scorm').'</h3>';
 333                  echo '<h3>'.get_string('interactions','scorm').'</h3>';
 334                  print_table($table);
 335              }
 336              
 337              // Print Objectives data
 338              $table = new stdClass();
 339              $table->head = array(get_string('identifier','scorm'),
 340                                   get_string('status','scorm'),
 341                                   get_string('raw','scorm'),
 342                                   get_string('min','scorm'),
 343                                   get_string('max','scorm'));
 344              $table->align = array('center', 'center', 'center', 'center', 'center');
 345              $table->wrap = array('nowrap', 'nowrap', 'nowrap', 'nowrap', 'nowrap');
 346              $table->width = '100%';
 347              $table->size = array('*', '*', '*', '*', '*');
 348              
 349              $existobjective = false;
 350              
 351              $i = 0;
 352              $objectiveid = 'cmi.objectives.'.$i.'.id';
 353              
 354              while (isset($trackdata->$objectiveid)) {
 355                  $existobjective = true;
 356                  $printedelements[]=$objectiveid;
 357                  $elements = array($objectiveid,
 358                                    'cmi.objectives.'.$i.'.status',
 359                                    'cmi.objectives.'.$i.'.score.raw',
 360                                    'cmi.objectives.'.$i.'.score.min',
 361                                    'cmi.objectives.'.$i.'.score.max');
 362                  $row = array();
 363                  foreach ($elements as $element) {
 364                      if (isset($trackdata->$element)) {
 365                          $row[] = s($trackdata->$element);
 366                          $printedelements[]=$element;
 367                      } else {
 368                          $row[] = '&nbsp;';
 369                      }
 370                  }
 371                  $table->data[] = $row;
 372                  
 373                  $i++;
 374                  $objectiveid = 'cmi.objectives.'.$i.'.id';
 375              }
 376              if ($existobjective) {
 377                  echo '<h3>'.get_string('objectives','scorm').'</h3>';
 378                  print_table($table);
 379              }
 380              $table = new stdClass();
 381              $table->head = array(get_string('element','scorm'), get_string('value','scorm'));
 382              $table->align = array('left', 'left');
 383              $table->wrap = array('nowrap', 'wrap');
 384              $table->width = '100%';
 385              $table->size = array('*', '*');
 386              
 387              $existelements = false;
 388              
 389              foreach($trackdata as $element => $value) {
 390                  if (substr($element,0,3) == 'cmi') { 
 391                      if (!(in_array ($element, $printedelements))) {
 392                          $existelements = true;
 393                          $row = array();
 394                          $row[] = get_string($element,'scorm') != '[['.$element.']]' ? get_string($element,'scorm') : $element;
 395                          $row[] = s($value);
 396                          $table->data[] = $row;
 397                      }
 398                  }
 399              }
 400              if ($existelements) {
 401                  echo '<h3>'.get_string('othertracks','scorm').'</h3>';
 402                  print_table($table);
 403              }                
 404              print_simple_box_end();
 405          } else {
 406              error('Missing script parameter');
 407          }
 408      }
 409  
 410  
 411      if (empty($noheader)) {
 412          print_footer($course);
 413      }
 414  ?>


Generated: Wed Jan 14 11:33:29 2009 Cross-referenced by PHPXref 0.7