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