diff --git a/lang/en/repository.php b/lang/en/repository.php
index b7fe4b0934683..babe63652e061 100644
--- a/lang/en/repository.php
+++ b/lang/en/repository.php
@@ -47,6 +47,7 @@
$string['attachment'] = 'Attachment';
$string['author'] = 'Author';
$string['back'] = '« Back';
+$string['backtodraftfiles'] = '« Back to draft files manager';
$string['cachecleared'] = 'Cached files are removed';
$string['cacheexpire'] = 'Cache expire';
$string['cannotaccessparentwin'] = 'If parent window is on HTTPS, then we are not allowed to access window.opener object, so we cannot refresh the repository for you automatically, but we already got your session, just go back to file picker and select the repository again, it should work now.';
@@ -165,7 +166,9 @@
$string['uploading'] = 'Uploading...';
$string['uploadsucc'] = 'The file has been uploaded successfully';
$string['usercontextrepositorydisabled'] = 'You cannot edit this repository in user context';
-$string['usenonjsfilemanager'] = 'Use non javascript file manager';
+$string['usenonjsfilemanager'] = 'Open file manager in new window';
+$string['usenonjsfilepicker'] = 'Open file picker in new window';
+$string['unzipped'] = 'Unzipped successfully';
$string['wrongcontext'] = 'You cannot access to this context';
$string['xhtmlerror'] = 'You are probably using XHTML strict header, some YUI Component doesn\'t work in this mode, please turn it off in moodle';
$string['ziped'] = 'Compress folder successfully';
diff --git a/lib/form/editor.php b/lib/form/editor.php
index 7ffa2dd03607a..5efa5af49633b 100644
--- a/lib/form/editor.php
+++ b/lib/form/editor.php
@@ -222,20 +222,22 @@ function toHtml() {
if (!during_initial_install() && empty($CFG->adminsetuppending)) {
// 0 means no files, -1 unlimited
if ($maxfiles != 0 ) {
- $str .= '
';
- $str .= '';
- $editorurl = new moodle_url("$CFG->wwwroot/repository/filepicker.php", array(
+ $str .= ' ';
+
+ // used by non js editor only
+ $editorurl = new moodle_url("$CFG->wwwroot/repository/draftfiles_manager.php", array(
'action'=>'browse',
'env'=>'editor',
'itemid'=>$draftitemid,
'subdirs'=>$subdirs,
'maxbytes'=>$maxbytes,
+ 'maxfiles'=>$maxfiles,
'ctx_id'=>$ctx->id,
'course'=>$PAGE->course->id
));
- $str .= html_writer::link($editorurl->out(false), get_string('manageeditorfiles'), array('target'=>'_blank'));
- //$str .= 'Error ';
- $str .= '
';
+ $str .= '';
+ $str .= " ";
+ $str .= ' ';
}
}
diff --git a/lib/form/filemanager.php b/lib/form/filemanager.php
index 184ff1a1f598f..b89d903f1f6aa 100644
--- a/lib/form/filemanager.php
+++ b/lib/form/filemanager.php
@@ -245,9 +245,7 @@ function form_filemanager_render($options) {
static $filemanagertemplateloaded;
$html = '';
- $nonjsfilemanager = optional_param('usenonjsfilemanager', 0, PARAM_INT);
$options = $fm->options;
- $options->usenonjs = $nonjsfilemanager;
$straddfile = get_string('add', 'repository') . '...';
$strmakedir = get_string('makeafolder', 'moodle');
$strdownload = get_string('downloadfolder', 'repository');
@@ -293,16 +291,6 @@ function form_filemanager_render($options) {
FMHTML;
}
- $filemanagerurl = new moodle_url('/repository/filepicker.php', array(
- 'env'=>'filemanager',
- 'action'=>'embedded',
- 'itemid'=>$itemid,
- 'subdirs'=>'/',
- 'maxbytes'=>$options->maxbytes,
- 'ctx_id'=>$PAGE->context->id,
- 'course'=>$PAGE->course->id,
- ));
-
$module = array(
'name'=>'form_filemanager',
'fullpath'=>'/lib/form/filemanager.js',
@@ -321,18 +309,20 @@ function form_filemanager_render($options) {
$PAGE->requires->js_init_call('M.form_filemanager.init', array($options), true, $module);
// non javascript file manager
- if (!empty($nonjsfilemanager)) {
- $html = '';
- $html .= <<Error
-NONJS;
- $html .= '
';
- } else {
- $url = new moodle_url($PAGE->url, array('usenonjsfilemanager'=>1));
- $html .= '';
- $html .= html_writer::link($url, get_string('usenonjsfilemanager', 'repository'));
- $html .= '
';
- }
+ $filemanagerurl = new moodle_url('/repository/draftfiles_manager.php', array(
+ 'env'=>'filemanager',
+ 'action'=>'browse',
+ 'itemid'=>$itemid,
+ 'subdirs'=>$options->subdirs,
+ 'maxbytes'=>$options->maxbytes,
+ 'maxfiles'=>$options->maxfiles,
+ 'ctx_id'=>$PAGE->context->id,
+ 'course'=>$PAGE->course->id,
+ ));
+
+ $html .= '';
+ $html .= " ";
+ $html .= ' ';
return $html;
diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php
index 2d04fad8b5a04..b8ca6ffe2e924 100644
--- a/lib/form/filepicker.php
+++ b/lib/form/filepicker.php
@@ -87,6 +87,22 @@ function toHtml() {
$module = array('name'=>'form_filepicker', 'fullpath'=>'/lib/form/filepicker.js', 'requires'=>array('core_filepicker'));
$PAGE->requires->js_init_call('M.form_filepicker.init', array($fp->options), true, $module);
+ $nonjsfilepicker = new moodle_url('/repository/draftfiles_manager.php', array(
+ 'env'=>'filepicker',
+ 'action'=>'browse',
+ 'itemid'=>$draftitemid,
+ 'subdirs'=>0,
+ 'maxbytes'=>$options->maxbytes,
+ 'maxfiles'=>1,
+ 'ctx_id'=>$PAGE->context->id,
+ 'course'=>$PAGE->course->id,
+ ));
+
+ // non js file picker
+ $html .= '';
+ $html .= " ";
+ $html .= ' ';
+
return $html;
}
diff --git a/repository/draftfiles_manager.php b/repository/draftfiles_manager.php
new file mode 100755
index 0000000000000..3b8f7f8db2826
--- /dev/null
+++ b/repository/draftfiles_manager.php
@@ -0,0 +1,384 @@
+.
+//
+
+
+//
+// NOTE TO ALL DEVELOPERS: this script must deal only with draft area of current user, it has to use only file_storage and no file_browser!!
+//
+
+
+/**
+ * This file is used to manage draft files in non-javascript browsers
+ *
+ * @since 2.0
+ * @package moodlecore
+ * @subpackage repository
+ * @copyright 2010 Dongsheng Cai
+ * @license http://www.gnu.org/copyleft/gpl.html GNU GPL v3 or later
+ */
+
+require_once('../config.php');
+require_once($CFG->libdir.'/filelib.php');
+require_once('lib.php');
+
+require_login();
+
+// disable blocks in this page
+$PAGE->set_pagelayout('embedded');
+
+// general parameters
+$action = optional_param('action', '', PARAM_ALPHA);
+$itemid = optional_param('itemid', '', PARAM_INT);
+
+// parameters for repository
+$contextid = optional_param('ctx_id', SYSCONTEXTID, PARAM_INT); // context ID
+$courseid = optional_param('course', SITEID, PARAM_INT); // course ID
+$env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in file picker, file manager or html editor
+$filename = optional_param('filename', '', PARAM_FILE);
+$targetpath = optional_param('targetpath', '', PARAM_PATH);
+$maxfiles = optional_param('maxfiles', -1, PARAM_INT); // maxfiles
+$maxbytes = optional_param('maxbytes', 0, PARAM_INT); // maxbytes
+$subdirs = optional_param('subdirs', 0, PARAM_INT); // maxbytes
+
+// draft area
+$newdirname = optional_param('newdirname', '', PARAM_FILE);
+$newfilename = optional_param('newfilename', '', PARAM_FILE);
+// path in draft area
+$draftpath = optional_param('draftpath', '/', PARAM_PATH);
+
+// user context
+$user_context = get_context_instance(CONTEXT_USER, $USER->id);
+
+
+$PAGE->set_context($user_context);
+
+$fs = get_file_storage();
+
+$params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs);
+$PAGE->set_url('/repository/draftfiles_manager.php', $params);
+$filepicker_url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", $params);
+
+$params['action'] = 'browse';
+$home_url = new moodle_url('/repository/draftfiles_manager.php', $params);
+
+switch ($action) {
+
+ // delete draft files
+case 'deletedraft':
+ if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
+ if ($file->is_directory()) {
+ $pathname = $draftpath;
+ if ($file->get_parent_directory()) {
+ $draftpath = $file->get_parent_directory()->get_filepath();
+ } else {
+ $draftpath = '/';
+ }
+
+ // delete files in folder
+ $files = $fs->get_directory_files($user_context->id, 'user', 'draft', $itemid, $pathname, true);
+ foreach ($files as $storedfile) {
+ $storedfile->delete();
+ }
+ $file->delete();
+ } else {
+ $file->delete();
+ }
+ $home_url->param('draftpath', $draftpath);
+ $home_url->param('action', 'browse');
+ redirect($home_url);
+ }
+ break;
+
+case 'renameform':
+ echo $OUTPUT->header();
+ echo '";
+ $home_url->param('draftpath', $draftpath);
+ $home_url->param('action', 'rename');
+ echo ' ';
+ echo $OUTPUT->footer();
+ break;
+
+case 'rename':
+
+ if ($fs->file_exists($user_context->id, 'user', 'draft', $itemid, $draftpath, $newfilename)) {
+ print_error('fileexists');
+ } else if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
+ $newfile = $fs->create_file_from_storedfile(array('filename'=>$newfilename), $file);
+ $file->delete();
+ }
+
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', $draftpath);
+ redirect($home_url);
+ break;
+
+case 'downloaddir':
+ $zipper = new zip_packer();
+
+ $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
+ if ($file->get_parent_directory()) {
+ $parent_path = $file->get_parent_directory()->get_filepath();
+ $filename = trim($draftpath, '/').'.zip';
+ } else {
+ $parent_path = '/';
+ $filename = get_string('files').'.zip';
+ }
+
+ if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id)) {
+ $fileurl = moodle_url::make_draftfile_url($itemid, '/', $filename)->out();
+ header('Location: ' . $fileurl );
+ } else {
+ print_error('cannotdownloaddir', 'repository');
+ }
+ break;
+
+case 'zip':
+ $zipper = new zip_packer();
+
+ $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
+ if (!$file->get_parent_directory()) {
+ $parent_path = '/';
+ $filename = get_string('files').'.zip';
+ } else {
+ $parent_path = $file->get_parent_directory()->get_filepath();
+ $filepath = explode('/', trim($file->get_filepath(), '/'));
+ $filename = array_pop($filepath).'.zip';
+ }
+
+ $newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $filename, $USER->id);
+
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', $parent_path);
+ redirect($home_url, get_string('ziped', 'repository'));
+ break;
+
+case 'unzip':
+ $zipper = new zip_packer();
+ $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename);
+
+ if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $itemid, $draftpath, $USER->id)) {
+ $str = get_string('unzipped', 'repository');
+ } else {
+ $str = get_string('cannotunzip', 'error');
+ }
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', $draftpath);
+ redirect($home_url, $str);
+ break;
+
+case 'movefile':
+ if (!empty($targetpath)) {
+ if ($fs->file_exists($user_context->id, 'user', 'draft', $itemid, $targetpath, $filename)) {
+ print_error('cannotmovefile');
+ } else if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
+ $newfile = $fs->create_file_from_storedfile(array('filepath'=>$targetpath), $file);
+ $file->delete();
+ } else {
+ var_dump('cannot find file');
+ die;
+ }
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', $targetpath);
+ redirect($home_url);
+ }
+ echo $OUTPUT->header();
+ echo '";
+ $data = new stdclass;
+ $home_url->param('action', 'movefile');
+ $home_url->param('draftpath', $draftpath);
+ $home_url->param('filename', $filename);
+ file_get_drafarea_folders($itemid, '/', $data);
+ print_draft_area_tree($data, true, $home_url);
+ echo $OUTPUT->footer();
+ break;
+
+case 'mkdirform':
+ echo $OUTPUT->header();
+ echo '";
+ $home_url->param('draftpath', $draftpath);
+ $home_url->param('action', 'mkdir');
+ echo ' ';
+ echo $OUTPUT->footer();
+ break;
+
+case 'mkdir':
+
+ $newfolderpath = $draftpath . trim($newdirname, '/') . '/';
+ $fs->create_directory($user_context->id, 'user', 'draft', $itemid, $newfolderpath);
+ $home_url->param('action', 'browse');
+ if (!empty($newdirname)) {
+ $home_url->param('draftpath', $newfolderpath);
+ $str = get_string('createfoldersuccess', 'repository');
+ } else {
+ $home_url->param('draftpath', $draftpath);
+ $str = get_string('createfolderfail', 'repository');
+ }
+ redirect($home_url, $str);
+ break;
+
+case 'browse':
+default:
+ $files = file_get_drafarea_files($itemid, $draftpath);
+ $info = file_get_draft_area_info($itemid);
+ $filecount = $info['filecount'];
+
+ echo $OUTPUT->header();
+ if ((!empty($files) or $draftpath != '/') and $env == 'filemanager') {
+ echo '';
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', '/');
+ echo '
' . get_string('files') . ' ▶';
+ $trail = '';
+ if ($draftpath !== '/') {
+ $path = '/' . trim($draftpath, '/') . '/';
+ $parts = explode('/', $path);
+ foreach ($parts as $part) {
+ if (!empty($part)) {
+ $trail .= ('/'.$part.'/');
+ $data->path[] = array('name'=>$part, 'path'=>$trail);
+ $home_url->param('draftpath', $trail);
+ echo '
'.$part.' ▶ ';
+ }
+ }
+ }
+ echo '
';
+ }
+
+ $filepicker_url->param('draftpath', $draftpath);
+ $filepicker_url->param('savepath', $draftpath);
+ $filepicker_url->param('action', 'plugins');
+ echo '';
+
+ if (!empty($files->list)) {
+ echo '';
+ foreach ($files->list as $file) {
+ if ($file->type != 'folder') {
+ $drafturl = $file->url;
+ // a file
+ $fileicon = $CFG->wwwroot.'/pix/'.(file_extension_icon($file->filename));
+ $type = str_replace('.gif', '', mimeinfo('icon', $file->filename));
+ echo '';
+ echo ' ';
+ echo ' '.$file->filename.' ';
+
+ $home_url->param('filename', $file->filename);
+ $home_url->param('draftpath', $file->filepath);
+
+ $home_url->param('action', 'deletedraft');
+ echo ' ['.get_string('delete').' ]';
+
+ $home_url->param('action', 'movefile');
+ echo ' ['.get_string('move').' ]';
+
+ $home_url->param('action', 'renameform');
+ echo ' ['.get_string('rename').' ]';
+
+ if ($type == 'zip') {
+ $home_url->param('action', 'unzip');
+ $home_url->param('draftpath', $file->filepath);
+ echo ' ['.get_string('unzip').' ]';
+ }
+
+ echo ' ';
+ } else {
+ // a folder
+ echo '';
+ echo ' ';
+
+ $home_url->param('action', 'browse');
+ $home_url->param('draftpath', $file->filepath);
+ $foldername = trim(array_pop(explode('/', trim($file->filepath, '/'))), '/');
+ echo ' '.$foldername.' ';
+
+ $home_url->param('draftpath', $file->filepath);
+ $home_url->param('filename', $file->filename);
+ $home_url->param('action', 'deletedraft');
+ echo ' ['.get_string('delete').' ]';
+
+ $home_url->param('action', 'zip');
+ echo ' [Zip ]';
+ echo ' ';
+ }
+ }
+ echo ' ';
+ } else {
+ echo get_string('nofilesavailable', 'repository');
+ }
+ echo $OUTPUT->footer();
+ break;
+}
+
+function print_draft_area_tree($tree, $root, $url) {
+ echo '';
+ if ($root) {
+ $url->param('targetpath', '/');
+ if ($url->param('draftpath') == '/') {
+ echo ''.get_string('files').' ';
+ } else {
+ echo ''.get_string('files').' ';
+ }
+ echo '';
+ if (isset($tree->children)) {
+ $tree = $tree->children;
+ }
+ }
+
+ if (!empty($tree)) {
+ foreach ($tree as $node) {
+ echo '';
+ $url->param('targetpath', $node->filepath);
+ if ($url->param('draftpath') != $node->filepath) {
+ echo ''.$node->fullname.' ';
+ } else {
+ echo $node->fullname;
+ }
+ echo ' ';
+ if (!empty($node->children)) {
+ print_draft_area_tree($node->children, false, $url);
+ }
+ }
+ }
+ if ($root) {
+ echo ' ';
+ }
+ echo ' ';
+}
diff --git a/repository/filepicker.php b/repository/filepicker.php
index 642ad3138eb6c..7d058911e7a82 100755
--- a/repository/filepicker.php
+++ b/repository/filepicker.php
@@ -32,8 +32,6 @@
/// Wait as long as it takes for this script to finish
set_time_limit(0);
-debugging('TODO: needs to be converted to use new component and security rules', DEBUG_DEVELOPER);
-
require_login();
// disable blocks in this page
@@ -57,25 +55,26 @@
$req_path = optional_param('p', '', PARAM_RAW); // the path in repository
$curr_page = optional_param('page', '', PARAM_RAW); // What page in repository?
$search_text = optional_param('s', '', PARAM_CLEANHTML);
+$maxfiles = optional_param('maxfiles', -1, PARAM_INT); // maxfiles
+$maxbytes = optional_param('maxbytes', 0, PARAM_INT); // maxbytes
+$subdirs = optional_param('subdirs', 0, PARAM_INT); // maxbytes
-// draft area
-$newdirname = optional_param('newdirname', '', PARAM_FILE);
-$newfilename = optional_param('newfilename', '', PARAM_FILE);
+// the path to save files
+$savepath = optional_param('savepath', '/', PARAM_PATH);
// path in draft area
-$draftpath = optional_param('draftpath', '/', PARAM_PATH);
+$draftpath = optional_param('draftpath', '/', PARAM_PATH);
// user context
-$user_context = get_context_instance(CONTEXT_USER, $USER->id);
+$user_context = get_context_instance(CONTEXT_USER, $USER->id);
-$PAGE->set_url('/repository/filepicker.php');
+$PAGE->set_context($user_context);
if (!$course = $DB->get_record('course', array('id'=>$courseid))) {
print_error('invalidcourseid');
}
$PAGE->set_course($course);
// init repository plugin
-//
$sql = 'SELECT i.name, i.typeid, r.type FROM {repository} r, {repository_instances} i '.
'WHERE i.id=? AND i.typeid=r.id';
if ($repository = $DB->get_record_sql($sql, array($repo_id))) {
@@ -84,7 +83,7 @@
require_once($CFG->dirroot.'/repository/'.$type.'/lib.php');
$classname = 'repository_' . $type;
try {
- $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name));
+ $repo = new $classname($repo_id, $contextid, array('ajax'=>false, 'name'=>$repository->name, 'type'=>$type));
} catch (repository_exception $e){
print_error('pluginerror', 'repository');
}
@@ -93,36 +92,21 @@
}
}
-$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid));
-$home_url = new moodle_url($url, array('action' => 'browse'));
+$params = array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env, 'course'=>$courseid, 'maxbytes'=>$maxbytes, 'maxfiles'=>$maxfiles, 'subdirs'=>$subdirs);
+$params['action'] = 'browse';
+$params['draftpath'] = $draftpath;
+$home_url = new moodle_url('/repository/draftfiles_manager.php', $params);
+
+$params['savepath'] = $savepath;
+$url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", $params);
+$PAGE->set_url('/repository/filepicker.php', $params);
switch ($action) {
case 'upload':
// The uploaded file has been processed in plugin construct function
// redirect to default page
$repo->upload();
- redirect($url, get_string('uploadsucc','repository'));
- break;
-
-case 'deletedraft':
- $contextid = $user_context->id;
- $fs = get_file_storage();
- if ($file = $fs->get_file($contextid, 'user', 'draft', $itemid, $draftpath, $filename)) {
- if ($file->is_directory()) {
- if ($file->get_parent_directory()) {
- $draftpath = $file->get_parent_directory()->get_filepath();
- } else {
- $draftpath = '/';
- }
- }
- if($result = $file->delete()) {
- $url->param('draftpath', $draftpath);
- $url->param('action', 'browse');
- redirect($url);
- } else {
- print_error('cannotdelete', 'repository');
- }
- }
+ redirect($home_url, get_string('uploadsucc','repository'));
break;
case 'search':
@@ -167,7 +151,7 @@
case 'list':
case 'sign':
echo $OUTPUT->header();
- echo '";
+ echo '";
if ($repo->check_login()) {
$list = $repo->get_listing($req_path, $curr_page);
$dynload = !empty($list['dynload'])?true:false;
@@ -177,6 +161,7 @@
echo ' ';
echo ' ';
echo ' ';
+ echo ' ';
echo ' ';
echo ' ';
echo '';
@@ -187,6 +172,7 @@
echo ' ';
+ echo ' ';
echo ' ';
echo '';
echo ' / ';
@@ -214,6 +200,7 @@
echo ' ';
echo ' ';
echo ' ';
+ echo ' ';
echo ' ';
echo ' ';
echo ' ';
@@ -241,9 +228,13 @@
case 'download':
$thefile = $repo->get_file($fileurl, $filename, $itemid);
+ $filesize = filesize($thefile['path']);
+ if (($maxbytes!=-1) && ($filesize>$maxbytes)) {
+ print_error('maxbytes');
+ }
if (!empty($thefile)) {
$record = new stdclass;
- $record->filepath = $draftpath;
+ $record->filepath = $savepath;
$record->filename = $filename;
$record->component = 'user';
$record->filearea = 'draft';
@@ -252,34 +243,13 @@
$record->author = '';
$record->source = $thefile['url'];
$info = repository::move_to_filepool($thefile['path'], $record);
- redirect($url, get_string('downloadsucc','repository'));
+ redirect($home_url, get_string('downloadsucc','repository'));
} else {
print_error('cannotdownload', 'repository');
}
break;
-case 'downloaddir':
- $zipper = new zip_packer();
- $fs = get_file_storage();
-
- $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
- if ($file->get_parent_directory()) {
- $parent_path = $file->get_parent_directory()->get_filepath();
- $filename = trim($draftpath, '/').'.zip';
- } else {
- $parent_path = '/';
- $filename = get_string('files').'.zip';
- }
-
- if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user_draft', $itemid, $parent_path, $filename, $USER->id)) {
- $fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$itemid.$parent_path.$filename;
- header('Location: ' . $fileurl );
- } else {
- print_error('cannotdownloaddir', 'repository');
- }
- break;
-
case 'confirm':
echo $OUTPUT->header();
echo '';
@@ -297,33 +267,33 @@
echo '';
// the save path
echo ' ';
+ echo ' ';
echo ' ';
echo '
';
echo '';
echo $OUTPUT->footer();
break;
+default:
case 'plugins':
- $user_context = get_context_instance(CONTEXT_USER, $USER->id);
$params = array();
$params['context'] = array($user_context, get_system_context());
$params['currentcontext'] = $PAGE->context;
- $params['returntypes'] = 2;
+ $params['return_types'] = FILE_INTERNAL;
+
$repos = repository::get_instances($params);
echo $OUTPUT->header();
- echo '";
+ echo html_writer::link($home_url->out(false), get_string('backtodraftfiles', 'repository'));
echo '';
echo '
';
foreach($repos as $repo) {
$info = $repo->get_meta();
$aurl = clone($url);
- $aurl->params(array('action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));
+ $aurl->params(array('savepath'=>$savepath, 'action' => 'list', 'repo_id' => $info->id, 'draftpath'=>$draftpath));
- if ($env == 'filemanager' && $info->type == 'draft') {
- continue;
- }
echo '';
+ echo ' ';
echo html_writer::link($aurl, $info->name);
echo ' ';
}
@@ -331,271 +301,4 @@
echo ' ';
echo $OUTPUT->footer();
break;
-
-case 'zip':
- $zipper = new zip_packer();
- $fs = get_file_storage();
-
- $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, '.');
- if (!$file->get_parent_directory()) {
- $parent_path = '/';
- } else {
- $parent_path = $file->get_parent_directory()->get_filepath();
- }
-
- $newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user', 'draft', $itemid, $parent_path, $file->get_filepath().'.zip', $USER->id);
-
- $url->param('action', 'browse');
- $url->param('draftpath', $parent_path);
- redirect($url, get_string('ziped','repository'));
- break;
-
-case 'unzip':
- $zipper = new zip_packer();
- $fs = get_file_storage();
- $file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename);
-
- if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user', 'draft', $itemid, $draftpath, $USER->id)) {
- $str = get_string('unziped','repository');
- } else {
- $str = get_string('cannotunzip', 'repository');
- }
- $url->param('action', 'browse');
- $url->param('draftpath', $draftpath);
- redirect($url, $str);
- break;
-
-case 'movefile':
- if (!empty($targetpath)) {
- $fb = get_file_browser();
- $file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
- $file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $targetpath, $filename);
- if ($file->delete()) {
- $url->param('action', 'browse');
- $url->param('draftpath', $targetpath);
- redirect($url, '');
- exit;
- }
- }
- echo $OUTPUT->header();
- echo '";
- $data = new stdclass;
- $url->param('action', 'movefile');
- $url->param('draftpath', $draftpath);
- $url->param('filename', $filename);
- file_get_drafarea_folders($itemid, '/', $data);
- print_draft_area_tree($data, true, $url);
- echo $OUTPUT->footer();
- break;
-case 'mkdirform':
- echo $OUTPUT->header();
- echo '";
- $url->param('draftpath', $draftpath);
- $url->param('action', 'mkdir');
- echo ' ';
- echo $OUTPUT->footer();
- break;
-
-case 'mkdir':
- $fs = get_file_storage();
- $fs->create_directory($user_context->id, 'user', 'draft', $itemid, file_correct_filepath(file_correct_filepath($draftpath).trim($newdirname, '/')));
- $url->param('action', 'browse');
- $url->param('draftpath', $draftpath);
- if (!empty($newdirname)) {
- $str = get_string('createfoldersuccess', 'repository');
- } else {
- $str = get_string('createfolderfail', 'repository');
- }
- redirect($url, $str);
- break;
-
-case 'rename':
- $fs = get_file_storage();
- if ($file = $fs->get_file($user_context->id, 'user', 'draft', $itemid, $draftpath, $filename)) {
- if ($file->is_directory()) {
- if ($file->get_parent_directory()) {
- $draftpath = $file->get_parent_directory()->get_filepath();
- } else {
- $draftpath = '/';
- }
- // use file storage to create new folder
- $newdir = $draftpath . trim($newfilename , '/') . '/';
- $fs->create_directory($user_context->id, 'user', 'draft', $itemid, $newdir);
- } else {
- // use file browser to copy file
- $fb = get_file_browser();
- $file = $fb->get_file_info($user_context, 'user', 'draft', $itemid, $draftpath, $filename);
- $file->copy_to_storage($user_context->id, 'user', 'draft', $itemid, $draftpath, $newfilename);
- }
- }
- $file->delete();
- $url->param('action', 'browse');
- $url->param('draftpath', $draftpath);
- redirect($url);
- break;
-
-case 'renameform':
- echo $OUTPUT->header();
- echo '";
- $url->param('draftpath', $draftpath);
- $url->param('action', 'rename');
- echo ' ';
- echo $OUTPUT->footer();
- break;
-
-case 'browse':
-default:
- $user_context = get_context_instance(CONTEXT_USER, $USER->id);
- $params = array();
- $params['context'] = array($user_context, get_system_context());
- $params['currentcontext'] = $PAGE->context;
- $params['returntypes'] = 2;
- $repos = repository::get_instances($params);
- $fs = get_file_storage();
- $files = $fs->get_directory_files($user_context->id, 'user', 'draft', $itemid, $draftpath, false);
-
- echo $OUTPUT->header();
- if ((!empty($files) or $draftpath != '/') and $env == 'filemanager') {
- echo '';
- $url->param('action', 'browse');
- $url->param('draftpath', '/');
- echo '
'.'Files ▶';
- $trail = '';
- if ($draftpath !== '/') {
- $path = file_correct_filepath($draftpath);
- $parts = explode('/', $path);
- foreach ($parts as $part) {
- if (!empty($part)) {
- $trail .= ('/'.$part.'/');
- $data->path[] = array('name'=>$part, 'path'=>$trail);
- $url->param('draftpath', $trail);
- echo '
'.$part.' ▶ ';
- }
- }
- }
- echo '
';
- }
-
- $url->param('draftpath', $draftpath);
- $url->param('action', 'plugins');
- echo '';
-
- if (!empty($files)) {
- echo '';
- foreach ($files as $file) {
- $drafturl = new moodle_url($CFG->httpswwwroot.'/draftfile.php/'.$user_context->id.'/user/draft/'.$itemid.'/'.$file->get_filename());
- if ($file->get_filename() != '.') {
- // a file
- $fileicon = $CFG->wwwroot.'/pix/'.(file_extension_icon($file->get_filename()));
- $type = str_replace('.gif', '', mimeinfo('icon', $file->get_filename()));
- echo '';
- echo ' ';
- echo ' '.$file->get_filename().' ';
-
- $url->param('filename', $file->get_filename());
-
- $url->param('action', 'deletedraft');
- $url->param('draftpath', $file->get_filepath());
- echo ' ['.get_string('delete').' ]';
-
- $url->param('action', 'movefile');
- echo ' ['.get_string('move').' ]';
-
- $url->param('action', 'renameform');
- echo ' ['.get_string('rename').' ]';
-
- if ($type == 'zip') {
- $url->param('action', 'unzip');
- $url->param('draftpath', $file->get_filepath());
- echo ' ['.get_string('unzip').' ]';
- }
-
- echo ' ';
- } else {
- // a folder
- echo '';
- echo ' ';
-
- $url->param('action', 'browse');
- $url->param('draftpath', $file->get_filepath());
- $foldername = trim(array_pop(explode('/', trim($file->get_filepath(), '/'))), '/');
- echo ' '.$foldername.' ';
-
- $url->param('draftpath', $file->get_filepath());
- $url->param('filename', $file->get_filename());
- $url->param('action', 'deletedraft');
- echo ' ['.get_string('delete').' ]';
-
- // file doesn't support rename yet
- // for folder with existing files, we need to move these files one by one
- //$url->param('action', 'renameform');
- //echo ' ['.get_string('rename').' ]';
-
- $url->param('action', 'zip');
- echo ' [Zip ]';
- echo ' ';
- }
- }
- echo ' ';
- } else {
- //echo get_string('nofilesattached', 'repository');
- }
- echo $OUTPUT->footer();
- break;
-}
-function print_draft_area_tree($tree, $root, $url) {
- echo '';
- if ($root) {
- $url->param('targetpath', '/');
- if ($url->param('draftpath') == '/') {
- echo ''.get_string('files').' ';
- } else {
- echo ''.get_string('files').' ';
- }
- echo '';
- if (isset($tree->children)) {
- $tree = $tree->children;
- }
- }
-
- if (!empty($tree)) {
- foreach ($tree as $node) {
- echo '';
- $url->param('targetpath', $node->filepath);
- if ($url->param('draftpath') != $node->filepath) {
- echo ''.$node->fullname.' ';
- } else {
- echo $node->fullname;
- }
- echo ' ';
- if (!empty($node->children)) {
- print_draft_area_tree($node->children, false, $url);
- }
- }
- }
- if ($root) {
- echo ' ';
- }
- echo ' ';
}
-
diff --git a/theme/base/style/core.css b/theme/base/style/core.css
index 7550642e049c5..e6f0c20fb6c0a 100644
--- a/theme/base/style/core.css
+++ b/theme/base/style/core.css
@@ -497,9 +497,8 @@ body.tag .managelink {padding: 5px;}
* File Manager
*/
.filemanager-toolbar {margin: 5px 0;}
-.filemanager-toolbar a:link,
-.filemanager-toolbar a:visited {border: 1px solid gray;background: #ccc;color: black;padding: 3px;}
-.filemanager-toolbar a:hover {background: white;text-decoration: none;}
+.filemanager-toolbar a {border: 1px solid #AACCEE;background: #F4FAFF;color: black;padding: 3px;}
+.filemanager-toolbar a:hover {background: #FFFFFF;}
.fm-breadcrumb {margin:0;}
.filemanager-container {padding: 5px;margin: 6px 0;background: #E9F4FF;border: #AACCEE 1px solid}
.filemanager-container ul{margin:0;padding:0;}