weekly release 2.2dev
[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
17/// This page prints a particular instance of aicc/scorm package
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
28$newattempt = optional_param('newattempt', 'off', PARAM_ALPHA); // the user request to start a new attempt
e73457e4 29
ca4eda13
DM
30//IE 6 Bug workaround
31if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 6') !== false) {
32 @ini_set('zlib.output_compression', 'Off');
33 @apache_setenv('no-gzip', 1);
34}
15d0fae4 35
ca4eda13
DM
36if (!empty($id)) {
37 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
38 print_error('invalidcoursemodule');
f9d5371b 39 }
ca4eda13
DM
40 if (! $course = $DB->get_record("course", array("id"=>$cm->course))) {
41 print_error('coursemisconf');
42 }
43 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance))) {
44 print_error('invalidcoursemodule');
5c508e3f 45 }
ca4eda13
DM
46} else if (!empty($a)) {
47 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
48 print_error('invalidcoursemodule');
5c508e3f 49 }
ca4eda13
DM
50 if (! $course = $DB->get_record("course", array("id"=>$scorm->course))) {
51 print_error('coursemisconf');
5c508e3f 52 }
ca4eda13
DM
53 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id, $course->id)) {
54 print_error('invalidcoursemodule');
30bce58e 55 }
ca4eda13
DM
56} else {
57 print_error('missingparameter');
58}
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}
5c508e3f 75
ca4eda13 76require_login($course->id, false, $cm);
f9d5371b 77
ca4eda13
DM
78$strscorms = get_string('modulenameplural', 'scorm');
79$strscorm = get_string('modulename', 'scorm');
80$strpopup = get_string('popup', 'scorm');
81$strexit = get_string('exitactivity', 'scorm');
f9d5371b 82
ca4eda13
DM
83$pagetitle = strip_tags("$course->shortname: ".format_string($scorm->name));
84$PAGE->set_title($pagetitle);
85$PAGE->set_heading($course->fullname);
86
87if (!$cm->visible and !has_capability('moodle/course:viewhiddenactivities', get_context_instance(CONTEXT_COURSE, $course->id))) {
88 echo $OUTPUT->header();
89 notice(get_string("activityiscurrentlyhidden"));
90 echo $OUTPUT->footer();
91 die;
92}
43f4e520 93
ca4eda13
DM
94//check if scorm closed
95$timenow = time();
96if ($scorm->timeclose !=0) {
97 if ($scorm->timeopen > $timenow) {
52869011 98 echo $OUTPUT->header();
ca4eda13 99 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen)), "generalbox boxaligncenter");
670bc3e7 100 echo $OUTPUT->footer();
d54e2145 101 die;
ca4eda13
DM
102 } else if ($timenow > $scorm->timeclose) {
103 echo $OUTPUT->header();
104 echo $OUTPUT->box(get_string("expired", "scorm", userdate($scorm->timeclose)), "generalbox boxaligncenter");
105 echo $OUTPUT->footer();
d54e2145 106
ca4eda13 107 die;
f9d5371b 108 }
ca4eda13
DM
109}
110// TOC processing
111$scorm->version = strtolower(clean_param($scorm->version, PARAM_SAFEDIR)); // Just to be safe
112if (!file_exists($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php')) {
113 $scorm->version = 'scorm_12';
114}
115require_once($CFG->dirroot.'/mod/scorm/datamodels/'.$scorm->version.'lib.php');
116$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
117if (($newattempt=='on') && (($attempt < $scorm->maxattempt) || ($scorm->maxattempt == 0))) {
118 $attempt++;
119 $mode = 'normal';
120}
121$attemptstr = '&amp;attempt=' . $attempt;
f9d5371b 122
ca4eda13
DM
123$result = scorm_get_toc($USER, $scorm, $cm->id, TOCJSLINK, $currentorg, $scoid, $mode, $attempt, true, true);
124$sco = $result->sco;
f9d5371b 125
ca4eda13
DM
126if (($mode == 'browse') && ($scorm->hidebrowse == 1)) {
127 $mode = 'normal';
128}
129if ($mode != 'browse') {
130 if ($trackdata = scorm_get_tracks($sco->id, $USER->id, $attempt)) {
131 if (($trackdata->status == 'completed') || ($trackdata->status == 'passed') || ($trackdata->status == 'failed')) {
132 $mode = 'review';
57d52eeb 133 } else {
134 $mode = 'normal';
f9d5371b 135 }
ca4eda13
DM
136 } else {
137 $mode = 'normal';
f9d5371b 138 }
ca4eda13 139}
f9d5371b 140
ca4eda13 141add_to_log($course->id, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id);
43f4e520 142
f9d5371b 143
ca4eda13
DM
144$scoidstr = '&amp;scoid='.$sco->id;
145$scoidpop = '&scoid='.$sco->id;
146$modestr = '&amp;mode='.$mode;
147if ($mode == 'browse') {
148 $modepop = '&mode='.$mode;
149} else {
150 $modepop = '';
151}
152$orgstr = '&currentorg='.$currentorg;
f9d5371b 153
ca4eda13
DM
154$SESSION->scorm_scoid = $sco->id;
155$SESSION->scorm_status = 'Not Initialized';
156$SESSION->scorm_mode = $mode;
157$SESSION->scorm_attempt = $attempt;
f9d5371b 158
ca4eda13
DM
159// Mark module viewed
160$completion = new completion_info($course);
161$completion->set_module_viewed($cm);
6553cda7 162
ca4eda13
DM
163// Print the page header
164$bodyscript = '';
165if ($scorm->popup == 1) {
166 $bodyscript = 'onunload="main.close();"';
167}
4e204f89 168
ca4eda13 169$exitlink = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'" title="'.$strexit.'">'.$strexit.'</a> ';
43f4e520 170
ca4eda13 171$PAGE->set_button($exitlink);
bd257031 172
ca4eda13
DM
173$PAGE->requires->data_for_js('scormplayerdata', Array('cwidth'=>$scorm->width,
174 'cheight'=>$scorm->height,
175 'popupoptions' => $scorm->options), true);
176$PAGE->requires->js('/mod/scorm/request.js', true);
177$PAGE->requires->js('/lib/cookies.js', true);
178$PAGE->requires->css('/mod/scorm/styles.css');
52869011 179
ca4eda13 180echo $OUTPUT->header();
bd257031 181
ca4eda13
DM
182// NEW IMS TOC
183$PAGE->requires->string_for_js('navigation', 'scorm');
184$PAGE->requires->string_for_js('toc', 'scorm');
185$PAGE->requires->string_for_js('hide', 'moodle');
186$PAGE->requires->string_for_js('show', 'moodle');
187$PAGE->requires->string_for_js('popupsblocked', 'scorm');
5c2aa157 188
ca4eda13 189$name = false;
5c2aa157 190
f9d5371b 191?>
192 <div id="scormpage">
5c2aa157
DM
193
194 <div id="tocbox">
195 <div id='scormapi-parent'>
196 <script id="external-scormapi" type="text/JavaScript"></script>
197 </div>
198 <div id="scormtop">
43f4e520 199<?php
ca4eda13
DM
200if ($result->prerequisites) {
201 if ($scorm->popup != 0) {
202 //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.
203 $linkcourse = '<a href="'.$CFG->wwwroot.'/course/view.php?id='.$scorm->course.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
204 echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
f9d5371b 205 }
ca4eda13 206}
f9d5371b 207?>
ca4eda13
DM
208 <?php echo $mode == 'browse' ? '<div id="scormmode" class="scorm-left">'.get_string('browsemode', 'scorm')."</div>\n" : ''; ?>
209 <?php echo $mode == 'review' ? '<div id="scormmode" class="scorm-left">'.get_string('reviewmode', 'scorm')."</div>\n" : ''; ?>
5c2aa157 210 <div id="scormnav" class="scorm-right">
f9d5371b 211<?php
99da7a95 212if ($scorm->hidetoc == SCORM_TOC_POPUP) {
ca4eda13
DM
213 echo $result->tocmenu;
214}
f9d5371b 215?>
5c2aa157
DM
216 </div> <!-- Scormnav -->
217 </div> <!-- Scormtop -->
218 <div id="toctree" class="generalbox">
219 <?php echo $result->toc; ?>
220 </div> <!-- toctree -->
221 </div> <!-- tocbox -->
f9d5371b 222 <noscript>
223 <div id="noscript">
ca4eda13 224 <?php print_string('noscriptnoscorm', 'scorm'); // No Martin(i), No Party ;-) ?>
f9d5371b 225
226 </div>
227 </noscript>
228<?php
ca4eda13
DM
229if ($result->prerequisites) {
230 if ($scorm->popup != 0) {
231 // Clean the name for the window as IE is fussy
232 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name);
233 if (!$name) {
234 $name = 'DefaultPlayerWindow';
235 }
236 $name = 'scorm_'.$name;
237 echo html_writer::script('', $CFG->wwwroot.'/mod/scorm/player.js');
238 echo html_writer::script(
239 js_writer::function_call('scorm_openpopup', Array("loadSCO.php?id=".$cm->id.$scoidpop,
240 $name, $scorm->options,
241 $scorm->width, $scorm->height)));
242 ?>
485f4ce6 243 <noscript>
ac2032dc 244 <!--[if IE]>
ec678a9a 245 <iframe id="main" class="scoframe" name="main" src="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe>
ac2032dc
DM
246 <![endif]-->
247 <!--[if !IE]>
ec678a9a 248 <object id="main" class="scoframe" type="text/html" data="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
ac2032dc 249 <![endif]-->
485f4ce6 250 </noscript>
ca4eda13 251 <?php
f9d5371b 252 }
ca4eda13
DM
253} else {
254 echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
255}
f9d5371b 256?>
5b89dfbb 257 </div> <!-- SCORM page -->
b3611e0d 258<?php
5c2aa157
DM
259// NEW IMS TOC
260if (!isset($result->toctitle)) {
261 $result->toctitle = get_string('toc', 'scorm');
262}
263
fe3b9da3 264$PAGE->requires->js_init_call('M.mod_scorm.init', array($scorm->hidenav, $scorm->hidetoc, $result->toctitle, $name, $sco->id));
5c2aa157 265
30bce58e
DM
266if (!empty($forcejs)) {
267 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
268}
b3611e0d 269echo $OUTPUT->footer();