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 if (!is_array($helpbuttonargs)){
94 $helpbuttonargs=array($helpbuttonargs);
96 $helpbuttonargs=$helpbuttonargs;
98 //we do this to to return html instead of printing it
99 //without having to specify it in every call to make a button.
100 if ('helpbutton' == $function){
101 $defaultargs=array('', '', 'moodle', true, false, '', true);
102 $helpbuttonargs=$helpbuttonargs +
$defaultargs ;
104 $this->_helpbutton
=call_user_func_array($function, $helpbuttonargs);
107 * get html for help button
110 * @return string html for help button
112 function getHelpButton(){
113 return $this->_helpbutton
;
116 * Removes an OPTION from the SELECT
118 * @param string $value Value for the OPTION to remove
123 function removeOption($value)
125 $key=array_search($value, $this->_values
);
126 if ($key!==FALSE and $key!==null) {
127 unset($this->_values
[$key]);
129 foreach ($this->_options
as $key=>$option){
130 if ($option['attr']['value']==$value){
131 unset($this->_options
[$key]);
135 } // end func removeOption
137 * Removes all OPTIONs from the SELECT
139 * @param string $value Value for the OPTION to remove
144 function removeOptions()
146 $this->_options
= array();
147 } // end func removeOption
149 * Slightly different container template when frozen. Don't want to use a label tag
150 * with a for attribute in that case for the element label but instead use a div.
151 * Templates are defined in renderer constructor.
155 function getElementTemplateType(){
156 if ($this->_flagFrozen
){