• Main Page
  • Related Pages
  • Namespaces
  • Data Structures
  • Files
  • File List

E:/E/GEAMP/www/openbiz/openbiz/bin/easy/element/ImageUploader.php

00001 <?php
00017 include_once("FileUploader.php");
00018 
00027 class ImageUploader extends FileUploader
00028 {
00029     public $m_PicWidth ;
00030     public $m_PicHeight ;
00031     public $m_ThumbWidth ;
00032     public $m_ThumbHeight ;
00033     public $m_ThumbFolder ;
00034     public $m_Preview ;
00035 
00042     function __construct(&$xmlArr, $formObj)
00043     {
00044         parent::__construct($xmlArr, $formObj);
00045         $this->readMetaData($xmlArr);
00046     }
00047 
00054     protected function readMetaData(&$xmlArr)
00055     {
00056         parent::readMetaData($xmlArr);
00057         $this->m_PicWidth   = isset($xmlArr["ATTRIBUTES"]["PICWIDTH"]) ? $xmlArr["ATTRIBUTES"]["PICWIDTH"] : null;
00058         $this->m_PicHeight  = isset($xmlArr["ATTRIBUTES"]["PICHEIGHT"]) ? $xmlArr["ATTRIBUTES"]["PICHEIGHT"] : null;
00059         $this->m_PicQuality        = isset($xmlArr["ATTRIBUTES"]["PICQUALITY"]) ? $xmlArr["ATTRIBUTES"]["PICQUALITY"] : 80;
00060         $this->m_ThumbWidth        = isset($xmlArr["ATTRIBUTES"]["THUMBWIDTH"]) ? $xmlArr["ATTRIBUTES"]["THUMBWIDTH"] : null;
00061         $this->m_ThumbHeight       = isset($xmlArr["ATTRIBUTES"]["THUMBHEIGHT"]) ? $xmlArr["ATTRIBUTES"]["THUMBHEIGHT"] : null;
00062         $this->m_ThumbQuality      = isset($xmlArr["ATTRIBUTES"]["THUMBQUALITY"]) ? $xmlArr["ATTRIBUTES"]["THUMBQUALITY"] : 50;
00063         $this->m_ThumbFolder       = isset($xmlArr["ATTRIBUTES"]["THUMBFOLDER"]) ? $xmlArr["ATTRIBUTES"]["THUMBFOLDER"] : null;
00064         $this->m_Preview    = isset($xmlArr["ATTRIBUTES"]["PREVIEW"]) ? $xmlArr["ATTRIBUTES"]["PREVIEW"] : false;
00065     }
00066 
00073     function setValue($value)
00074     {
00075        
00076        if($this->m_Deleteable=='N' )
00077        {
00078        
00079        
00080        }
00081            else
00082        {
00083               $delete_user_opt=BizSystem::clientProxy()->getFormInputs($this->m_Name."_DELETE"); 
00084               if($delete_user_opt)
00085               {
00086                      $this->m_Value="";
00087                      return;
00088               }
00089               else
00090               {
00091                      if(count($_FILES)>0){
00092                             
00093                      }else{
00094                             $this->m_Value = $value;
00095                      }  
00096               } 
00097        }
00098        
00099               if(count($_FILES)>0)
00100                {
00101                      
00102                    if(!$this->m_Uploaded)
00103                    {
00104                        $picFileName = parent::setValue($value);
00105                        if((int)$this->m_PicWidth>0 || (int)$this->m_PicHeight>0)
00106                        {
00107                            //resize picture size
00108                            $fileName = $this->m_UploadRoot.$picFileName;
00109                            $width = $this->m_PicWidth;
00110                            $height = $this->m_PicHeight;
00111                            $quality = $this->m_PicQuality;
00112        
00113                            $this->resizeImage($fileName, $fileName, $width, $height, $quality);
00114                        }
00115                        if(
00116                        ((int)$this->m_ThumbWidth>0 || (int)$this->m_ThumbHeight>0) &&
00117                                $this->m_ThumbFolder!=""
00118                        )
00119                        {
00120                            //generate thumbs picture
00121                            if(!is_dir($this->m_UploadRoot.$this->m_ThumbFolder))
00122                            {
00123                                mkdir($this->m_UploadRoot.$this->m_ThumbFolder ,0777,true);
00124                            }
00125                            $file = $_FILES[$this->m_Name];
00126                            $thumbPath = $this->m_ThumbFolder."/thumbs-".date("YmdHis")."-".urlencode($file['name']);
00127                            $thumbFileName = $this->m_UploadRoot.$thumbPath;
00128                            $width = $this->m_ThumbWidth;
00129                            $height = $this->m_ThumbHeight;
00130                            $quality = $this->m_ThumbQuality;
00131        
00132                            $this->resizeImage($fileName, $thumbFileName, $width, $height, $quality);
00133        
00134                            $result=array('picture'=>$this->m_UploadRootURL.$picFileName,'thumbpic'=>$this->m_UploadRootURL.$thumbPath);                         
00135                            $this->m_Value=serialize($result);
00136                        }
00137                    }
00138                }
00139                else
00140                {
00141                             $this->m_Value = $value;           
00142                }      
00143     }
00144 
00159     protected function resizeImage($sourceFileName, $destFileName, $width, $height, $quality)
00160     {
00161               if(!function_exists("imagejpeg"))
00162               {
00163                      return ;
00164               }
00165         if($width == 0)
00166         {
00167             $width = $height;
00168         }
00169 
00170         if($height == 0)
00171         {
00172             $height = $width;
00173         }
00174 
00175         list($origWidth, $origHeight) = getimagesize($sourceFileName);
00176 
00177         $origRatio = $origWidth / $origHeight;
00178 
00179         if ( ($width / $height) > $origRatio)
00180         {
00181             $width = $height * $origRatio;
00182         }
00183         else
00184         {
00185             $height = $width / $origRatio;
00186         }
00187 
00188         $image_p = imagecreatetruecolor($width, $height);
00189         try{
00190               $image = @imagecreatefromjpeg($sourceFileName);
00191         }catch(Exception $e){}
00192         try{
00193                if(!$image){
00194                      $image = @imagecreatefrompng($sourceFileName);
00195                }
00196         }catch(Exception $e){}
00197         try{
00198                if(!$image){
00199                      $image = @imagecreatefromgif($sourceFileName);
00200                }
00201        }catch(Exception $e){}
00202        try{
00203                if(!$image){
00204                      $image = @imagecreatefromwbmp($sourceFileName);
00205                }
00206        }catch(Exception $e){}
00207        
00208        try{
00209                if(!$image){
00210                      $image = @imagecreatefromxbm($sourceFileName);
00211                }
00212        }catch(Exception $e){}
00213        
00214     
00215        try{
00216                if(!$image){
00217                      $image = @imagecreatefromxpm($sourceFileName);
00218                }
00219        }catch(Exception $e){}
00220        
00221        if(!$image){
00222               return ;
00223            }
00224         imagecopyresampled($image_p, $image, 0, 0, 0, 0, $width, $height, $origWidth, $origHeight);
00225 
00226         return imagejpeg($image_p, $destFileName, $quality);
00227     }
00228     
00229     public function render()
00230     {
00231         $disabledStr = ($this->getEnabled() == "N") ? "disabled=\"true\"" : "";
00232         $style = $this->getStyle();
00233         $func = $this->getFunction();
00234         $value = $this->getValue();
00235         if($this->m_Preview){
00236                if($value){
00237                      $preview = "<img id=\"" . $this->m_Name ."_preview\" src=\"$value\" class=\"image_preview\" />";
00238                }
00239         }
00240         if($this->m_Deleteable=="Y"){
00241               $delete_opt="<input type=\"checkbox\" name=\"" . $this->m_Name . "_DELETE\" id=\"" . $this->m_Name ."_DELETE\" >Delete";
00242         } else{
00243               $delete_opt="";
00244         }
00245         $sHTML .= "
00246         $preview
00247         <input type=\"file\" onchange=\"Openbiz.ImageUploader.updatePreview('" . $this->m_Name ."')\" name=\"$this->m_Name\" id=\"" . $this->m_Name ."\" value=\"$this->m_Value\" $disabledStr $this->m_HTMLAttr $style $func>
00248         $delete_opt
00249         ";
00250         return $sHTML;
00251     }    
00252 }
00253 ?>

Generated on Thu Apr 19 2012 17:09:13 for openbiz by  doxygen 1.7.2