|
Moodle
2.2.1
http://www.collinsharper.com
|
00001 <?php 00002 require_once("HTML/QuickForm/text.php"); 00003 00010 class MoodleQuickForm_url extends HTML_QuickForm_text{ 00016 var $_helpbutton=''; 00017 var $_hiddenLabel=false; 00018 00019 function MoodleQuickForm_url($elementName=null, $elementLabel=null, $attributes=null, $options=null) { 00020 global $CFG; 00021 require_once("$CFG->dirroot/repository/lib.php"); 00022 $options = (array)$options; 00023 foreach ($options as $name=>$value) { 00024 $this->_options[$name] = $value; 00025 } 00026 if (!isset($this->_options['usefilepicker'])) { 00027 $this->_options['usefilepicker'] = true; 00028 } 00029 parent::HTML_QuickForm_text($elementName, $elementLabel, $attributes); 00030 } 00031 00032 function setHiddenLabel($hiddenLabel){ 00033 $this->_hiddenLabel = $hiddenLabel; 00034 } 00035 function toHtml(){ 00036 global $CFG, $COURSE, $USER, $PAGE, $OUTPUT; 00037 00038 $id = $this->_attributes['id']; 00039 $elname = $this->_attributes['name']; 00040 00041 if ($this->_hiddenLabel) { 00042 $this->_generateId(); 00043 $str = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'. 00044 $this->getLabel().'</label>'.parent::toHtml(); 00045 } else { 00046 $str = parent::toHtml(); 00047 } 00048 if (empty($this->_options['usefilepicker'])) { 00049 return $str; 00050 } 00051 $strsaved = get_string('filesaved', 'repository'); 00052 $straddlink = get_string('choosealink', 'repository'); 00053 if ($COURSE->id == SITEID) { 00054 $context = get_context_instance(CONTEXT_SYSTEM); 00055 } else { 00056 $context = get_context_instance(CONTEXT_COURSE, $COURSE->id); 00057 } 00058 $client_id = uniqid(); 00059 00060 $str .= <<<EOD 00061 <button id="filepicker-button-{$client_id}" style="display:none"> 00062 $straddlink 00063 </button> 00064 EOD; 00065 $args = new stdClass(); 00066 $args->accepted_types = '*'; 00067 $args->return_types = FILE_EXTERNAL; 00068 $args->context = $PAGE->context; 00069 $args->client_id = $client_id; 00070 $args->env = 'url'; 00071 $fp = new file_picker($args); 00072 $options = $fp->options; 00073 00074 // print out file picker 00075 $str .= $OUTPUT->render($fp); 00076 00077 $module = array('name'=>'form_url', 'fullpath'=>'/lib/form/url.js', 'requires'=>array('core_filepicker')); 00078 $PAGE->requires->js_init_call('M.form_url.init', array($options), true, $module); 00079 $PAGE->requires->js_function_call('show_item', array('filepicker-button-'.$client_id)); 00080 00081 return $str; 00082 } 00083 00091 function setHelpButton($helpbuttonargs, $function='helpbutton'){ 00092 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead'); 00093 } 00100 function getHelpButton(){ 00101 return $this->_helpbutton; 00102 } 00110 function getElementTemplateType(){ 00111 if ($this->_flagFrozen){ 00112 return 'static'; 00113 } else { 00114 return 'default'; 00115 } 00116 } 00117 }