$action = optional_param('action', 'list', PARAM_ALPHA);
$filename = optional_param('filename', '', PARAM_FILE);
-$filearea = optional_param('filearea', '', PARAM_ALPHAEXT);
+$filearea = optional_param('filearea', 'user_draft', PARAM_ALPHAEXT);
$filepath = optional_param('filepath', '/', PARAM_PATH);
$itemid = optional_param('itemid', -1, PARAM_INT);
$newfilepath = optional_param('newfilepath', '/', PARAM_PATH);
switch ($action) {
case 'dir':
$data = new stdclass;
- file_get_draft_area_folders($itemid, $filepath, $data);
+ file_get_user_area_folders($itemid, $filepath, $data, $filearea);
echo json_encode($data);
break;
case 'list':
- $data = file_get_draft_area_files($itemid, $filepath);
+ $data = file_get_user_area_files($itemid, $filepath, $filearea);
echo json_encode($data);
break;
case 'mkdir':
$fs = get_file_storage();
- $fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath(file_correct_filepath($filepath).$newdirname));
+ $fs->create_directory($user_context->id, $filearea, $itemid, file_correct_filepath(file_correct_filepath($filepath).$newdirname));
$return = new stdclass;
$return->filepath = $filepath;
echo json_encode($return);
$fs = get_file_storage();
$filepath = file_correct_filepath($filepath);
$return = new stdclass;
- if ($stored_file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename)) {
+ if ($stored_file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, $filename)) {
$parent_path = $stored_file->get_parent_directory()->get_filepath();
if($result = $stored_file->delete()) {
$return->filepath = $parent_path;
$fs = get_file_storage();
$fb = get_file_browser();
$return = new stdclass;
- $fileinfo = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, '.');
+ $fileinfo = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, '.');
if ($result = $fileinfo->delete()) {
- $newdir = $fs->create_directory($user_context->id, 'user_draft', $itemid, file_correct_filepath($newfilename));
+ $newdir = $fs->create_directory($user_context->id, $filearea, $itemid, file_correct_filepath($newfilename));
$return->filepath = $newdir->get_parent_directory()->get_filepath();
echo json_encode($return);
} else {
case 'rename':
$fb = get_file_browser();
- $file = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, $filename);
- $file->copy_to_storage($user_context->id, 'user_draft', $itemid, $filepath, $newfilename);
+ $file = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, $filename);
+ $file->copy_to_storage($user_context->id, $filearea, $itemid, $filepath, $newfilename);
if ($file->delete()) {
$return = new stdclass;
$return->filepath = $filepath;
$fb = get_file_browser();
$return = new stdclass;
if ($filepath != $newfilepath) {
- $file = $fb->get_file_info($user_context, 'user_draft', $itemid, $filepath, $filename);
- $file->copy_to_storage($user_context->id, 'user_draft', $itemid, $newfilepath, $filename);
+ $file = $fb->get_file_info($user_context, $filearea, $itemid, $filepath, $filename);
+ $file->copy_to_storage($user_context->id, $filearea, $itemid, $newfilepath, $filename);
if ($file->delete()) {
$return->filepath = $newfilepath;
}
$zipper = new zip_packer();
$fs = get_file_storage();
- $file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, '.');
+ $file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, '.');
$parent_path = $file->get_parent_directory()->get_filepath();
- if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, 'user_draft', $itemid, $parent_path, $filepath.'.zip', $USER->id)) {
+ if ($newfile = $zipper->archive_to_storage(array($file), $user_context->id, $filearea, $itemid, $parent_path, $filepath.'.zip', $USER->id)) {
$return = new stdclass;
$return->filepath = $parent_path;
echo json_encode($return);
$zipper = new zip_packer();
$fs = get_file_storage();
- $stored_file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, '.');
+ $stored_file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, '.');
if ($filepath === '/') {
$parent_path = '/';
$filename = get_string('files').'.zip';
// archive compressed file to an unused draft area
$newdraftitemid = file_get_unused_draft_itemid();
- if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, 'user_draft', $newdraftitemid, '/', $filename, $USER->id)) {
+ if ($newfile = $zipper->archive_to_storage(array($stored_file), $user_context->id, $filearea, $newdraftitemid, '/', $filename, $USER->id)) {
$return = new stdclass;
- $return->fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/user_draft/'.$newdraftitemid.'/'.$filename;
+ $return->fileurl = $CFG->wwwroot . '/draftfile.php/' . $user_context->id .'/'.$filearea.'/'.$newdraftitemid.'/'.$filename;
$return->filepath = $parent_path;
echo json_encode($return);
} else {
$fs = get_file_storage();
- $file = $fs->get_file($user_context->id, 'user_draft', $itemid, $filepath, $filename);
+ $file = $fs->get_file($user_context->id, $filearea, $itemid, $filepath, $filename);
- if ($newfile = $file->extract_to_storage($zipper, $user_context->id, 'user_draft', $itemid, $filepath, $USER->id)) {
+ if ($newfile = $file->extract_to_storage($zipper, $user_context->id, $filearea, $itemid, $filepath, $USER->id)) {
$return = new stdclass;
$return->filepath = $filepath;
echo json_encode($return);
* @param string $filepath
* @param mixed $data
*/
-function file_get_draft_area_folders($draftitemid, $filepath, &$data) {
+function file_get_user_area_folders($draftitemid, $filepath, &$data, $filearea = 'user_draft') {
global $USER, $OUTPUT, $CFG;
$data->children = array();
$context = get_context_instance(CONTEXT_USER, $USER->id);
$fs = get_file_storage();
- if ($files = $fs->get_directory_files($context->id, 'user_draft', $draftitemid, $filepath, false)) {
+ if ($files = $fs->get_directory_files($context->id, $filearea, $draftitemid, $filepath, false)) {
foreach ($files as $file) {
if ($file->is_directory()) {
$item = new stdclass;
* @param string $filepath
* @return mixed
*/
-function file_get_draft_area_files($draftitemid, $filepath = '/') {
+function file_get_user_area_files($draftitemid, $filepath = '/', $filearea = 'user_draft') {
global $USER, $OUTPUT, $CFG;
$context = get_context_instance(CONTEXT_USER, $USER->id);
}
$list = array();
- if ($files = $fs->get_directory_files($context->id, 'user_draft', $draftitemid, $filepath, false)) {
+ if ($files = $fs->get_directory_files($context->id, $filearea, $draftitemid, $filepath, false)) {
foreach ($files as $file) {
$item = new stdclass;
$item->filename = $file->get_filename();
require_once('HTML/QuickForm/element.php');
require_once($CFG->dirroot.'/lib/filelib.php');
-require_once("$CFG->dirroot/repository/lib.php");
+require_once($CFG->dirroot.'/repository/lib.php');
class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
public $_helpbutton = '';
$params->context = $PAGE->context;
$params->env = 'filemanager';
+ // including the repository instances list
$filepicker_options = initialise_filepicker($params);
- $filepicker_options->client_id = $client_id;
- $filepicker_options->maxbytes = $this->_options['maxbytes'];
- $filepicker_options->maxfiles = $this->_options['maxfiles'];
- $filepicker_options->env = 'filemanager';
- $filepicker_options->itemid = $draftitemid;
-
- $options = file_get_draft_area_files($draftitemid);
+ // including draft files
+ $options = file_get_user_area_files($draftitemid, '/', 'user_draft');
+ // filemanager options
+ $options->filepicker = $filepicker_options;
$options->mainfile = $this->_options['mainfile'];
$options->maxbytes = $this->_options['maxbytes'];
$options->maxfiles = $this->getMaxfiles();
$options->itemid = $draftitemid;
$options->subdirs = $this->_options['subdirs'];
// store filepicker options
- $options->filepicker = $filepicker_options;
$options->target = $id;
$html = $this->_getTabs();