Source for file DBMS_FIELD_IMAGE.phpclass

Documentation is available at DBMS_FIELD_IMAGE.phpclass

  1. <?php
  2. /**
  3.   * Class file DBMS_FIELD_IMAGE.phpclass
  4.   *
  5.   * @project    Open CSP-Management
  6.   * @package    dbms_field
  7.   * @category   string
  8.   *
  9.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  10.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  11.   *
  12.   * @version $Id: DBMS_FIELD_IMAGE.phpclass,v 1.19 2008/11/11 07:04:42 pitlinz Exp $
  13.   */
  14.  
  15. pcf_require_class('DBMS_FIELD_FILESELECTLIST',dirname(__FILE__)._OCSP_DIRSEP_."DBMS_FIELD_FILESELECTLIST.phpclass");
  16.  
  17.  
  18. /**
  19.   * Class DBMS_FIELD_IMAGE
  20.   *
  21.   * @project    Open CSP-Management
  22.   * @package    dbms_field
  23.   * @category   string
  24.   *
  25.   * @author     Peter Krebs <pitlinz@users.sourceforge.net>
  26.   * @license    http://opensource.org/licenses/gpl-license.php GNU Public License
  27.   *
  28.   * @version pk-07-01-15
  29.   * @version pk-07-09-12 changed parent class from DBMS_FIELD to DBMS_FIELD_FILESELECTLIST
  30.   * @version $Id: DBMS_FIELD_IMAGE.phpclass,v 1.19 2008/11/11 07:04:42 pitlinz Exp $
  31.   */
  32.  
  33.     /**
  34.       * attributes ------------------------------------------------------------------
  35.       */
  36.  
  37.     /**
  38.       * source file of the class
  39.       *
  40.       * @var string $classSrcFile 
  41.       * @since pk-04-10-05
  42.       */
  43.     var $classSrcFile=__FILE__;
  44.  
  45.     // ------------------------------------------------------------------------------
  46.  
  47.     /**
  48.       * @var int $maxWidth 
  49.       */
  50.     protected $maxWidth       = "1024";
  51.     /**
  52.       * @var int $maxHeight 
  53.       */
  54.     protected $maxHeight      = "768";
  55.     /**
  56.      * @var boolean $resizeOnUpload 
  57.      */
  58.     protected $resizeOnUpload=FALSE;
  59.     /**
  60.       * @var int $listMaxWidth 
  61.       */
  62.     protected $listMaxWidth   = "40";
  63.     /**
  64.       * @var int $listMaxHeight 
  65.       */
  66.     protected $listMaxHeight  = "30";
  67.  
  68.     /**
  69.       * @var boolean $hideInputField 
  70.       * @since pk-04-09-23
  71.       ***/
  72.     protected $hideInputField = FALSE;
  73.  
  74.     // ###########################################################
  75.     // OBJECT SETTINGS METHODS
  76.     // ###########################################################
  77.  
  78.     /**
  79.       * convert old object vars to DBMS_FIELD_DBLOOKUPSELECTLIST
  80.       * and then calls the parent method
  81.       *
  82.       * @param array $varArr 
  83.       * @param boolean $debug 
  84.       *
  85.       */
  86.     function setObjectVars($varArr,$debug=FALSE{
  87.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_IMAGE::setObjectVars(...)",print_r($varArr,TRUE));
  88.  
  89.         foreach($varArr as $str_name => $m_val)
  90.         {
  91.             switch($str_name)
  92.             {
  93.                 case "allowOverwrite":
  94.                     $varArr['allow_overwrite']=$m_val;
  95.                     unset($varArr['allowOverwrite']);
  96.                     break;
  97.                 case "allowMkDir":
  98.                     $varArr['allow_mkdir']=$m_val;
  99.                     unset($varArr['allowMkDir']);
  100.                     break;
  101.                 case "allowUpload":
  102.                     $varArr['allow_upload']=$m_val;
  103.                     unset($varArr['allowUpload']);
  104.                     break;
  105.                 case "dirPrefix":
  106.                     if ($m_val=="DOCUMENT_ROOT")
  107.                     {
  108.                         $varArr['useDocRoot']=TRUE;
  109.                     else {
  110.                         $varArr['useDocRoot']=FALSE;
  111.                     }
  112.                     unset($varArr['dirPrefix']);
  113.                     break;
  114.             }
  115.         }
  116.         parent::setObjectVars($varArr,$debug);
  117.     }
  118.  
  119.     /**
  120.      * returns if the upload is to resize
  121.      * @return boolean 
  122.      */
  123.     function getResizeOnUpload()
  124.     {
  125.         return $this->resizeOnUpload;
  126.     }
  127.     
  128.     /**
  129.      * returns the maxWidth
  130.      * @return int 
  131.      */
  132.     function getMaxWidth()
  133.     {
  134.         return intval($this->maxWidth);
  135.     }
  136.     
  137.     /**
  138.      * returns the maxHeight
  139.      * @return int 
  140.      */
  141.     function getMaxHeight()
  142.     {
  143.         return intval($this->maxHeight);   
  144.     }
  145.     
  146.     /**
  147.      * returns the value of the uploaded file
  148.      *
  149.      * @param array $uplFile ($_FILE[fld])
  150.      * @param string $path 
  151.      * 
  152.      * @return string value to set or Null on error
  153.      */
  154.     function uploadFile($uplFile,$path="")
  155.     {
  156.         if (isset($uplFile['error']&& !empty($uplFile['error']))
  157.         {
  158.             $this->setErrorMsg($uplFile['error'],True);
  159.             return Null;
  160.         }
  161.         
  162.         if ($this->userCanUpload())
  163.         {
  164.             pcf_require_class('OCSP_IMAGE',array(__OCSP_PHPINCPATH__,'common','OCSP_IMAGE.phpclass'));
  165.                         
  166.             $obj_image new OCSP_IMAGE($uplFile['tmp_name']);
  167.             if ($obj_image->isImage())
  168.             {
  169.                 $bol_fileOk        True;
  170.                 $bol_toresize    False;
  171.                 if (intval($this->getMaxWidth()) &&  ($obj_image->getWidth($this->getMaxWidth()))
  172.                 {
  173.                     if ($this->resizeOnUpload
  174.                     {
  175.                         $bol_toresize True;
  176.                     else {
  177.                         $this->setErrorMsg($uplFile['name'" is to wide " $obj_image->getWidth(" instead of " $this->getMaxWidth(),True);
  178.                         $bol_fileOk False
  179.                     }
  180.                 }
  181.  
  182.                 if (intval($this->getMaxHeight()) &&  ($obj_image->getHeight($this->getMaxHeight()))
  183.                 {
  184.                     if ($this->resizeOnUpload
  185.                     {
  186.                         $bol_toresize True;
  187.                     else {
  188.                         $this->setErrorMsg($uplFile['name'" is to heigh " $obj_image->getHeight(" instead of " $this->getMaxHeight(),True);
  189.                         $bol_fileOk False
  190.                     }
  191.                 }
  192.                 
  193.                 if (intval($this->maxSize&& (intval($uplFile['size']$this->getMaxFileSizeBytes())) 
  194.                 {
  195.                     $this->setErrorMsg($uplFile['name'" is to large max  " $this->maxSize . " kB",True);
  196.                     $bol_fileOk False;    
  197.                 }
  198.                 
  199.                 if ($bol_fileOk)
  200.                 {                
  201.                     $str_curDir $this->getDirFromValue($path,$debug);
  202.                     $str_path $this->getRootPath($str_curDir;    
  203.  
  204.                     //echo "L: " . __LINE__ . "\n$path\n$str_curDir\n$str_path";
  205.                     
  206.                     $str_fileName pcf_checkFileName($uplFile['name'])
  207.                        if (!$this->userCanOverwrite())
  208.                        {
  209.                            $arr_name=explode(".",$str_fileName,2);
  210.                            $int_idx=0;
  211.                            while (file_exists($str_path $str_fileName))
  212.                            {
  213.                                $str_fileName $arr_name[0].'_'.sprintf("%03d",$int_idx++).".".$arr_name[1];                            
  214.                            }
  215.                        }    
  216.                        
  217.                        $str_file pcf_checkFilePath($str_path _OCSP_DIRSEP_ $str_fileName,_OCSP_DIRSEP_);
  218.                        
  219.     
  220.                     if ($bol_toresize)
  221.                     {
  222.                         $obj_image->res_resize($this->getMaxWidth(),$this->getMaxHeight());
  223.                         if ($int_type=$obj_image->res_saveAs($str_file))
  224.                         {
  225.                             return str_replace($this->getBasePath(),"",$str_file);                    
  226.                         }
  227.                     else {
  228.                         //echo "\nL: " . __LINE__ . ": ".$str_file;
  229.                          if ((move_uploaded_file($uplFile['tmp_name']$str_file))) 
  230.                            {                               
  231.                                return str_replace($this->getBasePath(),"",$str_file);
  232.                            else {
  233.                             $this->setErrorMsg('Could not write File ' str_replace($this->getBasePath(),"",$str_file));                           
  234.                            }
  235.                     }
  236.                 }                
  237.             else {
  238.                 $this->setErrorMsg($uplFile['name']." is not an image");
  239.             }
  240.         else {
  241.             $this->setErrorMsg('You are not allowed to upload an image',True);            
  242.         }
  243.         
  244.         return Null;
  245.         
  246.     }
  247.     
  248.     
  249.     // ###########################################################
  250.     // FIELD DEFINITION DATA METHODS
  251.     // ###########################################################
  252.  
  253.     /**
  254.       * returns an array of field to bie shown in the edit form
  255.       * by using editTbl_echoForm
  256.       *
  257.       * @param boolean $debug 
  258.       *
  259.       * @returns array
  260.       *
  261.       * @since pk-06-08-15
  262.       *
  263.       ***/
  264.     function editTbl_getFieldEditArr($debug=FALSE{
  265.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_DBSELECTLIST::editTbl_getFieldEditArr","",0);
  266.         $a_ret=parent::editTbl_getFieldEditArr($debug);
  267.  
  268.         include __OCSP_PHPINCPATH__."db/forms/languages/DBMS_FIELD_IMAGE_FieldEditArr_DE.phpinc";
  269.         
  270.         unset($a_ret['LAYOUT']['FLD_INPUTADD']);
  271.         unset($a_ret['LAYOUT']['FLD_SIZE']);
  272.         unset($a_ret['LAYOUT']['FLD_SELSIZE']);
  273.         
  274.         unset($a_ret['FILESELECT']['FLD_DOWNL']);
  275.         unset($a_ret['FILESELECT']['FLD_EDITORURL']);
  276.         unset($a_ret['FILESELECT']['FLD_UPLOADURL']);
  277.         
  278.         return $a_ret;
  279.     }
  280.  
  281.  
  282.     /**
  283.       * save the filed definition form
  284.       *
  285.       * @param bool $debug 
  286.       * @returns bool return TRUE
  287.       *
  288.       * @version pk-06-08-15
  289.       ***/
  290.     function save($debug=FALSE{
  291.         $b_ret=parent::save();
  292.  
  293.         $this->maxWidth         = (isset($_POST['maxWidth']intval($_POST['maxWidth']0);
  294.         $this->maxHeight        = (isset($_POST['maxWidth']intval($_POST['maxHeight']0);
  295.         $this->listMaxWidth     = (isset($_POST['listMaxWidth']intval($_POST['listMaxWidth']0);
  296.         $this->listMaxHeight    = (isset($_POST['listMaxHeight']intval($_POST['listMaxHeight']0);
  297.         $this->hideInputField   = (intval($_POST['hideInputField']FALSE TRUE);
  298.         $this->resizeOnUpload   = (isset($_POST['resizeOnUpload']&& intval($_POST['resizeOnUpload']));
  299.  
  300.         return $b_ret;
  301.     }
  302.  
  303.  
  304.  
  305.     // ###########################################################
  306.     // OBJECT HTML FORM METHODS
  307.     // ###########################################################
  308.     
  309.     /**
  310.       * returns the html <img src= value >
  311.       *
  312.       * @param string $aImg 
  313.       * @param boolean $debug 
  314.       * @param int $mode since pk-06-08-15
  315.       *
  316.       * @global array $OCSP_CONF 
  317.       *
  318.       * @return string 
  319.       *
  320.       * @requires pcf_md5.phpinc
  321.       *
  322.       * @since pk-04-09-24
  323.       * @version pk-04-12-27
  324.       * @version pk-06-01-10
  325.       * @version pk-06-10-06 // different db-versions one with $rootDir and one without
  326.       * @version pk-06-12-06 // check for html urls
  327.       * @version pk-07-02-14 // SEC_REQ['PUBLIC']
  328.       * @version pk-07-09-12 // compleate rewrite
  329.       * @version $Id: DBMS_FIELD_IMAGE.phpclass,v 1.19 2008/11/11 07:04:42 pitlinz Exp $
  330.       * 
  331.       */
  332.     function getImgSrc($aValue,$debug=False{
  333.         $debug=($debug || $this->fldDebug);
  334.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_IMAGE::getImgSrc($aImg,...)");
  335.         
  336.         if (!empty($aValue))
  337.         {                        
  338.             $str_showUrl OCSP_OBJ::getConf('SYSTEMURL')."tools/imageSource.php?imgSrc=";
  339.             $str_showUrl.= OCSP_SESSION::getInstance()->encrypt($this->getFilePath($aValue,$debug));            
  340.             return $str_showUrl;
  341.         }
  342.         return Null;
  343.     }
  344.  
  345.     /**
  346.      * returns the img preview tag with link to the image browser
  347.      * 
  348.      * @param string $aValue 
  349.      * @param boolean $debug 
  350.      * 
  351.      * @return string (html)
  352.      */
  353.     function getInputImgPreview($aValue,$debug=False)
  354.     {        
  355.         $i_maxWidth =((intval($this->maxWidth>250 250 intval($this->maxWidth));
  356.         $i_maxHeight=((intval($this->maxHeight>200 200 intval($this->maxHeight));
  357.         
  358.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_IMAGE::getInputImgPreview($aValue)");
  359.         if (empty($aValue))
  360.         {
  361.             $str_imgSrc=OCSP_OBJ::getConf('SYSIMGURL')."icons-64x64/unknown.png";
  362.         else {
  363.             $str_imgSrc=$this->getImgSrc($aValue,$debug);
  364.             $str_imgSrc.="&w=$i_maxWidth&h=$i_maxHeight";            
  365.         }    
  366.                 
  367.         $str_tag="";
  368.                 
  369.         $str_onClick="onclick=\"
  370.                 if (obj_form = jOCSP.getFormByHash('" $this->myControll->jOCSP_getfrmHash("')) 
  371.                 {
  372.                     if (obj_field = obj_form.getFieldByDomId('" $this->getDOMId("')) 
  373.                     {
  374.                         obj_field.openBrowser();
  375.                     }
  376.                 }
  377.             \"";
  378.         
  379.         $str_style ="style=\"";
  380.         $str_style.="float: left;width:".($i_maxWidth+2)."px;height:".($i_maxHeight+2)."px;";
  381.         $str_style.="margin: 2px;border: dashed 2px #C0C0C0;padding: 2px;";
  382.         $str_style.="background-image: url('".$str_imgSrc."');";
  383.         $str_style.="background-repeat: no-repeat;";
  384.         $str_style.="background-position: left center;";
  385.         $str_style.="\"";
  386.         
  387.       
  388.         $str_tag.= "
  389.             <div id=\"preview_".$this->getDOMId()."\" $str_onClick $str_style>                                  
  390.             </div>
  391.             ";            
  392.         if ($debug$str_tag.= "<p><a href=\"" $str_imgSrc "\">" $aValue "</a></p>";            
  393.         return $str_tag;
  394.     }
  395.     
  396.                 
  397.     /**
  398.       *
  399.       * @param string $aValue (image path)
  400.       * @param string $arrName (overwrites $this->myDataArrName if not empty)
  401.       * @param boolean $debug 
  402.       *
  403.       * @global ${$this->myDataArrName} 
  404.       * @global $OCSP_CONF 
  405.       *
  406.       * @returns string (html)
  407.       *
  408.       * @returns string
  409.       *
  410.       * @version pk-04-09-23
  411.       *
  412.       ***/
  413.     function getInputTag($aValue,$arrName="DBVAL",$debug=FALSE)
  414.     {
  415.         $debug=($debug || $this->fldDebug);
  416.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_IMAGE::getInputTag() [".$this->getKey()."]","Value: ".$aValue);
  417.  
  418.         if (!empty($arrName)) $this->myDataArrName=$arrName;
  419.  
  420.         global ${$this->myDataArrName};
  421.         global $OCSP_CONF;
  422.  
  423.         if (substr($aValue,0,1)==_OCSP_DIRSEP_$aValue=substr($aValue,1);  // remove leading slash
  424.  
  425.         $str_ret="";
  426.         
  427.         $str_ret.="<div id=\"imgdiv_".$this->getDOMId()."\">";
  428.         $str_ret.=$this->getInputImgPreview($aValue);
  429.         $str_ret.="</div>";
  430.  
  431.         $str_ret.="
  432.             <div style=\"float:left\">
  433.                 <img src=\"" OCSP_OBJ::getConf('SYSIMGURL'"icons-16x16/cancel.gif\"
  434.                     alt=\"cancel\" title=\"Bild entfernen\" class=\"button\"
  435.                     onclick=\"
  436.                         document.getElementById('" $this->getDOMId("').value='';
  437.                         document.getElementById('preview_".$this->getDOMId()."').style.backgroundImage='url(" OCSP_OBJ::getConf('SYSIMGURL'"icons-64x64/unknown.png)';
  438.                     \" 
  439.                 />
  440.             </div>
  441.             ";
  442.         $str_type ($this->hideInputField ? "hidden" "text");
  443.         $str_ret .="
  444.             <div clear=\"left\">
  445.                 <input type=\"{$str_type}\" name=\"$this->myDataArrName . "[" $this->getName("]\" id=\"" $this->getDOMId("\" value=\"" $aValue "\" />
  446.             </div>
  447.             ";
  448.         
  449.         
  450.         return $str_ret;
  451.  
  452.     }
  453.  
  454.     function checkSrc($aValue{
  455.         return (($aValue&& (file_exists($_SERVER['DOCUMENT_ROOT'].$aValue)));
  456.     }
  457.  
  458.  
  459.     /**
  460.       * returns the screen representation
  461.       * here a img tag is returned
  462.       *
  463.       * @param string $aValue 
  464.       * @param string $arrName 
  465.       * @param boolean $debug 
  466.       *
  467.       * @returns string
  468.       *
  469.       * @version pk-04-09-24
  470.       *
  471.       ***/
  472.     function getScreenValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  473.         $debug=($debug || $this->fldDebug);
  474.         if ($debugecho "<p><b>DBMS_FIELD_IMAGE::getScreenValue($aValue,$arrName,..)</b> (".get_class($this).")</p>";
  475.  
  476.         if ($src=$this->getImgSrc($aValue,$debug)) {
  477.             $str_ret="<img src=\"$src\" alt=\"".basename($aValue)."\" border=\"0\">";
  478.             if ($debug$str_ret.="<a href=\"$src\">+</a>";
  479.             return $str_ret;
  480.         }
  481.         return "";
  482.     }
  483.  
  484.     /**
  485.       * returns the list representation
  486.       * here an img tag is returned
  487.       *
  488.       *
  489.       * @param string $aValue 
  490.       * @param string $arrName 
  491.       * @param boolean $debug 
  492.       *
  493.       * @returns string
  494.       *
  495.       * @since pk-06-08-09
  496.       *
  497.       ***/
  498.     function getListValue($aValue=NULL,$arrName="DBVAL",$debug=FALSE{
  499.         $debug=($debug || $this->fldDebug);
  500.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_IMAGE::getListValue()");
  501.  
  502.         if ($src=$this->getImgSrc($aValue,$debug,FRM_MODE_LIST)) {
  503.             return "<img src=\"$src\" border=\"0\">";
  504.         else if (!empty($aValue)) {
  505.             return $aValue;
  506.         else {
  507.             return "";
  508.         }
  509.     }
  510.  
  511.  
  512.     /**
  513.       * gets a htmltag for the value
  514.       * for images only the src url is returned
  515.       * as this is often used with: <img src="$*img$">
  516.       *
  517.       * @param mixed $aValue 
  518.       * @param string $arrName 
  519.       * @param bool $debug 
  520.       *
  521.       * @return mixed 
  522.       *
  523.       * @since pk-04-07-29
  524.       * @version pk-06-12-06 check for http?: in the url
  525.       *
  526.       ***/
  527.     function getHtmlTag($aValue,$arrName="DBVAL",$debug=FALSE{
  528.         if ($debugecho "<p><b>DMBS_FIELD::getHtmlTag($aValue,$arrName ...)</b> (".get_class($this).")</p>";
  529.  
  530.         if (preg_match('/^http?:\/\//',$aValue)) {
  531.             return $aValue;
  532.         }
  533.         $ret=trim($this->getDirPrefixUri()).trim($aValue);
  534.         switch($this->dirPrefix{
  535.             case "SERVERROOT":
  536.                 return $this->getImgSrc($aValue);
  537.             default:
  538.                 if (!strstr($ret,"http")) {
  539.                     $ret=str_replace("//","/",$ret);
  540.                 }
  541.                 return $ret;
  542.         }
  543.     }
  544.     
  545.     
  546.        // --------------------------------------------------------
  547.     // jOCSP
  548.     // -------------------------------------------------------- 
  549.     
  550.     /**
  551.      * returns an array of jOCSP/jQuery Modules which are required
  552.      * 
  553.      * $arr_ret[]="script url";
  554.      *
  555.      * @param boolean $debug 
  556.      * 
  557.      * @return string 
  558.      * 
  559.      * @version pk-08-06-02
  560.      */
  561.     public function jOCSP_getRequiredModules($debug=False)
  562.     {        
  563.         if ($debugechoDebugMethod(__FILE__,get_classe($this),"DBMS_FIELD::jOCSP_getRequiredModules()");
  564.         
  565.         $arr_ret parent::jOCSP_getRequiredModules($debug);
  566.         
  567.         $arr_ret[array(
  568.             'CLASS'    => 'jOCSP.FLDOBJ_Image',
  569.             'SRC'     => OCSP_OBJ::getConf('SYSTEMURL')."jOCSP/formFields/jOCSP_FLDOBJ_Image.js"
  570.         );
  571.  
  572.         
  573.         return $arr_ret;
  574.     }  
  575.  
  576.    /**
  577.      * returns additional object elements of the field object
  578.      * 
  579.      * array definition: [elemName] = value
  580.      * 
  581.      * NOTE: do not js_escapte value this is done when building the json object
  582.      *
  583.      * @param boolean $debug 
  584.      * 
  585.      * @return array 
  586.      * 
  587.      * @since pk-08-02-06
  588.      */
  589.     protected function jOCSP_getAdditonalFieldObjElems($debug=False)
  590.     {  
  591.         if ($debugechoDebugMethod(__FILE__,get_class($this),"DBMS_FIELD_FILESELECT::jOCSP_getAdditonalFieldObjElems()");
  592.         $arr_ret parent::jOCSP_getAdditonalFieldObjElems($debug);        
  593.         $arr_ret['fldClass'"'FLDOBJ_Image'";
  594.         $arr_ret['rootPath'"'" OCSP_SESSION::getInstance()->encrypt($this->getRootPath()) ."'";
  595.         $arr_ret['imgMaxWidth'intval($this->maxWidth);
  596.         $arr_ret['imgMaxHeight'intval($this->maxHeight);
  597.         $arr_ret['imgResizeOnUpload'($this->resizeOnUpload ? "1" "0");
  598.         //$arr_ret['debug'] = True;
  599.         return $arr_ret;          
  600.     }    
  601.  
  602.     public function jOCSP_openBrowser($request,$debug=False)
  603.     {
  604.         $str_ret "";
  605.         
  606.         $str_url =OCSP_OBJ::getConf('SYSTEMURL'"forms/filemanager/imagebrowser2/index.php";
  607.         
  608.         $arr_allow=array(
  609.             'C' => $this->allow_cd,
  610.             'E'    => $this->allow_edit,
  611.             'M'    => $this->allow_mkdir,
  612.             'U'    => $this->allow_upload,
  613.             'O'    => $this->allow_overwrite
  614.         );
  615.         
  616.         
  617.         $arr_secarray(
  618.                 'PUBLIC'    => OCSP_OBJ::currentUser()->isPublic(),
  619.                 'USER'      => OCSP_OBJ::currentUser()->getId(),
  620.                 'COMMANDS'  => $arr_allow,
  621.                 'IBRD_HASH'    => md5($this->getRootPath())
  622.                );        
  623.  
  624.            OCSP_SESSION::getInstance(True)->setValue('IMAGE_BROWSER_ROOTDIR',$this->getRootPath());
  625.                
  626.            $str_url.="?fldDOM=" $this->getDOMId();
  627.         $str_url.="&SecReq=" OCSP_SESSION::getInstance()->encrypt(serialize($arr_sec));
  628.         
  629.         $str_ret .= "
  630.             if (obj_form = jOCSP.getFormByHash('" $this->myControll->jOCSP_getfrmHash("')) 
  631.             {
  632.                 if (obj_field = obj_form.getFieldByDomId('" $this->getDOMId("')) 
  633.                 {
  634.                     obj_field.rootDir     = '" $this->getRootDir("';
  635.                     obj_field.rootPath   = '" OCSP_SESSION::getInstance()->encrypt($this->getRootPath()) "';     
  636.                     
  637.                     document.getElementById('" $this->getDOMId("').ocspForm  = obj_form;
  638.                     document.getElementById('" $this->getDOMId("').ocspField = obj_field;
  639.                     
  640.                     if (wnd=openWindow('imgBrowser','".$str_url."',700,500))
  641.                     {
  642.                         wnd.focus();                    
  643.                     }                    
  644.                 }
  645.             }          
  646.         ";
  647.         
  648.         
  649.         /*
  650.         $str_onClick="onclick=\"\n";
  651.         $str_onClick.="openWindow('imgBrowser','".$this->getImgBrowserUrl($aValue,$debug)."',700,500);\n";
  652.         $str_onClick.="this.innerHTML='";
  653.         $str_onClick.="<img src=\\'" . OCSP_OBJ::getConf('SYSIMGURL') ."jquery/loading.gif\\' />";
  654.         $str_onClick.="';\n";        
  655.         $str_onClick.="\"\n";        
  656.         */
  657.         
  658.         return $str_ret;
  659.     }
  660.     
  661.     /**
  662.      * sets a file path
  663.      * @param array $request 
  664.      * @param boolean $debug 
  665.      * 
  666.      * @global array ${$this->myDataArrName}; 
  667.      * 
  668.      * @return string (js)
  669.      * 
  670.      * @since pk-08-06-09
  671.      */
  672.     public function jOCSP_setImage($request,$debug=False)
  673.     {
  674.         $str_ret "";
  675.         if (isset($request['value']))
  676.         {
  677.             $str_ret .= "ocsp_imageBrowser.openerFld.setPreviewDiv('" pcf_js_escape($this->getInputImgPreview($aValue)) "');";            
  678.         }
  679.     }
  680.     
  681.     
  682.    /**
  683.      * uploads a file
  684.      *
  685.      * @param array $request 
  686.      * @param boolean $debug 
  687.      * 
  688.      * @global array ${$this->myDataArrName}; 
  689.      * 
  690.      * @return string (js)
  691.      */
  692.     public function jOCSP_uploadFile($request,$debug)
  693.     {        
  694.         $str_ret "";
  695.         if ($this->userCanUpload())
  696.         {            
  697.             if ($arr_upload $_FILES[$this->getDOMId('_upload'])
  698.             {
  699.                 if (isset($arr_upload['error']&& !empty($arr_upload['error']))
  700.                 {
  701.                     pcf_js_alert("Fehler: " $arr_upload['error'])
  702.                     return "";
  703.                 
  704.                     
  705.                 $str_value $request[$this->getDirSelNameId()];
  706.                 $str_curDir $this->getDirFromValue($str_value,$debug);
  707.                 $str_path $this->getRootPath($str_curDir;
  708.  
  709.                 if ($debugpcf_js_alert("value: " $str_value "\ncurDir: " $str_curDir "\npath: " $str_path);                
  710.                 
  711.                 $str_fileName pcf_checkFileName($arr_upload['name'])
  712.                    if (!$this->userCanOverwrite())
  713.                    {
  714.                        $arr_name=explode(".",$str_fileName,2);
  715.                        $int_idx=0;
  716.                        while (file_exists($str_path $str_fileName))
  717.                        {
  718.                            $str_fileName $arr_name[0].'_'.sprintf("%03d",$int_idx++).".".$arr_name[1];                            
  719.                        }
  720.                    }
  721.                     
  722.                 if ($debugpcf_js_alert($str_path $str_fileName);
  723.  
  724.                    if (!(move_uploaded_file($arr_upload['tmp_name']$str_path $str_fileName))) 
  725.                    {
  726.                        pcf_js_alert('Konnte Datei nicht schreiben');
  727.                        return "";
  728.                    }
  729.                    
  730.                    $str_val str_replace($this->getBasePath(),"",$str_path $str_fileName);
  731.  
  732.                    $str_ret .= "
  733.                        if (dom_field = parent.document.getElementById('" $this->getDOMId("'))
  734.                        {
  735.                            try {                           
  736.                                dom_field.options[dom_field.options.length]=new Option('" basename($str_val"','" $str_val "',true,true);                           
  737.                                dom_field.value='" $str_val "';
  738.  
  739.                                obj_field = dom_field.jOCSPFldObj
  740.                                obj_domForm = obj_field.myForm.getDomObj();
  741.                                obj_domForm.target=obj_field.uploadOri.target;
  742.                                obj_domForm.action=obj_field.uploadOri.action;
  743.                                if (obj_field.uploadOri.encoding)
  744.                                {
  745.                                    obj_domForm.encoding = obj_field.uploadOri.encoding;
  746.                                } else {
  747.                                    obj_domForm.enctype = obj_field.uploadOri.enctype;
  748.                                }
  749.                                
  750.                                parent.document.getElementById('" $this->getDOMId(."_upload').value='';
  751.                            } catch(e) {
  752.                                alert('" basename(__FILE__" L: " . __LINE__ . ": ' + dom_field.id + '\\n' + e );                               
  753.                            }
  754.                            
  755.                        } else {
  756.                            alert('Feld nicht gefunden');
  757.                        }
  758.                    ";
  759.                    
  760.             }             
  761.         }
  762.         
  763.         return $str_ret;
  764.     }    
  765.     
  766. // end class DBMS_FIELD_PASSWORD
  767. ?>

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