diff --git a/mod/scorm/lib.php b/mod/scorm/lib.php index 9d9b8dee8db..ef6d8a5441c 100755 --- a/mod/scorm/lib.php +++ b/mod/scorm/lib.php @@ -48,10 +48,11 @@ 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) { @@ -59,7 +60,11 @@ function scorm_add_instance($scorm) { 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,7 +94,7 @@ 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); } @@ -97,7 +102,11 @@ function scorm_update_instance($scorm) { 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; diff --git a/mod/scorm/loadSCO.php b/mod/scorm/loadSCO.php index 97af2fd6ce4..1cc3401a2d0 100755 --- a/mod/scorm/loadSCO.php +++ b/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 ($CFG->slasharguments) { - $result = $CFG->wwwroot.'/file.php/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$launcher; + if (basename($scorm->reference) == 'imsmanifest.xml') { + $basedir = dirname($scorm->reference); } else { - $result = $CFG->wwwroot.'/file.php?file=/'.$scorm->course.'/moddata/scorm/'.$scorm->id.'/'.$launcher; + $basedir = '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; } } ?> diff --git a/mod/scorm/mod.html b/mod/scorm/mod.html index 4ce777ec3d5..5f2e43914c7 100755 --- a/mod/scorm/mod.html +++ b/mod/scorm/mod.html @@ -62,6 +62,7 @@ function validate_scorm(theform,filename) { var myRequest = NewHttpReq(); result = DoRequest(myRequest,"wwwroot) ?>/mod/scorm/validate.php","id=course) ?>&reference="+filename+""); + //alert(result); results = result.split('\n'); result = ''; errorlogs = ''; diff --git a/mod/scorm/validate.php b/mod/scorm/validate.php index c1941654f55..022e5b5464a 100755 --- a/mod/scorm/validate.php +++ b/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 @@ if (confirm_sesskey() && !empty($courseid)) { // 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 @@ if (confirm_sesskey() && !empty($courseid)) { scorm_delete_files($tempdir); } } else { - $datadir = substr($tempdir,strlen($scormdir)); + if ($ext == '.xml') { + $datadir = dirname($reference); + } else { + $datadir = substr($tempdir,strlen($scormdir)); + } } } //