1 |
jonen |
1.1 |
<?php |
2 |
|
|
/** |
3 |
|
|
* This file contains the base FEDataList class |
4 |
|
|
* |
5 |
jonen |
1.4 |
* $Id: FEDataList.inc,v 1.15.2.1 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 |
|
|
* This is the DataList FormElement which builds a |
18 |
|
|
* a complex FEBoxElement. It has no validation method. |
19 |
|
|
* |
20 |
|
|
* |
21 |
jonen |
1.4 |
* @author Walter A. Boring IV <waboring@newsblob.com> |
22 |
jonen |
1.1 |
* @author Suren Markossian <suren@bcsweb.com> |
23 |
|
|
* @package phpHtmlLib |
24 |
|
|
* @subpackage FormProcessing |
25 |
|
|
* |
26 |
|
|
* @copyright LGPL - See LICENCE |
27 |
|
|
*/ |
28 |
|
|
class FEDataList extends FEBoxElement { |
29 |
|
|
|
30 |
|
|
/** |
31 |
|
|
* Holds the list of available |
32 |
|
|
* data elements |
33 |
|
|
* |
34 |
|
|
*/ |
35 |
|
|
var $_data_list = array(); |
36 |
|
|
|
37 |
|
|
/** |
38 |
jonen |
1.3 |
* The list of disabled items |
39 |
|
|
* (if any) |
40 |
|
|
*/ |
41 |
|
|
var $_disabled_items = array(); |
42 |
|
|
|
43 |
|
|
/** |
44 |
jonen |
1.1 |
* The constructor |
45 |
|
|
* |
46 |
jonen |
1.3 |
* @param string text label for the element |
47 |
|
|
* @param boolean is this a required element? |
48 |
|
|
* @param int element width in characters, pixels (px), percentage (%) or elements (em) |
49 |
|
|
* @param int element height in px |
50 |
jonen |
1.1 |
* @param array data_list - list of data elements (name=>value) |
51 |
|
|
*/ |
52 |
|
|
function FEDataList($label, $required = TRUE, $width = NULL, $height = NULL, $data_list = array()) { |
53 |
jonen |
1.2 |
$this->set_list_data( $data_list ); |
54 |
jonen |
1.3 |
$this->FEBoxElement($label, $required, $width, $height); |
55 |
jonen |
1.2 |
} |
56 |
|
|
|
57 |
|
|
/** |
58 |
|
|
* This function sets the array of data |
59 |
|
|
* to be used in the data list |
60 |
|
|
* |
61 |
|
|
* @param array data_list - list of data elements (name=>value) |
62 |
|
|
*/ |
63 |
|
|
function set_list_data( $data_list = array() ) { |
64 |
jonen |
1.1 |
$this->_data_list = $data_list; |
65 |
|
|
} |
66 |
|
|
|
67 |
|
|
|
68 |
|
|
/** |
69 |
|
|
* This provides a method |
70 |
|
|
* for the FormContent |
71 |
|
|
* to get access to the |
72 |
|
|
* text associated with a |
73 |
|
|
* field. This is only available |
74 |
|
|
* on FormElements that have text |
75 |
|
|
* associated with a field. |
76 |
|
|
* It is used during Confirmation |
77 |
|
|
* |
78 |
|
|
* @return string - the text associated |
79 |
|
|
*/ |
80 |
jonen |
1.3 |
function get_value_text() { |
81 |
|
|
$value = $this->get_value(); |
82 |
jonen |
1.1 |
$flip = array_flip($this->_data_list); |
83 |
jonen |
1.2 |
if (array_key_exists($value, $flip)) { |
84 |
|
|
return $flip[$value]; |
85 |
|
|
} else { |
86 |
|
|
return NULL; |
87 |
|
|
} |
88 |
jonen |
1.1 |
} |
89 |
|
|
|
90 |
|
|
/** |
91 |
|
|
* |
92 |
|
|
* This function is responsible for performing complete |
93 |
|
|
* validation and setting the appropriate error message |
94 |
|
|
* in case of a failed validation |
95 |
|
|
* |
96 |
jonen |
1.2 |
* @param FormValidation object |
97 |
jonen |
1.1 |
*/ |
98 |
jonen |
1.2 |
function validate(&$_FormValidation) { |
99 |
jonen |
1.1 |
// we make sure that the value is in the data list |
100 |
|
|
$values = $this->get_value(); |
101 |
|
|
if (is_array($values) ) { |
102 |
|
|
foreach( $values as $value ) { |
103 |
|
|
if (!in_array($value, $this->_data_list)) { |
104 |
|
|
$this->set_error_message("Invalid value"); |
105 |
|
|
return FALSE; |
106 |
|
|
} |
107 |
|
|
} |
108 |
|
|
} else { |
109 |
|
|
if (!in_array($values, $this->_data_list)) { |
110 |
|
|
$this->set_error_message("Invalid value"); |
111 |
|
|
return FALSE; |
112 |
|
|
} |
113 |
|
|
} |
114 |
jonen |
1.3 |
return TRUE; |
115 |
|
|
} |
116 |
jonen |
1.1 |
|
117 |
jonen |
1.3 |
/** |
118 |
|
|
* This method allows you to disable one of the items |
119 |
|
|
* in the list of checkboxes. |
120 |
|
|
* |
121 |
|
|
* @param string the name of the checkbox to disable |
122 |
|
|
* @return none |
123 |
|
|
*/ |
124 |
|
|
function disable_item($name) { |
125 |
|
|
$this->_disabled_items[$name] = 1; |
126 |
jonen |
1.1 |
} |
127 |
|
|
} |
128 |
|
|
?> |