/[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.2 by udo, Mon Dec 1 23:34:35 2003 UTC revision 1.6 by jonen, Tue Dec 14 21:10:10 2004 UTC
# Line 12  Line 12 
12   * Cvs-Log   * Cvs-Log
13   *   *
14   * $Id$   * $Id$
15     *
16     * $Log$
17     * Revision 1.6  2004/12/14 21:10:10  jonen
18     * + inserted Log-Tag
19     *
20     *
21     *
22   */   */
23    
24    
25   // this is an abstract form-class to edit LangText - content.   // this is an abstract form-class to edit LangText - content.
26   class EditPageForm extends EditDataItem {   class EditPageForm extends EditDataItem {
27    
# Line 31  Line 40 
40    var $_sql_key;    var $_sql_key;
41    
42    function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {    function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {
43      
44      $this->_show_lang = $show_lang;      $this->_show_lang = $show_lang;
45      $this->_set_lang = $set_lang;      $this->_set_lang = $set_lang;
46      $this->_sql_key = $whichKey;      $this->_sql_key = $whichKey;
47      $this->_undone = $undone;      $this->_undone = $undone;
48      $parent = get_parent_class($this);      $parent = get_parent_class($this);
49    
50    
51        //$this->$parent($title, $_SERVER['PHP_SELF'], $options);
52      $this->$parent($title, $options);      $this->$parent($title, $options);
53    }    }
     
   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);}  
       }  
     }  
54    
55  // 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
56  // different amount of entries.  // different amount of entries. in that case we have ensure, that there will
57  // 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
58  // entries have the same key and filling up entries, if theres an entry missing because  // with the correct lkey
59  // its not yet translated.    function get_nested_array_by_lkey($whichArray, $whichKey) {
60      function get_nested_array_by_lkey($whichArray=array(), $whichKey) {          $myArray = array();
61        foreach ($whichArray as $key=>$value) {          $myArray = &$whichArray;
62          foreach ($myArray as $key=>$value) {
63          if ($value['lkey'] == $whichKey) {return $value;}          if ($value['lkey'] == $whichKey) {return $value;}
64        }        }
65      }      }
66    
67      
68      function form_init_elements() {
69    
70  // this is needed for sorting  // hidden element for page control
71      $tmp_array = array();      $this->add_hidden_element( 't', 'Translate' );
72  $larger = array();      $this->add_hidden_element( 'sub_lang', $_REQUEST['sub_lang'] );
73  // this is needed because the arrays may have to be filled with an array          $this->add_hidden_element( '_set_lang', $this->_set_lang );
74      $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );          $this->add_hidden_element( '_show_lang', $this->_show_lang );
75            $this->add_hidden_element( '_undone', $this->_undone );
76  // the smaller array is backuped in tmp_array and then killed.  
77  // the larger array is parsed an doing this we reset the smaller array form the          if (empty($this->_set_lang)) {  
78  // backup in the right order. if there is an entry missing in the smaller                  $this->_set_lang = $_REQUEST['_set_lang'];
79  // array this key will not be filled here.          }
80      if (count($this->_set_items) > count($this->_show_items)) {          if (empty($this->_show_lang)) {
81        $larger = $this->_set_items;                  $this->_show_lang = $_REQUEST['_show_lang'];
82        $tmp_array = $this->_show_items;          }
83        $this->_show_items = array();          if (empty($this->_undone)) {    
84        foreach ($this->_set_items as $key=>$value) {                  $this->_undone = $_REQUEST['_undone'];
85          $this->_show_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);          }
       }  
     } else if (count($this->_set_items) < count($this->_show_items)) {  
       $larger = $this->_show_items;  
         $tmp_array = $this->_set_items;  
         $this->_set_items = array();  
         foreach ($this->_show_items as $key=>$value) {  
           $this->_set_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']);  
         }        
     } else {  
       $larger = $this->_show_items;  
       }  
