Source for file DBMS_FIELD_FILESELECTLIST.phpclass

Documentation is available at DBMS_FIELD_FILESELECTLIST.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_FILESELECTLIST.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   string
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @author     Christian Gaisberger <c.gaisberger@lvus.at>
  11.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  12.   *
  13.   * @version $Id: DBMS_FIELD_FILESELECTLIST.phpclass,v 1.25 2008/11/15 10:03:32 pitlinz Exp $
  14.   * 
  15.   */
  16.  
  17.     // ---------------------------------------------------------
  18.     // requirements
  19.     // ---------------------------------------------------------
  20.  
  21.     pcf_require_class('DBMS_FIELD_SELECTLIST',dirname(__FILE__"/");
  22.     pcf_require_interface('INFA_DBMS_FIELD_FILESELECT',dirname(__FILE__"/");
  23.     pcf_require_function('pcf_getDirList',"common/pcf_directory.phpinc");
  24.     pcf_require_function('pcf_checkFileName',"common/pcf_file.phpinc");
  25.     
  26.  
  27. /**
  28.   * Class DBMS_FIELD_FILESELECTLIST
  29.   *
  30.   * handles file upload
  31.   *
  32.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  33.   * @author     Christian Gaisberger <c.gaisberger@lvus.at>
  34.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  35.   *
  36.   * @version pk-05-06-24
  37.   * @version $Id: DBMS_FIELD_FILESELECTLIST.phpclass,v 1.25 2008/11/15 10:03:32 pitlinz Exp $
  38.   * 
  39.   */
  40. {
  41.     
  42.     /**
  43.       * source file of the class
  44.       *
  45.       * @var string $classSrcFile 
  46.       * @since pk-04-10-05
  47.       */
  48.     protected $classSrcFile=__FILE__;    
  49.     
  50.     // --------------------------------------------------------
  51.     // direcotry vars
  52.     // --------------------------------------------------------
  53.     
  54.     /**
  55.       * @var string $rootDir the first selectable directory
  56.       * @access protected
  57.       */
  58.     protected $rootDir         = "";
  59.     
  60.     /**
  61.       * rootDir is under documentRoot
  62.       * if True root starts at DOCUMENT_ROOT else root starts at Projekt root ($OCSP_CONF['PROJECTPATH']);
  63.       * @var boolean $useDocRoot 
  64.       * @access protected
  65.       ***/
  66.     protected $useDocRoot     = True;    
  67.     
  68.     /**
  69.       * @var string $rootDir the defaultDirectory == Default Value
  70.       * @access protected
  71.       ***/
  72.     protected $defaultDir      = "";
  73.  
  74.     /**
  75.       * @var boolean $allow_mkdir (does the form allow the creation of a new directory)
  76.       * @access protected
  77.       */
  78.     protected $allow_mkdirTrue;
  79.  
  80.     /**
  81.       * @var boolean $allow_cd (does the user have the right to change the directory)
  82.       * @access protected
  83.       */
  84.     protected $allow_cd=True;    
  85.     
  86.     /**
  87.      * max file size in kb
  88.      * @var int $maxSize 
  89.      */    
  90.     protected $maxSize=1024;
  91.         
  92.     // --------------------------------------------------------
  93.     // file vars
  94.     // --------------------------------------------------------
  95.     
  96.     /**
  97.      * comma seperated list of allowed file extensions
  98.      *  
  99.      * @var string $extfilter 
  100.      */
  101.     protected $extfilter       = "";    
  102.     
  103.   
  104.     
  105.     // --------------------------------------------------------
  106.     // getter / setter
  107.     // --------------------------------------------------------
  108.  
  109.     /**
  110.      * returns the max file size in bytes
  111.      * @return int 
  112.      * @since pk-07-11-18
  113.      */
  114.     public function getMaxFileSizeBytes()
  115.     {
  116.         return intval($this->maxSize)*1024;
  117.     }    
  118.     
  119.     /**
  120.      * returns the name of the directory select
  121.      *
  122.      * @return string 
  123.      */
  124.     public function getDirSelNameId()
  125.     {
  126.         return "DIRSEL_" $this->getDOMId();
  127.     }
  128.     
  129.     // --------------------------------------------------------
  130.     // field configuration
  131.     // --------------------------------------------------------
  132.  
  133.     /**
  134.       * returns an array of field to bie shown in the edit form
  135.       * by using editTbl_echoForm
  136.       *
  137.       * the array is in the form:
  138.       *
  139.       * <code>
  140.       * [_sectionName_]
  141.       *      [TITLE] -> string
  142.       *      [_rowName_]
  143.       *         [FLDLAB]  (complete html code with <td></td>)
  144.       *         [FLDVAL] (complete html code with <td></td>)
  145.       * </code>
  146.       *
  147.       * @param boolean $debug 
  148.       *
  149.       * @global $OCSP_CONF 
  150.       *
  151.       * @returns array
  152.       *
  153.       * @since pk-06-07-28
  154.       *
  155.       ***/
  156.     function editTbl_getFieldEditArr($debug=False)
  157.     {
  158.         global $OCSP_CONF;
  159.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DBSELECTLIST::editTbl_getFieldEditArr","",0);
  160.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  161.  
  162.         include __OCSP_PHPINCPATH__."db/forms/languages/DBMS_FIELD_FILESELECTLIST_FieldEditArr_DE.phpinc";
  163.         unset($a_ret['SELECT']);
  164.  
  165.         return $a_ret;
  166.     }
  167.  
  168.     /**
  169.       * saves the fld definition
  170.       *
  171.       * @return bool 
  172.       *
  173.       * @version pk-05-02-01
  174.       * @version pk-05-06-24
  175.       *
  176.       */
  177.     function save(
  178.     {
  179.         $ret parent::save();
  180.         $this->allowNullSelect  =$this->allowNull();
  181.         $this->showNullOption    =True;
  182.         
  183.         $this->rootDir          =trim($_POST['rootDir']);
  184.         if (substr($this->rootDir,-1!= _OCSP_DIRSEP_$this->rootDir.=_OCSP_DIRSEP_;
  185.         if (substr($this->rootDir,0,1== _OCSP_DIRSEP_$this->rootDir=substr($this->rootDir,1);
  186.         
  187.         //$this->htmlValWithRoot = (intval($_POST['htmlValWithRoot']) ? TRUE : FALSE);
  188.         $this->useDocRoot      = (intval($_POST['useDocRoot']True False);
  189.         $this->getValue_nochk  (intval($_POST['getValue_nochk']True False);
  190.  
  191.         // <pk-05-06-24>
  192.         if ($this->useDocRoot{
  193.             if (!is_dir($_SERVER['DOCUMENT_ROOT']._OCSP_DIRSEP_.$this->rootDir)) {
  194.                 echo "<p color='red'>Verzeichnis: ".$_SERVER['DOCUMENT_ROOT'].$this->rootDir." existiert nicht in der Document-Root</p>";
  195.                 return FALSE;
  196.             }
  197.         else {    
  198.            if (!is_dir(__OCSP_PROJECTPATH__.$this->rootDir)) {
  199.                 echo "<p color='red'>Verzeichnis:" __OCSP_PROJECTPATH__ $this->rootDir." existiert nicht</p>";
  200.                 return FALSE;
  201.             }
  202.         }
  203.         // </pk-05-06-24>
  204.         
  205.         $this->allow_mkdir = ((isset($_POST['allow_mkdir']&& intval($_POST['allow_mkdir'])) TRUE FALSE);
  206.         $this->allow_cd    = ((isset($_POST['allow_cd']&& intval($_POST['allow_cd'])) TRUE FALSE);
  207.          
  208.         
  209.         $this->defaultDir       = (isset($_POST['defaultDir']$_POST['defaultDir'"");
  210.                         
  211.         $this->allow_upload     (intval($_POST['allow_upload']True False);
  212.         $this->allow_overwrite  (intval($_POST['allow_overwrite']True False);
  213.         $this->allow_edit       (intval($_POST['allow_edit']True False);
  214.  
  215.         $this->uploadUrl        (isset($_POST['uploadUrl']$_POST['uploadUrl'"");
  216.         $this->editorUrl        (isset($_POST['editorUrl']$_POST['editorUrl'"");
  217.         $this->downloadUrl      (isset($_POST['downloadUrl']$_POST['downloadUrl']"");
  218.         $this->downlGrp         (isset($_POST['downlGrp']intval($_POST['downlGrp']0);
  219.  
  220.         return $ret;
  221.     }    
  222.  
  223.       
  224.     
  225.     // --------------------------------------------------------
  226.     // directory method
  227.     // --------------------------------------------------------
  228.        
  229.     /**
  230.      * returns the base path (DOCUMENTROOT or PROJECT PATH)
  231.      *
  232.      * @return string 
  233.      */
  234.     protected function getBasePath()
  235.     {
  236.         return ($this->useDocRoot ? $_SERVER['DOCUMENT_ROOT'_OCSP_DIRSEP_ OCSP_OBJ::getConf('PROJECTPATH'));
  237.     }
  238.     
  239.     /**
  240.       * returns the absolute root path
  241.       * and fixes $this->rootDir
  242.       *
  243.       * @param boolean $debug 
  244.       * 
  245.       * @return string 
  246.       * 
  247.       * @version pk-08-05-18
  248.       */
  249.     public function getRootPath($debug False)
  250.     {
  251.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FIELSELECT::getRootPath()");
  252.         
  253.         $str_ret $this->getBasePath();
  254.                 
  255.         if (!empty($this->rootDir&& ($arr_path explode(_OCSP_DIRSEP_,$this->rootDir)))
  256.         {
  257.             if (sizeof($arr_path))
  258.             {
  259.                 $this->rootDir = "";
  260.                 foreach($arr_path as $str_dir)
  261.                 {
  262.                     $str_dir trim($str_dir);
  263.                     if (!empty($str_dir))
  264.                     {
  265.                         $str_ret .= $str_dir _OCSP_DIRSEP_;
  266.                         $this->rootDir .= $str_dir _OCSP_DIRSEP_;
  267.                     }
  268.                 }     
  269.             }            
  270.         }
  271.                 
  272.         if ($debugechoDebugLine(__FILE__,__LINE__,"RootPath$str_ret");
  273.  
  274.         return $str_ret;        
  275.     }
  276.     
  277.     /**
  278.      * returns the root dir (without base path)
  279.      *
  280.      * @return string 
  281.      */
  282.     public function getRootDir()
  283.     {
  284.         return str_replace($this->getBasePath(),"",$this->rootDir);
  285.     }
  286.     
  287.     /**
  288.      * sets the root dir
  289.      *
  290.      * @param string $aRootDir 
  291.      * @param boolean $debug 
  292.      */
  293.     public function setRootDir($aRootDir,$debug=False)
  294.     {        
  295.         $this->rootDir = str_replace($this->getBasePath(),"",$aRootDir);
  296.     }
  297.     
  298.     /**
  299.      * returns the absolute default path
  300.      *
  301.      * @param boolean $debug 
  302.      * 
  303.      * @return string 
  304.      * 
  305.      * @version pk-08-05-18
  306.      */
  307.     protected function getDefaultPath($debug False)
  308.     {
  309.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getDefaultPath() [{$this->getName()}]");
  310.  
  311.         if (empty($this->defaultDir))
  312.         {
  313.             if ($debugechoDebugLine(__FILE__,__LINE__,"no default -> returning root path" );
  314.             return $this->getRootPath();
  315.         }
  316.         
  317.         if (empty($this->rootDir))
  318.         {
  319.             $str_ret $this->getBasePath();            
  320.         else {
  321.             $str_ret $this->getRootPath();
  322.         }
  323.  
  324.         $arr_default explode(_OCSP_DIRSEP_,$this->defaultDir);
  325.         $str_default "";
  326.         foreach($arr_default as $str_dir)
  327.         {
  328.             if (!empty($str_dir))
  329.             {                
  330.                 if (strstr($str_ret,$str_dir))
  331.                 {
  332.                     if (pcf_is_dir($str_ret.$str_default.$str_dir))
  333.                     {
  334.                         $str_default .= $str_dir _OCSP_DIRSEP_;
  335.                     }
  336.                 else {
  337.                     $str_default .= $str_dir _OCSP_DIRSEP_;
  338.                 }
  339.             }
  340.         }
  341.         
  342.         $str_ret .= $str_default;
  343.         
  344.         
  345.         if ($debugechoDebugLine(__FILE__,__LINE__,"DefaultPath: {$str_ret}");
  346.         
  347.         return $str_ret;
  348.     }
  349.         
  350.     /**
  351.       * extracts the directory from the value
  352.       * use this to avoid errors if $aValue is a directory in this case basename will return the parent dir.
  353.       *
  354.       * @param string $aValue 
  355.       * @param boolean $debug 
  356.       *
  357.       * @global OCSP_CONF 
  358.       *
  359.       * @returns string
  360.       *
  361.       * @access public
  362.       * @version pk-08-06-10
  363.       */
  364.     public function getDirFromValue($aValue,$debug=False{          
  365.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getDirFromValue($aValue)");
  366.                 
  367.         $str_basePath $this->getBasePath();
  368.         $str_rootPath $this->getRootPath($debug)// also fixes $this->rootDir
  369.            
  370.           if ($debugechoDebugLine(__FILE__,__LINE__,"basePath: " $str_basePath "<br />rootPath: " $str_rootPath);
  371.         
  372.         if (empty($aValue|| ($aValue == _OCSP_DIRSEP_))
  373.            {
  374.                $str_defaultPath $this->getDefaultPath($debug);
  375.                if ($debugechoDebugLine(__FILE__,__LINE__,"returning default path:" str_replace($str_rootPath,"",$str_defaultPath));
  376.                return str_replace($str_rootPath,"",$str_defaultPath);
  377.            }
  378.  
  379.            // <pk-08-06-10>
  380.           $str_fileName pcf_checkFilePath($this->getBasePath(_OCSP_DIRSEP_  $aValue);
  381.         if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  382.         if (pcf_is_file($str_fileName))
  383.         {
  384.             $str_ret pcf_checkDirName(str_replace($str_rootPath,"",dirname($str_fileName)) _OCSP_DIRSEP_,True;
  385.             return $str_ret;
  386.         }
  387.         if (pcf_is_dir($str_fileName))
  388.         {
  389.             $str_ret pcf_checkDirName(str_replace($str_rootPath,"",$str_fileName_OCSP_DIRSEP_,True;
  390.             return $str_ret;            
  391.         }
  392.                     
  393.         $str_fileName pcf_checkFilePath($this->getRootPath(_OCSP_DIRSEP_  $str_fileName);
  394.            if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  395.         if (pcf_is_file($str_fileName))
  396.         {
  397.             $str_ret pcf_checkDirName(str_replace($str_rootPath,"",dirname($str_fileName)) _OCSP_DIRSEP_,True;
  398.             return $str_ret;
  399.         }           
  400.         if (pcf_is_dir($str_fileName))
  401.         {
  402.             $str_ret pcf_checkDirName(str_replace($str_rootPath,"",$str_fileName_OCSP_DIRSEP_,True;
  403.             return $str_ret;            
  404.         }          
  405.            
  406.            // </pk-08-06-10>
  407.             
  408.            
  409.            $str_filePath "";
  410.            if ($arr_path=explode(_OCSP_DIRSEP_,$aValue))
  411.            {
  412.                foreach($arr_path as $str_dir)
  413.                {
  414.                    if (!empty($str_dir))
  415.                    {
  416.                        $str_filePath .= $str_dir _OCSP_DIRSEP_;
  417.                    }
  418.                }
  419.            }
  420.            
  421.            $str_filePath substr($str_filePath,0,-1);
  422.            
  423.            $str_ret "";
  424.            
  425.         if (pcf_is_dir($str_basePath $str_filePath)) {
  426.                $str_ret str_replace($str_rootPath,"",$str_basePath $str_filePath _OCSP_DIRSEP_);
  427.            else if (pcf_is_file($str_basePath $str_filePath)) {
  428.                $str_ret str_replace($str_rootPath,"",dirname($str_basePath $str_filePath_OCSP_DIRSEP_);
  429.            else if (pcf_is_dir($str_rootPath $str_filePath)) {
  430.                $str_ret $str_filePath _OCSP_DIRSEP_;
  431.            else if (pcf_is_file($str_rootPath $str_filePath)) {
  432.                $str_ret dirname($str_filePath_OCSP_DIRSEP_;
  433.            else if (strstr($str_filePath,$str_rootPath)) {
  434.                if (pcf_is_file($str_filePath))
  435.                {
  436.                    $str_ret str_replace($str_rootPath,"",dirname($str_filePath_OCSP_DIRSEP_)
  437.                else if (pcf_is_dir($str_filePath)) {
  438.                    $str_ret str_replace($str_rootPath,"",$str_filePath _OCSP_DIRSEP_);
  439.                }         
  440.            
  441.                       
  442.         if ($debugechoDebugLine(__FILE__,__LINE__,"Returning: " $str_ret);                      
  443.            
  444.            return $str_ret;
  445.     }
  446.     
  447.     /**
  448.      * returns an array with all values for the directory select box
  449.      *
  450.      * @param string $subPath (use $this->getDirFromValue() to get it)
  451.      * @param boolean $debug 
  452.      * 
  453.      * @return array 
  454.      */
  455.     protected function getDirSelectValues($subPath,$debug=False)
  456.     {              
  457.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getDirSelectValues()",$subPath);
  458.         
  459.         $str_curValue "";
  460.         $arr_ret array($str_curValue => "/");
  461.         $str_sep "__  ";
  462.                 
  463.         if ($arr_dirs explode(_OCSP_DIRSEP_,$subPath))
  464.         {
  465.             foreach($arr_dirs as $str_dir)
  466.             {
  467.                 if (!empty($str_dir&& ($str_dir != "CVS"))
  468.                 {
  469.                     $str_curValue .= $str_dir _OCSP_DIRSEP_;
  470.                     $arr_ret[$str_curValue$str_sep "/" $str_dir;
  471.                     $str_sep trim($str_sep"__  ";
  472.                 }
  473.             }
  474.         }
  475.         
  476.         if ($arr_subDirs pcf_getDirList($this->getRootPath($str_curValue,"D"))
  477.         {
  478.             foreach($arr_subDirs as $str_dir)
  479.             {
  480.                 if (!empty($str_dir&& ($str_dir != "CVS"))
  481.                 {
  482.                     $arr_ret[$str_curValue $str_dir _OCSP_DIRSEP_$str_sep "/" $str_dir;
  483.                 }                
  484.             }
  485.         }
  486.         
  487.         if ($debugechoDebugLine(__FILE__,__LINE__,"Returning: <pre>" print_r($arr_ret,True."</pre>");
  488.         return $arr_ret;
  489.         
  490.     }
  491.             
  492.     // --------------------------------------------------------
  493.     // file method
  494.     // --------------------------------------------------------
  495.     
  496.     /**
  497.       * returns the absoulte path to the file
  498.       *
  499.       * @param string $fileName 
  500.       * @param boolean $debug 
  501.       *
  502.       * @return string 
  503.       *
  504.       * @since pk-06-10-02
  505.       * @version pk-08-06-10
  506.       */
  507.     public function getFilePath($fileName,$debug=False{
  508.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getFilePath($fileName)","Name: ".$this->myName."\nrootPath:".$this->getRootPath()."\nrootDir:".$this->rootDir);  
  509.                 
  510.         if (!empty($fileName)) {
  511.  
  512.             $str_fileName pcf_checkFilePath($this->getBasePath(_OCSP_DIRSEP_  $fileName);
  513.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  514.             if (pcf_is_file($str_fileName))
  515.             {
  516.                 return $str_fileName;
  517.             }
  518.             
  519.             $str_fileName pcf_checkFilePath($this->getRootPath(_OCSP_DIRSEP_  $fileName);
  520.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  521.             if (pcf_is_file($str_fileName))
  522.             {
  523.                 return $str_fileName;
  524.             }
  525.             
  526.             if (!empty($this->defaultDir))
  527.             {
  528.                 $str_fileName pcf_checkFilePath($this->getBasePath(_OCSP_DIRSEP_ $this->defaultDir . _OCSP_DIRSEP_ $fileName);
  529.                 if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  530.                 if (pcf_is_file($str_fileName))
  531.                 {
  532.                     return $str_fileName;
  533.                 }
  534.                 
  535.                 $str_fileName pcf_checkFilePath($this->getRootPath(_OCSP_DIRSEP_ $this->defaultDir . _OCSP_DIRSEP_ $fileName);
  536.                 if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  537.                 if (pcf_is_file($str_fileName))
  538.                 {
  539.                     return $str_fileName;
  540.                 }
  541.                 
  542.             }
  543.             
  544.             $str_fileName pcf_checkFilePath($fileName);
  545.             if ($debugechoDebugLine(__FILE__,__LINE__,"\$str_fileName=" $str_fileName);
  546.             if (pcf_is_file($str_fileName))
  547.             {
  548.                 if (strstr($str_fileName,$this->getBasePath()))
  549.                 {
  550.                     return $str_fileName;
  551.                 }
  552.             }
  553.             
  554.             $fileName=str_replace($this->getRootPath(),"",$fileName)// <pk-06-11-20 />
  555.             $fileName=str_replace($this->rootDir,"",$fileName)// <pk-06-10-07 />
  556.             if (($fileName[0]=='/'|| ($fileName[0]=="\\")) $fileName=substr($fileName,1);
  557.             
  558.             if (file_exists($this->getRootPath().$fileName)) {
  559.                 if ($debugechoDebugLine(__FILE__,__LINE__,"Returning: ".$this->getRootPath().$fileName);
  560.                 return $this->getRootPath().$fileName;
  561.             else if (!empty($this->defaultDir)) {
  562.                 $c_lastChar=substr($this->defaultDir,-1);
  563.                 if (($c_lastChar == '/'|| ($c_lastChar == "\\")) $this->defaultDir=substr($this->defaultDir,0,-1);
  564.                 $this->defaultDir.=_OCSP_DIRSEP_;
  565.                 
  566.                 if (file_exists($this->getRootPath().$this->defaultDir.$fileName))
  567.                 {
  568.                     if ($debugechoDebugLine(__FILE__,__LINE__,"Returning: ".$this->getRootPath().$this->defaultDir.$fileName);
  569.                     return $this->getRootPath().$this->defaultDir.$fileName;
  570.                 }    
  571.  
  572.                 if (file_exists($this->getRootPath().$this->rootDir.$this->defaultDir.$fileName))
  573.                 {
  574.                     if ($debugechoDebugLine(__FILE__,__LINE__,"Returning: ".$this->getRootPath().$this->rootDir.$this->defaultDir.$fileName);
  575.                     return $this->getRootPath().$this->rootDir.$this->defaultDir.$fileName;
  576.                 }    
  577.                                 
  578.             }
  579.         }
  580.         return str_replace("//","/",$this->getRootPath()."/");
  581.     }    
  582.     
  583.     /**
  584.       * sets (populates) $this->myValues array from the database
  585.       *
  586.       * @param string $arrName 
  587.       * @param bool $debug 
  588.       * 
  589.       * @global string ${$arrName} 
  590.       *
  591.       * @since pk-08-05-19
  592.       */
  593.     public function setMyValues($arrName="DBVAL",$debug=False
  594.     {       
  595.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FIELSELECT::setMyValues() [" $this->myName ."]");
  596.         global ${$this->myDataArrName};
  597.         
  598.         $str_rootPath $this->getRootPath();
  599.         
  600.         if (isset(${$arrName}[$this->myName]))
  601.         {
  602.             $str_path $str_rootPath.$this->getDirFromValue(${$arrName}[$this->myName]);
  603.         else if (isset($_POST[$this->getJsName().'_DIRSEL'])) {
  604.             $str_path $str_rootPath.$this->getDirFromValue($_POST[$this->getJsName().'_DIRSEL']);
  605.         else {
  606.             $str_path $this->getDefaultPath($debug);        
  607.         }
  608.                         
  609.         $arr_files pcf_getDirList($str_path,"F");
  610.         
  611.         if ($debugechoDebugLine(__FILE__,__LINE__,"Path: " $str_path "<pre>" print_r($arr_files,True"</pre>");
  612.         
  613.         $this->myValues = array();
  614.         if (sizeof($arr_files))
  615.         {
  616.             $str_valPath str_replace($this->getBasePath(),"",$str_path);
  617.             if (substr($str_valPath,-1!= "/"$str_valPath.= "/";
  618.             
  619.             if (!empty($this->extfilter))
  620.             {
  621.                 $arr_extensions explode(',',$this->extfilter);
  622.                 $bol_doFilter (sizeof($arr_extensionsTrue False);
  623.             else {
  624.                 $bol_doFilter False;
  625.             }
  626.             
  627.             foreach($arr_files as $str_file)
  628.             {
  629.                 if ($bol_doFilter)
  630.                 {
  631.                     while (list($str_exteach($arr_extensions)) {
  632.                         if (substr($str_file,(strlen($str_ext* -1)) == $str_ext)
  633.                         {
  634.                             $this->myValues[$str_valPath $str_file$str_file;
  635.                             break// exit the while loop
  636.                         }
  637.                     }
  638.                 else {
  639.                     $this->myValues[pcf_checkFilePath($str_valPath $str_file,"/")$str_file;
  640.                 }
  641.             }
  642.         }
  643.         
  644.         return $this->myValues;
  645.     }
  646.     
  647.    /**
  648.      * returns the value of the uploaded file
  649.      *
  650.      * @param array $uplFile 
  651.      * @param string $path 
  652.      * @param boolean $debug 
  653.      * 
  654.      * @return string value to set or Null on error
  655.      */
  656.     public function uploadFile($uplFile,$path="",$debug=False)
  657.     {
  658.         if (isset($uplFile['error']&& !empty($uplFile['error']))
  659.         {
  660.             $this->setErrorMsg($uplFile['error'],True);
  661.             return Null;
  662.         }                        
  663.         
  664.         if ($this->userCanUpload())
  665.         {
  666.             if (intval($this->maxSize&& (intval($uplFile['size']$this->getMaxFileSizeBytes())) 
  667.             {
  668.                 $this->setErrorMsg($uplFile['name'" is to large max  " $this->maxSize . " kB",True);
  669.                 return Null;    
  670.             }            
  671.             
  672.             $str_curDir $this->getDirFromValue($path,$debug);
  673.             $str_path $this->getRootPath($str_curDir;                
  674.                 
  675.             $str_fileName pcf_checkFileName($uplFile['name'])
  676.                if (!$this->userCanOverwrite())
  677.                {
  678.                    $arr_name=explode(".",$str_fileName,2);
  679.                    $int_idx=0;
  680.                    while (file_exists($str_path $str_fileName))
  681.                    {
  682.                        $str_fileName $arr_name[0].'_'.sprintf("%03d",$int_idx++).".".$arr_name[1];                            
  683.                    }
  684.                }    
  685.                    
  686.                $str_file pcf_checkFilePath($str_path _OCSP_DIRSEP_ $str_fileName,_OCSP_DIRSEP_);
  687.              if ((move_uploaded_file($uplFile['tmp_name']$str_file))) 
  688.                {
  689.                    return str_replace($this->getBasePath(),"",$str_file);
  690.                else {
  691.                 $this->setErrorMsg('Could not write File ' str_replace($this->getBasePath(),"",$str_file));                           
  692.                    return Null;
  693.                }                    
  694.         else {
  695.             return Null;
  696.         }
  697.     }
  698.     
  699.     
  700.     // --------------------------------------------------------
  701.     // jOCSP
  702.     // --------------------------------------------------------
  703.  
  704.     /**
  705.      * returns an array of jOCSP/jQuery Modules which are required
  706.      * 
  707.      * $arr_ret[]="script url";
  708.      *
  709.      * @param boolean $debug 
  710.      * 
  711.      * @global array $OCSP_CONF 
  712.      * 
  713.      * @return string 
  714.      */
  715.     public function jOCSP_getRequiredModules($debug=FALSE)
  716.     {        
  717.         if ($debugechoDebugMethod(__FILE__,get_classe($this),"DBMS_FIELD::jOCSP_getRequiredModules()");
  718.         
  719.         $arr_ret parent::jOCSP_getRequiredModules($debug);
  720.         $arr_ret[array(
  721.             'CLASS'    => 'jOCSP.FLDOBJ_FileSelectList',
  722.             'SRC'     => OCSP_OBJ::getConf('SYSTEMURL')."jOCSP/formFields/jOCSP_FLDOBJ_FileSelectList.js"
  723.         );
  724.                
  725.         return $arr_ret;
  726.     }
  727.  
  728.    /**
  729.      * returns additional object elements of the field object
  730.      * 
  731.      * array definition: [elemName] = value
  732.      * 
  733.      * NOTE: do not js_escapte value this is done when building the json object
  734.      *
  735.      * @param boolean $debug 
  736.      * 
  737.      * @return array 
  738.      * 
  739.      * @since pk-08-02-06
  740.      */
  741.     protected function jOCSP_getAdditonalFieldObjElems($debug=False)
  742.     {  
  743.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECT::jOCSP_getAdditonalFieldObjElems()");
  744.         $arr_ret parent::jOCSP_getAdditonalFieldObjElems($debug);        
  745.         $arr_ret['fldClass'"'FLDOBJ_FileSelectList'";        
  746.         //$arr_ret['debug'] = True;
  747.         
  748.         if ($this->userCanDownload())
  749.         {            
  750.             $str_cmd  "if (obj_dwnlA = document.getElementById('" .$this->getDOMId()  "_DOWNLOADHREF')) {";
  751.             $str_cmd .= "obj_dwnlA.href='" $this->getDownloadUrl("""&value=escape(newValue)';";
  752.             $str_cmd .= "}";
  753.             
  754.             $arr_ret['onchange'"function(newValue) {" $str_cmd "}";
  755.         }
  756.         
  757.         return $arr_ret;          
  758.     }
  759.     
  760.     /**
  761.      * change the directory
  762.      *
  763.      * @param array $request 
  764.      * @param boolean $debug 
  765.      * 
  766.      * @return string (js)
  767.      */
  768.     public function jOCSP_setDir($request,$debug)
  769.     {
  770.         if ($this->userCanMkDir($debug))
  771.         {
  772.     
  773.             $str_ret "
  774.                 if (obj_field = document.getElementById('" $this->getDirSelNameId("'))
  775.                 {
  776.                     obj_field.options.length=0;                    
  777.                     int_idx = 0;
  778.                 ";
  779.             
  780.             if (($request[$this->getDirSelNameId()== _OCSP_DIRSEP_|| empty($request[$this->getDirSelNameId()]))
  781.             {
  782.                 $str_curDir "";
  783.             else {
  784.                 $str_value str_replace($this->getBasePath(),"",$this->getRootPath($request[$this->getDirSelNameId()]);
  785.                  $str_curDir  $this->getDirFromValue($str_value,$debug);
  786.             }
  787.            
  788.             $arr_options $this->getDirSelectValues($str_curDir);
  789.             
  790.             if ($debugpcf_js_alert($request[$this->getDirSelNameId()"\n" $str_curDir "\n" print_r($arr_options,True));
  791.             
  792.             if (substr($str_curDir,0,1== '/')
  793.             {
  794.                 $str_curDir substr($str_curDir,1);
  795.             }
  796.  
  797.             foreach($arr_options as $str_value => $str_label)
  798.             {
  799.                 $str_label str_replace("&nbsp;"," ",$str_label);
  800.                 $str_selected (($str_value == $str_curDir'true' 'false')
  801.                 $str_ret .= "obj_field.options[int_idx++] = new Option('{$str_label}','{$str_value}',{$str_selected},{$str_selected});\n";                
  802.             }
  803.                                 
  804.             $str_ret .= ";                    
  805.                 }
  806.             ";
  807.             
  808.             $str_ret .= $this->jOCSP_reloadFileList($request,$debug);
  809.             
  810.             return $str_ret;
  811.             
  812.         else {
  813.             pcf_js_alert('Verzeichnis kann nicht gewechselt werden');
  814.         }
  815.     }
  816.     
  817.    /**
  818.      * change the directory
  819.      *
  820.      * @param array $request 
  821.      * @param boolean $debug 
  822.      * 
  823.      * @return string (js)
  824.      */
  825.     public function jOCSP_addDir($request,$debug=False)
  826.     {
  827.         if (isset($_GET['newDirName']&& !empty($_GET['newDirName']))
  828.         {
  829.             $str_value str_replace($this->getBasePath(),"",$this->getRootPath($request[$this->getDirSelNameId()]);
  830.             $str_curDir $this->getDirFromValue($str_value,$debug);
  831.             $str_path $this->getRootPath($str_curDir;
  832.  
  833.             $str_path .= pcf_checkFileName($_GET['newDirName']);
  834.             
  835.             //pcf_js_alert('Path: ' . $str_path . "\n" . basename(__FILE__) . " L: " . __LINE__);            
  836.             if (pcf_checkDir(str_replace("/",_OCSP_DIRSEP_,$str_path),True))
  837.             {
  838.                 $request[$this->getDirSelNameId()str_replace($this->getBasePath(),"",$str_path);
  839.                 return $this->jOCSP_setDir($request,$debug);
  840.             else {
  841.                 pcf_js_alert("Konnte Verzeichns: " $_GET['newDirName'." nicht anlegen");
  842.             }
  843.         }
  844.     }
  845.     
  846.    /**
  847.      * reloads the file list
  848.      *
  849.      * @param array $request 
  850.      * @param boolean $debug 
  851.      * 
  852.      * @global array ${$this->myDataArrName}; 
  853.      * 
  854.      * @return string (js)
  855.      */
  856.     public function jOCSP_reloadFileList($request,$debug)
  857.     {
  858.         global ${$this->myDataArrName};
  859.         
  860.         $str_value str_replace($this->getBasePath(),"",$this->getRootPath($request[$this->getDirSelNameId()]);        
  861.         $str_curDir $this->getDirFromValue($str_value,$debug);
  862.         $str_path str_replace($this->getBasePath(),"",$this->getRootPath($str_curDir)
  863.         
  864.         $str_oriValue = ${$this->myDataArrName}[$this->getName()];
  865.         ${$this->myDataArrName}[$this->getName()$str_path;
  866.         $this->setMyValues($this->myDataArrName,$debug);
  867.  
  868.         $str_ret "
  869.             if (obj_field = document.getElementById('" $this->getDOMId("'))
  870.             {
  871.                 obj_field.options.length=0;                    
  872.                 int_idx = 0;
  873.                 
  874.             ";
  875.         
  876.         if (sizeof($this->myValues))
  877.         {
  878.             $str_ret .= "obj_field.options[int_idx++] = new Option('---Datei wählen---','" $str_path "',false,false);\n";
  879.             foreach($this->myValues as $str_filePath => $str_name)
  880.             {
  881.                 if ($str_name == basename($str_oriValue))
  882.                 {
  883.                     $str_ret .= "obj_field.options[int_idx++] = new Option('" $str_name "','" $str_filePath "',true,true);\n";                    
  884.                 else {
  885.                     $str_ret .= "obj_field.options[int_idx++] = new Option('" $str_name "','" $str_filePath "',false,false);\n";                    
  886.                    }
  887.             }
  888.         else {
  889.             $str_ret .= "obj_field.options[int_idx++] = new Option('[keine Dateien gefunden]','',false,false);\n";
  890.         }
  891.         
  892.         $str_ret .="} else {alert('Feld nicht gefunden');}";
  893.         return $str_ret;
  894.         
  895.     }
  896.     
  897.    /**
  898.      * uploads a file
  899.      *
  900.      * @param array $request
  901.      * @param boolean $debug
  902.      * 
  903.      * @global array ${$this->myDataArrName};
  904.      * 
  905.      * @return string (js)
  906.      * 
  907.      * @version pk-08-06-10
  908.      */
  909.     public function jOCSP_uploadFile($request,$debug=False)
  910.     {
  911.         $str_ret "";
  912.                 
  913.         if ($arr_upload $_FILES[$this->getDOMId('_upload'])
  914.         {
  915.             $str_value $request[$this->getDirSelNameId()];
  916.             $str_curDir $this->getDirFromValue($str_value,$debug);
  917.             if ($str_value=$this->uploadFile($arr_upload,$str_curDir))
  918.             {
  919.                    $str_ret .= "
  920.                        if (dom_field = parent.document.getElementById('" $this->getDOMId("'))
  921.                        {
  922.                            try {                           
  923.                                dom_field.options[dom_field.options.length]=new Option('" basename($str_value"','" $str_value "',true,true);                           
  924.                                dom_field.value='" $str_value "';
  925.  
  926.                                obj_field = dom_field.jOCSPFldObj
  927.                                obj_domForm = obj_field.myForm.getDomObj();
  928.                                obj_domForm.target=obj_field.uploadOri.target;
  929.                                obj_domForm.action=obj_field.uploadOri.action;
  930.                                if (obj_field.uploadOri.encoding)
  931.                                {
  932.                                    obj_domForm.encoding = obj_field.uploadOri.encoding;
  933.                                } else {
  934.                                    obj_domForm.enctype = obj_field.uploadOri.enctype;
  935.                                }
  936.                                
  937.                                parent.document.getElementById('" $this->getDOMId(."_upload').value='';
  938.                            } catch(e) {
  939.                                alert('" basename(__FILE__" L: " . __LINE__ . ": ' + dom_field.id + '\\n' + e );                               
  940.                            }
  941.                            
  942.                        } else {
  943.                            alert('Feld nicht gefunden');
  944.                        }
  945.                    ";
  946.             else {
  947.                 $str_ret .= "alert('" .pcf_js_escape($this->getErrorMsg()) "');";        
  948.             }
  949.         }
  950.                 
  951.         return $str_ret;
  952.     }
  953.     
  954.     
  955.     // --------------------------------------------------------
  956.     // html form output
  957.     // --------------------------------------------------------
  958.  
  959.     /**
  960.       * returns the html code for the directory select
  961.       *
  962.       * @param string $aValue
  963.       * @param boolean $debug
  964.       *
  965.       * @returns string (html)
  966.       *
  967.       * @since pk-07-03-01
  968.       * @version pk-08-05-18
  969.       *
  970.       * @access protected
  971.       *
  972.       */
  973.     function getDirSelectTag($aValue,$debug=False
  974.     {        
  975.         $debug=($debug || $this->fldDebug);       
  976.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getInputTag()","Value: ".$aValue);
  977.  
  978.         $str_ret "<div class=\"dbms_fldFielSel_dirOuter\" style=\"float:left;display:block;\">";
  979.         $str_debug    "";
  980.         
  981.         if ($this->allow_cd)
  982.         {
  983.             //
  984.             // js ------------------------------ 
  985.             //
  986.             
  987.             $str_jsReload="
  988.                 if (obj_form = jOCSP.getFormByHash('" $this->myControll->jOCSP_getfrmHash("')) 
  989.                 {
  990.                     if (obj_field = obj_form.getFieldByDomId('" $this->getDOMId("')) 
  991.                     {
  992.                         obj_field.setDir();
  993.                     } else { 
  994.                         alert('Feld nicht gefunden');
  995.                     }
  996.                 } else { 
  997.                     alert('Formular nicht gefunden');
  998.                 }            
  999.             ";
  1000.                         
  1001.             
  1002.             //
  1003.             // buttons ------------------------------ 
  1004.             //
  1005.             
  1006.             if ($this->getView()) // no ajax call
  1007.             {
  1008.                 $str_ret .= "<img 
  1009.                     src=\"" OCSP_OBJ::getConf('SYSIMGURL'"icons-16x16/reload.gif\"
  1010.                     class=\"button\" border=\"none\" style=\"margin-top:0px;float:right;\" alt=\"reload\" title=\"Verzeichnisliste neu einlesen\"
  1011.                     onClick=\"" $str_jsReload ";\" />";                 
  1012.             }            
  1013.             
  1014.             if ($this->userCanMkDir($debug))
  1015.             {
  1016.                 $str_ret .= "<img 
  1017.                     src=\"" OCSP_OBJ::getConf('SYSIMGURL'"icons-16x16/folder_new.gif\"
  1018.                     class=\"button\" border=\"none\" style=\"margin-top:0px;float:right;\" alt=\"folder_new\" title=\"neues Verzeichnis anlegen\"
  1019.                     onClick=\"
  1020.                         if (obj_form = jOCSP.getFormByHash('" $this->myControll->jOCSP_getfrmHash("')) 
  1021.                         {
  1022.                             if (obj_field = obj_form.getFieldByDomId('" $this->getDOMId("')) 
  1023.                             {
  1024.                                 obj_field.addDir();
  1025.                             } else { 
  1026.                                 alert('Feld nicht gefunden');
  1027.                             }
  1028.                         } else { 
  1029.                             alert('Formular nicht gefunden');
  1030.                         }                    
  1031.                     \"; />"
  1032.             }            
  1033.  
  1034.             //
  1035.             // select ------------------------------ 
  1036.             //
  1037.             
  1038.             $str_curDir  $this->getDirFromValue($aValue,$debug);
  1039.             $arr_options $this->getDirSelectValues($str_curDir);
  1040.             
  1041.             if ($debug$str_ret .= $str_curDir;
  1042.             
  1043.             $str_ret .= "<select name=\"" $this->getDirSelNameId(."\" id=\"" $this->getDirSelNameId(."\" onchange=\"" $str_jsReload "\">";
  1044.             
  1045.             foreach($arr_options as $str_val => $str_label)
  1046.             {
  1047.                 $str_ret .= "<option value=\"" $str_val "\" ";
  1048.                 if (($str_val == $str_curDir|| ("/".$str_val == $str_curDir))
  1049.                 {
  1050.                     $str_ret .= " selected=\"selected\"";
  1051.                 }
  1052.                 $str_ret .= ">" $str_label "</option>";                
  1053.             }
  1054.                         
  1055.             $str_ret .= "</select>";            
  1056.         else {
  1057.             $str_ret .= $this->getDirFromValue($aValue);
  1058.         }
  1059.     
  1060.         $str_ret .= "</div>";
  1061.         return $str_ret;
  1062.     }   
  1063.     
  1064.         
  1065.     /**
  1066.       * returns the html code for the select
  1067.       *
  1068.       * @param string $aValue
  1069.       * @param string $arrName (overwrites $this->myDataArrName if not empty)
  1070.       * @param boolean $debug
  1071.       *
  1072.       * @global ${$this->myDataArrName}
  1073.       * @global $OCSP_CONF
  1074.       *
  1075.       * @returns string (html)
  1076.       *
  1077.       * @version pk-04-08-18
  1078.       * @version pk-05-06-24
  1079.       *
  1080.       * @todo multiselect
  1081.       *
  1082.       **/
  1083.     function getInputTag($aValue,$arrName="",$debug=False
  1084.     {
  1085.         $debug=($debug || $this->fldDebug);
  1086.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getInputTag()","Value: ".$aValue);
  1087.             
  1088.         if (!empty($arrName)) $this->myDataArrName=$arrName;
  1089.  
  1090.         global ${$this->myDataArrName};
  1091.                
  1092.         if (substr($aValue,0,1)==_OCSP_DIRSEP_$aValue=substr($aValue,1);  // remove leading slash
  1093.         $str_ret="";
  1094.  
  1095.         if ($debug)
  1096.         {
  1097.             $str_ret.="<p>
  1098.                     BasePath: " $this->getBasePath("<br />
  1099.                     RootPath: " $this->getRootPath("<br />
  1100.                     FilePath: " $this->getFilePath($aValue"<br /> 
  1101.                 </p>";
  1102.         }
  1103.                 
  1104.         if ($this->allow_cd)
  1105.         {
  1106.             $str_ret.=$this->getDirSelectTag($aValue,$debug);
  1107.         }
  1108.         
  1109.         $str_ret .= "<div style=\"float:left;display:block;\">";
  1110.         
  1111.         if ($this->userCanDownload())
  1112.         {            
  1113.             if (empty($aValue))
  1114.             {
  1115.                 $str_dwnlUrl "javascript:{alert('keine Datei')}";
  1116.             else {
  1117.                 $str_dwnlUrl $this->getDownloadUrl($aValue);
  1118.             }
  1119.             $str_ret .= "
  1120.                 <div id=\"" $this->getDOMId()  "_DOWNLOAD\" style=\"float:right;display:block\">
  1121.                     <a id=\"" $this->getDOMId()  "_DOWNLOADHREF\"
  1122.                        href=\"" $this->getDownloadUrl($aValue"\"
  1123.                        target=\"_blank\"
  1124.                     >    
  1125.                         <img id=\"" $this->getDOMId()  "_DOWNLOADIMG\" 
  1126.                             src=\"" OCSP_OBJ::getConf('SYSIMGURL'"icons-16x16/document-save.gif\"
  1127.                             class=\"button\" border=\"none\" style=\"margin-top:0px;\" alt=\"download\" title=\"Datei herunterladen\"
  1128.                         />
  1129.                     </a>
  1130.                 </div>"
  1131.         }
  1132.         if ($this->userCanUpload($debug))
  1133.         {
  1134.             $str_ret .= "<div class=\"button\" style=\"float:right;display:block;width:16px;height:16px;overflow:hidden;margin-top:0px;\">" $this->getUploadBtn($arrName,$this->getDirFromValue($aValue,$debug),$debug."</div>";
  1135.         }           
  1136.         $str_ret .= parent::getInputTag($aValue,$arrName,$debug);              
  1137.         $str_ret .= "</div>";
  1138.  
  1139.         return $str_ret;
  1140.     }
  1141.     
  1142.     /**
  1143.       * returns the html code for the upload button
  1144.       *
  1145.       * @param string $arrName
  1146.       * @param string $curPath
  1147.       * @param boolean $debug
  1148.       *
  1149.       * @global $OCSP_CONF
  1150.       *
  1151.       * @returns string
  1152.       *
  1153.       * @since pk-06-11-19
  1154.       * @version pk-07-03-01
  1155.       * 
  1156.       * enctype="multipart/form-data" 
  1157.       */
  1158.     function getUploadBtn($arrName="DBVAL",$curPath="",$debug=False
  1159.     {         
  1160.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getUploadBtn()");
  1161.  
  1162.         if (!$this->userCanUpload($debug))
  1163.         {
  1164.             return "";
  1165.         }
  1166.         
  1167.         $str_ret "      
  1168.                 <div style=\"position: relative;width: 26px;height: 26px;overflow: hidden;margin:0px 0x 0px 70px;float:left;\">
  1169.                     <input 
  1170.                         name=\"" $this->getDOMId(."_upload\" type=\"file\"
  1171.                         id=\"" $this->getDOMId(."_upload\" 
  1172.                         onchange=\"
  1173.                             if (obj_form = jOCSP.getFormByHash('" $this->myControll->jOCSP_getfrmHash("')) 
  1174.                             {
  1175.                                 if (obj_field = obj_form.getFieldByDomId('" $this->getDOMId("')) 
  1176.                                 {
  1177.                                     obj_field.uploadFile();
  1178.                                 } else { 
  1179.                                     alert('Feld nicht gefunden');
  1180.                                 }
  1181.                             } else { 
  1182.                                 alert('Formular nicht gefunden');
  1183.                             }                    
  1184.                         \" 
  1185.                         title=\"Datei &uuml;bertragen\"
  1186.                         style=\"position: absolute;right: 0;font-size: 10px;cursor: pointer;opacity: 0; \" 
  1187.                     />
  1188.                     <div style=\"
  1189.                       background: transparent url(" OCSP_OBJ::getConf('SYSIMGURL'"icons-16x16/webexport.gif) no-repeat;
  1190.                         white-space: normal;width: 26px;height: 26px;
  1191.                     \"></div>
  1192.                 </div>
  1193.  
  1194.         ";        
  1195.         return $str_ret;
  1196.     }
  1197.     
  1198.     /**
  1199.      * returns the download url
  1200.      *
  1201.      * @param string $aValue
  1202.      * @param boolean $debug
  1203.      * 
  1204.      * @return string
  1205.      */
  1206.     public function getDownloadUrl($aValue="",$debug=False)
  1207.     {
  1208.            $arr_sec=array(
  1209.                  'PUBLIC'    => FALSE,
  1210.                'USER'      => OCSP_OBJ::currentUser()->getId()
  1211.            );
  1212.             
  1213.            $arr_fldKey array(
  1214.                'FRM_ID'     => $this->getFrmId(),
  1215.                'FLD_KEY'    => $this->getKey(),
  1216.            );
  1217.  
  1218.            $str_downlUrl OCSP_CONF::getInstance()->getValue('SYSTEMURL'"forms/fldFile_Download.php";
  1219.            $str_downlUrl.= "?SecReq=" OCSP_SESSION::getInstance()->encrypt(serialize($arr_sec));
  1220.         $str_downlUrl.= "&frmReq=" OCSP_SESSION::getInstance()->encrypt(serialize($arr_fldKey));            
  1221.         if (!empty($aValue))
  1222.         {
  1223.             $str_downlUrl.= "&value="  urlencode($aValue);
  1224.         }
  1225.         return $str_downlUrl;
  1226.     }
  1227.     
  1228.     /**
  1229.       * returns the html code for the download button
  1230.       *
  1231.       * @param string $filePath absoulte file
  1232.       * @param boolen $debug
  1233.       *
  1234.       * @global $OCSP_CONF
  1235.       *
  1236.       * @return string
  1237.       *
  1238.       * @since pk-06-10-02
  1239.       * @version pk-08-07-21
  1240.       */
  1241.     function getDownlBtn($aValue,$debug=False{
  1242.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getDownlBtn()",$this->myName);
  1243.  
  1244.         $str_ret "";
  1245.         if (!empty($aValue&& $this->userCanDownload())
  1246.         {
  1247.             $str_ret .= "
  1248.                 <a href=\"" $this->getDownloadUrl($aValue"\" target=\"_blank\">
  1249.                     <img 
  1250.                         src=\"" OCSP_CONF::getInstance()->getValue('SYSIMGURL'"icons-16x16/document-save.gif\"
  1251.                         alt=\"Datei herunterladen\"
  1252.                         class=\"button\" border=\"0\"
  1253.                     />
  1254.                 </a>
  1255.                 ";            
  1256.         }
  1257.         
  1258.         return $str_ret;
  1259.  
  1260.     }    
  1261.     
  1262.     // --------------------------------------------------------
  1263.     // data validation
  1264.     // --------------------------------------------------------
  1265.     
  1266.     
  1267.     /**
  1268.       * returns the field value if its an array,
  1269.       * it is imploded with \n as seperator
  1270.       *
  1271.       * @param  string  $aValue     the value
  1272.       * @param  array   $err        error array
  1273.       * @param  string  $arrName    name of the array to access fieldsarray  gloabl ${$arrName}
  1274.       * @param  bool    $debug
  1275.       *
  1276.       * @global $OCSP_CONF
  1277.       *
  1278.       * @return string
  1279.       *
  1280.       * @version pk-04-08-19
  1281.       * @version pk-05-06-24
  1282.       * @version pk-06-11-15
  1283.       * @version pk-08-05-19
  1284.       */
  1285.     function getValue($aValue,&$err,$arrName="DBVAL",$debug=False{
  1286.         
  1287.         $debug=($debug || $this->fldDebug || $this->fldDbgGetValue);
  1288.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getValue()",print_r($aValue,True));
  1289.  
  1290.         if (!empty($aValue)) {
  1291.             $aValue=pcf_checkFilePath($aValue,"/");
  1292.             
  1293.             $str_file $this->getFilePath($aValue);
  1294.             if (pcf_is_file($str_file))
  1295.             {
  1296.                 return str_replace($this->getBasePath(),_OCSP_DIRSEP_,$str_file);
  1297.             }
  1298.             
  1299.             
  1300.             $str_file pcf_checkFilePath($this->getBasePath($aValue);
  1301.             if (pcf_is_file($str_file))
  1302.             {
  1303.                 return $aValue;
  1304.             }
  1305.             
  1306.             $str_file pcf_checkFilePath($this->getRootPath($aValue);
  1307.             if (pcf_is_file($str_file))
  1308.             {
  1309.                 return str_replace($this->getBasePath(),"",$str_file);
  1310.             }
  1311.             
  1312.             
  1313.             $str_curDir $this->getDirFromValue($aValue,$debug);
  1314.             $str_path $this->getRootPath($str_curDir;
  1315.  
  1316.             $str_filePath   $str_path "/" basename(trim($aValue));
  1317.             $str_dbVal      str_replace($this->getBasePath(),"",$str_filePath);
  1318.             
  1319.             if (_OCSP_DIRSEP_ != '/')
  1320.             {
  1321.                 $str_filePath str_replace('/',_OCSP_DIRSEP_,$str_filePath);
  1322.             }
  1323.             
  1324.             if ($debugpcf_js_alert('File: $str_filePath');
  1325.  
  1326.             if (is_file($str_filePath|| is_link($str_filePath|| $this->getValue_nochk)
  1327.             {
  1328.                 return $str_dbVal;
  1329.             }
  1330.  
  1331.             $str_debug "\n\n\nValue: "  .$aValue;
  1332.             $str_debug.= "\ncurDir: " $str_curDir;
  1333.             $str_debug.= "\npath:"    $str_path;
  1334.             $str_debug.= "\nrootDir:" $this->rootDir;
  1335.             $str_debug.= "\nrootPath:" $this->getRootPath();
  1336.                         
  1337.             $err['ERROR']=True;
  1338.             $err[$this->myName]['MSG']t_admin("Datei"":{$str_dbVal}t_admin("nicht gefunden"nl2br($str_debug);
  1339.             
  1340.             $err[$this->myName]['LABEL']=$this->label;
  1341.             return $str_dbVal;
  1342.  
  1343.         else {
  1344.             // check null value
  1345.             return parent::getValue($aValue,$err,$arrName,$debug);
  1346.         }
  1347.     }
  1348.     
  1349.     // --------------------------------------------------------
  1350.     // user rights
  1351.     // --------------------------------------------------------
  1352.     
  1353.     /**
  1354.       * checks if the current user is member of $this->downlGrp
  1355.       *
  1356.       * @param boolean $debug
  1357.       *
  1358.       * @return boolean
  1359.       *
  1360.       * @version pk-08-07-21
  1361.       */
  1362.     public function userCanDownload($debug=False{
  1363.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::userCanDownload()",$this->myName);
  1364.         return OCSP_OBJ::currentUser()->isGroupMember($this->downlGrp);
  1365.     }
  1366.  
  1367.     /**
  1368.       * checks if the current user is member of $this->downlGrp
  1369.       *
  1370.       * @param boolean $debug
  1371.       *
  1372.       * @return boolean
  1373.       *
  1374.       */
  1375.     public function userCanUpload($debug=False{
  1376.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::userCanUpload() [".$this->myName."]",($this->allow_upload "True" "False"));
  1377.         return $this->allow_upload;
  1378.     }
  1379.     
  1380.     /**
  1381.      * checks if the current user can create a new directory
  1382.      * 
  1383.      * @param boolean $debug
  1384.      * 
  1385.      * @return boolean
  1386.      * 
  1387.      * @since pk-08-07-21
  1388.      */
  1389.     public function userCanMkDir($debug=False)
  1390.     {
  1391.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::userCanMkDir() [".$this->myName."]");
  1392.         if ($this->userCanUpload($debug))
  1393.         {
  1394.             return $this->allow_mkdir;
  1395.         else {
  1396.             return False;
  1397.         }
  1398.     }
  1399.     
  1400.     /**
  1401.      * checks if the current user can overwrite an existing file
  1402.      * 
  1403.      * @param boolean $debug
  1404.      * 
  1405.      * @return boolean
  1406.      * 
  1407.      * @since pk-07-11-04
  1408.      */
  1409.      public function userCanOverwrite($debug=False)
  1410.      {
  1411.          if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::userCanOverwrite() [$this->getKey()");
  1412.          if ($this->userCanUpload($debug))
  1413.          {
  1414.             return $this->allow_overwrite;        
  1415.          }
  1416.      }    
  1417.     
  1418.     
  1419.     
  1420.     
  1421.     
  1422.     
  1423.     
  1424.     
  1425.     
  1426.     
  1427.     
  1428.     // -------------------------------------------------------------
  1429.     // -------------------------------------------------------------
  1430.     // old version    
  1431.     // -------------------------------------------------------------
  1432.     // -------------------------------------------------------------
  1433.     
  1434.     
  1435.     
  1436.     // ###########################################################
  1437.     // OBJECT (CONST) VAR DECLARATION
  1438.     // ###########################################################
  1439.  
  1440.     
  1441.  
  1442.     
  1443.  
  1444.  
  1445.     /**
  1446.       * @var boolean $allow_upload
  1447.       */
  1448.     protected $allow_upload    True;
  1449.  
  1450.     /**
  1451.       * @var boolean $allow_edit
  1452.       */
  1453.     protected $allow_edit      True;
  1454.  
  1455.     /**
  1456.       * @var boolean $allow_overwrite
  1457.       */
  1458.     protected $allow_overwrite False;
  1459.  
  1460.     /**
  1461.       * @var strint $editorUrl
  1462.       */
  1463.     protected $editorUrl       "/ocsp-system/forms/fldFile_Edit.php";
  1464.  
  1465.     /**
  1466.       * @var string $downloadUrl url to open with download (save) button
  1467.       * @since pk-06-10-02
  1468.       **/
  1469.     protected $downloadUrl     "/ocsp-system/forms/fldFile_Download.php";
  1470.  
  1471.     /**
  1472.       * @var int $dwnlGrp group which is allowed to download the file
  1473.       * @since pk-06-10-02
  1474.       **/
  1475.     protected $downlGrp        0;
  1476.  
  1477.     /**
  1478.       * @var boolean $htmlValWithRoot
  1479.       */
  1480.     protected $htmlValWithRoot False;
  1481.     
  1482.  
  1483.     
  1484.     // ###########################################################
  1485.     // OBJECT SETTINGS METHODS
  1486.     // ###########################################################
  1487.  
  1488.  
  1489.     
  1490.  
  1491.  
  1492.      
  1493.      
  1494.     // ###########################################################
  1495.     // FIELD DEFINITION DATA METHODS
  1496.     // ###########################################################
  1497.  
  1498.  
  1499.  
  1500.  
  1501.  
  1502.         
  1503.  
  1504.     
  1505.  
  1506.  
  1507.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1508.     // file methods
  1509.     // ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  1510.  
  1511.  
  1512.     /**
  1513.       * returns an array with information about the file
  1514.       *
  1515.       * @param string $aValue
  1516.       * @param boolean $debug
  1517.       *
  1518.       * @return array
  1519.       *
  1520.       */
  1521.     function getFileInfo($aValue,$debug=False)
  1522.     {
  1523.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getFileInfo($aValue)");
  1524.  
  1525.         $arr_ret array(
  1526.             'DIR'           => $this->getRootPath().$this->defaultDir,
  1527.             'FILE'          => '',
  1528.             'IS_LINK'       => is_link($this->getRootPath().$this->defaultDir),
  1529.             'IS_WRITABLE'   => is_writable($this->getRootPath().$this->defaultDir),
  1530.             'IS_READABLE'   => is_readable($this->getRootPath().$this->defaultDir)
  1531.         );
  1532.  
  1533.         if (empty($aValue))
  1534.         {
  1535.             return $arr_ret;
  1536.         }
  1537.  
  1538.         $str_filePath=$this->getRootPath().$aValue;
  1539.         if (is_file($str_filePath))
  1540.         {
  1541.             $arr_ret['DIR'=dirname($str_filePath);
  1542.             $arr_ret['FILE']=str_replace($this->getRootPath(),"",$str_filePath);
  1543.             $arr_ret['IS_WRITABLE']=is_writable($arr_ret['FILE']);
  1544.             $arr_ret['IS_READABLE']=is_readable($arr_ret['DIR']);
  1545.  
  1546.         else if (is_dir($str_filePath)) {
  1547.             $arr_ret['DIR']=$str_filePath;
  1548.             $arr_ret['IS_WRITABLE']=is_writable($arr_ret['DIR']);
  1549.             $arr_ret['IS_READABLE']=is_readable($arr_ret['DIR']);
  1550.         else if (is_link($str_filePath)) {
  1551.             $arr_ret['IS_LINK']=True;
  1552.             $str_linkPath=readlink($str_filePath);
  1553.             if (is_file($str_linkPath))
  1554.             {
  1555.                 $arr_ret['DIR'=dirname($str_filePath);
  1556.                 $arr_ret['FILE']=str_replace($this->getRootPath(),"",$str_filePath);
  1557.                 $arr_ret['IS_WRITABLE']=is_writable($arr_ret['FILE']);
  1558.                 $arr_ret['IS_READABLE']=is_readable($arr_ret['DIR']);
  1559.  
  1560.             else if (is_dir($str_linkPath)) {
  1561.                 $arr_ret['DIR']=$str_filePath;
  1562.                 $arr_ret['IS_WRITABLE']=is_writable($arr_ret['DIR']);
  1563.                 $arr_ret['IS_READABLE']=is_readable($arr_ret['DIR']);
  1564.             }
  1565.         }
  1566.         return $arr_ret;
  1567.     }
  1568.  
  1569.  
  1570.  
  1571.     /**
  1572.       * returns an array with files of the current dir
  1573.       *
  1574.       * @param string $aPath
  1575.       * @param string $aFileName
  1576.       *
  1577.       * @returns array
  1578.       *
  1579.       * @requires pcf_directory.phpinc
  1580.       *
  1581.       * @todo DBMS_FIELD_FILESELECTLIST::getFileOptionArr() file extension filter
  1582.       **/
  1583.     function getFileOptionArr($aPath,$aValue="",$debug=False{
  1584.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getFileOptionArr($aPath,$aValue)");
  1585.         $arr_ret=array();
  1586.  
  1587.         $arr_ret[]=array('VAL'=>"",'LAB'=>'','SELECTED'=>"");
  1588.  
  1589.         if (!strstr($aPath,$this->getRootPath())) $aPath=$this->getRootPath().$aPath;       
  1590.         $aValue=basename($aValue);
  1591.  
  1592.         require_once __OCSP_PHPINCPATH__."common"._OCSP_DIRSEP_."pcf_directory.phpinc";
  1593.         if ($arr_files=pcf_getDirList($aPath,'FL',$debug))
  1594.         {
  1595.             $str_valPath=str_replace($this->getRootPath(),"",$aPath);
  1596.             if (substr($str_valPath,-1!= _OCSP_DIRSEP_$str_valPath.=_OCSP_DIRSEP_;
  1597.  
  1598.             foreach($arr_files as $str_file)
  1599.             {
  1600.                 $arr_ret[]=array('VAL'=>$str_valPath.$str_file,'LAB'=>$str_file,'SELECTED'=>(($str_file == $aValue"selected=\"selected\"" ""));
  1601.             }
  1602.         }
  1603.         return $arr_ret;
  1604.     }
  1605.  
  1606.  
  1607.     // ---------------------------------------------------------------
  1608.     // html code
  1609.     // ---------------------------------------------------------------
  1610.  
  1611.  
  1612.  
  1613.  
  1614.  
  1615.  
  1616.  
  1617.  
  1618.  
  1619.  
  1620.     /**
  1621.       * returns the html representation of the field
  1622.       *
  1623.       * @param mixed    $aValue     the falue
  1624.       * @param string $arrName  name of the global array holding data values
  1625.       * @param bool     $debug      show debug info
  1626.       *
  1627.       * @returns mixed   the html representation of the field
  1628.       **/
  1629.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=False{
  1630.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getScreenValue()",$this->myName);
  1631.  
  1632.         $s_ret="";
  1633.         if (!empty($aValue)) {
  1634.             if ($s_filePath=$this->getFilePath($aValue,$debug)) {
  1635.                 if (substr($s_filePath,-1,1!= '/'{
  1636.                     if (file_exists($s_filePath)) {
  1637.                         return basename($s_filePath)." ".$this->getDownlBtn($s_filePath,$debug);
  1638.                     else {
  1639.                         return "[".$aValue."]" ;
  1640.                     }
  1641.                else {
  1642.                     return "[NO FILE]";
  1643.                }
  1644.             }
  1645.         }
  1646.         return parent::getScreenValue($aValue,$arrName,$debug);
  1647.     }
  1648.  
  1649.  
  1650.     /**
  1651.       * returns the html representation of the field in a list (table col)
  1652.       *
  1653.       * @param mixed    $aValue     the falue
  1654.       * @param string $arrName  name of the global array holding data values
  1655.       * @param bool     $debug      show debug info
  1656.       *
  1657.       * @returns mixed   the html representation of the field
  1658.       *
  1659.       * @since pk-06-04-26
  1660.       *
  1661.       **/
  1662.     function getListValue($aValue=NULL,$arrName="DBVAL",$debug=False{
  1663.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECTLIST::getListValue()",$this->myName);
  1664.  
  1665.         $s_ret="";
  1666.         if (!empty($aValue)) {
  1667.             if ($s_filePath=$this->getFilePath($aValue,$debug)) {
  1668.                 if (substr($s_filePath,-1,1!= '/'{
  1669.                     if (file_exists($s_filePath)) {
  1670.                         return basename($s_filePath);
  1671.                     else {
  1672.                         return "[".$aValue."]" ;
  1673.                     }
  1674.                else {
  1675.                     return "[NO FILE]";
  1676.                }
  1677.             }
  1678.         }
  1679.         return parent::getScreenValue($aValue,$arrName,$debug);
  1680.     }
  1681.  
  1682.     /**
  1683.       * returns a empty link to not link the field
  1684.       *
  1685.       * @param mixed $aValue value of the db field
  1686.       * @param string $arrName  name of the GLOBAL array holding the row values
  1687.       *
  1688.       * @return string empty if no link is to show a <a href=...url..> if the field is linked
  1689.       *
  1690.       * @since pk-06-10-19
  1691.       *
  1692.       **/
  1693.     function getListLink($aValue,$arrName="DBVAL"{
  1694.         if (!empty($aValue)) {
  1695.             if (($s_filePath=$this->getFilePath($aValue,$debug)) && (substr($s_filePath,-1,1!= '/'&& file_exists($s_filePath)) {
  1696.                 if ($s_lnkBtn=$this->getDownlBtn($s_filePath,$debug)) {
  1697.                     return "<div style=\"float: right;\">".$s_lnkBtn."</div>";
  1698.                 }
  1699.             }
  1700.         }
  1701.         return "";
  1702.     }
  1703.  
  1704.     /**
  1705.       * gets a htmltag for the value
  1706.       *
  1707.       * this is mainly used in CMS Module
  1708.       *
  1709.       * @param mixed $aValue
  1710.       * @param string $arrName
  1711.       * @param bool $debug
  1712.       *
  1713.       * @return mixed
  1714.       *
  1715.       * @since pk-04-11-18
  1716.       *
  1717.       **/
  1718.     function getHtmlTag($aValue,$arrName="DBVAL",$debug=False{
  1719.         if ($debugecho "<p><b>DMBS_FIELD::getHtmlTag($aValue,$arrName ...)</b> (".get_class($this).")</p>";
  1720.         if (is_array($aValue)) {
  1721.             if ($debugecho "<p>VALUE:</p><pre>".print_r($aValue,True)."</pre>";
  1722.             if ($this->htmlValWithRoot$ret=$this->rootDir;
  1723.             else $ret="";
  1724.             return $ret.$aValue['DIR'].$aValue['FILE'];
  1725.         }
  1726.         return $aValue;
  1727.     }
  1728.  
  1729.  
  1730.     
  1731.     
  1732.     
  1733. // end class DBMS_FIELD_ARRSELECTLIST
  1734. ?>

Documentation generated on Thu, 08 Jan 2009 17:41:33 +0100 by phpDocumentor 1.4.0a2