]> git.mjollnir.org Git - moodle.git/commitdiff
"MDL-13766, improve filepicker to use path option"
authordongsheng <dongsheng>
Sat, 22 Aug 2009 18:16:20 +0000 (18:16 +0000)
committerdongsheng <dongsheng>
Sat, 22 Aug 2009 18:16:20 +0000 (18:16 +0000)
repository/lib.php
repository/repository.src.js
repository/upload/repository.class.php
repository/ws.php

index 70b8fad6406703e9c75e37d6cc4b21d8a2a1078e..3f4b284ff4af55f57b296c6dba49d9aab12fa14f 100644 (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;
         }
index 1facb7db1e173c9bb1b22093655428099db44a9b..937b2b0c635520fe7104d763fe374eddb67dbcd2 100644 (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]){
index b4941c4a70f11e8b8ca703a09284d38d8dcdf43f..d0f3821c8b932d85a0c6ec67b24a4c80f9e5852e 100755 (executable)
@@ -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);
         }
     }
index f711bc8d2464ccccbedf760e785bc6c297557b78..e43984947f483832658af6206ff10d56808ff5a9 100644 (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);
                 }