1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the Text FormElement class. |
4 |
|
|
* |
5 |
|
|
* $Id: FERadioGroup.inc,v 1.7 2003/02/18 23:02:00 hemna Exp $ |
6 |
|
|
* |
7 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
8 |
|
|
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
|
|
* @package phpHtmlLib |
10 |
|
|
* @subpackage FormProcessing |
11 |
|
|
* |
12 |
|
|
* @copyright LGPL - See LICENCE |
13 |
|
|
* |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
/** |
17 |
|
|
* This is the Radio Button Group FormElement which builds a |
18 |
|
|
* List of Radio buttons that can be used in any |
19 |
|
|
* style of layout. |
20 |
|
|
* |
21 |
|
|
* It has no validation method. |
22 |
|
|
* |
23 |
|
|
* |
24 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
25 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
26 |
|
|
* @package phpHtmlLib |
27 |
|
|
* @subpackage FormProcessing |
28 |
|
|
* |
29 |
|
|
* @copyright LGPL - See LICENCE |
30 |
|
|
*/ |
31 |
|
|
class FERadioGroup extends FormElement { |
32 |
|
|
|
33 |
|
|
/** |
34 |
|
|
* Holds the list of available |
35 |
|
|
* data elements |
36 |
|
|
* |
37 |
|
|
*/ |
38 |
|
|
var $_data_list = array(); |
39 |
|
|
|
40 |
|
|
/** |
41 |
|
|
* The constructor |
42 |
|
|
* |
43 |
|
|
* @param label string - text label for the element |
44 |
|
|
* @param array - the name => value pairs of the radio |
45 |
|
|
* buttons text => value |
46 |
|
|
*/ |
47 |
|
|
function FERadioGroup($label, $data_list=array()) { |
48 |
|
|
$this->FormElement($label, true); |
49 |
|
|
foreach ($data_list as $name=>$value) { |
50 |
|
|
$this->_data_list[] = array($name=>$value); |
51 |
|
|
} |
52 |
|
|
} |
53 |
|
|
|
54 |
|
|
/** |
55 |
|
|
* This provides a method |
56 |
|
|
* for the FormContent |
57 |
|
|
* to get access to the |
58 |
|
|
* text associated with a |
59 |
|
|
* field. This is only available |
60 |
|
|
* on FormElements that have text |
61 |
|
|
* associated with a field. |
62 |
|
|
* It is used during Confirmation |
63 |
|
|
* |
64 |
|
|
* @param mixed - the value to look up |
65 |
|
|
* @return string - the text associated |
66 |
|
|
*/ |
67 |
|
|
function get_value_text($value) { |
68 |
|
|
foreach( $this->_data_list as $arr) { |
69 |
|
|
$flip = array_flip($arr); |
70 |
|
|
if ($flip[$value]) { |
71 |
|
|
return $flip[$value]; |
72 |
|
|
} |
73 |
|
|
} |
74 |
|
|
return NULL; |
75 |
|
|
} |
76 |
|
|
|
77 |
|
|
|
78 |
|
|
/** |
79 |
|
|
* This function builds and returns the |
80 |
|
|
* form element object |
81 |
|
|
* |
82 |
|
|
* @return object |
83 |
|
|
*/ |
84 |
|
|
function get_element($index=NULL, $br_flag=FALSE) { |
85 |
|
|
$container = container(); |
86 |
|
|
|
87 |
|
|
if ($index == NULL) { |
88 |
|
|
$count = count( $this->_data_list ); |
89 |
|
|
for ($x=0;$x<=$count-1;$x++) { |
90 |
|
|
if ($br_flag) { |
91 |
|
|
$container->add( $this->_get_index_element($x), |
92 |
|
|
html_br()); |
93 |
|
|
} else { |
94 |
|
|
$container->add( $this->_get_index_element($x)); |
95 |
|
|
} |
96 |
|
|
|
97 |
|
|
} |
98 |
|
|
} else { |
99 |
|
|
$container->add( $this->_get_index_element($index), $br ); |
100 |
|
|
} |
101 |
|
|
|
102 |
|
|
return $container; |
103 |
|
|
} |
104 |
|
|
|
105 |
|
|
|
106 |
|
|
/** |
107 |
|
|
* This method builds an individual Radio button |
108 |
|
|
* with its associated text |
109 |
|
|
* |
110 |
|
|
* @param int - the index |
111 |
|
|
* @return INPUTtag of type radio |
112 |
|
|
*/ |
113 |
|
|
function _get_index_element($index) { |
114 |
|
|
$attributes = $this->_build_element_attributes(); |
115 |
|
|
$attributes["type"] = "radio"; |
116 |
|
|
|
117 |
|
|
list($name, $value) = each($this->_data_list[$index]); |
118 |
|
|
$attributes["value"] = $value; |
119 |
|
|
|
120 |
|
|
|
121 |
|
|
if (($value == $this->get_value())) |
122 |
|
|
$attributes[] = "checked"; |
123 |
|
|
|
124 |
|
|
$tag = new INPUTtag($attributes); |
125 |
|
|
|
126 |
|
|
//now build the href so we can click on it. |
127 |
|
|
$attr["class"] ="form_link"; |
128 |
|
|
$attr["href"] = "#"; |
129 |
|
|
$js = "javascript: function check(item){item.click();} ". |
130 |
|
|
"check(".$this->get_element_name().".item($index));"; |
131 |
|
|
$attr["onclick"] = $js; |
132 |
|
|
|
133 |
|
|
$href = new Atag($attr, $name); |
134 |
|
|
|
135 |
|
|
$c = container($tag, $href); |
136 |
|
|
$c->set_collapse(); |
137 |
|
|
return $c; |
138 |
|
|
} |
139 |
|
|
} |
140 |
|
|
|
141 |
|
|
|
142 |
|
|
|
143 |
|
|
/** |
144 |
|
|
* This is the Yes/No Radio Button Group FormElement. |
145 |
|
|
* It builds a FERadioGroup with 2 radio buttons labeled |
146 |
|
|
* "Yes" and "No". |
147 |
|
|
* |
148 |
|
|
* It has no validation method. |
149 |
|
|
* |
150 |
|
|
* |
151 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
152 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
153 |
|
|
* @package phpHtmlLib |
154 |
|
|
* @subpackage FormProcessing |
155 |
|
|
* |
156 |
|
|
* @copyright LGPL - See LICENCE |
157 |
|
|
*/ |
158 |
|
|
class FEYesNoRadioGroup extends FERadioGroup { |
159 |
|
|
|
160 |
|
|
/** |
161 |
|
|
* The constructor |
162 |
|
|
* |
163 |
|
|
* @param label string - text label for the element |
164 |
|
|
* @param bool required - is this a required element |
165 |
|
|
*/ |
166 |
|
|
function FEYesNoRadioGroup($label, $required = TRUE) { |
167 |
|
|
$this->FormElement($label, $required); |
168 |
|
|
$this->_data_list[] = array("Yes" => "yes"); |
169 |
|
|
$this->_data_list[] = array("No" => "no"); |
170 |
|
|
} |
171 |
|
|
} |
172 |
|
|
?> |