/[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.1 by udo, Sat Nov 22 18:36:38 2003 UTC revision 1.3 by udo, Mon Dec 15 21:03:19 2003 UTC
# Line 31  Line 31 
31    var $_sql_key;    var $_sql_key;
32    
33    function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {    function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {
34      
35      $this->_show_lang = $show_lang;      $this->_show_lang = $show_lang;
36      $this->_set_lang = $set_lang;      $this->_set_lang = $set_lang;
37      $this->_sql_key = $whichKey;      $this->_sql_key = $whichKey;
38      $this->_undone = $undone;      $this->_undone = $undone;
39      $parent = get_parent_class($this);      $parent = get_parent_class($this);
40    
41      $this->$parent($title, $options);      $this->$parent($title, $options);
42    }    }
43        
44    function form_init_elements() {    
   
 // hidden element for page control  
     $this->add_hidden_element( 't', 'News' );  
       
 // used_keys are all lkeys, that contain the _sql_key  
     $used_keys = array();  
       
 // the _datasource->result - object is parsed and the matching items are  
 // written into the arrays  
     foreach($this->_datasource->_result as $key => $value) {  
       if (strstr ( $value['lkey'], $this->_sql_key)) {  
         if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}  
         if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}  
         if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}  
       }  
     }  
   
45  // 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
46  // different amount of entries.  // different amount of entries. in that case we have ensure, that there will
47  // the follogwing is all about sorting the both arrays in a way, that the same  // be input-fields at the mising places and that the data will be recieved
48  // entries have the same key and filling up entries, if theres an entry missing because  // with the correct lkey
49  // its not yet translated.      function get_nested_array_by_lkey($whichArray, $whichKey) {
50      function get_nested_array_by_lkey($whichArray=array(), $whichKey) {          $myArray = array();
51        foreach ($whichArray as $key=>$value) {          $myArray = &$whichArray;
52          if ($value['lkey'] == $whichKey) {return $value;}        foreach ($myArray as $key=>$value) {
53            if ($value['lkey'] == $whichKey) {
54                    return $value;}
55        }        }
56      }      }
57    
58      
59      function form_init_elements() {
60    
61  // this is needed for sorting  // hidden element for page control
62      $tmp_array = array();      $this->add_hidden_element( 't', 'Translate' );
63  $larger = array();      $this->add_hidden_element( 'sub_lang', $_REQUEST['sub_lang'] );
64  // this is needed because the arrays may have to be filled with an array          $this->add_hidden_element( '_set_lang', $this->_set_lang );
65      $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );          $this->add_hidden_element( '_show_lang', $this->_show_lang );
66            $this->add_hidden_element( '_undone', $this->_undone );
67  // the smaller array is backuped in tmp_array and then killed.  
68  // the larger array is parsed an doing this we reset the smaller array form the          if (empty($this->_set_lang)) {  
69  // backup in the right order. if there is an entry missing in the smaller                  $this->_set_lang = $_REQUEST['_set_lang'];
70  // array this key will not be filled here.          }
71      if (count($this->_set_items) > count($this->_show_items)) {          if (empty($this->_show_lang)) {
72        $larger = $this->_set_items;                  $this->_show_lang = $_REQUEST['_show_lang'];
73        $tmp_array = $this->_show_items;          }
74        $this->_show_items = array();          if (empty($this->_undone)) {    
75        foreach ($this->_set_items as $key=>$value) {                  $this->_undone = $_REQUEST['_undone'];
76          $this->_show_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);          }
77        }          
78      } else if (count($this->_set_items) < count($this->_show_items)) {          
79        $larger = $this->_show_items;  // used_keys are all lkeys, that contain the _sql_key
80          $tmp_array = $this->_set_items;     $used_keys = array();
81          $this->_set_items = array();          
82          foreach ($this->_show_items as $key=>$value) {          $this->set_confirm();
83            $this->_set_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);  
84          }                // the _datasource->result - object is parsed and the matching items are
85      } else {          // written into the arrays
86        $larger = $this->_show_items;                  foreach($this->_datasource->_result as $key => $value) {
87        }                    if (strstr ( $value['lkey'], $this->_sql_key)) {
88                            if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}
89  // both arrays are parsed and missing entries (without a key) are filled                          if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
90  // with the empty_array. missing lkeys are filled with the lkey from used_keys,                          if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
91  // so that now every key of the arrays has matching entries. this is important,                    }
92  // because otherwise the empty fields could not be named.                  }
93    
94      foreach ($used_keys as $key => $value) {          
95          if (!is_array(get_nested_array_by_lkey($this->_set_items, $value))) {          // this is needed for sorting
96            $this->_set_items[$key] = $empty_array;                  $tmp_array = array();
97            $this->_set_items[$key]['lkey'] = $value;                  $larger = array();
98          }          // this is needed because the arrays may have to be filled with an array
99          if (!is_array(get_nested_array_by_lkey($this->_show_items, $value))) {                  $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
100            $this->_show_items[$key] = $empty_array;          
101            $this->_show_items[$key]['lkey'] = $value;          
102          }          // the smaller array is backuped in tmp_array and then killed.
103        }          // the larger array is parsed and doing this we reset the smaller array form the
104            // backup in the right order. if there is an entry missing in the smaller
105            // array this key will not be filled here.
106  // is _undone is selected, that means that the user only wants to see the items that          
107  // are not yet translated, every entry, that has lvalues in both arrays, is marked.                          if (array_count_values($this->_set_items) > array_count_values($this->_show_items)) {
108      if ($this->_undone == "yes") {                                  $larger = &$this->_set_items;
109        foreach ($used_keys as $key => $value) {                                        $tmp_array = $this->_show_items;
110          if ((strlen($this->_set_items[$key]['lvalue']) > 0) && (strlen($this->_show_items[$key]['lvalue']) > 0)) {                                  $this->_show_items = "killed";
111            $this->_set_items[$key] = "kickedMarkerXXX";                                  $whichLarger = "_set_items";
112            $this->_show_items[$key] = "kickedMarkerXXX";                          } else {
113          }                                  $larger = &$this->_show_items;
114        }                                  $tmp_array = $this->_set_items;
115      }                                  $this->_set_items = "killed";
116                                        $whichLarger="_show_items";                    
117                            }
118  // the elements of the form are created          
119      foreach($used_keys as $key => $value) {          $smaller = array();
120  // if the entry == kickedMarkerXXX, $value will be no array          foreach ($larger as $key=>$value) {
121        if (is_array($this->_set_items[$key])) {                  if (is_array($this->get_nested_array_by_lkey($tmp_array, $value['lkey']))) {
122          $show_element = $value . $this->_show_lang . "s";                          $smaller[$key] = $this->get_nested_array_by_lkey($tmp_array, $value['lkey']);
123          $set_element = $value . $this->_set_lang . "u";                  } else {
124                            $smaller[$key] = $empty_array;
125          if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {                          $smaller[$key]['lkey'] = $larger[$key]['lkey'];
126            $this->add_element( new FEText($show_element, true, 40, 60));                  }
127            $this->add_element( new FEText($set_element, true, 40, 60));          }
128          } else{          
129            $this->add_element( new FETextArea($show_element, true, 10, 40));          // is _undone is selected, that means that the user only wants to see the items that
130            $this->add_element( new FETextArea($set_element, true, 10, 40));          // are not yet translated, every entry, that has lvalues in both arrays, is marked.
131                    if ($this->_undone == "yes") {
132                      foreach ($used_keys as $key => $value) {      
133                            if ((strlen($larger[$key]['lvalue']) > 0) && (strlen($smaller[$key]['lvalue']) > 0)) {
134                              $this->_set_items[$key] = "kickedMarkerXXX";
135                              $this->_show_items[$key] = "kickedMarkerXXX";
136                            }
137                      }
138                    }
139            
140            if ($whichLarger=="_show_items") {
141                    $this->_show_items = $larger;
142                    $this->_set_items = $smaller;
143            } else {
144                    $this->_show_items = $smaller;
145                    $this->_set_items = $larger;
146            }
147    
148            
149            // the elements of the form are created
150            // the string-replacement is necessary because a slash (/) is turned into _
151            // in the html-code
152                    foreach($used_keys as $key => $value) {
153                      if ($this->_set_items[$key] != "kickedMarkerXXX") {
154                            $show_el = str_replace("/", "x_x", $value) . $this->_show_lang . "s";
155    
156                            $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";
157            
158                            if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {
159                              $this->add_element( new FEText($show_el, false, 40, 200));
160                              $this->add_element( new FEText($set_el, false, 40, 200));
161                            } else{
162                              $this->add_element( new FETextArea($show_el, false, 10, 40));
163                              $this->add_element( new FETextArea($set_el, false, 10, 40));
164                            }
165                      $my_el = &$this->get_element($show_el);
166                      $my_el->set_attribute("readonly");
167                      $my_el = &$this->get_element($set_el);
168                      }
169                    }
170              }
171    
172          }    
         $myElement = &$this->get_element($show_element);  
         $myElement->set_attribute("readonly");  
       }  
     }  
   }  
