4 |
* |
* |
5 |
* $Id$ |
* $Id$ |
6 |
* |
* |
7 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
8 |
* @author Suren Markosyan <suren@bcsweb.com> |
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
* @package phpHtmlLib |
* @package phpHtmlLib |
10 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
18 |
* input field of type="checkbox". It has no validation method. |
* input field of type="checkbox". It has no validation method. |
19 |
* |
* |
20 |
* |
* |
21 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
22 |
* @author Suren Markossian <suren@bcsweb.com> |
* @author Suren Markossian <suren@bcsweb.com> |
23 |
* @package phpHtmlLib |
* @package phpHtmlLib |
24 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
39 |
* @param label string - text label for the element |
* @param label string - text label for the element |
40 |
* @param string text - checkbox text to be displayed |
* @param string text - checkbox text to be displayed |
41 |
*/ |
*/ |
42 |
function FECheckBox($label, $text) { |
function FECheckBox($label, $text=null) { |
43 |
$this->FormElement($label, false); |
$this->FormElement($label, false); |
44 |
$this->_text = $text; |
if ($text === null) { |
45 |
|
$this->_text = $label; |
46 |
|
} else { |
47 |
|
$this->_text = $text; |
48 |
|
} |
49 |
} |
} |
50 |
|
|
51 |
/** |
/** |
66 |
return $this->_text; |
return $this->_text; |
67 |
} else { |
} else { |
68 |
return NULL; |
return NULL; |
69 |
} |
} |
70 |
} |
} |
71 |
|
|
72 |
/** |
/** |
80 |
$c = form_active_checkbox($this->get_element_name(), |
$c = form_active_checkbox($this->get_element_name(), |
81 |
$this->_text, |
$this->_text, |
82 |
$this->get_value(), |
$this->get_value(), |
83 |
"form_element"); |
"form_element", |
84 |
|
NULL, |
85 |
|
$this->is_disabled()); |
86 |
|
|
87 |
return $c; |
return $c; |
88 |
} |
} |
94 |
* It has no validation method. |
* It has no validation method. |
95 |
* |
* |
96 |
* |
* |
97 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
98 |
* @author Suren Markossian <suren@bcsweb.com> |
* @author Suren Markossian <suren@bcsweb.com> |
99 |
* @package phpHtmlLib |
* @package phpHtmlLib |
100 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
103 |
*/ |
*/ |
104 |
class FECheckBoxList extends FEMultiListBox { |
class FECheckBoxList extends FEMultiListBox { |
105 |
|
|
106 |
|
/** |
107 |
|
* Flag to tell us to render the check all |
108 |
|
* checkbox |
109 |
|
*/ |
110 |
|
var $_checkall_flag = FALSE; |
111 |
|
|
112 |
|
|
113 |
|
/** |
114 |
|
* This method is used to turn on/off |
115 |
|
* the magic 'check all' checkbox |
116 |
|
* |
117 |
|
* @param boolean |
118 |
|
*/ |
119 |
|
function enable_checkall($flag=TRUE) { |
120 |
|
$this->_checkall_flag = $flag; |
121 |
|
} |
122 |
|
|
123 |
|
|
124 |
|
/** |
125 |
|
* This returns the JS require to |
126 |
|
* do the work of the check all checkbox |
127 |
|
* |
128 |
|
* @return string |
129 |
|
*/ |
130 |
|
function javascript() { |
131 |
|
if (!$this->_checkall_flag) { |
132 |
|
return ''; |
133 |
|
} else { |
134 |
|
$js_name = $this->_js_checkall_name(); |
135 |
|
$id_name = 'id'.str_replace('[]','', |
136 |
|
str_replace('_','', |
137 |
|
$this->get_element_name())); |
138 |
|
$num = count($this->_data_list); |
139 |
|
|
140 |
|
$js_str = <<<JSEND |
141 |
|
|
142 |
|
function $js_name(fromlink) { |
143 |
|
var e_name = '$js_name'; |
144 |
|
var checkall = document.getElementById('id_$js_name'); |
145 |
|
var num = $num; |
146 |
|
var e; |
147 |
|
|
148 |
|
if (fromlink) { |
149 |
|
if (checkall.checked) { |
150 |
|
checkall.checked = false; |
151 |
|
} else { |
152 |
|
checkall.checked = true; |
153 |
|
} |
154 |
|
} |
155 |
|
|
156 |
|
state = checkall.checked; |
157 |
|
|
158 |
|
for (i=0;i<num;i++) { |
159 |
|
id_name = '$id_name'+i; |
160 |
|
e = document.getElementById(id_name); |
161 |
|
e.checked = state; |
162 |
|
} |
163 |
|
} |
164 |
|
|
165 |
|
|
166 |
|
JSEND; |
167 |
|
return $js_str; |
168 |
|
} |
169 |
|
} |
170 |
|
|
171 |
/** |
/** |
172 |
* This function builds and returns the |
* This function builds and returns the |
184 |
|
|
185 |
$attributes = $this->_build_element_attributes(); |
$attributes = $this->_build_element_attributes(); |
186 |
unset( $attributes["name"] ); |
unset( $attributes["name"] ); |
187 |
$c = new DIVtag($attributes); |
$div = new DIVtag($attributes); |
188 |
|
|
189 |
$element_name = $this->get_element_name(); |
$element_name = $this->get_element_name(); |
190 |
$selected_values = $this->get_value(); |
$selected_values = $this->get_value(); |
192 |
$x=0; |
$x=0; |
193 |
foreach ($this->_data_list as $text=>$value) { |
foreach ($this->_data_list as $text=>$value) { |
194 |
$name = str_replace("[]", "[$x]", $element_name); |
$name = str_replace("[]", "[$x]", $element_name); |
195 |
|
$id = str_replace('_','','id'.str_replace('[]','',$element_name).$x); |
196 |
$x++; |
$x++; |
197 |
$attributes = array("type"=>"checkbox", |
$attributes = array("type"=>"checkbox", |
198 |
"name"=>$name, |
"name"=>$name, |
199 |
|
"id"=>$id, |
200 |
"value"=>$value); |
"value"=>$value); |
201 |
|
|
202 |
if (is_array($selected_values) && in_array($value, $selected_values)) |
if (is_array($selected_values) && in_array($value, $selected_values)) |
204 |
|
|
205 |
$checkbox = new INPUTtag($attributes); |
$checkbox = new INPUTtag($attributes); |
206 |
|
|
207 |
if (isset($this->_disabled_items[$text])) { |
if ($this->is_disabled() || isset($this->_disabled_items[$text])) { |
208 |
$checkbox->set_tag_attribute("disabled"); |
$checkbox->set_tag_attribute("disabled", 'disabled'); |
209 |
$a = $text; |
$a = $text; |
210 |
} else { |
} else { |
211 |
$js_action = "javascript:elements['" . $name . "'].checked=!elements['".$name."'].checked;"; |
$js_action = "javascript:e=document.getElementById('" . $id . "'); e.checked=!e.checked;"; |
212 |
$a_attributes = array("href" => "javascript:void(0)", |
$a_attributes = array("href" => "javascript:void(0)", |
213 |
|
"class"=>"form_element", |
214 |
"onClick" => $js_action); |
"onClick" => $js_action); |
215 |
$a = new Atag($a_attributes, htmlspecialchars($text), FALSE); |
$a = new Atag($a_attributes, htmlspecialchars($text), FALSE); |
216 |
} |
} |
217 |
|
|
218 |
$check = container( $checkbox, $a ); |
$check = container( $checkbox, $a ); |
219 |
$check->set_collapse(); |
$check->set_collapse(); |
220 |
|
|
221 |
$c->push($check, html_br()); |
$div->push($check, html_br()); |
222 |
} |
} |
223 |
|
|
224 |
return $c; |
//build the checkall if needed |
225 |
} |
if ($this->_checkall_flag) { |
226 |
|
$name = $this->_js_checkall_name(); |
227 |
|
$onclick = "javascript:".$name."(false);"; |
228 |
|
|
229 |
|
$checkbox = new INPUTtag(array('type' => 'checkbox', 'value' => 0, |
230 |
|
'onclick' => $onclick, |
231 |
|
'id' => 'id_'.$name)); |
232 |
|
|
233 |
|
$onclick = "javascript:".$name."(true);"; |
234 |
|
$a = new Atag(array('href' => 'javascript:void(0)', |
235 |
|
'class' => 'form_element', |
236 |
|
'onclick' => $onclick), |
237 |
|
'Select All', FALSE); |
238 |
|
|
239 |
|
$check = container($checkbox, $a); |
240 |
|
|
241 |
|
//so we can get some nice spacing |
242 |
|
$check_div = new DIVtag(array('style' => 'padding-left:1px;padding-top:8px;'),$check); |
243 |
|
$check_div->set_collapse(); |
244 |
|
return container($div,$check_div); |
245 |
|
} |
246 |
|
return $div; |
247 |
|
} |
248 |
|
|
249 |
|
/** |
250 |
|
* This private method builds the name of the js |
251 |
|
* checkall function |
252 |
|
* |
253 |
|
* @return string |
254 |
|
*/ |
255 |
|
function _js_checkall_name() { |
256 |
|
return str_replace('[]', '',$this->get_element_name()."_checkall"); |
257 |
|
} |
258 |
|
|
259 |
} |
} |
260 |
?> |
?> |