2 // This file is part of Moodle - http://moodle.org/
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.
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.
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/>.
17 /// This page prints a particular instance of aicc/scorm package
19 require_once('../../config.php');
20 require_once($CFG->dirroot
.'/mod/scorm/locallib.php');
21 require_once($CFG->libdir
. '/completionlib.php');
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
29 $displaymode = optional_param('display','',PARAM_ALPHA
);
31 // IE 9 workaround for Flash bug: MDL-29213
32 // Note that it's not clear if appending the meta tag via $CFG->additionalhtmlhead
33 // is correct at all, both because of the mechanism itself and because MS says
34 // the tag must be used *before* including other stuff. See the issue for more info.
35 // TODO: Once we implement some way to inject meta tags, change this to use it. MDL-30039
36 if (strpos($_SERVER['HTTP_USER_AGENT'], 'MSIE 9') !== false) {
37 if (!isset($CFG->additionalhtmlhead
)) { //check to make sure set first - that way we can use .=
38 $CFG->additionalhtmlhead
= '';
40 $CFG->additionalhtmlhead
.= '<meta http-equiv="X-UA-Compatible" content="IE=8" />';
44 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
45 print_error('invalidcoursemodule');
47 if (! $course = $DB->get_record("course", array("id"=>$cm->course
))) {
48 print_error('coursemisconf');
50 if (! $scorm = $DB->get_record("scorm", array("id"=>$cm->instance
))) {
51 print_error('invalidcoursemodule');
53 } else if (!empty($a)) {
54 if (! $scorm = $DB->get_record("scorm", array("id"=>$a))) {
55 print_error('invalidcoursemodule');
57 if (! $course = $DB->get_record("course", array("id"=>$scorm->course
))) {
58 print_error('coursemisconf');
60 if (! $cm = get_coursemodule_from_instance("scorm", $scorm->id
, $course->id
)) {
61 print_error('invalidcoursemodule');
64 print_error('missingparameter');
67 $url = new moodle_url('/mod/scorm/player.php', array('scoid'=>$scoid, 'cm'=>$cm->id
));
68 if ($mode !== 'normal') {
69 $url->param('mode', $mode);
71 if ($currentorg !== '') {
72 $url->param('currentorg', $currentorg);
74 if ($newattempt !== 'off') {
75 $url->param('newattempt', $newattempt);
78 $forcejs = get_config('scorm', 'forcejavascript');
79 if (!empty($forcejs)) {
80 $PAGE->add_body_class('forcejavascript');
83 require_login($course, false, $cm);
85 $strscorms = get_string('modulenameplural', 'scorm');
86 $strscorm = get_string('modulename', 'scorm');
87 $strpopup = get_string('popup', 'scorm');
88 $strexit = get_string('exitactivity', 'scorm');
90 $coursecontext = context_course
::instance($course->id
);
92 if ($displaymode == 'popup') {
93 $PAGE->set_pagelayout('popup');
95 $shortname = format_string($course->shortname
, true, array('context' => $coursecontext));
96 $pagetitle = strip_tags("$shortname: ".format_string($scorm->name
));
97 $PAGE->set_title($pagetitle);
98 $PAGE->set_heading($course->fullname
);
100 if (!$cm->visible
and !has_capability('moodle/course:viewhiddenactivities', $coursecontext)) {
101 echo $OUTPUT->header();
102 notice(get_string("activityiscurrentlyhidden"));
103 echo $OUTPUT->footer();
107 //check if scorm closed
109 if ($scorm->timeclose
!=0) {
110 if ($scorm->timeopen
> $timenow) {
111 echo $OUTPUT->header();
112 echo $OUTPUT->box(get_string("notopenyet", "scorm", userdate($scorm->timeopen
)), "generalbox boxaligncenter");
113 echo $OUTPUT->footer();
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();
124 $scorm->version
= strtolower(clean_param($scorm->version
, PARAM_SAFEDIR
)); // Just to be safe
125 if (!file_exists($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php')) {
126 $scorm->version
= 'scorm_12';
128 require_once($CFG->dirroot
.'/mod/scorm/datamodels/'.$scorm->version
.'lib.php');
129 $attempt = scorm_get_last_attempt($scorm->id
, $USER->id
);
130 if (($newattempt=='on') && (($attempt < $scorm->maxattempt
) ||
($scorm->maxattempt
== 0))) {
134 $attemptstr = '&attempt=' . $attempt;
136 $result = scorm_get_toc($USER, $scorm, $cm->id
, TOCJSLINK
, $currentorg, $scoid, $mode, $attempt, true, true);
138 if ($scorm->lastattemptlock
== 1 && $result->attemptleft
== 0) {
139 echo $OUTPUT->header();
140 echo $OUTPUT->notification(get_string('exceededmaxattempts', 'scorm'));
141 echo $OUTPUT->footer();
145 if (($mode == 'browse') && ($scorm->hidebrowse
== 1)) {
148 if ($mode != 'browse') {
149 if ($trackdata = scorm_get_tracks($sco->id
, $USER->id
, $attempt)) {
150 if (($trackdata->status
== 'completed') ||
($trackdata->status
== 'passed') ||
($trackdata->status
== 'failed')) {
160 add_to_log($course->id
, 'scorm', 'view', "player.php?cm=$cm->id&scoid=$sco->id", "$scorm->id", $cm->id
);
163 $scoidstr = '&scoid='.$sco->id
;
164 $scoidpop = '&scoid='.$sco->id
;
165 $modestr = '&mode='.$mode;
166 if ($mode == 'browse') {
167 $modepop = '&mode='.$mode;
171 $orgstr = '¤torg='.$currentorg;
173 $SESSION->scorm
= new stdClass();
174 $SESSION->scorm
->scoid
= $sco->id
;
175 $SESSION->scorm
->scormstatus
= 'Not Initialized';
176 $SESSION->scorm
->scormmode
= $mode;
177 $SESSION->scorm
->attempt
= $attempt;
179 // Mark module viewed
180 $completion = new completion_info($course);
181 $completion->set_module_viewed($cm);
183 // Print the page header
184 if (empty($scorm->popup
) ||
$displaymode=='popup') {
185 $exitlink = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$scorm->course
.'" title="'.$strexit.'">'.$strexit.'</a> ';
186 $PAGE->set_button($exitlink);
189 $PAGE->requires
->data_for_js('scormplayerdata', Array('launch' => false,
193 'courseid' => $scorm->course
,
194 'cwidth' => $scorm->width
,
195 'cheight' => $scorm->height
,
196 'popupoptions' => $scorm->options
), true);
197 $PAGE->requires
->js('/mod/scorm/request.js', true);
198 $PAGE->requires
->js('/lib/cookies.js', true);
199 echo $OUTPUT->header();
202 $PAGE->requires
->string_for_js('navigation', 'scorm');
203 $PAGE->requires
->string_for_js('toc', 'scorm');
204 $PAGE->requires
->string_for_js('hide', 'moodle');
205 $PAGE->requires
->string_for_js('show', 'moodle');
206 $PAGE->requires
->string_for_js('popupsblocked', 'scorm');
214 <div id
='scormapi-parent'>
215 <script id
="external-scormapi" type
="text/JavaScript"></script
>
218 if ($scorm->hidetoc
== SCORM_TOC_POPUP
or $mode=='browse' or $mode=='review') {
219 echo '<div id="scormtop">';
220 echo $mode == 'browse' ?
'<div id="scormmode" class="scorm-left">'.get_string('browsemode', 'scorm')."</div>\n" : '';
221 echo $mode == 'review' ?
'<div id="scormmode" class="scorm-left">'.get_string('reviewmode', 'scorm')."</div>\n" : '';
222 if ($scorm->hidetoc
== SCORM_TOC_POPUP
) {
223 echo '<div id="scormnav" class="scorm-right">'.$result->tocmenu
.'</div>';
230 if (empty($scorm->popup
) ||
$displaymode == 'popup') {
233 //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.
234 $linkcourse = '<a href="'.$CFG->wwwroot
.'/course/view.php?id='.$scorm->course
.'">' . get_string('finishscormlinkname', 'scorm') . '</a>';
235 echo $OUTPUT->box(get_string('finishscorm', 'scorm', $linkcourse), 'generalbox', 'altfinishlink');
237 </div
> <!-- toctree
-->
238 </div
> <!-- tocbox
-->
241 <?php
print_string('noscriptnoscorm', 'scorm'); // No Martin(i), No Party ;-) ?>
246 if ($result->prerequisites
) {
247 if ($scorm->popup
!= 0 && $displaymode !=='popup') {
248 // Clean the name for the window as IE is fussy
249 $name = preg_replace("/[^A-Za-z0-9]/", "", $scorm->name
);
251 $name = 'DefaultPlayerWindow';
253 $name = 'scorm_'.$name;
254 echo html_writer
::script('', $CFG->wwwroot
.'/mod/scorm/player.js');
255 $url = new moodle_url($PAGE->url
, array('scoid' => $sco->id
, 'display' => 'popup'));
256 echo html_writer
::script(
257 js_writer
::function_call('scorm_openpopup', Array($url->out(false),
258 $name, $scorm->options
,
259 $scorm->width
, $scorm->height
)));
263 <iframe id
="main" class="scoframe" name
="main" src
="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></iframe
>
266 <object id
="main" class="scoframe" type
="text/html" data
="loadSCO.php?id=<?php echo $cm->id.$scoidstr.$modestr; ?>"></object>
272 echo $OUTPUT->box(get_string('noprerequisites', 'scorm'));
275 </div
> <!-- SCORM page
-->
277 $scoes = scorm_get_toc_object($USER, $scorm, "", $sco->id
, $mode, $attempt);
278 $adlnav = scorm_get_adlnav_json($scoes['scoes']);
280 if (empty($scorm->popup
) ||
$displaymode == 'popup') {
281 if (!isset($result->toctitle
)) {
282 $result->toctitle
= get_string('toc', 'scorm');
285 'name' => 'mod_scorm',
286 'fullpath' => '/mod/scorm/module.js',
287 'requires' => array('json'),
289 $PAGE->requires
->js_init_call('M.mod_scorm.init', array($scorm->hidenav
, $scorm->hidetoc
, $result->toctitle
, $name, $sco->id
, $adlnav), false, $jsmodule);
291 if (!empty($forcejs)) {
292 echo $OUTPUT->box(get_string("forcejavascriptmessage", "scorm"), "generalbox boxaligncenter forcejavascriptmessage");
294 echo $OUTPUT->footer();