173    
174    function form_init_data() {    function form_init_data() {
175            
176        // the items that maybe are not to be shown because they are already translated
177    // should have been replaced with kickedMarkerXXX
178      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
179        if (is_array($value)) {        if ($value != "kickedMarkerXXX") {
180          $show_element = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
181          $set_element = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
182              
183          $this->set_element_value($show_element, $this->_show_items[$key]['lvalue']);                  if (!empty($this->_show_items[$key]['lvalue'])) {
184          $this->set_element_value($set_element, $this->_set_items[$key]['lvalue']);                  $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
185                    } else {
186                    $this->set_element_value($show_el, "&nbsp");            
187                    }
188                    if (!empty($this->_set_items[$key]['lvalue'])) {
189                    $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
190                    } else {
191                    $this->set_element_value($set_el, "&nbsp");
192                    }
193                    
194          $myElement = &$this->get_element($show_element);          $myElement = &$this->get_element($show_el);
195          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
196          $myElement->set_required(false);          $myElement->set_required(0);
197                    
198          $myElement = &$this->get_element($set_element);          $myElement = &$this->get_element($set_el);
199          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
200          $myElement->set_required(false);          $myElement->set_required(0);
201        }        }
202      }            }      
203    }    }
204    
205      /**
206         * This method allows the child to overide the
207         * default confirm data.  By default the form_confirm()
208         * will show ALL FormElements.  This is prolly not good
209         * in case of a form where a password exists.
210         *
211         * @param InfoTable object
212         */  
213        function build_confirm_table( &$table ) {
214    
215            $useless_keys = array ('0' => "ecdfe",
216                                                                                            '1' => "_form_action",
217                                                                                            '2' => "_form_visited",
218                                                                                            '3' => "_form_confirm",
219                                                                                            );
220    
221    // the actually updated data has to be parsed out of the post data.
222    // there is a lot data in the post that is useless for this, like for page-control usw.
223    // if the selected show- and set-language is the same, we will only confirm the set-items
224                    if ($_REQUEST['_set_lang'] <> $_REQUEST['_show_lang']) {
225                            foreach( $_POST as $label => $element) {
226                            
227    // the wanted data is not part of the hidden elements, not part of the useless page-control-post (useless_keys)
228    // and its key contains the selected set-language
229                                    if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  stristr(substr($label, strlen($label)-3, 2) , $_REQUEST['_set_lang']) ){
230                                            $correct_key = substr($label, 0, strlen($label) - 3);
231                                            $correct_key = str_replace("x_x", "/", $correct_key);
232                                            $table->add_row( $correct_key, $element);
233                                    }
234                            }
235                    } else {
236                            foreach( $_POST as $label => $element) {
237                                    if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  (substr($label, strlen($label)-1, 1) == "u") ){
238                                            $correct_key = substr($label, 0, strlen($label) - 3);
239                                            $correct_key = str_replace("x_x", "/", $correct_key);
240                                            $table->add_row( $correct_key, $element);
241                                    }
242                            }                      
243                    }
244        }
245      
246            function form_confirm( ) {
247            $title = "confirmation form / " . $this->_options['caption'];
248       //     $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
249            $table = new InfoTable($title, $this->_width);
250    
251            $this->build_confirm_table( $table );
252    
253            //now add the confirmation button
254            $td = new TDtag(array("colspan" => 2,
255                                  "class" => "contentnovertical",
256                                  "align" => "center"),
257                            form_submit('ecdfe', "Confirm"),
258                            //_HTML_SPACE,
259                                                    form_submit('ecdfc',"Edit"));
260    
261            $table->add_row( $td );
262    
263            return $table;
264            }
265    
266    function form_content() {    function form_content() {
267            
268      $table = &html_table(600, 0, 2);      $table = &html_table(600, 0, 2);
# Line 200  $larger = array(); Line 294  $larger = array();
294      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
295        if (is_array($value)) {        if (is_array($value)) {
296          $all_elements_translated++;          $all_elements_translated++;
297          $show_element = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
298          $set_element = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']) . $this->_set_lang . "u";
299                            
300                    $show_el_label = str_replace("x_x", "/", $value['lkey']);
301                    $set_el_label = str_replace("x_x", "/", $value['lkey']);
302                    
303          $inner_table_left = &html_table();          $inner_table_left = &html_table();
304          $inner_table_left->add_row($this->element_label($show_element));                  $inner_table_left->add_row($show_el_label);
305          $inner_table_left->add_row($this->element_form($show_element));                  
306            $inner_table_left->add_row($this->element_form($show_el));
307          $inner_table_right = &html_table();          $inner_table_right = &html_table();
308          $inner_table_right->add_row($this->element_label($set_element));                  $inner_table_right->add_row($set_el_label);
309          $inner_table_right->add_row($this->element_form($set_element));                  
310            $inner_table_right->add_row($this->element_form($set_el));
311    
312          $table->add_row($inner_table_left, $inner_table_right );          $table->add_row($inner_table_left, $inner_table_right );
313        }        }
314      }      }
315      if ($all_elements_translated == 0) {      if ($all_elements_translated == 0) {
316        $table = &html_table(600, 0, 2);        $table = &html_table(600, 0, 2);
317        if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}            $table->add_row("no items found");
318        else {$table->add_row("no items found");}     }
       }  
