From af804e3e0f3009e45cfe626537b70d2777e5e405 Mon Sep 17 00:00:00 2001 From: dongsheng Date: Fri, 4 Sep 2009 06:48:26 +0000 Subject: [PATCH] "MDL-16596, make non-js filemanager identical to ajax filemanager, added more language strings" --- lang/en_utf8/error.php | 1 + lang/en_utf8/moodle.php | 2 + lang/en_utf8/repository.php | 6 +- repository/filepicker.php | 271 ++++++++++++++++++++++++++++-------- 4 files changed, 220 insertions(+), 60 deletions(-) diff --git a/lang/en_utf8/error.php b/lang/en_utf8/error.php index b46f2d5c60..aa6ed8272b 100644 --- a/lang/en_utf8/error.php +++ b/lang/en_utf8/error.php @@ -45,6 +45,7 @@ $string['cannotdeletecategoryquestions'] = 'Could not delete questions from cate $string['cannotdeletecourse'] = 'You do not have the permission to delete this course'; $string['cannotdeletecustomfield'] = 'Error deleting custom field data'; $string['cannotdeletedir'] = 'Cannot delete ($a)'; +$string['cannotdeletefile'] = 'Cannot delete this file'; $string['cannotdeleterole'] = 'It cannot be deleted, because $a'; $string['cannotdeletethisrole'] = 'You cannot delete this role because it is used by the system, or because it is the last role with administrator capabilities.'; $string['cannotdeleterolewithid'] = 'Could not delete role with ID $a'; diff --git a/lang/en_utf8/moodle.php b/lang/en_utf8/moodle.php index 044a1196ad..d82b0a968f 100644 --- a/lang/en_utf8/moodle.php +++ b/lang/en_utf8/moodle.php @@ -453,6 +453,8 @@ $string['documentation'] = 'Moodle Documentation'; $string['donotask'] = 'Do Not Ask'; $string['donotclickcontinue'] = 'Do not click on the following continue link ;-)'; $string['down'] = 'Down'; +$string['download'] = 'Download'; +$string['downloadall'] = 'Download all'; $string['downloadexcel'] = 'Download in Excel format'; $string['downloadfile'] = 'Download file'; $string['downloadods'] = 'Download in ODS format'; diff --git a/lang/en_utf8/repository.php b/lang/en_utf8/repository.php index 26f4de9337..546ea2b0bf 100644 --- a/lang/en_utf8/repository.php +++ b/lang/en_utf8/repository.php @@ -20,6 +20,7 @@ $string['cachecleared'] = 'Cached files are removed'; $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.'; $string['cannotdelete'] = 'Cannot delete this file.'; $string['cannotdownload'] = 'Cannot download this file'; +$string['cannotdownloaddir'] = 'Cannot download this folder'; $string['cannotinitplugin'] = 'Call plugin_init failed'; $string['clicktohide'] = 'Click here to hide'; $string['clicktoshow'] = 'Click here to show'; @@ -41,6 +42,7 @@ $string['date'] = 'Date'; $string['deleterepository'] = 'Delete this repository'; $string['deleted'] = 'Repository deleted'; $string['download'] = 'Download'; +$string['downloadfolder'] = 'Download this folder'; $string['downloadsucc'] = 'The file has been downloaded successfully'; $string['editrepositoryinstance'] = 'Edit repository instance'; $string['emptytype'] = 'Cannot create repository type: type name is empty'; @@ -48,7 +50,8 @@ $string['emptylist'] = 'Empty result'; $string['enablecourseinstances'] = 'Allow teachers to add a repository instance into the file picker'; $string['enableuserinstances'] = 'Allow users to add a repository instance into the file picker'; $string['enter'] = 'Enter'; -$string['entername'] = 'Please enter file/folder name'; +$string['entername'] = 'Please enter folder name'; +$string['enternewname'] = 'Please enter the new file name'; $string['error'] = 'An unknown error occurred!'; $string['existingrepository'] = 'This repository already exists'; $string['filename'] = 'Filename'; @@ -87,6 +90,7 @@ $string['plugin'] = 'Repository plug-ins'; $string['pluginerror'] = 'Errors in repository plugin.'; $string['preview'] = 'Preview'; $string['popup'] = 'Click "Login" button to login'; +$string['popupblockeddownload'] = 'The downloading windows blocked, please clicked the archived folder.'; $string['readonlyinstance'] = 'You cannot edit/delete a read-only instance'; $string['refresh'] = 'Refresh'; $string['refreshnonjsfilepicker'] = 'Please close this window and refresh non-javascript file picker'; diff --git a/repository/filepicker.php b/repository/filepicker.php index 561de8802e..60f4117369 100755 --- a/repository/filepicker.php +++ b/repository/filepicker.php @@ -24,7 +24,7 @@ set_time_limit(0); require_login(); // disable blocks in this page -$PAGE->set_generaltype('form'); +$PAGE->set_generaltype('embedded'); // general parameters $action = optional_param('action', '', PARAM_ALPHA); @@ -38,6 +38,7 @@ $env = optional_param('env', 'filepicker', PARAM_ALPHA); // opened in f $filename = optional_param('filename', '', PARAM_FILE); $fileurl = optional_param('fileurl', '', PARAM_FILE); $thumbnail = optional_param('thumbnail', '', PARAM_RAW); +$targetpath = optional_param('targetpath', '', PARAM_PATH); $repo_id = optional_param('repo_id', 0, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // the path in repository $page = optional_param('page', '', PARAM_RAW); // What page in repository? @@ -45,6 +46,7 @@ $search_text = optional_param('s', '', PARAM_CLEANHTML); // draft area $newdirname = optional_param('newdirname', '', PARAM_FILE); +$newfilename = optional_param('newfilename', '', PARAM_FILE); // path in draft area $draftpath = optional_param('draftpath', '/', PARAM_PATH); @@ -74,7 +76,7 @@ if ($repository = $DB->get_record_sql($sql, array($repo_id))) { } $url = new moodle_url($CFG->httpswwwroot."/repository/filepicker.php", array('ctx_id' => $contextid, 'itemid' => $itemid, 'env' => $env)); -$home_url = new moodle_url($url, array('action' => 'embedded')); +$home_url = new moodle_url($url, array('action' => 'browse')); switch ($action) { case 'upload': @@ -87,8 +89,17 @@ 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()) { - header('Location: ' . $home_url->out(false, array(), false)); + $url->param('draftpath', $draftpath); + $url->param('action', 'browse'); + redirect($url); } else { print_error('cannotdelete', 'repository'); } @@ -141,7 +152,7 @@ case 'search': case 'list': case 'sign': - print_header(); + echo $OUTPUT->header(); echo '
'.get_string('back', 'repository')."
"; if ($repo->check_login()) { $list = $repo->get_listing($req_path, $page); @@ -225,8 +236,29 @@ case 'download': 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 = 'draft_area.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': - print_header(); + echo $OUTPUT->header(); echo '
'.get_string('back', 'repository').'
'; echo ''; echo '
'; @@ -251,7 +283,7 @@ case 'confirm': case 'plugins': $user_context = get_context_instance(CONTEXT_USER, $USER->id); $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); - print_header(); + echo $OUTPUT->header(); echo '
'.get_string('back', 'repository')."
"; echo '
'; echo '
    '; @@ -273,19 +305,6 @@ case 'plugins': 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 'zip': $zipper = new zip_packer(); $fs = get_file_storage(); @@ -319,43 +338,137 @@ case 'unzip': redirect($url, $str); break; -case 'browse': -default: - $user_context = get_context_instance(CONTEXT_USER, $USER->id); - $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); - print_header(); +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 '
    '.get_string('back', 'repository')."
    "; + $data = new stdclass; + $url->param('action', 'movefile'); + $url->param('draftpath', $draftpath); + $url->param('filename', $filename); + file_get_draft_area_folders($itemid, '/', $data); + print_draft_area_tree($data, true, $url); + echo $OUTPUT->footer(); + break; +case 'mkdirform': + echo $OUTPUT->header(); + echo '
    '.get_string('back', 'repository')."
    "; + $url->param('draftpath', $draftpath); + $url->param('action', 'mkdir'); + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo $OUTPUT->footer(); + break; - echo '
    '; - $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.' ▶ '; +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); } } - echo '
    '; + $file->delete(); + $url->param('action', 'browse'); + $url->param('draftpath', $draftpath); + redirect($url); + break; +case 'renameform': + echo $OUTPUT->header(); + echo '
    '.get_string('back', 'repository')."
    "; + $url->param('draftpath', $draftpath); + $url->param('action', 'rename'); + echo '
    '; + echo ' '; + echo ' '; + echo ' '; + echo ' '; + echo '
    '; + echo $OUTPUT->footer(); + break; +case 'browse': +default: + $user_context = get_context_instance(CONTEXT_USER, $USER->id); + $repos = repository::get_instances(array($user_context, get_system_context()), null, true, null, '*', 'ref_id'); $fs = get_file_storage(); $files = $fs->get_directory_files($user_context->id, 'user_draft', $itemid, $draftpath, false); - $iconzip = $CFG->wwwroot . '/pix/f/zip.gif'; + echo $OUTPUT->header(); + if (!empty($files) or $draftpath != '/') { + 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 '
    '; + } - if (empty($files)) { - echo get_string('nofilesattached', 'repository'); - } else { + $url->param('draftpath', $draftpath); + $url->param('action', 'plugins'); + echo '
    '; + echo ' '.get_string('addfile', 'repository').''; + $url->param('action', 'mkdirform'); + echo ' '.get_string('makeafolder', 'moodle').''; + $url->param('action', 'downloaddir'); + echo ' '.get_string('downloadfolder', 'repository').''; + 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()!='.') { + 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())); @@ -364,13 +477,21 @@ default: echo ' '.$file->get_filename().' '; $url->param('filename', $file->get_filename()); + $url->param('action', 'deletedraft'); - echo ' '; + $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 ' [Unzip]'; + echo ' ['.get_string('unzip').']'; } echo ''; @@ -387,27 +508,59 @@ default: $url->param('draftpath', $file->get_filepath()); $url->param('filename', $file->get_filename()); $url->param('action', 'deletedraft'); - echo ' '; + 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 ' [Zip]'; echo ''; } } echo '
    '; + } else { + //echo get_string('nofilesattached', 'repository'); } - $url->param('draftpath', $draftpath); - $url->param('action', 'plugins'); - - echo '
    '; - echo ' '.get_string('addfile', 'repository').''; - $url->param('action', 'mkdir'); - echo '
    '; - echo ' '; - echo ' '; - echo '
    '; - echo '
    '; - 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 '
    '; +} + -- 2.39.5