86    
87  // both arrays are parsed and missing entries (without a key) are filled  // used_keys are all lkeys, that contain the _sql_key
88  // with the empty_array. missing lkeys are filled with the lkey from used_keys,     $used_keys = array();
 // so that now every key of the arrays has matching entries. this is important,  
 // because otherwise the empty fields could not be named.  
   
     foreach ($used_keys as $key => $value) {  
         if (!is_array(get_nested_array_by_lkey($this->_set_items, $value))) {  
           $this->_set_items[$key] = $empty_array;  
           $this->_set_items[$key]['lkey'] = $value;  
         }  
         if (!is_array(get_nested_array_by_lkey($this->_show_items, $value))) {  
           $this->_show_items[$key] = $empty_array;  
           $this->_show_items[$key]['lkey'] = $value;  
         }  
       }  
89    
90            $this->set_confirm();
91    
92  // is _undone is selected, that means that the user only wants to see the items that          // the _datasource->result - object is parsed and the matching items are
93  // are not yet translated, every entry, that has lvalues in both arrays, is marked.          // written into the arrays
94      if ($this->_undone == "yes") {                  foreach($this->_datasource->_result as $key => $value) {
95        foreach ($used_keys as $key => $value) {                          if (strstr ( $value['lkey'], $this->_sql_key)) {
96          if ((strlen($this->_set_items[$key]['lvalue']) > 0) && (strlen($this->_show_items[$key]['lvalue']) > 0)) {                          if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);}
97            $this->_set_items[$key] = "kickedMarkerXXX";                          //if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
98            $this->_show_items[$key] = "kickedMarkerXXX";                          if ($value['lcountrykey'] == $this->_show_lang) {$this->_show_items[$value['lkey']] = $value;}
99          }                          //if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
100        }                          if ($value['lcountrykey'] == $this->_set_lang) {$this->_set_items[$value['lkey']] = $value;}
101      }                    }
102                        }
103                    
104            
105            // this is needed for sorting
106                    $tmp_array = array();
107                    $larger = array();
108            // this is needed because the arrays may have to be filled with an array
109                    $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
110            
111            
112            // the smaller array is backuped in tmp_array and then killed.
113            // the larger array is parsed and doing this we reset the smaller array form the
114            // backup in the right order. if there is an entry missing in the smaller
115            // array this key will not be filled here.
116            
117                            if (array_count_values($this->_set_items) > array_count_values($this->_show_items)) {
118                                    $larger = &$this->_set_items;
119                                    $tmp_array = $this->_show_items;
120                                    $this->_show_items = "killed";
121                                    $whichLarger = "_set_items";
122                            } else {
123                                    $larger = &$this->_show_items;
124                                    $tmp_array = $this->_set_items;
125                                    $this->_set_items = "killed";
126                                    $whichLarger="_show_items";                    
127                            }
128            
129            $smaller = array();
130            foreach ($larger as $key=>$value) {
131                    if (is_array($this->get_nested_array_by_lkey($tmp_array, $value['lkey']))) {
132                            $smaller[$key] = $this->get_nested_array_by_lkey($tmp_array, $value['lkey']);
133                    } else {
134                            $smaller[$key] = $empty_array;
135                            $smaller[$key]['lkey'] = $larger[$key]['lkey'];
136                    }
137            }
138            
139            // is _undone is selected, that means that the user only wants to see the items that
140            // are not yet translated, every entry, that has lvalues in both arrays, is marked.
141                    if ($this->_undone == "yes") {
142                      foreach ($used_keys as $key => $value) {      
143                            if ((strlen($larger[$value]['lvalue']) > 0) && (strlen($smaller[$value]['lvalue']) > 0)) {
144                              $this->_set_items[$value] = "kickedMarkerXXX";
145                              $this->_show_items[$value] = "kickedMarkerXXX";
146                            }
147                      }
148                    }
149            
150            if ($whichLarger=="_show_items") {
151                    $this->_show_items = $larger;
152                    $this->_set_items = $smaller;
153            } else {
154                    $this->_show_items = $smaller;
155                    $this->_set_items = $larger;
156            }
157    
158  // the elements of the form are created          
159      foreach($used_keys as $key => $value) {          // the elements of the form are created
160  // if the entry == kickedMarkerXXX, $value will be no array          // the string-replacement is necessary because a slash (/) is turned into _
161        if ($this->_set_items[$key] != "kickedMarkerXXX") {          // in the html-code
162          $show_el = $value . $this->_show_lang . "s";                  foreach($used_keys as $key => $value) {
163          $set_el = $value . $this->_set_lang . "u";                    if ($this->_set_items[$key] != "kickedMarkerXXX") {
164                                            $show_el = str_replace("/", "x_x", $value) . $this->_show_lang . "s";
165                  print "array_show_el: " .$show_el. "<br>";  
166                  print "array_set_el: " .$set_el. "<br>";                          $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";
167            
168          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)) {
169            $this->add_element( new FEText($show_el, true, 40, 60));                            $this->add_element( new FEText($show_el, false, 40));
170            $this->add_element( new FEText($set_el, true, 40, 60));                            $this->add_element( new FEText($set_el, false, 40));
171          } else{                          } else{
172            $this->add_element( new FETextArea($show_el, true, 10, 40));                            $this->add_element( new FETextArea($show_el, false, 10, 40));
173            $this->add_element( new FETextArea($set_el, true, 10, 40));                            $this->add_element( new FETextArea($set_el, false, 10, 40));
174                            }
175          }                    $my_el = &$this->get_element($show_el);
176  //        $myElement = &$this->get_element($show_el);                    $my_el->set_attribute("readonly");
177  //        $myElement->set_attribute("readonly");                    $my_el = &$this->get_element($set_el);
178        } else {                    }
179                          print "no_show_el: " .$key. "<br>";                  }
                         print "no_set_el: " .$key. "<br>";  
