[ Index ]

PHP Cross Reference of moodle-2.8

title

Body

[close]

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

   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  require_once("../../config.php");
  18  require_once($CFG->dirroot.'/mod/scorm/locallib.php');
  19  require_once($CFG->dirroot.'/course/lib.php');
  20  
  21  $id = optional_param('id', '', PARAM_INT);       // Course Module ID, or
  22  $a = optional_param('a', '', PARAM_INT);         // scorm ID
  23  $organization = optional_param('organization', '', PARAM_INT); // organization ID.
  24  $action = optional_param('action', '', PARAM_ALPHA);
  25  $preventskip = optional_param('preventskip', '', PARAM_INT); // Prevent Skip view, set by javascript redirects.
  26  
  27  if (!empty($id)) {
  28      if (! $cm = get_coursemodule_from_id('scorm', $id, 0, true)) {
  29          print_error('invalidcoursemodule');
  30      }
  31      if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
  32          print_error('coursemisconf');
  33      }
  34      if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
  35          print_error('invalidcoursemodule');
  36      }
  37  } else if (!empty($a)) {
  38      if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
  39          print_error('invalidcoursemodule');
  40      }
  41      if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
  42          print_error('coursemisconf');
  43      }
  44      if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id, true)) {
  45          print_error('invalidcoursemodule');
  46      }
  47  } else {
  48      print_error('missingparameter');
  49  }
  50  
  51  $url = new moodle_url('/mod/scorm/view.php', array('id' => $cm->id));
  52  if ($organization !== '') {
  53      $url->param('organization', $organization);
  54  }
  55  $PAGE->set_url($url);
  56  $forcejs = get_config('scorm', 'forcejavascript');
  57  if (!empty($forcejs)) {
  58      $PAGE->add_body_class('forcejavascript');
  59  }
  60  
  61  require_login($course, false, $cm);
  62  
  63  $context = context_course::instance($course->id);
  64  $contextmodule = context_module::instance($cm->id);
  65  
  66  $launch = false; // Does this automatically trigger a launch based on skipview.
  67  if (!empty($scorm->popup)) {
  68      $orgidentifier = '';
  69  
  70      $scoid = 0;
  71      $orgidentifier = '';
  72      if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) {
  73          if (($sco->organization == '') && ($sco->launch == '')) {
  74              $orgidentifier = $sco->identifier;
  75          } else {
  76              $orgidentifier = $sco->organization;
  77          }
  78          $scoid = $sco->id;
  79      }
  80  
  81      if (empty($preventskip) && $scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
  82          has_capability('mod/scorm:skipview', $contextmodule) &&
  83          !has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
  84  
  85          // Do we launch immediately and redirect the parent back ?
  86          if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $USER->id)) {
  87              $launch = true;
  88          }
  89      }
  90      // Redirect back to the section with one section per page ?
  91  
  92      $courseformat = course_get_format($course)->get_course();
  93      $sectionid = '';
  94      if (isset($courseformat->coursedisplay) && $courseformat->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
  95          $sectionid = $cm->sectionnum;
  96      }
  97      if ($courseformat->format == 'singleactivity') {
  98          $courseurl = $url->out(false, array('preventskip' => '1'));
  99      } else {
 100          $courseurl = course_get_url($course, $sectionid)->out(false);
 101      }
 102      $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => $launch,
 103                                                             'currentorg' => $orgidentifier,
 104                                                             'sco' => $scoid,
 105                                                             'scorm' => $scorm->id,
 106                                                             'courseurl' => $courseurl,
 107                                                             'cwidth' => $scorm->width,
 108                                                             'cheight' => $scorm->height,
 109                                                             'popupoptions' => $scorm->options), true);
 110      $PAGE->requires->string_for_js('popupsblocked', 'scorm');
 111      $PAGE->requires->string_for_js('popuplaunched', 'scorm');
 112      $PAGE->requires->js('/mod/scorm/view.js', true);
 113  }
 114  
 115  if (isset($SESSION->scorm)) {
 116      unset($SESSION->scorm);
 117  }
 118  
 119  $strscorms = get_string("modulenameplural", "scorm");
 120  $strscorm  = get_string("modulename", "scorm");
 121  
 122  $shortname = format_string($course->shortname, true, array('context' => $context));
 123  $pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
 124  
 125  // Trigger module viewed event.
 126  $event = \mod_scorm\event\course_module_viewed::create(array(
 127      'objectid' => $scorm->id,
 128      'context' => $contextmodule,
 129  ));
 130  $event->add_record_snapshot('course', $course);
 131  $event->add_record_snapshot('scorm', $scorm);
 132  $event->add_record_snapshot('course_modules', $cm);
 133  $event->trigger();
 134  
 135  if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
 136      scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
 137  }
 138  
 139  // Print the page header.
 140  
 141  $PAGE->set_title($pagetitle);
 142  $PAGE->set_heading($course->fullname);
 143  echo $OUTPUT->header();
 144  echo $OUTPUT->heading(format_string($scorm->name));
 145  
 146  if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
 147      if ($action == 'delete') {
 148          $confirmurl = new moodle_url($PAGE->url, array('action' => 'deleteconfirm'));
 149          echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
 150          echo $OUTPUT->footer();
 151          exit;
 152      } else if ($action == 'deleteconfirm') {
 153          // Delete this users attempts.
 154          $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id));
 155          scorm_update_grades($scorm, $USER->id, true);
 156          echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
 157      }
 158  }
 159  
 160  $currenttab = 'info';
 161  require($CFG->dirroot . '/mod/scorm/tabs.php');
 162  
 163  // Print the main part of the page.
 164  $attemptstatus = '';
 165  if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ALL ||
 166           $scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY)) {
 167      $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
 168  }
 169  echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
 170  
 171  $scormopen = true;
 172  $timenow = time();
 173  if (!empty($scorm->timeopen) && $scorm->timeopen > $timenow) {
 174      echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
 175      $scormopen = false;
 176  }
 177  if (!empty($scorm->timeclose) && $timenow > $scorm->timeclose) {
 178      echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
 179      $scormopen = false;
 180  }
 181  if ($scormopen && empty($launch)) {
 182      scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
 183  }
 184  if (!empty($forcejs)) {
 185      echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
 186  }
 187  
 188  if (!empty($scorm->popup)) {
 189      $PAGE->requires->js_init_call('M.mod_scormform.init');
 190  }
 191  
 192  echo $OUTPUT->footer();


Generated: Fri Nov 28 20:29:05 2014 Cross-referenced by PHPXref 0.7.1