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;
}
}
$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;
}
}
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) {
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> </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>';
}