/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/forms/EditPageForm.php
ViewVC logotype

Diff of /nfo/php/libs/org.netfrag.patches/phphtmllib/forms/EditPageForm.php

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

revision 1.3 by udo, Mon Dec 15 21:03:19 2003 UTC revision 1.4 by udo, Thu Mar 4 23:07:13 2004 UTC
# Line 38  Line 38 
38      $this->_undone = $undone;      $this->_undone = $undone;
39      $parent = get_parent_class($this);      $parent = get_parent_class($this);
40    
41    
42        //$this->$parent($title, $_SERVER['PHP_SELF'], $options);
43      $this->$parent($title, $options);      $this->$parent($title, $options);
44    }    }
45      
     
46  // this function is needed, because _set_items and _show_items may contain a  // this function is needed, because _set_items and _show_items may contain a
47  // different amount of entries. in that case we have ensure, that there will  // different amount of entries. in that case we have ensure, that there will
48  // be input-fields at the mising places and that the data will be recieved  // be input-fields at the mising places and that the data will be recieved
49  // with the correct lkey  // with the correct lkey
50      function get_nested_array_by_lkey($whichArray, $whichKey) {    function get_nested_array_by_lkey($whichArray, $whichKey) {
51          $myArray = array();          $myArray = array();
52          $myArray = &$whichArray;          $myArray = &$whichArray;
53        foreach ($myArray as $key=>$value) {        foreach ($myArray as $key=>$value) {
54          if ($value['lkey'] == $whichKey) {          if ($value['lkey'] == $whichKey) {return $value;}
                 return $value;}  
55        }        }
56      }      }
57    
# Line 74  Line 74 
74          if (empty($this->_undone)) {              if (empty($this->_undone)) {    
75                  $this->_undone = $_REQUEST['_undone'];                  $this->_undone = $_REQUEST['_undone'];
76          }          }
77            
           
78  // used_keys are all lkeys, that contain the _sql_key  // used_keys are all lkeys, that contain the _sql_key
79     $used_keys = array();     $used_keys = array();
80            
81          $this->set_confirm();          $this->set_confirm();
82    
83          // the _datasource->result - object is parsed and the matching items are          // the _datasource->result - object is parsed and the matching items are
# Line 211  Line 210 
210       * @param InfoTable object       * @param InfoTable object
211       */         */  
212      function build_confirm_table( &$table ) {      function build_confirm_table( &$table ) {
213                    foreach( $this->_elements as $label => $element) {
214          $useless_keys = array ('0' => "ecdfe",                          if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
215                                                                                          '1' => "_form_action",                                  $correct_key = substr($label, 0, strlen($label) - 3);
216                                                                                          '2' => "_form_visited",                                  $correct_key = str_replace("x_x", "/", $correct_key);
217                                                                                          '3' => "_form_confirm",                                  $table->add_row( $correct_key, $element->get_value());
                                                                                         );  
   
 // the actually updated data has to be parsed out of the post data.  
 // there is a lot data in the post that is useless for this, like for page-control usw.  
 // if the selected show- and set-language is the same, we will only confirm the set-items  
                 if ($_REQUEST['_set_lang'] <> $_REQUEST['_show_lang']) {  
                         foreach( $_POST as $label => $element) {  
                           
 // the wanted data is not part of the hidden elements, not part of the useless page-control-post (useless_keys)  
 // and its key contains the selected set-language  
                                 if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  stristr(substr($label, strlen($label)-3, 2) , $_REQUEST['_set_lang']) ){  
                                         $correct_key = substr($label, 0, strlen($label) - 3);  
                                         $correct_key = str_replace("x_x", "/", $correct_key);  
                                         $table->add_row( $correct_key, $element);  
                                 }  
218                          }                          }
                 } else {  
                         foreach( $_POST as $label => $element) {  
                                 if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  (substr($label, strlen($label)-1, 1) == "u") ){  
                                         $correct_key = substr($label, 0, strlen($label) - 3);  
                                         $correct_key = str_replace("x_x", "/", $correct_key);  
                                         $table->add_row( $correct_key, $element);  
                                 }  
                         }                        
219                  }                  }
220      }      }
221        
# Line 259  Line 235 
235                                                  form_submit('ecdfc',"Edit"));                                                  form_submit('ecdfc',"Edit"));
236    
237          $table->add_row( $td );          $table->add_row( $td );
   
