Fixes for the problem creating directories.
authormoodler <moodler>
Sat, 22 May 2004 04:00:34 +0000 (04:00 +0000)
committermoodler <moodler>
Sat, 22 May 2004 04:00:34 +0000 (04:00 +0000)
It was just a missing $CFG, but I got rid of scorm_mkdirs to use
the moodlelib equivalent instead

mod/scorm/details.php
mod/scorm/lib.php

index d9547d22e921b76dbab5576dbcd6da76f708bea4..7eb7d64277d9d2b17436c1a553d8337950794dec 100755 (executable)
        //
        // Create a temporary directory to unzip package and validate imsmanifest
        //
-       $basedir = $CFG->dataroot."/".$course->id;
-       $scormdir = "/moddata/scorm";   
-       if (scorm_mkdirs($basedir.$scormdir)) {
-           if ($tempdir = scorm_datadir($basedir.$scormdir, $form->datadir)) {
-               copy ($basedir."/".$form->reference, $tempdir."/".basename($form->reference));
-               if (empty($CFG->unzip)) {    // Use built-in php-based unzip function
-                   include_once($CFG->dirroot.'/lib/pclzip/pclzip.lib.php');
-                   $archive = new PclZip($tempdir."/".basename($form->reference));
-                   if (!$list = $archive->extract($tempdir)) {
-                       error($archive->errorInfo(true));
-                   }
-               } else {
-                   $command = "cd $tempdir; $CFG->unzip -o ".basename($form->reference)." 2>&1";
-                   exec($command);
-               }
-               $result = scorm_validate($tempdir."/imsmanifest.xml");
-           } else {
-               $result = "packagedir";
-           }
+
+       $coursedir = "$CFG->dataroot/$course->id";
+
+       if ($scormdir = make_upload_directory("$course->id/$CFG->moddata/scorm")) {
+        if ($tempdir = scorm_datadir($scormdir, $form->datadir)) {
+            copy ("$coursedir/$form->reference", $tempdir."/".basename($form->reference));
+            if (empty($CFG->unzip)) {    // Use built-in php-based unzip function
+                include_once($CFG->dirroot.'/lib/pclzip/pclzip.lib.php');
+                $archive = new PclZip($tempdir."/".basename($form->reference));
+                if (!$list = $archive->extract($tempdir)) {
+                    error($archive->errorInfo(true));
+                }
+            } else {
+                $command = "cd $tempdir; $CFG->unzip -o ".basename($form->reference)." 2>&1";
+                exec($command);
+            }
+            $result = scorm_validate($tempdir."/imsmanifest.xml");
+        } else {
+            $result = "packagedir";
+        }
        } else {
            $result = "datadir";
        }
@@ -85,7 +86,7 @@
            echo "<form name=\"theform\" method=\"post\" $onsubmit action=\"$form->destination\">\n";
 ?>
         <input type="hidden" name="reference"  value="<?php p($form->reference) ?>">
-        <input type="hidden" name="datadir"    value="<?php p(substr($tempdir,strlen($basedir)+strlen($scormdir))) ?>">
+        <input type="hidden" name="datadir"    value="<?php p(substr($tempdir,strlen($scormdir))) ?>">
         <input type="hidden" name="summary"    value="<?php p($form->summary) ?>">
         <input type="hidden" name="auto"       value="<?php p($form->auto) ?>">
         <input type="hidden" name="name"       value="<?php p($form->name) ?>">
index 111d2a8a248818ad5ad68d8b34c267c643d07690..f54bda276835d48b5114cf6b34aaf081d41c1e2d 100755 (executable)
@@ -171,19 +171,11 @@ function scorm_randstring($len = "8")
         return $rstring;
 }
 
-function scorm_mkdirs($strPath)
-{
- global $CFG;
- if (is_dir($strPath))
-       return true;
- $pStrPath = dirname($strPath);
- if (!scorm_mkdirs($pStrPath)) 
-       return false;
- return mkdir($strPath, $CFG->directorypermissions);
-}
  
 function scorm_datadir($strPath, $existingdir="", $prefix = "SCORM")
 {
+    global $CFG;
+
        if (($existingdir!="") && (is_dir($strPath.$existingdir)))
                return $strPath.$existingdir;
                
@@ -192,6 +184,7 @@ function scorm_datadir($strPath, $existingdir="", $prefix = "SCORM")
                        $datadir="/".$prefix.scorm_randstring();
                } while (file_exists($strPath.$datadir));
                mkdir($strPath.$datadir, $CFG->directorypermissions);
+        @chmod($strPath.$datadir, $CFG->directorypermissions);  // Just in case mkdir didn't do it
                return $strPath.$datadir;
        } else {
                return false;