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
  •    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 script uses installed report plugins to print scorm reports.
      18  
      19  require_once("../../config.php");
      20  require_once($CFG->libdir.'/tablelib.php');
      21  require_once($CFG->dirroot.'/mod/scorm/locallib.php');
      22  require_once($CFG->dirroot.'/mod/scorm/reportsettings_form.php');
      23  require_once($CFG->dirroot.'/mod/scorm/report/reportlib.php');
      24  require_once($CFG->libdir.'/formslib.php');
      25  
      26  define('SCORM_REPORT_DEFAULT_PAGE_SIZE', 20);
      27  define('SCORM_REPORT_ATTEMPTS_ALL_STUDENTS', 0);
      28  define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH', 1);
      29  define('SCORM_REPORT_ATTEMPTS_STUDENTS_WITH_NO', 2);
      30  
      31  $id = required_param('id', PARAM_INT);// Course Module ID, or ...
      32  $download = optional_param('download', '', PARAM_RAW);
      33  $mode = optional_param('mode', '', PARAM_ALPHA); // Report mode.
      34  
      35  $cm = get_coursemodule_from_id('scorm', $id, 0, false, MUST_EXIST);
      36  $course = $DB->get_record('course', array('id' => $cm->course), '*', MUST_EXIST);
      37  $scorm = $DB->get_record('scorm', array('id' => $cm->instance), '*', MUST_EXIST);
      38  
      39  $contextmodule = context_module::instance($cm->id);
      40  $reportlist = scorm_report_list($contextmodule);
      41  
      42  $url = new moodle_url('/mod/scorm/report.php');
      43  
      44  $url->param('id', $id);
      45  if (empty($mode)) {
      46      $mode = reset($reportlist);
      47  } else if (!in_array($mode, $reportlist)) {
      48      print_error('erroraccessingreport', 'scorm');
      49  }
      50  $url->param('mode', $mode);
      51  
      52  $PAGE->set_url($url);
      53  
      54  require_login($course, false, $cm);
      55  $PAGE->set_pagelayout('report');
      56  
      57  require_capability('mod/scorm:viewreport', $contextmodule);
      58  
      59  if (count($reportlist) < 1) {
      60      print_error('erroraccessingreport', 'scorm');
      61  }
      62  
      63  // Trigger a report viewed event.
      64  $event = \mod_scorm\event\report_viewed::create(array(
      65      'context' => $contextmodule,
      66      'other' => array(
      67          'scormid' => $scorm->id,
      68          'mode' => $mode
      69      )
      70  ));
      71  $event->add_record_snapshot('course_modules', $cm);
      72  $event->add_record_snapshot('scorm', $scorm);
      73  $event->trigger();
      74  
      75  $userdata = null;
      76  if (!empty($download)) {
      77      $noheader = true;
      78  }
      79  // Print the page header.
      80  if (empty($noheader)) {
      81      $strreport = get_string('report', 'scorm');
      82      $strattempt = get_string('attempt', 'scorm');
      83  
      84      $PAGE->set_title("$course->shortname: ".format_string($scorm->name));
      85      $PAGE->set_heading($course->fullname);
      86      $PAGE->navbar->add($strreport, new moodle_url('/mod/scorm/report.php', array('id' => $cm->id)));
      87  
      88      echo $OUTPUT->header();
      89      echo $OUTPUT->heading(format_string($scorm->name));
      90      $currenttab = 'reports';
      91      require($CFG->dirroot . '/mod/scorm/tabs.php');
      92  }
      93  
      94  // Open the selected Scorm report and display it.
      95  $classname = "scormreport_{$mode}\\report";
      96  $legacyclassname = "scorm_{$mode}_report";
      97  $report = class_exists($classname) ? new $classname() : new $legacyclassname();
      98  $report->display($scorm, $cm, $course, $download); // Run the report!
      99  
     100  // Print footer.
     101  
     102  if (empty($noheader)) {
     103      echo $OUTPUT->footer();
     104  }
    

    Search This Site: