diff --git a/htdocs/product/photos_resize.php b/htdocs/core/photos_resize.php similarity index 62% rename from htdocs/product/photos_resize.php rename to htdocs/core/photos_resize.php index 68d6e8d7382..aacd0c548b7 100644 --- a/htdocs/product/photos_resize.php +++ b/htdocs/core/photos_resize.php @@ -34,7 +34,7 @@ if (isset($_GET["id"])) $result=restrictedArea($user,'produit|service',$id,'product','','',$fieldid); -$original_file = isset($_GET["file"])?urldecode($_GET["file"]):''; +$original_file = isset($_REQUEST["file"])?urldecode($_REQUEST["file"]):''; $langs->load("products"); @@ -46,32 +46,28 @@ if (!$user->rights->produit->lire) accessforbidden(); * Actions */ -if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") &&(isset($_POST["sizey"]) != "")) +if ($_POST["action"] == 'confirm_resize' && (isset($_POST["file"]) != "") && (isset($_POST["sizex"]) != "") && (isset($_POST["sizey"]) != "")) { -/* $thumb = new Imagick($conf->produit->dir_output."/".$_POST["file"]); - $height=$thumb->getImageHeight(); // dimensions de l'image actuelle - $width=$thumb->getImageWidth(); // dimensions de l'image actuelle + $fullpath=$conf->produit->dir_output."/".$_POST["file"]; + $result=dol_imageResize($fullpath,$_POST['sizex'],$_POST['sizey']); - if($_POST["sizex"] != "") + if ($result == $fullpath) { - if ($width > $_POST['sizex']) - $thumb->scaleImage(intval($_POST['sizex']), 0); + header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["product"].'&action=addthumb&file='.urldecode($_POST["file"])); + exit; } - if($_POST["sizey"] != "") + else { - if ($height > $_POST['sizey']) - $thumb->scaleImage(0, intval($_POST['sizey'])); + $mesg=$result; + $_GET['file']=$_POST["file"]; + $_GET['id']=$_POST["id"]; } - $thumb->writeImage($conf->produit->dir_output."/".$_POST["file"]); - $thumb->destroy(); -*/ - header("Location: ".DOL_URL_ROOT."/product/photos.php?id=".$_POST["product"].'&action=addthumb&file='.urldecode($_POST["file"])); - exit; } // Crop d'une image if ($_POST["action"] == 'confirm_crop' && $_POST["file"]) { + // TODO Add function to crop image in images.lib.php /* $thumb = new Imagick($conf->produit->dir_output."/".urldecode($_POST["file"])); $thumb->cropImage($_POST['w'], $_POST['h'], $_POST['x'], $_POST['y']); $thumb->writeImage($conf->produit->dir_output."/".urldecode($_POST["file"])); @@ -86,31 +82,35 @@ if ($_POST["action"] == 'confirm_crop' && $_POST["file"]) * View */ -llxHeader($head, $langs->trans("Resize"), '', '', 0, 0, array('includes/jcrop/js/jquery.min.js','includes/jcrop/js/jquery.Jcrop.min.js','lib/lib_photosresize.js'), array(DOL_URL_ROOT.'/includes/jcrop/css/jquery.Jcrop.css')); +llxHeader($head, $langs->trans("Image"), '', '', 0, 0, array('includes/jcrop/js/jquery.min.js','includes/jcrop/js/jquery.Jcrop.min.js','lib/lib_photosresize.js'), array(DOL_URL_ROOT.'/includes/jcrop/css/jquery.Jcrop.css')); -print_fiche_titre($langs->trans("Current")); +print_fiche_titre($langs->trans("Image")); + +if ($mesg) print '
'.$mesg.'
'; $infoarray=dol_getImageSize($conf->produit->dir_output."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; print $langs->trans("Size").':

