/[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.4 by udo, Thu Mar 4 23:07:13 2004 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    
42        //$this->$parent($title, $_SERVER['PHP_SELF'], $options);
43      $this->$parent($title, $options);      $this->$parent($title, $options);
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    
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.  // different amount of entries. in that case we have ensure, that there will
48  // 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
49  // entries have the same key and filling up entries, if theres an entry missing because  // with the correct lkey
50  // its not yet translated.    function get_nested_array_by_lkey($whichArray, $whichKey) {
51      function get_nested_array_by_lkey($whichArray=array(), $whichKey) {          $myArray = array();
52        foreach ($whichArray as $key=>$value) {          $myArray = &$whichArray;
53          foreach ($myArray as $key=>$value) {
54          if ($value['lkey'] == $whichKey) {return $value;}          if ($value['lkey'] == $whichKey) {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']);          }
       }  
     } 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;  
       }  
77    
78  // both arrays are parsed and missing entries (without a key) are filled  // used_keys are all lkeys, that contain the _sql_key
79  // 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;  
         }  
       }  
80    
81            $this->set_confirm();
82    
83  // 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
84  // are not yet translated, every entry, that has lvalues in both arrays, is marked.          // written into the arrays
85      if ($this->_undone == "yes") {                  foreach($this->_datasource->_result as $key => $value) {
86        foreach ($used_keys as $key => $value) {                          if (strstr ( $value['lkey'], $this->_sql_key)) {
87          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']);}
88            $this->_set_items[$key] = "kickedMarkerXXX";                          if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
89            $this->_show_items[$key] = "kickedMarkerXXX";                          if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
90          }                    }
91        }                  }
92      }  
93                
94            // this is needed for sorting
95                    $tmp_array = array();
96                    $larger = array();
97            // this is needed because the arrays may have to be filled with an array
98                    $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
99            
100            
101            // the smaller array is backuped in tmp_array and then killed.
102            // the larger array is parsed and doing this we reset the smaller array form the
103            // backup in the right order. if there is an entry missing in the smaller
104            // array this key will not be filled here.
105            
106                            if (array_count_values($this->_set_items) > array_count_values($this->_show_items)) {
107                                    $larger = &$this->_set_items;
108                                    $tmp_array = $this->_show_items;
109                                    $this->_show_items = "killed";
110                                    $whichLarger = "_set_items";
111                            } else {
112                                    $larger = &$this->_show_items;
113                                    $tmp_array = $this->_set_items;
114                                    $this->_set_items = "killed";
115                                    $whichLarger="_show_items";                    
116                            }
117            
118            $smaller = array();
119            foreach ($larger as $key=>$value) {
120                    if (is_array($this->get_nested_array_by_lkey($tmp_array, $value['lkey']))) {
121                            $smaller[$key] = $this->get_nested_array_by_lkey($tmp_array, $value['lkey']);
122                    } else {
123                            $smaller[$key] = $empty_array;
124                            $smaller[$key]['lkey'] = $larger[$key]['lkey'];
125                    }
126            }
127            
128            // is _undone is selected, that means that the user only wants to see the items that
129            // are not yet translated, every entry, that has lvalues in both arrays, is marked.
130                    if ($this->_undone == "yes") {
131                      foreach ($used_keys as $key => $value) {      
132                            if ((strlen($larger[$key]['lvalue']) > 0) && (strlen($smaller[$key]['lvalue']) > 0)) {
133                              $this->_set_items[$key] = "kickedMarkerXXX";
134                              $this->_show_items[$key] = "kickedMarkerXXX";
135                            }
136                      }
137                    }
138            
139            if ($whichLarger=="_show_items") {
140                    $this->_show_items = $larger;
141                    $this->_set_items = $smaller;
142            } else {
143                    $this->_show_items = $smaller;
144                    $this->_set_items = $larger;
145            }
146    
147            
148            // the elements of the form are created
149            // the string-replacement is necessary because a slash (/) is turned into _
150            // in the html-code
151                    foreach($used_keys as $key => $value) {
152                      if ($this->_set_items[$key] != "kickedMarkerXXX") {
153                            $show_el = str_replace("/", "x_x", $value) . $this->_show_lang . "s";
154    
155                            $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";
156            
157                            if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {
158                              $this->add_element( new FEText($show_el, false, 40, 200));
159                              $this->add_element( new FEText($set_el, false, 40, 200));
160                            } else{
161                              $this->add_element( new FETextArea($show_el, false, 10, 40));
162                              $this->add_element( new FETextArea($set_el, false, 10, 40));
163                            }
164                      $my_el = &$this->get_element($show_el);
165                      $my_el->set_attribute("readonly");
166                      $my_el = &$this->get_element($set_el);
167                      }
168                    }
169              }
170    
171  // the elements of the form are created    
     foreach($used_keys as $key => $value) {  
 // if the entry == kickedMarkerXXX, $value will be no array  
       if (is_array($this->_set_items[$key])) {  
         $show_element = $value . $this->_show_lang . "s";  
         $set_element = $value . $this->_set_lang . "u";  
   
         if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) {  
           $this->add_element( new FEText($show_element, true, 40, 60));  
           $this->add_element( new FEText($set_element, true, 40, 60));  
         } else{  
           $this->add_element( new FETextArea($show_element, true, 10, 40));  
           $this->add_element( new FETextArea($set_element, true, 10, 40));  
   
         }  
         $myElement = &$this->get_element($show_element);  
         $myElement->set_attribute("readonly");  
       }  
     }  
   }  
