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

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

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.5 - (show annotations)
Tue Dec 14 21:07:13 2004 UTC (19 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.4: +13 -11 lines
+ BIG bugfix: remember, don't trust numeric-Arrays if its *really* importent to get same entry at 2 arrays!!!

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 * $Id: EditPageForm.php,v 1.4 2004/03/04 23:07:13 udo Exp $
15 */
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
35 $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
41
42 //$this->$parent($title, $_SERVER['PHP_SELF'], $options);
43 $this->$parent($title, $options);
44 }
45
46 // 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
48 // be input-fields at the mising places and that the data will be recieved
49 // with the correct lkey
50 function get_nested_array_by_lkey($whichArray, $whichKey) {
51 $myArray = array();
52 $myArray = &$whichArray;
53 foreach ($myArray as $key=>$value) {
54 if ($value['lkey'] == $whichKey) {return $value;}
55 }
56 }
57
58
59 function form_init_elements() {
60
61 // 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
78 // used_keys are all lkeys, that contain the _sql_key
79 $used_keys = array();
80
81 $this->set_confirm();
82
83 // 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->_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
97 $tmp_array = array();
98 $larger = array();
99 // this is needed because the arrays may have to be filled with an array
100 $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
101
102
103 // the smaller array is backuped in tmp_array and then killed.
104 // the larger array is parsed and doing this we reset the smaller array form the
105 // backup in the right order. if there is an entry missing in the smaller
106 // array this key will not be filled here.
107
108 if (array_count_values($this->_set_items) > array_count_values($this->_show_items)) {
109 $larger = &$this->_set_items;
110 $tmp_array = $this->_show_items;
111 $this->_show_items = "killed";
112 $whichLarger = "_set_items";
113 } else {
114 $larger = &$this->_show_items;
115 $tmp_array = $this->_set_items;
116 $this->_set_items = "killed";
117 $whichLarger="_show_items";
118 }
119
120 $smaller = array();
121 foreach ($larger as $key=>$value) {
122 if (is_array($this->get_nested_array_by_lkey($tmp_array, $value['lkey']))) {
123 $smaller[$key] = $this->get_nested_array_by_lkey($tmp_array, $value['lkey']);
124 } else {
125 $smaller[$key] = $empty_array;
126 $smaller[$key]['lkey'] = $larger[$key]['lkey'];
127 }
128 }
129
130 // is _undone is selected, that means that the user only wants to see the items that
131 // are not yet translated, every entry, that has lvalues in both arrays, is marked.
132 if ($this->_undone == "yes") {
133 foreach ($used_keys as $key => $value) {
134 if ((strlen($larger[$value]['lvalue']) > 0) && (strlen($smaller[$value]['lvalue']) > 0)) {
135 $this->_set_items[$value] = "kickedMarkerXXX";
136 $this->_show_items[$value] = "kickedMarkerXXX";
137 }
138 }
139 }
140
141 if ($whichLarger=="_show_items") {
142 $this->_show_items = $larger;
143 $this->_set_items = $smaller;
144 } else {
145 $this->_show_items = $smaller;
146 $this->_set_items = $larger;
147 }
148
149
150 // the elements of the form are created
151 // the string-replacement is necessary because a slash (/) is turned into _
152 // in the html-code
153 foreach($used_keys as $key => $value) {
154 if ($this->_set_items[$key] != "kickedMarkerXXX") {
155 $show_el = str_replace("/", "x_x", $value) . $this->_show_lang . "s";
156
157 $set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u";
158
159 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));
161 $this->add_element( new FEText($set_el, false, 40));
162 } else{
163 $this->add_element( new FETextArea($show_el, false, 10, 40));
164 $this->add_element( new FETextArea($set_el, false, 10, 40));
165 }
166 $my_el = &$this->get_element($show_el);
167 $my_el->set_attribute("readonly");
168 $my_el = &$this->get_element($set_el);
169 }
170 }
171 }
172
173
174
175 function form_init_data() {
176
177 // the items that maybe are not to be shown because they are already translated
178 // should have been replaced with kickedMarkerXXX
179 foreach($this->_show_items as $key => $value) {
180 if ($value != "kickedMarkerXXX") {
181 $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
182 $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
183
184 if (!empty($this->_show_items[$key]['lvalue'])) {
185 $this->set_element_value($show_el, $this->_show_items[$key]['lvalue']);
186 } else {
187 $this->set_element_value($show_el, "&nbsp");
188 }
189 if (!empty($this->_set_items[$key]['lvalue'])) {
190 $this->set_element_value($set_el, $this->_set_items[$key]['lvalue']);
191 } else {
192 $this->set_element_value($set_el, "&nbsp");
193 }
194
195 $myElement = &$this->get_element($show_el);
196 $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
197 $myElement->set_required(0);
198
199 $myElement = &$this->get_element($set_el);
200 $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
201 $myElement->set_required(0);
202 }
203 }
204 }
205
206 /**
207 * This method allows the child to overide the
208 * default confirm data. By default the form_confirm()
209 * will show ALL FormElements. This is prolly not good
210 * in case of a form where a password exists.
211 *
212 * @param InfoTable object
213 */
214 function build_confirm_table( &$table ) {
215 foreach( $this->_elements as $label => $element) {
216 if ((substr($label, strlen($label) - 3, 2) == $_REQUEST['_set_lang']) && (substr($label, strlen($label) - 1, 1) == "u") && $element->get_value()){
217 $correct_key = substr($label, 0, strlen($label) - 3);
218 $correct_key = str_replace("x_x", "/", $correct_key);
219 $table->add_row( $correct_key, $element->get_value());
220 }
221 }
222 }
223
224 function form_confirm( ) {
225 $title = "confirmation form / " . $this->_options['caption'];
226 // $title .="( ".$this->_required_field_marker." ".$this->_required_field_text." )";
227 $table = new InfoTable($title, $this->_width);
228
229 $this->build_confirm_table( $table );
230
231 //now add the confirmation button
232 $td = new TDtag(array("colspan" => 2,
233 "class" => "contentnovertical",
234 "align" => "center"),
235 form_submit('ecdfe', "Confirm"),
236 //_HTML_SPACE,
237 form_submit('ecdfc',"Edit"));
238
239 $table->add_row( $td );
240 return $table;
241 }
242
243 function form_content() {
244
245 $table = &html_table(600, 0, 2);
246 switch ($this->_show_lang) {
247 case 'de':
248 $showLanguange = " german";
249 break;
250 case 'en':
251 $showLanguange = " english";
252 break;
253 case 'tr':
254 $showLanguange = " turkish";
255 break;
256 }
257 switch ($this->_set_lang) {
258 case 'de':
259 $setLanguange = " german";
260 break;
261 case 'en':
262 $setLanguange = " english";
263 break;
264 case 'tr':
265 $setLanguange = " turkish";
266 break;
267 }
268 $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );
269 $all_elements_translated = 0;
270
271 foreach($this->_show_items as $key => $value) {
272 if (is_array($value)) {
273 $all_elements_translated++;
274 $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
275 $set_el = str_replace("/", "x_x", $value['lkey']) . $this->_set_lang . "u";
276
277 $show_el_label = str_replace("x_x", "/", $value['lkey']);
278 $set_el_label = str_replace("x_x", "/", $value['lkey']);
279
280 $inner_table_left = &html_table();
281 $inner_table_left->add_row($show_el_label);
282
283 $inner_table_left->add_row($this->element_form($show_el));
284 $inner_table_right = &html_table();
285 $inner_table_right->add_row($set_el_label);
286
287 $inner_table_right->add_row($this->element_form($set_el));
288
289 $table->add_row($inner_table_left, $inner_table_right );
290 }
291 }
292 if ($all_elements_translated == 0) {
293 $table = &html_table(600, 0, 2);
294 $table->add_row("no items found");
295 }
296 $this->add_form_block("", $table );
297 }
298
299
300 function form_action() {
301
302 $data = array();
303 $new_data = array();
304 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()){
306 $correct_key = substr($label, 0, strlen($label) - 3);
307 $correct_key = str_replace("x_x", "/", $correct_key);
308 $new_data[$correct_key]=$element->get_value();
309 }
310 }
311
312 foreach ($this->_set_items as $item_key => $item_value) {
313 foreach($new_data as $data_key => $data_value) {
314 if ($data_key == $item_value['lkey']) {
315 $tmp_array = $item_value;
316 $tmp_array['lvalue'] = $data_value;
317 array_push($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)
326 $this->_options['data_locator_meta']['action'] = "write";
327 $this->_options['data_locator_meta']['data'] = $data;
328 // TODO: 'data_prefetch()' will never return ANYTHING!
329 // Implement some error-handling there or somewhere.
330 $error = $this->data_prefetch();
331 }
332 function form_backend_validation() {
333 $this->set_action("Confirm");
334 return TRUE;
335 }
336 function confirm_action() {
337 $this->set_action_message("yip, alles klar!");
338 return TRUE;
339 }
340 }
341
342
343 ?>

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