diff --git a/htdocs/langs/en_US/products.lang b/htdocs/langs/en_US/products.lang index 1c7452f6a19..38694b6ded1 100644 --- a/htdocs/langs/en_US/products.lang +++ b/htdocs/langs/en_US/products.lang @@ -52,4 +52,5 @@ AddToOtherProposals=Add to other proposals AddToMyBills=Add to my bills AddToOtherBills=Add to other bills CorrectStock=Correct stock -ListOfStockMovements=List of stock movements \ No newline at end of file +ListOfStockMovements=List of stock movements +NoPhotoYet=No pictures available yet \ No newline at end of file diff --git a/htdocs/langs/fr_FR/products.lang b/htdocs/langs/fr_FR/products.lang index f5a3a5f944c..3914e8ae584 100644 --- a/htdocs/langs/fr_FR/products.lang +++ b/htdocs/langs/fr_FR/products.lang @@ -56,4 +56,5 @@ AddToMyBills=Ajouter AddToOtherBills=Ajouter aux autres factures CorrectStock=Corriger stock AddPhoto=Ajouter une photo -ListOfStockMovements=Liste des mouvements de stock \ No newline at end of file +ListOfStockMovements=Liste des mouvements de stock +NoPhotoYet=Pas de photos disponibles pour l'instant \ No newline at end of file diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 90398f972a7..e7f86baa3fd 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -880,62 +880,28 @@ class Product * \brief Affiche la première photo du produit * \param sdir Répertoire à scanner * \param size 0=taille origine, 1 taille vignette + * \return int Nombre de photos affichées */ function show_photo($sdir,$size=0) { - $pdir = get_exdir($this->id) . $this->id ."/photos/"; - $dir = $sdir . '/'. $pdir; - - if ( file_exists($dir)) - { - $handle=opendir($dir); - - while (($file = readdir($handle))!==false) - { - $photo=''; - if (is_file($dir.$file)) $photo = $file; - - if ($photo) - { - if ($size == 1) { - // 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]; - } - print ''; - - // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine - if ($photo_vignette && is_file($photo_vignette)) { - print ''; - } - else { - print ''; - } - - print ''; - } - - if ($size == 0) - print ''; - - break; - } - } - } + return $this->show_photos($sdir,$size,1); } /** - * \brief Affiche toutes les photos du produit - * \param sdir Répertoire à scanner - * \param size 0=taille origine, 1 taille vignette + * \brief Affiche toutes les photos du produit (nbmax maximum) + * \param sdir Répertoire à scanner + * \param size 0=taille origine, 1 taille vignette + * \param nbmax Nombre maximum de photos + * \return int Nombre de photos affichées */ - function show_photos($sdir,$size=0) + function show_photos($sdir,$size=0,$nbmax=0) { + $nbphoto=0; + $pdir = get_exdir($this->id) . $this->id ."/photos/"; $dir = $sdir . '/'. $pdir; - if ( file_exists($dir)) + if (file_exists($dir)) { $handle=opendir($dir); @@ -946,6 +912,8 @@ class Product if ($photo) { + $nbphoto++; + if ($size == 1) { // On determine nom du fichier vignette $photo_vignette=''; @@ -968,10 +936,14 @@ class Product if ($size == 0) print ''; - print ' '; + // On continue ou on arrete de boucler ? + if ($nbmax && $nbphoto >= $nbmax) break; + else print ' '; } } } + + return $nbphoto; } } diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index f2fcf49ca1d..30536fd923a 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -699,7 +699,7 @@ print "\n\n"; */ if ($_GET["id"] && $_GET["action"]=='') { - print $product->show_photo($conf->produit->dir_output,1); + $nbphoto=$product->show_photo($conf->produit->dir_output,1); } if ($_GET["id"] && $_GET["action"] == '' && $product->envente) diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 8b072142b01..7bb7e7e8736 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -141,16 +141,11 @@ if ($_GET["id"]) print "
\n"; - /* - * Photo - * - */ - if ($_GET["id"] && $_GET["action"]=='') - { - print $product->show_photos($conf->produit->dir_output,1); - } + // Affiche photos + $nbphoto=$product->show_photos($conf->produit->dir_output,1); + if ($nbphoto < 1) print $langs->trans("NoPhotoYet")."

"; - print "
\n"; + print "\n"; } } else