diff --git a/htdocs/admin/company.php b/htdocs/admin/company.php index 9067c1883d7..43793883069 100644 --- a/htdocs/admin/company.php +++ b/htdocs/admin/company.php @@ -27,6 +27,7 @@ require("./pre.inc.php"); require_once(DOL_DOCUMENT_ROOT."/lib/admin.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/company.lib.php"); +require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php"); $langs->load("admin"); $langs->load("companies"); @@ -34,6 +35,7 @@ $langs->load("companies"); if (!$user->admin) accessforbidden(); + if ( (isset($_POST["action"]) && $_POST["action"] == 'update') || (isset($_POST["action"]) && $_POST["action"] == 'updateedit') ) { diff --git a/htdocs/conf/conf.class.php b/htdocs/conf/conf.class.php index f0f437d73bc..887b0d47f92 100644 --- a/htdocs/conf/conf.class.php +++ b/htdocs/conf/conf.class.php @@ -76,7 +76,7 @@ class Conf */ function setValues($db) { - dolibarr_syslog("functions.inc.php::setValues"); + dolibarr_syslog("Conf::setValues"); // Par defaut, a oui $this->global->PRODUIT_CONFIRM_DELETE_LINE=1; diff --git a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php index 81a5cb72cfb..1f153fb8d45 100644 --- a/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php +++ b/htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php @@ -17,19 +17,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ */ /** \file htdocs/expedition/mods/pdf/ModelePdfExpedition.class.php \ingroup shipping \brief Fichier contenant la classe mère de generation des expeditions - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once DOL_DOCUMENT_ROOT.'/includes/fpdf/DolibarrPdfBarCode.class.php'; diff --git a/htdocs/fourn/product/photos.php b/htdocs/fourn/product/photos.php index 3a5b1f51439..a33790492eb 100644 --- a/htdocs/fourn/product/photos.php +++ b/htdocs/fourn/product/photos.php @@ -15,17 +15,13 @@ * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. - * - * $Id$ - * $Source$ - * */ /** \file htdocs/fourn/product/photos.php \ingroup product \brief Page de la fiche produit - \version $Revision$ + \version $Id$ */ require("./pre.inc.php"); diff --git a/htdocs/html.formmail.class.php b/htdocs/html.formmail.class.php index 34ee99320a0..96b9de2e0b1 100644 --- a/htdocs/html.formmail.class.php +++ b/htdocs/html.formmail.class.php @@ -23,7 +23,7 @@ */ require_once(DOL_DOCUMENT_ROOT ."/html.form.class.php"); -require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); +require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"); /** \class FormMail diff --git a/htdocs/includes/fckeditor/editor/filemanager/connectors/php/config.php b/htdocs/includes/fckeditor/editor/filemanager/connectors/php/config.php index 40325d14416..58f4bfcb593 100644 --- a/htdocs/includes/fckeditor/editor/filemanager/connectors/php/config.php +++ b/htdocs/includes/fckeditor/editor/filemanager/connectors/php/config.php @@ -34,7 +34,7 @@ define('DOL_URL_ROOT', $pos); /* $conf->syslog->enabled=1; define('SYSLOG_FILE','c:/log/dolibarr/dolibarr.log'); -require_once("../../../../../../../../lib/functions.inc.php"); +require_once("../../../../../../../../lib/functions.lib.php"); dolibarr_syslog("eee".$conf->fckeditor->dir_output); */ diff --git a/htdocs/includes/modules/barcode/modules_barcode.php b/htdocs/includes/modules/barcode/modules_barcode.php index b99d6366110..bc7f8c565c8 100644 --- a/htdocs/includes/modules/barcode/modules_barcode.php +++ b/htdocs/includes/modules/barcode/modules_barcode.php @@ -18,18 +18,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ */ /** \file htdocs/includes/modules/barcode/modules_barcode.php \ingroup barcode \brief Fichier contenant la classe mère de generation des codes barres - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); /** diff --git a/htdocs/includes/modules/commande/modules_commande.php b/htdocs/includes/modules/commande/modules_commande.php index be7648f551d..bb611b14732 100644 --- a/htdocs/includes/modules/commande/modules_commande.php +++ b/htdocs/includes/modules/commande/modules_commande.php @@ -18,10 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ - * */ /** @@ -29,10 +25,10 @@ \ingroup commande \brief Fichier contenant la classe mère de generation des commandes en PDF et la classe mère de numérotation des commandes - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); // requis car utilise par les classes qui heritent require_once(DOL_DOCUMENT_ROOT.'/discount.class.php'); diff --git a/htdocs/includes/modules/dons/modules_don.php b/htdocs/includes/modules/dons/modules_don.php index 2f91037343b..04e54d2f4c0 100644 --- a/htdocs/includes/modules/dons/modules_don.php +++ b/htdocs/includes/modules/dons/modules_don.php @@ -27,7 +27,7 @@ \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT."/don.class.php"); diff --git a/htdocs/includes/modules/export/modules_export.php b/htdocs/includes/modules/export/modules_export.php index f3b4a74fadf..4da9d54adcb 100644 --- a/htdocs/includes/modules/export/modules_export.php +++ b/htdocs/includes/modules/export/modules_export.php @@ -16,19 +16,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ */ /** \file htdocs/includes/modules/export/modules_export.php \ingroup export \brief Fichier contenant la classe mère de generation des exports - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); /** diff --git a/htdocs/includes/modules/facture/modules_facture.php b/htdocs/includes/modules/facture/modules_facture.php index cf0f7cafa9d..6289b2e161a 100644 --- a/htdocs/includes/modules/facture/modules_facture.php +++ b/htdocs/includes/modules/facture/modules_facture.php @@ -18,9 +18,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ */ /** @@ -28,10 +25,10 @@ \ingroup facture \brief Fichier contenant la classe mère de generation des factures en PDF et la classe mère de numérotation des factures - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT."/product.class.php"); require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); // Requis car utilisé dans les classes qui héritent diff --git a/htdocs/includes/modules/fichinter/modules_fichinter.php b/htdocs/includes/modules/fichinter/modules_fichinter.php index 5c2e43daedc..0cbf038e7e5 100644 --- a/htdocs/includes/modules/fichinter/modules_fichinter.php +++ b/htdocs/includes/modules/fichinter/modules_fichinter.php @@ -16,10 +16,6 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ - * */ /** @@ -27,10 +23,10 @@ \ingroup ficheinter \brief Fichier contenant la classe mère de generation des fiches interventions en PDF et la classe mère de numérotation des fiches interventions - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); diff --git a/htdocs/includes/modules/mailings/modules_mailings.php b/htdocs/includes/modules/mailings/modules_mailings.php index 3ce7d55e80f..12b0a77060a 100644 --- a/htdocs/includes/modules/mailings/modules_mailings.php +++ b/htdocs/includes/modules/mailings/modules_mailings.php @@ -26,7 +26,7 @@ \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); /** diff --git a/htdocs/includes/modules/propale/modules_propale.php b/htdocs/includes/modules/propale/modules_propale.php index 6e083b9d1bf..614eee16cb0 100644 --- a/htdocs/includes/modules/propale/modules_propale.php +++ b/htdocs/includes/modules/propale/modules_propale.php @@ -26,7 +26,7 @@ \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); require_once(DOL_DOCUMENT_ROOT."/compta/bank/account.class.php"); // Requis car utilisé dans les classes qui héritent diff --git a/htdocs/includes/modules/security/generate/modules_genpassword.php b/htdocs/includes/modules/security/generate/modules_genpassword.php index 15a4b7e95d3..21f7ba31122 100644 --- a/htdocs/includes/modules/security/generate/modules_genpassword.php +++ b/htdocs/includes/modules/security/generate/modules_genpassword.php @@ -15,19 +15,16 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * or see http://www.gnu.org/ - * - * $Id$ - * $Source$ */ /** \file htdocs/includes/modules/facture/modules_genpassword.php \ingroup core \brief Fichier contenant la classe mère de generation des mots de passe - \version $Revision$ + \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); /** diff --git a/htdocs/install/etape5.php b/htdocs/install/etape5.php index 72660fee652..1fbb05a75e7 100644 --- a/htdocs/install/etape5.php +++ b/htdocs/install/etape5.php @@ -88,7 +88,7 @@ if ($_POST["action"] == "set" || $_POST["action"] == "upgrade") $error=0; // on décode le mot de passe de la base si besoin - require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); + require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"); if (isset($dolibarr_main_db_encrypted_pass) && $dolibarr_main_db_encrypted_pass) $dolibarr_main_db_pass = dolibarr_decode($dolibarr_main_db_encrypted_pass); $conf->db->type = $dolibarr_main_db_type; diff --git a/htdocs/install/inc.php b/htdocs/install/inc.php index c2dde69e0e3..d491bd2645e 100644 --- a/htdocs/install/inc.php +++ b/htdocs/install/inc.php @@ -25,7 +25,7 @@ */ require_once('../translate.class.php'); -require_once('../lib/functions.inc.php'); +require_once('../lib/functions.lib.php'); require_once('../lib/admin.lib.php'); // DOL_DOCUMENT_ROOT has been defined in function.inc.php to '..' diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.lib.php similarity index 92% rename from htdocs/lib/functions.inc.php rename to htdocs/lib/functions.lib.php index ac38855cdcc..0cdb0fc81f5 100644 --- a/htdocs/lib/functions.inc.php +++ b/htdocs/lib/functions.lib.php @@ -24,7 +24,7 @@ */ /** - \file htdocs/lib/functions.inc.php + \file htdocs/lib/functions.lib.php \brief Ensemble de fonctions de base de dolibarr sous forme d'include \version $Id$ */ @@ -295,7 +295,7 @@ function dolibarr_set_user_page_param($db, &$user, $url='', $tab) $i++; } $sql.= ")"; - dolibarr_syslog("functions.inc.php::dolibarr_set_user_page_param $sql"); + dolibarr_syslog("functions.lib.php::dolibarr_set_user_page_param $sql"); $resql=$db->query($sql); if (! $resql) @@ -315,7 +315,7 @@ function dolibarr_set_user_page_param($db, &$user, $url='', $tab) if ($url) $sql.= " '".urlencode($url)."',"; else $sql.= " '',"; $sql.= " '".$key."','".addslashes($value)."');"; - dolibarr_syslog("functions.inc.php::dolibarr_set_user_page_param $sql"); + dolibarr_syslog("functions.lib.php::dolibarr_set_user_page_param $sql"); $result=$db->query($sql); if (! $result) @@ -1345,7 +1345,7 @@ function restrictedArea($user, $feature='societe', $objectid=0, $dbtablename='') } else { - dolibarr_syslog("Functions.inc.php::restrictedArea sql=".$sql, LOG_ERROR); + dolibarr_syslog("functions.lib.php::restrictedArea sql=".$sql, LOG_ERROR); accessforbidden(); } } @@ -2151,7 +2151,7 @@ function get_exdir($num,$level=3) */ function create_exdir($dir) { - dolibarr_syslog("functions.inc.php::create_exdir: dir=$dir",LOG_INFO); + dolibarr_syslog("functions.lib.php::create_exdir: dir=$dir",LOG_INFO); if (@is_dir($dir)) return 0; @@ -2172,18 +2172,18 @@ function create_exdir($dir) { if (! @is_dir($ccdir)) { - dolibarr_syslog("functions.inc.php::create_exdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.",LOG_DEBUG); + dolibarr_syslog("functions.lib.php::create_exdir: Directory '".$ccdir."' does not exists or is outside open_basedir PHP setting.",LOG_DEBUG); umask(0); if (! @mkdir($ccdir, 0755)) { // Si le is_dir a renvoyé une fausse info, alors on passe ici. - dolibarr_syslog("functions.inc.php::create_exdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING); + dolibarr_syslog("functions.lib.php::create_exdir: Fails to create directory '".$ccdir."' or directory already exists.",LOG_WARNING); $nberr++; } else { - dolibarr_syslog("functions.inc.php::create_exdir: Directory '".$ccdir."' created",LOG_DEBUG); + dolibarr_syslog("functions.lib.php::create_exdir: Directory '".$ccdir."' created",LOG_DEBUG); $nberr=0; // On remet a zéro car si on arrive ici, cela veut dire que les échecs précédents peuvent etre ignorés $nbcreated++; } @@ -2211,7 +2211,7 @@ function create_exdir($dir) */ function dolibarr_dir_list($path, $types="all", $recursive=0, $filter="", $excludefilter="", $sortcriteria="name", $sortorder=SORT_ASC) { - dolibarr_syslog("functions.inc.php::dolibarr_dir_list $path"); + dolibarr_syslog("functions.lib.php::dolibarr_dir_list $path"); $loaddate=false; $loadsize=false; @@ -2917,219 +2917,6 @@ function print_date_range($date_start,$date_end) } } -/* - * \brief Création de 2 vignettes a partir d'un fichier image (une small et un mini) - * \brief Les extension prise en compte sont jpg et png - * \param file Chemin du fichier image a redimensionner - * \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut) - * \param maxHeight Hauteur maximum que dois faire l'image (120 par défaut) - * \param extName Extension pour différencier le nom de la vignette - * \param quality Qualité de compression (0=worst, 100=best) - * \return string Chemin de la vignette - */ -function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50) -{ - global $langs; - - dolibarr_syslog("functions.inc::vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality); - - // Nettoyage parametres - $file=trim($file); - - // Vérification des paramétres - if (! $file) - { - // Si le fichier n'a pas été indiqué - return 'Bad parameter file'; - } - elseif (! file_exists($file)) - { - // Si le fichier passé en paramétre n'existe pas - return $langs->trans("ErrorFileNotFound",$file); - } - elseif(image_format_supported($file) < 0) - { - return 'This file '.$file.' does not seem to be an image format file name.'; - } - elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < 0){ - // Si la largeur max est incorrecte (n'est pas numérique, est vide, ou est inférieure a 0) - return 'Valeur de la largeur incorrecte.'; - } - elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < 0){ - // Si la hauteur max est incorrecte (n'est pas numérique, est vide, ou est inférieure a 0) - return 'Valeur de la hauteur incorrecte.'; - } - - $fichier = realpath($file); // Chemin canonique absolu de l'image - $dir = dirname($file).'/'; // Chemin du dossier contenant l'image - $dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes - - $infoImg = getimagesize($fichier); // Récupération des infos de l'image - $imgWidth = $infoImg[0]; // Largeur de l'image - $imgHeight = $infoImg[1]; // Hauteur de l'image - - // Si l'image est plus petite que la largeur et la hauteur max, on ne crée pas de vignette - if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) - { - // On cree toujours les vignettes - dolibarr_syslog("File size is smaller than thumb size",LOG_DEBUG); - //return 'Le fichier '.$file.' ne nécessite pas de création de vignette'; - } - - $imgfonction=''; - switch($infoImg[2]) - { - case 1: // IMG_GIF - $imgfonction = 'imagecreatefromgif'; - break; - case 2: // IMG_JPG - $imgfonction = 'imagecreatefromjpeg'; - break; - case 3: // IMG_PNG - $imgfonction = 'imagecreatefrompng'; - break; - case 4: // IMG_WBMP - $imgfonction = 'imagecreatefromwbmp'; - break; - } - if ($imgfonction) - { - if (! function_exists($imgfonction)) - { - // Fonctions de conversion non presente dans ce PHP - return 'Creation de vignette impossible. Ce PHP ne supporte pas les fonctions du module GD '.$imgfonction; - } - } - - // On crée le répertoire contenant les vignettes - if (! file_exists($dirthumb)) - { - create_exdir($dirthumb); - } - - // Initialisation des variables selon l'extension de l'image - switch($infoImg[2]) - { - case 1: // Gif - $img = imagecreatefromgif($fichier); - $extImg = '.gif'; // Extension de l'image - $newquality='NU'; - break; - case 2: // Jpg - $img = imagecreatefromjpeg($fichier); - $extImg = '.jpg'; // Extension de l'image - $newquality=$quality; - break; - case 3: // Png - $img = imagecreatefrompng($fichier); - $extImg = '.png'; - $newquality=$quality-100; - $newquality=round(abs($quality-100)*9/100); - break; - case 4: // Bmp - $img = imagecreatefromwbmp($fichier); - $extImg = '.bmp'; - $newquality='NU'; - break; - } - - // Initialisation des dimensions de la vignette si elles sont supérieures a l'original - if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } - if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } - - $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette - $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original - - // Fixe les dimensions de la vignette - if($whFact < $imgWhFact){ - // Si largeur déterminante - $thumbWidth = $maxWidth; - $thumbHeight = $thumbWidth / $imgWhFact; - } else { - // Si hauteur déterminante - $thumbHeight = $maxHeight; - $thumbWidth = $thumbHeight * $imgWhFact; - } - $thumbHeight=round($thumbHeight); - $thumbWidth=round($thumbWidth); - - // Create empty image - if ($infoImg[2] == 1) - { - // Compatibilité image GIF - $imgThumb = imagecreate($thumbWidth, $thumbHeight); - } - else - { - $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); - } - - // Activate antialiasing for better quality - if (function_exists('imageantialias')) - { - imageantialias($imgThumb, true); - } - - // This is to keep transparent alpha channel if exists (PHP >= 4.2) - if (function_exists('imagesavealpha')) - { - imagesavealpha($imgThumb, true); - } - - // Initialisation des variables selon l'extension de l'image - switch($infoImg[2]) - { - case 1: // Gif - $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procéde autrement pour le format GIF - imagecolortransparent($imgThumb,$trans_colour); - break; - case 2: // Jpg - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); - break; - case 3: // Png - imagealphablending($imgThumb,false); // Pour compatibilité sur certain systéme - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel - break; - case 4: // Bmp - $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); - break; - } - if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); - - dolibarr_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality"); - //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insére l'image de base redimensionnée - imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insére l'image de base redimensionnée - - $fileName = eregi_replace('(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$','',$file); // On enleve extension quelquesoit la casse - $fileName = basename($fileName); - $imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette - - // Check if permission are ok - //$fp = fopen($imgThumbName, "w"); - //fclose($fp); - - // Create image on disk - switch($infoImg[2]) - { - case 1: // Gif - imagegif($imgThumb, $imgThumbName); - break; - case 2: // Jpg - imagejpeg($imgThumb, $imgThumbName, $newquality); - break; - case 3: // Png - imagepng($imgThumb, $imgThumbName, $newquality); - break; - case 4: // Bmp - image2wmp($imgThumb, $imgThumbName); - break; - } - - // Free memory - imagedestroy($imgThumb); - - return $imgThumbName; -} /* * \brief Converti les heures et minutes en secondes diff --git a/htdocs/lib/images.lib.php b/htdocs/lib/images.lib.php new file mode 100644 index 00000000000..b1bc33a3dc7 --- /dev/null +++ b/htdocs/lib/images.lib.php @@ -0,0 +1,243 @@ + + * Copyright (C) 2005-2007 Regis Houssin + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + * or see http://www.gnu.org/ + */ + +/** + \file htdocs/lib/images.lib.php + \brief Ensemble de fonctions de base de traitement d'images + \version $Id$ +*/ + + + +/* + * \brief Création de 2 vignettes a partir d'un fichier image (une small et un mini) + * \brief Les extension prise en compte sont jpg et png + * \param file Chemin du fichier image a redimensionner + * \param maxWidth Largeur maximum que dois faire la miniature (160 par défaut) + * \param maxHeight Hauteur maximum que dois faire l'image (120 par défaut) + * \param extName Extension pour différencier le nom de la vignette + * \param quality Qualité de compression (0=worst, 100=best) + * \return string Chemin de la vignette + */ +function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $quality=50) +{ + global $langs; + + dolibarr_syslog("functions.inc::vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality); + + // Nettoyage parametres + $file=trim($file); + + // Vérification des paramétres + if (! $file) + { + // Si le fichier n'a pas été indiqué + return 'Bad parameter file'; + } + elseif (! file_exists($file)) + { + // Si le fichier passé en paramétre n'existe pas + return $langs->trans("ErrorFileNotFound",$file); + } + elseif(image_format_supported($file) < 0) + { + return 'This file '.$file.' does not seem to be an image format file name.'; + } + elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < 0){ + // Si la largeur max est incorrecte (n'est pas numérique, est vide, ou est inférieure a 0) + return 'Valeur de la largeur incorrecte.'; + } + elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < 0){ + // Si la hauteur max est incorrecte (n'est pas numérique, est vide, ou est inférieure a 0) + return 'Valeur de la hauteur incorrecte.'; + } + + $fichier = realpath($file); // Chemin canonique absolu de l'image + $dir = dirname($file).'/'; // Chemin du dossier contenant l'image + $dirthumb = $dir.'thumbs/'; // Chemin du dossier contenant les vignettes + + $infoImg = getimagesize($fichier); // Récupération des infos de l'image + $imgWidth = $infoImg[0]; // Largeur de l'image + $imgHeight = $infoImg[1]; // Hauteur de l'image + + // Si l'image est plus petite que la largeur et la hauteur max, on ne crée pas de vignette + if ($infoImg[0] < $maxWidth && $infoImg[1] < $maxHeight) + { + // On cree toujours les vignettes + dolibarr_syslog("File size is smaller than thumb size",LOG_DEBUG); + //return 'Le fichier '.$file.' ne nécessite pas de création de vignette'; + } + + $imgfonction=''; + switch($infoImg[2]) + { + case 1: // IMG_GIF + $imgfonction = 'imagecreatefromgif'; + break; + case 2: // IMG_JPG + $imgfonction = 'imagecreatefromjpeg'; + break; + case 3: // IMG_PNG + $imgfonction = 'imagecreatefrompng'; + break; + case 4: // IMG_WBMP + $imgfonction = 'imagecreatefromwbmp'; + break; + } + if ($imgfonction) + { + if (! function_exists($imgfonction)) + { + // Fonctions de conversion non presente dans ce PHP + return 'Creation de vignette impossible. Ce PHP ne supporte pas les fonctions du module GD '.$imgfonction; + } + } + + // On crée le répertoire contenant les vignettes + if (! file_exists($dirthumb)) + { + create_exdir($dirthumb); + } + + // Initialisation des variables selon l'extension de l'image + switch($infoImg[2]) + { + case 1: // Gif + $img = imagecreatefromgif($fichier); + $extImg = '.gif'; // Extension de l'image + $newquality='NU'; + break; + case 2: // Jpg + $img = imagecreatefromjpeg($fichier); + $extImg = '.jpg'; // Extension de l'image + $newquality=$quality; + break; + case 3: // Png + $img = imagecreatefrompng($fichier); + $extImg = '.png'; + $newquality=$quality-100; + $newquality=round(abs($quality-100)*9/100); + break; + case 4: // Bmp + $img = imagecreatefromwbmp($fichier); + $extImg = '.bmp'; + $newquality='NU'; + break; + } + + // Initialisation des dimensions de la vignette si elles sont supérieures a l'original + if($maxWidth > $imgWidth){ $maxWidth = $imgWidth; } + if($maxHeight > $imgHeight){ $maxHeight = $imgHeight; } + + $whFact = $maxWidth/$maxHeight; // Facteur largeur/hauteur des dimensions max de la vignette + $imgWhFact = $imgWidth/$imgHeight; // Facteur largeur/hauteur de l'original + + // Fixe les dimensions de la vignette + if($whFact < $imgWhFact){ + // Si largeur déterminante + $thumbWidth = $maxWidth; + $thumbHeight = $thumbWidth / $imgWhFact; + } else { + // Si hauteur déterminante + $thumbHeight = $maxHeight; + $thumbWidth = $thumbHeight * $imgWhFact; + } + $thumbHeight=round($thumbHeight); + $thumbWidth=round($thumbWidth); + + // Create empty image + if ($infoImg[2] == 1) + { + // Compatibilité image GIF + $imgThumb = imagecreate($thumbWidth, $thumbHeight); + } + else + { + $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); + } + + // Activate antialiasing for better quality + if (function_exists('imageantialias')) + { + imageantialias($imgThumb, true); + } + + // This is to keep transparent alpha channel if exists (PHP >= 4.2) + if (function_exists('imagesavealpha')) + { + imagesavealpha($imgThumb, true); + } + + // Initialisation des variables selon l'extension de l'image + switch($infoImg[2]) + { + case 1: // Gif + $trans_colour = imagecolorallocate($imgThumb, 255, 255, 255); // On procéde autrement pour le format GIF + imagecolortransparent($imgThumb,$trans_colour); + break; + case 2: // Jpg + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); + break; + case 3: // Png + imagealphablending($imgThumb,false); // Pour compatibilité sur certain systéme + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 127); // Keep transparent channel + break; + case 4: // Bmp + $trans_colour = imagecolorallocatealpha($imgThumb, 255, 255, 255, 0); + break; + } + if (function_exists("imagefill")) imagefill($imgThumb, 0, 0, $trans_colour); + + dolibarr_syslog("vignette: convert image from ($imgWidth x $imgHeight) to ($thumbWidth x $thumbHeight) as $extImg, newquality=$newquality"); + //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insére l'image de base redimensionnée + imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insére l'image de base redimensionnée + + $fileName = eregi_replace('(\.gif|\.jpeg|\.jpg|\.png|\.bmp)$','',$file); // On enleve extension quelquesoit la casse + $fileName = basename($fileName); + $imgThumbName = $dirthumb.$fileName.$extName.$extImg; // Chemin complet du fichier de la vignette + + // Check if permission are ok + //$fp = fopen($imgThumbName, "w"); + //fclose($fp); + + // Create image on disk + switch($infoImg[2]) + { + case 1: // Gif + imagegif($imgThumb, $imgThumbName); + break; + case 2: // Jpg + imagejpeg($imgThumb, $imgThumbName, $newquality); + break; + case 3: // Png + imagepng($imgThumb, $imgThumbName, $newquality); + break; + case 4: // Bmp + image2wmp($imgThumb, $imgThumbName); + break; + } + + // Free memory + imagedestroy($imgThumb); + + return $imgThumbName; +} + +?> diff --git a/htdocs/livraison/mods/modules_livraison.php b/htdocs/livraison/mods/modules_livraison.php index 2e67815f960..e94829e0459 100644 --- a/htdocs/livraison/mods/modules_livraison.php +++ b/htdocs/livraison/mods/modules_livraison.php @@ -28,7 +28,7 @@ \version $Id$ */ -require_once(DOL_DOCUMENT_ROOT.'/lib/functions.inc.php'); +require_once(DOL_DOCUMENT_ROOT.'/lib/functions.lib.php'); require_once(DOL_DOCUMENT_ROOT.'/includes/fpdf/fpdfi/fpdi_protection.php'); diff --git a/htdocs/master.inc.php b/htdocs/master.inc.php index 7be4a6b0dee..9c2e30ee686 100644 --- a/htdocs/master.inc.php +++ b/htdocs/master.inc.php @@ -96,7 +96,7 @@ if (! empty($dolibarr_main_document_root_bis)) define('DOL_DOCUMENT_ROOT_BIS', $ /* * Controle validite fichier conf */ -if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php")) +if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php")) { print "Error: Dolibarr config file content seems to be not correctly defined.
\n"; print "Please run dolibarr setup by calling page /install.
\n"; @@ -109,7 +109,7 @@ if (! file_exists(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php")) */ // on décode le mot de passe de la base si besoin -require_once(DOL_DOCUMENT_ROOT ."/lib/functions.inc.php"); // Need 1.1Mo memory +require_once(DOL_DOCUMENT_ROOT ."/lib/functions.lib.php"); // Need 1.1 Mo memory if (! empty($dolibarr_main_db_encrypted_pass)) $dolibarr_main_db_pass = dolibarr_decode($dolibarr_main_db_encrypted_pass); //stopwithmem(); diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 41d3b6da3c8..f8cd987b193 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2224,37 +2224,39 @@ class Product extends CommonObject { $originImage = $dir . $file['name']; - // Cr�e fichier en taille origine + // Cree fichier en taille origine doliMoveFileUpload($file['tmp_name'], $originImage); if (file_exists($originImage)) { - // Cr�e fichier en taille vignette + // Cree fichier en taille vignette $this->add_thumb($originImage,$maxWidth,$maxHeight); } } } - /** - * \brief G�n�re la vignette - * \param sdir R�pertoire destination finale - * \param file Chemin du fichier d'origine - * \param maxWidth Largeur maximum que dois faire la miniature (160 par d�faut) - * \param maxHeight Hauteur maximum que dois faire la miniature (120 par d�faut) - */ - function add_thumb($file, $maxWidth = 160, $maxHeight = 120) - { - if (file_exists($file)) - { - vignette($file,$maxWidth,$maxHeight); - } - } + /** + * \brief Build thumb + * \param sdir Repertoire destination finale + * \param file Chemin du fichier d'origine + * \param maxWidth Largeur maximum que dois faire la miniature (160 par defaut) + * \param maxHeight Hauteur maximum que dois faire la miniature (120 par defaut) + */ + function add_thumb($file, $maxWidth = 160, $maxHeight = 120) + { + require_once(DOL_DOCUMENT_ROOT ."/lib/images.lib.php"); + + if (file_exists($file)) + { + vignette($file,$maxWidth,$maxHeight); + } + } /** - * \brief D�place fichier r�cup�r� sur internet (utilis� pour interface avec OSC) - * \param sdir R�pertoire destination finale - * \param $files url de l'image - * Jean Heimburger juin 2007 + * \brief Deplace fichier recupere sur internet (utilise pour interface avec OSC) + * \param sdir Repertoire destination finale + * \param $files url de l'image + * \author Jean Heimburger juin 2007 */ function add_photo_web($sdir, $files) { @@ -2269,10 +2271,10 @@ class Product extends CommonObject if (file_exists($dir)) { - // Cr�e fichier en taille vignette - // \todo A faire + // Cree fichier en taille vignette + // \todo A faire - // Cr�e fichier en taille origine + // Cree fichier en taille origine $content = file_get_contents($files); $nom = basename($files);