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