From f3a6f85b941a6d5d23a88da5f8e52108de5cf75f Mon Sep 17 00:00:00 2001 From: dongsheng Date: Wed, 6 Aug 2008 08:09:01 +0000 Subject: [PATCH] MDL-13766, use a better value for itemid. --- lib/form/filepicker.php | 5 +---- repository/lib.php | 10 ++++------ repository/ws.php | 10 ++++++---- 3 files changed, 11 insertions(+), 14 deletions(-) diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index 8e8097a120..564cb0d2b3 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -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(); diff --git a/repository/lib.php b/repository/lib.php index 8735f04b97..5381aa2a09 100644 --- a/repository/lib.php +++ b/repository/lib.php @@ -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'); diff --git a/repository/ws.php b/repository/ws.php index d9568b99de..45cb6b79b2 100644 --- a/repository/ws.php +++ b/repository/ws.php @@ -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)); } } - -?> -- 2.39.5