1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
jonen |
1.4 |
* This file contains the FEListBox, FEMultiListBox |
4 |
jonen |
1.1 |
* |
5 |
jonen |
1.4 |
* $Id: FEListBox.inc,v 1.47.2.3 2005/05/12 01:24:02 hemna Exp $ |
6 |
jonen |
1.1 |
* |
7 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
8 |
jonen |
1.1 |
* @author Suren Markosyan <suren@bcsweb.com> |
9 |
|
|
* @package phpHtmlLib |
10 |
|
|
* @subpackage FormProcessing |
11 |
|
|
* |
12 |
|
|
* @copyright LGPL - See LICENCE |
13 |
|
|
* |
14 |
|
|
*/ |
15 |
|
|
|
16 |
|
|
/** |
17 |
jonen |
1.4 |
* This is the ListBox FormElement which builds a |
18 |
|
|
* select field with all of its options. |
19 |
jonen |
1.1 |
* It has no validation method. |
20 |
|
|
* |
21 |
jonen |
1.4 |
* |
22 |
|
|
* @author Walter A. Boring IV <waboring@newsblob.com> |
23 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
24 |
|
|
* @package phpHtmlLib |
25 |
|
|
* @subpackage FormProcessing |
26 |
|
|
* |
27 |
|
|
* @copyright LGPL - See LICENCE |
28 |
|
|
*/ |
29 |
|
|
class FEListBox extends FEDataList { |
30 |
|
|
|
31 |
|
|
/** |
32 |
|
|
* This function builds and returns the |
33 |
|
|
* form element object |
34 |
|
|
* |
35 |
|
|
* @return object |
36 |
|
|
*/ |
37 |
|
|
function get_element() { |
38 |
|
|
|
39 |
|
|
$attributes = $this->_build_element_attributes(); |
40 |
|
|
|
41 |
|
|
if ($this->_height) { |
42 |
|
|
$attributes["size"] = 5; |
43 |
|
|
} |
44 |
|
|
|
45 |
|
|
$selected_value = $this->get_value(); |
46 |
|
|
|
47 |
|
|
$tag = new SELECTtag($attributes); |
48 |
|
|
|
49 |
|
|
foreach ($this->_data_list as $name=>$value) { |
50 |
|
|
|
51 |
|
|
$attributes = array("value"=>$value); |
52 |
jonen |
1.3 |
if ($value == $selected_value) { |
53 |
jonen |
1.4 |
$attributes['selected'] = "selected"; |
54 |
jonen |
1.3 |
} |
55 |
|
|
if (isset($this->_disabled_items[$name])) { |
56 |
jonen |
1.4 |
$attributes['disabled'] = "disabled"; |
57 |
jonen |
1.3 |
} |
58 |
jonen |
1.1 |
|
59 |
jonen |
1.4 |
$tag->add(new OPTIONtag($attributes, htmlspecialchars($name))); |
60 |
jonen |
1.1 |
} |
61 |
|
|
return $tag; |
62 |
|
|
} |
63 |
|
|
} |
64 |
jonen |
1.2 |
|
65 |
|
|
/** |
66 |
|
|
* Build a Yes/No Select box |
67 |
|
|
* |
68 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
69 |
jonen |
1.2 |
* @author Suren Markossian <suren@bcsweb.com> |
70 |
|
|
* @package phpHtmlLib |
71 |
|
|
* @subpackage FormProcessing |
72 |
|
|
* |
73 |
|
|
* @copyright LGPL - See LICENCE |
74 |
|
|
*/ |
75 |
|
|
class FEYesNoListBox extends FEListBox { |
76 |
|
|
|
77 |
|
|
/** |
78 |
|
|
* The Constructor |
79 |
jonen |
1.4 |
* |
80 |
jonen |
1.2 |
* @param label string - text label for the element |
81 |
|
|
* @param bool required - is this a required element |
82 |
|
|
* @param array data_list - list of data elements (name=>value) |
83 |
|
|
* @param int required - element width in characters, pixels (px), percentage (%) or elements (em) |
84 |
|
|
* @param string - the value to use for the 'yes' radio |
85 |
|
|
* NOTE: default is 'yes' |
86 |
|
|
* @param string - the value to use for the 'no' radio |
87 |
|
|
* NOTE: default is 'no' |
88 |
|
|
*/ |
89 |
|
|
function FEYesNoListBox($label, $required = TRUE, $width = NULL, $height = NULL, |
90 |
|
|
$yes_value="yes", $no_value="no") { |
91 |
|
|
$options = array("Yes" => $yes_value, "No" => $no_value); |
92 |
|
|
$this->FEListBox($label, $required, $width, $height, $options); |
93 |
|
|
} |
94 |
|
|
} |
95 |
jonen |
1.3 |
|
96 |
|
|
|
97 |
|
|
/** |
98 |
|
|
* This class builds a nested select box that |
99 |
|
|
* is used to select an entry from nested levels. |
100 |
jonen |
1.4 |
* |
101 |
|
|
* NOTE: The data array must be in the format |
102 |
jonen |
1.3 |
* array("test" => "testvalue", |
103 |
|
|
* "nestedtest" => array("value" => "nestedtestvalue", |
104 |
|
|
* "items" => array( "foo" => "foovalue", |
105 |
|
|
* "bar" => "barvalue")); |
106 |
jonen |
1.4 |
* |
107 |
jonen |
1.3 |
* Example |
108 |
|
|
* $data = array("Test" => 1, |
109 |
|
|
* "Foo" => array("value" => 2, |
110 |
|
|
* "items" => array("Blah" => 3, |
111 |
|
|
* "php" => 4)), |
112 |
|
|
* "Bar" => array("value" => 5, |
113 |
|
|
* "items" => array("testing" => array("value" => 6, |
114 |
|
|
* "items" => array("ugh" => 7)), |
115 |
|
|
* "again" => 8))); |
116 |
jonen |
1.4 |
* |
117 |
jonen |
1.3 |
* would result in |
118 |
jonen |
1.4 |
* |
119 |
jonen |
1.3 |
* <select > |
120 |
|
|
* <option value="1">Test</option> |
121 |
|
|
* <option value="2">Foo</option> |
122 |
|
|
* <option value="3"> Blah</option> |
123 |
|
|
* <option value="4"> php</option> |
124 |
|
|
* <option value="5">Bar</option> |
125 |
|
|
* <option value="6"> testing</option> |
126 |
|
|
* <option value="7"> ugh</option> |
127 |
|
|
* <option value="8"> again</option> |
128 |
|
|
* </select> |
129 |
jonen |
1.4 |
* |
130 |
|
|
* |
131 |
|
|
* @author Walter A. Boring IV <waboring@newsblob.com> |
132 |
jonen |
1.3 |
* @package phpHtmlLib |
133 |
|
|
* @subpackage FormProcessing |
134 |
|
|
* |
135 |
|
|
* @copyright LGPL - See LICENCE |
136 |
|
|
*/ |
137 |
|
|
class FENestedListBox extends FEDataList { |
138 |
|
|
|
139 |
|
|
/** |
140 |
|
|
* This function builds and returns the |
141 |
|
|
* form element object |
142 |
|
|
* |
143 |
|
|
* @return object |
144 |
|
|
*/ |
145 |
|
|
function get_element() { |
146 |
|
|
|
147 |
|
|
$attributes = $this->_build_element_attributes(); |
148 |
|
|
|
149 |
|
|
if ($this->_height) { |
150 |
|
|
$attributes["size"] = 5; |
151 |
jonen |
1.4 |
} |
152 |
jonen |
1.3 |
|
153 |
|
|
$tag = new SELECTtag($attributes); |
154 |
|
|
|
155 |
|
|
$this->_add_array($this->_data_list, 0, $tag); |
156 |
|
|
return $tag; |
157 |
|
|
} |
158 |
|
|
|
159 |
|
|
|
160 |
|
|
/** |
161 |
|
|
* |
162 |
|
|
* This function is responsible for performing complete |
163 |
|
|
* validation and setting the appropriate error message |
164 |
|
|
* in case of a failed validation |
165 |
|
|
* |
166 |
|
|
* @param FormValidation object |
167 |
|
|
*/ |
168 |
|
|
function validate(&$_FormValidation) { |
169 |
|
|
// we make sure that the value is in the data list |
170 |
|
|
$value = $this->get_value(); |
171 |
|
|
|
172 |
|
|
if (!$this->_array_search_r($value, $this->_data_list, $temp)) { |
173 |
|
|
$this->set_error_message("Invalid value"); |
174 |
|
|
return FALSE; |
175 |
|
|
} |
176 |
|
|
return TRUE; |
177 |
|
|
} |
178 |
jonen |
1.4 |
|
179 |
|
|
|
180 |
|
|
function _array_search_r($needle, $haystack, &$item) { |
181 |
jonen |
1.3 |
//xxx($needle); |
182 |
|
|
$match = FALSE; |
183 |
|
|
|
184 |
jonen |
1.4 |
foreach($haystack as $name=>$value) { |
185 |
jonen |
1.3 |
if (is_array($value)) { |
186 |
|
|
if ($value["value"] == $needle) { |
187 |
|
|
$item = $name; |
188 |
|
|
$match = TRUE; |
189 |
|
|
} else { |
190 |
|
|
$match = $this->_array_search_r($needle, $value["items"], $item); |
191 |
|
|
$item = $name."::".$item; |
192 |
jonen |
1.4 |
} |
193 |
jonen |
1.3 |
} else if ($value==$needle) { |
194 |
|
|
$item = $name; |
195 |
|
|
$match = TRUE; |
196 |
|
|
} |
197 |
|
|
|
198 |
jonen |
1.4 |
if ($match) |
199 |
jonen |
1.3 |
return TRUE; |
200 |
|
|
} |
201 |
|
|
return $match; |
202 |
|
|
} |
203 |
|
|
|
204 |
|
|
|
205 |
|
|
/** |
206 |
|
|
* This provides a method |
207 |
|
|
* for the FormContent |
208 |
jonen |
1.4 |
* to get access to the |
209 |
jonen |
1.3 |
* text associated with a |
210 |
|
|
* field. This is only available |
211 |
|
|
* on FormElements that have text |
212 |
|
|
* associated with a field. |
213 |
|
|
* It is used during Confirmation |
214 |
|
|
* |
215 |
|
|
* @return string - the text associated |
216 |
|
|
*/ |
217 |
|
|
function get_value_text() { |
218 |
jonen |
1.4 |
$ret = $this->_array_search_r($this->get_value(), |
219 |
jonen |
1.3 |
$this->_data_list, $item); |
220 |
|
|
return $item; |
221 |
|
|
} |
222 |
|
|
|
223 |
|
|
|
224 |
|
|
/** |
225 |
jonen |
1.4 |
* This is a recursive function used to add |
226 |
jonen |
1.3 |
* an array of layers to the select box. |
227 |
jonen |
1.4 |
* |
228 |
jonen |
1.3 |
* @param array - the next level of name=>value pairs |
229 |
|
|
* @param int - the level |
230 |
|
|
* @param SELECTtag - the SELECTtag object to add the options |
231 |
|
|
* @return none |
232 |
|
|
*/ |
233 |
|
|
function _add_array($layer_arr, $level, &$tag) { |
234 |
|
|
if (!is_array($layer_arr)) { |
235 |
|
|
return; |
236 |
|
|
} |
237 |
|
|
|
238 |
|
|
foreach( $layer_arr as $name=>$value) { |
239 |
|
|
if (is_array($value)) { |
240 |
|
|
$tag->add( $this->_build_option($name, $value["value"], $level)); |
241 |
|
|
$this->_add_array($value["items"], $level+1, $tag); |
242 |
jonen |
1.4 |
} else { |
243 |
|
|
|
244 |
jonen |
1.3 |
$tag->add($this->_build_option($name, $value, $level)); |
245 |
|
|
} |
246 |
|
|
} |
247 |
|
|
} |
248 |
|
|
|
249 |
|
|
/** |
250 |
|
|
* This method builds the actual OPTIONtag object |
251 |
jonen |
1.4 |
* |
252 |
jonen |
1.3 |
* @param string the name |
253 |
|
|
* @param string the value |
254 |
|
|
* @param int the level |
255 |
|
|
* @return OPTIONtag object |
256 |
|
|
*/ |
257 |
|
|
function _build_option($name, $value, $level) { |
258 |
|
|
$selected_value = $this->get_value(); |
259 |
jonen |
1.4 |
|
260 |
jonen |
1.3 |
$attributes = array("value"=>$value); |
261 |
|
|
if ($value == $selected_value) { |
262 |
jonen |
1.4 |
$attributes['selected'] = "selected"; |
263 |
jonen |
1.3 |
} |
264 |
jonen |
1.4 |
|
265 |
jonen |
1.3 |
if (isset($this->_disabled_items[$name])) { |
266 |
jonen |
1.4 |
$attributes['disabled'] = "disabled"; |
267 |
jonen |
1.3 |
} |
268 |
jonen |
1.4 |
|
269 |
jonen |
1.3 |
return new OPTIONtag($attributes, $this->_layer_name($name, $level)); |
270 |
|
|
} |
271 |
|
|
|
272 |
|
|
/** |
273 |
|
|
* This builds a layer's name |
274 |
jonen |
1.4 |
* |
275 |
jonen |
1.3 |
* @param string - original name |
276 |
|
|
* @param int the layer level |
277 |
|
|
* @return string the new name |
278 |
|
|
*/ |
279 |
|
|
function _layer_name($name, $level) { |
280 |
|
|
$newname = ''; |
281 |
|
|
|
282 |
|
|
if ($level == 0) { |
283 |
|
|
return $name; |
284 |
|
|
} else { |
285 |
|
|
$newname .= str_repeat(_HTML_SPACE, $level*2).$name; |
286 |
|
|
} |
287 |
jonen |
1.4 |
|
288 |
jonen |
1.3 |
return $newname; |
289 |
|
|
} |
290 |
|
|
} |
291 |
jonen |
1.4 |
|
292 |
jonen |
1.1 |
|
293 |
|
|
/** |
294 |
jonen |
1.4 |
* This is the MultiListBox FormElement which builds a |
295 |
jonen |
1.1 |
* select field with all of its options. It enables |
296 |
|
|
* the ability to have multiple selections. |
297 |
|
|
* It has no validation method. |
298 |
|
|
* |
299 |
jonen |
1.4 |
* |
300 |
|
|
* @author Walter A. Boring IV <waboring@newsblob.com> |
301 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
302 |
|
|
* @package phpHtmlLib |
303 |
|
|
* @subpackage FormProcessing |
304 |
|
|
* |
305 |
|
|
* @copyright LGPL - See LICENCE |
306 |
|
|
*/ |
307 |
|
|
class FEMultiListBox extends FEListBox { |
308 |
|
|
|
309 |
|
|
|
310 |
|
|
/** |
311 |
|
|
* This function creates element name |
312 |
|
|
* used in the form based on the text label |
313 |
|
|
* or any other parameters |
314 |
|
|
* |
315 |
|
|
* Overriding things function to make sure |
316 |
|
|
* an array is created instead of a single variable |
317 |
|
|
*/ |
318 |
|
|
function create_element_name() { |
319 |
|
|
|
320 |
|
|
parent::create_element_name(); |
321 |
|
|
|
322 |
|
|
$this->_element_name .= "[]"; |
323 |
|
|
} |
324 |
|
|
|
325 |
|
|
/** |
326 |
jonen |
1.3 |
* build the string for the confirmation page |
327 |
jonen |
1.4 |
* |
328 |
jonen |
1.3 |
* @return string |
329 |
|
|
*/ |
330 |
|
|
function get_value_text() { |
331 |
|
|
$value = $this->get_value(); |
332 |
|
|
if (empty($value)) { |
333 |
|
|
return ''; |
334 |
|
|
} |
335 |
|
|
|
336 |
|
|
$data_flip = array_flip( $this->_data_list ); |
337 |
|
|
foreach( $value as $val ) { |
338 |
|
|
$ret[] = $data_flip[$val]; |
339 |
|
|
} |
340 |
|
|
return implode(", ", $ret); |
341 |
|
|
} |
342 |
|
|
|
343 |
|
|
/** |
344 |
jonen |
1.1 |
* This function builds and returns the |
345 |
|
|
* form element object |
346 |
|
|
* |
347 |
|
|
* @return object |
348 |
|
|
*/ |
349 |
|
|
function get_element() { |
350 |
|
|
|
351 |
|
|
$attributes = $this->_build_element_attributes(); |
352 |
|
|
|
353 |
jonen |
1.4 |
$attributes['multiple'] = "multiple"; |
354 |
jonen |
1.1 |
|
355 |
|
|
if ($this->_height) { |
356 |
|
|
$attributes["size"] = 5; |
357 |
|
|
} |
358 |
|
|
|
359 |
|
|
$selected_values = $this->get_value(); |
360 |
|
|
|
361 |
|
|
$tag = new SELECTtag($attributes); |
362 |
|
|
|
363 |
|
|
foreach ($this->_data_list as $name=>$value) { |
364 |
|
|
|
365 |
|
|
$attributes = array("value"=>$value); |
366 |
jonen |
1.3 |
if (is_array($selected_values) && in_array($value, $selected_values)) { |
367 |
jonen |
1.4 |
$attributes['selected'] = "selected"; |
368 |
jonen |
1.3 |
} |
369 |
|
|
if (isset($this->_disabled_items[$name])) { |
370 |
jonen |
1.4 |
$attributes['disabled'] = "disabled"; |
371 |
jonen |
1.3 |
} |
372 |
jonen |
1.1 |
|
373 |
|
|
$tag->add(new OPTIONtag($attributes, $name)); |
374 |
|
|
} |
375 |
|
|
return $tag; |
376 |
|
|
} |
377 |
|
|
} |
378 |
jonen |
1.3 |
|
379 |
|
|
/** |
380 |
|
|
* This class builds a FEDataList that shows |
381 |
|
|
* a select box for States of the U.S.A. |
382 |
jonen |
1.4 |
* |
383 |
jonen |
1.3 |
* @author Walter A. Boring IV |
384 |
|
|
*/ |
385 |
|
|
class FEUnitedStates extends FEListBox { |
386 |
|
|
|
387 |
|
|
/** |
388 |
|
|
* The states array |
389 |
|
|
* @var array |
390 |
|
|
*/ |
391 |
|
|
var $_states = array("Select State" => "", |
392 |
|
|
"Alabama" => "AL", |
393 |
|
|
"Alaska" => "AK", |
394 |
|
|
"Arizona" => "AZ", |
395 |
|
|
"Arkansas" => "AR", |
396 |
|
|
"California" => "CA", |
397 |
|
|
"Colorado" => "CO", |
398 |
|
|
"Connecticut" => "CT", |
399 |
|
|
"Deleware" => "DE", |
400 |
|
|
"District of Columbia" => "DC", |
401 |
|
|
"Florida" => "FL", |
402 |
|
|
"Georgia" => "GA", |
403 |
|
|
"Hawaii" => "HI", |
404 |
|
|
"Idaho" => "ID", |
405 |
|
|
"Illinois" => "IL", |
406 |
|
|
"Indiana" => "IN", |
407 |
|
|
"Iowa" => "IA", |
408 |
|
|
"Kansas" => "KS", |
409 |
|
|
"Kentucky" => "KY", |
410 |
|
|
"Louisiana" => "LA", |
411 |
|
|
"Maine" => "ME", |
412 |
|
|
"Maryland" => "MD", |
413 |
|
|
"Massachusetts" => "MA", |
414 |
|
|
"Michigan" => "MI", |
415 |
|
|
"Minnesota" => "MN", |
416 |
|
|
"Mississippi" => "MS", |
417 |
|
|
"Missouri" => "MO", |
418 |
|
|
"Montana" => "MT", |
419 |
|
|
"Nebraska" => "NE", |
420 |
|
|
"Nevada" => "NV", |
421 |
|
|
"New Hampshire" => "NH", |
422 |
|
|
"New Jersey" => "NJ", |
423 |
|
|
"New Mexico" => "NM", |
424 |
|
|
"New York" => "NY", |
425 |
|
|
"North Carolina" => "NC", |
426 |
|
|
"North Dakota" => "ND", |
427 |
|
|
"Ohio" => "OH", |
428 |
|
|
"Oklahoma" => "OK", |
429 |
|
|
"Oregon" => "OR", |
430 |
|
|
"Pennsylvania" => "PA", |
431 |
|
|
"Rhode Island" => "RI", |
432 |
|
|
"South Carolina" => "SC", |
433 |
|
|
"South Dakota" => "SD", |
434 |
|
|
"Tennessee" => "TN", |
435 |
|
|
"Texas" => "TX", |
436 |
|
|
"Utah" => "UT", |
437 |
|
|
"Vermont" => "VT", |
438 |
|
|
"Virginia" => "VA", |
439 |
|
|
"Washington" => "WA", |
440 |
|
|
"West Virginia" => "WV", |
441 |
|
|
"Wisconsin" => "WI", |
442 |
|
|
"Wyoming" => "WY", |
443 |
|
|
"Puerto Rico" => "PR", |
444 |
|
|
"Virgin Island" => "VI", |
445 |
|
|
"Northern Mariana Islands" => "MP", |
446 |
|
|
"Guam" => "GU", |
447 |
|
|
"American Samoa" => "AS", |
448 |
|
|
"Palau" => "PW", |
449 |
jonen |
1.4 |
); |
450 |
jonen |
1.3 |
|
451 |
|
|
/** |
452 |
|
|
* The constructor |
453 |
jonen |
1.4 |
* |
454 |
jonen |
1.3 |
* @param string text label for the element |
455 |
|
|
* @param boolean is this a required element? |
456 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
457 |
|
|
* @param int element height in px |
458 |
|
|
* @param array data_list - list of data elements (name=>value) |
459 |
|
|
*/ |
460 |
|
|
function FEUnitedStates($label, $required = TRUE, $width = NULL, $height = NULL) { |
461 |
|
|
$this->FEListBox($label, $required, $width, $height, $this->_states); |
462 |
|
|
} |
463 |
|
|
} |
464 |
|
|
|
465 |
jonen |
1.4 |
/** |
466 |
|
|
* This class builds a FEDataList that shows |
467 |
|
|
* a select box for states of the European Union. |
468 |
|
|
*/ |
469 |
|
|
class FEEuropeanUnion extends FEListBox { |
470 |
|
|
/** |
471 |
|
|
* The states array |
472 |
|
|
* @var array |
473 |
|
|
*/ |
474 |
|
|
var $_states = array("Select State" => "", |
475 |
|
|
"Belgium" => "be", |
476 |
|
|
"Denmark" => "dk", |
477 |
|
|
"Germany" => "de", |
478 |
|
|
"Greece" => "gr", |
479 |
|
|
"Spain" => "es", |
480 |
|
|
"France" => "fr", |
481 |
|
|
"Ireland" => "ie", |
482 |
|
|
"Italy" => "it", |
483 |
|
|
"Luxembourg" => "lu", |
484 |
|
|
"The Netherlands" => "nl", |
485 |
|
|
"Austria" => "at", |
486 |
|
|
"Portugal" => "pt", |
487 |
|
|
"Finland" => "fi", |
488 |
|
|
"Sweden" => "se", |
489 |
|
|
"United Kingdom" => "uk", |
490 |
|
|
"Czech Republic" => "cz", |
491 |
|
|
"Estonia" => "ee", |
492 |
|
|
"Cyprus" => "cy", |
493 |
|
|
"Latvia" => "lv", |
494 |
|
|
"Lithuania" => "lt", |
495 |
|
|
"Hungary" => "hu", |
496 |
|
|
"Malta" => "mt", |
497 |
|
|
"Poland" => "pl", |
498 |
|
|
"Slovenia" => "si", |
499 |
|
|
"Slovakia" => "sk", |
500 |
|
|
); |
501 |
|
|
|
502 |
|
|
/** |
503 |
|
|
* The constructor |
504 |
|
|
* |
505 |
|
|
* @param string text label for the element |
506 |
|
|
* @param boolean is this a required element? |
507 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
508 |
|
|
* @param int element height in px |
509 |
|
|
* @param array data_list - list of data elements (name=>value) |
510 |
|
|
*/ |
511 |
|
|
function FEEuropeanUnion($label, $required = TRUE, $width = NULL, $height = NULL) { |
512 |
|
|
$this->FEListBox($label, $required, $width, $height, $this->_states); |
513 |
|
|
} |
514 |
|
|
} |
515 |
|
|
|
516 |
jonen |
1.3 |
|
517 |
|
|
/** |
518 |
|
|
* This builds a complex dual select box |
519 |
|
|
* with buttons to move entries from one |
520 |
|
|
* select box to another. |
521 |
jonen |
1.4 |
* |
522 |
jonen |
1.3 |
* From Actions To |
523 |
|
|
* -------- Add >> -------- |
524 |
|
|
* |------| Add All |------| |
525 |
|
|
* |------| |------| |
526 |
|
|
* |------| |------| |
527 |
|
|
* |------| << Remove |------| |
528 |
|
|
* |------| Remove All |------| |
529 |
|
|
* |------| |------| |
530 |
|
|
* -------- -------- |
531 |
jonen |
1.4 |
* |
532 |
jonen |
1.3 |
* @author Walter A. Boring IV |
533 |
|
|
*/ |
534 |
|
|
class FEComboListBox extends FEDataList { |
535 |
|
|
|
536 |
|
|
|
537 |
|
|
/** |
538 |
|
|
* Holds the list of available |
539 |
jonen |
1.4 |
* data elements for the 'to' |
540 |
jonen |
1.3 |
* box. |
541 |
|
|
* |
542 |
|
|
*/ |
543 |
|
|
var $_data_list_to = array(); |
544 |
|
|
|
545 |
|
|
/** |
546 |
|
|
* The from field's label |
547 |
jonen |
1.4 |
* |
548 |
jonen |
1.3 |
* @var string |
549 |
|
|
*/ |
550 |
|
|
var $_from_label = 'Available'; |
551 |
|
|
|
552 |
|
|
/** |
553 |
|
|
* The to field's label |
554 |
jonen |
1.4 |
* |
555 |
jonen |
1.3 |
* @var string |
556 |
|
|
*/ |
557 |
|
|
var $_to_label = 'Selected'; |
558 |
|
|
|
559 |
|
|
/** |
560 |
|
|
* This Form Element needs to |
561 |
jonen |
1.4 |
* propogate some js to the |
562 |
jonen |
1.3 |
* Form tag's onsubmit attribute |
563 |
jonen |
1.4 |
* |
564 |
jonen |
1.3 |
* @var string |
565 |
|
|
*/ |
566 |
|
|
var $_has_form_on_submit = true; |
567 |
|
|
|
568 |
|
|
|
569 |
|
|
/** |
570 |
|
|
* The constructor |
571 |
jonen |
1.4 |
* |
572 |
jonen |
1.3 |
* @param string text label for the element |
573 |
|
|
* @param boolean is this a required element? |
574 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
575 |
|
|
* @param int element height in px |
576 |
|
|
* @param array list of 'from' field data elements (name=>value) |
577 |
|
|
* @param array list of 'to' field data elements (name=>value) |
578 |
|
|
*/ |
579 |
jonen |
1.4 |
function FEComboListBox($label, $required = TRUE, $width="200px", $height="100px", |
580 |
jonen |
1.3 |
$from_data_list = array(), $to_data_list = array()) { |
581 |
|
|
$this->set_to_list_data($to_data_list); |
582 |
jonen |
1.4 |
$this->FEDataList($label, $required, $width, $height, $from_data_list); |
583 |
jonen |
1.3 |
} |
584 |
|
|
|
585 |
|
|
/** |
586 |
|
|
* This function sets the array of data |
587 |
|
|
* to be used in the data list |
588 |
|
|
* |
589 |
|
|
* @param array data_list - list of data elements (name=>value) |
590 |
|
|
*/ |
591 |
|
|
function set_to_list_data( $data_list = array() ) { |
592 |
|
|
$this->_data_list_to = $data_list; |
593 |
|
|
} |
594 |
|
|
|
595 |
|
|
/** |
596 |
|
|
* Use this method to set the label for the |
597 |
|
|
* 'from' field |
598 |
jonen |
1.4 |
* |
599 |
jonen |
1.3 |
* @param string |
600 |
|
|
* @return none |
601 |
|
|
*/ |
602 |
|
|
function set_from_label($label) { |
603 |
|
|
$this->_from_label = $label; |
604 |
|
|
} |
605 |
|
|
|
606 |
|
|
/** |
607 |
|
|
* Use this method to set the label for the |
608 |
|
|
* 'to' field |
609 |
jonen |
1.4 |
* |
610 |
jonen |
1.3 |
* @param string |
611 |
|
|
* @return none |
612 |
|
|
*/ |
613 |
|
|
function set_to_label($label) { |
614 |
|
|
$this->_to_label = $label; |
615 |
|
|
} |
616 |
|
|
|
617 |
|
|
|
618 |
|
|
/** |
619 |
jonen |
1.4 |
* This returns the initial value of |
620 |
|
|
* the element |
621 |
|
|
* |
622 |
|
|
* @return mixed |
623 |
|
|
*/ |
624 |
|
|
function get_init_value() { |
625 |
|
|
if ($this->_data_list_to) { |
626 |
|
|
return $this->_data_list_to; |
627 |
|
|
} else { |
628 |
|
|
return parent::get_init_value(); |
629 |
|
|
} |
630 |
|
|
} |
631 |
|
|
|
632 |
|
|
|
633 |
|
|
/** |
634 |
jonen |
1.3 |
* This function will set the |
635 |
|
|
* initial value for the element |
636 |
|
|
* |
637 |
|
|
* @param value mixed |
638 |
|
|
*/ |
639 |
|
|
function set_value($value) { |
640 |
|
|
//we need to see if we need to modify the |
641 |
jonen |
1.4 |
//the 2 data sets so the values of each are |
642 |
jonen |
1.3 |
//correctly displayed. |
643 |
jonen |
1.4 |
|
644 |
|
|
|
645 |
|
|
if (array_key_exists($this->_element_name, $_REQUEST)) { |
646 |
jonen |
1.3 |
$all_list = array_merge( $this->_data_list, $this->_data_list_to); |
647 |
|
|
|
648 |
|
|
if (isset($_REQUEST[$this->_element_name])) { |
649 |
|
|
$diff = array_diff( $all_list, $_REQUEST[$this->_element_name]); |
650 |
|
|
$this->set_list_data( $diff ); |
651 |
|
|
$to_list = array(); |
652 |
jonen |
1.4 |
|
653 |
jonen |
1.3 |
if (is_array($_REQUEST[$this->_element_name])) { |
654 |
|
|
foreach( $_REQUEST[$this->_element_name] as $value ) { |
655 |
|
|
$key = array_search($value, $all_list); |
656 |
|
|
if ($key) { |
657 |
|
|
$to_list[$key] = $value; |
658 |
jonen |
1.4 |
} |
659 |
jonen |
1.3 |
} |
660 |
|
|
} else { |
661 |
|
|
if (!empty($_REQUEST[$this->_element_name])) { |
662 |
|
|
$to_list[array_search($_REQUEST[$this->_element_name], $all_list)] = $_REQUEST[$this->_element_name]; |
663 |
jonen |
1.4 |
} |
664 |
jonen |
1.3 |
} |
665 |
|
|
$this->set_to_list_data( $to_list ); |
666 |
|
|
} else { |
667 |
|
|
//the assigned list is empty |
668 |
|
|
$this->set_list_data( $all_list ); |
669 |
|
|
$this->set_to_list_data(array()); |
670 |
|
|
} |
671 |
jonen |
1.4 |
} else { |
672 |
|
|
$this->set_to_list_data($value); |
673 |
|
|
} |
674 |
|
|
|
675 |
jonen |
1.3 |
} |
676 |
|
|
|
677 |
|
|
|
678 |
|
|
|
679 |
|
|
/** |
680 |
|
|
* This function builds and returns the |
681 |
|
|
* form element object |
682 |
|
|
* |
683 |
|
|
* @return object |
684 |
|
|
*/ |
685 |
|
|
function get_element() { |
686 |
|
|
$table = html_table(); |
687 |
jonen |
1.4 |
$table->add_row($this->_from_label, _HTML_SPACE, |
688 |
|
|
$this->get_label(NULL,$this->_to_label, FALSE)); |
689 |
jonen |
1.3 |
|
690 |
|
|
$from_select = form_select($this->_element_name.'_available', |
691 |
|
|
$this->_data_list,'', TRUE); |
692 |
jonen |
1.4 |
|
693 |
|
|
if ($this->onChangeJS != null) { |
694 |
|
|
$from_select->set_tag_attribute("onChange", $this->onChangeJS); |
695 |
|
|
} |
696 |
|
|
|
697 |
jonen |
1.3 |
$style = ''; |
698 |
|
|
if ($this->_height) { |
699 |
|
|
$style .= "height: ".$this->_height.";"; |
700 |
|
|
} |
701 |
|
|
if ($this->_width) { |
702 |
|
|
$style .= "width: ".$this->_width.";"; |
703 |
jonen |
1.4 |
} |
704 |
jonen |
1.3 |
|
705 |
|
|
//build the buttons |
706 |
|
|
$button_style = 'width: 90px;'; |
707 |
|
|
$f_name = $this->_element_name."_move_around"; |
708 |
|
|
$add = form_button($this->_element_name.'_add', 'Add >>', array('style' => $button_style, |
709 |
|
|
'onclick' => $f_name."('right',false);")); |
710 |
|
|
$add_all = form_button($this->_element_name.'_add_all', 'Add All', array('style' => $button_style, |
711 |
|
|
"onclick" => $f_name."('right', true);")); |
712 |
|
|
|
713 |
|
|
$remove = form_button($this->_element_name.'_remove', '<< Remove', array('style' => $button_style, |
714 |
|
|
'onclick' => $f_name."('left', false);")); |
715 |
|
|
$remove_all = form_button($this->_element_name.'_remove_all', 'Remove All', array('style' => $button_style, |
716 |
|
|
'onclick' => $f_name."('left', true);")); |
717 |
|
|
|
718 |
|
|
$to_select = form_select($this->_element_name.'[]', |
719 |
|
|
$this->_data_list_to, '', TRUE); |
720 |
|
|
|
721 |
|
|
if (strlen($style) > 0) { |
722 |
|
|
$from_select->set_style($style); |
723 |
|
|
$to_select->set_style($style); |
724 |
|
|
} |
725 |
|
|
|
726 |
jonen |
1.4 |
//check to see if we are disabled |
727 |
|
|
if ($this->is_disabled()) { |
728 |
|
|
$from_select->set_tag_attribute('disabled'); |
729 |
|
|
$add->set_tag_attribute('disabled'); |
730 |
|
|
$add_all->set_tag_attribute('disabled'); |
731 |
|
|
$remove->set_tag_attribute('disabled'); |
732 |
|
|
$remove_all->set_tag_attribute('disabled'); |
733 |
|
|
$to_select->set_tag_attribute('disabled'); |
734 |
|
|
} |
735 |
|
|
|
736 |
|
|
|
737 |
|
|
$button_td = new TDtag(array('align' => 'left'), |
738 |
jonen |
1.3 |
$add, html_br(), $add_all, html_br(2), |
739 |
jonen |
1.4 |
$remove, html_br(), $remove_all); |
740 |
|
|
//IE sucks. |
741 |
|
|
$button_td->set_collapse(); |
742 |
|
|
$table->add_row( $from_select, |
743 |
|
|
$button_td, |
744 |
jonen |
1.3 |
$to_select ); |
745 |
|
|
|
746 |
|
|
return $table; |
747 |
|
|
} |
748 |
|
|
|
749 |
|
|
/** |
750 |
|
|
* |
751 |
|
|
* This function is responsible for performing complete |
752 |
|
|
* validation and setting the appropriate error message |
753 |
|
|
* in case of a failed validation |
754 |
jonen |
1.4 |
* |
755 |
jonen |
1.3 |
* NOTE: This makes sure that the data submitted for both |
756 |
|
|
* fields is in the original list. |
757 |
|
|
* |
758 |
|
|
* @param FormValidation object |
759 |
|
|
*/ |
760 |
|
|
function validate(&$_FormValidation) { |
761 |
|
|
//need to make sure we only allow |
762 |
|
|
//elements that the class has. |
763 |
|
|
$combined = array_flip(array_merge( $this->_data_list, $this->_data_list_to)); |
764 |
|
|
|
765 |
|
|
if (isset($_REQUEST[$this->_element_name])) { |
766 |
|
|
if (is_array($_REQUEST[$this->_element_name])) { |
767 |
|
|
foreach( $_REQUEST[$this->_element_name] as $value ) { |
768 |
|
|
if (!isset($combined[$value])) { |
769 |
|
|
return FALSE; |
770 |
|
|
} |
771 |
|
|
} |
772 |
|
|
return TRUE; |
773 |
|
|
} else { |
774 |
|
|
if (!isset($combined[$value])) { |
775 |
|
|
return FALSE; |
776 |
|
|
} else { |
777 |
|
|
return TRUE; |
778 |
|
|
} |
779 |
|
|
} |
780 |
|
|
} else { |
781 |
|
|
//empty value |
782 |
|
|
return TRUE; |
783 |
|
|
} |
784 |
|
|
|
785 |
|
|
return TRUE; |
786 |
|
|
} |
787 |
|
|
|
788 |
|
|
/** |
789 |
|
|
* This provides a method |
790 |
|
|
* for the FormContent |
791 |
jonen |
1.4 |
* to get access to the |
792 |
jonen |
1.3 |
* text associated with a |
793 |
|
|
* field. This is only available |
794 |
|
|
* on FormElements that have text |
795 |
|
|
* associated with a field. |
796 |
|
|
* It is used during Confirmation |
797 |
|
|
* |
798 |
|
|
* @param mixed - the value to look up |
799 |
|
|
* @return string - the text associated |
800 |
|
|
*/ |
801 |
|
|
function get_value_text() { |
802 |
|
|
return implode( ", ", array_keys( $this->get_value() ) ); |
803 |
|
|
} |
804 |
|
|
|
805 |
|
|
/** |
806 |
|
|
* This is a method for getting the JS needed |
807 |
|
|
* for the form tag's onsubmit attribute. |
808 |
jonen |
1.4 |
* |
809 |
jonen |
1.3 |
* @return string |
810 |
|
|
*/ |
811 |
|
|
function form_tag_onsubmit() { |
812 |
|
|
return $this->_element_name.'_check_submit();'; |
813 |
|
|
} |
814 |
|
|
|
815 |
|
|
|
816 |
|
|
/** |
817 |
jonen |
1.4 |
* This method builds the Javascript needed for this |
818 |
jonen |
1.3 |
* element. |
819 |
jonen |
1.4 |
* |
820 |
jonen |
1.3 |
* @return string The javascript. |
821 |
|
|
*/ |
822 |
|
|
function javascript() { |
823 |
|
|
|
824 |
jonen |
1.4 |
$js = "function ".$this->_element_name."_move_around(direction, all) {\n". |
825 |
|
|
" if (direction==\"right\") {\n". |
826 |
|
|
" box1 = \"".$this->_element_name."_available\";\n". |
827 |
|
|
" box2 = \"".$this->_element_name."[]\";\n". |
828 |
|
|
" } else {\n". |
829 |
|
|
" box1 = \"".$this->_element_name."[]\";\n". |
830 |
|
|
" box2 = \"".$this->_element_name."_available\" + \"\";\n". |
831 |
|
|
" }\n". |
832 |
|
|
|
833 |
|
|
" for (var i=0;i<document.forms[0].elements[box1].length;i++) {\n". |
834 |
|
|
" if (document.forms[0].elements[box1][i].selected || all) {\n". |
835 |
|
|
" // add to the other list box\n". |
836 |
|
|
" document.forms[0].elements[box2].options[document.forms[0].elements[box2].length] =". |
837 |
|
|
" new Option(document.forms[0].elements[box1].options[i].text, document.forms[0].elements[box1][i].value);\n". |
838 |
|
|
" // remove from the current listbox\n". |
839 |
|
|
" document.forms[0].elements[box1][i] = null;\n". |
840 |
|
|
" i--;\n". |
841 |
|
|
" }\n". |
842 |
|
|
" }\n". |
843 |
|
|
"}\n"; |
844 |
|
|
|
845 |
|
|
|
846 |
|
|
$js .= "\nfunction ".$this->_element_name."_check_submit() {\n". |
847 |
|
|
" // select all items in the added ip list\n". |
848 |
|
|
" // in order to include in the post data\n". |
849 |
|
|
" box = \"".$this->_element_name."[]\";\n". |
850 |
|
|
" if (document.forms[0].elements[box]) {\n". |
851 |
|
|
" for (var i=0;i<document.forms[0].elements[box].length;i++) {\n". |
852 |
|
|
" document.forms[0].elements[box][i].selected = true;\n". |
853 |
|
|
" }\n". |
854 |
|
|
" }\n". |
855 |
|
|
|
856 |
|
|
" // disable the buttons\n". |
857 |
|
|
" //document.forms[0]._form_action1.disabled = true;\n". |
858 |
|
|
" //if (document.forms[0]._form_action2)\n". |
859 |
|
|
" // document.forms[0]._form_action2.disabled = true;\n". |
860 |
|
|
" //document.forms[0].cancel.disabled = true;\n". |
861 |
|
|
" return true;\n". |
862 |
|
|
"}\n"; |
863 |
jonen |
1.3 |
|
864 |
|
|
return trim($js); |
865 |
|
|
} |
866 |
|
|
|
867 |
|
|
/** |
868 |
|
|
* This function will return the |
869 |
|
|
* elements value |
870 |
|
|
* |
871 |
|
|
* @return mixed |
872 |
|
|
*/ |
873 |
jonen |
1.4 |
function get_value(){ |
874 |
jonen |
1.3 |
return $this->_data_list_to; |
875 |
|
|
} |
876 |
|
|
|
877 |
|
|
|
878 |
|
|
/** |
879 |
|
|
* This method returns the hidden version of this |
880 |
jonen |
1.4 |
* element for a confirmation page. |
881 |
|
|
* |
882 |
|
|
* NOTE: This is called by the FormProcessor only. |
883 |
jonen |
1.3 |
* It shouldn't be called manually. |
884 |
jonen |
1.4 |
* |
885 |
jonen |
1.3 |
* @return INPUTtag of type hidden |
886 |
|
|
*/ |
887 |
jonen |
1.4 |
function get_confirm_element(){ |
888 |
jonen |
1.3 |
$name = $this->get_element_name(); |
889 |
|
|
|
890 |
|
|
$c = container(); |
891 |
|
|
if (is_array( $_REQUEST[$name]) ) { |
892 |
jonen |
1.4 |
foreach( $_REQUEST[$name] as $value ){ |
893 |
jonen |
1.3 |
$c->add(form_hidden( $name."[]", $value)); |
894 |
jonen |
1.4 |
} |
895 |
jonen |
1.3 |
} else { |
896 |
|
|
$c->add(form_hidden($name."[]", $_REQUEST[$name] )); |
897 |
|
|
} |
898 |
|
|
|
899 |
|
|
return $c; |
900 |
|
|
} |
901 |
|
|
} |
902 |
|
|
|
903 |
|
|
/** |
904 |
jonen |
1.4 |
* This class builds the FEComboList with buttons below each element |
905 |
|
|
* |
906 |
|
|
* @author Sumedh Thakar |
907 |
|
|
*/ |
908 |
|
|
class FEComboListButtonsBox extends FEComboListBox { |
909 |
|
|
|
910 |
|
|
/** |
911 |
|
|
* This variable holds the button array |
912 |
|
|
*/ |
913 |
|
|
var $_button_info = array(); |
914 |
|
|
/** |
915 |
|
|
* this function sets the array of buttons and related info |
916 |
|
|
* array is of format |
917 |
|
|
* array('left' => array( |
918 |
|
|
* array( |
919 |
|
|
* 'name'=> 'expand', |
920 |
|
|
* 'value' => 'Expand it", |
921 |
|
|
* 'onclick'=> 'some_function()', |
922 |
|
|
* 'js' => 'function some_function(){ alert('hi'); }' * ), |
923 |
|
|
* ) |
924 |
|
|
* ) |
925 |
|
|
* @author Sumedh Thakar |
926 |
|
|
* @param array of buttons and related info |
927 |
|
|
*/ |
928 |
|
|
function set_button_array($button_array){ |
929 |
|
|
$this->_button_info = $button_array; |
930 |
|
|
} |
931 |
|
|
|
932 |
|
|
function javascript(){ |
933 |
|
|
$js = parent::javascript(); |
934 |
|
|
if(count($this->_button_info)){ |
935 |
|
|
foreach ($this->_button_info as $side){ |
936 |
|
|
foreach ($side as $button){ |
937 |
|
|
if(isset($button['js'])) $js .= " ".$button['js']." "; |
938 |
|
|
} |
939 |
|
|
} |
940 |
|
|
} |
941 |
|
|
return $js; |
942 |
|
|
} |
943 |
|
|
|
944 |
|
|
function get_element(){ |
945 |
|
|
$table = parent::get_element(); |
946 |
|
|
if(empty($this->_button_info)) return $table; |
947 |
|
|
if (isset($this->_button_info['left'])){ |
948 |
|
|
$lbuttons = new TDtag(); |
949 |
|
|
foreach($this->_button_info['left'] as $butt) { |
950 |
|
|
|
951 |
|
|
$attributes = array(); |
952 |
|
|
if (strlen($butt['value'])>12) $attributes["style"] = "padding-left:6px;padding-right:6px;"; |
953 |
|
|
else $attributes["style"] = "width:100px;"; |
954 |
|
|
$attributes["onClick"] = $butt['onclick']; |
955 |
|
|
|
956 |
|
|
$lbuttons->add(form_button( |
957 |
|
|
$butt['name'], |
958 |
|
|
$butt['value'], |
959 |
|
|
$attributes), |
960 |
|
|
_HTML_SPACE); |
961 |
|
|
} |
962 |
|
|
}else{ |
963 |
|
|
$lbuttons = _HTML_SPACE; |
964 |
|
|
} |
965 |
|
|
if (isset($this->_button_info['right'])){ |
966 |
|
|
$rbuttons = new TDtag(); |
967 |
|
|
foreach($this->_button_info['right'] as $butt) { |
968 |
|
|
|
969 |
|
|
$attributes = array(); |
970 |
|
|
if (strlen($butt['value'])>12) $attributes["style"] = "padding-left:6px;padding-right:6px;"; |
971 |
|
|
else $attributes["style"] = "width:100px;"; |
972 |
|
|
$attributes["onClick"] = $butt['onclick']; |
973 |
|
|
|
974 |
|
|
$rbuttons->add(form_button( |
975 |
|
|
$butt['name'], |
976 |
|
|
$butt['value'], |
977 |
|
|
$attributes), |
978 |
|
|
_HTML_SPACE); |
979 |
|
|
} |
980 |
|
|
}else{ |
981 |
|
|
$rbuttons = _HTML_SPACE; |
982 |
|
|
} |
983 |
|
|
$table->add_row($lbuttons, |
984 |
|
|
_HTML_SPACE, |
985 |
|
|
$rbuttons |
986 |
|
|
); |
987 |
|
|
return $table; |
988 |
|
|
|
989 |
|
|
} |
990 |
|
|
|
991 |
|
|
|
992 |
|
|
} |
993 |
|
|
|
994 |
|
|
/** |
995 |
|
|
* This class builds a FEDataList that shows a select box for Months of the year |
996 |
|
|
* |
997 |
|
|
* You should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale} |
998 |
|
|
* function to affect the language used for the month list. |
999 |
|
|
* |
1000 |
jonen |
1.3 |
* @author Culley Harrelson <culley@fastmail.fm> |
1001 |
jonen |
1.4 |
* @see FEDate |
1002 |
jonen |
1.3 |
* |
1003 |
|
|
*/ |
1004 |
|
|
|
1005 |
|
|
class FEMonths extends FEListBox { |
1006 |
|
|
|
1007 |
|
|
/** |
1008 |
|
|
* The constructor |
1009 |
jonen |
1.4 |
* |
1010 |
jonen |
1.3 |
* @param string text label for the element |
1011 |
|
|
* @param boolean is this a required element? |
1012 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
1013 |
|
|
* @param int element height in px |
1014 |
|
|
* @param string format should be F m or M: Full month name, digit, abbreviated month name |
1015 |
jonen |
1.4 |
* |
1016 |
jonen |
1.3 |
*/ |
1017 |
jonen |
1.4 |
function FEMonths($label, $required = TRUE, $width = NULL, $height = NULL, $format = 'F'){ |
1018 |
|
|
|
1019 |
jonen |
1.3 |
// $format should be M m or F. Default to F if the user passes in garbage. |
1020 |
|
|
switch ($format) { |
1021 |
jonen |
1.4 |
case 'M': |
1022 |
|
|
$format = '%b'; |
1023 |
|
|
break; |
1024 |
|
|
case 'm': |
1025 |
|
|
$format = '%m'; |
1026 |
|
|
break; |
1027 |
|
|
default: |
1028 |
|
|
$format = '%B'; |
1029 |
|
|
break; |
1030 |
jonen |
1.3 |
} |
1031 |
|
|
|
1032 |
|
|
for ($i = 1; $i < 13; $i++) { |
1033 |
|
|
$months[$i] = strftime($format, strtotime("$i/12/2004")); |
1034 |
|
|
} |
1035 |
|
|
|
1036 |
|
|
$this->FEListBox($label, $required, $width, $height, array_flip($months)); |
1037 |
|
|
|
1038 |
jonen |
1.4 |
|
1039 |
jonen |
1.3 |
} |
1040 |
|
|
} |
1041 |
|
|
|
1042 |
|
|
/** |
1043 |
jonen |
1.4 |
* This class builds a FEDataList that shows a select box listing a range of years |
1044 |
|
|
* |
1045 |
jonen |
1.3 |
* @author Culley Harrelson <culley@fastmail.fm> |
1046 |
jonen |
1.4 |
* @see FEDate |
1047 |
jonen |
1.3 |
* |
1048 |
|
|
*/ |
1049 |
|
|
|
1050 |
|
|
class FEYears extends FEListBox { |
1051 |
|
|
|
1052 |
|
|
/** |
1053 |
|
|
* The constructor |
1054 |
jonen |
1.4 |
* |
1055 |
jonen |
1.3 |
* @param string text label for the element |
1056 |
|
|
* @param boolean is this a required element? |
1057 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
1058 |
|
|
* @param int element height in px |
1059 |
|
|
* @param int min_year |
1060 |
|
|
* @param int max_year |
1061 |
|
|
*/ |
1062 |
jonen |
1.4 |
function FEYears($label, $required = TRUE, $width = NULL, $height = NULL, $min_year = 2000, $max_year = 2010){ |
1063 |
jonen |
1.3 |
// this will be cleaner in php5 with array_combine() |
1064 |
|
|
$list = range($min_year, $max_year); |
1065 |
jonen |
1.4 |
foreach ($list as $year){ |
1066 |
jonen |
1.3 |
$years[$year] = $year; |
1067 |
|
|
} |
1068 |
|
|
$this->FEListBox($label, $required, $width, $height, $years); |
1069 |
|
|
} |
1070 |
|
|
} |
1071 |
|
|
|
1072 |
|
|
/** |
1073 |
jonen |
1.4 |
* This class builds a FEDataList that shows a select box listing the days of the month |
1074 |
|
|
* |
1075 |
jonen |
1.3 |
* @author Culley Harrelson <culley@fastmail.fm> |
1076 |
jonen |
1.4 |
* @see FEDate |
1077 |
jonen |
1.3 |
* |
1078 |
|
|
*/ |
1079 |
|
|
|
1080 |
|
|
class FEDays extends FEListBox { |
1081 |
|
|
|
1082 |
|
|
/** |
1083 |
|
|
* The constructor |
1084 |
jonen |
1.4 |
* |
1085 |
jonen |
1.3 |
* @param string text label for the element |
1086 |
|
|
* @param boolean is this a required element? |
1087 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
1088 |
|
|
* @param int element height in px |
1089 |
|
|
*/ |
1090 |
|
|
|
1091 |
jonen |
1.4 |
function FEDays($label, $required = TRUE, $width = NULL, $height = NULL){ |
1092 |
jonen |
1.3 |
|
1093 |
|
|
// this will be cleaner in php5 with array_combine() |
1094 |
|
|
$list = range(1, 31); |
1095 |
jonen |
1.4 |
foreach ($list as $day){ |
1096 |
jonen |
1.3 |
// pad the single digit days with zeros |
1097 |
jonen |
1.4 |
$new_day = sprintf('%02d', $day); |
1098 |
|
|
$days[$new_day] = $day; |
1099 |
jonen |
1.3 |
} |
1100 |
|
|
$this->FEListBox($label, $required, $width, $height, $days); |
1101 |
|
|
|
1102 |
jonen |
1.4 |
|
1103 |
jonen |
1.3 |
} |
1104 |
|
|
} |
1105 |
|
|
|
1106 |
|
|
/** |
1107 |
jonen |
1.4 |
* This class builds a widget that shows a group of select boxes (FEYears, FEMonths, FEDays) representing a date. |
1108 |
|
|
* |
1109 |
|
|
* FEDate will display three drop down lists representing a date. You can set |
1110 |
|
|
* the order in which these elements are displayed and the minimum and maximum |
1111 |
|
|
* years displayed. |
1112 |
|
|
* |
1113 |
|
|
* Like in FEMonths you should use the built in php {@link http://www.php.net/manual/en/function.setlocale.php setlocale} |
1114 |
|
|
* function to affect the language used for the month list. |
1115 |
|
|
* |
1116 |
|
|
* Example as it would appear in FormContent::form_init_elements(): |
1117 |
|
|
* <code> |
1118 |
|
|
* // set the locale to dutch |
1119 |
|
|
* setlocale(LC_TIME, 'nl_NL'); |
1120 |
|
|
* $date_element = new FEDate("FEDate label", false, null, null, 'Fdy', 1970, 1975); |
1121 |
|
|
* </code> |
1122 |
|
|
* |
1123 |
|
|
* the $format parameter conforms the the php {@link http://www.php.net/manual/en/function.setlocale.php date} function |
1124 |
|
|
* format argument specification (for years, months and days only). |
1125 |
jonen |
1.3 |
* |
1126 |
|
|
* @author Culley Harrelson <culley@fastmail.fm> |
1127 |
|
|
* @author Suren Markosian <suren@emicron.net> |
1128 |
jonen |
1.4 |
* @see FEMonths |
1129 |
|
|
* @see FEDays |
1130 |
|
|
* @see FEYears |
1131 |
jonen |
1.3 |
* |
1132 |
|
|
*/ |
1133 |
|
|
|
1134 |
|
|
class FEDate extends FEBoxElement { |
1135 |
|
|
|
1136 |
|
|
/** |
1137 |
|
|
* The earliest year shown in the year list. |
1138 |
jonen |
1.4 |
* @var integer |
1139 |
|
|
* @access private |
1140 |
jonen |
1.3 |
*/ |
1141 |
|
|
var $_min_year; |
1142 |
|
|
|
1143 |
|
|
/** |
1144 |
|
|
* The latest year shown in the year list. |
1145 |
|
|
* @var string |
1146 |
jonen |
1.4 |
* @access private |
1147 |
jonen |
1.3 |
*/ |
1148 |
|
|
var $_max_year; |
1149 |
|
|
|
1150 |
|
|
/** |
1151 |
|
|
* The order in which to show the elements. This variable must be 3 |
1152 |
|
|
* characters long and contain only one m only one d and only one y. |
1153 |
|
|
* |
1154 |
|
|
* @var string |
1155 |
jonen |
1.4 |
* @access private |
1156 |
jonen |
1.3 |
*/ |
1157 |
|
|
var $_format = 'mdy'; |
1158 |
|
|
|
1159 |
|
|
/** |
1160 |
|
|
* A printf style format string used to add punctuation to the confirmation |
1161 |
|
|
* display. Defaults to space separated. The placeholders are filled |
1162 |
|
|
* according to the order set in $_format |
1163 |
|
|
* |
1164 |
|
|
* @var string |
1165 |
jonen |
1.4 |
* @access private |
1166 |
jonen |
1.3 |
*/ |
1167 |
|
|
var $_text_format = '%s %s %s'; |
1168 |
|
|
|
1169 |
|
|
/** |
1170 |
|
|
* The year form element |
1171 |
|
|
* |
1172 |
|
|
* @var FEYears |
1173 |
jonen |
1.4 |
* @access private |
1174 |
jonen |
1.3 |
*/ |
1175 |
|
|
var $_year; |
1176 |
|
|
|
1177 |
|
|
/** |
1178 |
|
|
* The month form element |
1179 |
|
|
* |
1180 |
|
|
* @var FEMonths |
1181 |
jonen |
1.4 |
* @access private |
1182 |
jonen |
1.3 |
*/ |
1183 |
|
|
var $_month; |
1184 |
|
|
|
1185 |
|
|
/** |
1186 |
|
|
* The day form element |
1187 |
|
|
* |
1188 |
|
|
* @var FEDays |
1189 |
jonen |
1.4 |
* @access private |
1190 |
jonen |
1.3 |
*/ |
1191 |
|
|
var $_day; |
1192 |
|
|
|
1193 |
|
|
/** |
1194 |
|
|
* The constructor |
1195 |
|
|
* |
1196 |
|
|
* @param string text label for the element |
1197 |
|
|
* @param boolean is this a required element? |
1198 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
1199 |
|
|
* @param int element height in px |
1200 |
|
|
* @param string date format string. M m F Y y d D are valid. 3 characters max. |
1201 |
|
|
* @param int min value for year drop down list |
1202 |
|
|
* @param int max value for year drop down list |
1203 |
jonen |
1.4 |
* @see FEDate for an example |
1204 |
|
|
* @todo we need to blow up somehow if the format string is bogus |
1205 |
|
|
* @access public |
1206 |
jonen |
1.3 |
* |
1207 |
|
|
*/ |
1208 |
|
|
|
1209 |
jonen |
1.4 |
function FEDate($label, $required = TRUE, $width = NULL, $height = NULL, |
1210 |
|
|
$format = 'mdy', $min_year = 2000, $max_year = 2010){ |
1211 |
jonen |
1.3 |
|
1212 |
|
|
$this->_set_format($format); |
1213 |
|
|
$this->_min_year = $min_year; |
1214 |
|
|
$this->_max_year = $max_year; |
1215 |
|
|
|
1216 |
|
|
$this->_year = new FEYears($this->_element_name . '_years', $required, null, null, $min_year, $max_year); |
1217 |
|
|
$this->_month = new FEMonths($this->_element_name . '_months', $required, null, null, preg_replace('/[dy]/i', '', $this->_format)); |
1218 |
|
|
$this->_day = new FEDays($this->_element_name . '_days', $required, null, null); |
1219 |
|
|
$this->FEBoxElement($label, $required, $width, $height); |
1220 |
|
|
} |
1221 |
|
|
|
1222 |
|
|
/** |
1223 |
jonen |
1.4 |
* We need to override this so we get |
1224 |
|
|
* the form name set in the child elements |
1225 |
|
|
* so the id attributes are set correctly. |
1226 |
|
|
*/ |
1227 |
|
|
function set_form_name($name) { |
1228 |
|
|
$this->_form_name = $name; |
1229 |
|
|
$this->_year->set_form_name($name); |
1230 |
|
|
$this->_month->set_form_name($name); |
1231 |
|
|
$this->_day->set_form_name($name); |
1232 |
|
|
} |
1233 |
|
|
|
1234 |
|
|
/** |
1235 |
jonen |
1.3 |
* This function builds and returns the |
1236 |
|
|
* form element object |
1237 |
|
|
* |
1238 |
|
|
* @return object |
1239 |
jonen |
1.4 |
* @access public |
1240 |
jonen |
1.3 |
*/ |
1241 |
jonen |
1.4 |
function get_element(){ |
1242 |
jonen |
1.3 |
|
1243 |
|
|
$container = new Container(); |
1244 |
|
|
|
1245 |
|
|
// add the elements in the order specified. |
1246 |
|
|
$chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY); |
1247 |
jonen |
1.4 |
foreach ($chars as $char){ |
1248 |
jonen |
1.3 |
switch ($char) { |
1249 |
jonen |
1.4 |
case 'y': |
1250 |
|
|
$container->add($this->_year->get_element()); |
1251 |
|
|
break; |
1252 |
|
|
case 'm': |
1253 |
|
|
case 'F': |
1254 |
|
|
$container->add($this->_month->get_element()); |
1255 |
|
|
break; |
1256 |
|
|
case 'd': |
1257 |
|
|
$container->add($this->_day->get_element()); |
1258 |
|
|
break; |
1259 |
jonen |
1.3 |
} |
1260 |
|
|
} |
1261 |
|
|
|
1262 |
|
|
return $container; |
1263 |
|
|
} |
1264 |
|
|
|
1265 |
|
|
/** |
1266 |
jonen |
1.4 |
* This function will return the elements value as an array or month, day and year |
1267 |
jonen |
1.3 |
* |
1268 |
|
|
* @return array |
1269 |
jonen |
1.4 |
* @access public |
1270 |
|
|
*/ |
1271 |
|
|
function get_value(){ |
1272 |
|
|
$value= array("day"=>$this->_day->get_value(), |
1273 |
|
|
"month"=>$this->_month->get_value(), |
1274 |
|
|
"year"=>$this->_year->get_value()); |
1275 |
|
|
|
1276 |
|
|
return $value; |
1277 |
jonen |
1.3 |
|
1278 |
|
|
|
1279 |
|
|
} |
1280 |
|
|
|
1281 |
|
|
/** |
1282 |
jonen |
1.4 |
* Set the value of the element |
1283 |
|
|
* |
1284 |
jonen |
1.3 |
* This function sets the default values for the date element The |
1285 |
|
|
* parameter should be a string representation of the date in ISO 8601 |
1286 |
|
|
* format. |
1287 |
|
|
* |
1288 |
|
|
* @param string |
1289 |
jonen |
1.4 |
* @access public |
1290 |
jonen |
1.3 |
*/ |
1291 |
jonen |
1.4 |
function set_value($value){ |
1292 |
|
|
if ($value) { |
1293 |
|
|
if (is_array($value)) { |
1294 |
|
|
$this->_year->set_value($value['year']); |
1295 |
|
|
$this->_month->set_value($value['month']); |
1296 |
|
|
$this->_day->set_value($value['day']); |
1297 |
|
|
} else { |
1298 |
|
|
$date_parts = explode('-', $value); |
1299 |
|
|
$this->_year->set_value($date_parts[0]); |
1300 |
|
|
$this->_month->set_value($date_parts[1]); |
1301 |
|
|
$this->_day->set_value($date_parts[2]); |
1302 |
|
|
} |
1303 |
|
|
} |
1304 |
jonen |
1.3 |
|
1305 |
|
|
|
1306 |
|
|
} |
1307 |
|
|
|
1308 |
|
|
/** |
1309 |
jonen |
1.4 |
* This returns a formatted string used for the confirmation display (and possibly elsewhere) |
1310 |
|
|
* |
1311 |
jonen |
1.3 |
* @return string |
1312 |
jonen |
1.4 |
* @access public |
1313 |
jonen |
1.3 |
*/ |
1314 |
jonen |
1.4 |
function get_value_text(){ |
1315 |
jonen |
1.3 |
|
1316 |
|
|
// loop through the characters in $_format to properly set the placeholders |
1317 |
|
|
// determined in $_text_format |
1318 |
|
|
$chars = preg_split('//', $this->_format, -1, PREG_SPLIT_NO_EMPTY); |
1319 |
|
|
$i = 1; |
1320 |
jonen |
1.4 |
foreach ($chars as $char){ |
1321 |
jonen |
1.3 |
|
1322 |
|
|
switch ($char) { |
1323 |
jonen |
1.4 |
case 'y': |
1324 |
|
|
$value = $this->_year->get_value_text(); |
1325 |
|
|
break; |
1326 |
|
|
case 'm': |
1327 |
|
|
case 'F': |
1328 |
|
|
$value = $this->_month->get_value_text(); |
1329 |
|
|
break; |
1330 |
|
|
case 'd': |
1331 |
|
|
$value = $this->_day->get_value_text(); |
1332 |
|
|
break; |
1333 |
jonen |
1.3 |
} |
1334 |
|
|
|
1335 |
|
|
switch ($i) { |
1336 |
jonen |
1.4 |
case 1: |
1337 |
|
|
$one = $value; |
1338 |
|
|
break; |
1339 |
|
|
case 2: |
1340 |
|
|
$two = $value; |
1341 |
|
|
break; |
1342 |
|
|
case 3: |
1343 |
|
|
$three = $value; |
1344 |
|
|
break; |
1345 |
jonen |
1.3 |
} |
1346 |
|
|
|
1347 |
|
|
$i++; |
1348 |
|
|
} |
1349 |
|
|
|
1350 |
|
|
return sprintf($this->_text_format, $one, $two, $three); |
1351 |
|
|
} |
1352 |
|
|
|
1353 |
|
|
/** |
1354 |
|
|
* |
1355 |
|
|
* This function is responsible for performing complete |
1356 |
|
|
* validation and setting the appropriate error message |
1357 |
|
|
* in case of a failed validation |
1358 |
|
|
* |
1359 |
jonen |
1.4 |
* @param FormValidation |
1360 |
|
|
* @access public |
1361 |
|
|
* @return boolean success or failure |
1362 |
jonen |
1.3 |
*/ |
1363 |
jonen |
1.4 |
function validate(&$_FormValidation){ |
1364 |
jonen |
1.3 |
$value = $this->get_value(); |
1365 |
|
|
|
1366 |
|
|
// we make sure that the date is valid |
1367 |
|
|
if (!checkdate($value["month"], $value["day"], $value["year"])) { |
1368 |
|
|
$this->set_error_message("Invalid date"); |
1369 |
|
|
return FALSE; |
1370 |
|
|
} |
1371 |
|
|
return TRUE; |
1372 |
|
|
} |
1373 |
|
|
|
1374 |
|
|
/** |
1375 |
|
|
* this method sets the display order for the elements in the widget |
1376 |
|
|
* |
1377 |
|
|
* @param string |
1378 |
|
|
* @return bool success or failure |
1379 |
jonen |
1.4 |
* @access private |
1380 |
jonen |
1.3 |
*/ |
1381 |
jonen |
1.4 |
function _set_format($format){ |
1382 |
jonen |
1.3 |
|
1383 |
jonen |
1.4 |
// must be 2 or 3 characters |
1384 |
jonen |
1.3 |
if (strlen($format) != 3) { |
1385 |
|
|
return FALSE; |
1386 |
|
|
} |
1387 |
|
|
|
1388 |
|
|
// month can be represented by F m or M |
1389 |
|
|
if (strstr($format, 'F')) { |
1390 |
|
|
$month = 'f'; |
1391 |
|
|
} else { |
1392 |
|
|
$month = 'm'; |
1393 |
|
|
} |
1394 |
|
|
|
1395 |
|
|
// compare the characters sent with the characters needed. only set |
1396 |
|
|
// the property if one of each is present |
1397 |
|
|
$search_for = array ('y', $month, 'd'); |
1398 |
|
|
$chars = preg_split('//', strtolower($format), -1, PREG_SPLIT_NO_EMPTY); |
1399 |
|
|
|
1400 |
|
|
if (count(array_diff($search_for, $chars)) > 0) { |
1401 |
|
|
return FALSE; |
1402 |
|
|
} |
1403 |
|
|
|
1404 |
|
|
$this->_format = $format; |
1405 |
|
|
return TRUE; |
1406 |
|
|
|
1407 |
jonen |
1.4 |
|
1408 |
jonen |
1.3 |
} |
1409 |
|
|
|
1410 |
|
|
/** |
1411 |
jonen |
1.4 |
* Set the text format for confirmation |
1412 |
|
|
* |
1413 |
jonen |
1.3 |
* this method sets the format string used in get_value_text(). Use this |
1414 |
jonen |
1.4 |
* method to set special punctuation for the confirmation display. It is |
1415 |
|
|
* fed through sprintf |
1416 |
|
|
* |
1417 |
|
|
* Examples: |
1418 |
|
|
* <code> |
1419 |
|
|
* $date_element->set_text_format("%s %s, %s"); |
1420 |
|
|
* $date_element->set_text_format("%04d-%02d-%02d"); |
1421 |
|
|
* </code> |
1422 |
jonen |
1.3 |
* |
1423 |
|
|
* @param string |
1424 |
jonen |
1.4 |
* @access public |
1425 |
|
|
* @link http://www.php.net/manual/en/function.sprintf.php |
1426 |
jonen |
1.3 |
* |
1427 |
|
|
*/ |
1428 |
jonen |
1.4 |
function set_text_format($format){ |
1429 |
jonen |
1.3 |
|
1430 |
|
|
$this->_text_format = $format; |
1431 |
|
|
} |
1432 |
|
|
|
1433 |
|
|
/** |
1434 |
jonen |
1.4 |
* This method returns the hidden version of this element for a confirmation page. |
1435 |
|
|
* |
1436 |
|
|
* NOTE: This is called by the FormProcessor only. |
1437 |
jonen |
1.3 |
* It shouldn't be called manually. |
1438 |
jonen |
1.4 |
* |
1439 |
|
|
* @return container |
1440 |
|
|
* @access public |
1441 |
jonen |
1.3 |
*/ |
1442 |
jonen |
1.4 |
function get_confirm_element(){ |
1443 |
jonen |
1.3 |
$element_name = $this->get_element_name(); |
1444 |
|
|
|
1445 |
|
|
$c = container(); |
1446 |
jonen |
1.4 |
$c->add(form_hidden($this->_year->get_element_name(), $this->_year->get_value())); |
1447 |
|
|
$c->add(form_hidden($this->_month->get_element_name(), $this->_month->get_value())); |
1448 |
|
|
$c->add(form_hidden($this->_day->get_element_name(), $this->_day->get_value())); |
1449 |
jonen |
1.3 |
return $c; |
1450 |
|
|
} |
1451 |
|
|
|
1452 |
jonen |
1.4 |
|
1453 |
|
|
/** |
1454 |
|
|
* Sets the disabled element flag |
1455 |
|
|
* |
1456 |
|
|
* @param bool disabled |
1457 |
|
|
*/ |
1458 |
|
|
function set_disabled($flag) { |
1459 |
|
|
$this->_is_disabled = $flag; |
1460 |
|
|
$this->_year->set_disabled($flag); |
1461 |
|
|
$this->_month->set_disabled($flag); |
1462 |
|
|
$this->_day->set_disabled($flag); |
1463 |
|
|
} |
1464 |
|
|
|
1465 |
|
|
} |
1466 |
|
|
|
1467 |
|
|
|
1468 |
|
|
|
1469 |
|
|
/** |
1470 |
|
|
* this class is used for building a listbox for |
1471 |
|
|
* displaying Hours. |
1472 |
|
|
* |
1473 |
|
|
* @author Walter A. Boring IV |
1474 |
|
|
*/ |
1475 |
|
|
class FEHoursListBox extends FEListbox { |
1476 |
|
|
|
1477 |
|
|
/** |
1478 |
|
|
* Flag to tell us to use 12 or 24 hour format |
1479 |
|
|
*/ |
1480 |
|
|
var $_extended_hours = TRUE; |
1481 |
|
|
|
1482 |
|
|
/** |
1483 |
|
|
* The constructor |
1484 |
|
|
* |
1485 |
|
|
* @param string the label |
1486 |
|
|
* @param boolean required flag or not |
1487 |
|
|
* @param boolean show 24 hour format? |
1488 |
|
|
*/ |
1489 |
|
|
function FEHoursListBox($label='Hours', $required=FALSE, $extended_hours=TRUE) { |
1490 |
|
|
if ($extended_hours) { |
1491 |
|
|
$hours = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, |
1492 |
|
|
'06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10, '11'=>11, |
1493 |
|
|
'12'=>12, '13'=>13, '14'=>14, '15'=>15, '16'=>16, '17'=>17, |
1494 |
|
|
'18'=>18, '19'=>19, '20'=>20, '21'=>21, '22'=>22, '23'=>23); |
1495 |
|
|
} else { |
1496 |
|
|
$hours = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, |
1497 |
|
|
'06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10, '11'=>11, |
1498 |
|
|
'12'=>12); |
1499 |
|
|
} |
1500 |
|
|
parent::FEListBox($label, $required, null, null, $hours); |
1501 |
|
|
} |
1502 |
|
|
} |
1503 |
|
|
|
1504 |
|
|
/** |
1505 |
|
|
* this class is used for building a listbox for |
1506 |
|
|
* displaying Minutes. |
1507 |
|
|
* |
1508 |
|
|
* @author Walter A. Boring IV |
1509 |
|
|
*/ |
1510 |
|
|
class FEMinutesListBox extends FEListbox { |
1511 |
|
|
|
1512 |
|
|
/** |
1513 |
|
|
* The constructor |
1514 |
|
|
* |
1515 |
|
|
* @param string the label (default = 'Minutes') |
1516 |
|
|
* @param boolean required flag or not |
1517 |
|
|
*/ |
1518 |
|
|
function FEMinutesListBox($label='Minutes', $required=FALSE) { |
1519 |
|
|
$minutes = array('00'=>0, '01'=>1, '02'=>2, '03'=>3, '04'=>4, '05'=>5, |
1520 |
|
|
'06'=>6, '07'=>7, '08'=>8, '09'=>9, '10'=>10); |
1521 |
|
|
|
1522 |
|
|
for($x=11;$x<=59;$x++) { |
1523 |
|
|
$minutes[$x]=$x; |
1524 |
|
|
} |
1525 |
|
|
|
1526 |
|
|
parent::FEListBox($label, $required, null, null, $minutes); |
1527 |
|
|
} |
1528 |
|
|
} |
1529 |
|
|
|
1530 |
|
|
/** |
1531 |
|
|
* this class is used for building a listbox for |
1532 |
|
|
* displaying Seconds. |
1533 |
|
|
* |
1534 |
|
|
* @author Walter A. Boring IV |
1535 |
|
|
*/ |
1536 |
|
|
class FESecondsListBox extends FEMinutesListbox { |
1537 |
|
|
|
1538 |
|
|
/** |
1539 |
|
|
* The constructor |
1540 |
|
|
* |
1541 |
|
|
* @param string the label (default = 'Seconds') |
1542 |
|
|
* @param boolean required flag or not |
1543 |
|
|
*/ |
1544 |
|
|
function FESecondsListBox($label='Seconds', $required=FALSE) { |
1545 |
|
|
parent::FEMinutesListBox($label, $required); |
1546 |
|
|
} |
1547 |
|
|
} |
1548 |
|
|
|
1549 |
|
|
|
1550 |
|
|
/** |
1551 |
|
|
* This class is used to build a ListBox for |
1552 |
|
|
* GMT timezone selection |
1553 |
|
|
* |
1554 |
|
|
* @author Walter A. Boring IV |
1555 |
|
|
*/ |
1556 |
|
|
class FEGMTTimeZoneListBox extends FEListBox { |
1557 |
|
|
|
1558 |
|
|
/** |
1559 |
|
|
* The timezone selections |
1560 |
|
|
*/ |
1561 |
|
|
var $_zones=array("GMT -12 : Eniwetok, Kwajalein"=>-12, |
1562 |
|
|
"GMT -11 : Midway Islands, Samoa"=>-11, |
1563 |
|
|
"GMT -10 : Hawaii"=>-10, |
1564 |
|
|
"GMT -09 : Alaska"=>-9, |
1565 |
|
|
"GMT -08 : Pacific (USA, Canada), Tijuana"=>-8, |
1566 |
|
|
"GMT -07 : Arizona"=>-7, |
1567 |
|
|
"GMT -06 : Central (USA, Canada), Mexico"=>-6, |
1568 |
|
|
"GMT -05 : Bogota, Lima, Quito, East (USA, Canada)"=>-5, |
1569 |
|
|
"GMT -04 : Caracas, La Paz, Atlantic (Canada)"=>-4, |
1570 |
|
|
"GMT -03 : Terre Neuve, Brasilia, Georgetown"=>-3, |
1571 |
|
|
"GMT -02 : Atlantic Center"=>-2, |
1572 |
|
|
"GMT -01 : Azores"=>-1, |
1573 |
|
|
"GMT +00 : Casablanca, London, Dublin, Lisbon"=>0, |
1574 |
|
|
"GMT +01 : Paris, Amsterdam, Berlin, Rome, Vienna"=>1, |
1575 |
|
|
"GMT +02 : Athens, Bucharest, Riga, Cairo, Israel"=>2, |
1576 |
|
|
"GMT +03 : Nairobi, Moscow, Baghdad"=>3, |
1577 |
|
|
"GMT +04 : Abu Dhabi, Kabul"=>4, |
1578 |
|
|
"GMT +05 : Islamabad"=>5, |
1579 |
|
|
"GMT +06 : Colombo"=>6, |
1580 |
|
|
"GMT +07 : Bangkok, Hanoi, Jakarta"=>7, |
1581 |
|
|
"GMT +08 : Beijing, Hong Kong, Singapore, Taipei"=>8, |
1582 |
|
|
"GMT +09 : Tokyo, Seoul"=>9, |
1583 |
|
|
"GMT +10 : Sydney, Vladivostok"=>10, |
1584 |
|
|
"GMT +11 : New Caledonia"=>11, |
1585 |
|
|
"GMT +12 : Wellington"=>12); |
1586 |
|
|
|
1587 |
|
|
/** |
1588 |
|
|
* The constructor |
1589 |
|
|
* |
1590 |
|
|
* @param string the label (default = 'Minutes') |
1591 |
|
|
* @param boolean required flag or not |
1592 |
|
|
*/ |
1593 |
|
|
function FEGMTTimeZoneListBox($label='TimeZone', $required=FALSE) { |
1594 |
|
|
parent::FEListBox($label, $required, null,null, $this->_zones); |
1595 |
|
|
} |
1596 |
|
|
} |
1597 |
|
|
|
1598 |
|
|
/** |
1599 |
|
|
* This Form Element builds a list box of the days of the week. |
1600 |
|
|
* |
1601 |
|
|
* Sunday, Monday, Tuesday, Wednesday, Thursday, Friday, Saturday |
1602 |
|
|
* |
1603 |
|
|
* @author Walter A. Boring IV |
1604 |
|
|
*/ |
1605 |
|
|
class FEWeekdaysListBox extends FEListBox { |
1606 |
|
|
var $_weekdays = array('Sunday' => 0, 'Monday' => 1, |
1607 |
|
|
'Tuesday' => 2, 'Wednesday' => 3, |
1608 |
|
|
'Thursday' => 4, 'Friday' => 5, |
1609 |
|
|
'Saturday' => 6); |
1610 |
|
|
|
1611 |
|
|
function FEWeekdaysListBox($label='Weekdays', $required=FALSE) { |
1612 |
|
|
parent::FEListBox($label, $required, null,null, $this->_weekdays); |
1613 |
|
|
} |
1614 |
jonen |
1.3 |
} |
1615 |
|
|
|
1616 |
jonen |
1.1 |
?> |