'; print '
'; print_fiche_titre($langs->trans("Resize"),'',''); -print '
'; -print 'Entrer la nouvelle largeur OU la nouvelle hauteur. Le ratio est conservé lors du redimensionnement...
'; -print 'Nouvelle largeur : px
'; -print 'Nouvelle hauteur : px  
'; +print ''; + +print $langs->trans("ResizeDesc").'
'; +print $langs->trans("NewLength").': px
'; +print $langs->trans("NewHeight").': px  
'; print ''; print ''; print ''; -print '
'; +print ''; +print '
'; print '
'; print '
'; @@ -121,14 +121,16 @@ print '
'; print '
'; print_fiche_titre($langs->trans("Recenter"),'',''); -print 'Define new area to keep...
'; -print 'Taille origine'; +print $langs->trans("DefineNewAreaToPick").'...
'; +print '
'; +print 'Taille origine'; +print '
'; $infoarray=dol_getImageSize($conf->produit->dir_output."/".urldecode($_GET["file"])); $height=$infoarray['height']; $width=$infoarray['width']; -print '
+print '
-
Nouvelles dimensions après recadrage
+ '.$langs->trans("NewSizeAfterCropping").': @@ -140,7 +142,8 @@ print ' -
+ +
'; llxFooter('$Date$ - $Revision$'); diff --git a/htdocs/core/pre.inc.php b/htdocs/core/pre.inc.php new file mode 100644 index 00000000000..327822b2326 --- /dev/null +++ b/htdocs/core/pre.inc.php @@ -0,0 +1,41 @@ + + * Copyright (C) 2004-2010 Laurent Destailleur + * Copyright (C) 2007 Auguria SARL + * + * 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. + */ + +/** + * \file htdocs/core/pre.inc.php + * \ingroup core + * \brief Menu file + * \version $Id$ + */ +require("../main.inc.php"); + + + +function llxHeader($head = '',$help_url='', $title='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='') +{ + global $user, $conf, $langs; + + top_menu($head, $title, $target, $disablejs, $disablehead, $arrayofjs, $arrayofcss); + + $menu = new Menu(); + + left_menu($menu->liste, $help_url); +} +?> diff --git a/htdocs/includes/barcode/html.formbarcode.class.php b/htdocs/includes/barcode/html.formbarcode.class.php index 1cd74ca2ccf..c55e42b0854 100644 --- a/htdocs/includes/barcode/html.formbarcode.class.php +++ b/htdocs/includes/barcode/html.formbarcode.class.php @@ -153,7 +153,7 @@ class FormBarCode print '
'; print ''; print ''; - print ''; + print '
'; print ''; diff --git a/htdocs/langs/en_US/other.lang b/htdocs/langs/en_US/other.lang index 409745bccea..c697d2f783d 100644 --- a/htdocs/langs/en_US/other.lang +++ b/htdocs/langs/en_US/other.lang @@ -115,6 +115,11 @@ EMailTextOrderRefused=The order %s has been refused. EMailTextOrderRefusedBy=The order %s has been refused by %s. ImportedWithSet=Importation data set DolibarrNotification=Automatic notification +ResizeDesc=Enter new width OR new height. Ratio will be kept during resizing... +NewLength=New width +NewHeight=New height +NewSizeAfterCropping=New size after cropping +DefineNewAreaToPick=Define new area on image to pick (left click on image then drag until you reach the opposite corner) ##### Bookmark ##### Bookmark=Bookmark diff --git a/htdocs/langs/fr_FR/other.lang b/htdocs/langs/fr_FR/other.lang index e2e0a2d8e6e..72603482b5a 100644 --- a/htdocs/langs/fr_FR/other.lang +++ b/htdocs/langs/fr_FR/other.lang @@ -115,6 +115,11 @@ EMailTextOrderRefused=La commande %s a été réfusée. EMailTextOrderRefusedBy=La commande %s a été réfusée par %s. ImportedWithSet=Lot d'importation (Import key) DolibarrNotification=Notification automatique +ResizeDesc=Entrer la nouvelle largeur OU la nouvelle hauteur. Le ratio est conservé lors du redimensionnement... +NewLength=Nouvelle largeur +NewHeight=Nouvelle hauteur +NewSizeAfterCropping=Nouvelles dimensions après recadrage +DefineNewAreaToPick=Définissez la zone d'image à conserver (clic gauche sur l'image puis drag vers les coin opposé) ##### Bookmark ##### Bookmark=Marque page diff --git a/htdocs/lib/images.lib.php b/htdocs/lib/images.lib.php index 1c494ed37dd..ba7276ba60b 100644 --- a/htdocs/lib/images.lib.php +++ b/htdocs/lib/images.lib.php @@ -1,5 +1,5 @@ +/* Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2007 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -49,6 +49,195 @@ function dol_getImageSize($file) } +/** + * \brief Resize an image file + * \brief Supported extensions are jpg and png + * \param file Chemin du fichier image a redimensionner + * \param newWidth Largeur maximum que dois faire la miniature (-1=unchanged) + * \param newHeight Hauteur maximum que dois faire l'image (-1=unchanged) + * \return int File name if OK, error message if KO + * \remarks With file=myfile.jpg -> myfile_small.jpg + */ +function dol_imageResize($file, $newWidth, $newHeight) +{ + require_once(DOL_DOCUMENT_ROOT."/lib/functions2.lib.php"); + + global $conf,$langs; + + dol_syslog("dol_imageResize file=".$file." newWidth=".$newWidth." newHeight=".$newHeight); + + // Clean parameters + $file=trim($file); + + // Check parameters + if (! $file) + { + // Si le fichier n'a pas ete indique + return 'Bad parameter file'; + } + elseif (! file_exists($file)) + { + // Si le fichier passe en parametre 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($newWidth) && !is_numeric($newHeight)){ + return 'Wrong value for parameter newWidth or newHeight'; + } + elseif ($newWidth <= 0 && $newHeight <= 0) + { + return 'At least newHeight or newWidth must be defined'; + } + + $fichier = realpath($file); // Chemin canonique absolu de l'image + $dir = dirname($file); // Chemin du dossier contenant l'image + + $infoImg = getimagesize($fichier); // Recuperation des infos de l'image + $imgWidth = $infoImg[0]; // Largeur de l'image + $imgHeight = $infoImg[1]; // Hauteur de l'image + + if ($newWidth <= 0) + { + $newWidth=intval(($newHeight / $imgHeight) * $imgWidth); // Keep ratio + } + if ($newHeight <= 0) + { + $newHeight=intval(($newWidth / $imgWidth) * $imgHeight); // Keep ratio + } + + $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 'Resize not possible. This PHP does not support GD functions '.$imgfonction; + } + } + + // 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=100; + break; + case 3: // Png + $img = imagecreatefrompng($fichier); + $extImg = '.png'; + $newquality=10; + break; + case 4: // Bmp + $img = imagecreatefromwbmp($fichier); + $extImg = '.bmp'; + $newquality='NU'; + break; + } + + // Create empty image + if ($infoImg[2] == 1) + { + // Compatibilite image GIF + $imgThumb = imagecreate($newWidth, $newHeight); + } + else + { + $imgThumb = imagecreatetruecolor($newWidth, $newHeight); + } + + // 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 procede 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 compatibilite sur certain systeme + $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); + + dol_syslog("dol_imageResize: convert image from ($imgWidth x $imgHeight) to ($newWidth x $newHeight) as $extImg, newquality=$newquality"); + //imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee + imagecopyresampled($imgThumb, $img, 0, 0, 0, 0, $newWidth, $newHeight, $imgWidth, $imgHeight); // Insere l'image de base redimensionnee + + $imgThumbName = $file; + + // 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; + } + + // Set permissions on file + if (! empty($conf->global->MAIN_UMASK)) @chmod($imgThumbName, octdec($conf->global->MAIN_UMASK)); + + // Free memory + imagedestroy($imgThumb); + + return $imgThumbName; +} + + /** * \brief Create a thumbnail from an image file (une small et un mini) * \brief Les extensions prises en compte sont jpg et png @@ -66,7 +255,7 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $ global $conf,$langs; - dol_syslog("functions.inc::vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality); + dol_syslog("vignette file=".$file." extName=".$extName." maxWidth=".$maxWidth." maxHeight=".$maxHeight." quality=".$quality); // Clean parameters $file=trim($file); @@ -88,11 +277,11 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $ } elseif(!is_numeric($maxWidth) || empty($maxWidth) || $maxWidth < -1){ // Si la largeur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) - return 'Valeur de la largeur incorrecte.'; + return 'Wrong value for parameter maxWidth'; } elseif(!is_numeric($maxHeight) || empty($maxHeight) || $maxHeight < -1){ // Si la hauteur max est incorrecte (n'est pas numerique, est vide, ou est inferieure a 0) - return 'Valeur de la hauteur incorrecte.'; + return 'Wrong value for parameter maxHeight'; } $fichier = realpath($file); // Chemin canonique absolu de l'image @@ -271,15 +460,11 @@ function vignette($file, $maxWidth = 160, $maxHeight = 120, $extName='_small', $ /** - \brief permet d'afficher un thermometre monetaire. - \param actualValue - \param pendingValue - \param intentValue - \return thermometer htmlLegenda - This function returns the html for the moneymeter. - cachedValue: amount of actual money - pendingValue: amount of money of pending memberships - intentValue: amount of intended money (that's without the amount of actual money) + * \brief This function returns the html for the moneymeter. + * \param actualValue: amount of actual money + * \param pendingValue: amount of money of pending memberships + * \param intentValue: amount of intended money (that's without the amount of actual money) + * \return thermometer htmlLegenda */ function moneyMeter($actualValue=0, $pendingValue=0, $intentValue=0) { diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 8276146b385..de95779c96e 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -2404,7 +2404,7 @@ class Product extends CommonObject */ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5,$showfilename=0,$showaction=0) { - global $user,$langs; + global $conf,$user,$langs; include_once(DOL_DOCUMENT_ROOT ."/lib/files.lib.php"); @@ -2468,12 +2468,10 @@ class Product extends CommonObject } if ($user->rights->produit->creer || $user->rights->service->creer) { - if ($conf->global->MAIN_FEATURES_LEVEL > 0) - { - // Link to resize - print ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).''; - } - // Link to delete + // Link to resize + print ''.img_picto($langs->trans("Resize"),DOL_URL_ROOT.'/theme/common/transform-crop-and-resize','',1).'   '; + + // Link to delete print ''; print img_delete().''; } diff --git a/htdocs/product/barcode.php b/htdocs/product/barcode.php index ea9acdd366f..e595cf0c4b7 100644 --- a/htdocs/product/barcode.php +++ b/htdocs/product/barcode.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin * * This program is free software; you can redistribute it and/or modify @@ -42,6 +42,7 @@ $fieldid = isset($_GET["ref"])?'ref':'rowid'; if ($user->societe_id) $socid=$user->societe_id; $result=restrictedArea($user,'produit|service&barcode',$id,'product','','',$fieldid); + /* * Actions */ @@ -70,7 +71,7 @@ if ($_POST['action'] == 'setbarcode' && $user->rights->barcode->creer) /* - * Mode vue et edition + * View */ llxHeader("","",$langs->trans("BarCode")); diff --git a/htdocs/product/pre.inc.php b/htdocs/product/pre.inc.php index 8d7a55a3d35..07a06bc4eeb 100644 --- a/htdocs/product/pre.inc.php +++ b/htdocs/product/pre.inc.php @@ -1,6 +1,6 @@ - * Copyright (C) 2004-2009 Laurent Destailleur + * Copyright (C) 2004-2010 Laurent Destailleur * Copyright (C) 2007 Auguria SARL * * This program is free software; you can redistribute it and/or modify
'; $this->select_barcode_type($selected, $htmlname, 1); print '