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

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

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.1 by udo, Fri Nov 14 17:02:28 2003 UTC revision 1.4 by udo, Sat Nov 22 18:38:46 2003 UTC
# Line 14  Line 14 
14   * $Id$   * $Id$
15   *   *
16   * $Log$   * $Log$
17     * Revision 1.4  2003/11/22 18:38:46  udo
18     * created seperate files of the classes
19     *
20     * Revision 1.3  2003/11/14 18:04:13  udo
21     * fixed textArea dependent to _show_items and _set_items
22     *
23     * Revision 1.2  2003/11/14 17:51:20  udo
24     * changed label-text
25     *
26   * Revision 1.1  2003/11/14 17:02:28  udo   * Revision 1.1  2003/11/14 17:02:28  udo
27   * initial commit   * initial commit
28   *   *
# Line 21  Line 30 
30   *   *
31   */   */
32    
   
   
 // this is an abstract form-class to edit LangText - content.  
  class EditPageForm extends EditDataItem {  
   
 // _show_lang is the language to be shown readonly  
   var $_show_lang;  
 // _set_lang is the language to be entered and updated in the Langtext-table  
   var $_set_lang;  
 // _show_items are the items that will be shown  
   var $_show_items = array();  
 // _set_items are the items, that will maybe be changed an updated  
   var $_set_items = array();  
 // undone is true, if the user selected to show untranslated items only  
   var $_undone;  
 // all LangText - entries that contain the string _sql_key will be selected.  
 // this is passed dependent on which topic is selected in the page_news - class  
   var $_sql_key;  
   
   function EditPageForm($title, $width, $whichKey, $show_lang, $set_lang, $undone, $options) {  
     $this->_show_lang = $show_lang;  
     $this->_set_lang = $set_lang;  
     $this->_sql_key = $whichKey;  
     $this->_undone = $undone;  
     $parent = get_parent_class($this);  
     $this->$parent($title, $options);  
   }  
     
   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);}  
       }  
     }  
   
 // this function is needed, because _set_items and _show_items may contain a  
 // different amount of entries.  
 // the follogwing is all about sorting the both arrays in a way, that the same  
 // entries have the same key and filling up entries, if theres an entry missing because  
 // its not yet translated.  
     function get_nested_array_by_lkey($whichArray=array(), $whichKey) {  
       foreach ($whichArray as $key=>$value) {  
         if ($value['lkey'] == $whichKey) {return $value;}  
       }  
     }  
   
   
 // this is needed for sorting  
     $tmp_array = array();  
     $larger = array();  
 // this is needed because the arrays may have to be filled with an array  
     $empty_array = array("lvalue" => "", "lkey" => "", "lcountrykey" => "", "guid" => "" );  
   
 // the smaller array is backuped in tmp_array and then killed.  
 // the larger array is parsed an doing this we reset the smaller array form the  
 // backup in the right order. if there is an entry missing in the smaller  
 // array this key will not be filled here.  
     if (count($this->_set_items) > count($this->_show_items)) {  
       $larger = $this->_set_items;  
       $tmp_array = $this->_show_items;  
       $this->_show_items = array();  
       foreach ($this->_set_items as $key=>$value) {  
         $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;  
       }  
         
   
       
 // both arrays are parsed and missing entries (without a key) are filled  
 // with the empty_array. missing lkeys are filled with the lkey from used_keys,  
 // 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;  
         }  
       }  
   
         
 // is _undone is selected, that means that the user only wants to see the items that  
 // are not yet translated, every entry, that has lvalues in both arrays, is marked.  
     if ($this->_undone == "yes") {  
       foreach ($used_keys as $key => $value) {        
         if ((strlen($this->_set_items[$key]['lvalue']) > 0) && (strlen($this->_show_items[$key]['lvalue']) > 0)) {  
           $this->_set_items[$key] = "kickedMarkerXXX";  
           $this->_show_items[$key] = "kickedMarkerXXX";  
         }  
       }  
     }  
       
       
 // the elements of the form are created  
     foreach($this->_set_items as $key => $value) {  
   
         
 // if the entry == kickedMarkerXXX, $value will be no array  
       if (is_array($value)) {  
         $show_element = $value['lkey'] . $this->_show_lang . "s";  
         $set_element = $value['lkey'] . $this->_set_lang . "u";  
           
   
   
         if (strlen($value['lvalue']) > 40) {  
           $this->add_element( new FETextArea($show_element, true, 10, 40));  
           $this->add_element( new FETextArea($set_element, true, 10, 40));  
         } else{  
           $this->add_element( new FEText($show_element, true, 40, 60));  
           $this->add_element( new FEText($set_element, true, 40, 60));  
         }  
         $myElement = &$this->get_element($show_element);  
         $myElement->set_attribute("readonly");  
       }  
     }  
   }  
   
   function form_init_data() {  
   
       
     foreach($this->_show_items as $key => $value) {  
       if (is_array($value)) {  
         $show_element = $value['lkey'] . $this->_show_lang . "s";  
         $set_element = $value['lkey'] . $this->_set_lang . "u";  
     
         $this->set_element_value($show_element, $this->_show_items[$key]['lvalue']);  
         $this->set_element_value($set_element, $this->_set_items[$key]['lvalue']);  
           
         $myElement = &$this->get_element($show_element);  
         $myElement->set_label_text("");  
         $myElement->set_required(false);  
           
         $myElement = &$this->get_element($set_element);  
         $myElement->set_label_text("");  
         $myElement->set_required(false);  
       }  
     }        
   }  
   
   function form_content() {  
       
     $table = &html_table(600, 0, 2);  
     switch ($this->_show_lang) {  
       case 'de':  
         $showLanguange = " german";  
         break;  
       case 'en':  
         $showLanguange = " english";  
         break;  
       case 'tr':  
         $showLanguange = " turkish";  
         break;          
       }  
     switch ($this->_set_lang) {  
       case 'de':  
         $setLanguange = " german";  
         break;  
       case 'en':  
         $setLanguange = " english";  
         break;  
       case 'tr':  
         $setLanguange = " turkish";  
         break;          
       }  
     $table->add_row("translate from" . $showLanguange, "translate to" . $setLanguange );  
     $all_elements_translated = 0;      
   
     foreach($this->_show_items as $key => $value) {  
       if (is_array($value)) {  
         $all_elements_translated++;  
         $show_element = $value['lkey'] . $this->_show_lang . "s";  
         $set_element = $value['lkey'] . $this->_set_lang . "u";  
           
         $inner_table_left = &html_table();  
         $inner_table_left->add_row($this->element_label($show_element));  
         $inner_table_left->add_row($this->element_form($show_element));  
         $inner_table_right = &html_table();  
         $inner_table_right->add_row($this->element_label($set_element));  
         $inner_table_right->add_row($this->element_form($set_element));  
   
         $table->add_row($inner_table_left, $inner_table_right );  
       }  
     }  
     if ($all_elements_translated == 0) {  
       $table = &html_table(600, 0, 2);  
       if (count($this->_set_items)>0) {$table->add_row("all items are translated!");}  
       else {$table->add_row("no items found");}  
       }  
     $this->add_form_block("", $table );  
   }  
   
   function form_action() {  
     $data = array();  
       
     foreach ($this->_set_items as $key=>$value) {  
       if (is_array($value)) {  
         array_push($data, $this->_set_items[$key]);  
         }  
       }  
   
     //$this->_options['data_locator_meta']['action'] = "write";  
     //$this->_options['data_locator_meta']['data'] = $data;  
     //$error = $this->data_prefetch();  
   
   }  
   function form_backend_validation() {  
     $this->set_action("Confirm");  
     return TRUE;  
   }  
   function confirm_action() {  
     return TRUE;  
   }  
 }  
   
   
   
 //class EditTextForm extends StandardFormContent {  
 class EditTextForm extends EditDataItem {  
   
   var $_whichNews;  
   var $_sql_key_long;  
   var $_sql_key_short;  
   var $_sql_key_title;  
   var $_sql_key_source;  
   var $_language;  
   
   function EditTextForm($title, $width, $whichNews, $whichLanguage, $options=array()) {  
     // something that has to be executed BEFORE parent constructor  
     //  
   
     $parent =  get_parent_class($this);  
     $this->$parent($title,$options);  
     $this->_whichNews = $whichNews;  
     $this->_sql_key_long = "page/news/feed/" . $whichNews . "/long";  
     $this->_sql_key_short = "page/news/feed/" . $whichNews . "/short";  
     $this->_sql_key_title = "page/news/feed/" . $whichNews . "/title";  
     $this->_sql_key_source = "page/news/feed/" . $whichNews . "/source";  
     $this->_language = $whichLanguage;  
   }    
     
   function form_init_elements() {  
      //we want an confirmation page for this form.  
       
      global $app;  
   
      $this->set_confirm();  
   
      // add hidden element for page control  
      $this->add_hidden_element( 't', 'News' );  
      $this->add_hidden_element( 'subtopic', $_REQUEST['subtopic'] );  
                   
                  $this->add_element( new FEText("Titel", true, 10, 20));                  
                  $this->add_element( new FETextArea("kurzer Text", true, 10, 20));  
                  $this->add_element( new FETextArea("langer Text", true, 10, 20));  
                  $this->add_element( new FEText("Quelle", true, 10, 20));  
   
                  $handle=opendir ($app->getConfig("path.news.img.archive"));  
                  $myFileList= array();  
                  while ($myFile = readdir ($handle)) {  
        if (($myFile <> ".") && ($myFile<> "..") && (strstr($myFile, "."))){$myFileList[$myFile] = $myFile;}  
      }  
      closedir($handle);  
       
                  $this->add_element( new FEListBox("Bilderarchiv", FALSE,"200px", "80px",$myFileList));  
   
   }  
   function form_init_data() {  
     
     foreach($this->_datasource->_result as $key => $value) {  
       if ($value['lcountrykey'] == $this->_language) {  
         if ($value['lkey'] == $this->_sql_key_long) {  
           $this->set_element_value("langer Text", $value['lvalue']);  
         }  
         if ($value['lkey'] == $this->_sql_key_short) {  
           $this->set_element_value("kurzer Text", $value['lvalue']);  
         }  
         if ($value['lkey'] == $this->_sql_key_title) {  
           $this->set_element_value("Titel", $value['lvalue']);  
         }  
         if ($value['lkey'] == $this->_sql_key_source) {  
           $this->set_element_value("Quelle", $value['lvalue']);  
         }  
       }  
     }  
                   
                 $this->set_element_value("Bilderarchiv", array());  
                           
   }  
     
   
   function form_content() {  
                 $this->add_form_block("Please enter new text below " . $this->_whichNews, $this->_upload() );  
         }  
           
         function &_upload() {  
   
                 $table = &html_table($this->_width, 0, 2);  
   
                 $table->add_row($this->element_label("Titel"), $this->element_form("Titel"));  
                 $table->add_row($this->element_label("kurzer Text"), $this->element_form("kurzer Text") );  
                 $table->add_row($this->element_label("langer Text"), $this->element_form("langer Text") );  
                 $table->add_row($this->element_label("Quelle"), $this->element_form("Quelle"));  
                 $table->add_row($this->element_label("Bilderarchiv"), $this->element_form("Bilderarchiv"));              
                   
                 return $table;  
         }  
           
   
         function form_action() {  
             
           $data = array();  
             
           foreach($this->_datasource->_result as $key => $value) {  
       if ($value['lcountrykey'] == $this->_language) {        
               if ($value['lkey'] == $this->_sql_key_long) {  
                 $data[$key] = $value;  
                 $data[$key]['lvalue'] = $this->get_element_value("langer Text");  
               }  
               if ($value['lkey'] == $this->_sql_key_short) {  
                 $data[$key] = $value;  
                 $data[$key]['lvalue'] = $this->get_element_value("kurzer Text");  
               }  
               if ($value['lkey'] == $this->_sql_key_title) {  
                 $data[$key] = $value;  
                 $data[$key]['lvalue'] = $this->get_element_value("Titel");  
               }  
               if ($value['lkey'] == $this->_sql_key_source) {  
                 $data[$key] = $value;  
                 $data[$key]['lvalue'] = $this->get_element_value("Quelle");  
               }  
             }  
           }  
             
   
             
           // write new data to datasource in $data as array (keep old indices, set new values)  
         $this->_options['data_locator_meta']['action'] = "write";  
         $this->_options['data_locator_meta']['data'] = $data;  
         // TODO: 'data_prefetch()' will never return ANYTHING!  
         //           Implement some error-handling there or somewhere.  
         $error = $this->data_prefetch();  
           
   
           
     
         //$error = $this->_datasource->set($item);  
  /*       if(!$error) {  
           // fetch fresh data  
           $this->_options['data_locator_meta']['action'] = "read";  
           // unset previous initialed 'data' var  
           $this->_options['data_locator_meta']['data'] = NULL;  
           $this->data_prefetch();  
           
           $this->set_action_message($this->_confirm_msg);  
           return TRUE;  
         } else {  
           return FALSE;  
         }*/  
             
     global $app;  
   
         // This contains the image-file that has to be moved from the archive-dir to the online-dir.  
         // The name of the file has to be changed to the name which is hardcoded in the news-templates.  
         // The online-dir will already contain a file with this name but possibly with a different suffix.  
         // Make sure that this will be removed also, so that there is only one file matching in the online-dir.  
           
 // prepare to copy selected file from archive-dir to online-dir  
   
   
           if ($this->get_element_value("Bilderarchiv")) {  
             $_dest_file_suffix = substr($this->get_element_value("Bilderarchiv"), count($this->get_element_value("Bilderarchiv")) - 4, 4);  
             $_dest_file_name = $app->getConfig("path.news.img.online"). $this->_language ."/img_news_" . $this->_whichNews . "." . $_dest_file_suffix;  
             $_source_file_name = $app->getConfig("path.news.img.archive") . $this->get_element_value("Bilderarchiv");  
   
 // delete all files in online-dir, which have the current news-number in the filename  
   
       $handle=opendir ($app->getConfig("path.news.img.online") . $this->_language. "/");  
   
                   while ($myFile = readdir ($handle)) {  
         if (substr($myFile, 9, 1) == $this->_whichNews){unlink($app->getConfig("path.news.img.online") . "de/" . $myFile);}  
       }  
       closedir($handle);  
             
       copy($_source_file_name, $_dest_file_name);  
     }  
       
         }  
   
   function form_backend_validation() {  
     $this->set_action("Confirm");  
     return TRUE;  
   }  
   
     /**  
      * This method is called ONLY after ALL validation has  
      * passed.  This is the method that allows you to  
      * do something with the data, say insert/update records  
      * in the DB.  
      */  
     function confirm_action() {  
         
           
         /*  
 // all of the following is to be done later !!!!!  
   
 // get data  
           //print "All fetched RPC items: " . Dumper($this->_datasource->_result) . "<br>";  
   
         // write new data to datasource in $data as array (keep old indices, set new values)  
         $this->_options['data_locator_meta']['action'] = "write";  
         $this->_options['data_locator_meta']['data'] = $data;  
         // TODO: 'data_prefetch()' will never return ANYTHING!  
         //           Implement some error-handling there or somewhere.  
         $error = $this->data_prefetch();  
           
         //$error = $this->_datasource->set($item);  
         if(!$error) {  
           // fetch fresh data  
           $this->_options['data_locator_meta']['action'] = "read";  
           // unset previous initialed 'data' var  
           $this->_options['data_locator_meta']['data'] = NULL;  
           $this->data_prefetch();  
           
           $this->set_action_message($this->_confirm_msg);  
           return TRUE;  
         } else {  
           return FALSE;  
         }*/  
         return TRUE;  
     }  
   
       
 }  
   
   
 //////////////////////////////////////////////////////////////////////////////////////////  
   
   
   
33  class UploadForm extends StandardFormContent {  class UploadForm extends StandardFormContent {
34    
35    function UploadForm($title, $width) {    function UploadForm($title, $width) {
# Line 565  class UploadForm extends StandardFormCon Line 111  class UploadForm extends StandardFormCon
111            
112  }  }
113    
 ?>  
114    ?>

Legend:
Removed from v.1.1  
changed lines
  Added in v.1.4

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