]> git.mjollnir.org Git - moodle.git/commitdiff
MDL-19002 file size limits in filepicker + improved options
authorskodak <skodak>
Mon, 11 May 2009 18:49:04 +0000 (18:49 +0000)
committerskodak <skodak>
Mon, 11 May 2009 18:49:04 +0000 (18:49 +0000)
lib/form/filemanager.php
lib/form/filepicker.php
mod/forum/post_form.php
mod/glossary/edit_form.php

index 81acd13d4cc385621af91979efc38ec6e6fc78b1..b70daa16bba046c37c91e19eb1f365de44cf5076 100644 (file)
@@ -5,9 +5,9 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/lib/filelib.php');
 
 class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
     protected $_helpbutton = '';
-    protected $_options    = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1);
+    protected $_options    = array('subdirs'=>0, 'maxbytes'=>0, 'maxfiles'=>-1, 'filetypes'=>'*', 'returnvalue'=>'*');
 
-    function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $options=null, $attributes=null) {
+    function MoodleQuickForm_filemanager($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
         global $CFG;
 
         $options = (array)$options;
@@ -16,16 +16,6 @@ class MoodleQuickForm_filemanager extends HTML_QuickForm_element {
                 $this->_options[$name] = $value;
             }
         }
-        if (!empty($options['filetypes'])) {
-            $this->filetypes = $options['filetypes'];
-        } else {
-            $this->filetypes = '*';
-        }
-        if (!empty($options['returnvalue'])) {
-            $this->returnvalue = $options['returnvalue'];
-        } else {
-            $this->returnvalue = '*';
-        }
         if (!empty($options['maxbytes'])) {
             $this->_options['maxbytes'] = get_max_upload_file_size($CFG->maxbytes, $options['maxbytes']);
         }
index 93f809789ea089aaf72526c2d5da25f9343232ff..ae0c06dc7b2385175d4335ec2a80c9802b2ddef9 100644 (file)
@@ -13,11 +13,21 @@ require_once(dirname(dirname(dirname(__FILE__))) . '/repository/lib.php');
  * @access       public
  */
 class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
-    var $_helpbutton='';
+    protected $_helpbutton = '';
+    protected $_options    = array('maxbytes'=>0, 'filetypes'=>'*', 'returnvalue'=>'*');
+    
+    function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $options=null) {
+        global $CFG;
 
-    function MoodleQuickForm_filepicker($elementName=null, $elementLabel=null, $attributes=null, $filetypes = '*', $returnvalue = '*') {
-        $this->filetypes = $filetypes;
-        $this->returnvalue = $returnvalue;
+        $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_input($elementName, $elementLabel, $attributes);
     }
 
@@ -73,7 +83,7 @@ class MoodleQuickForm_filepicker extends HTML_QuickForm_input {
             $context = get_context_instance(CONTEXT_COURSE, $COURSE->id);
         }
         $client_id = uniqid();
-        $repository_info = repository_get_client($context, $client_id, $this->filetypes, $this->returnvalue);
+        $repository_info = repository_get_client($context, $client_id, $this->_options['filetypes'], $this->_options['returnvalue']);
 
         $id     = $this->_attributes['id'];
         $elname = $this->_attributes['name'];
index ff0a0fa585c162f4d6960a19f8ee09b3405b9e0c..244066b9a3f875334d31d3eef6773bcca0308367 100644 (file)
@@ -50,7 +50,7 @@ class mod_forum_post_form extends moodleform {
         }
 
         if (!empty($forum->maxattachments) && $forum->maxbytes != 1 && has_capability('mod/forum:createattachment', $modcontext))  {  //  1 = No attachments at all
-            $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'),
+            $mform->addElement('filemanager', 'attachments', get_string('attachment', 'forum'), null,
                 array('subdirs'=>0,
                       'maxbytes'=>$forum->maxbytes,
                       'maxfiles'=>$forum->maxattachments,
index 2ede126b138b901fec1d1864a54041957d58b578..de29588385cb2100b2de2bd67e2e0c9a09224aba 100644 (file)
@@ -36,7 +36,7 @@ class mod_glossary_entry_form extends moodleform {
         $mform->setType('aliases', PARAM_TEXT);
         $mform->setHelpButton('aliases', array('aliases2', strip_tags(get_string('aliases', 'glossary')), 'glossary'));
 
-        $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'glossary'), $attachmentoptions);
+        $mform->addElement('filemanager', 'attachment_filemanager', get_string('attachment', 'glossary'), null, $attachmentoptions);
         $mform->setHelpButton('attachment_filemanager', array('attachment2', get_string('attachment', 'glossary'), 'glossary'));
 
         if (!$glossary->usedynalink) {