From e5fa0e8d7d0911c1c38510310fc98a67b4ba1afe Mon Sep 17 00:00:00 2001 From: dongsheng Date: Sat, 22 Aug 2009 18:16:20 +0000 Subject: [PATCH] "MDL-13766, improve filepicker to use path option" --- repository/lib.php | 15 ++++++++++++--- repository/repository.src.js | 3 +++ repository/upload/repository.class.php | 2 +- repository/ws.php | 3 ++- 4 files changed, 18 insertions(+), 5 deletions(-) diff --git a/repository/lib.php b/repository/lib.php index 70b8fad6406..3f4b284ff4a 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -737,16 +737,19 @@ abstract class repository { * @param string $filearea file area * @return array information of file in file pool */ - public static function move_to_filepool($path, $name, $itemid, $filearea = 'user_draft') { + public static function move_to_filepool($path, $name, $itemid, $filepath = '/', $filearea = 'user_draft') { global $DB, $CFG, $USER, $OUTPUT; + if ($filepath !== '/') { + $filepath = trim($filepath, '/'); + $filepath = '/'.$filepath.'/'; + } $context = get_context_instance(CONTEXT_USER, $USER->id); $now = time(); $entry = new object(); $entry->filearea = $filearea; $entry->contextid = $context->id; $entry->filename = $name; - //$entry->filepath = '/'.uniqid().'/'; - $entry->filepath = '/'; + $entry->filepath = $filepath; $entry->timecreated = $now; $entry->timemodified = $now; $entry->userid = $USER->id; @@ -792,6 +795,12 @@ abstract class repository { */ public static function store_to_filepool($elname, $filearea='user_draft', $filepath='/', $itemid='', $filename = '', $override = false) { global $USER; + + if ($filepath !== '/') { + $filepath = trim($filepath, '/'); + $filepath = '/'.$filepath.'/'; + } + if (!isset($_FILES[$elname])) { return false; } diff --git a/repository/repository.src.js b/repository/repository.src.js index 1facb7db1e1..937b2b0c635 100644 --- a/repository/repository.src.js +++ b/repository/repository.src.js @@ -998,6 +998,7 @@ repository_client.download = function(client_id, repo_id) { } params['env']=fp.env; params['file']=file; + params['savepath']=fp.savepath; params['title']=title; params['sesskey']=moodle_cfg.sesskey; params['ctx_id']=fp_config.contextid; @@ -1091,6 +1092,7 @@ repository_client.upload = function(client_id) { moodle_cfg.wwwroot+'/repository/ws.php?action=upload&itemid='+fp.itemid +'&sesskey='+moodle_cfg.sesskey +'&ctx_id='+fp_config.contextid + +'&savepath='+fp.savepath +'&repo_id='+u.repo_id +'&client_id='+client_id, repository_client.upload_cb); @@ -1210,6 +1212,7 @@ function open_filepicker(id, params) { r = new repository_client(); r.env = params.env; r.target = params.target; + r.savepath = params.savepath; if(params.itemid){ r.itemid = params.itemid; } else if(tinyMCE && id2itemid[tinyMCE.selectedInstance.editorId]){ diff --git a/repository/upload/repository.class.php b/repository/upload/repository.class.php index b4941c4a70f..d0f3821c8b9 100755 --- a/repository/upload/repository.class.php +++ b/repository/upload/repository.class.php @@ -22,8 +22,8 @@ class repository_upload extends repository { global $_FILES, $SESSION, $action, $CFG; parent::__construct($repositoryid, $context, $options); $itemid = optional_param('itemid', '', PARAM_INT); + $filepath = optional_param('savepath', '/', PARAM_PATH); if($action=='upload'){ - $filepath = '/'; $this->info = repository::store_to_filepool('repo_upload_file', 'user_draft', $filepath, $itemid); } } diff --git a/repository/ws.php b/repository/ws.php index f711bc8d246..e43984947f4 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -18,6 +18,7 @@ $ctx_id = optional_param('ctx_id', SITEID, PARAM_INT); // context ID $repo_id = optional_param('repo_id', 1, PARAM_INT); // repository ID $req_path = optional_param('p', '', PARAM_RAW); // path + $save_path = optional_param('savepath', '/', PARAM_PATH); $callback = optional_param('callback', '', PARAM_CLEANHTML); $search_text = optional_param('s', '', PARAM_CLEANHTML); @@ -232,7 +233,7 @@ EOD; echo json_encode($info); } else { // normal file path name - $info = repository::move_to_filepool($filepath, $title, $itemid); + $info = repository::move_to_filepool($filepath, $title, $itemid, $save_path); $info['client_id'] = $client_id; echo json_encode($info); }