. 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 $scoid = required_param('scoid', PARAM_INT); // sco ID. $delayseconds = 2; // Delay time before sco launch, used to give time to browser to define API. if (!empty($id)) { if (! $cm = get_coursemodule_from_id('scorm', $id)) { print_error('invalidcoursemodule'); } if (! $course = $DB->get_record('course', array('id' => $cm->course))) { print_error('coursemisconf'); } if (! $scorm = $DB->get_record('scorm', array('id' => $cm->instance))) { print_error('invalidcoursemodule'); } } else if (!empty($a)) { if (! $scorm = $DB->get_record('scorm', array('id' => $a))) { print_error('coursemisconf'); } if (! $course = $DB->get_record('course', array('id' => $scorm->course))) { print_error('coursemisconf'); } if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { print_error('invalidcoursemodule'); } } else { print_error('missingparameter'); } $PAGE->set_url('/mod/scorm/loadSCO.php', array('scoid' => $scoid, 'id' => $cm->id)); 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. // Check if scorm closed. $timenow = time(); if ($scorm->timeclose != 0) { 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)); } } $context = context_module::instance($cm->id); if (!empty($scoid)) { // Direct SCO request. if ($sco = scorm_get_sco($scoid)) { if ($sco->launch == '') { // Search for the next launchable sco. 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), 'sortorder, id')) { $sco = current($scoes); } } } } // If no sco was found get the first of SCORM package. if (!isset($sco)) { $scoes = $DB->get_records_select( 'scorm_scoes', 'scorm = ? AND '.$DB->sql_isnotempty('scorm_scoes', 'launch', false, true), array($scorm->id), 'sortorder, id' ); $sco = current($scoes); } if ($sco->scormtype == 'asset') { $attempt = scorm_get_last_attempt($scorm->id, $USER->id); $element = (scorm_version_check($scorm->version, SCORM_13)) ? 'cmi.completion_status' : 'cmi.core.lesson_status'; $value = 'completed'; $result = scorm_insert_track($USER->id, $scorm->id, $sco->id, $attempt, $element, $value); } // Forge SCO URL. $connector = ''; $version = substr($scorm->version, 0, 4); if ((isset($sco->parameters) && (!empty($sco->parameters))) || ($version == 'AICC')) { if (stripos($sco->launch, '?') !== false) { $connector = '&'; } else { $connector = '?'; } if ((isset($sco->parameters) && (!empty($sco->parameters))) && ($sco->parameters[0] == '?')) { $sco->parameters = substr($sco->parameters, 1); } } if ($version == 'AICC') { require_once("$CFG->dirroot/mod/scorm/datamodels/aicclib.php"); $aiccsid = scorm_aicc_get_hacp_session($scorm->id); if (empty($aiccsid)) { $aiccsid = sesskey(); } $scoparams = ''; if (isset($sco->parameters) && (!empty($sco->parameters))) { $scoparams = '&'. $sco->parameters; } $launcher = $sco->launch.$connector.'aicc_sid='.$aiccsid.'&aicc_url='.$CFG->wwwroot.'/mod/scorm/aicc.php'.$scoparams; } else { if (isset($sco->parameters) && (!empty($sco->parameters))) { $launcher = $sco->launch.$connector.$sco->parameters; } else { $launcher = $sco->launch; } } if (scorm_external_link($sco->launch)) { // TODO: does this happen? $result = $launcher; } else if ($scorm->scormtype === SCORM_TYPE_EXTERNAL) { // Remote learning activity. $result = dirname($scorm->reference).'/'.$launcher; } 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"; } else if ($scorm->scormtype === SCORM_TYPE_LOCAL or $scorm->scormtype === SCORM_TYPE_LOCALSYNC) { // 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. $result = "$CFG->wwwroot/pluginfile.php/$context->id/mod_scorm/content/$scorm->revision/$launcher"; } // 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(); header('Content-Type: text/html; charset=UTF-8'); if ($sco->scormtype == 'asset') { // HTTP 302 Found => Moved Temporarily. header('Location: ' . $result); // Provide a short feedback in case of slow network connection. 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'); exit; } // We expect a SCO: select which API are we looking for. $lmsapi = (scorm_version_check($scorm->version, SCORM_12) || empty($scorm->version)) ? 'API' : 'API_1484_11'; echo html_writer::start_tag('html'); echo html_writer::start_tag('head'); echo html_writer::tag('title', 'LoadSCO'); ?> "doredirect();")); echo html_writer::end_tag('html');