/[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.8 - (hide annotations)
Mon Dec 15 21:05:19 2003 UTC (20 years, 9 months ago) by udo
Branch: MAIN
Changes since 1.7: +7 -3 lines
bugfix: $PHP_SELF -> $_SERVER['PHP_SELF']

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

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