Skip to content

Commit

Permalink
Fixed external manifest problems
Browse files Browse the repository at this point in the history
  • Loading branch information
bobopinna committed Jan 25, 2007
1 parent 8e452b0 commit 8949f8d
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 53 deletions.
4 changes: 2 additions & 2 deletions mod/scorm/lib.php
Expand Up @@ -44,7 +44,7 @@ function scorm_add_instance($scorm) {


$id = insert_record('scorm', $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 // Rename temp scorm dir to scorm id
$scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm'; $scorm->dir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id); rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$id);
Expand Down Expand Up @@ -113,7 +113,7 @@ function scorm_update_instance($scorm) {
scorm_delete_files($scorm->dir.'/'.$scorm->id); scorm_delete_files($scorm->dir.'/'.$scorm->id);
} }
if (isset($scorm->datadir) && ($scorm->datadir != $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); rename($scorm->dir.$scorm->datadir,$scorm->dir.'/'.$scorm->id);
} }


Expand Down
30 changes: 20 additions & 10 deletions mod/scorm/loadSCO.php
Expand Up @@ -6,6 +6,8 @@
$a = optional_param('a', '', PARAM_INT); // scorm ID $a = optional_param('a', '', PARAM_INT); // scorm ID
$scoid = required_param('scoid', PARAM_INT); // sco 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 (!empty($id)) {
if (! $cm = get_coursemodule_from_id('scorm', $id)) { if (! $cm = get_coursemodule_from_id('scorm', $id)) {
error('Course Module ID was incorrect'); error('Course Module ID was incorrect');
Expand Down Expand Up @@ -89,20 +91,28 @@
} }


