1. Directory Resources now support sub directories
authormoodler <moodler>
Sun, 16 May 2004 08:52:32 +0000 (08:52 +0000)
committermoodler <moodler>
Sun, 16 May 2004 08:52:32 +0000 (08:52 +0000)
2.  Subdirectories in File Manager now display their total size

files/index.php
lib/moodlelib.php
mod/resource/details.php
mod/resource/version.php
mod/resource/view.php
version.php

index 437d36fe6136dc1e25969690fdd5aba2fd45d232..90910ab569cb7d78344c832b3ca2704cbfa29dac 100644 (file)
@@ -715,13 +715,14 @@ function displaydir ($wdir) {
             $filename = $fullpath."/".$dir;
             $fileurl  = rawurlencode($wdir."/".$dir);
             $filesafe = rawurlencode($dir);
+            $filesize = display_size(get_directory_size("$fullpath/$dir"));
             $filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
     
             echo "<TR>";
 
             print_cell("center", "<INPUT TYPE=checkbox NAME=\"file$count\" VALUE=\"$fileurl\">");
             print_cell("left", "<A HREF=\"index.php?id=$id&wdir=$fileurl\"><IMG SRC=\"$CFG->pixpath/f/folder.gif\" HEIGHT=16 WIDTH=16 BORDER=0 ALT=\"Folder\"></A> <A HREF=\"index.php?id=$id&wdir=$fileurl\">".htmlspecialchars($dir)."</A>");
-            print_cell("right", "-");
+            print_cell("right", "<b>$filesize</b>");
             print_cell("right", $filedate);
             print_cell("right", "<A HREF=\"index.php?id=$id&wdir=$wdir&file=$filesafe&action=rename\">$strrename</A>");
     
index 2401f1c4491f868e99397beeb9b4a20fe1749aad..5cb48ca31651feb9517dfe15658bf16392203ebf 100644 (file)
@@ -1526,19 +1526,25 @@ function get_max_upload_sizes($sitebytes=0, $coursebytes=0, $modulebytes=0) {
     return $filesize;
 }
 
-function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=false) {
+function get_directory_list($rootdir, $excludefile="", $descend=true, $getdirs=false, $getfiles=true) {
 /// Returns an array with all the filenames in
 /// all subdirectories, relative to the given rootdir.
 /// If excludefile is defined, then that file/directory is ignored
-/// If justdirs is defined, then only subdirectories are listed, otherwise just files
+/// If getdirs is true, then (sub)directories are included in the output
+/// If getfiles is true, then files are included in the output
+/// (at least one of these must be true!)
 
     $dirs = array();
 
-    if (!is_dir($rootdir)) {
+    if (!$getdirs and !$getfiles) {   // Nothing to show
         return $dirs;
     }
 
-    if (!$dir = opendir($rootdir)) {
+    if (!is_dir($rootdir)) {          // Must be a directory
+        return $dirs;
+    }
+
+    if (!$dir = opendir($rootdir)) {  // Can't open it for some reason
         return $dirs;
     }
 
@@ -1549,16 +1555,16 @@ function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=
         }
         $fullfile = "$rootdir/$file";
         if (filetype($fullfile) == "dir") {
-            if ($justdirs) {
+            if ($getdirs) {
                 $dirs[] = $file;
             }
             if ($descend) {
-                $subdirs = get_directory_list($fullfile, $excludefile, $descend, $justdirs);
+                $subdirs = get_directory_list($fullfile, $excludefile, $descend, $getdirs, $getfiles);
                 foreach ($subdirs as $subdir) {
                     $dirs[] = "$file/$subdir";
                 }
             }
-        } else if (!$justdirs) {
+        } else if ($getfiles) {
             $dirs[] = $file;
         }
     }
@@ -1569,6 +1575,36 @@ function get_directory_list($rootdir, $excludefile="", $descend=true, $justdirs=
     return $dirs;
 }
 
+function get_directory_size($rootdir, $excludefile="") {
+/// Adds up all the files in a directory and works out the size
+
+    $size = 0;
+
+    if (!is_dir($rootdir)) {          // Must be a directory
+        return $dirs;
+    }
+
+    if (!$dir = opendir($rootdir)) {  // Can't open it for some reason
+        return $dirs;
+    }
+
+    while (false !== ($file = readdir($dir))) {
+        $firstchar = substr($file, 0, 1);
+        if ($firstchar == "." or $file == "CVS" or $file == $excludefile) {
+            continue;
+        }
+        $fullfile = "$rootdir/$file";
+        if (filetype($fullfile) == "dir") {
+            $size += get_directory_size($fullfile, $excludefile);
+        } else {
+            $size += filesize($fullfile);
+        }
+    }
+    closedir($dir);
+
+    return $size;
+}
+
 function get_real_size($size=0) {
 /// Converts numbers like 10M into bytes
     if (!$size) {
index 3a05c58619a086570fe3ded8999de716e64c3a89..a93a1a5650ea8d79d60a0ed3b72875582b519203 100644 (file)
                 break;
 
             case DIRECTORY:
-                $rawdirs = get_directory_list("$CFG->dataroot/$course->id", 'moddata', true, true);
+                $rawdirs = get_directory_list("$CFG->dataroot/$course->id", 'moddata', true, true, false);
                 $dirs = array();
                 foreach ($rawdirs as $rawdir) {
                    $dirs[$rawdir] = $rawdir;
index d783b541f0d9549b751aa9514eb3bf918d9c3f35..023a4396456d27068e73730ff5fcf502f7d22c2b 100644 (file)
@@ -6,7 +6,7 @@
 ////////////////////////////////////////////////////////////////////////////////
 
 $module->version  = 2004013101;
-$module->requires = 2004050200;  // Requires this Moodle version
+$module->requires = 2004051600;  // Requires this Moodle version
 $module->cron     = 0;
 
 ?>
index 3b3ac886569d1e3a30f81a20515063eab2892371..37436a2b2996668fbe40896906917de6c62e49f1 100644 (file)
@@ -5,6 +5,7 @@
  
     require_variable($id);    // Course Module ID
     optional_variable($frameset, "");
+    optional_variable($subdir, "");
 
     if (!empty($CFG->forcelogin)) {
         require_login();
             require_once("../../files/mimetypes.php");
 
             add_to_log($course->id, "resource", "view", "view.php?id=$cm->id", $resource->id, $cm->id);
-            print_header($pagetitle, "$course->fullname", "$navigation $resource->name",
-                "", "", true, update_module_button($cm->id, $course->id, $strresource), navmenu($course, $cm));
+
+            if ($resource->reference) {
+                $relativepath = "$course->id/$resource->reference";
+            } else {
+                $relativepath = "$course->id";
+            }
+            
+            if ($subdir) {
+                if (detect_munged_arguments($subdir)) {
+                    error("The value for 'subdir' contains illegal characters!");
+                }
+                $relativepath = "$relativepath$subdir";
+
+                $subs = explode('/', $subdir);
+                array_shift($subs);
+                $countsubs = count($subs);
+                $count = 0;
+                $subnav = "<a href=\"view.php?id=$cm->id\">$resource->name</a>";
+                $backsub = '';
+                foreach ($subs as $sub) {
+                    $count++;
+                    if ($count < $countsubs) {
+                        $backsub .= "/$sub";
+                        $subnav  .= " -> <a href=\"view.php?id=$cm->id&subdir=$backsub\">$sub</a>";
+                    } else {
+                        $subnav .= " -> $sub";
+                    }
+                }
+            } else {
+                $subnav = $resource->name;
+            }
+
+            print_header($pagetitle, "$course->fullname", "$navigation $subnav",
+                         "", "", true, update_module_button($cm->id, $course->id, $strresource), 
+                         navmenu($course, $cm));
 
             if (trim($resource->summary)) {
                 print_simple_box(text_to_html($resource->summary), "center");
 
             print_simple_box_start("center", "", "$THEME->cellcontent", '0' );
 
-            if ($resource->reference) {
-                $relativepath = "$course->id/$resource->reference";
-            } else {
-                $relativepath = "$course->id";
-            }
-
-            $files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false);
+            $files = get_directory_list("$CFG->dataroot/$relativepath", 'moddata', false, true, true);
             $strftime = get_string('strftimedatetime');
             $strname = get_string("name");
             $strsize = get_string("size");
                      "<th align=\"right\">$strmodified</th>".
                  "</tr>";
             foreach ($files as $file) {
-                $icon = mimeinfo("icon", $file);
+                if (is_dir("$CFG->dataroot/$relativepath/$file")) {          // Must be a directory
+                    $icon = "folder.gif";
+                    $relativeurl = "/view.php?blah";
+                    $filesize = display_size(get_directory_size("$CFG->dataroot/$relativepath/$file"));
 
-                if ($CFG->slasharguments) {
-                    $relativeurl = "/file.php/$relativepath/$file";
                 } else {
-                    $relativeurl = "/file.php?file=/$relativepath/$file";
+                    $icon = mimeinfo("icon", $file);
+
+                    if ($CFG->slasharguments) {
+                        $relativeurl = "/file.php/$relativepath/$file";
+                    } else {
+                        $relativeurl = "/file.php?file=/$relativepath/$file";
+                    }
+                    $filesize = display_size(filesize("$CFG->dataroot/$relativepath/$file"));
                 }
-                $filesize = display_size(filesize("$CFG->dataroot/$course->id/$resource->reference/$file"));
 
                 echo '<tr>';
                 echo '<td>';
                 echo "<img src=\"$CFG->pixpath/f/$icon\" width=\"16\" height=\"16\">";
                 echo '</td>';
                 echo '<td nowrap="nowrap"><p>';
-                link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, '');
+                if ($icon == 'folder.gif') {
+                    echo "<a href=\"view.php?id=$cm->id&subdir=$subdir/$file\">$file</a>";
+                } else {
+                    link_to_popup_window($relativeurl, "resourceedirectory$resource->id", "$file", 450, 600, '');
+                }
                 echo '</p></td>';
                 echo '<td>&nbsp;</td>';
                 echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
                 echo $filesize;
                 echo '</font></p></td>';
                 echo '<td align="right" nowrap="nowrap"><p><font size="-1">';
-                echo userdate(filectime("$CFG->dataroot/$course->id/$resource->reference/$file"), $strftime);
+                echo userdate(filectime("$CFG->dataroot/$relativepath/$file"), $strftime);
                 echo '</font></p></td>';
                 echo '</tr>';
             }
index 64d22588854dcdf7984b8cbec0c2d49bbeae9fdd..9d0f29d9c19d93805012287a688374216b14828b 100644 (file)
@@ -5,7 +5,7 @@
 // database to determine whether upgrades should
 // be performed (see lib/db/*.php)
 
-$version = 2004051500;   // The current version is a date (YYYYMMDDXX)
+$version = 2004051600;   // The current version is a date (YYYYMMDDXX)
 
 $release = "1.3 Beta +";   // User-friendly version number