1 |
<? |
2 |
/** |
3 |
* This file contains the UploadForm child class. |
4 |
* |
5 |
* |
6 |
* @package org.netfrag.patches |
7 |
* @name UploadForm |
8 |
* |
9 |
*/ |
10 |
|
11 |
/** |
12 |
* Cvs-Log |
13 |
* |
14 |
* $Id: UploadForm.php,v 1.2 2003/11/14 17:51:20 udo Exp $ |
15 |
* |
16 |
* $Log: UploadForm.php,v $ |
17 |
* Revision 1.2 2003/11/14 17:51:20 udo |
18 |
* changed label-text |
19 |
* |
20 |
* Revision 1.1 2003/11/14 17:02:28 udo |
21 |
* initial commit |
22 |
* |
23 |
* |
24 |
* |
25 |
*/ |
26 |
|
27 |
|
28 |
|
29 |
// this is an abstract form-class to edit LangText - content. |
30 |
class EditPageForm extends EditDataItem { |
31 |
|
32 |
// _show_lang is the language to be shown readonly |
33 |
var $_show_lang; |
34 |
// _set_lang is the language to be entered and updated in the Langtext-table |
35 |
var $_set_lang; |
36 |
// _show_items are the items that will be shown |
37 |
var $_show_items = array(); |
38 |
// _set_items are the items, that will maybe be changed an updated |
39 |
var $_set_items = array(); |
40 |
// undone is true, if the user selected to show untranslated items only |
41 |
var $_undone; |
42 |
// all LangText - entries that contain the string _sql_key will be selected. |
43 |
// this is passed dependent on which topic is selected in the page_news - class |
44 |
var $_sql_key; |
45 |
|
46 |
function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) { |
47 |
$this->_show_lang = $show_lang; |
48 |
$this->_set_lang = $set_lang; |
49 |
$this->_sql_key = $whichKey; |
50 |
$this->_undone = $undone; |
51 |
$parent = get_parent_class($this); |
52 |
$this->$parent($title, $options); |
53 |
} |
54 |
|
55 |
function form_init_elements() { |
56 |
|
57 |
// hidden element for page control |
58 |
$this->add_hidden_element( 't', 'News' ); |
59 |
|
60 |
// used_keys are all lkeys, that contain the _sql_key |
61 |
$used_keys = array(); |
62 |
|
63 |
// the _datasource->result - object is parsed and the matching items are |
64 |
// written into the arrays |
65 |
foreach($this->_datasource->_result as $key => $value) { |
66 |
if (strstr ( $value['lkey'], $this->_sql_key)) { |
67 |
if (!in_array($value['lkey'], $used_keys)) {array_push($used_keys, $value['lkey']);} |
68 |
if ($value['lcountrykey'] == $this->_show_lang) {array_push($this->_show_items, $value);} |
69 |
if ($value['lcountrykey'] == $this->_set_lang) {array_push($this->_set_items, $value);} |
70 |
} |
71 |
} |
72 |
|
73 |
// this function is needed, because _set_items and _show_items may contain a |
74 |
// different amount of entries. |
75 |
// the follogwing is all about sorting the both arrays in a way, that the same |
76 |
// entries have the same key and filling up entries, if theres an entry missing because |
77 |
// its not yet translated. |
78 |
function get_nested_array_by_lkey($whichArray=array(), $whichKey) { |
79 |
foreach ($whichArray as $key=>$value) { |
80 |
if ($value['lkey'] == $whichKey) {return $value;} |
81 |
} |
82 |
} |
83 |
|
84 |
|
85 |
// this is needed for sorting |
86 |
$tmp_array = array(); |
87 |
$larger = array(); |
88 |
// this is needed because the arrays may have to be filled with an array |
89 |
$empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" ); |
90 |
|
91 |
// the smaller array is backuped in tmp_array and then killed. |
92 |
// the larger array is parsed an doing this we reset the smaller array form the |
93 |
// backup in the right order. if there is an entry missing in the smaller |
94 |
// array this key will not be filled here. |
95 |
if (count($this->_set_items) > count($this->_show_items)) { |
96 |
$larger = $this->_set_items; |
97 |
$tmp_array = $this->_show_items; |
98 |
$this->_show_items = array(); |
99 |
foreach ($this->_set_items as $key=>$value) { |
100 |
$this->_show_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']); |
101 |
} |
102 |
} else if (count($this->_set_items) < count($this->_show_items)) { |
103 |
$larger = $this->_show_items; |
104 |
$tmp_array = $this->_set_items; |
105 |
$this->_set_items = array(); |
106 |
foreach ($this->_show_items as $key=>$value) { |
107 |
$this->_set_items[$key] = get_nested_array_by_lkey($tmp_array, $value['lkey']); |
108 |
} |
109 |
} else { |
110 |
$larger = $this->_show_items; |
111 |
} |
112 |
|
113 |
// both arrays are parsed and missing entries (without a key) are filled |
114 |
// with the empty_array. missing lkeys are filled with the lkey from used_keys, |
115 |
// so that now every key of the arrays has matching entries. this is important, |
116 |
// because otherwise the empty fields could not be named. |
117 |
|
118 |
foreach ($used_keys as $key => $value) { |
119 |
if (!is_array(get_nested_array_by_lkey($this->_set_items, $value))) { |
120 |
$this->_set_items[$key] = $empty_array; |
121 |
$this->_set_items[$key]['lkey'] = $value; |
122 |
} |
123 |
if (!is_array(get_nested_array_by_lkey($this->_show_items, $value))) { |
124 |
$this->_show_items[$key] = $empty_array; |
125 |
$this->_show_items[$key]['lkey'] = $value; |
126 |
} |
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 |
if ((strlen($this->_set_items[$key]['lvalue']) > 0) && (strlen($this->_show_items[$key]['lvalue']) > 0)) { |
135 |
$this->_set_items[$key] = "kickedMarkerXXX"; |
136 |
$this->_show_items[$key] = "kickedMarkerXXX"; |
137 |
} |
138 |
} |
139 |
} |
140 |
|
141 |
|
142 |
//print "used_keys: " . Dumper($used_keys) . "<br>"; |
143 |
//print "_set_items: " . Dumper($this->_set_items) . "<br>"; |
144 |
//print "_show_items: " . Dumper($this->_show_items) . "<br>"; |
145 |
|
146 |
|
147 |
|
148 |
// the elements of the form are created |
149 |
foreach($used_keys as $key => $value) { |
150 |
// if the entry == kickedMarkerXXX, $value will be no array |
151 |
if (is_array($this->_set_items[$key])) { |
152 |
$show_element = $value . $this->_show_lang . "s"; |
153 |
$set_element = $value . $this->_set_lang . "u"; |
154 |
|
155 |
if ((strlen($this->_set_items[$key]['lvalue']) < 40) && (strlen($this->_show_items[$key]['lvalue']) < 40)) { |
156 |
$this->add_element( new FEText($show_element, true, 40, 60)); |
157 |
$this->add_element( new FEText($set_element, true, 40, 60)); |
158 |
} else{ |
159 |
$this->add_element( new FETextArea($show_element, true, 10, 40)); |
160 |
$this->add_element( new FETextArea($set_element, true, 10, 40)); |
161 |
|
162 |
} |
163 |
$myElement = &$this->get_element($show_element); |
164 |
$myElement->set_attribute("readonly"); |
165 |
} |
166 |
} |
167 |
} |
168 |
|
169 |
function form_init_data() { |
170 |
|
171 |
|
172 |
foreach($this->_show_items as $key => $value) { |
173 |
if (is_array($value)) { |
174 |
$show_element = $value['lkey'] . $this->_show_lang . "s"; |
175 |
$set_element = $value['lkey'] . $this->_set_lang . "u"; |
176 |
|
177 |
$this->set_element_value($show_element, $this->_show_items[$key]['lvalue']); |
178 |
$this->set_element_value($set_element, $this->_set_items[$key]['lvalue']); |
179 |
|
180 |
$myElement = &$this->get_element($show_element); |
181 |
$myElement->set_label_text($value['lkey']); |
182 |
$myElement->set_required(false); |
183 |
|
184 |
$myElement = &$this->get_element($set_element); |
185 |
$myElement->set_label_text($value['lkey']); |
186 |
$myElement->set_required(false); |
187 |
} |
188 |
} |
189 |
} |
190 |
|
191 |
function form_content() { |
192 |
|
193 |
$table = &html_table(600, 0, 2); |
194 |
switch ($this->_show_lang) { |
195 |
case 'de': |
196 |
$showLanguange = " german"; |
197 |
break; |
198 |
case 'en': |
199 |
$showLanguange = " english"; |
200 |
break; |
201 |
case 'tr': |
202 |
$showLanguange = " turkish"; |
203 |
break; |
204 |
} |
205 |
switch ($this->_set_lang) { |
206 |
case 'de': |
207 |
$setLanguange = " german"; |
208 |
break; |
209 |
case 'en': |
210 |
$setLanguange = " english"; |
211 |
break; |
212 |
case 'tr': |
213 |
$setLanguange = " turkish"; |
214 |
break; |
215 |
} |
216 |
$table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange ); |
217 |
$all_elements_translated = 0; |
218 |
|
219 |
foreach($this->_show_items as $key => $value) { |
220 |
if (is_array($value)) { |
221 |
$all_elements_translated++; |
222 |
$show_element = $value['lkey'] . $this->_show_lang . "s"; |
223 |
$set_element = $value['lkey'] . $this->_set_lang . "u"; |
224 |
|
225 |
$inner_table_left = &html_table(); |
226 |
$inner_table_left->add_row($this->element_label($show_element)); |
227 |
$inner_table_left->add_row($this->element_form($show_element)); |
228 |
$inner_table_right = &html_table(); |
229 |
$inner_table_right->add_row($this->element_label($set_element)); |
230 |
$inner_table_right->add_row($this->element_form($set_element)); |
231 |
|
232 |
$table->add_row($inner_table_left, $inner_table_right ); |
233 |
} |
234 |
} |
235 |
if ($all_elements_translated == 0) { |
236 |
$table = &html_table(600, 0, 2); |
237 |
if (count($this->_set_items)>0) {$table->add_row("all items are translated!");} |
238 |
else {$table->add_row("no items found");} |
239 |
} |
240 |
$this->add_form_block("", $table ); |
241 |
} |
242 |
|
243 |
function form_action() { |
244 |
$data = array(); |
245 |
|
246 |
foreach ($this->_set_items as $key=>$value) { |
247 |
if (is_array($value)) { |
248 |
array_push($data, $this->_set_items[$key]); |
249 |
} |
250 |
} |
251 |
|
252 |
//$this->_options['data_locator_meta']['action'] = "write"; |
253 |
//$this->_options['data_locator_meta']['data'] = $data; |
254 |
//$error = $this->data_prefetch(); |
255 |
|
256 |
} |
257 |
function form_backend_validation() { |
258 |
$this->set_action("Confirm"); |
259 |
return TRUE; |
260 |
} |
261 |
function confirm_action() { |
262 |
return TRUE; |
263 |
} |
264 |
} |
265 |
|
266 |
|
267 |
|
268 |
//class EditTextForm extends StandardFormContent { |
269 |
class EditTextForm extends EditDataItem { |
270 |
|
271 |
var $_whichNews; |
272 |
var $_sql_key_long; |
273 |
var $_sql_key_short; |
274 |
var $_sql_key_title; |
275 |
var $_sql_key_source; |
276 |
var $_language; |
277 |
|
278 |
function EditTextForm($title, $width, $whichNews, $whichLanguage, $options=array()) { |
279 |
// something that has to be executed BEFORE parent constructor |
280 |
// |
281 |
|
282 |
$parent = get_parent_class($this); |
283 |
$this->$parent($title,$options); |
284 |
$this->_whichNews = $whichNews; |
285 |
$this->_sql_key_long = "page/news/feed/" . $whichNews . "/long"; |
286 |
$this->_sql_key_short = "page/news/feed/" . $whichNews . "/short"; |
287 |
$this->_sql_key_title = "page/news/feed/" . $whichNews . "/title"; |
288 |
$this->_sql_key_source = "page/news/feed/" . $whichNews . "/source"; |
289 |
$this->_language = $whichLanguage; |
290 |
} |
291 |
|
292 |
function form_init_elements() { |
293 |
//we want an confirmation page for this form. |
294 |
|
295 |
global $app; |
296 |
|
297 |
$this->set_confirm(); |
298 |
|
299 |
// add hidden element for page control |
300 |
$this->add_hidden_element( 't', 'News' ); |
301 |
$this->add_hidden_element( 'subtopic', $_REQUEST['subtopic'] ); |
302 |
|
303 |
$this->add_element( new FEText("Titel", true, 10, 20)); |
304 |
$this->add_element( new FETextArea("kurzer Text", true, 10, 20)); |
305 |
$this->add_element( new FETextArea("langer Text", true, 10, 20)); |
306 |
$this->add_element( new FEText("Quelle", true, 10, 20)); |
307 |
|
308 |
$handle=opendir ($app->getConfig("path.news.img.archive")); |
309 |
$myFileList= array(); |
310 |
while ($myFile = readdir ($handle)) { |
311 |
if (($myFile <> ".") && ($myFile<> "..") && (strstr($myFile, "."))){$myFileList[$myFile] = $myFile;} |
312 |
} |
313 |
closedir($handle); |
314 |
|
315 |
$this->add_element( new FEListBox("Bilderarchiv", FALSE,"200px", "80px",$myFileList)); |
316 |
|
317 |
} |
318 |
function form_init_data() { |
319 |
|
320 |
foreach($this->_datasource->_result as $key => $value) { |
321 |
if ($value['lcountrykey'] == $this->_language) { |
322 |
if ($value['lkey'] == $this->_sql_key_long) { |
323 |
$this->set_element_value("langer Text", $value['lvalue']); |
324 |
} |
325 |
if ($value['lkey'] == $this->_sql_key_short) { |
326 |
$this->set_element_value("kurzer Text", $value['lvalue']); |
327 |
} |
328 |
if ($value['lkey'] == $this->_sql_key_title) { |
329 |
$this->set_element_value("Titel", $value['lvalue']); |
330 |
} |
331 |
if ($value['lkey'] == $this->_sql_key_source) { |
332 |
$this->set_element_value("Quelle", $value['lvalue']); |
333 |
} |
334 |
} |
335 |
} |
336 |
|
337 |
$this->set_element_value("Bilderarchiv", array()); |
338 |
|
339 |
} |
340 |
|
341 |
|
342 |
function form_content() { |
343 |
$this->add_form_block("Please enter new text below " . $this->_whichNews, $this->_upload() ); |
344 |
} |
345 |
|
346 |
function &_upload() { |
347 |
|
348 |
$table = &html_table($this->_width, 0, 2); |
349 |
|
350 |
$table->add_row($this->element_label("Titel"), $this->element_form("Titel")); |
351 |
$table->add_row($this->element_label("kurzer Text"), $this->element_form("kurzer Text") ); |
352 |
$table->add_row($this->element_label("langer Text"), $this->element_form("langer Text") ); |
353 |
$table->add_row($this->element_label("Quelle"), $this->element_form("Quelle")); |
354 |
$table->add_row($this->element_label("Bilderarchiv"), $this->element_form("Bilderarchiv")); |
355 |
|
356 |
return $table; |
357 |
} |
358 |
|
359 |
|
360 |
function form_action() { |
361 |
|
362 |
$data = array(); |
363 |
|
364 |
foreach($this->_datasource->_result as $key => $value) { |
365 |
if ($value['lcountrykey'] == $this->_language) { |
366 |
if ($value['lkey'] == $this->_sql_key_long) { |
367 |
$data[$key] = $value; |
368 |
$data[$key]['lvalue'] = $this->get_element_value("langer Text"); |
369 |
} |
370 |
if ($value['lkey'] == $this->_sql_key_short) { |
371 |
$data[$key] = $value; |
372 |
$data[$key]['lvalue'] = $this->get_element_value("kurzer Text"); |
373 |
} |
374 |
if ($value['lkey'] == $this->_sql_key_title) { |
375 |
$data[$key] = $value; |
376 |
$data[$key]['lvalue'] = $this->get_element_value("Titel"); |
377 |
} |
378 |
if ($value['lkey'] == $this->_sql_key_source) { |
379 |
$data[$key] = $value; |
380 |
$data[$key]['lvalue'] = $this->get_element_value("Quelle"); |
381 |
} |
382 |
} |
383 |
} |
384 |
|
385 |
|
386 |
|
387 |
// write new data to datasource in $data as array (keep old indices, set new values) |
388 |
$this->_options['data_locator_meta']['action'] = "write"; |
389 |
$this->_options['data_locator_meta']['data'] = $data; |
390 |
// TODO: 'data_prefetch()' will never return ANYTHING! |
391 |
// Implement some error-handling there or somewhere. |
392 |
$error = $this->data_prefetch(); |
393 |
|
394 |
|
395 |
|
396 |
|
397 |
//$error = $this->_datasource->set($item); |
398 |
/* if(!$error) { |
399 |
// fetch fresh data |
400 |
$this->_options['data_locator_meta']['action'] = "read"; |
401 |
// unset previous initialed 'data' var |
402 |
$this->_options['data_locator_meta']['data'] = NULL; |
403 |
$this->data_prefetch(); |
404 |
|
405 |
$this->set_action_message($this->_confirm_msg); |
406 |
return TRUE; |
407 |
} else { |
408 |
return FALSE; |
409 |
}*/ |
410 |
|
411 |
global $app; |
412 |
|
413 |
// This contains the image-file that has to be moved from the archive-dir to the online-dir. |
414 |
// The name of the file has to be changed to the name which is hardcoded in the news-templates. |
415 |
// The online-dir will already contain a file with this name but possibly with a different suffix. |
416 |
// Make sure that this will be removed also, so that there is only one file matching in the online-dir. |
417 |
|
418 |
// prepare to copy selected file from archive-dir to online-dir |
419 |
|
420 |
|
421 |
if ($this->get_element_value("Bilderarchiv")) { |
422 |
$_dest_file_suffix = substr($this->get_element_value("Bilderarchiv"), count($this->get_element_value("Bilderarchiv")) - 4, 4); |
423 |
$_dest_file_name = $app->getConfig("path.news.img.online"). $this->_language ."/img_news_" . $this->_whichNews . "." . $_dest_file_suffix; |
424 |
$_source_file_name = $app->getConfig("path.news.img.archive") . $this->get_element_value("Bilderarchiv"); |
425 |
|
426 |
// delete all files in online-dir, which have the current news-number in the filename |
427 |
|
428 |
$handle=opendir ($app->getConfig("path.news.img.online") . $this->_language. "/"); |
429 |
|
430 |
while ($myFile = readdir ($handle)) { |
431 |
if (substr($myFile, 9, 1) == $this->_whichNews){unlink($app->getConfig("path.news.img.online") . "de/" . $myFile);} |
432 |
} |
433 |
closedir($handle); |
434 |
|
435 |
copy($_source_file_name, $_dest_file_name); |
436 |
} |
437 |
|
438 |
} |
439 |
|
440 |
function form_backend_validation() { |
441 |
$this->set_action("Confirm"); |
442 |
return TRUE; |
443 |
} |
444 |
|
445 |
/** |
446 |
* This method is called ONLY after ALL validation has |
447 |
* passed. This is the method that allows you to |
448 |
* do something with the data, say insert/update records |
449 |
* in the DB. |
450 |
*/ |
451 |
function confirm_action() { |
452 |
|
453 |
|
454 |
/* |
455 |
// all of the following is to be done later !!!!! |
456 |
|
457 |
// get data |
458 |
//print "All fetched RPC items: " . Dumper($this->_datasource->_result) . "<br>"; |
459 |
|
460 |
// write new data to datasource in $data as array (keep old indices, set new values) |
461 |
$this->_options['data_locator_meta']['action'] = "write"; |
462 |
$this->_options['data_locator_meta']['data'] = $data; |
463 |
// TODO: 'data_prefetch()' will never return ANYTHING! |
464 |
// Implement some error-handling there or somewhere. |
465 |
$error = $this->data_prefetch(); |
466 |
|
467 |
//$error = $this->_datasource->set($item); |
468 |
if(!$error) { |
469 |
// fetch fresh data |
470 |
$this->_options['data_locator_meta']['action'] = "read"; |
471 |
// unset previous initialed 'data' var |
472 |
$this->_options['data_locator_meta']['data'] = NULL; |
473 |
$this->data_prefetch(); |
474 |
|
475 |
$this->set_action_message($this->_confirm_msg); |
476 |
return TRUE; |
477 |
} else { |
478 |
return FALSE; |
479 |
}*/ |
480 |
return TRUE; |
481 |
} |
482 |
|
483 |
|
484 |
} |
485 |
|
486 |
|
487 |
////////////////////////////////////////////////////////////////////////////////////////// |
488 |
|
489 |
|
490 |
|
491 |
class UploadForm extends StandardFormContent { |
492 |
|
493 |
function UploadForm($title, $width) { |
494 |
// something that has to be executed BEFORE parent constructor |
495 |
// |
496 |
//$this->_feFile = new FEFile("testfile", TRUE, 20); |
497 |
// |
498 |
$parent = get_parent_class($this); |
499 |
$this->$parent($title, $PHP_SELF, $width=600); |
500 |
} |
501 |
|
502 |
function form_init_elements() { |
503 |
|
504 |
//print_r "scandir($this->_uploaddir)"; |
505 |
|
506 |
// add hidden element for page control |
507 |
$this->add_hidden_element( 't', 'News' ); |
508 |
$this->add_hidden_element( 'subtopic', 'upload' ); |
509 |
$this->set_confirm(false); |
510 |
$this->add_element( new FEFile("File")); |
511 |
|
512 |
} |
513 |
function form_init_data() { |
514 |
// ??? |
515 |
} |
516 |
|
517 |
|
518 |
function form_content() { |
519 |
$this->add_form_block("Waehlen Sie hier ein neues Bild aus:", $this->_upload() ); |
520 |
} |
521 |
|
522 |
function &_upload() { |
523 |
$table = &html_table($this->_width, 0, 2); |
524 |
$table->add_row($this->element_label("File"),$this->element_form("File") ); |
525 |
|
526 |
return $table; |
527 |
} |
528 |
|
529 |
|
530 |
function form_action() { |
531 |
|
532 |
global $app; |
533 |
|
534 |
$tmp = $this->get_element("File"); |
535 |
$fileInformation = $tmp->get_file_info(); |
536 |
if ($fileInformation["tmp_name"] > "") { |
537 |
|
538 |
$uploadfile = $app->getConfig("path.news.img.archive") . $fileInformation["name"]; |
539 |
|
540 |
/* the destination-name of the uploaded film is hardcoded, but not the suffix (.jpg ....) |
541 |
* so we have to ensure that there are no double files with the same filename but different suffixes |
542 |
* in the online - folder |
543 |
* |
544 |
*/ |
545 |
|
546 |
if (move_uploaded_file($fileInformation["tmp_name"], $uploadfile)) { |
547 |
print "File was successfully uploaded. "; |
548 |
//print_r($_FILES); |
549 |
} else { |
550 |
print "File not uploaded\n"; |
551 |
//print_r($_FILES); |
552 |
} |
553 |
} |
554 |
|
555 |
} |
556 |
|
557 |
function form_backend_validation() { |
558 |
//$this->set_action("Confirm"); |
559 |
return TRUE; |
560 |
} |
561 |
|
562 |
|
563 |
function &_user_info() { |
564 |
$table = &html_table(100,0,2); |
565 |
$table->add_row($this->element_label("File"), $this->element_form("File")); |
566 |
|
567 |
return $table; |
568 |
} |
569 |
|
570 |
} |
571 |
|
572 |
?> |