From: bobopinna Date: Thu, 25 Jan 2007 13:49:50 +0000 (+0000) Subject: Fixed external manifest problems X-Git-Url: http://git.mjollnir.org/gw?a=commitdiff_plain;h=8949f8df0ee6724903f8df67d29c92420cc7f13e;p=moodle.git Fixed external manifest problems --- diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 93b205bc7e..9a170a7ef7 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -44,7 +44,7 @@ function scorm_add_instance($scorm) { $id = insert_record('scorm', $scorm); - if ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) { + if (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#'))) { // Rename temp scorm dir to scorm id $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id); @@ -113,7 +113,7 @@ function scorm_update_instance($scorm) { scorm_delete_files($scorm->dir.'/'.$scorm->id); } if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && - (basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')) { + (scorm_external_link($scorm->reference) || ((basename($scorm->reference) != 'imsmanifest.xml') && ($scorm->reference[0] != '#')))) { rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id); } diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index f260c2718c..fb3804656f 100755 --- a/mod/scorm/loadSCO.php +++ b/mod/scorm/loadSCO.php @@ -6,6 +6,8 @@ $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)) { error('Course Module ID was incorrect'); @@ -89,20 +91,28 @@ } if (scorm_external_link($sco->launch)) { + // Remote learning activity $result = $launcher; } else if ($scorm->reference[0] == '#') { + // Repository require_once($repositoryconfigfile); $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch; } else { - if (basename($scorm->reference) == 'imsmanifest.xml') { - $basedir = scorm_dirname($scorm->reference); - } else { - $basedir = 'moddata/scorm/'.$scorm->id; - } - if ($CFG->slasharguments) { - $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher; + if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) { + // Remote manifest + $result = dirname($scorm->reference).'/'.$launcher; } else { - $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher; + // Moodle internal package/manifest or remote (auto-imported) package + if (basename($scorm->reference) == 'imsmanifest.xml') { + $basedir = dirname($scorm->reference); + } else { + $basedir = $CFG->moddata.'/scorm/'.$scorm->id; + } + if ($CFG->slasharguments) { + $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher; + } else { + $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher; + } } } ?> @@ -111,11 +121,11 @@ LoadSCO diff --git a/mod/scorm/locallib.php b/mod/scorm/locallib.php index e4df6db1f9..f5f4f52385 100755 --- a/mod/scorm/locallib.php +++ b/mod/scorm/locallib.php @@ -199,22 +199,6 @@ function scorm_external_link($link) { return $result; } -function scorm_dirname($location) { - if (scorm_external_link($location)) { - return substr($location,0,strrpos($location,'/')); - } else { - return dirname($location); - } -} - -function scorm_basename($location) { - if (scorm_external_link($location)) { - return substr($location,strrpos($location,'/')+1); - } else { - return basename($location); - } -} - /** * Returns an object containing all datas relative to the given sco ID * @@ -473,7 +457,7 @@ function scorm_course_format_display($user,$course) { // The module SCORM activity with the least id is the course $scorm = current($scorms); if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { - error("Course Module ID was incorrect"); + error('Course Module ID was incorrect'); } $colspan = ''; $headertext = '
'.get_string('name').': '.format_string($scorm->name).''; @@ -563,7 +547,7 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
popup == 1?' target="newwin"':'' ?>> hidebrowse == 0) { - print_string("mode","scorm"); + print_string('mode','scorm'); echo ': '."\n"; echo '\n"; } else { @@ -607,26 +591,23 @@ function scorm_simple_play($scorm,$user) { function scorm_parse($scorm) { global $CFG,$repositoryconfigfile; - + + if ($scorm->reference[0] == '#') { + $reference = $CFG->repository.substr($scorm->reference,1); + } else { + $reference = $scorm->dir.'/'.$scorm->id; + } // Parse scorm manifest if ($scorm->pkgtype == 'AICC') { require_once('datamodels/aicclib.php'); - $scorm->launch = scorm_parse_aicc($scorm->dir.'/'.$scorm->id,$scorm->id); + $scorm->launch = scorm_parse_aicc($reference, $scorm->id); } else { require_once('datamodels/scormlib.php'); - $reference = $scorm->reference; if ($scorm->reference[0] == '#') { require_once($repositoryconfigfile); - $reference = $CFG->repository.substr($scorm->reference,1).'/imsmanifest.xml'; - } else if (substr($reference,0,7) != 'http://') { - $reference = $CFG->dataroot.'/'.$scorm->course.'/'.$scorm->reference; } - if (basename($reference) != 'imsmanifest.xml') { - $scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id); - } else { - $scorm->launch = scorm_parse_scorm(scorm_dirname($reference),$scorm->id); - } + $scorm->launch = scorm_parse_scorm($reference,$scorm->id); } return $scorm->launch; } @@ -699,7 +680,7 @@ function scorm_validate($data) { $scormid = $data['instance']; // scorm ID $scorm = new stdClass(); if (!empty($scormid)) { - if (!$scorm = get_record("scorm","id",$scormid)) { + if (!$scorm = get_record('scorm','id',$scormid)) { $validation->errors['reference'] = get_string('missingparam','scorm'); $validation->result = false; return $validation; @@ -724,7 +705,7 @@ function scorm_validate($data) { $scormdir = ''; if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($tempdir = scorm_tempdir($scormdir)) { - $localreference = $tempdir."/".scorm_basename($reference); + $localreference = $tempdir.'/'.basename($reference); copy ("$reference", $localreference); if (!is_file($localreference)) { $validation->errors['reference'] = get_string('badpackage','scorm'); @@ -790,7 +771,6 @@ function scorm_check_package($data) { $scormid = $data->instance; // scorm ID $validation = new stdClass(); - $fstat=array("mtime"=>0); if (!empty($courseid) && !empty($reference)) { $externalpackage = scorm_external_link($reference); @@ -815,7 +795,6 @@ function scorm_check_package($data) { // // SCORM Update // - //if (($validation->launch != -1) && is_file($reference)) { if ((!empty($validation)) && (is_file($reference) || $externalpackage)){ if (!$externalpackage) { @@ -823,14 +802,14 @@ function scorm_check_package($data) { } else if ($externalpackage){ if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($tempdir = scorm_tempdir($scormdir)) { - copy ("$reference", $tempdir."/".basename($reference)); - $mdcheck = md5_file($tempdir."/".basename($reference)); + copy ("$reference", $tempdir.'/'.basename($reference)); + $mdcheck = md5_file($tempdir.'/'.basename($reference)); scorm_delete_files($tempdir); } } } - if ($scorm = get_record("scorm","id",$scormid)) { + if ($scorm = get_record('scorm','id',$scormid)) { if ($scorm->reference[0] == '#') { require_once($repositoryconfigfile); if ($CFG->repositoryactivate) { @@ -876,10 +855,10 @@ function scorm_check_package($data) { $scormdir = ''; if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($tempdir = scorm_tempdir($scormdir)) { - copy ("$reference", $tempdir."/".basename($reference)); - unzip_file($tempdir."/".basename($reference), $tempdir, false); + copy ("$reference", $tempdir.'/'.basename($reference)); + unzip_file($tempdir.'/'.basename($reference), $tempdir, false); if (!$externalpackage) { - unlink ($tempdir."/".basename($reference)); + unlink ($tempdir.'/'.basename($reference)); } if (is_file($tempdir.'/imsmanifest.xml')) { $validation = scorm_validate_manifest($tempdir.'/imsmanifest.xml'); @@ -900,8 +879,8 @@ function scorm_check_package($data) { if ($externalpackage) { if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($tempdir = scorm_tempdir($scormdir)) { - copy ("$reference", $tempdir."/".basename($reference)); - if (is_file($tempdir."/".basename($reference))) { + copy ("$reference", $tempdir.'/'.basename($reference)); + if (is_file($tempdir.'/'.basename($reference))) { $validation = scorm_validate_manifest($tempdir.'/'.basename($reference)); } else { $validation = null;