Source for file xt_picture.class.php

Documentation is available at xt_picture.class.php

  1. <?php   /*
  2.    *@=@=@=@ START LICENSE @=@=@=@*
  3.    Copyright or © or Copr. Stéphane TRICHET and Nicolas SOTRON
  4.    
  5.    stephane.t@simpliciweb.net and nicolas.s@simpliciweb.net
  6.    
  7.    This software is a computer program whose purpose is to make a
  8.    web hosting platform
  9.    
  10.    This software is governed by the CeCILL  license under French law and
  11.    abiding by the rules of distribution of free software.  You can  use, 
  12.    modify and/ or redistribute the software under the terms of the CeCILL
  13.    license as circulated by CEA, CNRS and INRIA at the following URL
  14.    "http://www.cecill.info". 
  15.    
  16.    As a counterpart to the access to the source code and  rights to copy,
  17.    modify and redistribute granted by the license, users are provided only
  18.    with a limited warranty  and the software's author,  the holder of the
  19.    economic rights,  and the successive licensors  have only  limited
  20.    liability. 
  21.    
  22.    In this respect, the user's attention is drawn to the risks associated
  23.    with loading,  using,  modifying and/or developing or reproducing the
  24.    software by the user in light of its specific status of free software,
  25.    that may mean  that it is complicated to manipulate,  and  that  also
  26.    therefore means  that it is reserved for developers  and  experienced
  27.    professionals having in-depth computer knowledge. Users are therefore
  28.    encouraged to load and test the software's suitability as regards their
  29.    requirements in conditions enabling the security of their systems and/or 
  30.    data to be ensured and,  more generally, to use and operate it in the 
  31.    same conditions as regards security. 
  32.    
  33.    The fact that you are presently reading this means that you have had
  34.    knowledge of the CeCILL license and that you accept its terms.
  35.    *@=@=@=@ END   LICENSE @=@=@=@*
  36.  
  37. */?><?php  
  38. /**
  39.  * XTPicture Class
  40.  * 
  41.  * 
  42.  * @author SimpliciWeb
  43.  * @version $Id: xt_picture.class.php 781 2007-12-27 13:07:16Z stephanet $
  44.  * @package Common
  45.  * @subpackage FrameWork
  46.  */    
  47. /**
  48.  * Abstract class to manage Pictures
  49.  *
  50.  * @author SimpliciWeb
  51.  * @version $Id: xt_picture.class.php 781 2007-12-27 13:07:16Z stephanet $
  52.  * @package Common
  53.  * @subpackage FrameWork
  54.  */
  55.  
  56. class XTPicture {
  57.  
  58.  /**
  59.   * Database Connexion object
  60.   *
  61.   * @var DbConnexion 
  62.   */
  63.   var $m_object_dbconnexion    = NULL;
  64.  /**
  65.   * SiteInformation Object
  66.   *
  67.   * @var siteInformation 
  68.   */
  69.   var $m_object_siteinformation = NULL;
  70.   
  71.  
  72.  /**
  73.   * SQL Request : Insert
  74.   *
  75.   * @var string 
  76.   */  
  77.   var $req_insert             = "";  
  78.     /**
  79.      * SQL Request : Select by type
  80.      *
  81.      * @var string 
  82.      */
  83.   var $req_select_by_type     = "";
  84.     /**
  85.      * SQL Request : Delete by type
  86.      *
  87.      * @var string 
  88.      */  
  89.   var $req_delete_by_type     = "";
  90.     /**
  91.      * SQL Request : Update position by type
  92.      *
  93.      * @var string 
  94.      */
  95.   var $req_update_position_by_type     = "";
  96.     /**
  97.      * SQL Request : Select
  98.      *
  99.      * @var string 
  100.      */
  101.   var $req_select         = "";
  102.      /**
  103.      * SQL Request : Delete
  104.      *
  105.      * @var string 
  106.      */
  107.   var $req_delete         = "";
  108.      /**
  109.      * SQL Request : Update desc
  110.      *
  111.      * @var string 
  112.      */
  113.   var $req_update_desc = "";
  114.   
  115. /**
  116.  * Supported formats
  117.  *
  118.  * @var array 
  119.  */
  120.   var $m_supported_formats = array();
  121. /**
  122.  * Supported formats string
  123.  *
  124.  * @var array 
  125.  */
  126.     /**
  127.      * Format Object
  128.      *
  129.      * @var Format 
  130.      */
  131.   var $m_object_format = NULL;
  132. /**
  133.  * @var array 
  134.  */
  135.   var $m_types_used = array();
  136. /**
  137.  * @var array 
  138.  */
  139.   var $m_position_used = array();
  140.  
  141.   /**
  142.    * Constructor, init the requests and objects
  143.    *
  144.    * @return XTPicture 
  145.    */
  146.   function XTPicture ({
  147.       global $g_object_loader;
  148.       $this->m_object_siteinformation =$g_object_loader->getSiteInformation();
  149.       $this->m_object_format =$g_object_loader->getFormat();
  150.       $this->m_object_dbconnexion =$g_object_loader->getDbConnexion();
  151.  
  152.    $this->req_insert             = "insert into t_picture(pic_filename,pic_height,pic_width,pic_type,pic_size,".multilang('pic_desc'TRUE).", pic_position ) values ('%s', %d, %d, '%s', %d, '%s', '%s');";  
  153.    $this->req_select_by_type     = "select pic_id, pic_filename, pic_height, pic_width, pic_type, pic_size, ".multilang('pic_desc').", pic_position  from t_picture where pic_type = '%s';";
  154.    $this->req_delete_by_type     = "delete from t_picture where pic_type = '%s';";
  155.    $this->req_update_position_by_type     = "update t_picture set pic_position='%s' where pic_type = '%s';";
  156.  
  157.    $this->req_select         = "select pic_id, pic_filename, pic_height, pic_width, pic_type, pic_size, ".multilang('pic_desc').", pic_position  from t_picture where pic_id = '%d' and pic_type = '%s';";
  158.    $this->req_delete         = "delete from t_picture where pic_id = '%d' and pic_type = '%s';";
  159.  
  160.    $this->req_update_desc = "update t_picture set ".multilang('pic_desc'TRUE)."='%s' where pic_id = '%d' and pic_type = '%s';";
  161.  
  162.  
  163.  
  164.     $sf $this->m_supported_formats;
  165.     // definition des t_picture que l'on peut accepter
  166.     if (function_exists('imagecreatefromgif')) 
  167.       $sf[sizeof($sf)array(1"GIF"'imagecreatefromgif');
  168.  
  169.     if (function_exists('imagecreatefromjpeg')) 
  170.       $sf[sizeof($sf)array(2"JPG"'imagecreatefromjpeg');
  171.        
  172.     if (function_exists('imagecreatefrompng')) 
  173.       $sf[sizeof($sf)array(3"PNG"'imagecreatefrompng');
  174.        
  175.     if (function_exists('imagecreatefromwbmp')) 
  176.       $sf[sizeof($sf)array(15"WBMP"'imagecreatefromwbmp');
  177.     
  178.     if (function_exists('imagecreatefromxbm')) 
  179.       $sf[sizeof($sf)array(16"XBM"'imagecreatefromxbm');
  180.  
  181.     $supported_formats_string "";
  182.     for ($i=0$i<sizeof($sf)$i++{
  183.         if ($i>0)
  184.            $supported_formats_string .= ", ";
  185.         $supported_formats_string .= $sf[$i][1];
  186.     }
  187.     
  188.     $this->m_supported_formats_string = $supported_formats_string;
  189.     $this->m_supported_formats =   $sf;
  190.     
  191.     $this->m_types_used['logo_top_type']        "lt"//logotop
  192.     $this->m_types_used['logo_bill_type']        "lb"//logo for bill
  193.     $this->m_types_used['product_little_type']    "pl"//prodlittle
  194.     $this->m_types_used['product_medium_type']    "pm"//prodmedium
  195.     $this->m_types_used['product_full_type']    "pf"//prodfull
  196.     $this->m_types_used['lang_type']            "la"//lang
  197.     $this->m_types_used['page_little_type']        "rl"//page little
  198.     $this->m_types_used['page_medium_type']        "rm"//page medium
  199.     $this->m_types_used['page_full_type']        "rf"//page full
  200.  
  201.     $this->m_position_used['right''r';
  202.     $this->m_position_used['left''l';
  203.     $this->m_position_used['center''c';
  204.     $this->m_position_used['''';
  205.   }
  206.  
  207.  
  208.     /**
  209.      * Parameter Integrity checker
  210.      *
  211.      * @access private
  212.      * @param string $p_value 
  213.      * @return  bool TRUE if not valid
  214.      */  
  215.   function xIsNotValidDesc($value{
  216.       return $this->m_object_format->isNotVarchar($value128);
  217.   }
  218.       /**
  219.      * Parameter Integrity checker
  220.      *
  221.      * @access private
  222.      * @param string $p_value 
  223.      * @return  bool TRUE if not valid
  224.      */
  225.   function xIsNotValidId($value{
  226.       
  227.     return $this->m_object_format->isNotUnsignedInteger($value11);
  228.     
  229.   }
  230.       /**
  231.      * Parameter Integrity checker
  232.      *
  233.      * @access private
  234.      * @param string $p_value 
  235.      * @return  bool TRUE if not valid
  236.      */
  237.   function xIsNotValidFilename($value{
  238.       return $this->m_object_format->isNotVarchar($value255);
  239.   }
  240.      /**
  241.      * Parameter Integrity checker
  242.      *
  243.      * @access private
  244.      * @param string $p_value 
  245.      * @return  bool TRUE if not valid
  246.      */
  247.   function xIsNotValidHeight($value{
  248.       return $this->m_object_format->isNotUnsignedInteger($value6);
  249.   }
  250.      /**
  251.      * Parameter Integrity checker
  252.      *
  253.      * @access private
  254.      * @param string $p_value 
  255.      * @return  bool TRUE if not valid
  256.      */
  257.   function xIsNotValidWidth($value{
  258.       return $this->m_object_format->isNotUnsignedInteger($value6);
  259.   }
  260.     /**
  261.      * Parameter Integrity checker
  262.      *
  263.      * @access private
  264.      * @param string $p_value 
  265.      * @return  bool TRUE if not valid
  266.      */
  267.   function xIsNotValidSize($value{
  268.       return $this->m_object_format->isNotUnsignedInteger($value11);
  269.   }
  270.      /**
  271.      * Parameter Integrity checker
  272.      *
  273.      * @access private
  274.      * @param string $p_value 
  275.      * @return  bool TRUE if not valid
  276.      */
  277.   function xIsNotValidType(&$value){
  278.      if ((trim($value== ""))
  279.         return false;
  280.           
  281.     if (!$this->m_object_format->isNotVarchar($value50)) {
  282.            return !isset($this->m_types_used[$value]);
  283.        
  284.     
  285.     return true;
  286.   }
  287.     /**
  288.      * Parameter Integrity checker
  289.      *
  290.      * @access private
  291.      * @param string $p_value 
  292.      * @return  bool TRUE if not valid
  293.      */
  294.   function xIsNotValidPositionnement(&$value){
  295.      if ((trim($value== ""))
  296.         return false;
  297.           
  298.        if (!$this->m_object_format->isNotVarchar($value1)) {
  299.            return !isset($this->m_position_used[$value]);
  300.        
  301.     
  302.     return true;
  303.   }
  304.  
  305.  
  306.  
  307.  
  308.   
  309.   
  310.   
  311.   /**
  312.    * Get supported image format
  313.    *
  314.    * @return array 
  315.    */
  316.   function getSupportedImageFormat({
  317.            return $this->m_supported_formats_string;
  318.   }
  319.  
  320.  
  321.   // renvoi false et id=0 : si aucun fichier fourni
  322.   // renvoi true : si une erreur est survenue
  323.   
  324.   //$p_form_src : bool - Si le fichier vient d'un formulaire ou pas
  325.   /**
  326.    * Insert
  327.    * 
  328.    * @access private
  329.    *
  330.    * @param string $p_picture_type 
  331.    * @param array $p_file_array $_FILES
  332.    * @param integer $r_result_id 
  333.    * @param integer $p_next_width 
  334.    * @param integer $p_next_height 
  335.    * @param string $p_desc 
  336.    * @param bool $p_only_one_by_type 
  337.    * @param string $p_pic_position 
  338.    * @param bool $p_force_resize 
  339.    * @param bool $p_form_src 
  340.    * @return bool TRUE on error
  341.    */
  342.   function xInsert($p_picture_type$p_file_array&$r_result_id$p_next_width 0
  343.                               $p_next_height 0
  344.                               $p_desc ""
  345.                               $p_only_one_by_type false,
  346.                               $p_pic_position ""
  347.                               $p_force_resize true
  348.                               $p_form_src true{
  349.  
  350.     // Set result id
  351.       $r_result_id 0;
  352.  
  353.       // Valid input //
  354.     if ($this->xIsNotValidType($p_picture_type)) {
  355.         return onErrorThrow(true,plici_lang("lang_error_field"));
  356.     }
  357.     $image_type_orig $p_picture_type;
  358.     $p_picture_type $this->m_types_used[$p_picture_type];
  359.     if ($this->m_object_format->isNotFileArray($p_file_array)) {
  360.         return onErrorThrow(true,plici_lang("lang_error_field"));
  361.     }
  362.     if ($this->xIsNotValidWidth($p_next_width)) {
  363.         return onErrorThrow(true,plici_lang("lang_error_field"));
  364.     }
  365.     if ($this->xIsNotValidHeight($p_next_height)) {
  366.         return onErrorThrow(true,plici_lang("lang_error_field"));
  367.     }
  368.     if ($this->xIsNotValidDesc($p_desc)) {
  369.         return onErrorThrow(true,plici_lang("lang_error_field"));
  370.     }
  371.     if ($this->xIsNotValidPositionnement($p_pic_position)) {
  372.         return onErrorThrow(true,plici_lang("lang_error_field"));
  373.     }
  374.       $p_pic_position $this->m_position_used[$p_pic_position];
  375.  
  376.  
  377.  
  378.     if (($p_file_array['error'!= 0&& (trim($p_file_array['name']!= ""))   {
  379.       return onErrorThrow(true,plici_lang("lang_error_imagetransferttoobig"));
  380.     
  381.  
  382.     if ($p_file_array['error'!= )   {
  383.         // aucun fichier fourni donc on ne fait rien
  384.         //$this->setId(0);
  385.         return false;
  386.     }
  387.  
  388.     //Essaies de charger la taille de m'image qu'on viend de télécharger
  389.  
  390.     if (($p_form_src&& (!is_uploaded_file($p_file_array['tmp_name']))) {
  391.        onErrorThrow(true,plici_lang("lang_error_imagetransfert"));
  392.        //echo("isn't uploaded file");
  393.        return true;
  394.     }
  395.  
  396.     // All input are valid
  397.  
  398.  
  399.     // Retrieve image size
  400.     $size getimagesize($p_file_array['tmp_name']);
  401.     if (sizeof($size== 0{
  402.         return onErrorThrow(true,plici_lang("lang_error_imageformat").":".$p_file_array['tmp_name']);
  403.     }
  404.       
  405.     // verification du type de l'image 
  406.     $picture_type $size[2];//exif_imagetype($p_file_array['tmp_name']);
  407.     //echo("(".$picture_type.")");
  408.  
  409.     $is_supported_image_format false;
  410.  
  411.  
  412.     $sf $this->m_supported_formats;
  413.     $to_evaluate_create_image "";
  414.     $ext_src "";
  415.     for ($i=0$i<sizeof($sf)$i++{
  416.         if ($picture_type == $sf[$i][0]{
  417.            $is_supported_image_format true;
  418.            $ext_src $sf[$i][1]// Set source picture extension
  419.            $to_evaluate_create_image $sf[$i][2];
  420.            break;
  421.         }
  422.     }
  423.     
  424.     if (!$is_supported_image_format{
  425.         onErrorThrow(true,plici_lang("lang_error_imageformat"));
  426.          //echo("not supported file format");
  427.          return true
  428.     }
  429.               
  430.     
  431.     
  432.     $current_width =  $size[0];
  433.     $current_height $size[1];
  434.     
  435.     $must_destroy_temp_file false;
  436.     
  437.     $have_got_to_resize false;
  438.     
  439.     if ((( $current_width <= $p_next_width&& ($current_height <= $p_next_height)) && !$p_force_resize)
  440.       $have_got_to_resize false;
  441.     else      
  442.       $have_got_to_resize true;
  443.  
  444.     if ((($p_next_width == 0&&  ($p_next_height == 0)))
  445.       $have_got_to_resize false;
  446.       
  447.     if ($have_got_to_resize{
  448.           
  449.           // Resolve new size
  450.           $width_ratio  $p_next_width/$current_width;
  451.           $height_ratio $p_next_height/$current_height;
  452.       
  453.           $ratio 1;
  454.           if ($p_next_height == 0{
  455.             $ratio $width_ratio;
  456.           else if ($p_next_width == 0{
  457.             $ratio $height_ratio;
  458.           else  {
  459.             if ($width_ratio $height_ratio)
  460.               $ratio $width_ratio;
  461.             else
  462.               $ratio $height_ratio;
  463.           }
  464.       
  465.           $new_width  =$ratio*$current_width;
  466.           $new_height =$ratio*$current_height;
  467.  
  468.             // Determine destination extension
  469.         $ext_dst ""// After this switch can be only have 2 value:: GIF or JPG
  470.         switch ($ext_src)
  471.         {
  472.             case "GIF":
  473.                         if (imagetypes(IMG_GIF)
  474.                         {
  475.                             // Can create gif for output
  476.                             $ext_dst "GIF";
  477.                             break;
  478.                         else {
  479.                             // Get default value
  480.                         }
  481.             case "JPG":
  482.             default:
  483.                     $ext_dst "JPG";
  484.                     break;
  485.         }
  486.  
  487.         // Set source image in $src_im var
  488.         eval("\$src_im = ".$to_evaluate_create_image."(\$p_file_array['tmp_name']);");
  489.     
  490.         // Set new name
  491.         $next_name $p_file_array['tmp_name'].'_resized.'.strtolower($ext_dst);
  492.  
  493.         // Create picture by type
  494.         switch ($ext_dst)
  495.         {
  496.             case "GIF":
  497.                             // Transform picture in reduce gif picture
  498.                         // Create destination image
  499.                         $dst_im imagecreate($new_width$new_height);
  500.                         // Resize
  501.                         if (function_exists('imagecopyresampled'))
  502.                           imagecopyresampled ($dst_im$src_im0000$new_width$new_height$current_width$current_height);
  503.                         else 
  504.                           imagecopyresized($dst_im$src_im0000$new_width$new_height$current_width$current_height );
  505.  
  506.                         // Save picture
  507.                         imagegif($dst_im$next_name);
  508.                         break;
  509.             case "JPG":
  510.                         // Transform picture in reduce jpg picture
  511.                     // Create destination image
  512.                     $dst_im imagecreatetruecolor($new_width$new_height);
  513.                     // Resize
  514.                     if (function_exists('imagecopyresampled'))
  515.                       imagecopyresampled ($dst_im$src_im0000$new_width$new_height$current_width$current_height);
  516.                     else 
  517.                       imagecopyresized($dst_im$src_im0000$new_width$new_height$current_width$current_height );
  518.  
  519.                     // Save picture
  520.                     imagejpeg($dst_im$next_name100);
  521.                     break;
  522.         }
  523.  
  524.         // Replace picture by rezised picture
  525.       $p_file_array['tmp_name'$next_name;
  526.       $p_file_array['size'filesize($next_name);
  527.  
  528.       // Must detroy temp file
  529.       $must_destroy_temp_file true;
  530.  
  531.       // Reload size of resized picture
  532.       $size getimagesize($p_file_array['tmp_name']);
  533.       if (sizeof($size== 0{
  534.             unlink($p_file_array['tmp_name']);
  535.             return true;
  536.       }
  537.  
  538.       // Free memory used by picture transformation
  539.       imagedestroy($src_im);
  540.       imagedestroy($dst_im);
  541.  
  542.     else {
  543.         // Don't have to resize
  544.             // Don't change the extension
  545.         $ext_dst$ext_src;
  546.     }
  547.  
  548.     // Move picture //
  549.  
  550.         // Define picture id
  551.     if (function_exists('microtime')) {
  552.         $array_stamp explode(" "microtime());
  553.         $stamp $array_stamp[0];
  554.         
  555.     else {
  556.         //Faut boucler sinon c'est trop rapide et on peut avoir 2 ids ==
  557.         for ($i=0$i<1000$i++{
  558.         }
  559.         $stamp strtotime ("now")
  560.     }
  561.     $picture_id $stamp."-".$_SERVER["REMOTE_ADDR"]
  562.     $picture_id str_replace("."""$picture_id)
  563.     
  564.  
  565.  
  566.         // Set filename
  567.     $upload_dir $this->m_object_siteinformation->getPictureFilePath()
  568.     $upload_filename $p_picture_type.'_'.$size[0].'_'.$size[1].'_'.$p_file_array['size'].'_'.$picture_id.'.'.strtolower($ext_dst);
  569.     $upload_file $upload_dir.$upload_filename
  570.  
  571.     if (file_exists($upload_dir))
  572.         @plici_mkdir($upload_dir);
  573.     
  574. //    echo($p_file_array['tmp_name']."<br />");
  575. //    echo($upload_file."<br />");
  576.     if (!copy($p_file_array['tmp_name']$upload_file)) {
  577.         if ($must_destroy_temp_file)
  578.           unlink($p_file_array['tmp_name']);
  579.  
  580.       onErrorThrow(true,plici_lang("lang_error_imagecopyproblem"));
  581.  
  582.         return true;
  583.     }
  584.     
  585.     
  586.     // si le fichier doit être le seul à avoir ce type en BD
  587.     if ($p_only_one_by_type{
  588.        if ($this->xDeleteByType($image_type_orig)){
  589.           if ($must_destroy_temp_file)
  590.               unlink($p_file_array['tmp_name']);
  591.  
  592.           onErrorThrow(true,plici_lang("lang_error_imagedeleteold"));
  593.  
  594.           return true;
  595.        }
  596.     }
  597.     
  598.     $parameters array();
  599.     $parameters[sizeof($parameters)$upload_filename;
  600.     $parameters[sizeof($parameters)$size[1];
  601.     $parameters[sizeof($parameters)$size[0];
  602.     $parameters[sizeof($parameters)$p_picture_type;
  603.     $parameters[sizeof($parameters)$p_file_array['size'];
  604.     $parameters[sizeof($parameters)$p_desc;
  605.     $parameters[sizeof($parameters)$p_pic_position;
  606.     
  607.     
  608.     
  609.     if ($this->m_object_dbconnexion->makeSqlQueryWithId($this->req_insert$parameters$result$r_result_id)) {
  610.       if ($must_destroy_temp_file)
  611.           unlink($p_file_array['tmp_name']);
  612.  
  613.       unlink($upload_file);
  614.  
  615.       onErrorThrow(true,plici_lang("lang_error_imagedatabase"));
  616.  
  617.       return true;
  618.     }
  619.     
  620.     if ($must_destroy_temp_file)
  621.         unlink($p_file_array['tmp_name']);
  622.  
  623.     //On va stocker l'identifiant de l'image apres son insertion
  624.     //$this->setId(mysql_insert_id());
  625.     return false;
  626.   }
  627.  
  628.  
  629.  
  630.  
  631.   /**
  632.    * Get by type
  633.    *
  634.    * @access private
  635.    * @param string $p_picture_type 
  636.    * @param array $r_result 
  637.    * @param string $p_database_selected 
  638.    * @return bool TRUE on error
  639.    */
  640.   function xGetByType($p_picture_type&$r_result$p_database_selected=""{
  641.     
  642.     $r_result array();
  643.  
  644.     if ($this->xIsNotValidType($p_picture_type)) {
  645.         return onErrorThrow(true,plici_lang("lang_error_field"));
  646.     }
  647.     $p_picture_type $this->m_types_used[$p_picture_type];
  648.     
  649.    
  650.     $parameters array();
  651.     $parameters[sizeof($parameters)$p_picture_type;
  652.  
  653.     if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select_by_type$parameters$result$p_database_selected))
  654.       return true;
  655.     
  656.     while ($row mysql_fetch_row($result)) {
  657.        $sousTableaux array();
  658.        $sousTableaux['pic_id'$row[0];
  659.        $sousTableaux['pic_filename'$row[1];
  660.        $sousTableaux['pic_height']   $row[2];
  661.        $sousTableaux['pic_width']    $row[3];
  662.        $sousTableaux['pic_type']     $row[4];
  663.        $sousTableaux['pic_size']     $row[5];
  664.        $sousTableaux['pic_desc']     $this->m_object_dbconnexion->translate("DB_TO_ALT"$row[6]);
  665.        $sousTableaux['pic_position']     $row[7];
  666.        //$sousTableaux['pic_file_path'] = $this->m_object_siteinformation->getPictureFilePath().$row[1];
  667.        //$sousTableaux['pic_file_path'] = $this->m_object_siteinformation->getViewRootPath();
  668.        if (""==$p_database_selected)
  669.        {
  670.                $sousTableaux['pic_file_path'$this->m_object_siteinformation->getPictureFilePath().$row[1];
  671.        else {
  672.                $sousTableaux['pic_file_path'$this->m_object_siteinformation->getViewRootPath().$p_database_selected."/".$this->m_object_siteinformation->getPictureDirectoryName().$row[1];
  673.                $sousTableaux['pic_file_path'$this->m_object_siteinformation->getPictureFilePathSpecified($p_database_selected).$row[1];
  674.        }
  675.        //$sousTableaux['pic_file_path'] .= $row[1];
  676.        $sousTableaux['pic_http_path'$this->m_object_siteinformation->getPictureHttpPath().$row[1];
  677.        
  678.        $r_result[sizeof($r_result)$sousTableaux;
  679.     }
  680.  
  681.     return false;
  682.   }
  683.  
  684.  
  685.   /**
  686.    * Provide an array with all the picture properties
  687.    *
  688.    * Va renvoyer un tableaux contenant toutes les informations necessaires à l'affichage d'une image
  689.    * Entree:
  690.    *    int : represente l'identifiant de l'image
  691.    * Sortie:
  692.    *    array
  693.    * @access private
  694.    * @param integer $id 
  695.    * @param string $p_picture_type 
  696.    * @param array $r_result 
  697.    * @return bool TRUE on error
  698.    */
  699.   function xGet($id$p_picture_type&$r_result{
  700. //echo "\n<br />Debug - Class image - Recherche image par Id : ".$id;
  701.     $r_result array();
  702.  
  703.     // Valid input
  704.     if ($this->xIsNotValidId($id)) {
  705.         return onErrorThrow(true,plici_lang("lang_error_field"));
  706.     }
  707.     if ($this->xIsNotValidType($p_picture_type)) {
  708.         return onErrorThrow(true,plici_lang("lang_error_field"));
  709.     }
  710.     $p_picture_type $this->m_types_used[$p_picture_type];
  711.  
  712.     // Detect if site is in website group
  713.     // Declare var
  714.     $sitename "";
  715.     if ($this->m_object_dbconnexion->mustWeCheckWebsiteMasterGroup("t_picture"$p_picture_type))
  716.     {
  717.             // Get master
  718.         $master_website_group "";
  719.         if ($this->m_object_dbconnexion->getWebsiteGroupMaster($master_website_group$this->m_object_siteinformation->getDatabaseSiteName()))
  720.             return true;
  721.  
  722.         if (0<strlen(trim($master_website_group)))
  723.         {
  724.             // Get domaine name
  725.                 // Load object
  726.             global $g_object_loader;
  727.             $object_databaseconnect =$g_object_loader->getDatabaseconnectSa();
  728.             if ($object_databaseconnect->getSiteName($sitename$master_website_group))
  729.                 return true;
  730.             if (0<strlen(trim($sitename)))
  731.             {
  732.                 if ($this->m_object_siteinformation->isNotLocalhost())
  733.                     $sitename "http://".$sitename;
  734.                     else $sitename "http://".$object_databaseconnect->getDbcSitenamePrefixForLocal().$sitename;
  735.             }
  736.         }
  737.     }
  738.  
  739.     if ($id == 0{
  740.         $r_result['pic_id'0;
  741.         
  742.         //        il faudra changer les informations de la picture pas d'image
  743.         //        les lire dans le fichier no_photo.gif
  744.         //         et mettre les params en variables membres
  745.                 $r_result['pic_height']   '83';
  746.                 $r_result['pic_width']    '82';
  747.         
  748.         //echo_net($this->m_object_siteinformation->getIHavePersonalNoPhoto()?"oui":"non");
  749.  
  750.             
  751.         $r_result['pic_http_path'$sitename.$this->m_object_siteinformation->getPictureHttpPath().'detail/no_photo.gif';
  752.         //echo_net($r_result['pic_http_path']);
  753.         
  754.         return false;
  755.     }
  756.  
  757.  
  758.  
  759.  
  760.     $parameters array();
  761.     $parameters[sizeof($parameters)$id;
  762.     $parameters[sizeof($parameters)$p_picture_type;
  763.     
  764.     
  765.     
  766.     if ($this->m_object_dbconnexion->makeSqlQuery($this->req_select$parameters$result))
  767.       return true;
  768.     
  769.     $row mysql_fetch_row($result);
  770.     $r_result['pic_id'$row[0];
  771.     $r_result['pic_filename'$row[1];
  772.     $r_result['pic_height']   $row[2];
  773.     $r_result['pic_width']    $row[3];
  774.     $r_result['pic_type']     $row[4];
  775.     $r_result['pic_size']     $row[5];
  776.     $r_result['pic_desc']     $this->m_object_dbconnexion->translate("DB_TO_ALT"$row[6]);
  777.     $r_result['pic_position']     $row[7];
  778.     $r_result['pic_file_path'$this->m_object_siteinformation->getPictureFilePath().$row[1];
  779.     $r_result['pic_http_path'$sitename.$this->m_object_siteinformation->getPictureHttpPath().$row[1];
  780.     
  781.      return false;
  782.  
  783.   }// getImageById
  784.  
  785.  
  786.   
  787.   /**
  788.    * Update position by type
  789.    *
  790.    * @param string $p_picture_type 
  791.    * @param string $p_new_position 
  792.    * @return bool TRUE on error
  793.    */
  794.   function xUpdatePositionByType($p_picture_type$p_new_position{
  795.     
  796.     if ($this->xIsNotValidType($p_picture_type)) {
  797.         return onErrorThrow(true,plici_lang("lang_error_field"));
  798.     }
  799.     $p_picture_type $this->m_types_used[$p_picture_type];
  800.     
  801.     if ($this->xIsNotValidPositionnement($p_new_position)) {
  802.         return onErrorThrow(true,plici_lang("lang_error_field"));
  803.     }
  804.     $p_new_position $this->m_position_used[$p_new_position];
  805.     
  806.     // suppression logique des t_picture en BD 
  807.     $parameters array();
  808.     $parameters[sizeof($parameters)$p_new_position;
  809.     $parameters[sizeof($parameters)$p_picture_type;
  810.  
  811.     return $this->m_object_dbconnexion->makeSqlQuery($this->req_update_position_by_type$parameters$result);
  812.  
  813.   }
  814.  
  815.   
  816.   
  817.   
  818.   /**
  819.    * Delete by type
  820.    *
  821.    * @access private
  822.    * @param string $p_picture_type 
  823.    * @return bool TRUE on error
  824.    */
  825.   function xDeleteByType($p_picture_type{
  826.  
  827.     if ($this->xIsNotValidType($p_picture_type)) {
  828.         return onErrorThrow(true,plici_lang("lang_error_field"));
  829.     }
  830.     $orig_picture_type $p_picture_type;
  831.     $p_picture_type $this->m_types_used[$p_picture_type];
  832.    
  833.     
  834.     // suppression physique des fichiers
  835.     $file_to_delete array();
  836.     $this->xGetByType($orig_picture_type$file_to_delete);
  837.     for ($i=0$i<sizeof($file_to_delete)$i++{
  838.         if (file_exists($file_to_delete[$i]['pic_file_path']))
  839.             @unlink($file_to_delete[$i]['pic_file_path']);
  840.     }
  841.     
  842.  
  843.     // suppression logique des t_picture en BD 
  844.     $parameters array();
  845.     $parameters[sizeof($parameters)$p_picture_type;
  846.     return $this->m_object_dbconnexion->makeSqlQuery($this->req_delete_by_type$parameters$result);
  847.   }
  848.  
  849.  
  850.  
  851.  
  852.   /**
  853.    * Delete
  854.    *
  855.    * @access private
  856.    * @param integer $p_picture_id 
  857.    * @param string $p_picture_type 
  858.    * @return bool TRUE on error
  859.    */
  860.   function xDelete($p_picture_id$p_picture_type{
  861.  
  862.       //echo("Avant le delete <br />");
  863.     if ($this->xIsNotValidId($p_picture_id)) {
  864.         return onErrorThrow(true,plici_lang("lang_error_field"));
  865.     }
  866.     if ($this->xIsNotValidType($p_picture_type)) {
  867.         return onErrorThrow(true,plici_lang("lang_error_field"));
  868.     }
  869.     $picture_orig_type $p_picture_type;
  870.     $p_picture_type $this->m_types_used[$p_picture_type];
  871.  
  872.       //echo("après verification <br />");
  873.    
  874.     // suppression physique des fichiers
  875.     $file_to_delete array();
  876.     $this->xGet($p_picture_id$picture_orig_type$file_to_delete);
  877.  
  878.     if ((0<strlen(trim($file_to_delete['pic_file_path']))) && (file_exists($file_to_delete['pic_file_path'])))
  879.     {
  880.         if (!@unlink($file_to_delete['pic_file_path']))
  881.             trigger_error("PLICI - Unable to delete: *".$file_to_delete['pic_file_path']."*");
  882.     }
  883.  
  884.     
  885.       //echo("après get et unlink <br />");
  886.  
  887.     // suppression logique des t_picture en BD 
  888.     $parameters array();
  889.     $parameters[sizeof($parameters)$p_picture_id;
  890.     $parameters[sizeof($parameters)$p_picture_type;
  891.     return $this->m_object_dbconnexion->makeSqlQuery($this->req_delete$parameters$result);
  892.  
  893.   }
  894.  
  895.  
  896.  
  897.   /**
  898.    * Udpate desc
  899.    *
  900.    * @param integer $p_id 
  901.    * @param string $p_picture_type 
  902.    * @param string $p_desc 
  903.    * @return bool TRUE on error
  904.    */
  905.   function xUpdateDesc($p_id$p_picture_type$p_desc{
  906.  
  907.       if ($this->xIsNotValidId($p_id)) {
  908.         return onErrorThrow(true,plici_lang("lang_error_field"));
  909.     }
  910.       if ($this->xIsNotValidDesc($p_desc)) {
  911.         return onErrorThrow(true,plici_lang("lang_error_field"));
  912.     }
  913.     if ($this->xIsNotValidType($p_picture_type)) {
  914.         return onErrorThrow(true,plici_lang("lang_error_field"));
  915.     }
  916.     $picture_orig_type $p_picture_type;
  917.     $p_picture_type $this->m_types_used[$p_picture_type];
  918.  
  919.      $parameters array();
  920.     //echo("$p_desc, $p_id, $p_picture_type<br />");
  921.     
  922.     
  923.     $parameters[sizeof($parameters)$p_desc;
  924.     $parameters[sizeof($parameters)$p_id;
  925.     $parameters[sizeof($parameters)$p_picture_type;
  926.     
  927.     return onErrorThrow($this->m_object_dbconnexion->makeSqlQuery($this->req_update_desc$parameters$result),plici_lang("lang_error_imagedescupdate"));
  928.   }
  929.  
  930.    /**
  931.     * Get Ratio
  932.     *
  933.     * @param array $p_array_picture 
  934.     * @param integer $p_next_width 
  935.     * @param integer $p_next_height 
  936.     * @param integer $r_ratio 
  937.     * @return bool TRUE on error
  938.     */
  939.    function getRatio($p_array_picture$p_next_width$p_next_height&$r_ratio{
  940.        $ratio1 $p_next_width/$p_array_picture['pic_width'];
  941.        $ratio2 $p_next_height/$p_array_picture['pic_height'];
  942.        
  943.        if ($ratio1 $ratio2)
  944.          $ratio $ratio1;
  945.        else
  946.          $ratio $ratio2;
  947.    
  948.        $r_ratio $ratio;
  949.        
  950.        return false;
  951.    }  
  952.   
  953. }
  954.  
  955.  
  956. ?>

Documentation generated on Tue, 25 Mar 2008 15:37:37 +0100 by phpDocumentor 1.3.2