MDL-41577 SCORM: remove old IE9 hack that didn't really work.
[moodle.git] / mod / scorm / player.php
CommitLineData
f7b5c6aa
DM
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/>.
f9d5371b 16
39355b46 17// This page prints a particular instance of aicc/scorm package.
f9d5371b 18
ca4eda13
DM
19require_once('../../config.php');
20require_once($CFG->dirroot.'/mod/scorm/locallib.php');
21require_once($CFG->libdir . '/completionlib.php');
134c8644 22
ca4eda13
DM
23$id = optional_param('cm', '', PARAM_INT); // Course Module ID, or
24$a = optional_param('a', '', PARAM_INT); // scorm ID
25$scoid = required_param('scoid', PARAM_INT); // sco ID
26$mode = optional_param('mode', 'normal', PARAM_ALPHA); // navigation mode
27$currentorg = optional_param('currentorg', '', PARAM_RAW); // selected organization
39355b46
DM
28$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt.
29$displaymode = optional_param('display', '', PARAM_ALPHA);
e73457e4 30
ca4eda13
DM
31if (!empty($id)) {
32 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
33 print_error('invalidcoursemodule');
f9d5371b 34 }
ca4eda13
DM
35 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
36 print_error('coursemisconf');
37 }
38 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
39 print_error('invalidcoursemodule');
5c508e3f 40 }
ca4eda13
DM
41} else if (!empty($a)) {
42 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
43 print_error('invalidcoursemodule');
5c508e3f 44 }
ca4eda13
DM
45 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
46 print_error('coursemisconf');
5c508e3f 47 }
ca4eda13
DM
48 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
49 print_error('invalidcoursemodule');
30bce58e 50 }
ca4eda13
DM
51} else {
52 print_error('missingparameter');
53}
39355b46
DM
54// If new attempt is being triggered set normal mode and increment attempt number.
55$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
56
57// Check mode is correct and set mode/attempt (uses pass by reference).
58scorm_check_mode($scorm, $newattempt, $attempt, $USER->id, $mode);
ca4eda13
DM
59
60$url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id));
61if ($mode !== 'normal') {
62 $url->param('mode', $mode);
63}
64if ($currentorg !== '') {
65 $url->param('currentorg', $currentorg);
66}
67if ($newattempt !== 'off') {
68 $url->param('newattempt', $newattempt);
69}
70$PAGE->set_url($url);
71$forcejs = get_config('scorm', 'forcejavascript');
72if (!empty($forcejs)) {
73 $PAGE->add_body_class('forcejavascript');
74}
df5c7086
MG
75$collapsetocwinsize = get_config('scorm', 'collapsetocwinsize');
76if (empty($collapsetocwinsize)) {
77 // Set as default window size to collapse TOC.
78 $collapsetocwinsize = 767;
79} else {
80 $collapsetocwinsize = intval($collapsetocwinsize);
81}
5c508e3f 82
cdbea7ee 83require_login($course, false, $cm);
f9d5371b 84
ca4eda13
DM
85$strscorms = get_string('modulenameplural', 'scorm');
86$strscorm = get_string('modulename', 'scorm');
87$strpopup = get_string('popup', 'scorm');
88$strexit = get_string('exitactivity', 'scorm');
f9d5371b 89
a3fc4b3a 90$coursecontext = context_course::instance($course->id);
ca4eda13 91
6d954dd3
DM
92if ($displaymode == 'popup') {
93 $PAGE->set_pagelayout('popup');
94} else {
8ebbb06a
SH
95 $shortname = format_string($course->shortname, true, array('context' => $coursecontext));
96 $pagetitle = strip_tags("$shortname: ".format_string($scorm->name));
6d954dd3
DM
97 $PAGE->set_title($pagetitle);
98 $PAGE->set_heading($course->fullname);
99}
8ebbb06a 100if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
ca4eda13
DM
101 echo $OUTPUT->header();
102 notice(get_string("activityiscurrentlyhidden"));
103 echo $OUTPUT->footer();
104 die;
105}
43f4e520 106
39355b46 107// Check if scorm closed.
ca4eda13
DM
108$timenow = time();
109if ($scorm->timeclose !=0) {
110 if ($scorm->timeopen > $timenow) {
52869011 111 echo $OUTPUT->header();
ca4eda13 112 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
670bc3e7 113 echo $OUTPUT->footer();
d54e2145 114 die;
ca4eda13
DM
115 } else if ($timenow > $scorm->timeclose) {
116 echo $OUTPUT->header();
117 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
118 echo $OUTPUT->footer();
d54e2145 119
ca4eda13 120 die;
f9d5371b 121 }
ca4eda13
DM
122}
123// TOC processing
39355b46 124$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe.
ca4eda13
DM
125if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
126 $scorm->version = 'scorm_12';
127}
128require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
f9d5371b 129
ca4eda13
DM
130$result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
131$sco = $result->sco;
cce0da74
DM
132if ($scorm->lastattemptlock == 1 && $result->attemptleft == 0) {
133 echo $OUTPUT->header();
134 echo $OUTPUT->notification(get_string('exceededmaxattempts', 'scorm'));
135 echo $OUTPUT->footer();
136 exit;
137}
f9d5371b 138
ca4eda13 139add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
43f4e520 140
f9d5371b 141
ca4eda13 142$scoidstr = '&amp;scoid='.$sco->id;
ca4eda13 143$modestr = '&amp;mode='.$mode;
f9d5371b 144
37ca1722 145$SESSION->scorm = new stdClass();
ba0e91a2
DM
146$SESSION->scorm->scoid = $sco->id;
147$SESSION->scorm->scormstatus = 'Not Initialized';
148$SESSION->scorm->scormmode = $mode;
149$SESSION->scorm->attempt = $attempt;
f9d5371b 150
39355b46 151// Mark module viewed.
ca4eda13
DM
152$completion = new completion_info($course);
153$completion->set_module_viewed($cm);
6553cda7 154
39355b46 155// Print the page header.
6d954dd3
DM
156if (empty($scorm->popup) || $displaymode=='popup') {
157 $exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
158 $PAGE->set_button($exitlink);
ca4eda13 159}
4e204f89 160
81f460b1 161$PAGE->requires->data_for_js('scormplayerdata', Array('launch' => false,
35cfa9e6
PH
162 'currentorg' => '',
163 'sco' => 0,
164 'scorm' => 0,
165 'courseid' => $scorm->course,
166 'cwidth' => $scorm->width,
167 'cheight' => $scorm->height,
168 'popupoptions' => $scorm->options), true);
ca4eda13
DM
169$PAGE->requires->js('/mod/scorm/request.js', true);
170$PAGE->requires->js('/lib/cookies.js', true);
ca4eda13 171echo $OUTPUT->header();
b2970f96 172echo $OUTPUT->heading(format_string($scorm->name));
bd257031 173
ca4eda13
DM
174$PAGE->requires->string_for_js('navigation', 'scorm');
175$PAGE->requires->string_for_js('toc', 'scorm');
176$PAGE->requires->string_for_js('hide', 'moodle');
177$PAGE->requires->string_for_js('show', 'moodle');
178$PAGE->requires->string_for_js('popupsblocked', 'scorm');
5c2aa157 179
ca4eda13 180$name = false;
5c2aa157 181
f9d5371b 182?>
183 <div id="scormpage">
b5b99e0b 184
5c2aa157
DM
185 <div id="tocbox">
186 <div id='scormapi-parent'>
187 <script id="external-scormapi" type="text/JavaScript"></script>
188 </div>
f9d5371b 189<?php
61c347cc
DM
190if ($scorm->hidetoc == SCORM_TOC_POPUP or $mode=='browse' or $mode=='review') {
191 echo '<div id="scormtop">';
192 echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode', 'scorm')."</div>\n" : '';
193 echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode', 'scorm')."</div>\n" : '';
194 if ($scorm->hidetoc == SCORM_TOC_POPUP) {
195 echo '<div id="scormnav" class="scorm-right">'.$result->tocmenu.'</div>';
196 }
197 echo '</div>';
ca4eda13 198}
f9d5371b 199?>
61c347cc 200 <div id="toctree">
6d954dd3
DM
201 <?php
202 if (empty($scorm->popup) || $displaymode == 'popup') {
203 echo $result->toc;
204 } else {
205 //Added incase javascript popups are blocked we don't provide a direct link to the pop-up as JS communication can fail - the user must disable their pop-up blocker.
206 $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
207 echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
208 }?>
5c2aa157
DM
209 </div> <!-- toctree -->
210 </div> <!-- tocbox -->
f9d5371b 211 <noscript>
212 <div id="noscript">
ca4eda13 213 <?php print_string('noscriptnoscorm', 'scorm'); // No Martin(i), No Party ;-) ?>
f9d5371b 214
215 </div>
216 </noscript>
217<?php
ca4eda13 218if ($result->prerequisites) {
6d954dd3 219 if ($scorm->popup != 0 && $displaymode !=='popup') {
ca4eda13
DM
220 // Clean the name for the window as IE is fussy
221 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
222 if (!$name) {
223 $name = 'DefaultPlayerWindow';
224 }
225 $name = 'scorm_'.$name;
226 echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
39355b46 227 $url = new moodle_url($PAGE->url, array('scoid' => $sco->id, 'display' => 'popup', 'mode' => $mode));
ca4eda13 228 echo html_writer::script(
6d954dd3 229 js_writer::function_call('scorm_openpopup', Array($url->out(false),
ca4eda13
DM
230 $name, $scorm->options,
231 $scorm->width, $scorm->height)));
232 ?>
485f4ce6 233 <noscript>
ec678a9a 234 <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
485f4ce6 235 </noscript>
ca4eda13 236 <?php
f9d5371b 237 }
ca4eda13
DM
238} else {
239 echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
240}
f9d5371b 241?>
5b89dfbb 242 </div> <!-- SCORM page -->
b5b99e0b 243<?php
df5c7086 244$scoes = scorm_get_toc_object($USER, $scorm, $currentorg, $sco->id, $mode, $attempt);
41e205cd 245$adlnav = scorm_get_adlnav_json($scoes['scoes']);
39355b46 246
6d954dd3
DM
247if (empty($scorm->popup) || $displaymode == 'popup') {
248 if (!isset($result->toctitle)) {
249 $result->toctitle = get_string('toc', 'scorm');
250 }
c23ff8e3
DS
251 $jsmodule = array(
252 'name' => 'mod_scorm',
253 'fullpath' => '/mod/scorm/module.js',
254 'requires' => array('json'),
255 );
df5c7086
MG
256 $scorm->nav = intval($scorm->nav);
257 $PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->nav, $scorm->navpositionleft, $scorm->navpositiontop, $scorm->hidetoc,
258 $collapsetocwinsize, $result->toctitle, $name, $sco->id, $adlnav), false, $jsmodule);
5c2aa157 259}
30bce58e
DM
260if (!empty($forcejs)) {
261 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
262}
a5ba44f9 263echo $OUTPUT->footer();