319      $this->add_form_block("", $table );      $this->add_form_block("", $table );
320    }    }
321    
322    
323    // for the final form action the post-variables have to be parsed again and merged together with the datasource-result
324    // in a way that keeps the guid from the datasource-result and replaces the old lvalues with the new ones.
325    function form_action() {    function form_action() {
     $data = array();  
       
     foreach ($this->_set_items as $key=>$value) {  
       if (is_array($value)) {  
         array_push($data, $this->_set_items[$key]);  
         }  
       }  
326    
327      //$this->_options['data_locator_meta']['action'] = "write";          $useless_keys = array ('0' => "ecdfe",
328      //$this->_options['data_locator_meta']['data'] = $data;                                                                                          '1' => "_form_action",
329      //$error = $this->data_prefetch();                                                                                          '2' => "_form_visited",
330                                                                                            '3' => "_form_confirm",
331                                                                                            );
332    
333            $new_data = array();
334            $used_keys = array();
335    
336    // the keys that will be needed for update are parsed from the post
337            foreach( $_POST as $label => $element) {
338                            if (!array_key_exists( $label, $this->get_hidden_elements()) && !in_array( $label, $useless_keys) &&  stristr(substr($label, strlen($label)-3, 2) , $_REQUEST['_set_lang']) ){
339                                    $correct_key = substr($label, 0, strlen($label) - 3);
340                                    $correct_key = str_replace("x_x", "/", $correct_key);
341                                    $used_keys[$correct_key] = $element;
342                            }
343            }
344    
345    // the guid of the updated elements is received out of the datasource-result and
346    // the old items are replaced by the new ones.
347                    foreach ($this->_datasource->_result as $key=>$value) {
348                            if      (array_key_exists($value['lkey'], $used_keys) && ($value['lcountrykey'] == $_REQUEST['_set_lang'])) {
349                                    $new_data[$key] = $value;
350                                    $new_data[$key]['lvalue'] = $used_keys[$value['lkey']];
351                            }
352                    }
353    
354    // if there are completely new items without a guid, they are pushed to the new data-array in
355    // the correct form, as an array containing a lkey, a lcountrykey and, of course, a lvalue
356                    if (array_count_values($new_data)<array_count_values($used_keys)) {
357                            foreach ($used_keys as $key=>$value) {
358                                    $wanted_array = $this->get_nested_array_by_lkey($new_data, $key);
359                                    if (!is_array($wanted_array)) {
360                                            $tmp_array = array();
361                                            $tmp_array['lcountrykey'] = $_REQUEST['_set_lang'];
362                                            $tmp_array['lvalue'] = $value;
363                                            $tmp_array['lkey'] = $key;
364                                            $tmp_array['GIUD'] = "";
365                                            array_push($new_data, $tmp_array);
366                                    }
367                            }
368                    }
369              // write new data to datasource in $data as array (keep old indices, set new values)
370            $this->_options['data_locator_meta']['action'] = "write";
371            $this->_options['data_locator_meta']['data'] = $new_data;
372            // TODO: 'data_prefetch()' will never return ANYTHING!
373            //           Implement some error-handling there or somewhere.
374            $error = $this->data_prefetch();
375    }    }
376    function form_backend_validation() {    function form_backend_validation() {
377      $this->set_action("Confirm");      $this->set_action("Confirm");
# Line 245  $larger = array(); Line 383  $larger = array();
383  }  }
384    
385    
  ?>  
386     ?>

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

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