MDL-38489 mod_scorm: added require to be explicit
[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");
18require_once($CFG->dirroot.'/mod/scorm/locallib.php');
29b56cfd 19require_once($CFG->dirroot.'/course/lib.php');
f7b5c6aa
DM
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
d32e353e 24$action = optional_param('action', '', PARAM_ALPHA);
f7b5c6aa
DM
25
26if (!empty($id)) {
27 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
28 print_error('invalidcoursemodule');
f9d5371b 29 }
f7b5c6aa
DM
30 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
31 print_error('coursemisconf');
6381fa56 32 }
f7b5c6aa
DM
33 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
34 print_error('invalidcoursemodule');
bd803ac7 35 }
f7b5c6aa
DM
36} else if (!empty($a)) {
37 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
38 print_error('invalidcoursemodule');
d54e2145 39 }
f7b5c6aa
DM
40 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
41 print_error('coursemisconf');
d54e2145 42 }
f7b5c6aa
DM
43 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
44 print_error('invalidcoursemodule');
30bce58e 45 }
f7b5c6aa
DM
46} else {
47 print_error('missingparameter');
48}
49
50$url = new moodle_url('/mod/scorm/view.php', array('id'=>$cm->id));
51if ($organization !== '') {
52 $url->param('organization', $organization);
53}
54$PAGE->set_url($url);
55$forcejs = get_config('scorm', 'forcejavascript');
56if (!empty($forcejs)) {
57 $PAGE->add_body_class('forcejavascript');
58}
59
cdbea7ee 60require_login($course, false, $cm);
f7b5c6aa 61
81f460b1
DM
62$context = context_course::instance($course->id);
63$contextmodule = context_module::instance($cm->id);
64
65$launch = false; // Does this automatically trigger a launch based on skipview.
d5159fb8 66if (!empty($scorm->popup)) {
35cfa9e6
PH
67 $orgidentifier = '';
68 $scoid = 0;
234415c4 69 if ($scorm->skipview >= SCORM_SKIPVIEW_FIRST &&
81f460b1
DM
70 has_capability('mod/scorm:skipview', $contextmodule) &&
71 !has_capability('mod/scorm:viewreport', $contextmodule)) { // Don't skip users with the capability to view reports.
72
35cfa9e6 73 // do we launch immediately and redirect the parent back ?
410b7c9b 74 if ($scorm->skipview == SCORM_SKIPVIEW_ALWAYS || !scorm_has_tracks($scorm->id, $USER->id)) {
35cfa9e6
PH
75 $orgidentifier = '';
76 if ($sco = scorm_get_sco($scorm->launch, SCO_ONLY)) {
77 if (($sco->organization == '') && ($sco->launch == '')) {
78 $orgidentifier = $sco->identifier;
79 } else {
80 $orgidentifier = $sco->organization;
81 }
82 $scoid = $sco->id;
83 }
812bdaeb 84 $launch = true;
35cfa9e6
PH
85 }
86 }
011ae52a 87 // Redirect back to the section with one section per page ?
011ae52a 88
b98dcd7d
DM
89 $courseformat = course_get_format($course)->get_course();
90 $sectionid = '';
91 if (isset($courseformat->coursedisplay) && $courseformat->coursedisplay == COURSE_DISPLAY_MULTIPAGE) {
011ae52a 92 $sectionid = $cm->section;
011ae52a
VM
93 }
94
35cfa9e6
PH
95 $PAGE->requires->data_for_js('scormplayerdata', Array('launch' => $launch,
96 'currentorg' => $orgidentifier,
97 'sco' => $scoid,
98 'scorm' => $scorm->id,
b98dcd7d 99 'courseurl' => course_get_url($course, $sectionid)->out(false),
35cfa9e6
PH
100 'cwidth' => $scorm->width,
101 'cheight' => $scorm->height,
102 'popupoptions' => $scorm->options), true);
d5159fb8
DM
103 $PAGE->requires->js('/mod/scorm/view.js', true);
104}
105
ba0e91a2
DM
106if (isset($SESSION->scorm)) {
107 unset($SESSION->scorm);
f7b5c6aa
DM
108}
109
110$strscorms = get_string("modulenameplural", "scorm");
111$strscorm = get_string("modulename", "scorm");
112
8ebbb06a
SH
113$shortname = format_string($course->shortname, true, array('context' => $context));
114$pagetitle = strip_tags($shortname.': '.format_string($scorm->name));
f7b5c6aa
DM
115
116add_to_log($course->id, 'scorm', 'pre-view', 'view.php?id='.$cm->id, "$scorm->id", $cm->id);
117
81f460b1 118if (empty($launch) && (has_capability('mod/scorm:skipview', $contextmodule))) {
666efc14 119 scorm_simple_play($scorm, $USER, $contextmodule, $cm->id);
f7b5c6aa
DM
120}
121
122//
123// Print the page header
124//
125$PAGE->set_title($pagetitle);
126$PAGE->set_heading($course->fullname);
127echo $OUTPUT->header();
128
d32e353e
DM
129if (!empty($action) && confirm_sesskey() && has_capability('mod/scorm:deleteownresponses', $contextmodule)) {
130 if ($action == 'delete') {
131 $confirmurl = new moodle_url($PAGE->url, array('action'=>'deleteconfirm'));
132 echo $OUTPUT->confirm(get_string('deleteuserattemptcheck', 'scorm'), $confirmurl, $PAGE->url);
133 echo $OUTPUT->footer();
134 exit;
135 } else if ($action == 'deleteconfirm') {
136 //delete this users attempts.
137 $DB->delete_records('scorm_scoes_track', array('userid' => $USER->id, 'scormid' => $scorm->id));
138 scorm_update_grades($scorm, $USER->id, true);
139 echo $OUTPUT->notification(get_string('scormresponsedeleted', 'scorm'), 'notifysuccess');
140 }
141}
142
f7b5c6aa
DM
143$currenttab = 'info';
144require($CFG->dirroot . '/mod/scorm/tabs.php');
145
146// Print the main part of the page
147echo $OUTPUT->heading(format_string($scorm->name));
148$attemptstatus = '';
da92e3b0
DM
149if (empty($launch) && ($scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ALL ||
150 $scorm->displayattemptstatus == SCORM_DISPLAY_ATTEMPTSTATUS_ENTRY)) {
d32e353e 151 $attemptstatus = scorm_get_attempt_status($USER, $scorm, $cm);
f7b5c6aa
DM
152}
153echo $OUTPUT->box(format_module_intro('scorm', $scorm, $cm->id).$attemptstatus, 'generalbox boxaligncenter boxwidthwide', 'intro');
154
155$scormopen = true;
156$timenow = time();
157if (!empty($scorm->timeopen) && $scorm->timeopen > $timenow) {
158 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
159 $scormopen = false;
160}
161if (!empty($scorm->timeclose) && $timenow > $scorm->timeclose) {
162 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
163 $scormopen = false;
164}
81f460b1 165if ($scormopen && empty($launch)) {
f7b5c6aa
DM
166 scorm_view_display($USER, $scorm, 'view.php?id='.$cm->id, $cm);
167}
168if (!empty($forcejs)) {
169 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
170}
d5159fb8
DM
171
172if (!empty($scorm->popup)) {
173 $PAGE->requires->js_init_call('M.mod_scormform.init');
174}
175
f7b5c6aa 176echo $OUTPUT->footer();