weekly release 4.0dev
[moodle.git] / mod / scorm / view.php
CommitLineData
5c508e3f 1<?php
f7b5c6aa
DM
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
17require_once("../../config.php");
ade341de 18require_once($CFG->dirroot.'/mod/scorm/lib.php');
f7b5c6aa 19require_once($CFG->dirroot.'/mod/scorm/locallib.php');
29b56cfd 20require_once($CFG->dirroot.'/course/lib.php');
f7b5c6aa
DM
21
22$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
23$a = optional_param('a', '', PARAM_INT); // scorm ID
4cb25b36 24$organization = optional_param('organization', '', PARAM_INT); // organization ID.
d32e353e 25$action = optional_param('action', '', PARAM_ALPHA);
6573b077 26$preventskip = optional_param('preventskip', '', PARAM_INT); // Prevent Skip view, set by javascript redirects.
f7b5c6aa
DM
27
28if (!empty($id)) {
d6d0c4e0 29 if (! $cm = get_coursemodule_from_id('scorm', $id, 0, true)) {
f7b5c6aa 30 print_error('invalidcoursemodule');
f9d5371b 31 }
27b8872c 32 if (! $course = $DB->get_record("course", array("id" => $cm->course))) {
f7b5c6aa 33 print_error('coursemisconf');
6381fa56 34 }
27b8872c 35 if (! $scorm = $DB->get_record("scorm", array("id" => $cm->instance))) {
f7b5c6aa 36 print_error('invalidcoursemodule');
bd803ac7 37 }
f7b5c6aa 38} else if (!empty($a)) {
27b8872c 39 if (! $scorm = $DB->get_record("scorm", array("id" => $a))) {
f7b5c6aa 40 print_error('invalidcoursemodule');
d54e2145 41 }
27b8872c 42 if (! $course = $DB->get_record("course", array("id" => $scorm->course))) {
f7b5c6aa 43 print_error('coursemisconf');
d54e2145 44 }
d6d0c4e0 45 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id, true)) {
f7b5c6aa 46 print_error('invalidcoursemodule');
30bce58e 47 }
f7b5c6aa
DM
48} else {
49 print_error('missingparameter');
50}
51
27b8872c 52$url = new moodle_url('/mod/scorm/view.php', array('id' => $cm->id));
f7b5c6aa
DM
53if ($organization !== '') {
54 $url->param('organization', $organization);
55}
56$PAGE->set_url($url);
57$forcejs = get_config('scorm', 'forcejavascript');
58if (!empty($forcejs)) {
59 $PAGE->add_body_class('forcejavascript');
60}
61
cdbea7ee 62require_login($course, false, $cm);
f7b5c6aa 63
81f460b1
DM
64$context = context_course::instance($course->id);
65$contextmodule = context_module::instance($cm->id);
66
67$launch = false; // Does this automatically trigger a launch based on skipview.
d5159fb8 68if (!empty($scorm->popup)) {
35cfa9e6 69 $scoid = 0;
6f850a51 70 $orgidentifier = '';
4d3fb5b8
DM
71
72 $result = scorm_get_toc($USER, $scorm, $cm->id, TOCFULLURL);
73 // Set last incomplete sco to launch first.
74 if (!empty($result->sco->id)) {
7c75e027 75 $sco = $result->sco;
4d3fb5b8 76 } else {
7c75e027
DM
77 $sco = scorm_get_sco($scorm->launch, SCO_ONLY);
78 }
79 if (!empty($sco)) {
80 $scoid = $sco->id;
81 if (($sco->organization == '') && ($sco->launch == '')) {
82 $orgidentifier = $sco->identifier;
83 } else {
84 $orgidentifier = $sco->organization;
6f850a51 85 }
6f850a51
N
86 }
87
6573b077 88 if (empty($preventskip) && $scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
81f460b1
DM
89 has_capability('mod/scorm:skipview', $contextmodule) &&
90 !has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
91
4cb25b36 92 // Do we launch immediately and redirect the parent back ?
410b7c9b 93 if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $USER->id)) {
812bdaeb 94 $launch = true;
35cfa9e6
PH
95 }
96 }
011ae52a 97 // Redirect back to the section with one section per page ?
011ae52a 98
b98dcd7d 99 $courseformat = course_get_format($course)->get_course();
6573b077
DM
100 if ($courseformat->format == 'singleactivity') {
101 $courseurl = $url->out(false, array('preventskip' => '1'));
102 } else {
b96da4ea 103 $courseurl = course_get_url($course, $cm->sectionnum)->out(false);
6573b077 104 }
35cfa9e6
PH
105 $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => $launch,
106 'currentorg' => $orgidentifier,
107 'sco' => $scoid,
108 'scorm' => $scorm->id,
6573b077 109 'courseurl' => $courseurl,
35cfa9e6
PH
110 'cwidth' => $scorm->width,
111 'cheight' => $scorm->height,
112 'popupoptions' => $scorm->options), true);
6573b077
DM
113 $PAGE->requires->string_for_js('popupsblocked', 'scorm');
114 $PAGE->requires->string_for_js('popuplaunched', 'scorm');
d5159fb8
DM
115 $PAGE->requires->js('/mod/scorm/view.js', true);
116}
117
ba0e91a2
DM
118if (isset($SESSION->scorm)) {
119 unset($SESSION->scorm);
f7b5c6aa
DM
120}
121
122$strscorms = get_string("modulenameplural", "scorm");
123$strscorm = get_string("modulename", "scorm");
124
8ebbb06a
SH
125$shortname = format_string($course->shortname, true, array('context' => $context));
126$pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
f7b5c6aa 127
0a616190 128// Trigger module viewed event.
ade341de 129scorm_view($scorm, $course, $cm, $contextmodule);
f7b5c6aa 130
6573b077 131if (empty($preventskip) && empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
666efc14 132 scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
f7b5c6aa
DM
133}
134
4cb25b36 135// Print the page header.
136
f7b5c6aa
DM
137$PAGE->set_title($pagetitle);
138$PAGE->set_heading($course->fullname);
139echo $OUTPUT->header();
b2970f96 140echo $OUTPUT->heading(format_string($scorm->name));
f7b5c6aa 141
92064623
MH
142// Display any activity information (eg completion requirements / dates).
143$cminfo = cm_info::create($cm);
144$completiondetails = \core_completion\cm_completion_details::get_instance($cminfo, $USER->id);
145$activitydates = \core\activity_dates::get_dates_for_module($cminfo, $USER->id);
146echo $OUTPUT->activity_information($cminfo, $completiondetails, $activitydates);
147
d32e353e
DM
148if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
149 if ($action == 'delete') {
27b8872c 150 $confirmurl = new moodle_url($PAGE->url, array('action' => 'deleteconfirm'));
d32e353e
DM
151 echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
152 echo $OUTPUT->footer();
153 exit;
154 } else if ($action == 'deleteconfirm') {
4cb25b36 155 // Delete this users attempts.
d32e353e
DM
156 $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id));
157 scorm_update_grades($scorm, $USER->id, true);
158 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
159 }
160}
161
f7b5c6aa
DM
162$currenttab = 'info';
163require($CFG->dirroot . '/mod/scorm/tabs.php');
164
4cb25b36 165// Print the main part of the page.
f7b5c6aa 166$attemptstatus = '';
da92e3b0
DM
167if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ALL ||
168 $scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY)) {
d32e353e 169 $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
f7b5c6aa 170}
f25185d7 171echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'container', 'intro');
f7b5c6aa 172
3ba12dcc 173// Check if SCORM available. No need to display warnings because activity dates are displayed at the top of the page.
02c256c9 174list($available, $warnings) = scorm_get_availability_status($scorm);
02c256c9
JL
175
176if ($available && empty($launch)) {
0b9fc18b 177 scorm_print_launch($USER, $scorm, 'view.php?id='.$cm->id, $cm);
f7b5c6aa
DM
178}
179if (!empty($forcejs)) {
e63d7244
DM
180 $message = $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "container forcejavascriptmessage");
181 echo html_writer::tag('noscript', $message);
f7b5c6aa 182}
d5159fb8
DM
183
184if (!empty($scorm->popup)) {
185 $PAGE->requires->js_init_call('M.mod_scormform.init');
186}
187
f7b5c6aa 188echo $OUTPUT->footer();