/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/EditDataItem.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.patches/phphtmllib/widgets/EditDataItem.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (hide annotations)
Wed Apr 9 09:59:30 2003 UTC (21 years, 5 months ago) by joko
Branch: MAIN
Changes since 1.4: +6 -3 lines
fixes regarding modification of decode-function-behavior

1 jonen 1.1 <?
2     /*
3     ## -----------------------------------------------------------------------------
4 joko 1.5 ## $Id: EditDataItem.php,v 1.4 2003/04/06 01:41:33 jonen Exp $
5 jonen 1.1 ## -----------------------------------------------------------------------------
6 jonen 1.2 ## $Log: EditDataItem.php,v $
7 joko 1.5 ## Revision 1.4 2003/04/06 01:41:33 jonen
8     ## - removed duplicated decode functions
9     ##
10 jonen 1.4 ## Revision 1.3 2003/04/04 23:58:02 jonen
11     ## + saving of items sould now work with new 'GenericSource' structure
12     ##
13 jonen 1.3 ## Revision 1.2 2003/04/04 00:43:22 jonen
14     ## + complete rework
15     ##
16 jonen 1.2 ## Revision 1.1 2003/03/27 01:18:06 jonen
17     ## + inital commit (was orginal 'DataItem.php')
18     ##
19 jonen 1.1 ## Revision 1.4 2003/02/27 17:33:14 cvsmax
20     ## + enabled saving of data objects at confirm action
21     ## + fixed bug with POST/GET vars at form confirm
22     ## o ToDo: fix all bugs related to un-wanted hidden form elements
23     ## caused by mixed/duplicated POST/GET vars!
24     ##
25     ## Revision 1.3 2003/02/26 21:37:53 cvsmax
26     ## + reworked to enable linking if item value is an array or special expression
27     ##
28     ## Revision 1.2 2003/02/25 03:46:59 cvsmax
29     ## + refactored complete to work now with phphtmllib FormProcessor/Content
30     ## o ToDo: field validation seems not to work...
31     ##
32     ## Revision 1.1 2003/02/22 17:27:31 cvsmax
33     ## + renamed from DataEdit.php
34     ## + added simple support for class 'FormElementsInterface' which is an interface
35     ## to class 'FormBuilder' by binarycloud
36     ## o ToDo: refactor code to use new (added 21.02.03!) 'FormProcess' classes by phphtmllib
37     ## + class 'DataItem' now extends class 'InfoTable'
38     ##
39     ## Revision 1.1 2003/02/21 03:19:35 cvsmax
40     ## + first init
41     ##
42     ##
43     ## -----------------------------------------------------------------------------
44     */
45    
46     class EditDataItem extends StandardFormContent {
47    
48 jonen 1.2 /**
49     * holds reference to source object.
50     */
51     var $_datasource = NULL;
52    
53     /**
54     * container for arguments needed for e.g. setting the source object.
55     */
56 jonen 1.1 var $_options = array();
57 jonen 1.2
58 jonen 1.1 var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";
59    
60 jonen 1.2 function EditDataItem($title, $options = array()) {
61 jonen 1.1 $this->_options = $options;
62 jonen 1.2 // prefetch data
63     $this->data_prefetch();
64 jonen 1.1
65     $parent = get_parent_class($this);
66 jonen 1.2 $this->$parent($title, $PHP_SELF, 600);
67 jonen 1.1 }
68    
69     function set_data_source(&$source) {
70 jonen 1.2 $this->_datasource = &$source;
71 jonen 1.1 }
72    
73     function get_data_source() {
74     $initial_locator = php::mkComponent( 'DataSource::Locator', array( adapter_type => 'phpHtmlLib' ) );
75     $proxy = php::mkComponent('DataSource::Generic', $initial_locator, $this->_options['data_locator_meta']);
76     $source = $proxy->get_adapter();
77     $this->set_data_source( &$source );
78     }
79    
80 jonen 1.2 function _check_datasource($function_name) {
81     if ( !is_object($this->_datasource) ) {
82     user_error("DataList::".$function_name."() - DataListSource object is not set");
83     exit;
84     }
85     }
86    
87     function data_prefetch() {
88     $this->get_data_source();
89     $this->_check_datasource("data_prefetch");
90    
91     $this->_datasource->do_query();
92     }
93 jonen 1.1
94     /**
95     * This method gets called EVERY time the object is
96     * created. It is used to build all of the
97     * FormElement objects used in this Form.
98     *
99     */
100     function form_init_elements() {
101     //we want an confirmation page for this form.
102     $this->set_confirm();
103    
104 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
105     $hidden = $this->get_hidden_elements();
106     $options = $this->_options['decode_args'];
107    
108 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
109 jonen 1.1 if($value) {
110     $validation = TRUE;
111     } else {
112     $validation = FALSE;
113     }
114 jonen 1.4 if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
115 jonen 1.1 $this->add_element( new FEText($key, $validation, "350px") );
116     }
117     }
118    
119     }
120    
121     /**
122     * This method is called only the first time the form
123     * page is hit. This enables u to query a DB and
124     * pre populate the FormElement objects with data.
125     *
126     */
127     function form_init_data() {
128     //Pull some valies from the DB
129     //and set the initial values of some of the
130     //form fields.
131    
132 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
133     $hidden = $this->get_hidden_elements();
134     $options = $this->_options['decode_args'];
135    
136 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
137 jonen 1.4 if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
138 jonen 1.1 $this->set_element_value($key, $value);
139     }
140     }
141    
142 jonen 1.2 /* OLD !!
143 jonen 1.1 $post_vars = array_join_merge($_GET, $_POST);
144     foreach ($post_vars as $var => $val) {
145     $this->set_hidden_element_value($var, $val);
146     }
147 jonen 1.2 */
148 jonen 1.1
149     }
150    
151    
152     function form_content() {
153     $this->add_form_block($this->_caption, $this->_dataitem() );
154     }
155    
156     function &_dataitem() {
157     $table = &html_table($this->_width,0,2);
158    
159 jonen 1.2 foreach($this->_datasource->_result as $key => $value) {
160 jonen 1.1 // if item is match by expression we will replace it with an link object
161 jonen 1.2 if($this->_options['decode']) {
162 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
163     $hidden = $this->get_hidden_elements();
164     $options = $this->_options['decode_args'];
165     if($utils->decode_item_expr($value, $hidden, $options)) {
166 joko 1.5 $table->add_row($key, $value);
167 jonen 1.2 }
168     // if item is an Array we will replace it with an selection form object
169 jonen 1.4 elseif($utils->decode_item_array($value, $hidden, $options) ) {
170 joko 1.5 $table->add_row($key, $value);
171 jonen 1.2 } else {
172     $table->add_row($this->element_label($key), $this->element_form($key));
173     }
174     } else {
175 jonen 1.1 $table->add_row($this->element_label($key), $this->element_form($key));
176     }
177     }
178    
179     return $table;
180     }
181    
182     /**
183     * This method gets called after the FormElement data has
184     * passed the validation. This enables you to validate the
185     * data against some backend mechanism, say a DB.
186     *
187     */
188     function form_backend_validation() {
189     //$this->add_error("Ass", "some bogus error happened");
190     //return FALSE;
191     //foreach($this->raw_data as $key => $value) {
192     // if($this->_elements[$key]->get_value()) {
193     // $this->add_error($key, "empty field!");
194     // return FALSE;
195     // } else {
196     // return TRUE;
197     // }
198     // }
199     $this->set_action("Confirm");
200     return TRUE;
201     }
202    
203    
204     /**
205     * This function is used to show an intermediary
206     * confirmation page. Use this function to
207     * show a confirmation of the data that was
208     * submitted by the user.
209     * This will get called after all of the
210     * form data was successfully validated.
211     * All of the form data will automatically
212     * be created as hidden form fields. All you
213     * have to do is show the data, and a confirm
214     * submit button.
215     *
216     * @return mixed - either raw html, or some
217     * container HTMLTag object.
218     */
219     function form_confirm( ) {
220     $title = "Form Confirmation / " . $this->_options['caption'];
221     $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
222     $table = new InfoTable($title, $this->_width);
223    
224     $this->build_confirm_table( $table );
225    
226     //now add the confirmation button
227     $td = new TDtag(array("colspan" => 2,
228     "class" => "contentnovertical",
229     "align" => "center"),
230 jonen 1.3 form_submit('ecdfe', "Confirm"),
231 jonen 1.1 _HTML_SPACE,
232     $this->add_action("Edit"));
233    
234     if ($this->_cancel_action) {
235     $td->add(_HTML_SPACE, $this->add_cancel());
236     }
237    
238     $table->add_row( $td );
239    
240     return $table;
241     }
242    
243    
244    
245    
246     /**
247     * This method is called ONLY after ALL validation has
248     * passed. This is the method that allows you to
249     * do something with the data, say insert/update records
250     * in the DB.
251     */
252     function confirm_action() {
253    
254 jonen 1.4 $utils = php::mkComponent('WebExplorer::utils');
255     $hidden = $this->get_hidden_elements();
256     $options = $this->_options['decode_args'];
257    
258 jonen 1.2 foreach($this->_datasource->_result as $label => $value_old) {
259 jonen 1.4 if(!$utils->decode_item_expr($value_old, $hidden, $options) && !$utils->decode_item_array($value_old, $hidden, $options)) {
260 jonen 1.1 $value_new = $this->_elements[$label]->get_value();
261 jonen 1.2 $data[$label] = $value_new;
262     }
263 jonen 1.1 }
264 jonen 1.3 // write new data to datasource
265 jonen 1.2 $this->_options['data_locator_meta']['action'] = "write";
266     $this->_options['data_locator_meta']['data'] = $data;
267 jonen 1.3 // TODO: 'data_prefetch()' will never return ANYTHING!
268     // Implement some error-handling there or somewhere.
269 jonen 1.2 $error = $this->data_prefetch();
270 jonen 1.3
271 jonen 1.2 //$error = $this->_datasource->set($item);
272 jonen 1.1 if(!$error) {
273 jonen 1.3 // fetch fresh data
274     $this->_options['data_locator_meta']['action'] = "read";
275     // unset previous initialed 'data' var
276     $this->_options['data_locator_meta']['data'] = NULL;
277     $this->data_prefetch();
278    
279 jonen 1.1 $this->set_action_message($this->_confirm_msg);
280     return TRUE;
281     } else {
282     return FALSE;
283     }
284     }
285    
286 jonen 1.2 /**
287     * This function is used to build the standard
288     * buttons for a form.
289     *
290     * @return ButtonPanel
291     */
292     function form_content_buttons() {
293     $div = new DIVtag( array("style" => "background-color: #eeeeee;".
294     "padding-top:5px;padding-bottom:5px",
295     "align"=>"center", "nowrap"),
296 jonen 1.3 form_submit('ecdfe', "Save"),
297 jonen 1.2 _HTML_SPACE,
298 jonen 1.3 //$this->add_cancel()
299     form_submit('ecdfc', "Cancel")
300     );
301 jonen 1.2 return $div;
302     }
303    
304    
305 jonen 1.4 function get_hidden_elements() {
306     foreach($this->_hidden_elements as $label => $object) {
307     $value = $this->_hidden_elements[$label]->get_value();
308     $tmp_array[$label] = $value;
309 jonen 1.1 }
310 jonen 1.4 return $tmp_array;
311 jonen 1.1 }
312    
313     }
314    
315    
316     ?>

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