MDL-16596 areafiles element renamed to "filemanager"

This commit is contained in:
skodak 2008-11-19 20:27:18 +00:00
parent 4664b66c73
commit 241431cdcc
2 changed files with 3 additions and 3 deletions

126
lib/form/filemanager.php Normal file
View file

@ -0,0 +1,126 @@
<?php // $Id$
require_once('HTML/QuickForm/element.php');
class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
protected $_helpbutton = '';
protected $_options = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>0);
function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
global $CFG;
$options = (array)$options;
foreach ($options as $name=>$value) {
if (array_key_exists($name, $this->_options)) {
$this->_options[$name] = $value;
}
}
if (!empty($options['maxbytes'])) {
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
}
parent::HTML_QuickForm_element($elementName, $elementLabel, $attributes);
}
function setName($name) {
$this->updateAttributes(array('name'=>$name));
}
function getName() {
return $this->getAttribute('name');
}
function setValue($value) {
$this->updateAttributes(array('value'=>$value));
}
function getValue() {
return $this->getAttribute('value');
}
function getMaxbytes() {
return $this->_options['maxbytes'];
}
function setMaxbytes($maxbytes) {
global $CFG;
$this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $maxbytes);
}
function getSubdirs() {
return $this->_options['subdirs'];
}
function setSubdirs($allow) {
$this->_options['subdirs'] = $allow;
}
function getMaxfiles() {
return $this->_options['maxfiles'];
}
function setMaxfiles($num) {
$this->_options['maxfiles'] = $num;
}
function setHelpButton($_helpbuttonargs, $function='_helpbutton') {
if (!is_array($_helpbuttonargs)) {
$_helpbuttonargs = array($_helpbuttonargs);
} else {
$_helpbuttonargs = $_helpbuttonargs;
}
//we do this to to return html instead of printing it
//without having to specify it in every call to make a button.
if ('_helpbutton' == $function){
$defaultargs = array('', '', 'moodle', true, false, '', true);
$_helpbuttonargs = $_helpbuttonargs + $defaultargs ;
}
$this->_helpbutton=call_user_func_array($function, $_helpbuttonargs);
}
function getHelpButton() {
return $this->_helpbutton;
}
function getElementTemplateType() {
if ($this->_flagFrozen){
return 'nodisplay';
} else {
return 'default';
}
}
function toHtml() {
global $CFG, $USER;
// security - never ever allow guest/not logged in user to upload anything or use this element!
if (isguestuser() or !isloggedin()) {
print_error('noguest');
}
if ($this->_flagFrozen) {
return $this->getFrozenHtml();
}
$id = $this->_attributes['id'];
$elname = $this->_attributes['name'];
$subdirs = $this->_options['subdirs'];
$maxbytes = $this->_options['maxbytes'];
$draftitemid = $this->getValue();
if (empty($draftitemid)) {
// no existing area info provided - let's use fresh new draft area
require_once("$CFG->libdir/filelib.php");
$this->setValue(file_get_new_draftitemid());
$draftitemid = $this->getValue();
}
$editorurl = "$CFG->wwwroot/files/draftfiles.php?itemid=$draftitemid&amp;subdirs=$subdirs&amp;maxbytes=$maxbytes";
$str = $this->_getTabs();
$str .= '<input type="hidden" name="'.$elname.'" value="'.$draftitemid.'" />';
$str .= '<object type="text/html" id="'.$id.'" data="'.$editorurl.'" height="160" width="600" style="border:1px solid #000">Error</object>'; // TODO: localise, fix styles, etc.
return $str;
}
}