/[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.1 - (hide annotations)
Thu Mar 27 01:18:06 2003 UTC (21 years, 5 months ago) by jonen
Branch: MAIN
+ inital commit (was orginal 'DataItem.php')

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

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