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 |
21 |
* It has no validation method. |
* It has no validation method. |
22 |
* |
* |
23 |
* |
* |
24 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
25 |
* @author Suren Markossian <suren@bcsweb.com> |
* @author Suren Markossian <suren@bcsweb.com> |
26 |
* @package phpHtmlLib |
* @package phpHtmlLib |
27 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
38 |
var $_data_list = array(); |
var $_data_list = array(); |
39 |
|
|
40 |
/** |
/** |
41 |
|
* the br flag |
42 |
|
*/ |
43 |
|
var $_br_flag=FALSE; |
44 |
|
|
45 |
|
/** |
46 |
* The constructor |
* The constructor |
47 |
* |
* |
48 |
* @param label string - text label for the element |
* @param label string - text label for the element |
49 |
* @param array - the name => value pairs of the radio |
* @param array - the name => value pairs of the radio |
50 |
* buttons text => value |
* buttons text => value |
51 |
|
* @param boolean - required flag |
52 |
*/ |
*/ |
53 |
function FERadioGroup($label, $data_list=array()) { |
function FERadioGroup($label, $data_list=array(), $required=true) { |
54 |
$this->FormElement($label, true); |
$this->FormElement($label, $required); |
55 |
foreach ($data_list as $name=>$value) { |
foreach ($data_list as $name=>$value) { |
56 |
$this->_data_list[] = array($name=>$value); |
$this->_data_list[] = array($name=>$value); |
57 |
} |
} |
83 |
|
|
84 |
|
|
85 |
/** |
/** |
86 |
|
* This function is used to set the br flag |
87 |
|
* that will automatically add a BR tag after |
88 |
|
* each radio button |
89 |
|
* |
90 |
|
* @param boolean |
91 |
|
*/ |
92 |
|
function set_br_flag($flag=TRUE) { |
93 |
|
$this->_br_flag = $flag; |
94 |
|
} |
95 |
|
|
96 |
|
|
97 |
|
/** |
98 |
* This function builds and returns the |
* This function builds and returns the |
99 |
* form element object |
* form element object |
100 |
* |
* |
101 |
|
* @param int the index to get |
102 |
|
* @param boolean the br flag. |
103 |
|
* NOTE: the class's br flag takes precedence. |
104 |
* @return object |
* @return object |
105 |
*/ |
*/ |
106 |
function get_element($index=NULL, $br_flag=FALSE) { |
function get_element($index=NULL, $br_flag=FALSE) { |
107 |
$container = container(); |
$container = container(); |
108 |
|
|
109 |
if ($index == NULL) { |
if ($br_flag != $this->_br_flag) { |
110 |
|
$br_flag = $this->_br_flag; |
111 |
|
} |
112 |
|
|
113 |
|
if ($index === NULL) { |
114 |
$count = count( $this->_data_list ); |
$count = count( $this->_data_list ); |
115 |
for ($x=0;$x<=$count-1;$x++) { |
for ($x=0;$x<=$count-1;$x++) { |
116 |
if ($br_flag) { |
if ($br_flag) { |
122 |
|
|
123 |
} |
} |
124 |
} else { |
} else { |
125 |
$container->add( $this->_get_index_element($index), $br ); |
$container->add( $this->_get_index_element($index)); |
126 |
} |
} |
127 |
|
|
128 |
return $container; |
return $container; |
143 |
list($name, $value) = each($this->_data_list[$index]); |
list($name, $value) = each($this->_data_list[$index]); |
144 |
$attributes["value"] = $value; |
$attributes["value"] = $value; |
145 |
|
|
146 |
|
$id_name = $this->get_element_name().'_'.$index; |
147 |
|
$attributes['id'] = $id_name; |
148 |
|
|
149 |
|
$attr_onclick = isset($attributes["onclick"])?$attributes["onclick"]:""; |
150 |
|
|
151 |
if (($value == $this->get_value())) |
if (($value == $this->get_value())) |
152 |
$attributes[] = "checked"; |
$attributes[] = "checked"; |
156 |
//now build the href so we can click on it. |
//now build the href so we can click on it. |
157 |
$attr["class"] ="form_link"; |
$attr["class"] ="form_link"; |
158 |
$attr["href"] = "javascript:void(0)"; |
$attr["href"] = "javascript:void(0)"; |
159 |
$js = "javascript: function check(item){item.click();} ". |
|
160 |
"check(".$this->get_element_name().".item($index));"; |
$js = "e=document.getElementById('".$id_name."'); e.click();"; |
161 |
$attr["onclick"] = $js; |
$attr["onclick"] = $js.$attr_onclick; |
162 |
|
|
163 |
$href = new Atag($attr, $name); |
$href = new Atag($attr, $name); |
164 |
|
|
178 |
* It has no validation method. |
* It has no validation method. |
179 |
* |
* |
180 |
* |
* |
181 |
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
* @author Walter A. Boring IV <waboring@newsblob.com> |
182 |
* @author Suren Markossian <suren@bcsweb.com> |
* @author Suren Markossian <suren@bcsweb.com> |
183 |
* @package phpHtmlLib |
* @package phpHtmlLib |
184 |
* @subpackage FormProcessing |
* @subpackage FormProcessing |
204 |
$this->_data_list[] = array("No" => $no_value); |
$this->_data_list[] = array("No" => $no_value); |
205 |
} |
} |
206 |
} |
} |
207 |
|
|
208 |
|
|
209 |
|
/** |
210 |
|
* This is a special FERadioButtonGroup form element |
211 |
|
* that allows each of the radio buttons to show/hide |
212 |
|
* a div on the fly. |
213 |
|
* |
214 |
|
* @author Walter A. Boring IV <waboring@newsblob.com> |
215 |
|
* @author Suren Markossian <suren@bcsweb.com> |
216 |
|
* @package phpHtmlLib |
217 |
|
* @subpackage FormProcessing |
218 |
|
* |
219 |
|
* @copyright LGPL - See LICENCE |
220 |
|
*/ |
221 |
|
class FEActiveDIVRadioButtonGroup extends FERadioGroup { |
222 |
|
|
223 |
|
|
224 |
|
function javascript() { |
225 |
|
$name = $this->get_element_name(); |
226 |
|
|
227 |
|
$js = 'function '.$this->_form_name.'_'.$name."_activate(id) {\n"; |
228 |
|
$js .= " var e,o;\n"; |
229 |
|
$js .= " e = document.getElementById(id);\n"; |
230 |
|
|
231 |
|
foreach ($this->_data_list as $button) { |
232 |
|
list($name, $value) = each( $button ); |
233 |
|
$js .= " o = document.getElementById('".$this->_id_name($name)."');\n"; |
234 |
|
$js .= " o.style.display = 'none';\n"; |
235 |
|
} |
236 |
|
|
237 |
|
$js .= " e.style.display = 'block';\n}\n\n"; |
238 |
|
|
239 |
|
return $js; |
240 |
|
} |
241 |
|
|
242 |
|
|
243 |
|
/** |
244 |
|
* This method builds an individual Radio button |
245 |
|
* with its associated text |
246 |
|
* |
247 |
|
* @param int - the index |
248 |
|
* @return INPUTtag of type radio |
249 |
|
*/ |
250 |
|
function _get_index_element($index) { |
251 |
|
$element_name = $this->get_element_name(); |
252 |
|
|
253 |
|
$attributes = $this->_build_element_attributes(); |
254 |
|
$attributes["type"] = "radio"; |
255 |
|
|
256 |
|
list($name, $value) = each($this->_data_list[$index]); |
257 |
|
$attributes["value"] = $value; |
258 |
|
|
259 |
|
$id_name = $this->get_element_name().'_'.$index; |
260 |
|
$attributes['id'] = $id_name; |
261 |
|
|
262 |
|
$attributes['onclick'] = 'javascript:'.$this->_form_name.'_'.$element_name. |
263 |
|
"_activate('".$this->_id_name($name)."');"; |
264 |
|
|
265 |
|
if (($value == $this->get_value())) |
266 |
|
$attributes['checked'] = "checked"; |
267 |
|
|
268 |
|
$tag = new INPUTtag($attributes); |
269 |
|
|
270 |
|
//now build the href so we can click on it. |
271 |
|
$attr["class"] ="form_link"; |
272 |
|
$attr["href"] = "javascript:void(0)"; |
273 |
|
$js = "javascript: function check(item){item.click();} ". |
274 |
|
"check(".$element_name.".item($index));"; |
275 |
|
|
276 |
|
$js = "e=document.getElementById('".$id_name."'); e.click();"; |
277 |
|
$attr["onclick"] = $js; |
278 |
|
|
279 |
|
$href = new Atag($attr, $name); |
280 |
|
|
281 |
|
$c = container($tag, $href); |
282 |
|
$c->set_collapse(); |
283 |
|
return $c; |
284 |
|
} |
285 |
|
|
286 |
|
|
287 |
|
/** |
288 |
|
* This builds the magic div |
289 |
|
* |
290 |
|
* @param int the index |
291 |
|
* @return DIVtag object |
292 |
|
*/ |
293 |
|
function build_div($index) { |
294 |
|
//which one is selected? |
295 |
|
|
296 |
|
reset($this->_data_list[$index]); |
297 |
|
list($name, $value) = each($this->_data_list[$index]); |
298 |
|
|
299 |
|
$style = 'position:absolute;left:0px;top:0px;'; |
300 |
|
|
301 |
|
if ($value == $this->get_value()) { |
302 |
|
//ok this item is selected! |
303 |
|
//it needs to be visible first. |
304 |
|
$style .= 'visibility:visible;'; |
305 |
|
} else { |
306 |
|
$style .= 'visibility:hidden;'; |
307 |
|
} |
308 |
|
|
309 |
|
return new DIVtag(array('id' => $this->_id_name($name), |
310 |
|
'style' => $style)); |
311 |
|
} |
312 |
|
|
313 |
|
function _id_name($name) { |
314 |
|
return $this->_form_name.'_'.$this->get_element_name(). |
315 |
|
'_'.$this->_sanitize_string($name); |
316 |
|
} |
317 |
|
|
318 |
|
} |
319 |
?> |
?> |