MDL-10496:
[moodle-linuxchix.git] / lib / form / file.php
blobb25842b70208ec6dc052320f95c868a89519360c
1 <?php
2 require_once('HTML/QuickForm/file.php');
4 /**
5 * HTML class for a form element to upload a file
7 * @author Jamie Pratt
8 * @access public
9 */
10 class MoodleQuickForm_file extends HTML_QuickForm_file{
11 /**
12 * html for help button, if empty then no help
14 * @var string
16 var $_helpbutton='';
17 /**
18 * set html for help button
20 * @access public
21 * @param array $help array of arguments to make a help button
22 * @param string $function function name to call to get html
24 function setHelpButton($helpbuttonargs, $function='helpbutton'){
25 if (!is_array($helpbuttonargs)){
26 $helpbuttonargs=array($helpbuttonargs);
27 }else{
28 $helpbuttonargs=$helpbuttonargs;
30 //we do this to to return html instead of printing it
31 //without having to specify it in every call to make a button.
32 if ('helpbutton' == $function){
33 $defaultargs=array('', '', 'moodle', true, false, '', true);
34 $helpbuttonargs=$helpbuttonargs + $defaultargs ;
36 $this->_helpbutton=call_user_func_array($function, $helpbuttonargs);
38 /**
39 * set html for help button
41 * @access public
42 * @param array $help array of arguments to make a help button
43 * @param string $function function name to call to get html
45 function getHelpButton(){
46 return $this->_helpbutton;
49 /**
50 * Override createElement event to add max files
52 function onQuickFormEvent($event, $arg, &$caller)
54 if ($event == 'createElement') {
55 $className = get_class($this);
56 $this->$className($arg[0], $arg[1].' ('.get_string('maxsize', '', display_size($caller->getMaxFileSize())).')', $arg[2]);
57 return true;
59 return parent::onQuickFormEvent($event, $arg, $caller);
60 } // end func onQuickFormEvent
61 /**
62 * Slightly different container template when frozen.
64 * @return string
66 function getElementTemplateType(){
67 if ($this->_flagFrozen){
68 return 'static';
69 } else {
70 return 'default';