/[cvs]/nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FECheckBox.inc
ViewVC logotype

Annotation of /nfo/php/libs/com.newsblob.phphtmllib/form/form_elements/FECheckBox.inc

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Thu Aug 11 14:09:58 2005 UTC (19 years ago) by jonen
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +121 -17 lines
+ updated to version 2.5.3

1 jonen 1.1 <?php
2     /**
3     * This file contains the base FECheckBox class.
4     *
5 jonen 1.4 * $Id: FECheckBox.inc,v 1.24.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 CheckBox FormElement which builds a
18     * input field of type="checkbox". 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 FECheckBox extends FormElement {
29    
30     /**
31     * Holds the checkbox text
32     *
33     */
34     var $_text = NULL;
35    
36     /**
37     * The constructor
38     *
39     * @param label string - text label for the element
40     * @param string text - checkbox text to be displayed
41     */
42 jonen 1.4 function FECheckBox($label, $text=null) {
43 jonen 1.1 $this->FormElement($label, false);
44 jonen 1.4 if ($text === null) {
45     $this->_text = $label;
46     } else {
47     $this->_text = $text;
48     }
49 jonen 1.1 }
50    
51     /**
52     * This provides a method
53     * for the FormContent
54     * to get access to the
55     * text associated with a
56     * field. This is only available
57     * on FormElements that have text
58     * associated with a field.
59     * It is used during Confirmation
60     *
61     * @return string - the text associated
62     */
63 jonen 1.3 function get_value_text() {
64     $value = $this->get_value();
65 jonen 1.2 if ($value != NULL) {
66     return $this->_text;
67     } else {
68     return NULL;
69 jonen 1.4 }
70 jonen 1.1 }
71    
72     /**
73     * This function builds and returns the
74     * form element object
75     *
76     * @return object
77     */
78     function get_element() {
79    
80     $c = form_active_checkbox($this->get_element_name(),
81     $this->_text,
82     $this->get_value(),
83 jonen 1.4 "form_element",
84     NULL,
85     $this->is_disabled());
86 jonen 1.1
87     return $c;
88     }
89     }
90    
91     /**
92     * This is the CheckBoxList FormElement which builds a
93     * list of checkboxes inside a scrollable DIV.
94     * It has no validation method.
95     *
96     *
97 jonen 1.4 * @author Walter A. Boring IV <waboring@newsblob.com>
98 jonen 1.1 * @author Suren Markossian <suren@bcsweb.com>
99     * @package phpHtmlLib
100     * @subpackage FormProcessing
101     *
102     * @copyright LGPL - See LICENCE
103     */
104     class FECheckBoxList extends FEMultiListBox {
105    
106 jonen 1.4 /**
107     * Flag to tell us to render the check all
108     * checkbox
109     */
110     var $_checkall_flag = FALSE;
111    
112    
113     /**
114     * This method is used to turn on/off
115     * the magic 'check all' checkbox
116     *
117     * @param boolean
118     */
119     function enable_checkall($flag=TRUE) {
120     $this->_checkall_flag = $flag;
121     }
122    
123    
124     /**
125     * This returns the JS require to
126     * do the work of the check all checkbox
127     *
128     * @return string
129     */
130     function javascript() {
131     if (!$this->_checkall_flag) {
132     return '';
133     } else {
134     $js_name = $this->_js_checkall_name();
135     $id_name = 'id'.str_replace('[]','',
136     str_replace('_','',
137     $this->get_element_name()));
138     $num = count($this->_data_list);
139    
140     $js_str = <<<JSEND
141    
142     function $js_name(fromlink) {
143     var e_name = '$js_name';
144     var checkall = document.getElementById('id_$js_name');
145     var num = $num;
146     var e;
147    
148     if (fromlink) {
149     if (checkall.checked) {
150     checkall.checked = false;
151     } else {
152     checkall.checked = true;
153     }
154     }
155    
156     state = checkall.checked;
157    
158     for (i=0;i<num;i++) {
159     id_name = '$id_name'+i;
160     e = document.getElementById(id_name);
161     e.checked = state;
162     }
163     }
164    
165    
166     JSEND;
167     return $js_str;
168     }
169     }
170 jonen 1.3
171 jonen 1.1 /**
172     * This function builds and returns the
173     * form element object
174     *
175     * @return object
176     */
177     function get_element() {
178    
179     if ($this->_height || $this->_width) {
180     $this->set_style_attribute("overflow", "auto");
181     $this->set_style_attribute("border", "1px inset");
182     $this->set_style_attribute("background-color", "white");
183     }
184    
185     $attributes = $this->_build_element_attributes();
186 jonen 1.2 unset( $attributes["name"] );
187 jonen 1.4 $div = new DIVtag($attributes);
188 jonen 1.1
189     $element_name = $this->get_element_name();
190     $selected_values = $this->get_value();
191    
192     $x=0;
193     foreach ($this->_data_list as $text=>$value) {
194     $name = str_replace("[]", "[$x]", $element_name);
195 jonen 1.4 $id = str_replace('_','','id'.str_replace('[]','',$element_name).$x);
196 jonen 1.1 $x++;
197     $attributes = array("type"=>"checkbox",
198     "name"=>$name,
199 jonen 1.4 "id"=>$id,
200 jonen 1.1 "value"=>$value);
201    
202     if (is_array($selected_values) && in_array($value, $selected_values))
203     $attributes[] = "checked";
204    
205     $checkbox = new INPUTtag($attributes);
206    
207 jonen 1.4 if ($this->is_disabled() || isset($this->_disabled_items[$text])) {
208     $checkbox->set_tag_attribute("disabled", 'disabled');
209 jonen 1.3 $a = $text;
210     } else {
211 jonen 1.4 $js_action = "javascript:e=document.getElementById('" . $id . "'); e.checked=!e.checked;";
212 jonen 1.3 $a_attributes = array("href" => "javascript:void(0)",
213 jonen 1.4 "class"=>"form_element",
214 jonen 1.3 "onClick" => $js_action);
215     $a = new Atag($a_attributes, htmlspecialchars($text), FALSE);
216 jonen 1.4 }
217 jonen 1.1
218     $check = container( $checkbox, $a );
219     $check->set_collapse();
220    
221 jonen 1.4 $div->push($check, html_br());
222     }
223    
224     //build the checkall if needed
225     if ($this->_checkall_flag) {
226     $name = $this->_js_checkall_name();
227     $onclick = "javascript:".$name."(false);";
228    
229     $checkbox = new INPUTtag(array('type' => 'checkbox', 'value' => 0,
230     'onclick' => $onclick,
231     'id' => 'id_'.$name));
232    
233     $onclick = "javascript:".$name."(true);";
234     $a = new Atag(array('href' => 'javascript:void(0)',
235     'class' => 'form_element',
236     'onclick' => $onclick),
237     'Select All', FALSE);
238    
239     $check = container($checkbox, $a);
240    
241     //so we can get some nice spacing
242     $check_div = new DIVtag(array('style' => 'padding-left:1px;padding-top:8px;'),$check);
243     $check_div->set_collapse();
244     return container($div,$check_div);
245 jonen 1.1 }
246 jonen 1.4 return $div;
247     }
248 jonen 1.1
249 jonen 1.4 /**
250     * This private method builds the name of the js
251     * checkall function
252     *
253     * @return string
254     */
255     function _js_checkall_name() {
256     return str_replace('[]', '',$this->get_element_name()."_checkall");
257     }
258 jonen 1.3
259 jonen 1.1 }
260     ?>

MailToCvsAdmin">MailToCvsAdmin
ViewVC Help
Powered by ViewVC 1.1.26 RSS 2.0 feed