/[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.3 - (show annotations)
Mon Dec 15 21:03:19 2003 UTC (20 years, 8 months ago) by udo
Branch: MAIN
Changes since 1.2: +256 -136 lines
finished

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.2 2003/12/01 23:34:35 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 $this->$parent($title, $options);
42 }
43
44
45 // this function is needed, because _set_items and _show_items may contain a
46 // different amount of entries. in that case we have ensure, that there will
47 // be input-fields at the mising places and that the data will be recieved
48 // with the correct lkey
49 function get_nested_array_by_lkey($whichArray, $whichKey) {
50 $myArray = array();
51 $myArray = &$whichArray;
52 foreach ($myArray as $key=>$value) {
53 if ($value['lkey'] == $whichKey) {
54 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
79 // used_keys are all lkeys, that contain the _sql_key
80 $used_keys = array();
81
82 $this->set_confirm();
83
84 // the _datasource->result - object is parsed and the matching items are
85 // written into the arrays
86 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 if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);}
90 if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);}
91 }
92 }
93
94
95 // this is needed for sorting
96 $tmp_array = array();
97 $larger = array();
98 // this is needed because the arrays may have to be filled with an array
99 $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );
100
101
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
107 if (array_count_values($this->_set_items) > array_count_values($this->_show_items)) {
108 $larger = &$this->_set_items;
109 $tmp_array = $this->_show_items;
110 $this->_show_items = "killed";
111 $whichLarger = "_set_items";
112 } else {
113 $larger = &$this->_show_items;
114 $tmp_array = $this->_set_items;
115 $this->_set_items = "killed";
116 $whichLarger="_show_items";
117 }
118
119 $smaller = array();
120 foreach ($larger as $key=>$value) {
121 if (is_array($this->get_nested_array_by_lkey($tmp_array, $value['lkey']))) {
122 $smaller[$key] = $this->get_nested_array_by_lkey($tmp_array, $value['lkey']);
123 } else {
124 $smaller[$key] = $empty_array;
125 $smaller[$key]['lkey'] = $larger[$key]['lkey'];
126 }
127 }
128
129 // is _undone is selected, that means that the user only wants to see the items that
130 // 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
173
174 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) {
179 if ($value != "kickedMarkerXXX") {
180 $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
181 $set_el = str_replace("/", "x_x", $value['lkey']). $this->_set_lang . "u";
182
183 if (!empty($this->_show_items[$key]['lvalue'])) {
184 $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_el);
195 $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
196 $myElement->set_required(0);
197
198 $myElement = &$this->get_element($set_el);
199 $myElement->set_label_text(str_replace("x_x", "/", $value['lkey']));
200 $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() {
267
268 $table = &html_table(600, 0, 2);
269 switch ($this->_show_lang) {
270 case 'de':
271 $showLanguange = " german";
272 break;
273 case 'en':
274 $showLanguange = " english";
275 break;
276 case 'tr':
277 $showLanguange = " turkish";
278 break;
279 }
280 switch ($this->_set_lang) {
281 case 'de':
282 $setLanguange = " german";
283 break;
284 case 'en':
285 $setLanguange = " english";
286 break;
287 case 'tr':
288 $setLanguange = " turkish";
289 break;
290 }
291 $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );
292 $all_elements_translated = 0;
293
294 foreach($this->_show_items as $key => $value) {
295 if (is_array($value)) {
296 $all_elements_translated++;
297 $show_el = str_replace("/", "x_x", $value['lkey']) . $this->_show_lang . "s";
298 $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();
304 $inner_table_left->add_row($show_el_label);
305
306 $inner_table_left->add_row($this->element_form($show_el));
307 $inner_table_right = &html_table();
308 $inner_table_right->add_row($set_el_label);
309
310 $inner_table_right->add_row($this->element_form($set_el));
311
312 $table->add_row($inner_table_left, $inner_table_right );
313 }
314 }
315 if ($all_elements_translated == 0) {
316 $table = &html_table(600, 0, 2);
317 $table->add_row("no items found");
318 }
319 $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() {
326
327 $useless_keys = array ('0' => "ecdfe",
328 '1' => "_form_action",
329 '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() {
377 $this->set_action("Confirm");
378 return TRUE;
379 }
380 function confirm_action() {
381 return TRUE;
382 }
383 }
384
385
386 ?>

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