diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index c2fcfaa35f7..54d3f9bb676 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -74,20 +74,31 @@ class Form
\return string Code html du texte,picto
*/
function textwithtooltip($text,$htmltext,$tooltipon=1,$direction=0,$img='')
- {
- global $conf;
+ {
+ global $conf;
if (! $htmltext) return $text;
- $paramfortooltiptext ='';
- $paramfortooltippicto ='';
- if ($conf->use_javascript)
- {
- // Sanitize tooltip
- $htmltext=ereg_replace("'","\'",$htmltext);
- $htmltext=ereg_replace("'","\'",$htmltext);
- if ($tooltipon==1 || $tooltipon==3)
- {
+ $paramfortooltiptext ='';
+ $paramfortooltippicto ='';
+
+ // Sanitize tooltip
+ $htmltext=ereg_replace("'","\'",$htmltext);
+ $htmltext=ereg_replace("'","\'",$htmltext);
+
+ if ($conf->use_ajax && $tooltipon == 4)
+ {
+ $s = '';
+ $s.= ''.$text.'';
+ }
+ else
+ {
+ if ($conf->use_javascript)
+ {
+ if ($tooltipon==1 || $tooltipon==3)
+ {
$paramfortooltiptext.=' onmouseover="showtip(\''.$htmltext.'\')"';
$paramfortooltiptext.=' onMouseout="hidetip()"';
}
@@ -96,7 +107,7 @@ class Form
$paramfortooltippicto.=' onmouseover="showtip(\''.$htmltext.'\')"';
$paramfortooltippicto.=' onMouseout="hidetip()"';
}
- }
+ }
$s="";
$s.='
';
@@ -121,8 +132,9 @@ class Form
}
}
$s.='
';
- return $s;
- }
+ }
+ return $s;
+ }
/**
\brief Affiche un texte avec picto help qui affiche un tooltip
diff --git a/htdocs/lib/functions.inc.php b/htdocs/lib/functions.inc.php
index dddfac452a8..68ebcdfc1dc 100644
--- a/htdocs/lib/functions.inc.php
+++ b/htdocs/lib/functions.inc.php
@@ -1470,7 +1470,7 @@ function doliMoveFileUpload($src_file, $dest_file)
// On renomme les fichiers avec extention executable car si on a mis le rep
// documents dans un rep de la racine web (pas bien), cela permet d'executer
// du code a la demande.
- if (eregi('\.php|\.pl|\.cgi$',$file_name))
+ if (eregi('\.htm|\.html|\.php|\.pl|\.cgi$',$file_name))
{
$file_name.= '.txt';
}
@@ -2927,4 +2927,93 @@ function print_date_range($date_start,$date_end)
}
}
+/*
+ * \brief Création d'une vignette à partir d'une image ($file)
+ * \brief Les extension prise en compte sont jpg et png
+ * \param file Chemin du fichier image à 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)
+ * \return imgThumbName Chemin de la vignette
+ */
+function vignette($file, $maxWidth = 160, $maxHeight = 120){
+
+ // Vérification des erreurs dans les paramètres de la fonction
+ //============================================================
+ if(!file_exists($file)){
+ // Si le fichier passé en paramètre n'existe pas
+ return 'Le fichier '.$file.' n\'a pas été trouvé sur le serveur.';
+ }
+ elseif(empty($file)){
+ // Si le fichier n'a pas été indiqué
+ return 'Nom du fichier non renseigné.';
+ }
+ 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 à 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 à 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
+ $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
+
+ // Initialisation des variables selon l'extension de l'image
+ switch($infoImg[2]){
+ case 2:
+ $img = imagecreatefromjpeg($fichier); // Création d'une nouvelle image jpeg à partir du fichier
+ $extImg = '.jpg'; // Extension de l'image
+ break;
+ case 3:
+ $img = imagecreatefrompng($fichier); // Création d'une nouvelle image png à partir du fichier
+ $extImg = '.png';
+ }
+
+ // Initialisation des dimensions de la vignette si elles sont supérieures à 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;
+ }
+
+ $imgThumb = imagecreatetruecolor($thumbWidth, $thumbHeight); // Création de la vignette
+
+ imagecopyresized($imgThumb, $img, 0, 0, 0, 0, $thumbWidth, $thumbHeight, $imgWidth, $imgHeight); // Insère l'image de base redimensionnée
+
+ $fileName = basename($file, $extImg); // Nom du fichier sans son extension
+ $imgThumbName = $dir.$fileName.'_small'.$extImg; // Chemin complet du fichier de la vignette
+
+ //Création du fichier de la vignette
+ $fp = fopen($imgThumbName, "w");
+ fclose($fp);
+
+ // Renvoi la vignette créée
+ switch($infoImg[2]){
+ case 2:
+ imagejpeg($imgThumb, $imgThumbName, 50); // Renvoi d'une image jpeg avec une qualité de 50
+ break;
+ case 3:
+ imagepng($imgThumb, $imgThumbName);
+ }
+
+ return $imgThumbName;
+
+}
+
?>
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index b8ff1f208b2..ddc8b355e7d 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -2131,19 +2131,24 @@ class Product
$dir .= "photos/";
if (! file_exists($dir))
- {
- dolibarr_syslog("Product Create $dir");
- create_exdir($dir);
- }
+ {
+ dolibarr_syslog("Product Create $dir");
+ create_exdir($dir);
+ }
if (file_exists($dir))
- {
- // Crée fichier en taille vignette
- // \todo A faire
-
- // Crée fichier en taille origine
- doliMoveFileUpload($files['tmp_name'], $dir . $files['name']);
- }
+ {
+ $originImage = $dir . $files['name'];
+
+ // Crée fichier en taille origine
+ doliMoveFileUpload($files['tmp_name'], $originImage);
+
+ if (file_exists($originImage))
+ {
+ // Crée fichier en taille vignette
+ vignette($originImage);
+ }
+ }
}
/**
@@ -2158,10 +2163,10 @@ class Product
$dir .= "photos/";
if (! file_exists($dir))
- {
- dolibarr_syslog("Product Create $dir");
- create_exdir($dir);
- }
+ {
+ dolibarr_syslog("Product Create $dir");
+ create_exdir($dir);
+ }
if (file_exists($dir))
{
@@ -2182,7 +2187,7 @@ class Product
/**
* \brief Affiche la première photo du produit
* \param sdir Répertoire à scanner
- * \return boolean true si photo dispo, flase sinon
+ * \return boolean true si photo dispo, false sinon
*/
function is_photo_available($sdir)
{
@@ -2191,14 +2196,14 @@ class Product
$nbphoto=0;
if (file_exists($dir))
- {
- $handle=opendir($dir);
-
- while (($file = readdir($handle)) != false)
- {
- if (is_file($dir.$file)) return true;
- }
- }
+ {
+ $handle=opendir($dir);
+
+ while (($file = readdir($handle)) != false)
+ {
+ if (is_file($dir.$file)) return true;
+ }
+ }
return false;
}
@@ -2222,21 +2227,20 @@ class Product
$handle=opendir($dir);
while (($file = readdir($handle)) != false)
- {
- $photo='';
- if (is_file($dir.$file)) $photo = $file;
+ {
+ $photo='';
- if ($photo)
- {
- $nbphoto++;
-
- if ($size == 1) { // Format vignette
-
- // On determine nom du fichier vignette
- $photo_vignette='';
- if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) {
- $photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
- }
+ if (is_file($dir.$file) && !eregi('\_small',$file))
+ {
+ $nbphoto++;
+ $photo = $file;
+
+ if ($size == 1) { // Format vignette
+ // On determine nom du fichier vignette
+ $photo_vignette='';
+ if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs)) {
+ $photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
+ }
if ($nbbyrow && $nbphoto == 1) print '';
@@ -2247,7 +2251,7 @@ class Product
print '';
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
- if ($photo_vignette && is_file($photo_vignette)) {
+ if ($photo_vignette && is_file($dir.$photo_vignette)) {
print '
';
}
else {
@@ -2298,39 +2302,39 @@ class Product
$tabobj=array();
if (file_exists($dir))
- {
- $handle=opendir($dir);
-
- while (($file = readdir($handle)) != false)
- {
- if (is_file($dir.$file))
+ {
+ $handle=opendir($dir);
+
+ while (($file = readdir($handle)) != false)
+ {
+ if (is_file($dir.$file) && !eregi('\_small',$file))
{
- $nbphoto++;
- $photo = $file;
+ $nbphoto++;
+ $photo = $file;
+
+ // On determine nom du fichier vignette
+ $photo_vignette='';
+ if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs))
+ {
+ $photo_vignette=eregi_replace($regs[0],'',$photo).'_small'.$regs[0];
+ }
+
+ // Objet
+ $obj=array();
+ $obj['photo']=$photo;
+ if ($photo_vignette && is_file($dir.$photo_vignette)) $obj['photo_vignette']=$photo_vignette;
+ else $obj['photo_vignette']="";
- // On determine nom du fichier vignette
- $photo_vignette='';
- if (eregi('(\.jpg|\.bmp|\.gif|\.png|\.tiff)$',$photo,$regs))
- {
- $photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0];
- }
-
- // Objet
- $obj=array();
- $obj['photo']=$photo;
- if ($photo_vignette && is_file($photo_vignette)) $obj['photo_vignette']=$photo_vignette;
- else $obj['photo_vignette']="";
-
- $tabobj[$nbphoto-1]=$obj;
-
- // On continue ou on arrete de boucler ?
- if ($nbmax && $nbphoto >= $nbmax) break;
+ $tabobj[$nbphoto-1]=$obj;
+
+ // On continue ou on arrete de boucler ?
+ if ($nbmax && $nbphoto >= $nbmax) break;
}
+ }
+
+ closedir($handle);
}
- closedir($handle);
- }
-
return $tabobj;
}
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 81571417529..b2957a5a33e 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -661,12 +661,12 @@ if ($_GET["id"] || $_GET["ref"])
if ($product->isproduct() && $conf->stock->enabled) $nblignes++;
if ($product->isservice()) $nblignes++;
if ($product->is_photo_available($conf->produit->dir_output))
- {
+ {
// Photo
print '';
$nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0);
print ' | ';
- }
+ }
print '';
// Libelle
diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php
index 1c06c551290..d5b49e8b053 100644
--- a/htdocs/product/photos.php
+++ b/htdocs/product/photos.php
@@ -178,12 +178,19 @@ if ($_GET["id"] || $_GET["ref"])
print '';
// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
- if ($obj['photo_vignette']) $filename=$obj['photo_vignette'];
- else $filename=$obj['photo'];
+ if ($obj['photo_vignette'])
+ {
+ $filename=$obj['photo_vignette'];
+ $viewfilename=$obj['photo'];
+ }
+ else
+ {
+ $filename=$obj['photo'];
+ }
print '
';
print '';
- print '
'.$langs->trans("File").': '.dolibarr_trunc($filename,16);
+ print '
'.$langs->trans("File").': '.dolibarr_trunc($viewfilename,16);
if ($user->rights->produit->creer)
{
print '
'.''.img_delete().'';