238          return $table;          return $table;
239          }          }
240    
# Line 320  Line 295 
295    }    }
296    
297    
 // for the final form action the post-variables have to be parsed again and merged together with the datasource-result  
 // in a way that keeps the guid from the datasource-result and replaces the old lvalues with the new ones.  
298    function form_action() {    function form_action() {
299    
300          $useless_keys = array ('0' => "ecdfe",          $data = array();        
                                                                                         '1' => "_form_action",  
                                                                                         '2' => "_form_visited",  
                                                                                         '3' => "_form_confirm",  
                                                                                         );  
   
301          $new_data = array();          $new_data = array();
302          $used_keys = array();          foreach( $this->_elements as $label => $element) {                      
303                    if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
 // the keys that will be needed for update are parsed from the post  
         foreach( $_POST as $label => $element) {  
                         if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  stristr(substr($label, strlen($label)-3, 2) , $_REQUEST['_set_lang']) ){  
304                                  $correct_key = substr($label, 0, strlen($label) - 3);                                  $correct_key = substr($label, 0, strlen($label) - 3);
305                                  $correct_key = str_replace("x_x", "/", $correct_key);                                  $correct_key = str_replace("x_x", "/", $correct_key);
306                                  $used_keys[$correct_key] = $element;                                  $new_data[$correct_key]=$element->get_value();
307                          }                          }
308          }          }      
309    
310  // the guid of the updated elements is received out of the datasource-result and          foreach ($this->_set_items as $item_key => $item_value) {
311  // the old items are replaced by the new ones.                  foreach($new_data as $data_key => $data_value) {
312                  foreach ($this->_datasource->_result as $key=>$value) {                          if ($data_key == $item_value['lkey']) {
313                          if      (array_key_exists($value['lkey'], $used_keys) && ($value['lcountrykey'] == $_REQUEST['_set_lang'])) {                                  $tmp_array = $item_value;
314                                  $new_data[$key] = $value;                                  $tmp_array['lvalue'] = $data_value;
315                                  $new_data[$key]['lvalue'] = $used_keys[$value['lkey']];                                  array_push($data, $tmp_array);
                         }  
                 }  
   
 // if there are completely new items without a guid, they are pushed to the new data-array in  
 // the correct form, as an array containing a lkey, a lcountrykey and, of course, a lvalue  
                 if (array_count_values($new_data)<array_count_values($used_keys)) {  
                         foreach ($used_keys as $key=>$value) {  
                                 $wanted_array = $this->get_nested_array_by_lkey($new_data, $key);  
                                 if (!is_array($wanted_array)) {  
                                         $tmp_array = array();  
                                         $tmp_array['lcountrykey'] = $_REQUEST['_set_lang'];  
                                         $tmp_array['lvalue'] = $value;  
                                         $tmp_array['lkey'] = $key;  
                                         $tmp_array['GIUD'] = "";  
                                         array_push($new_data, $tmp_array);  
                                 }  
316                          }                          }
317                  }                  }
318            }
319                    
320                    
321            //      print " data: " .Dumper($data). "<br>";
322                    
323            // write new data to datasource in $data as array (keep old indices, set new values)            // write new data to datasource in $data as array (keep old indices, set new values)
324          $this->_options['data_locator_meta']['action'] = "write";          $this->_options['data_locator_meta']['action'] = "write";
325          $this->_options['data_locator_meta']['data'] = $new_data;          $this->_options['data_locator_meta']['data'] = $data;
326          // TODO: 'data_prefetch()' will never return ANYTHING!          // TODO: 'data_prefetch()' will never return ANYTHING!
327          //           Implement some error-handling there or somewhere.          //           Implement some error-handling there or somewhere.
328          $error = $this->data_prefetch();          $error = $this->data_prefetch();
329    }    }
330    function form_backend_validation() {    function form_backend_validation() {
331      $this->set_action("Confirm");      $this->set_action("Confirm");
332      return TRUE;      return TRUE;
333    }    }
334    function confirm_action() {    function confirm_action() {
335         $this->set_action_message("yip, alles klar!");
336      return TRUE;      return TRUE;
337    }    }
338  }  }

Legend:
Removed from v.1.3  
changed lines
  Added in v.1.4

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