/[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.5 by jonen, Tue Dec 14 21: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
84          // written into the arrays          // written into the arrays
85                  foreach($this->_datasource->_result as $key => $value) {                  foreach($this->_datasource->_result as $key => $value) {
86                    if (strstr ( $value['lkey'], $this->_sql_key)) {                    if (strstr ( $value['lkey'], $this->_sql_key)) {
87                          if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}                          if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}
88                          if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}                          //if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
89                          if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}                          if ($value['lcountrykey'] == $this->_show_lang) {$this->_show_items[$value['lkey']] = $value;}
90                            //if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
91                            if ($value['lcountrykey'] == $this->_set_lang) {$this->_set_items[$value['lkey']] = $value;}
92                    }                    }
93                  }                  }
94                    
95                    
96          // this is needed for sorting          // this is needed for sorting
97                  $tmp_array = array();                  $tmp_array = array();
# Line 130  Line 131 
131          // are not yet translated, every entry, that has lvalues in both arrays, is marked.          // are not yet translated, every entry, that has lvalues in both arrays, is marked.
132                  if ($this->_undone == "yes") {                  if ($this->_undone == "yes") {
133                    foreach ($used_keys as $key => $value) {                          foreach ($used_keys as $key => $value) {      
134                          if ((strlen($larger[$key]['lvalue']) > 0) && (strlen($smaller[$key]['lvalue']) > 0)) {                          if ((strlen($larger[$value]['lvalue']) > 0) && (strlen($smaller[$value]['lvalue']) > 0)) {
135                            $this->_set_items[$key] = "kickedMarkerXXX";                            $this->_set_items[$value] = "kickedMarkerXXX";
136                            $this->_show_items[$key] = "kickedMarkerXXX";                            $this->_show_items[$value] = "kickedMarkerXXX";
137                          }                          }
138                    }                    }
139                  }                  }
# Line 155  Line 156 
156    
157                          $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";                          $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";
158                    
159                          if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {                          if ((strlen($this->_set_items[$value]['lvalue']) < 40) && (strlen($this->_show_items[$value]['lvalue']) < 40)) {
160                            $this->add_element( new FEText($show_el, false, 40, 200));                            $this->add_element( new FEText($show_el, false, 40));
161                            $this->add_element( new FEText($set_el, false, 40, 200));                            $this->add_element( new FEText($set_el, false, 40));
162                          } else{                          } else{
163                            $this->add_element( new FETextArea($show_el, false, 10, 40));                            $this->add_element( new FETextArea($show_el, false, 10, 40));
164                            $this->add_element( new FETextArea($set_el, false, 10, 40));                            $this->add_element( new FETextArea($set_el, false, 10, 40));
# Line 211  Line 212 
212       * @param InfoTable object       * @param InfoTable object
213       */         */  
214      function build_confirm_table( &$table ) {      function build_confirm_table( &$table ) {
215                    foreach( $this->_elements as $label => $element) {
216          $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()){
217                                                                                          '1' => "_form_action",                                  $correct_key = substr($label, 0, strlen($label) - 3);
218                                                                                          '2' => "_form_visited",                                  $correct_key = str_replace("x_x", "/", $correct_key);
219                                                                                          '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);  
                                 }  
220                          }                          }
                 } 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);  
                                 }  
                         }                        
221                  }                  }
222      }      }
223        
# Line 259  Line 237 
237                                                  form_submit('ecdfc',"Edit"));                                                  form_submit('ecdfc',"Edit"));
238    
239          $table->add_row( $td );          $table->add_row( $td );
   
240          return $table;          return $table;
241          }          }
242    
# Line 320  Line 297 
297    }    }
298    
299    
 // 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.  
300    function form_action() {    function form_action() {
301    
302          $useless_keys = array ('0' => "ecdfe",          $data = array();        
                                                                                         '1' => "_form_action",  
                                                                                         '2' => "_form_visited",  
                                                                                         '3' => "_form_confirm",  
                                                                                         );  
   
303          $new_data = array();          $new_data = array();
304          $used_keys = array();          foreach( $this->_elements as $label => $element) {                      
305                    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']) ){  
306                                  $correct_key = substr($label, 0, strlen($label) - 3);                                  $correct_key = substr($label, 0, strlen($label) - 3);
307                                  $correct_key = str_replace("x_x", "/", $correct_key);                                  $correct_key = str_replace("x_x", "/", $correct_key);
308                                  $used_keys[$correct_key] = $element;                                  $new_data[$correct_key]=$element->get_value();
                         }  
         }  
   
 // the guid of the updated elements is received out of the datasource-result and  
 // the old items are replaced by the new ones.  
                 foreach ($this->_datasource->_result as $key=>$value) {  
                         if      (array_key_exists($value['lkey'], $used_keys) && ($value['lcountrykey'] == $_REQUEST['_set_lang'])) {  
                                 $new_data[$key] = $value;  
                                 $new_data[$key]['lvalue'] = $used_keys[$value['lkey']];  
309                          }                          }
310                  }          }      
311    
312  // if there are completely new items without a guid, they are pushed to the new data-array in          foreach ($this->_set_items as $item_key => $item_value) {
313  // the correct form, as an array containing a lkey, a lcountrykey and, of course, a lvalue                  foreach($new_data as $data_key => $data_value) {
314                  if (array_count_values($new_data)<array_count_values($used_keys)) {                          if ($data_key == $item_value['lkey']) {
315                          foreach ($used_keys as $key=>$value) {                                  $tmp_array = $item_value;
316                                  $wanted_array = $this->get_nested_array_by_lkey($new_data, $key);                                  $tmp_array['lvalue'] = $data_value;
317                                  if (!is_array($wanted_array)) {                                  array_push($data, $tmp_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);  
                                 }  
318                          }                          }
319                  }                  }
320            }
321                    
322                    
323            //      print " data: " .Dumper($data). "<br>";
324                    
325            // 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)
326          $this->_options['data_locator_meta']['action'] = "write";          $this->_options['data_locator_meta']['action'] = "write";
327          $this->_options['data_locator_meta']['data'] = $new_data;          $this->_options['data_locator_meta']['data'] = $data;
328          // TODO: 'data_prefetch()' will never return ANYTHING!          // TODO: 'data_prefetch()' will never return ANYTHING!
329          //           Implement some error-handling there or somewhere.          //           Implement some error-handling there or somewhere.
330          $error = $this->data_prefetch();          $error = $this->data_prefetch();
331    }    }
332    function form_backend_validation() {    function form_backend_validation() {
333      $this->set_action("Confirm");      $this->set_action("Confirm");
334      return TRUE;      return TRUE;
335    }    }
336    function confirm_action() {    function confirm_action() {
337         $this->set_action_message("yip, alles klar!");
338      return TRUE;      return TRUE;
339    }    }
340  }  }

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

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