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