/[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.6 - (show annotations)
Tue Dec 14 21:10:10 2004 UTC (19 years, 8 months ago) by jonen
Branch: MAIN
Changes since 1.5: +7 -1 lines
+ inserted Log-Tag

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

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