if (scorm_external_link($sco->launch)) { if (scorm_external_link($sco->launch)) {
// Remote learning activity
$result = $launcher; $result = $launcher;
} else if ($scorm->reference[0] == '#') { } else if ($scorm->reference[0] == '#') {
// Repository
require_once($repositoryconfigfile); require_once($repositoryconfigfile);
$result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch; $result = $CFG->repositorywebroot.substr($scorm->reference,1).'/'.$sco->launch;
} else { } else {
if (basename($scorm->reference) == 'imsmanifest.xml') { if ((basename($scorm->reference) == 'imsmanifest.xml') && scorm_external_link($scorm->reference)) {
$basedir = scorm_dirname($scorm->reference); // Remote manifest
} else { $result = dirname($scorm->reference).'/'.$launcher;
$basedir = 'moddata/scorm/'.$scorm->id;
}
if ($CFG->slasharguments) {
$result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
} else { } 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;
}
} }
} }
?> ?>
Expand All @@ -111,11 +121,11 @@
<title>LoadSCO</title> <title>LoadSCO</title>
<script type="text/javascript"> <script type="text/javascript">
//<![CDATA[ //<![CDATA[
setTimeout('document.location = "<?php echo $result ?>";',2000); setTimeout('document.location = "<?php echo $result ?>";',<?php echo $delayseconds ?>000);
//]]> //]]>
</script> </script>
<noscript> <noscript>
<meta http-equiv="refresh" content="2;url=<?php echo $result ?>" /> <meta http-equiv="refresh" content="<?php echo $delayseconds ?>;url=<?php echo $result ?>" />
</noscript> </noscript>
</head> </head>
<body> <body>
Expand Down
61 changes: 20 additions & 41 deletions mod/scorm/locallib.php
Expand Up @@ -199,22 +199,6 @@ function scorm_external_link($link) {
return $result; 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 * Returns an object containing all datas relative to the given sco ID
* *
Expand Down Expand Up @@ -473,7 +457,7 @@ function scorm_course_format_display($user,$course) {
// The module SCORM activity with the least id is the course // The module SCORM activity with the least id is the course
$scorm = current($scorms); $scorm = current($scorms);
if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) { if (! $cm = get_coursemodule_from_instance('scorm', $scorm->id, $course->id)) {
error("Course Module ID was incorrect"); error('Course Module ID was incorrect');
} }
$colspan = ''; $colspan = '';
$headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>'; $headertext = '<table width="100%"><tr><td class="title">'.get_string('name').': <b>'.format_string($scorm->name).'</b>';
Expand Down Expand Up @@ -563,7 +547,7 @@ function scorm_view_display ($user, $scorm, $action, $cm, $boxwidth='') {
<form id="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>> <form id="theform" method="post" action="<?php echo $CFG->wwwroot ?>/mod/scorm/player.php?id=<?php echo $cm->id ?>"<?php echo $scorm->popup == 1?' target="newwin"':'' ?>>
<?php <?php
if ($scorm->hidebrowse == 0) { if ($scorm->hidebrowse == 0) {
print_string("mode","scorm"); print_string('mode','scorm');
echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n"; echo ': <input type="radio" id="b" name="mode" value="browse" /><label for="b">'.get_string('browse','scorm').'</label>'."\n";
echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n"; echo '<input type="radio" id="n" name="mode" value="normal" checked="checked" /><label for="n">'.get_string('normal','scorm')."</label>\n";
} else { } else {
Expand Down Expand Up @@ -607,26 +591,23 @@ function scorm_simple_play($scorm,$user) {


function scorm_parse($scorm) { function scorm_parse($scorm) {
global $CFG,$repositoryconfigfile; global $CFG,$repositoryconfigfile;


if ($scorm->reference[0] == '#') {
$reference = $CFG->repository.substr($scorm->reference,1);
} else {
$reference = $scorm->dir.'/'.$scorm->id;
}
// Parse scorm manifest // Parse scorm manifest
if ($scorm->pkgtype == 'AICC') { if ($scorm->pkgtype == 'AICC') {
require_once('datamodels/aicclib.php'); 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 { } else {
require_once('datamodels/scormlib.php'); require_once('datamodels/scormlib.php');
$reference = $scorm->reference;
if ($scorm->reference[0] == '#') { if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile); 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($reference,$scorm->id);
$scorm->launch = scorm_parse_scorm($scorm->dir.'/'.$scorm->id,$scorm->id);
} else {
$scorm->launch = scorm_parse_scorm(scorm_dirname($reference),$scorm->id);
}
} }
return $scorm->launch; return $scorm->launch;
} }
Expand Down Expand Up @@ -699,7 +680,7 @@ function scorm_validate($data) {
$scormid = $data['instance']; // scorm ID $scormid = $data['instance']; // scorm ID
$scorm = new stdClass(); $scorm = new stdClass();
if (!empty($scormid)) { 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->errors['reference'] = get_string('missingparam','scorm');
$validation->result = false; $validation->result = false;
return $validation; return $validation;
Expand All @@ -724,7 +705,7 @@ function scorm_validate($data) {
$scormdir = ''; $scormdir = '';
if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
if ($tempdir = scorm_tempdir($scormdir)) { if ($tempdir = scorm_tempdir($scormdir)) {
$localreference = $tempdir."/".scorm_basename($reference); $localreference = $tempdir.'/'.basename($reference);
copy ("$reference", $localreference); copy ("$reference", $localreference);
if (!is_file($localreference)) { if (!is_file($localreference)) {
$validation->errors['reference'] = get_string('badpackage','scorm'); $validation->errors['reference'] = get_string('badpackage','scorm');
Expand Down Expand Up @@ -790,7 +771,6 @@ function scorm_check_package($data) {
$scormid = $data->instance; // scorm ID $scormid = $data->instance; // scorm ID


$validation = new stdClass(); $validation = new stdClass();
$fstat=array("mtime"=>0);


if (!empty($courseid) && !empty($reference)) { if (!empty($courseid) && !empty($reference)) {
$externalpackage = scorm_external_link($reference); $externalpackage = scorm_external_link($reference);
Expand All @@ -815,22 +795,21 @@ function scorm_check_package($data) {
// //
// SCORM Update // SCORM Update
// //
//if (($validation->launch != -1) && is_file($reference)) {
if ((!empty($validation)) && (is_file($reference) || $externalpackage)){ if ((!empty($validation)) && (is_file($reference) || $externalpackage)){


if (!$externalpackage) { if (!$externalpackage) {
$mdcheck = md5_file($reference); $mdcheck = md5_file($reference);
} else if ($externalpackage){ } else if ($externalpackage){
if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
if ($tempdir = scorm_tempdir($scormdir)) { if ($tempdir = scorm_tempdir($scormdir)) {
copy ("$reference", $tempdir."/".basename($reference)); copy ("$reference", $tempdir.'/'.basename($reference));
$mdcheck = md5_file($tempdir."/".basename($reference)); $mdcheck = md5_file($tempdir.'/'.basename($reference));
scorm_delete_files($tempdir); scorm_delete_files($tempdir);
} }
} }
} }


if ($scorm = get_record("scorm","id",$scormid)) { if ($scorm = get_record('scorm','id',$scormid)) {
if ($scorm->reference[0] == '#') { if ($scorm->reference[0] == '#') {
require_once($repositoryconfigfile); require_once($repositoryconfigfile);
if ($CFG->repositoryactivate) { if ($CFG->repositoryactivate) {
Expand Down Expand Up @@ -876,10 +855,10 @@ function scorm_check_package($data) {
$scormdir = ''; $scormdir = '';
if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
if ($tempdir = scorm_tempdir($scormdir)) { if ($tempdir = scorm_tempdir($scormdir)) {
copy ("$reference", $tempdir."/".basename($reference)); copy ("$reference", $tempdir.'/'.basename($reference));
unzip_file($tempdir."/".basename($reference), $tempdir, false); unzip_file($tempdir.'/'.basename($reference), $tempdir, false);
if (!$externalpackage) { if (!$externalpackage) {
unlink ($tempdir."/".basename($reference)); unlink ($tempdir.'/'.basename($reference));
} }
if (is_file($tempdir.'/imsmanifest.xml')) { if (is_file($tempdir.'/imsmanifest.xml')) {
$validation = scorm_validate_manifest($tempdir.'/imsmanifest.xml'); $validation = scorm_validate_manifest($tempdir.'/imsmanifest.xml');
Expand All @@ -900,8 +879,8 @@ function scorm_check_package($data) {
if ($externalpackage) { if ($externalpackage) {
if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) { if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
if ($tempdir = scorm_tempdir($scormdir)) { if ($tempdir = scorm_tempdir($scormdir)) {
copy ("$reference", $tempdir."/".basename($reference)); copy ("$reference", $tempdir.'/'.basename($reference));
if (is_file($tempdir."/".basename($reference))) { if (is_file($tempdir.'/'.basename($reference))) {
$validation = scorm_validate_manifest($tempdir.'/'.basename($reference)); $validation = scorm_validate_manifest($tempdir.'/'.basename($reference));
} else { } else {
$validation = null; $validation = null;
Expand Down

0 comments on commit 8949f8d

Please sign in to comment.