1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the Text FormElement class. |
4 |
|
|
* |
5 |
jonen |
1.3 |
* $Id: FERadioGroup.inc,v 1.11 2004/03/25 21:02:59 hemna Exp $ |
6 |
jonen |
1.1 |
* |
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 |
jonen |
1.3 |
function get_value_text() { |
68 |
|
|
$value = $this->get_value(); |
69 |
jonen |
1.1 |
foreach( $this->_data_list as $arr) { |
70 |
|
|
$flip = array_flip($arr); |
71 |
jonen |
1.3 |
if (isset($flip[$value])) { |
72 |
jonen |
1.1 |
return $flip[$value]; |
73 |
|
|
} |
74 |
|
|
} |
75 |
|
|
return NULL; |
76 |
|
|
} |
77 |
|
|
|
78 |
|
|
|
79 |
|
|
/** |
80 |
|
|
* This function builds and returns the |
81 |
|
|
* form element object |
82 |
|
|
* |
83 |
|
|
* @return object |
84 |
|
|
*/ |
85 |
|
|
function get_element($index=NULL, $br_flag=FALSE) { |
86 |
|
|
$container = container(); |
87 |
|
|
|
88 |
|
|
if ($index == NULL) { |
89 |
|
|
$count = count( $this->_data_list ); |
90 |
|
|
for ($x=0;$x<=$count-1;$x++) { |
91 |
|
|
if ($br_flag) { |
92 |
|
|
$container->add( $this->_get_index_element($x), |
93 |
|
|
html_br()); |
94 |
|
|
} else { |
95 |
|
|
$container->add( $this->_get_index_element($x)); |
96 |
|
|
} |
97 |
|
|
|
98 |
|
|
} |
99 |
|
|
} else { |
100 |
|
|
$container->add( $this->_get_index_element($index), $br ); |
101 |
|
|
} |
102 |
|
|
|
103 |
|
|
return $container; |
104 |
|
|
} |
105 |
|
|
|
106 |
|
|
|
107 |
|
|
/** |
108 |
|
|
* This method builds an individual Radio button |
109 |
|
|
* with its associated text |
110 |
|
|
* |
111 |
|
|
* @param int - the index |
112 |
|
|
* @return INPUTtag of type radio |
113 |
|
|
*/ |
114 |
|
|
function _get_index_element($index) { |
115 |
|
|
$attributes = $this->_build_element_attributes(); |
116 |
|
|
$attributes["type"] = "radio"; |
117 |
|
|
|
118 |
|
|
list($name, $value) = each($this->_data_list[$index]); |
119 |
|
|
$attributes["value"] = $value; |
120 |
|
|
|
121 |
|
|
|
122 |
|
|
if (($value == $this->get_value())) |
123 |
|
|
$attributes[] = "checked"; |
124 |
|
|
|
125 |
|
|
$tag = new INPUTtag($attributes); |
126 |
|
|
|
127 |
|
|
//now build the href so we can click on it. |
128 |
|
|
$attr["class"] ="form_link"; |
129 |
jonen |
1.3 |
$attr["href"] = "javascript:void(0)"; |
130 |
jonen |
1.1 |
$js = "javascript: function check(item){item.click();} ". |
131 |
|
|
"check(".$this->get_element_name().".item($index));"; |
132 |
|
|
$attr["onclick"] = $js; |
133 |
|
|
|
134 |
|
|
$href = new Atag($attr, $name); |
135 |
|
|
|
136 |
|
|
$c = container($tag, $href); |
137 |
|
|
$c->set_collapse(); |
138 |
|
|
return $c; |
139 |
|
|
} |
140 |
|
|
} |
141 |
|
|
|
142 |
|
|
|
143 |
|
|
|
144 |
|
|
/** |
145 |
|
|
* This is the Yes/No Radio Button Group FormElement. |
146 |
|
|
* It builds a FERadioGroup with 2 radio buttons labeled |
147 |
|
|
* "Yes" and "No". |
148 |
|
|
* |
149 |
|
|
* It has no validation method. |
150 |
|
|
* |
151 |
|
|
* |
152 |
|
|
* @author Walter A. Boring IV <waboring@buildabetterweb.com> |
153 |
|
|
* @author Suren Markossian <suren@bcsweb.com> |
154 |
|
|
* @package phpHtmlLib |
155 |
|
|
* @subpackage FormProcessing |
156 |
|
|
* |
157 |
|
|
* @copyright LGPL - See LICENCE |
158 |
|
|
*/ |
159 |
|
|
class FEYesNoRadioGroup extends FERadioGroup { |
160 |
|
|
|
161 |
|
|
/** |
162 |
|
|
* The constructor |
163 |
|
|
* |
164 |
|
|
* @param label string - text label for the element |
165 |
|
|
* @param bool required - is this a required element |
166 |
jonen |
1.2 |
* @param string - the value to use for the 'yes' radio |
167 |
|
|
* NOTE: default is 'yes' |
168 |
|
|
* @param string - the value to use for the 'no' radio |
169 |
|
|
* NOTE: default is 'no' |
170 |
jonen |
1.1 |
*/ |
171 |
jonen |
1.2 |
function FEYesNoRadioGroup($label, $required = TRUE, |
172 |
|
|
$yes_value="yes", $no_value="no") { |
173 |
jonen |
1.1 |
$this->FormElement($label, $required); |
174 |
jonen |
1.2 |
$this->_data_list[] = array("Yes" => $yes_value); |
175 |
|
|
$this->_data_list[] = array("No" => $no_value); |
176 |
jonen |
1.1 |
} |
177 |
|
|
} |
178 |
|
|
?> |