/[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.8 by udo, Mon Dec 15 21:05:19 2003 UTC
# Line 4  Line 4 
4  ##    $Id$  ##    $Id$
5  ##    -----------------------------------------------------------------------------  ##    -----------------------------------------------------------------------------
6  ##    $Log$  ##    $Log$
7    ##    Revision 1.8  2003/12/15 21:05:19  udo
8    ##    bugfix: $PHP_SELF -> $_SERVER['PHP_SELF']
9    ##
10    ##    Revision 1.7  2003/05/10 18:04:45  jonen
11    ##    + added values needed for 'create/add new' links
12    ##
13    ##    Revision 1.6  2003/04/11 00:48:03  joko
14    ##    minor fix: calling parent constructor explicitely by name now, transparency seems not be automagically compatible with inheritance in php ,-)    (non-orthogonal)
15    ##
16    ##    Revision 1.5  2003/04/09 09:59:30  joko
17    ##    fixes regarding modification of decode-function-behavior
18    ##
19    ##    Revision 1.4  2003/04/06 01:41:33  jonen
20    ##    - removed duplicated decode functions
21    ##
22    ##    Revision 1.3  2003/04/04 23:58:02  jonen
23    ##    + saving of items sould now work with new 'GenericSource' structure
24    ##
25    ##    Revision 1.2  2003/04/04 00:43:22  jonen
26    ##    + complete rework
27    ##
28  ##    Revision 1.1  2003/03/27 01:18:06  jonen  ##    Revision 1.1  2003/03/27 01:18:06  jonen
29  ##    + inital commit (was orginal 'DataItem.php')  ##    + inital commit (was orginal 'DataItem.php')
30  ##  ##
# Line 36  Line 57 
57    
58  class EditDataItem extends StandardFormContent {  class EditDataItem extends StandardFormContent {
59    
60     /**
61      * holds reference to source object.
62      */
63     var $_datasource = NULL;
64    
65     /**
66      * container for arguments needed for e.g. setting the source object.
67      */
68   var $_options = array();   var $_options = array();
69    
70   var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";   var $_confirm_msg = "Die Daten wurden erfolgreich gespeichert!";
71    
72    function EditDataItem($options = array()) {    function EditDataItem($title, $options = array()) {
73      $this->_options = $options;      $this->_options = $options;
74        // prefetch data
75        $this->data_prefetch();
76    
77        // doesn't work if EditDataItem gets inherited
78        //$parent = get_parent_class($this);
79        //$this->$parent($title, $PHP_SELF, 600);
80        
81    //    $this->StandardFormContent($title, $PHP_SELF, 600);
82        $this->StandardFormContent($title, $_SERVER['PHP_SELF'], 600);
83    
     $parent =  get_parent_class($this);  
     $this->$parent($this->_options['caption'], $PHP_SELF, 600);  
84    }    }
85    
86    function set_data_source(&$source) {    function set_data_source(&$source) {
87      $this->_source = &$source;      $this->_datasource = &$source;
88    }    }
89    
90    function get_data_source() {    function get_data_source() {
# Line 57  class EditDataItem extends StandardFormC Line 94  class EditDataItem extends StandardFormC
94        $this->set_data_source( &$source );            $this->set_data_source( &$source );    
95    }    }
96    
97      function _check_datasource($function_name) {
98          if ( !is_object($this->_datasource) ) {
99                user_error("DataList::".$function_name."() - DataListSource object is not set");
100                exit;
101          }
102      }
103    
104      function data_prefetch() {
105        $this->get_data_source();
106        $this->_check_datasource("data_prefetch");
107    
108        $this->_datasource->do_query();
109      }
110    
111      /**      /**
112       * 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 118  class EditDataItem extends StandardFormC
118          //we want an confirmation page for this form.          //we want an confirmation page for this form.
119          $this->set_confirm();          $this->set_confirm();
120    
121          foreach($this->_source->_result as $key => $value) {           $utils = php::mkComponent('WebExplorer::utils');
122             $hidden = $this->get_hidden_elements();
123             $options = $this->_options['decode_args'];
124    
125            foreach($this->_datasource->_result as $key => $value) {
126            if($value) {            if($value) {
127              $validation = TRUE;              $validation = TRUE;
128            } else {            } else {
129              $validation = FALSE;              $validation = FALSE;
130            }            }
131            if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {            if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
132              $this->add_element( new FEText($key, $validation, "350px") );              $this->add_element( new FEText($key, $validation, "350px") );
133            }            }
134          }          }
# Line 92  class EditDataItem extends StandardFormC Line 146  class EditDataItem extends StandardFormC
146          //and set the initial values of some of the          //and set the initial values of some of the
147          //form fields.          //form fields.
148    
149        foreach($this->_source->_result as $key => $value) {           $utils = php::mkComponent('WebExplorer::utils');
150          if(!$this->decode_item_expr($value, $this->_options) && !$this->decode_item_array($value, $this->_options)) {           $hidden = $this->get_hidden_elements();
151             $options = $this->_options['decode_args'];
152    
153          foreach($this->_datasource->_result as $key => $value) {
154            if(!$utils->decode_item_expr($value, $hidden, $options) && !$utils->decode_item_array($value, $hidden, $options)) {
155            $this->set_element_value($key, $value);            $this->set_element_value($key, $value);
156          }          }
157        }        }
158    
159          /* OLD !!
160       $post_vars = array_join_merge($_GET, $_POST);       $post_vars = array_join_merge($_GET, $_POST);
161        foreach ($post_vars as $var => $val) {        foreach ($post_vars as $var => $val) {
162          $this->set_hidden_element_value($var, $val);          $this->set_hidden_element_value($var, $val);
163        }        }
164          */
165    
166      }      }
167    
# Line 113  class EditDataItem extends StandardFormC Line 173  class EditDataItem extends StandardFormC
173      function &_dataitem() {      function &_dataitem() {
174        $table = &html_table($this->_width,0,2);        $table = &html_table($this->_width,0,2);
175                    
176        foreach($this->_source->_result as $key => $value) {        foreach($this->_datasource->_result as $key => $value) {
177          // 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  
178          if($this->decode_item_expr($value, $this->_options) && $this->_options['inheritance']) {            if($this->_options['decode']) {
179            $table->add_row($key, $this->decode_item_expr($value, $this->_options));             $utils = php::mkComponent('WebExplorer::utils');
180          }           $hidden = $this->get_hidden_elements();
181          // if item is an Array we will replace it with an selection form object             $options = $this->_options['decode_args'];
182          elseif($this->decode_item_array($value, $this->_options) && $this->_options['inheritance']) {           $options[label] = $key;
183            $table->add_row($key, $this->decode_item_array($value, $this->_options));             $options[parent_guid] = $this->_options['parent']['guid'];
184          }           $options[parent_class] = $this->_options['parent']['class'];
185          else {           if($utils->decode_item_expr($value, $hidden, $options)) {  
186              $table->add_row($key, $value);  
187             }  
188             // if item is an Array we will replace it with an selection form object  
189             elseif($utils->decode_item_array($value, $hidden, $options) ) {
190                $table->add_row($key, $value);
191             } else {
192               $table->add_row($this->element_label($key), $this->element_form($key));
193             }
194            } else {
195            $table->add_row($this->element_label($key), $this->element_form($key));            $table->add_row($this->element_label($key), $this->element_form($key));
196          }          }
197        }        }
# Line 178  class EditDataItem extends StandardFormC Line 247  class EditDataItem extends StandardFormC
247          $td = new TDtag(array("colspan" => 2,          $td = new TDtag(array("colspan" => 2,
248                                "class" => "contentnovertical",                                "class" => "contentnovertical",
249                                "align" => "center"),                                "align" => "center"),
250                          $this->add_action("Confirm"),                          form_submit('ecdfe', "Confirm"),
251                          _HTML_SPACE,                          _HTML_SPACE,
252                          $this->add_action("Edit"));                          $this->add_action("Edit"));
253    
# Line 202  class EditDataItem extends StandardFormC Line 271  class EditDataItem extends StandardFormC
271       */       */
272      function confirm_action() {      function confirm_action() {
273    
274          foreach($this->_source->_result as $label => $value_old) {           $utils = php::mkComponent('WebExplorer::utils');
275             $hidden = $this->get_hidden_elements();
276             $options = $this->_options['decode_args'];
277    
278            foreach($this->_datasource->_result as $label => $value_old) {
279              if(!$utils->decode_item_expr($value_old, $hidden, $options) && !$utils->decode_item_array($value_old, $hidden, $options)) {
280              $value_new = $this->_elements[$label]->get_value();              $value_new = $this->_elements[$label]->get_value();
281              $item[$label] = $value_new;              $data[$label] = $value_new;
282              }
283          }          }
284          $error = $this->_source->set($item);          // write new data to datasource
285            $this->_options['data_locator_meta']['action'] = "write";
286            $this->_options['data_locator_meta']['data'] = $data;
287            // TODO: 'data_prefetch()' will never return ANYTHING!
288            //           Implement some error-handling there or somewhere.
289            $error = $this->data_prefetch();
290            
291            //$error = $this->_datasource->set($item);
292          if(!$error) {          if(!$error) {
293              // fetch fresh data
294              $this->_options['data_locator_meta']['action'] = "read";
295              // unset previous initialed 'data' var
296              $this->_options['data_locator_meta']['data'] = NULL;
297              $this->data_prefetch();
298            
299            $this->set_action_message($this->_confirm_msg);            $this->set_action_message($this->_confirm_msg);
300            return TRUE;            return TRUE;
301          } else {          } else {
# Line 215  class EditDataItem extends StandardFormC Line 303  class EditDataItem extends StandardFormC
303          }          }
304      }      }
305    
306        /**
307    function decode_item_array($item, $options=array()) {       * This function is used to build the standard
308      if( is_array($item) ) {       * buttons for a form.
309            //$cur_row_index = $this->_datasource->get_cur_data_index();       *
310            //$parent_guid = $this->_datasource->_data[$cur_row_index]['guid'];       * @return ButtonPanel
311            // build list for selection form       */
312         if($options['form']) {      function form_content_buttons() {
313            foreach($item as $key => $value) {          $div = new DIVtag( array("style" => "background-color: #eeeeee;".
314                  $tmp = split($options['seperator'], $value);                                              "padding-top:5px;padding-bottom:5px",
315                  $ident = $tmp['1'];                                   "align"=>"center", "nowrap"),
316                  $meta = $tmp['2'];                             form_submit('ecdfe', "Save"),
317                  $list[$key] = $ident;                             _HTML_SPACE,
318                  }                             //$this->add_cancel()
319                  if(is_array($list) ) {                             form_submit('ecdfc', "Cancel")
320                $container = container(                             );
321                    form_open( $item[0], $_SERVER["PHP_SELF"], "POST" ),          return $div;
                   form_open("meta", $meta),  
                   form_select("ident", $list),  
                   form_submit("submit","view" ),  
                   form_close()  
                   );  
                foreach($this->_hidden_items as $label => $value) {  
                  $container->add(form_hidden($label, $value));  
                }  
               $item = $container;  
               }  
         } else {  
           $container = container();  
           foreach($item as $key => $value) {  
                 $tmp = split($options['seperator'], $value);  
                 $ident = $tmp['1'];  
                 $meta = $tmp['2'];  
                      foreach($this->_hidden_items as $label => $value) {  
                        $tmp_array[] = $label . "=" . $value;  
                      }  
                      $str_hidden = join("&", $tmp_array);  
                 $container->add("->", html_a($_SERVER["PHP_SELF"] . "?ident=" . $ident . "&meta=" . $meta . $str_hidden, $key . " view"), html_br());                
           }  
           $item = $container;  
         }  
               return $item;  
322      }      }
   }  
323    
324    function decode_item_expr($item, $options=array()) {  
325      if(substr($item, 0, 2) == "o_") {    function get_hidden_elements() {
326            $tmp = split($options['seperator'], $item);      foreach($this->_hidden_elements as $label => $object) {
327            $ident = $tmp['1'];        $value = $this->_hidden_elements[$label]->get_value();
328            $meta = $tmp['2'];        $tmp_array[$label] = $value;
           foreach($this->_hidden_items as $label => $value) {  
              $tmp_array[] = $label . "=" . $value;  
           }  
           $str_hidden = join("&", $tmp_array);  
           $item = html_a($_SERVER["PHP_SELF"] . "?ident=" . $guid . "&meta=" . $meta . $str_hidden, "view");  
           return $item;  
329      }      }
330        return $tmp_array;
331    }    }
332    
   
333  }  }
334    
335    
 ?>  
336    ?>

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

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