"MDL-13766, improve filepicker to use path option"

This commit is contained in:
dongsheng 2009-08-22 18:16:20 +00:00
parent 1bf9a6311e
commit e5fa0e8d7d
4 changed files with 18 additions and 5 deletions

View File

@ -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;
}

View File

@ -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]){

View File

@ -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);
}
}

View File

@ -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);
}