180            }            }
     }  
181    
182    }    
183    
184    function form_init_data() {    function form_init_data() {
185                    
186    // the items that maybe are not to be shown because they are already translated
187    // should have been replaced with kickedMarkerXXX
188      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
189        if (is_array($value)) {        if ($value != "kickedMarkerXXX") {
190          $show_el = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
191          $set_el = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
192                            
193                  if (!empty($this->_show_items[$key]['lvalue'])) {                  if (!empty($this->_show_items[$key]['lvalue'])) {
                 //print "show_item: " .$key. "<br>";  
194                  $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);                  $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
195                  } else {                  } else {
196                  //print "empty_show_item: " .$key. "<br>";                  $this->set_element_value($show_el, "&nbsp");            
                 $this->set_element_value($show_el, "xxx");                
197                  }                  }
198                  if (!empty($this->_set_items[$key]['lvalue'])) {                  if (!empty($this->_set_items[$key]['lvalue'])) {
                 //print "set_item: " . $key . "<br>";  
199                  $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);                  $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
200                  } else {                  } else {
201                  //print "empty_set_item: " .$key. "<br>";                  $this->set_element_value($set_el, "&nbsp");
                 $this->set_element_value($set_el, "xxx");  
202                  }                  }
203                    
204      /*    $myElement = &$this->get_element($show_el);          $myElement = &$this->get_element($show_el);
205          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
206          $myElement->set_required(false);          $myElement->set_required(0);
207                    
208          $myElement = &$this->get_element($set_el);          $myElement = &$this->get_element($set_el);
209          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
210          $myElement->set_required(false);*/          $myElement->set_required(0);
211        }        }
212      }            }      
213    }    }
214    
215      /**
216         * This method allows the child to overide the
217         * default confirm data.  By default the form_confirm()
218         * will show ALL FormElements.  This is prolly not good
219         * in case of a form where a password exists.
220         *
221         * @param InfoTable object
222         */  
223        function build_confirm_table( &$table ) {
224                    foreach( $this->_elements as $label => $element) {
225                            if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
226                                    $correct_key = substr($label, 0, strlen($label) - 3);
227                                    $correct_key = str_replace("x_x", "/", $correct_key);
228                                    $table->add_row( $correct_key, $element->get_value());
229                            }
230                    }
231        }
232      
233            function form_confirm( ) {
234            $title = "confirmation form / " . $this->_options['caption'];
235       //     $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
236            $table = new InfoTable($title, $this->_width);
237    
238            $this->build_confirm_table( $table );
239    
240            //now add the confirmation button
241            $td = new TDtag(array("colspan" => 2,
242                                  "class" => "contentnovertical",
243                                  "align" => "center"),
244                            form_submit('ecdfe', "Confirm"),
245                            //_HTML_SPACE,
246                                                    form_submit('ecdfc',"Edit"));
247    
248            $table->add_row( $td );
249            return $table;
250            }
251    
252    function form_content() {    function form_content() {
253            
254      $table = &html_table(600, 0, 2);      $table = &html_table(600, 0, 2);
# Line 218  $larger = array(); Line 280  $larger = array();
280      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
281        if (is_array($value)) {        if (is_array($value)) {
282          $all_elements_translated++;          $all_elements_translated++;
283          $show_el = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
284          $set_el = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']) . $this->_set_lang . "u";
285                            
286                    $show_el_label = str_replace("x_x", "/", $value['lkey']);
287                    $set_el_label = str_replace("x_x", "/", $value['lkey']);
288                    
289          $inner_table_left = &html_table();          $inner_table_left = &html_table();
290   //       $inner_table_left->add_row($this->element_label($show_el));                  $inner_table_left->add_row($show_el_label);
291                    
292          $inner_table_left->add_row($this->element_form($show_el));          $inner_table_left->add_row($this->element_form($show_el));
293          $inner_table_right = &html_table();          $inner_table_right = &html_table();
294   //       $inner_table_right->add_row($this->element_label($set_el));                  $inner_table_right->add_row($set_el_label);
295                    
296          $inner_table_right->add_row($this->element_form($set_el));          $inner_table_right->add_row($this->element_form($set_el));
297    
298          $table->add_row($inner_table_left, $inner_table_right );          $table->add_row($inner_table_left, $inner_table_right );
# Line 233  $larger = array(); Line 300  $larger = array();
300      }      }
301      if ($all_elements_translated == 0) {      if ($all_elements_translated == 0) {
302        $table = &html_table(600, 0, 2);        $table = &html_table(600, 0, 2);
303        if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}            $table->add_row("no items found");
304        else {$table->add_row("no items found");}     }
       }  
305      $this->add_form_block("", $table );      $this->add_form_block("", $table );
306    }    }
307    
   function form_action() {  
     $data = array();  
       
     foreach ($this->_set_items as $key=>$value) {  
       if (is_array($value)) {  
         array_push($data, $this->_set_items[$key]);  
         }  
       }  
308    
309      //$this->_options['data_locator_meta']['action'] = "write";    function form_action() {
     //$this->_options['data_locator_meta']['data'] = $data;  
     //$error = $this->data_prefetch();  
310    
311            $data = array();        
312            $new_data = array();
313            foreach( $this->_elements as $label => $element) {                      
314                    if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
315                                    $correct_key = substr($label, 0, strlen($label) - 3);
316                                    $correct_key = str_replace("x_x", "/", $correct_key);
317                                    $new_data[$correct_key]=$element->get_value();
318                            }
319            }      
320    
321            foreach ($this->_set_items as $item_key => $item_value) {
322                    foreach($new_data as $data_key => $data_value) {
323                            if ($data_key == $item_value['lkey']) {
324                                    $tmp_array = $item_value;
325                                    $tmp_array['lvalue'] = $data_value;
326                                    array_push($data, $tmp_array);
327                            }
328                    }
329            }
330                    
331                    
332            //      print " data: " .Dumper($data). "<br>";
333                    
334              // write new data to datasource in $data as array (keep old indices, set new values)
335            $this->_options['data_locator_meta']['action'] = "write";
336            $this->_options['data_locator_meta']['data'] = $data;
337            // TODO: 'data_prefetch()' will never return ANYTHING!
338            //           Implement some error-handling there or somewhere.
339            $error = $this->data_prefetch();
340    }    }
341    function form_backend_validation() {    function form_backend_validation() {
342      $this->set_action("Confirm");      $this->set_action("Confirm");
343      return TRUE;      return TRUE;
344    }    }
345    function confirm_action() {    function confirm_action() {
346         $this->set_action_message("yip, alles klar!");
347      return TRUE;      return TRUE;
348    }    }
349  }  }

Legend:
Removed from v.1.2  
changed lines
  Added in v.1.6

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