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 |
jonen |
1.5 |
* $Id: EditPageForm.php,v 1.4 2004/03/04 23:07:13 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 |
jonen |
1.5 |
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 |
udo |
1.3 |
} |
93 |
|
|
} |
94 |
jonen |
1.5 |
|
95 |
udo |
1.3 |
|
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 |
jonen |
1.5 |
if ((strlen($larger[$value]['lvalue']) > 0) && (strlen($smaller[$value]['lvalue']) > 0)) { |
135 |
|
|
$this->_set_items[$value] = "kickedMarkerXXX"; |
136 |
|
|
$this->_show_items[$value] = "kickedMarkerXXX"; |
137 |
udo |
1.3 |
} |
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 |
udo |
1.1 |
|
149 |
udo |
1.3 |
|
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 |
udo |
1.1 |
|
157 |
udo |
1.3 |
$set_el = str_replace("/", "x_x", $value) . $this->_set_lang . "u"; |
158 |
|
|
|
159 |
jonen |
1.5 |
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 |
udo |
1.3 |
} 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 |
udo |
1.2 |
} |
172 |
|
|
|
173 |
udo |
1.3 |
|
174 |
udo |
1.1 |
|
175 |
|
|
function form_init_data() { |
176 |
udo |
1.2 |
|
177 |
udo |
1.3 |
// the items that maybe are not to be shown because they are already translated |
178 |
|
|
// should have been replaced with kickedMarkerXXX |
179 |
udo |
1.1 |
foreach($this->_show_items as $key => $value) { |
180 |
udo |
1.3 |
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 |
udo |
1.2 |
if (!empty($this->_show_items[$key]['lvalue'])) { |
185 |
|
|
$this->set_element_value($show_el, $this->_show_items[$key]['lvalue']); |
186 |
|
|
} else { |
187 |
udo |
1.3 |
$this->set_element_value($show_el, " "); |
188 |
udo |
1.2 |
} |
189 |
|
|
if (!empty($this->_set_items[$key]['lvalue'])) { |
190 |
|
|
$this->set_element_value($set_el, $this->_set_items[$key]['lvalue']); |
191 |
|
|
} else { |
192 |
udo |
1.3 |
$this->set_element_value($set_el, " "); |
193 |
udo |
1.2 |
} |
194 |
udo |
1.1 |
|
195 |
udo |
1.3 |
$myElement = &$this->get_element($show_el); |
196 |
|
|
$myElement->set_label_text(str_replace("x_x", "/", $value['lkey'])); |
197 |
|
|
$myElement->set_required(0); |
198 |
udo |
1.1 |
|
199 |
udo |
1.2 |
$myElement = &$this->get_element($set_el); |
200 |
udo |
1.3 |
$myElement->set_label_text(str_replace("x_x", "/", $value['lkey'])); |
201 |
|
|
$myElement->set_required(0); |
202 |
udo |
1.1 |
} |
203 |
|
|
} |
204 |
|
|
} |
205 |
|
|
|
206 |
udo |
1.3 |
/** |
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 |
udo |
1.4 |
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 |
udo |
1.3 |
} |
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 |
udo |
1.1 |
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 |
udo |
1.3 |
$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 |
udo |
1.1 |
$inner_table_left = &html_table(); |
281 |
udo |
1.3 |
$inner_table_left->add_row($show_el_label); |
282 |
|
|
|
283 |
udo |
1.2 |
$inner_table_left->add_row($this->element_form($show_el)); |
284 |
udo |
1.1 |
$inner_table_right = &html_table(); |
285 |
udo |
1.3 |
$inner_table_right->add_row($set_el_label); |
286 |
|
|
|
287 |
udo |
1.2 |
$inner_table_right->add_row($this->element_form($set_el)); |
288 |
udo |
1.1 |
|
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 |
udo |
1.3 |
$table->add_row("no items found"); |
295 |
|
|
} |
296 |
udo |
1.1 |
$this->add_form_block("", $table ); |
297 |
|
|
} |
298 |
|
|
|
299 |
udo |
1.3 |
|
300 |
udo |
1.1 |
function form_action() { |
301 |
udo |
1.3 |
|
302 |
udo |
1.4 |
$data = array(); |
303 |
udo |
1.3 |
$new_data = array(); |
304 |
udo |
1.4 |
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 |
udo |
1.3 |
$correct_key = substr($label, 0, strlen($label) - 3); |
307 |
|
|
$correct_key = str_replace("x_x", "/", $correct_key); |
308 |
udo |
1.4 |
$new_data[$correct_key]=$element->get_value(); |
309 |
udo |
1.3 |
} |
310 |
udo |
1.4 |
} |
311 |
udo |
1.1 |
|
312 |
udo |
1.4 |
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 |
udo |
1.3 |
} |
319 |
|
|
} |
320 |
udo |
1.4 |
} |
321 |
|
|
|
322 |
|
|
|
323 |
|
|
// print " data: " .Dumper($data). "<br>"; |
324 |
|
|
|
325 |
udo |
1.3 |
// write new data to datasource in $data as array (keep old indices, set new values) |
326 |
|
|
$this->_options['data_locator_meta']['action'] = "write"; |
327 |
udo |
1.4 |
$this->_options['data_locator_meta']['data'] = $data; |
328 |
udo |
1.3 |
// TODO: 'data_prefetch()' will never return ANYTHING! |
329 |
|
|
// Implement some error-handling there or somewhere. |
330 |
udo |
1.4 |
$error = $this->data_prefetch(); |
331 |
udo |
1.1 |
} |
332 |
|
|
function form_backend_validation() { |
333 |
|
|
$this->set_action("Confirm"); |
334 |
|
|
return TRUE; |
335 |
|
|
} |
336 |
|
|
function confirm_action() { |
337 |
udo |
1.4 |
$this->set_action_message("yip, alles klar!"); |
338 |
udo |
1.1 |
return TRUE; |
339 |
|
|
} |
340 |
|
|
} |
341 |
|
|
|
342 |
|
|
|
343 |
udo |
1.2 |
?> |