Search moodle.org's
Developer Documentation


  • Bug fixes for general core bugs in 2.8.x ended 9 November 2015 (12 months).
  • Bug fixes for security issues in 2.8.x ended 9 May 2016 (18 months).
  • minimum PHP 5.4.4 (always use latest PHP 5.4.x or 5.5.x on Windows - http://windows.php.net/download/), PHP 7 is NOT supported
  • Differences Between: [Versions 28 and 29] [Versions 28 and 30] [Versions 28 and 31] [Versions 28 and 32] [Versions 28 and 33] [Versions 28 and 34] [Versions 28 and 35] [Versions 28 and 36] [Versions 28 and 37]

       1  <?php
       2  // This file is part of Moodle - http://moodle.org/
       3  //
       4  // Moodle is free software: you can redistribute it and/or modify
       5  // it under the terms of the GNU General Public License as published by
       6  // the Free Software Foundation, either version 3 of the License, or
       7  // (at your option) any later version.
       8  //
       9  // Moodle is distributed in the hope that it will be useful,
      10  // but WITHOUT ANY WARRANTY; without even the implied warranty of
      11  // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
      12  // GNU General Public License for more details.
      13  //
      14  // You should have received a copy of the GNU General Public License
      15  // along with Moodle.  If not, see <http://www.gnu.org/licenses/>.
      16  
      17  // This page prints a particular instance of aicc/scorm package.
      18  
      19  require_once('../../config.php');
      20  require_once($CFG->dirroot.'/mod/scorm/locallib.php');
      21  require_once($CFG->libdir . '/completionlib.php');
      22  
      23  $id = optional_param('cm', '', PARAM_INT);                          // Course Module ID, or
      24  $a = optional_param('a', '', PARAM_INT);                            // scorm ID
      25  $scoid = required_param('scoid', PARAM_INT);                        // sco ID
      26  $mode = optional_param('mode', 'normal', PARAM_ALPHA);              // navigation mode
      27  $currentorg = optional_param('currentorg', '', PARAM_RAW);          // selected organization
      28  $newattempt = optional_param('newattempt', 'off', PARAM_ALPHA);     // the user request to start a new attempt.
      29  $displaymode = optional_param('display', '', PARAM_ALPHA);
      30  
      31  if (!empty($id)) {
      32      if (! $cm = get_coursemodule_from_id('scorm', $id)) {
      33          print_error('invalidcoursemodule');
      34      }
      35      if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
      36          print_error('coursemisconf');
      37      }
      38      if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
      39          print_error('invalidcoursemodule');
      40      }
      41  } else if (!empty($a)) {
      42      if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
      43          print_error('invalidcoursemodule');
      44      }
      45      if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
      46          print_error('coursemisconf');
      47      }
      48      if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
      49          print_error('invalidcoursemodule');
      50      }
      51  } else {
      52      print_error('missingparameter');
      53  }
      54  
      55  // PARAM_RAW is used for $currentorg, validate it against records stored in the table.
      56  if (!empty($currentorg)) {
      57      if (!$DB->record_exists('scorm_scoes', array('scorm' => $scorm->id, 'identifier' => $currentorg))) {
      58          $currentorg = '';
      59      }
      60  }
      61  
      62  // If new attempt is being triggered set normal mode and increment attempt number.
      63  $attempt = scorm_get_last_attempt($scorm->id, $USER->id);
      64  
      65  // Check mode is correct and set/validate mode/attempt/newattempt (uses pass by reference).
      66  scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode);
      67  
      68  if (!empty($scoid)) {
      69      $scoid = scorm_check_launchable_sco($scorm, $scoid);
      70  }
      71  
      72  $url = new moodle_url('/mod/scorm/player.php', array('scoid' => $scoid, 'cm' => $cm->id));
      73  if ($mode !== 'normal') {
      74      $url->param('mode', $mode);
      75  }
      76  if ($currentorg !== '') {
      77      $url->param('currentorg', $currentorg);
      78  }
      79  if ($newattempt !== 'off') {
      80      $url->param('newattempt', $newattempt);
      81  }
      82  $PAGE->set_url($url);
      83  $forcejs = get_config('scorm', 'forcejavascript');
      84  if (!empty($forcejs)) {
      85      $PAGE->add_body_class('forcejavascript');
      86  }
      87  $collapsetocwinsize = get_config('scorm', 'collapsetocwinsize');
      88  if (empty($collapsetocwinsize)) {
      89      // Set as default window size to collapse TOC.
      90      $collapsetocwinsize = 767;
      91  } else {
      92      $collapsetocwinsize = intval($collapsetocwinsize);
      93  }
      94  
      95  require_login($course, false, $cm);
      96  
      97  $strscorms = get_string('modulenameplural', 'scorm');
      98  $strscorm  = get_string('modulename', 'scorm');
      99  $strpopup = get_string('popup', 'scorm');
     100  $strexit = get_string('exitactivity', 'scorm');
     101  
     102  $coursecontext = context_course::instance($course->id);
     103  
     104  if ($displaymode == 'popup') {
     105      $PAGE->set_pagelayout('embedded');
     106  } else {
     107      $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
     108      $pagetitle = strip_tags("$shortname: ".format_string($scorm->name));
     109      $PAGE->set_title($pagetitle);
     110      $PAGE->set_heading($course->fullname);
     111  }
     112  if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', context_module::instance($cm->id))) {
     113      echo $OUTPUT->header();
     114      notice(get_string("activityiscurrentlyhidden"));
     115      echo $OUTPUT->footer();
     116      die;
     117  }
     118  
     119  // Check if SCORM available.
     120  list($available, $warnings) = scorm_get_availability_status($scorm);
     121  if (!$available) {
     122      $reason = current(array_keys($warnings));
     123      echo $OUTPUT->header();
     124      echo $OUTPUT->box(get_string($reason, "scorm", $warnings[$reason]), "generalbox boxaligncenter");
     125      echo $OUTPUT->footer();
     126      die;
     127  }
     128  
     129  // TOC processing
     130  $scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR));   // Just to be safe.
     131  if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
     132      $scorm->version = 'scorm_12';
     133  }
     134  require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
     135  
     136  $result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
     137  $sco = $result->sco;
     138  if ($scorm->lastattemptlock == 1 && $result->attemptleft == 0) {
     139      echo $OUTPUT->header();
     140      echo $OUTPUT->notification(get_string('exceededmaxattempts', 'scorm'));
     141      echo $OUTPUT->footer();
     142      exit;
     143  }
     144  
     145  $scoidstr = '&amp;scoid='.$sco->id;
     146  $modestr = '&amp;mode='.$mode;
     147  
     148  $SESSION->scorm = new stdClass();
     149  $SESSION->scorm->scoid = $sco->id;
     150  $SESSION->scorm->scormstatus = 'Not Initialized';
     151  $SESSION->scorm->scormmode = $mode;
     152  $SESSION->scorm->attempt = $attempt;
     153  
     154  // Mark module viewed.
     155  $completion = new completion_info($course);
     156  $completion->set_module_viewed($cm);
     157  
     158  // Print the page header.
     159  if (empty($scorm->popup) || $displaymode == 'popup') {
     160      $exitlink = html_writer::link($CFG->wwwroot.'/course/view.php?id='.$scorm->course, $strexit, array('title' => $strexit));
     161      $PAGE->set_button($exitlink);
     162  }
     163  
     164  $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => false,
     165                                                         'currentorg' => '',
     166                                                         'sco' => 0,
     167                                                         'scorm' => 0,
     168                                                         'courseid' => $scorm->course,
     169                                                         'cwidth' => $scorm->width,
     170                                                         'cheight' => $scorm->height,
     171                                                         'popupoptions' => $scorm->options), true);
     172  $PAGE->requires->js('/mod/scorm/request.js', true);
     173  $PAGE->requires->js('/lib/cookies.js', true);
     174  
     175  if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.js')) {
     176      $PAGE->requires->js('/mod/scorm/datamodels/'.$scorm->version.'.js', true);
     177  } else {
     178      $PAGE->requires->js('/mod/scorm/datamodels/scorm_12.js', true);
     179  }
     180  
     181  echo $OUTPUT->header();
     182  if (!empty($scorm->displayactivityname)) {
     183      echo $OUTPUT->heading(format_string($scorm->name));
     184  }
     185  
     186  $PAGE->requires->string_for_js('navigation', 'scorm');
     187  $PAGE->requires->string_for_js('toc', 'scorm');
     188  $PAGE->requires->string_for_js('hide', 'moodle');
     189  $PAGE->requires->string_for_js('show', 'moodle');
     190  $PAGE->requires->string_for_js('popupsblocked', 'scorm');
     191  
     192  $name = false;
     193  
     194  echo html_writer::start_div('', array('id' => 'scormpage'));
     195  echo html_writer::start_div('', array('id' => 'tocbox'));
     196  echo html_writer::div(html_writer::tag('script', '', array('id' => 'external-scormapi', 'type' => 'text/JavaScript')), '',
     197                          array('id' => 'scormapi-parent'));
     198  
     199  if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode == 'browse' or $mode == 'review') {
     200      echo html_writer::start_div('', array('id' => 'scormtop'));
     201      echo $mode == 'browse' ? html_writer::div(get_string('browsemode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : '';
     202      echo $mode == 'review' ? html_writer::div(get_string('reviewmode', 'scorm'), 'scorm-left', array('id' => 'scormmode')) : '';
     203      if ($scorm->hidetoc == SCORM_TOC_POPUP) {
     204          echo html_writer::div($result->tocmenu, 'scorm-right', array('id' => 'scormnav'));
     205      }
     206      echo html_writer::end_div();
     207  }
     208  
     209  echo html_writer::start_div('', array('id' => 'toctree'));
     210  
     211  if (empty($scorm->popup) || $displaymode == 'popup') {
     212      echo $result->toc;
     213  } else {
     214      // Added incase javascript popups are blocked we don't provide a direct link
     215      // to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
     216      $linkcourse = html_writer::link($CFG->wwwroot.'/course/view.php?id='.
     217                      $scorm->course, get_string('finishscormlinkname', 'scorm'));
     218      echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
     219  }
     220  echo html_writer::end_div(); // Toc tree ends.
     221  echo html_writer::end_div(); // Toc box ends.
     222  echo html_writer::tag('noscript', html_writer::div(get_string('noscriptnoscorm', 'scorm'), '', array('id' => 'noscript')));
     223  
     224  if ($result->prerequisites) {
     225      if ($scorm->popup != 0 && $displaymode !== 'popup') {
     226          // Clean the name for the window as IE is fussy.
     227          $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
     228          if (!$name) {
     229              $name = 'DefaultPlayerWindow';
     230          }
     231          $name = 'scorm_'.$name;
     232          echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
     233          $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup', 'mode' => $mode));
     234          echo html_writer::script(
     235              js_writer::function_call('scorm_openpopup', Array($url->out(false),
     236                                                         $name, $scorm->options,
     237                                                         $scorm->width, $scorm->height)));
     238          echo html_writer::tag('noscript', html_writer::tag('iframe', '', array('id' => 'main',
     239                                  'class' => 'scoframe', 'name' => 'main', 'src' => 'loadSCO.php?id='.$cm->id.$scoidstr.$modestr)));
     240      }
     241  } else {
     242      echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
     243  }
     244  echo html_writer::end_div(); // Scorm page ends.
     245  
     246  $scoes = scorm_get_toc_object($USER, $scorm, $currentorg, $sco->id, $mode, $attempt);
     247  $adlnav = scorm_get_adlnav_json($scoes['scoes']);
     248  
     249  if (empty($scorm->popup) || $displaymode == 'popup') {
     250      if (!isset($result->toctitle)) {
     251          $result->toctitle = get_string('toc', 'scorm');
     252      }
     253      $jsmodule = array(
     254          'name' => 'mod_scorm',
     255          'fullpath' => '/mod/scorm/module.js',
     256          'requires' => array('json'),
     257      );
     258      $scorm->nav = intval($scorm->nav);
     259      $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->nav, $scorm->navpositionleft, $scorm->navpositiontop,
     260                              $scorm->hidetoc, $collapsetocwinsize, $result->toctitle, $name, $sco->id, $adlnav), false, $jsmodule);
     261  }
     262  if (!empty($forcejs)) {
     263      echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
     264  }
     265  
     266  if (file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.php')) {
     267      include_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'.php');
     268  } else {
     269      include_once($CFG->dirroot.'/mod/scorm/datamodels/scorm_12.php');
     270  }
     271  
     272  // Add the checknet system to keep checking for a connection.
     273  $PAGE->requires->string_for_js('networkdropped', 'mod_scorm');
     274  $PAGE->requires->yui_module('moodle-core-checknet', 'M.core.checknet.init', array(array(
     275      'message' => array('networkdropped', 'mod_scorm'),
     276  )));
     277  echo $OUTPUT->footer();
     278  
     279  // Set the start time of this SCO.
     280  scorm_insert_track($USER->id, $scorm->id, $scoid, $attempt, 'x.start.time', time());
    

    Search This Site: