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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (hide annotations)
Thu Mar 4 23:07:13 2004 UTC (20 years, 5 months ago) by udo
Branch: MAIN
Changes since 1.3: +32 -77 lines
changed getting new element values from this->elements

1 udo 1.1 <?
2     /**
3     * This file contains the EditPageForm child class.
4     *
5     *
6     * @package org.netfrag.patches
7     * @name EditPageForm
8     *
9     */
10    
11     /**
12     * Cvs-Log
13     *
14 udo 1.4 * $Id: EditPageForm.php,v 1.3 2003/12/15 21:03:19 udo Exp $
15 udo 1.1 */
16     // this is an abstract form-class to edit LangText - content.
17     class EditPageForm extends EditDataItem {
18    
19     // _show_lang is the language to be shown readonly
20     var $_show_lang;
21     // _set_lang is the language to be entered and updated in the Langtext-table
22     var $_set_lang;
23     // _show_items are the items that will be shown
24     var $_show_items = array();
25     // _set_items are the items, that will maybe be changed an updated
26     var $_set_items = array();
27     // undone is true, if the user selected to show untranslated items only
28     var $_undone;
29     // all LangText - entries that contain the string _sql_key will be selected.
30     // this is passed dependent on which topic is selected in the page_news - class
31     var $_sql_key;
32    
33     function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {
34 udo 1.3
35 udo 1.1 $this->_show_lang = $show_lang;
36     $this->_set_lang = $set_lang;
37     $this->_sql_key = $whichKey;
38     $this->_undone = $undone;
39     $parent = get_parent_class($this);
40 udo 1.3
41 udo 1.4
42     //$this->$parent($title, $_SERVER['PHP_SELF'], $options);
43 udo 1.1 $this->$parent($title, $options);
44     }
45 udo 1.4
46 udo 1.1 // this function is needed, because _set_items and _show_items may contain a
47 udo 1.3 // 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
49     // with the correct lkey
50 udo 1.4 function get_nested_array_by_lkey($whichArray, $whichKey) {
51 udo 1.3 $myArray = array();
52     $myArray = &$whichArray;
53     foreach ($myArray as $key=>$value) {
54 udo 1.4 if ($value['lkey'] == $whichKey) {return $value;}
55 udo 1.1 }
56     }
57    
58 udo 1.3
59     function form_init_elements() {
60 udo 1.1
61 udo 1.3 // hidden element for page control
62     $this->add_hidden_element( 't', 'Translate' );
63     $this->add_hidden_element( 'sub_lang', $_REQUEST['sub_lang'] );
64     $this->add_hidden_element( '_set_lang', $this->_set_lang );
65     $this->add_hidden_element( '_show_lang', $this->_show_lang );
66     $this->add_hidden_element( '_undone', $this->_undone );
67    
68     if (empty($this->_set_lang)) {
69     $this->_set_lang = $_REQUEST['_set_lang'];
70     }
71     if (empty($this->_show_lang)) {
72     $this->_show_lang = $_REQUEST['_show_lang'];
73     }
74     if (empty($this->_undone)) {
75     $this->_undone = $_REQUEST['_undone'];
76     }
77 udo 1.4
78 udo 1.3 // used_keys are all lkeys, that contain the _sql_key
79     $used_keys = array();
80 udo 1.4
81 udo 1.3 $this->set_confirm();
82 udo 1.1
83 udo 1.3 // the _datasource->result - object is parsed and the matching items are
84     // written into the arrays
85     foreach($this->_datasource->_result as $key => $value) {
86     if (strstr ( $value['lkey'], $this->_sql_key)) {
87     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);}
89     if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
90     }
91     }
92 udo 1.1
93 udo 1.3
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 udo 1.1
147 udo 1.3
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 udo 1.1
155 udo 1.3 $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 udo 1.2 }
170    
171 udo 1.3
172 udo 1.1
173     function form_init_data() {
174 udo 1.2
175 udo 1.3 // the items that maybe are not to be shown because they are already translated
176     // should have been replaced with kickedMarkerXXX
177 udo 1.1 foreach($this->_show_items as $key => $value) {
178 udo 1.3 if ($value != "kickedMarkerXXX") {
179     $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
180     $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
181    
182 udo 1.2 if (!empty($this->_show_items[$key]['lvalue'])) {
183     $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
184     } else {
185 udo 1.3 $this->set_element_value($show_el, "&nbsp");
186 udo 1.2 }
187     if (!empty($this->_set_items[$key]['lvalue'])) {
188     $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
189     } else {
190 udo 1.3 $this->set_element_value($set_el, "&nbsp");
191 udo 1.2 }
192 udo 1.1
193 udo 1.3 $myElement = &$this->get_element($show_el);
194     $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
195     $myElement->set_required(0);
196 udo 1.1
197 udo 1.2 $myElement = &$this->get_element($set_el);
198 udo 1.3 $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
199     $myElement->set_required(0);
200 udo 1.1 }
201     }
202     }
203    
204 udo 1.3 /**
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 udo 1.4 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 udo 1.3 }
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 udo 1.1 function form_content() {
242    
243     $table = &html_table(600, 0, 2);
244     switch ($this->_show_lang) {
245     case 'de':
246     $showLanguange = " german";
247     break;
248     case 'en':
249     $showLanguange = " english";
250     break;
251     case 'tr':
252     $showLanguange = " turkish";
253     break;
254     }
255     switch ($this->_set_lang) {
256     case 'de':
257     $setLanguange = " german";
258     break;
259     case 'en':
260     $setLanguange = " english";
261     break;
262     case 'tr':
263     $setLanguange = " turkish";
264     break;
265     }
266     $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );
267     $all_elements_translated = 0;
268    
269     foreach($this->_show_items as $key => $value) {
270     if (is_array($value)) {
271     $all_elements_translated++;
272 udo 1.3 $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
273     $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 udo 1.1 $inner_table_left = &html_table();
279 udo 1.3 $inner_table_left->add_row($show_el_label);
280    
281 udo 1.2 $inner_table_left->add_row($this->element_form($show_el));
282 udo 1.1 $inner_table_right = &html_table();
283 udo 1.3 $inner_table_right->add_row($set_el_label);
284    
285 udo 1.2 $inner_table_right->add_row($this->element_form($set_el));
286 udo 1.1
287     $table->add_row($inner_table_left, $inner_table_right );
288     }
289     }
290     if ($all_elements_translated == 0) {
291     $table = &html_table(600, 0, 2);
292 udo 1.3 $table->add_row("no items found");
293     }
294 udo 1.1 $this->add_form_block("", $table );
295     }
296    
297 udo 1.3
298 udo 1.1 function form_action() {
299 udo 1.3
300 udo 1.4 $data = array();
301 udo 1.3 $new_data = array();
302 udo 1.4 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 udo 1.3 $correct_key = substr($label, 0, strlen($label) - 3);
305     $correct_key = str_replace("x_x", "/", $correct_key);
306 udo 1.4 $new_data[$correct_key]=$element->get_value();
307 udo 1.3 }
308 udo 1.4 }
309 udo 1.1
310 udo 1.4 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 udo 1.3 }
317     }
318 udo 1.4 }
319    
320    
321     // print " data: " .Dumper($data). "<br>";
322    
323 udo 1.3 // write new data to datasource in $data as array (keep old indices, set new values)
324     $this->_options['data_locator_meta']['action'] = "write";
325 udo 1.4 $this->_options['data_locator_meta']['data'] = $data;
326 udo 1.3 // TODO: 'data_prefetch()' will never return ANYTHING!
327     // Implement some error-handling there or somewhere.
328 udo 1.4 $error = $this->data_prefetch();
329 udo 1.1 }
330     function form_backend_validation() {
331     $this->set_action("Confirm");
332     return TRUE;
333     }
334     function confirm_action() {
335 udo 1.4 $this->set_action_message("yip, alles klar!");
336 udo 1.1 return TRUE;
337     }
338     }
339    
340    
341 udo 1.2 ?>

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