diff --git a/lib/form/filepicker.php b/lib/form/filepicker.php index aafcbbf4dd4..bed14ea8d9a 100644 --- a/lib/form/filepicker.php +++ b/lib/form/filepicker.php @@ -49,28 +49,19 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { } function toHtml() { - global $CFG, $COURSE, $USER, $PAGE; - + global $CFG, $COURSE, $USER, $PAGE, $OUTPUT; + $id = $this->_attributes['id']; + $elname = $this->_attributes['name']; if ($this->_flagFrozen) { return $this->getFrozenHtml(); } - - $strsaved = get_string('filesaved', 'repository'); - $straddfile = get_string('openpicker', 'repository'); - $currentfile = ''; - if ($draftitemid = (int)$this->getValue()) { - $fs = get_file_storage(); - $usercontext = get_context_instance(CONTEXT_USER, $USER->id); - if ($files = $fs->get_area_files($usercontext->id, 'user_draft', $draftitemid, 'id DESC', false)) { - $file = reset($files); - $currentfile = $file->get_filename(); - } - } else { + if (!$draftitemid = (int)$this->getValue()) { // no existing area info provided - let's use fresh new draft area $draftitemid = file_get_unused_draft_itemid(); $this->setValue($draftitemid); } + if ($COURSE->id == SITEID) { $context = get_context_instance(CONTEXT_SYSTEM); } else { @@ -83,38 +74,14 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input { // need these three to filter repositories list $args->accepted_types = $this->_options['accepted_types']?$this->_options['accepted_types']:'*'; $args->return_types = FILE_INTERNAL; + $args->itemid = $draftitemid; $args->context = $PAGE->context; - $options = initialise_filepicker($args); - - $options->client_id = $client_id; - $options->maxbytes = $this->_options['maxbytes']; - $options->maxfiles = 1; - $options->env = 'filepicker'; - $options->itemid = $draftitemid; - - $id = $this->_attributes['id']; - $elname = $this->_attributes['name']; - $str = $this->_getTabs(); + $fp = new file_picker($args); + $options = $fp->options; + $str .= $OUTPUT->render($fp); $str .= ''; - - $str .= <<