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 require_once('../../config.php');
18 require_once($CFG->dirroot
.'/mod/scorm/locallib.php');
20 $id = optional_param('id', '', PARAM_INT
); // Course Module ID, or
21 $a = optional_param('a', '', PARAM_INT
); // scorm ID
22 $scoid = required_param('scoid', PARAM_INT
); // sco ID
24 $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API
27 if (! $cm = get_coursemodule_from_id('scorm', $id)) {
28 print_error('invalidcoursemodule');
30 if (! $course = $DB->get_record('course', array('id'=>$cm->course
))) {
31 print_error('coursemisconf');
33 if (! $scorm = $DB->get_record('scorm', array('id'=>$cm->instance
))) {
34 print_error('invalidcoursemodule');
36 } else if (!empty($a)) {
37 if (! $scorm = $DB->get_record('scorm', array('id'=>$a))) {
38 print_error('coursemisconf');
40 if (! $course = $DB->get_record('course', array('id'=>$scorm->course
))) {
41 print_error('coursemisconf');
43 if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id
, $course->id
)) {
44 print_error('invalidcoursemodule');
47 print_error('missingparameter');
50 $PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid'=>$scoid, 'id'=>$cm->id
));
52 if (!isloggedin()) { // Prevent login page from being shown in iframe.
53 // Using simple html instead of exceptions here as shown inside iframe/object.
54 echo html_writer
::start_tag('html');
55 echo html_writer
::tag('head', '');
56 echo html_writer
::tag('body', get_string('loggedinnot'));
57 echo html_writer
::end_tag('html');
61 require_login($course, false, $cm, false); // Call require_login anyway to set up globals correctly.
63 //check if scorm closed
65 if ($scorm->timeclose
!=0) {
66 if ($scorm->timeopen
> $timenow) {
67 print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen
));
68 } else if ($timenow > $scorm->timeclose
) {
69 print_error('expired', 'scorm', null, userdate($scorm->timeclose
));
73 $context = context_module
::instance($cm->id
);
79 if ($sco = scorm_get_sco($scoid)) {
80 if ($sco->launch
== '') {
81 // Search for the next launchable sco
82 if ($scoes = $DB->get_records_select(
84 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true).' AND id > ?',
85 array($scorm->id
, $sco->id
),
87 $sco = current($scoes);
93 // If no sco was found get the first of SCORM package
96 $scoes = $DB->get_records_select(
98 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true),
102 $sco = current($scoes);
105 if ($sco->scormtype
== 'asset') {
106 $attempt = scorm_get_last_attempt($scorm->id
, $USER->id
);
107 $element = (scorm_version_check($scorm->version
, SCORM_13
)) ?
'cmi.completion_status':'cmi.core.lesson_status';
108 $value = 'completed';
109 $result = scorm_insert_track($USER->id
, $scorm->id
, $sco->id
, $attempt, $element, $value);
116 $version = substr($scorm->version
, 0, 4);
117 if ((isset($sco->parameters
) && (!empty($sco->parameters
))) ||
($version == 'AICC')) {
118 if (stripos($sco->launch
, '?') !== false) {
123 if ((isset($sco->parameters
) && (!empty($sco->parameters
))) && ($sco->parameters
[0] == '?')) {
124 $sco->parameters
= substr($sco->parameters
, 1);
128 if ($version == 'AICC') {
129 require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php");
130 $aicc_sid = scorm_aicc_get_hacp_session($scorm->id
);
131 if (empty($aicc_sid)) {
132 $aicc_sid = sesskey();
135 if (isset($sco->parameters
) && (!empty($sco->parameters
))) {
136 $sco_params = '&'. $sco->parameters
;
138 $launcher = $sco->launch
.$connector.'aicc_sid='.$aicc_sid.'&aicc_url='.$CFG->wwwroot
.'/mod/scorm/aicc.php'.$sco_params;
140 if (isset($sco->parameters
) && (!empty($sco->parameters
))) {
141 $launcher = $sco->launch
.$connector.$sco->parameters
;
143 $launcher = $sco->launch
;
147 if (scorm_external_link($sco->launch
)) {
148 //TODO: does this happen?
150 } else if ($scorm->scormtype
=== SCORM_TYPE_EXTERNAL
) {
151 // Remote learning activity.
152 $result = dirname($scorm->reference
).'/'.$launcher;
153 } else if ($scorm->scormtype
=== SCORM_TYPE_LOCAL
&& strtolower($scorm->reference
) == 'imsmanifest.xml') {
154 // This SCORM content sits in a repository that allows relative links.
155 $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/imsmanifest/$scorm->revision/$launcher";
156 } else if ($scorm->scormtype
=== SCORM_TYPE_LOCAL
or $scorm->scormtype
=== SCORM_TYPE_LOCALSYNC
) {
157 // Note: do not convert this to use get_file_url() or moodle_url()
158 // SCORM does not work without slasharguments and moodle_url() encodes querystring vars.
159 $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher";
162 add_to_log($course->id
, 'scorm', 'launch', 'view.php?id='.$cm->id
, $result, $cm->id
);
164 header('Content-Type: text/html; charset=UTF-8');
166 if ($sco->scormtype
== 'asset') {
167 // HTTP 302 Found => Moved Temporarily.
168 header('Location: ' . $result);
169 // Provide a short feedback in case of slow network connection.
170 echo '<html><body><p>' . get_string('activitypleasewait', 'scorm'). '</p></body></html>';
174 // We expect a SCO: select which API are we looking for.
175 $LMS_api = (scorm_version_check($scorm->version
, SCORM_12
) ||
empty($scorm->version
)) ?
'API' : 'API_1484_11';
180 <title
>LoadSCO
</title
>
181 <script type
="text/javascript">
183 var myApiHandle
= null;
184 var myFindAPITries
= 0;
186 function myGetAPIHandle() {
188 if (myApiHandle
== null) {
189 myApiHandle
= myGetAPI();
194 function myFindAPI(win
) {
195 while ((win
.<?php
echo $LMS_api; ?
> == null) && (win
.parent
!= null) && (win
.parent
!= win
)) {
197 // Note: 7 is an arbitrary number, but should be more than sufficient
198 if (myFindAPITries
> 7) {
203 return win
.<?php
echo $LMS_api; ?
>;
206 // hun for the API - needs to be loaded before we can launch the package
207 function myGetAPI() {
208 var theAPI
= myFindAPI(window
);
209 if ((theAPI
== null) && (window
.opener
!= null) && (typeof(window
.opener
) != "undefined")) {
210 theAPI
= myFindAPI(window
.opener
);
212 if (theAPI
== null) {
218 function doredirect() {
219 if (myGetAPIHandle() != null) {
220 location
= "<?php echo $result ?>";
223 document
.body
.innerHTML
= "<p><?php echo get_string('activityloading', 'scorm');?> <span id='countdown'><?php echo $delayseconds ?></span> <?php echo get_string('numseconds', 'moodle', '');?>. <img src='<?php echo $OUTPUT->pix_url('wait', 'scorm') ?>'><p>";
224 var e
= document
.getElementById("countdown");
225 var cSeconds
= parseInt(e
.innerHTML
);
226 var timer
= setInterval(function() {
227 if( cSeconds
&& myGetAPIHandle() == null ) {
228 e
.innerHTML
= --cSeconds
;
230 clearInterval(timer
);
231 document
.body
.innerHTML
= "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>";
232 location
= "<?php echo $result ?>";
240 <meta http
-equiv
="refresh" content
="0;url=<?php echo $result ?>" />
243 <body onload
="doredirect();">
244 <p
><?php
echo get_string('activitypleasewait', 'scorm');?
></p
>