2009-09-24 08:28:51 +00:00
|
|
|
<?php
|
2011-06-30 14:59:08 +12:00
|
|
|
// This file is part of Moodle - http://moodle.org/
|
|
|
|
//
|
|
|
|
// Moodle is free software: you can redistribute it and/or modify
|
|
|
|
// it under the terms of the GNU General Public License as published by
|
|
|
|
// the Free Software Foundation, either version 3 of the License, or
|
|
|
|
// (at your option) any later version.
|
|
|
|
//
|
|
|
|
// Moodle is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
// GNU General Public License for more details.
|
|
|
|
//
|
|
|
|
// You should have received a copy of the GNU General Public License
|
|
|
|
// along with Moodle. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
require_once('../../config.php');
|
|
|
|
require_once($CFG->dirroot.'/mod/scorm/locallib.php');
|
|
|
|
|
|
|
|
$id = optional_param('id', '', PARAM_INT); // Course Module ID, or
|
|
|
|
$a = optional_param('a', '', PARAM_INT); // scorm ID
|
2014-08-08 07:08:57 +05:30
|
|
|
$scoid = required_param('scoid', PARAM_INT); // sco ID.
|
2011-06-30 14:59:08 +12:00
|
|
|
|
2014-08-08 07:08:57 +05:30
|
|
|
$delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API.
|
2011-06-30 14:59:08 +12:00
|
|
|
|
|
|
|
if (!empty($id)) {
|
|
|
|
if (! $cm = get_coursemodule_from_id('scorm', $id)) {
|
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $cm->course))) {
|
2011-06-30 14:59:08 +12:00
|
|
|
print_error('coursemisconf');
|
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
if (! $scorm = $DB->get_record('scorm', array('id' => $cm->instance))) {
|
2011-06-30 14:59:08 +12:00
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
|
|
|
} else if (!empty($a)) {
|
2014-05-29 21:54:00 +00:00
|
|
|
if (! $scorm = $DB->get_record('scorm', array('id' => $a))) {
|
2011-06-30 14:59:08 +12:00
|
|
|
print_error('coursemisconf');
|
2006-09-20 19:46:52 +00:00
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
if (! $course = $DB->get_record('course', array('id' => $scorm->course))) {
|
2011-06-30 14:59:08 +12:00
|
|
|
print_error('coursemisconf');
|
|
|
|
}
|
|
|
|
if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
|
|
|
|
print_error('invalidcoursemodule');
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
print_error('missingparameter');
|
|
|
|
}
|
2006-09-20 19:46:52 +00:00
|
|
|
|
2014-05-29 21:54:00 +00:00
|
|
|
$PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid' => $scoid, 'id' => $cm->id));
|
2009-09-24 08:28:51 +00:00
|
|
|
|
2012-08-01 09:27:37 +12:00
|
|
|
if (!isloggedin()) { // Prevent login page from being shown in iframe.
|
|
|
|
// Using simple html instead of exceptions here as shown inside iframe/object.
|
|
|
|
echo html_writer::start_tag('html');
|
|
|
|
echo html_writer::tag('head', '');
|
|
|
|
echo html_writer::tag('body', get_string('loggedinnot'));
|
|
|
|
echo html_writer::end_tag('html');
|
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
require_login($course, false, $cm, false); // Call require_login anyway to set up globals correctly.
|
2008-12-05 03:19:56 +00:00
|
|
|
|
2014-08-08 07:08:57 +05:30
|
|
|
// Check if scorm closed.
|
2011-06-30 14:59:08 +12:00
|
|
|
$timenow = time();
|
2014-05-29 21:54:00 +00:00
|
|
|
if ($scorm->timeclose != 0) {
|
2011-06-30 14:59:08 +12:00
|
|
|
if ($scorm->timeopen > $timenow) {
|
|
|
|
print_error('notopenyet', 'scorm', null, userdate($scorm->timeopen));
|
|
|
|
} else if ($timenow > $scorm->timeclose) {
|
|
|
|
print_error('expired', 'scorm', null, userdate($scorm->timeclose));
|
2008-11-28 09:20:59 +00:00
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
}
|
2008-12-05 03:19:56 +00:00
|
|
|
|
2012-07-24 16:56:57 +08:00
|
|
|
$context = context_module::instance($cm->id);
|
2008-09-09 08:30:00 +00:00
|
|
|
|
2011-06-30 14:59:08 +12:00
|
|
|
if (!empty($scoid)) {
|
2014-08-08 07:08:57 +05:30
|
|
|
// Direct SCO request.
|
2011-06-30 14:59:08 +12:00
|
|
|
if ($sco = scorm_get_sco($scoid)) {
|
|
|
|
if ($sco->launch == '') {
|
2014-08-08 07:08:57 +05:30
|
|
|
// Search for the next launchable sco.
|
2012-10-19 22:36:26 +02:00
|
|
|
if ($scoes = $DB->get_records_select(
|
|
|
|
'scorm_scoes',
|
|
|
|
'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true).' AND id > ?',
|
|
|
|
array($scorm->id, $sco->id),
|
2013-08-27 12:55:10 +12:00
|
|
|
'sortorder, id')) {
|
2011-06-30 14:59:08 +12:00
|
|
|
$sco = current($scoes);
|
2006-09-20 19:46:52 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
}
|
2014-08-08 07:08:57 +05:30
|
|
|
|
|
|
|
// If no sco was found get the first of SCORM package.
|
2011-06-30 14:59:08 +12:00
|
|
|
if (!isset($sco)) {
|
2012-10-19 22:36:26 +02:00
|
|
|
$scoes = $DB->get_records_select(
|
|
|
|
'scorm_scoes',
|
|
|
|
'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true),
|
|
|
|
array($scorm->id),
|
2013-08-27 12:55:10 +12:00
|
|
|
'sortorder, id'
|
2012-10-19 22:36:26 +02:00
|
|
|
);
|
2011-06-30 14:59:08 +12:00
|
|
|
$sco = current($scoes);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ($sco->scormtype == 'asset') {
|
|
|
|
$attempt = scorm_get_last_attempt($scorm->id, $USER->id);
|
2014-05-29 21:54:00 +00:00
|
|
|
$element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status' : 'cmi.core.lesson_status';
|
2011-06-30 14:59:08 +12:00
|
|
|
$value = 'completed';
|
|
|
|
$result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value);
|
|
|
|
}
|
|
|
|
|
2014-08-08 07:08:57 +05:30
|
|
|
// Forge SCO URL.
|
2011-06-30 14:59:08 +12:00
|
|
|
$connector = '';
|
|
|
|
$version = substr($scorm->version, 0, 4);
|
|
|
|
if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) {
|
|
|
|
if (stripos($sco->launch, '?') !== false) {
|
|
|
|
$connector = '&';
|
|
|
|
} else {
|
|
|
|
$connector = '?';
|
2006-09-20 19:46:52 +00:00
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) {
|
|
|
|
$sco->parameters = substr($sco->parameters, 1);
|
2006-09-29 06:27:47 +00:00
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
}
|
2008-09-09 08:30:00 +00:00
|
|
|
|
2011-06-30 14:59:08 +12:00
|
|
|
if ($version == 'AICC') {
|
2011-11-05 15:21:19 +13:00
|
|
|
require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php");
|
2014-05-29 21:54:00 +00:00
|
|
|
$aiccsid = scorm_aicc_get_hacp_session($scorm->id);
|
|
|
|
if (empty($aiccsid)) {
|
|
|
|
$aiccsid = sesskey();
|
2011-11-05 15:21:19 +13:00
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
$scoparams = '';
|
2011-06-30 14:59:08 +12:00
|
|
|
if (isset($sco->parameters) && (!empty($sco->parameters))) {
|
2014-05-29 21:54:00 +00:00
|
|
|
$scoparams = '&'. $sco->parameters;
|
2006-09-20 19:46:52 +00:00
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
$launcher = $sco->launch.$connector.'aicc_sid='.$aiccsid.'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$scoparams;
|
2011-06-30 14:59:08 +12:00
|
|
|
} else {
|
|
|
|
if (isset($sco->parameters) && (!empty($sco->parameters))) {
|
|
|
|
$launcher = $sco->launch.$connector.$sco->parameters;
|
2006-09-20 19:46:52 +00:00
|
|
|
} else {
|
2011-06-30 14:59:08 +12:00
|
|
|
$launcher = $sco->launch;
|
2006-09-20 19:46:52 +00:00
|
|
|
}
|
2011-06-30 14:59:08 +12:00
|
|
|
}
|
|
|
|
|
|
|
|
if (scorm_external_link($sco->launch)) {
|
2014-05-29 21:54:00 +00:00
|
|
|
// TODO: does this happen?
|
2011-06-30 14:59:08 +12:00
|
|
|
$result = $launcher;
|
|
|
|
} else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) {
|
2013-09-04 18:46:35 +12:00
|
|
|
// Remote learning activity.
|
2011-06-30 14:59:08 +12:00
|
|
|
$result = dirname($scorm->reference).'/'.$launcher;
|
2013-09-04 18:46:35 +12:00
|
|
|
} else if ($scorm->scormtype === SCORM_TYPE_LOCAL && strtolower($scorm->reference) == 'imsmanifest.xml') {
|
|
|
|
// This SCORM content sits in a repository that allows relative links.
|
|
|
|
$result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/imsmanifest/$scorm->revision/$launcher";
|
2011-06-30 14:59:08 +12:00
|
|
|
} else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) {
|
2013-09-04 18:46:35 +12:00
|
|
|
// Note: do not convert this to use get_file_url() or moodle_url()
|
|
|
|
// SCORM does not work without slasharguments and moodle_url() encodes querystring vars.
|
2011-06-30 14:59:08 +12:00
|
|
|
$result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher";
|
|
|
|
}
|
|
|
|
|
2014-01-07 14:10:20 +08:00
|
|
|
// Trigger a Sco launched event.
|
|
|
|
$event = \mod_scorm\event\sco_launched::create(array(
|
|
|
|
'objectid' => $sco->id,
|
|
|
|
'context' => $context,
|
|
|
|
'other' => array('instanceid' => $scorm->id, 'loadedcontent' => $result)
|
|
|
|
));
|
|
|
|
$event->add_record_snapshot('course_modules', $cm);
|
|
|
|
$event->add_record_snapshot('scorm', $scorm);
|
|
|
|
$event->add_record_snapshot('scorm_scoes', $sco);
|
|
|
|
$event->trigger();
|
2011-12-05 21:38:27 +13:00
|
|
|
|
2013-04-05 14:34:07 +08:00
|
|
|
header('Content-Type: text/html; charset=UTF-8');
|
|
|
|
|
2013-03-24 12:01:52 +01:00
|
|
|
if ($sco->scormtype == 'asset') {
|
|
|
|
// HTTP 302 Found => Moved Temporarily.
|
|
|
|
header('Location: ' . $result);
|
|
|
|
// Provide a short feedback in case of slow network connection.
|
2014-05-29 21:54:00 +00:00
|
|
|
echo html_writer::start_tag('html');
|
|
|
|
echo html_writer::tag('body', html_writer::tag('p', get_string('activitypleasewait', 'scorm')));
|
|
|
|
echo html_writer::end_tag('html');
|
2013-03-24 12:01:52 +01:00
|
|
|
exit;
|
|
|
|
}
|
|
|
|
|
|
|
|
// We expect a SCO: select which API are we looking for.
|
2014-08-08 07:08:57 +05:30
|
|
|
$lmsapi = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11';
|
2013-03-24 12:01:52 +01:00
|
|
|
|
2014-05-29 21:54:00 +00:00
|
|
|
echo html_writer::start_tag('html');
|
|
|
|
echo html_writer::start_tag('head');
|
|
|
|
echo html_writer::tag('title', 'LoadSCO');
|
2006-09-20 19:46:52 +00:00
|
|
|
?>
|
2014-05-29 21:54:00 +00:00
|
|
|
<script type="text/javascript">
|
|
|
|
//<![CDATA[
|
|
|
|
var myApiHandle = null;
|
|
|
|
var myFindAPITries = 0;
|
2008-12-05 03:19:56 +00:00
|
|
|
|
2014-05-29 21:54:00 +00:00
|
|
|
function myGetAPIHandle() {
|
|
|
|
myFindAPITries = 0;
|
|
|
|
if (myApiHandle == null) {
|
|
|
|
myApiHandle = myGetAPI();
|
|
|
|
}
|
|
|
|
return myApiHandle;
|
|
|
|
}
|
2008-12-05 03:19:56 +00:00
|
|
|
|
2014-05-29 21:54:00 +00:00
|
|
|
function myFindAPI(win) {
|
2014-08-08 07:08:57 +05:30
|
|
|
while ((win.<?php echo $lmsapi; ?> == null) && (win.parent != null) && (win.parent != win)) {
|
2014-05-29 21:54:00 +00:00
|
|
|
myFindAPITries++;
|
|
|
|
// Note: 7 is an arbitrary number, but should be more than sufficient
|
|
|
|
if (myFindAPITries > 7) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
win = win.parent;
|
|
|
|
}
|
2014-08-08 07:08:57 +05:30
|
|
|
return win.<?php echo $lmsapi; ?>;
|
2014-05-29 21:54:00 +00:00
|
|
|
}
|
2008-12-05 03:19:56 +00:00
|
|
|
|
2014-05-29 21:54:00 +00:00
|
|
|
// hun for the API - needs to be loaded before we can launch the package
|
|
|
|
function myGetAPI() {
|
|
|
|
var theAPI = myFindAPI(window);
|
|
|
|
if ((theAPI == null) && (window.opener != null) && (typeof(window.opener) != "undefined")) {
|
|
|
|
theAPI = myFindAPI(window.opener);
|
|
|
|
}
|
|
|
|
if (theAPI == null) {
|
|
|
|
return null;
|
|
|
|
}
|
|
|
|
return theAPI;
|
|
|
|
}
|
|
|
|
|
|
|
|
function doredirect() {
|
|
|
|
if (myGetAPIHandle() != null) {
|
|
|
|
location = "<?php echo $result ?>";
|
2008-08-04 02:35:13 +00:00
|
|
|
}
|
2014-05-29 21:54:00 +00:00
|
|
|
else {
|
2014-08-08 07:08:57 +05:30
|
|
|
document.body.innerHTML = "<p><?php echo get_string('activityloading', 'scorm');?>" +
|
|
|
|
"<span id='countdown'><?php echo $delayseconds ?></span> " +
|
|
|
|
"<?php echo get_string('numseconds', 'moodle', '');?>. " +
|
2014-10-24 16:45:32 -05:00
|
|
|
"<img src='<?php echo $OUTPUT->pix_url('wait', 'scorm') ?>'></p>";
|
2014-05-29 21:54:00 +00:00
|
|
|
var e = document.getElementById("countdown");
|
|
|
|
var cSeconds = parseInt(e.innerHTML);
|
|
|
|
var timer = setInterval(function() {
|
|
|
|
if( cSeconds && myGetAPIHandle() == null ) {
|
|
|
|
e.innerHTML = --cSeconds;
|
|
|
|
} else {
|
|
|
|
clearInterval(timer);
|
2014-08-15 13:55:06 +05:30
|
|
|
document.body.innerHTML = "<p><?php echo get_string('activitypleasewait', 'scorm');?></p>";
|
2014-05-29 21:54:00 +00:00
|
|
|
location = "<?php echo $result ?>";
|
|
|
|
}
|
|
|
|
}, 1000);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
//]]>
|
|
|
|
</script>
|
|
|
|
<noscript>
|
|
|
|
<meta http-equiv="refresh" content="0;url=<?php echo $result ?>" />
|
|
|
|
</noscript>
|
|
|
|
<?php
|
|
|
|
echo html_writer::end_tag('head');
|
|
|
|
echo html_writer::tag('body', html_writer::tag('p', get_string('activitypleasewait', 'scorm')), array('onload' => "doredirect();"));
|
|
|
|
echo html_writer::end_tag('html');
|