moodle/files/index.php

891 lines
38 KiB
PHP
Raw Normal View History

<?php // $Id$
2001-11-22 06:23:56 +00:00
// Manage all uploaded files in a course file area
// All the Moodle-specific stuff is in this top section
// Configuration and access control occurs here.
// Must define: USER, basedir, baseweb, html_header and html_footer
// USER is a persistent variable using sessions
require('../config.php');
require($CFG->libdir.'/filelib.php');
2001-11-22 06:23:56 +00:00
$id = required_param('id', PARAM_INT);
$file = optional_param('file', '', PARAM_PATH);
$wdir = optional_param('wdir', '', PARAM_PATH);
$action = optional_param('action', '', PARAM_ACTION);
$name = optional_param('name', '', PARAM_FILE);
$oldname = optional_param('oldname', '', PARAM_FILE);
2004-11-02 12:45:04 +00:00
$choose = optional_param('choose', '', PARAM_CLEAN);
2005-06-10 13:18:29 +00:00
$userfile= optional_param('userfile','',PARAM_FILE);
$save = optional_param('save', 0, PARAM_BOOL);
$text = optional_param('text', '', PARAM_RAW);
$confirm = optional_param('confirm', 0, PARAM_BOOL);
2004-11-02 12:45:04 +00:00
if ($choose) {
if (count(explode('.', $choose)) != 2) {
error('Incorrect format for choose parameter');
}
}
2001-11-22 06:23:56 +00:00
if (! $course = get_record("course", "id", $id) ) {
error("That's an invalid course id");
}
2001-11-22 06:23:56 +00:00
require_login($course->id);
2001-11-22 06:23:56 +00:00
if (! isteacheredit($course->id) ) {
error("You need to be a teacher with editing privileges");
2001-11-22 06:23:56 +00:00
}
function html_footer() {
2004-11-02 12:45:04 +00:00
global $course, $choose;
echo '</td></tr></table>';
print_footer($course);
2001-11-22 06:23:56 +00:00
}
function html_header($course, $wdir, $formfield=""){
2005-03-19 08:32:01 +00:00
global $CFG, $ME, $choose;
2004-11-02 12:45:04 +00:00
if (! $site = get_site()) {
error("Invalid site!");
}
2004-11-02 12:45:04 +00:00
if ($course->id == $site->id) {
$strfiles = get_string("sitefiles");
} else {
$strfiles = get_string("files");
}
2004-11-02 12:45:04 +00:00
if ($wdir == "/") {
$fullnav = "$strfiles";
} else {
$dirs = explode("/", $wdir);
$numdirs = count($dirs);
$link = "";
$navigation = "";
for ($i=1; $i<$numdirs-1; $i++) {
$navigation .= " -> ";
$link .= "/".urlencode($dirs[$i]);
2004-11-02 12:45:04 +00:00
$navigation .= "<a href=\"".$ME."?id=$course->id&amp;wdir=$link&amp;choose=$choose\">".$dirs[$i]."</a>";
}
2004-11-02 12:45:04 +00:00
$fullnav = "<a href=\"".$ME."?id=$course->id&amp;wdir=/&amp;choose=$choose\">$strfiles</a> $navigation -> ".$dirs[$numdirs-1];
}
2004-11-02 12:45:04 +00:00
if ($choose) {
print_header();
$chooseparts = explode('.', $choose);
?>
<script language="javascript" type="text/javascript">
<!--
function set_value(txt) {
opener.document.forms['<?php echo $chooseparts[0]."'].".$chooseparts[1] ?>.value = txt;
window.close();
}
-->
</script>
<?php
$fullnav = str_replace('->', '&raquo;', "$course->shortname -> $fullnav");
2005-03-19 08:32:01 +00:00
echo '<div id="nav-bar">'.$fullnav.'</div>';
2004-11-02 12:45:04 +00:00
if ($course->id == $site->id) {
print_heading(get_string("publicsitefileswarning"), "center", 2);
}
} else {
2004-11-02 12:45:04 +00:00
if ($course->id == $site->id) {
print_header("$course->shortname: $strfiles", "$course->fullname",
"<a href=\"../$CFG->admin/index.php\">".get_string("administration").
"</a> -> $fullnav", $formfield);
print_heading(get_string("publicsitefileswarning"), "center", 2);
} else {
print_header("$course->shortname: $strfiles", "$course->fullname",
"<a href=\"../course/view.php?id=$course->id\">$course->shortname".
"</a> -> $fullnav", $formfield);
}
}
2004-11-02 12:45:04 +00:00
echo "<table border=\"0\" align=\"center\" cellspacing=\"3\" cellpadding=\"3\" width=\"640\">";
2001-11-22 06:23:56 +00:00
echo "<tr>";
echo "<td colspan=\"2\">";
2004-11-02 12:45:04 +00:00
2001-11-22 06:23:56 +00:00
}
2004-11-02 12:45:04 +00:00
if (! $basedir = make_upload_directory("$course->id")) {
error("The site administrator needs to fix the file permissions");
2001-11-22 06:23:56 +00:00
}
$baseweb = $CFG->wwwroot;
// End of configuration and access control
if ($wdir == '') {
$wdir = "/";
}
if ($wdir{0} != '/') { //make sure $wdir starts with slash
$wdir = "/".$wdir;
2001-11-22 06:23:56 +00:00
}
if ($wdir == "/backupdata") {
if (! make_upload_directory("$course->id/backupdata")) { // Backup folder
error("Could not create backupdata folder. The site administrator needs to fix the file permissions");
}
}
if (!is_dir($basedir.$wdir)) {
html_header($course, $wdir);
error("Requested directory does not exist.", "$CFG->wwwroot/files/index.php?id=$id");
}
2001-11-22 06:23:56 +00:00
switch ($action) {
case "upload":
html_header($course, $wdir);
require_once($CFG->dirroot.'/lib/uploadlib.php');
if ($save and confirm_sesskey()) {
2004-11-10 15:48:48 +00:00
$course->maxbytes = 0; // We are ignoring course limits
$um = new upload_manager('userfile',false,false,$course,false,0);
$dir = "$basedir$wdir";
if ($um->process_file_uploads($dir)) {
notify(get_string('uploadedfile'));
2001-11-22 06:23:56 +00:00
}
// um will take care of error reporting.
2001-11-22 06:23:56 +00:00
displaydir($wdir);
} else {
$upload_max_filesize = get_max_upload_file_size($CFG->maxbytes, $course->maxbytes);
$filesize = display_size($upload_max_filesize);
$struploadafile = get_string("uploadafile");
$struploadthisfile = get_string("uploadthisfile");
$strmaxsize = get_string("maxsize", "", $filesize);
$strcancel = get_string("cancel");
echo "<p>$struploadafile ($strmaxsize) --> <b>$wdir</b></p>";
2004-09-12 21:43:59 +00:00
echo "<table><tr><td colspan=\"2\">";
echo "<form enctype=\"multipart/form-data\" method=\"post\" action=\"index.php\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2004-11-10 15:48:48 +00:00
upload_print_form_fragment(1,array('userfile'),null,false,null,$upload_max_filesize,0,false);
echo " </td></tr><tr><td width=\"10\">";
2004-09-12 21:43:59 +00:00
echo " <input type=\"submit\" name=\"save\" value=\"$struploadthisfile\" />";
echo "</form>";
echo "</td><td width=\"100%\">";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"$strcancel\" />";
echo "</form>";
echo "</td></tr></table>";
2001-11-22 06:23:56 +00:00
}
html_footer();
break;
case "delete":
if ($confirm and confirm_sesskey()) {
html_header($course, $wdir);
if (!empty($USER->filelist)) {
foreach ($USER->filelist as $file) {
$fullfile = $basedir.'/'.$file;
if (! fulldelete($fullfile)) {
echo "<br />Error: Could not delete: $fullfile";
}
2001-11-22 06:23:56 +00:00
}
}
clearfilelist();
displaydir($wdir);
html_footer();
} else {
html_header($course, $wdir);
if (setfilelist($_POST)) {
notify(get_string('deletecheckwarning').':');
print_simple_box_start("center");
printfilelist($USER->filelist);
print_simple_box_end();
echo "<br />";
$resourcelist = false;
foreach ($USER->filelist as $file) {
// If file is specified in a resource, then delete that too.
$clean_name = substr($file, 1);
if (record_exists('resource', 'reference', $clean_name)) {
if (!$resourcelist) {
print_simple_box_start("center");
$resourcelist = true;
}
$resource_id = files_get_cm_from_resource_name($clean_name);
echo '<p>'.get_string('warningdeleteresource', '', $file)." <a href='$CFG->wwwroot/course/mod.php?update=$resource_id&sesskey=$USER->sesskey'>".get_string('update')."</a></p>";
}
}
if ($resourcelist) {
print_simple_box_end();
echo "<br />";
}
notice_yesno (get_string("deletecheckfiles"),
"index.php?id=$id&amp;wdir=$wdir&amp;action=delete&amp;confirm=1&amp;sesskey=$USER->sesskey&amp;choose=$choose",
"index.php?id=$id&amp;wdir=$wdir&amp;action=cancel&amp;choose=$choose");
2001-11-22 06:23:56 +00:00
} else {
displaydir($wdir);
}
html_footer();
}
break;
case "move":
html_header($course, $wdir);
if (($count = setfilelist($_POST)) and confirm_sesskey()) {
2001-11-22 06:23:56 +00:00
$USER->fileop = $action;
$USER->filesource = $wdir;
2004-09-12 21:43:59 +00:00
echo "<p align=\"center\">";
2003-08-05 03:25:16 +00:00
print_string("selectednowmove", "moodle", $count);
echo "</p>";
2001-11-22 06:23:56 +00:00
}
displaydir($wdir);
html_footer();
break;
case "paste":
html_header($course, $wdir);
if (isset($USER->fileop) and ($USER->fileop == "move") and confirm_sesskey()) {
2001-11-22 06:23:56 +00:00
foreach ($USER->filelist as $file) {
$shortfile = basename($file);
$oldfile = $basedir.'/'.$file;
2001-11-22 06:23:56 +00:00
$newfile = $basedir.$wdir."/".$shortfile;
if (!rename($oldfile, $newfile)) {
2004-09-12 21:43:59 +00:00
echo "<p>Error: $shortfile not moved";
2001-11-22 06:23:56 +00:00
}
}
}
clearfilelist();
displaydir($wdir);
html_footer();
break;
case "rename":
if (($name != '') and confirm_sesskey()) {
html_header($course, $wdir);
$name = clean_filename($name);
2001-11-22 06:23:56 +00:00
if (file_exists($basedir.$wdir."/".$name)) {
echo "<center>Error: $name already exists!</center>";
2001-11-22 06:23:56 +00:00
} else if (!rename($basedir.$wdir."/".$oldname, $basedir.$wdir."/".$name)) {
echo "<p align=\"center\">Error: could not rename $oldname to $name</p>";
}
//if file is part of resource then update resource table as well
//this line only catch the root directory
if (record_exists('resource', 'reference', $oldname)) {
set_field('resource', 'reference', $name, 'reference', $oldname);
}
if (get_dir_name_from_resource($oldname)) {
$resources = get_dir_name_from_resource($oldname);
print_simple_box_start("center");
echo "<b>The following files might be referenced as a resource :</b><br>";
foreach ($resources as $resource) {
$resource_id = files_get_cm_from_resource_name($name);
echo '<p align=\"center\">'. "$resource->reference :"."</align><a href='$CFG->wwwroot/course/mod.php?update=$resource_id&sesskey=$USER->sesskey'> ".get_string('update')."</a>";
}
print_simple_box_end();
2001-11-22 06:23:56 +00:00
}
displaydir($wdir);
2001-11-22 06:23:56 +00:00
} else {
$strrename = get_string("rename");
$strcancel = get_string("cancel");
$strrenamefileto = get_string("renamefileto", "moodle", $file);
html_header($course, $wdir, "form.name");
2004-09-12 21:43:59 +00:00
echo "<p>$strrenamefileto:";
echo "<table><tr><td>";
echo "<form action=\"index.php\" method=\"post\" name=\"form\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"rename\" />";
echo " <input type=\"hidden\" name=\"oldname\" value=\"$file\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"$file\" />";
echo " <input type=\"submit\" value=\"$strrename\" />";
echo "</form>";
echo "</td><td>";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"$strcancel\" />";
echo "</form>";
echo "</td></tr></table>";
2001-11-22 06:23:56 +00:00
}
html_footer();
break;
2005-08-14 02:27:18 +00:00
case "makedir":
if (($name != '') and confirm_sesskey()) {
html_header($course, $wdir);
2001-11-22 06:23:56 +00:00
$name = clean_filename($name);
if (file_exists("$basedir$wdir/$name")) {
2001-11-22 06:23:56 +00:00
echo "Error: $name already exists!";
} else if (! make_upload_directory("$course->id$wdir/$name")) {
2001-11-22 06:23:56 +00:00
echo "Error: could not create $name";
}
displaydir($wdir);
2001-11-22 06:23:56 +00:00
} else {
$strcreate = get_string("create");
$strcancel = get_string("cancel");
$strcreatefolder = get_string("createfolder", "moodle", $wdir);
html_header($course, $wdir, "form.name");
echo "<p>$strcreatefolder:</p>";
2004-09-12 21:43:59 +00:00
echo "<table><tr><td>";
echo "<form action=\"index.php\" method=\"post\" name=\"form\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
2005-08-14 02:27:18 +00:00
echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"text\" name=\"name\" size=\"35\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"submit\" value=\"$strcreate\" />";
echo "</form>";
echo "</td><td>";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"$strcancel\" />";
echo "</form>";
echo "</td></tr></table>";
2001-11-22 06:23:56 +00:00
}
html_footer();
break;
case "edit":
html_header($course, $wdir);
if (($text != '') and confirm_sesskey()) {
$fileptr = fopen($basedir.'/'.$file,"w");
2001-11-22 06:23:56 +00:00
fputs($fileptr, stripslashes($text));
fclose($fileptr);
displaydir($wdir);
2001-11-22 06:23:56 +00:00
} else {
2004-09-12 21:43:59 +00:00
$streditfile = get_string("edit", "", "<b>$file</b>");
$fileptr = fopen($basedir.'/'.$file, "r");
$contents = fread($fileptr, filesize($basedir.'/'.$file));
2001-11-22 06:23:56 +00:00
fclose($fileptr);
2002-12-26 16:26:55 +00:00
if (mimeinfo("type", $file) == "text/html") {
$usehtmleditor = can_use_html_editor();
2002-12-26 16:26:55 +00:00
} else {
$usehtmleditor = false;
}
2004-08-30 08:44:00 +00:00
$usehtmleditor = false; // Always keep it off for now
2002-12-26 16:26:55 +00:00
print_heading("$streditfile");
2004-09-12 21:43:59 +00:00
echo "<table><tr><td colspan=\"2\">";
echo "<form action=\"index.php\" method=\"post\" name=\"form\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"file\" value=\"$file\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"edit\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
print_textarea($usehtmleditor, 25, 80, 680, 400, "text", $contents);
2004-09-12 21:43:59 +00:00
echo "</td></tr><tr><td>";
echo " <input type=\"submit\" value=\"".get_string("savechanges")."\" />";
echo "</form>";
echo "</td><td>";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />";
echo "</form>";
echo "</td></tr></table>";
2002-12-26 16:26:55 +00:00
if ($usehtmleditor) {
use_html_editor();
2002-12-26 16:26:55 +00:00
}
2001-11-22 06:23:56 +00:00
}
html_footer();
break;
case "zip":
if (($name != '') and confirm_sesskey()) {
html_header($course, $wdir);
2001-11-22 06:23:56 +00:00
$name = clean_filename($name);
$files = array();
foreach ($USER->filelist as $file) {
$files[] = "$basedir/$file";
}
if (!zip_files($files,"$basedir$wdir/$name")) {
error(get_string("zipfileserror","error"));
2001-11-22 06:23:56 +00:00
}
2001-11-22 06:23:56 +00:00
clearfilelist();
displaydir($wdir);
2001-11-22 06:23:56 +00:00
} else {
html_header($course, $wdir, "form.name");
if (setfilelist($_POST)) {
2004-09-12 21:43:59 +00:00
echo "<p align=\"center\">".get_string("youareabouttocreatezip").":</p>";
2001-11-22 06:23:56 +00:00
print_simple_box_start("center");
printfilelist($USER->filelist);
print_simple_box_end();
2004-09-12 21:43:59 +00:00
echo "<br />";
echo "<p align=\"center\">".get_string("whattocallzip")."</p>";
2004-09-12 21:43:59 +00:00
echo "<table><tr><td>";
echo "<form action=\"index.php\" method=\"post\" name=\"form\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"zip\" />";
echo " <input type=\"text\" name=\"name\" size=\"35\" value=\"new.zip\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"submit\" value=\"".get_string("createziparchive")."\" />";
echo "</form>";
echo "</td><td>";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"".get_string("cancel")."\" />";
echo "</form>";
echo "</td></tr></table>";
2001-11-22 06:23:56 +00:00
} else {
displaydir($wdir);
clearfilelist();
}
}
html_footer();
break;
case "unzip":
html_header($course, $wdir);
if (($file != '') and confirm_sesskey()) {
$strok = get_string("ok");
$strunpacking = get_string("unpacking", "", $file);
2004-09-12 21:43:59 +00:00
echo "<p align=\"center\">$strunpacking:</p>";
2001-11-22 06:23:56 +00:00
$file = basename($file);
if (!unzip_file("$basedir$wdir/$file")) {
error(get_string("unzipfileserror","error"));
}
2004-09-12 21:43:59 +00:00
echo "<center><form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"$strok\" />";
echo "</form>";
echo "</center>";
2001-11-22 06:23:56 +00:00
} else {
displaydir($wdir);
}
html_footer();
break;
case "listzip":
html_header($course, $wdir);
if (($file != '') and confirm_sesskey()) {
$strname = get_string("name");
$strsize = get_string("size");
$strmodified = get_string("modified");
$strok = get_string("ok");
$strlistfiles = get_string("listfiles", "", $file);
2004-09-12 21:43:59 +00:00
echo "<p align=\"center\">$strlistfiles:</p>";
$file = basename($file);
include_once("$CFG->libdir/pclzip/pclzip.lib.php");
$archive = new PclZip(cleardoubleslashes("$basedir$wdir/$file"));
if (!$list = $archive->listContent(cleardoubleslashes("$basedir$wdir"))) {
notify($archive->errorInfo(true));
} else {
2005-03-13 17:16:26 +00:00
echo "<table cellpadding=\"4\" cellspacing=\"2\" border=\"0\" width=\"640\" class=\"files\">";
echo "<tr class=\"file\"><th align=\"left\" class=\"header name\">$strname</th><th align=\"right\" class=\"header size\">$strsize</th><th align=\"right\" class=\"header date\">$strmodified</th></tr>";
foreach ($list as $item) {
echo "<tr>";
2005-03-13 17:16:26 +00:00
print_cell("left", $item['filename'], 'name');
if (! $item['folder']) {
2005-03-13 17:16:26 +00:00
print_cell("right", display_size($item['size']), 'size');
} else {
echo "<td>&nbsp;</td>";
}
$filedate = userdate($item['mtime'], get_string("strftimedatetime"));
2005-03-13 17:16:26 +00:00
print_cell("right", $filedate, 'date');
echo "</tr>";
}
echo "</table>";
}
2004-09-12 21:43:59 +00:00
echo "<br /><center><form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"cancel\" />";
echo " <input type=\"submit\" value=\"$strok\" />";
echo "</form>";
echo "</center>";
} else {
displaydir($wdir);
}
html_footer();
break;
case "restore":
html_header($course, $wdir);
if (($file != '') and confirm_sesskey()) {
2004-09-12 21:43:59 +00:00
echo "<p align=\"center\">".get_string("youaregoingtorestorefrom").":</p>";
print_simple_box_start("center");
echo $file;
print_simple_box_end();
echo "<br />";
echo "<p align=\"center\">".get_string("areyousuretorestorethisinfo")."</p>";
$restore_path = "$CFG->wwwroot/backup/restore.php";
notice_yesno (get_string("areyousuretorestorethis"),
$restore_path."?id=".$id."&amp;file=".cleardoubleslashes($id.$wdir."/".$file)."&amp;method=manual",
"index.php?id=$id&amp;wdir=$wdir&amp;action=cancel");
} else {
displaydir($wdir);
}
html_footer();
break;
2005-03-12 21:17:15 +00:00
case "cancel":
2001-11-22 06:23:56 +00:00
clearfilelist();
default:
html_header($course, $wdir);
2001-11-22 06:23:56 +00:00
displaydir($wdir);
html_footer();
break;
}
/// FILE FUNCTIONS ///////////////////////////////////////////////////////////
function setfilelist($VARS) {
global $USER;
$USER->filelist = array ();
$USER->fileop = "";
$count = 0;
foreach ($VARS as $key => $val) {
if (substr($key,0,4) == "file") {
$count++;
$val = rawurldecode($val);
$USER->filelist[] = clean_param($val, PARAM_PATH);
2001-11-22 06:23:56 +00:00
}
}
return $count;
}
function clearfilelist() {
global $USER;
$USER->filelist = array ();
$USER->fileop = "";
}
function printfilelist($filelist) {
global $CFG, $basedir;
2001-11-22 06:23:56 +00:00
foreach ($filelist as $file) {
if (is_dir($basedir.'/'.$file)) {
echo "<img src=\"$CFG->pixpath/f/folder.gif\" height=\"16\" width=\"16\" alt=\"\" /> $file<br />";
2001-11-22 06:23:56 +00:00
$subfilelist = array();
$currdir = opendir($basedir.'/'.$file);
2005-03-12 06:23:22 +00:00
while (false !== ($subfile = readdir($currdir))) {
2001-11-22 06:23:56 +00:00
if ($subfile <> ".." && $subfile <> ".") {
$subfilelist[] = $file."/".$subfile;
}
}
printfilelist($subfilelist);
} else {
2001-11-22 06:23:56 +00:00
$icon = mimeinfo("icon", $file);
echo "<img src=\"$CFG->pixpath/f/$icon\" height=\"16\" width=\"16\" alt=\"\" /> $file<br />";
2001-11-22 06:23:56 +00:00
}
}
}
2005-03-13 17:16:26 +00:00
function print_cell($alignment='center', $text='&nbsp;', $class='') {
if ($class) {
$class = ' class="'.$class.'"';
}
echo '<td align="'.$alignment.'" nowrap="nowrap"'.$class.'>'.$text.'</td>';
2001-11-22 06:23:56 +00:00
}
function displaydir ($wdir) {
// $wdir == / or /a or /a/b/c/d etc
global $basedir;
global $id;
global $USER, $CFG;
2004-11-02 12:45:04 +00:00
global $choose;
2001-11-22 06:23:56 +00:00
$fullpath = $basedir.$wdir;
$dirlist = array();
2001-11-22 06:23:56 +00:00
$directory = opendir($fullpath); // Find all files
2005-03-10 06:04:29 +00:00
while (false !== ($file = readdir($directory))) {
if ($file == "." || $file == "..") {
2001-11-22 06:23:56 +00:00
continue;
}
2001-11-22 06:23:56 +00:00
if (is_dir($fullpath."/".$file)) {
$dirlist[] = $file;
} else {
$filelist[] = $file;
}
}
closedir($directory);
$strname = get_string("name");
$strsize = get_string("size");
$strmodified = get_string("modified");
$straction = get_string("action");
$strmakeafolder = get_string("makeafolder");
$struploadafile = get_string("uploadafile");
$strselectall = get_string("selectall");
$strselectnone = get_string("deselectall");
$strwithchosenfiles = get_string("withchosenfiles");
$strmovetoanotherfolder = get_string("movetoanotherfolder");
$strmovefilestohere = get_string("movefilestohere");
$strdeletecompletely = get_string("deletecompletely");
$strcreateziparchive = get_string("createziparchive");
$strrename = get_string("rename");
$stredit = get_string("edit");
$strunzip = get_string("unzip");
$strlist = get_string("list");
$strrestore= get_string("restore");
2004-11-02 12:45:04 +00:00
$strchoose = get_string("choose");
2001-11-22 06:23:56 +00:00
2004-09-12 21:43:59 +00:00
echo "<form action=\"index.php\" method=\"post\" name=\"dirform\">";
echo '<input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\" class=\"files\">";
2004-09-12 21:43:59 +00:00
echo "<tr>";
echo "<th width=\"5\"></th>";
2005-03-13 17:16:26 +00:00
echo "<th align=\"left\" class=\"header name\">$strname</th>";
echo "<th align=\"right\" class=\"header size\">$strsize</th>";
echo "<th align=\"right\" class=\"header date\">$strmodified</th>";
echo "<th align=\"right\" class=\"header commands\">$straction</th>";
2004-09-12 21:43:59 +00:00
echo "</tr>\n";
2001-11-22 06:23:56 +00:00
if ($wdir != "/") {
$dirlist[] = '..';
}
2001-11-22 06:23:56 +00:00
$count = 0;
2003-01-02 13:08:20 +00:00
if (!empty($dirlist)) {
2001-11-22 06:23:56 +00:00
asort($dirlist);
foreach ($dirlist as $dir) {
2005-03-13 17:16:26 +00:00
echo "<tr class=\"folder\">";
2001-11-22 06:23:56 +00:00
2005-03-13 17:16:26 +00:00
if ($dir == '..') {
$fileurl = rawurlencode(dirname($wdir));
print_cell();
print_cell('left', '<a href="index.php?id='.$id.'&amp;wdir='.$fileurl.'&amp;choose='.$choose.'"><img src="'.$CFG->pixpath.'/f/parent.gif" height="16" width="16" alt="'.get_string('parentfolder').'" /></a> <a href="index.php?id='.$id.'&amp;wdir='.$fileurl.'&amp;choose='.$choose.'">'.get_string('parentfolder').'</a>', 'name');
print_cell();
print_cell();
print_cell();
2005-03-13 17:16:26 +00:00
} else {
$count++;
$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");
2005-03-13 17:16:26 +00:00
print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox');
print_cell("left", "<a href=\"index.php?id=$id&amp;wdir=$fileurl&amp;choose=$choose\"><img src=\"$CFG->pixpath/f/folder.gif\" height=\"16\" width=\"16\" border=\"0\" alt=\"Folder\" /></a> <a href=\"index.php?id=$id&amp;wdir=$fileurl&amp;choose=$choose\">".htmlspecialchars($dir)."</a>", 'name');
print_cell("right", $filesize, 'size');
print_cell("right", $filedate, 'date');
print_cell("right", "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=rename&amp;choose=$choose\">$strrename</a>", 'commands');
}
2004-09-12 21:43:59 +00:00
echo "</tr>";
2001-11-22 06:23:56 +00:00
}
}
2003-01-02 13:08:20 +00:00
if (!empty($filelist)) {
2001-11-22 06:23:56 +00:00
asort($filelist);
foreach ($filelist as $file) {
$icon = mimeinfo("icon", $file);
$count++;
$filename = $fullpath."/".$file;
$fileurl = trim($wdir, "/")."/$file";
2001-11-22 06:23:56 +00:00
$filesafe = rawurlencode($file);
$fileurlsafe = rawurlencode($fileurl);
2003-12-08 13:31:14 +00:00
$filedate = userdate(filemtime($filename), "%d %b %Y, %I:%M %p");
2001-11-22 06:23:56 +00:00
$selectfile = trim($fileurl, "/");
2004-11-02 12:45:04 +00:00
2005-03-13 17:16:26 +00:00
echo "<tr class=\"file\">";
2001-11-22 06:23:56 +00:00
2005-03-13 17:16:26 +00:00
print_cell("center", "<input type=\"checkbox\" name=\"file$count\" value=\"$fileurl\" />", 'checkbox');
echo "<td align=\"left\" nowrap=\"nowrap\" class=\"name\">";
if ($CFG->slasharguments) {
$ffurl = str_replace('//', '/', "/file.php/$id/$fileurl");
} else {
$ffurl = str_replace('//', '/', "/file.php?file=/$id/$fileurl");
}
link_to_popup_window ($ffurl, "display",
"<img src=\"$CFG->pixpath/f/$icon\" height=\"16\" width=\"16\" border=\"0\" alt=\"File\" />",
2001-11-22 06:23:56 +00:00
480, 640);
2005-03-13 17:16:26 +00:00
echo '&nbsp;';
link_to_popup_window ($ffurl, "display",
2001-11-22 06:23:56 +00:00
htmlspecialchars($file),
480, 640);
2005-03-13 17:16:26 +00:00
echo "</td>";
2001-11-22 06:23:56 +00:00
$file_size = filesize($filename);
2005-03-13 17:16:26 +00:00
print_cell("right", display_size($file_size), 'size');
print_cell("right", $filedate, 'date');
2004-11-02 12:45:04 +00:00
if ($choose) {
2005-08-01 16:52:05 +00:00
$edittext = "<strong><a onclick=\"return set_value('$selectfile')\" href=\"#\">$strchoose</a></strong>&nbsp;";
2004-11-02 12:45:04 +00:00
} else {
$edittext = '';
}
2001-11-22 06:23:56 +00:00
if ($icon == "text.gif" || $icon == "html.gif") {
2004-11-02 12:45:04 +00:00
$edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=edit&amp;choose=$choose\">$stredit</a>";
2001-11-22 06:23:56 +00:00
} else if ($icon == "zip.gif") {
2004-11-02 12:45:04 +00:00
$edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=unzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strunzip</a>&nbsp;";
$edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$fileurl&amp;action=listzip&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strlist</a> ";
if (!empty($CFG->backup_version) and isteacheredit($id)) {
2004-11-02 12:45:04 +00:00
$edittext .= "<a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=restore&amp;sesskey=$USER->sesskey&amp;choose=$choose\">$strrestore</a> ";
}
2001-11-22 06:23:56 +00:00
}
2004-11-02 12:45:04 +00:00
2005-03-13 17:16:26 +00:00
print_cell("right", "$edittext <a href=\"index.php?id=$id&amp;wdir=$wdir&amp;file=$filesafe&amp;action=rename&amp;choose=$choose\">$strrename</a>", 'commands');
2004-09-12 21:43:59 +00:00
echo "</tr>";
2001-11-22 06:23:56 +00:00
}
}
2004-09-12 21:43:59 +00:00
echo "</table>";
echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
2001-11-22 06:23:56 +00:00
echo "<table border=\"0\" cellspacing=\"2\" cellpadding=\"2\" width=\"640\">";
2004-09-12 21:43:59 +00:00
echo "<tr><td>";
echo "<input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo '<input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo "<input type=\"hidden\" name=\"wdir\" value=\"$wdir\" /> ";
echo "<input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2001-11-22 06:23:56 +00:00
$options = array (
"move" => "$strmovetoanotherfolder",
"delete" => "$strdeletecompletely",
"zip" => "$strcreateziparchive"
2001-11-22 06:23:56 +00:00
);
2003-01-02 13:08:20 +00:00
if (!empty($count)) {
choose_from_menu ($options, "action", "", "$strwithchosenfiles...", "javascript:document.dirform.submit()");
2001-11-22 06:23:56 +00:00
}
2004-09-12 21:43:59 +00:00
echo "</form>";
echo "<td align=\"center\">";
if (!empty($USER->fileop) and ($USER->fileop == "move") and ($USER->filesource <> $wdir)) {
2004-09-12 21:43:59 +00:00
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"paste\" />";
echo " <input type=\"hidden\" name=\"sesskey\" value=\"$USER->sesskey\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"submit\" value=\"$strmovefilestohere\" />";
echo "</form>";
2001-11-22 06:23:56 +00:00
}
echo "</td>";
2004-09-12 21:43:59 +00:00
echo "<td align=\"right\">";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
2005-08-14 02:27:18 +00:00
echo " <input type=\"hidden\" name=\"action\" value=\"makedir\" />";
2004-09-12 21:43:59 +00:00
echo " <input type=\"submit\" value=\"$strmakeafolder\" />";
echo "</form>";
echo "</td>";
echo "<td align=\"right\">";
echo "<form action=\"index.php\" method=\"get\">"; //dummy form - alignment only
echo " <input type=\"button\" value=\"$strselectall\" onclick=\"checkall();\" />";
echo " <input type=\"button\" value=\"$strselectnone\" onclick=\"uncheckall();\" />";
echo "</form>";
echo "</td>";
2004-09-12 21:43:59 +00:00
echo "<td align=\"right\">";
echo "<form action=\"index.php\" method=\"get\">";
echo ' <input type="hidden" name="choose" value="'.$choose.'" />';
2004-09-12 21:43:59 +00:00
echo " <input type=\"hidden\" name=\"id\" value=\"$id\" />";
echo " <input type=\"hidden\" name=\"wdir\" value=\"$wdir\" />";
echo " <input type=\"hidden\" name=\"action\" value=\"upload\" />";
echo " <input type=\"submit\" value=\"$struploadafile\" />";
echo "</form>";
echo "</td></tr>";
echo "</table>";
echo "<hr width=\"640\" align=\"center\" noshade=\"noshade\" size=\"1\" />";
2001-11-22 06:23:56 +00:00
}
function files_get_cm_from_resource_name($clean_name) {
global $CFG;
$SQL = 'SELECT a.id FROM '.$CFG->prefix.'course_modules a, '.$CFG->prefix.'resource b
WHERE a.instance = b.id AND b.reference = "'.$clean_name.'"';
$resource = get_record_sql($SQL);
return $resource->id;
}
function get_dir_name_from_resource($clean_name) {
global $CFG;
$LIKE = sql_ilike();
$SQL = 'SELECT * FROM '.$CFG->prefix.'resource WHERE reference '.$LIKE. "\"%$clean_name%\"";
$resource = get_records_sql($SQL);
return $resource;
}
2001-11-22 06:23:56 +00:00
?>