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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by jonen, Thu Mar 27 01:18:06 2003 UTC revision 1.2 by jonen, Fri Apr 4 00:43:22 2003 UTC
# Line 4  Line 4 
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ##    -----------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.2  2003/04/04 00:43:22  jonen
8    ##    + complete rework
9    ##
10  ##    Revision 1.1  2003/03/27 01:18:06  jonen  ##    Revision 1.1  2003/03/27 01:18:06  jonen
11  ##    + inital commit (was orginal 'DataItem.php')  ##    + inital commit (was orginal 'DataItem.php')
12  ##  ##
# Line 36  Line 39 
39    
40  class EditDataItem extends StandardFormContent {  class EditDataItem extends StandardFormContent {
41    
42     /**
43      * holds reference to source object.
44      */
45     var $_datasource = NULL;
46    
47     /**
48      * container for arguments needed for e.g. setting the source object.
49      */
50   var $_options = array();   var $_options = array();
51    
52   var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";   var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";
53    
54    function EditDataItem($options = array()) {    function EditDataItem($title, $options = array()) {
55      $this->_options = $options;      $this->_options = $options;
56        // prefetch data
57        $this->data_prefetch();
58    
59      $parent =  get_parent_class($this);      $parent =  get_parent_class($this);
60      $this->$parent($this->_options['caption'], $PHP_SELF, 600);      $this->$parent($title, $PHP_SELF, 600);
61    }    }
62    
63    function set_data_source(&$source) {    function set_data_source(&$source) {
64      $this->_source = &$source;      $this->_datasource = &$source;
65    }    }
66    
67    function get_data_source() {    function get_data_source() {
# Line 57  class EditDataItem extends StandardFormC Line 71  class EditDataItem extends StandardFormC
71        $this->set_data_source( &$source );            $this->set_data_source( &$source );    
72    }    }
73    
74      function _check_datasource($function_name) {
75          if ( !is_object($this->_datasource) ) {
76                user_error("DataList::".$function_name."() - DataListSource object is not set");
77                exit;
78          }
79      }
80    
81      function data_prefetch() {
82        $this->get_data_source();
83        $this->_check_datasource("data_prefetch");
84    
85        $this->_datasource->do_query();
86      }
87    
88      /**      /**
89       * This method gets called EVERY time the object is       * This method gets called EVERY time the object is
# Line 68  class EditDataItem extends StandardFormC Line 95  class EditDataItem extends StandardFormC
95          //we want an confirmation page for this form.          //we want an confirmation page for this form.
96          $this->set_confirm();          $this->set_confirm();
97    
98          foreach($this->_source->_result as $key => $value) {          foreach($this->_datasource->_result as $key => $value) {
99            if($value) {            if($value) {
100              $validation = TRUE;              $validation = TRUE;
101            } else {            } else {
# Line 92  class EditDataItem extends StandardFormC Line 119  class EditDataItem extends StandardFormC
119          //and set the initial values of some of the          //and set the initial values of some of the
120          //form fields.          //form fields.
121    
122        foreach($this->_source->_result as $key => $value) {        foreach($this->_datasource->_result as $key => $value) {
123          if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {          if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {
124            $this->set_element_value($key, $value);            $this->set_element_value($key, $value);
125          }          }
126        }        }
127    
128          /* OLD !!
129       $post_vars = array_join_merge($_GET, $_POST);       $post_vars = array_join_merge($_GET, $_POST);
130        foreach ($post_vars as $var => $val) {        foreach ($post_vars as $var => $val) {
131          $this->set_hidden_element_value($var, $val);          $this->set_hidden_element_value($var, $val);
132        }        }
133          */
134    
135      }      }
136    
# Line 113  class EditDataItem extends StandardFormC Line 142  class EditDataItem extends StandardFormC
142      function &_dataitem() {      function &_dataitem() {
143        $table = &html_table($this->_width,0,2);        $table = &html_table($this->_width,0,2);
144                    
145        foreach($this->_source->_result as $key => $value) {        foreach($this->_datasource->_result as $key => $value) {
146          // if item is match by expression we will replace it with an link object            // if item is match by expression we will replace it with an link object  
147          if($this->decode_item_expr($value, $this->_options) && $this->_options['inheritance']) {            if($this->_options['decode']) {
148            $table->add_row($key, $this->decode_item_expr($value, $this->_options));             if($this->decode_item_expr($value)) {  
149          }            $table->add_row($key, $this->decode_item_expr($value));  
150          // if item is an Array we will replace it with an selection form object             }  
151          elseif($this->decode_item_array($value, $this->_options) && $this->_options['inheritance']) {           // if item is an Array we will replace it with an selection form object  
152            $table->add_row($key, $this->decode_item_array($value, $this->_options));             elseif($this->decode_item_array($value) ) {
153          }              $table->add_row($key, $this->decode_item_array($value));
154          else {           } else {
155               $table->add_row($this->element_label($key), $this->element_form($key));
156             }
157            } else {
158            $table->add_row($this->element_label($key), $this->element_form($key));            $table->add_row($this->element_label($key), $this->element_form($key));
159          }          }
160        }        }
# Line 178  class EditDataItem extends StandardFormC Line 210  class EditDataItem extends StandardFormC
210          $td = new TDtag(array("colspan" => 2,          $td = new TDtag(array("colspan" => 2,
211                                "class" => "contentnovertical",                                "class" => "contentnovertical",
212                                "align" => "center"),                                "align" => "center"),
213                          $this->add_action("Confirm"),                          form_submit('ecfedit', "Confirm"),
214                          _HTML_SPACE,                          _HTML_SPACE,
215                          $this->add_action("Edit"));                          $this->add_action("Edit"));
216    
# Line 202  class EditDataItem extends StandardFormC Line 234  class EditDataItem extends StandardFormC
234       */       */
235      function confirm_action() {      function confirm_action() {
236    
237          foreach($this->_source->_result as $label => $value_old) {          foreach($this->_datasource->_result as $label => $value_old) {
238                print $label . "<br>";
239              if(!$this->decode_item_expr($value_old) && !$this->decode_item_array($value_old)) {
240              $value_new = $this->_elements[$label]->get_value();              $value_new = $this->_elements[$label]->get_value();
241              $item[$label] = $value_new;              $data[$label] = $value_new;
242              }
243          }          }
244          $error = $this->_source->set($item);          $this->_options['data_locator_meta']['action'] = "write";
245            $this->_options['data_locator_meta']['data'] = $data;
246            $error = $this->data_prefetch();
247    
248            //$error = $this->_datasource->set($item);
249          if(!$error) {          if(!$error) {
250            $this->set_action_message($this->_confirm_msg);            $this->set_action_message($this->_confirm_msg);
251            return TRUE;            return TRUE;
# Line 215  class EditDataItem extends StandardFormC Line 254  class EditDataItem extends StandardFormC
254          }          }
255      }      }
256    
257        /**
258         * This function is used to build the standard
259         * buttons for a form.
260         *
261         * @return ButtonPanel
262         */
263        function form_content_buttons() {
264            $div = new DIVtag( array("style" => "background-color: #eeeeee;".
265                                                "padding-top:5px;padding-bottom:5px",
266                                     "align"=>"center", "nowrap"),
267                               form_submit('ecfedit', "Save"),
268                               _HTML_SPACE,
269                               $this->add_cancel() );
270            return $div;
271        }
272    
273    
274    
275    function decode_item_array($item, $options=array()) {  
276      function decode_item_array($item) {
277        $options = $this->_options['decode_args'];
278      if( is_array($item) ) {      if( is_array($item) ) {
279            //$cur_row_index = $this->_datasource->get_cur_data_index();            //$cur_row_index = $this->_datasource->get_cur_data_index();
280            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];
# Line 231  class EditDataItem extends StandardFormC Line 289  class EditDataItem extends StandardFormC
289                  if(is_array($list) ) {                  if(is_array($list) ) {
290                $container = container(                $container = container(
291                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),
292                    form_open("meta", $meta),                    form_hidden("ecdm", $meta),
293                    form_select("ident", $list),                    form_select("ecdid", $list),
294                    form_submit("submit","view" ),                    form_submit("submit","view" )
                   form_close()  
295                    );                    );
296                 foreach($this->_hidden_items as $label => $value) {                 foreach($this->_hidden_elements as $label => $value) {
297                   $container->add(form_hidden($label, $value));                   $container->add(form_hidden($label, $value));
298                 }                 }
299                  $container->add(form_close() );
300                $item = $container;                $item = $container;
301                }                }
302          } else {          } else {
# Line 247  class EditDataItem extends StandardFormC Line 305  class EditDataItem extends StandardFormC
305                  $tmp = split($options['seperator'], $value);                  $tmp = split($options['seperator'], $value);
306                  $ident = $tmp['1'];                  $ident = $tmp['1'];
307                  $meta = $tmp['2'];                  $meta = $tmp['2'];
308                       foreach($this->_hidden_items as $label => $value) {                  foreach($this->_hidden_elements as $label => $object) {
309                      $value = $this->_hidden_elements[$label]->get_value();
310                         $tmp_array[] = $label . "=" . $value;                         $tmp_array[] = $label . "=" . $value;
311                       }                       }
312                       $str_hidden = join("&", $tmp_array);                       $str_hidden = join("&", $tmp_array);
313                  $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ident=" . $ident . "&meta=" . $meta . $str_hidden, $key . " view"), html_br());                                $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, $key . " view"), html_br());              
314            }            }
315            $item = $container;            $item = $container;
316          }          }
# Line 259  class EditDataItem extends StandardFormC Line 318  class EditDataItem extends StandardFormC
318      }      }
319    }    }
320    
321    function decode_item_expr($item, $options=array()) {  
322      function decode_item_expr($item) {
323        $options = $this->_options['decode_args'];
324      if(substr($item, 0, 2) == "o_") {      if(substr($item, 0, 2) == "o_") {
325            $tmp = split($options['seperator'], $item);            $tmp = split($options['seperator'], $item);
326            $ident = $tmp['1'];            $ident = $tmp['1'];
327            $meta = $tmp['2'];            $meta = $tmp['2'];
328            foreach($this->_hidden_items as $label => $value) {            foreach($this->_hidden_elements as $label => $object) {
329                 $value = $this->_hidden_elements[$label]->get_value();
330               $tmp_array[] = $label . "=" . $value;               $tmp_array[] = $label . "=" . $value;
331            }            }
332            $str_hidden = join("&", $tmp_array);            $str_hidden = join("&", $tmp_array);
333            $item = html_a($_SERVER["PHP_SELF"] . "?ident=" . $guid . "&meta=" . $meta . $str_hidden, "view");            $item = html_a($_SERVER["PHP_SELF"] . "?ecdid=" . $ident . "&ecdm=" . $meta . "&" . $str_hidden, "view");
334            return $item;            return $item;
335      }      }
336    }    }

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.2

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