172    
173    function form_init_data() {    function form_init_data() {
174            
175        // the items that maybe are not to be shown because they are already translated
176    // should have been replaced with kickedMarkerXXX
177      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
178        if (is_array($value)) {        if ($value != "kickedMarkerXXX") {
179          $show_element = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
180          $set_element = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
181              
182          $this->set_element_value($show_element, $this->_show_items[$key]['lvalue']);                  if (!empty($this->_show_items[$key]['lvalue'])) {
183          $this->set_element_value($set_element, $this->_set_items[$key]['lvalue']);                  $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
184                    } else {
185                    $this->set_element_value($show_el, "&nbsp");            
186                    }
187                    if (!empty($this->_set_items[$key]['lvalue'])) {
188                    $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
189                    } else {
190                    $this->set_element_value($set_el, "&nbsp");
191                    }
192                    
193          $myElement = &$this->get_element($show_element);          $myElement = &$this->get_element($show_el);
194          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
195          $myElement->set_required(false);          $myElement->set_required(0);
196                    
197          $myElement = &$this->get_element($set_element);          $myElement = &$this->get_element($set_el);
198          $myElement->set_label_text($value['lkey']);          $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
199          $myElement->set_required(false);          $myElement->set_required(0);
200        }        }
201      }            }      
202    }    }
203    
204      /**
205         * This method allows the child to overide the
206         * default confirm data.  By default the form_confirm()
207         * will show ALL FormElements.  This is prolly not good
208         * in case of a form where a password exists.
209         *
210         * @param InfoTable object
211         */  
212        function build_confirm_table( &$table ) {
213                    foreach( $this->_elements as $label => $element) {
214                            if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
215                                    $correct_key = substr($label, 0, strlen($label) - 3);
216                                    $correct_key = str_replace("x_x", "/", $correct_key);
217                                    $table->add_row( $correct_key, $element->get_value());
218                            }
219                    }
220        }
221      
222            function form_confirm( ) {
223            $title = "confirmation form / " . $this->_options['caption'];
224       //     $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
225            $table = new InfoTable($title, $this->_width);
226    
227            $this->build_confirm_table( $table );
228    
229            //now add the confirmation button
230            $td = new TDtag(array("colspan" => 2,
231                                  "class" => "contentnovertical",
232                                  "align" => "center"),
233                            form_submit('ecdfe', "Confirm"),
234                            //_HTML_SPACE,
235                                                    form_submit('ecdfc',"Edit"));
236    
237            $table->add_row( $td );
238            return $table;
239            }
240    
241    function form_content() {    function form_content() {
242            
243      $table = &html_table(600, 0, 2);      $table = &html_table(600, 0, 2);
# Line 200  $larger = array(); Line 269  $larger = array();
269      foreach($this->_show_items as $key => $value) {      foreach($this->_show_items as $key => $value) {
270        if (is_array($value)) {        if (is_array($value)) {
271          $all_elements_translated++;          $all_elements_translated++;
272          $show_element = $value['lkey'] . $this->_show_lang . "s";          $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
273          $set_element = $value['lkey'] . $this->_set_lang . "u";          $set_el = str_replace("/", "x_x", $value['lkey']) . $this->_set_lang . "u";
274                            
275                    $show_el_label = str_replace("x_x", "/", $value['lkey']);
276                    $set_el_label = str_replace("x_x", "/", $value['lkey']);
277                    
278          $inner_table_left = &html_table();          $inner_table_left = &html_table();
279          $inner_table_left->add_row($this->element_label($show_element));                  $inner_table_left->add_row($show_el_label);
280          $inner_table_left->add_row($this->element_form($show_element));                  
281            $inner_table_left->add_row($this->element_form($show_el));
282          $inner_table_right = &html_table();          $inner_table_right = &html_table();
283          $inner_table_right->add_row($this->element_label($set_element));                  $inner_table_right->add_row($set_el_label);
284          $inner_table_right->add_row($this->element_form($set_element));                  
285            $inner_table_right->add_row($this->element_form($set_el));
286    
287          $table->add_row($inner_table_left, $inner_table_right );          $table->add_row($inner_table_left, $inner_table_right );
288        }        }
289      }      }
290      if ($all_elements_translated == 0) {      if ($all_elements_translated == 0) {
291        $table = &html_table(600, 0, 2);        $table = &html_table(600, 0, 2);
292        if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}            $table->add_row("no items found");
293        else {$table->add_row("no items found");}     }
       }  
294      $this->add_form_block("", $table );      $this->add_form_block("", $table );
295    }    }
296    
   function form_action() {  
     $data = array();  
       
     foreach ($this->_set_items as $key=>$value) {  
       if (is_array($value)) {  
         array_push($data, $this->_set_items[$key]);  
         }  
       }  
297    
298      //$this->_options['data_locator_meta']['action'] = "write";    function form_action() {
     //$this->_options['data_locator_meta']['data'] = $data;  
     //$error = $this->data_prefetch();  
299    
300            $data = array();        
301            $new_data = array();
302            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()){
304                                    $correct_key = substr($label, 0, strlen($label) - 3);
305                                    $correct_key = str_replace("x_x", "/", $correct_key);
306                                    $new_data[$correct_key]=$element->get_value();
307                            }
308            }      
309    
310            foreach ($this->_set_items as $item_key => $item_value) {
311                    foreach($new_data as $data_key => $data_value) {
312                            if ($data_key == $item_value['lkey']) {
313                                    $tmp_array = $item_value;
314                                    $tmp_array['lvalue'] = $data_value;
315                                    array_push($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)
324            $this->_options['data_locator_meta']['action'] = "write";
325            $this->_options['data_locator_meta']['data'] = $data;
326            // TODO: 'data_prefetch()' will never return ANYTHING!
327            //           Implement some error-handling there or somewhere.
328            $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  }  }
339    
340    
  ?>  
341     ?>

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

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