MDL-13766, use a better value for itemid.
authordongsheng <dongsheng>
Wed, 6 Aug 2008 08:09:01 +0000 (08:09 +0000)
committerdongsheng <dongsheng>
Wed, 6 Aug 2008 08:09:01 +0000 (08:09 +0000)
lib/form/filepicker.php
repository/lib.php
repository/ws.php

index 8e8097a120d43f6e1f0676413cf637a259bcf699..564cb0d2b337071b53a1c6763ab453d7570c2793 100644 (file)
@@ -45,10 +45,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_button
             return $this->getFrozenHtml();
         } else {
             $strsaved = get_string('filesaved', 'repository');
-            // TODO
-            // Use a better itemid value to identify a repository
-            // file
-            $itemid = time();
+            $itemid = substr(hexdec(uniqid()), 0, 9)+rand(1,100);
             $ret = get_repository_client();
             $suffix = $ret['suffix'];
             $str = $this->_getTabs();
index 8735f04b978d1cec1207209a977dc5f7abbd50b1..5381aa2a09fc1da71bfc82f94d18bdd6e4ebcba6 100644 (file)
@@ -282,9 +282,8 @@ function repository_get_option($id, $position){
     $ret = (array)unserialize($entry->$option);
     return $ret;
 }
-function repository_instances(){
+function repository_instances($contextid = SITEID){
     global $DB, $CFG, $USER;
-    $contextid = 0;
     $params = array();
     $sql = 'SELECT * FROM {repository} r WHERE ';
     $sql .= ' (r.userid = 0 or r.userid = ?) ';
@@ -354,17 +353,16 @@ function move_to_filepool($path, $name, $itemid) {
     if ($file = $fs->create_file_from_pathname($entry, $path)) {
         $id = json_encode($file->get_itemid());
         $ret = $browser->get_file_info($context, $file->get_filearea(), $file->get_itemid(), $file->get_filepath(), $file->get_filename());
-        // TODO
-        // get_params should include id value, talk to Petr.
         return array('url'=>$ret->get_url(),'id'=>$file->get_itemid());
     } else {
         return null;
     }
 }
 
-
+// TODO
+// Need to pass contextid and contextlevel here
 function get_repository_client(){
-    global $CFG;
+    global $CFG, $USER;
     $suffix = uniqid();
     $strsubmit    = get_string('submit', 'repository');
     $strlistview  = get_string('listview', 'repository');
index d9568b99deb1bb9c35f453fd56d89c48a66b1d9b..45cb6b79b201313bb21fbecbc20f692f03b883a0 100644 (file)
@@ -17,9 +17,13 @@ $action = optional_param('action', '', PARAM_RAW);
 $search = optional_param('s', '', PARAM_RAW);
 // id of repository
 $repo_id = optional_param('repo_id', 1, PARAM_INT);
-$itemid  = optional_param('itemid',  0, PARAM_INT);
+// context id
+$ctx_id  = optional_param('ctx_id', SITEID, PARAM_INT);
+$itemid  = optional_param('itemid', 0, PARAM_INT);
+$userid  = $USER->id;
 
-if(!$repository = $DB->get_record('repository', array('id'=>$repo_id))) {
+if(!$repository = $DB->get_record('repository', array('id'=>$repo_id)))
+{
     $err = new stdclass;
     $err->e = get_string('invalidrepositoryid', 'repository');
     die(json_encode($err));
@@ -87,5 +91,3 @@ if($action == 'list') {
         die(json_encode($err));
     }
 }
-
-?>