Browse files

Added direct import of manifest files.

Now is possible to select in the package field a imsmanifest.xml file
  • Loading branch information...
1 parent e112e31 commit 45b700159a34c7a85efa190cbcedf4917bdccfed bobopinna committed Sep 13, 2005
Showing with 60 additions and 30 deletions.
  1. +17 −8 mod/scorm/lib.php
  2. +8 −3 mod/scorm/loadSCO.php
  3. +1 −0 mod/scorm/mod.html
  4. +34 −19 mod/scorm/validate.php
View
25 mod/scorm/lib.php
@@ -48,18 +48,23 @@ function scorm_add_instance($scorm) {
$id = insert_record('scorm', $scorm);
-
- // Rename temp scorm dir to scorm id
- $scormdir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
- rename($scormdir.$scorm->datadir,$scormdir.'/'.$id);
+ if (basename($scorm->reference) != 'imsmanifest.xml') {
+ // Rename temp scorm dir to scorm id
+ $scormdir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
+ rename($scormdir.$scorm->datadir,$scormdir.'/'.$id);
+ }
// Parse scorm manifest
if ($scorm->launch == 0) {
if ($scorm->pkgtype == 'AICC') {
$scorm->launch = scorm_parse_aicc($scormdir.'/'.$id,$id);
} else {
- $scorm->launch = scorm_parse_scorm($scormdir.'/'.$id,$id);
+ if (basename($scorm->reference) != 'imsmanifest.xml') {
+ $scorm->launch = scorm_parse_scorm($scormdir.'/'.$id,$id);
+ } else {
+ $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$id);
+ }
}
set_field('scorm','launch',$scorm->launch,'id',$id);
}
@@ -89,15 +94,19 @@ function scorm_update_instance($scorm) {
delete_records('scorm_scoes_track','scormid',$scorm->id);
$scormdir = $CFG->dataroot.'/'.$scorm->course.'/moddata/scorm';
- if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id)) {
+ if (isset($scorm->datadir) && ($scorm->datadir != $scorm->id) && (basename($scorm->reference) != 'imsmanifest.xml')) {
scorm_delete_files($scormdir.'/'.$scorm->id);
rename($scormdir.$scorm->datadir,$scormdir.'/'.$scorm->id);
}
if ($scorm->pkgtype == 'AICC') {
$scorm->launch = scorm_parse_aicc($scormdir.'/'.$scorm->id,$scorm->id);
} else {
- $scorm->launch = scorm_parse_scorm($scormdir.'/'.$scorm->id,$scorm->id);
+ if (basename($scorm->reference) != 'imsmanifest.xml') {
+ $scorm->launch = scorm_parse_scorm($scormdir.'/'.$scorm->id,$scorm->id);
+ } else {
+ $scorm->launch = scorm_parse_scorm($CFG->dataroot.'/'.$scorm->course.'/'.dirname($scorm->reference),$scorm->id);
+ }
}
}
@@ -114,7 +123,7 @@ function scorm_update_instance($scorm) {
*/
function scorm_delete_instance($id) {
- require('../config.php');
+ global $CFG;
if (! $scorm = get_record('scorm', 'id', $id)) {
return false;
View
11 mod/scorm/loadSCO.php
@@ -75,7 +75,7 @@
} else {
$connector = '?';
}
- if ($sco->parameters[0] == '?') {
+ if (!empty($sco->parameters) && ($sco->parameters[0] == '?')) {
$sco->parameters = substr($sco->parameters,1);
}
}
@@ -92,10 +92,15 @@
if (scorm_external_link($sco->launch)) {
$result = $launcher;
} else {
+ if (basename($scorm->reference) == 'imsmanifest.xml') {
+ $basedir = dirname($scorm->reference);
+ } else {
+ $basedir = 'moddata/scorm/'.$scorm->id;
+ }
if ($CFG->slasharguments) {
- $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$launcher;
+ $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/'.$basedir.'/'.$launcher;
} else {
- $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$launcher;
+ $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/'.$basedir.'/'.$launcher;
}
}
?>
View
1 mod/scorm/mod.html
@@ -62,6 +62,7 @@
function validate_scorm(theform,filename) {
var myRequest = NewHttpReq();
result = DoRequest(myRequest,"<?php p($CFG->wwwroot) ?>/mod/scorm/validate.php","id=<?php p($form->course) ?>&reference="+filename+"<?php echo $sessionkey.$scormid.$datadir ?>");
+ //alert(result);
results = result.split('\n');
result = '';
errorlogs = '';
View
53 mod/scorm/validate.php
@@ -7,7 +7,7 @@
$reference = required_param('reference', '', PARAM_PATH); // Package path
$scormid = optional_param('instance', '', PARAM_INT); // scorm ID
- require_login($course->id, false, $cm);
+ require_login($courseid, false);
if (confirm_sesskey() && !empty($courseid)) {
$launch = 0;
@@ -53,25 +53,36 @@
// Package must be validated
//
- // Create a temporary directory to unzip package and validate package
- $tempdir = '';
- $scormdir = '';
- if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
- if ($tempdir = scorm_datadir($scormdir)) {
- copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
- $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));
- if (($ext == '.zip') || ($ext == '.pif')) {
- unzip_file($tempdir."/".basename($reference), $tempdir, false);
- unlink ($tempdir."/".basename($reference));
- $validation = scorm_validate($tempdir);
+ $ext = strtolower(substr(basename($reference),strrpos(basename($reference),'.')));
+ switch ($ext) {
+ case '.pif':
+ case '.zip':
+ // Create a temporary directory to unzip package and validate package
+ $tempdir = '';
+ $scormdir = '';
+ if ($scormdir = make_upload_directory("$courseid/$CFG->moddata/scorm")) {
+ if ($tempdir = scorm_datadir($scormdir)) {
+ copy ("$CFG->dataroot/$courseid/$reference", $tempdir."/".basename($reference));
+ unzip_file($tempdir."/".basename($reference), $tempdir, false);
+ unlink ($tempdir."/".basename($reference));
+ $validation = scorm_validate($tempdir);
+ } else {
+ $validation->result = "packagedir";
+ }
} else {
- $validation->result = "packagefile";
+ $validation->result = "datadir";
}
- } else {
- $validation->result = "packagedir";
- }
- } else {
- $validation->result = "datadir";
+ break;
+ case '.xml':
+ if (basename($reference) == 'imsmanifest.xml') {
+ $validation = scorm_validate("$CFG->dataroot/$courseid/".dirname($reference));
+ } else {
+ $validation->result = "manifestfile";
+ }
+ break;
+ default:
+ $validation->result = "packagefile";
+ break;
}
if (($validation->result != "regular") && ($validation->result != "found")) {
$validation->result = get_string($validation->result,'scorm');
@@ -80,7 +91,11 @@
scorm_delete_files($tempdir);
}
} else {
- $datadir = substr($tempdir,strlen($scormdir));
+ if ($ext == '.xml') {
+ $datadir = dirname($reference);
+ } else {
+ $datadir = substr($tempdir,strlen($scormdir));
+ }
}
}
//

0 comments on commit 45b7001

Please sign in to comment.