/[cvs]/nfo/php/libs/org.netfrag.patches/phphtmllib/forms/UploadForm.php
ViewVC logotype

Annotation of /nfo/php/libs/org.netfrag.patches/phphtmllib/forms/UploadForm.php

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.2 - (hide annotations)
Fri Nov 14 17:51:20 2003 UTC (21 years, 2 months ago) by udo
Branch: MAIN
Changes since 1.1: +10 -11 lines
changed label-text

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

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