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

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

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