2 require_once('HTML/QuickForm/select.php');
5 * HTML class for a select type element
10 class MoodleQuickForm_selectwithlink extends HTML_QuickForm_select{
12 * html for help button, if empty then no help
17 var $_hiddenLabel=false;
20 var $_linkreturn=null;
22 function MoodleQuickForm_selectwithlink($elementName=null, $elementLabel=null, $options=null, $attributes=null, $linkdata=null)
24 if (!empty($linkdata['link']) && !empty($linkdata['label'])) {
25 $this->_link = $linkdata['link'];
26 $this->_linklabel = $linkdata['label'];
29 if (!empty($linkdata['return'])) {
30 $this->_linkreturn = $linkdata['return'];
33 parent::HTML_QuickForm_select($elementName, $elementLabel, $options, $attributes);
36 function setHiddenLabel($hiddenLabel){
37 $this->_hiddenLabel = $hiddenLabel;
41 if ($this->_hiddenLabel){
43 $retval = '<label class="accesshide" for="'.$this->getAttribute('id').'" >'.
44 $this->getLabel().'</label>'.parent::toHtml();
46 $retval = parent::toHtml();
49 if (!empty($this->_link)) {
50 if (!empty($this->_linkreturn) && is_array($this->_linkreturn)) {
52 if (strstr($this->_link, '?')) {
53 $appendchar = '&';
56 foreach ($this->_linkreturn as $key => $val) {
57 $this->_link .= $appendchar."$key=$val";
58 $appendchar = '&';
62 $retval .= '<a style="margin-left: 5px" href="'.$this->_link.'">'.$this->_linklabel.'</a>';
68 * Automatically generates and assigns an 'id' attribute for the element.
70 * Currently used to ensure that labels work on radio buttons and
71 * checkboxes. Per idea of Alexander Radivanovich.
72 * Overriden in moodleforms to remove qf_ prefix.
77 function _generateId()
81 if (!$this->getAttribute('id')) {
82 $this->updateAttributes(array('id' => 'id_'. substr(md5(microtime() . $idx++), 0, 6)));
84 } // end func _generateId
86 * set html for help button
89 * @param array $help array of arguments to make a help button
90 * @param string $function function name to call to get html
92 function setHelpButton($helpbuttonargs, $function='helpbutton'){
93 debugging('component setHelpButton() is not used any more, please use $mform->setHelpButton() instead');
96 * get html for help button
99 * @return string html for help button
101 function getHelpButton(){
102 return $this->_helpbutton;
105 * Removes an OPTION from the SELECT
107 * @param string $value Value for the OPTION to remove
112 function removeOption($value)
114 $key=array_search($value, $this->_values);
115 if ($key!==FALSE and $key!==null) {
116 unset($this->_values[$key]);
118 foreach ($this->_options as $key=>$option){
119 if ($option['attr']['value']==$value){
120 unset($this->_options[$key]);
124 } // end func removeOption
126 * Removes all OPTIONs from the SELECT
128 * @param string $value Value for the OPTION to remove
133 function removeOptions()
135 $this->_options = array();
136 } // end func removeOption
138 * Slightly different container template when frozen. Don't want to use a label tag
139 * with a for attribute in that case for the element label but instead use a div.
140 * Templates are defined in renderer constructor.
144 function getElementTemplateType(){
145 if ($this->_flagFrozen){