diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 8a686c54042..90398f972a7 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -877,56 +877,101 @@ class Product
}
/**
- *
- *
+ * \brief Affiche la première photo du produit
+ * \param sdir Répertoire à scanner
+ * \param size 0=taille origine, 1 taille vignette
*/
- function show_photo($sdir)
+ function show_photo($sdir,$size=0)
{
- $photo = '';
$pdir = get_exdir($this->id) . $this->id ."/photos/";
$dir = $sdir . '/'. $pdir;
-
+
if ( file_exists($dir))
- {
- $handle=opendir($dir);
-
- while (($file = readdir($handle))!==false)
- {
- if (is_file($dir.$file))
- {
- $photo = $file;
- }
- }
-
- if (strlen($photo))
- {
- print '
';
- }
- }
+ {
+ $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;
+ }
+ }
+ }
}
/**
- * Je sais c'est sale mais le besoin est urgent ;-)
- *
+ * \brief Affiche toutes les photos du produit
+ * \param sdir Répertoire à scanner
+ * \param size 0=taille origine, 1 taille vignette
*/
- function show_photos($sdir)
+ function show_photos($sdir,$size=0)
{
- $photo = '';
$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 '';
- $handle=opendir($dir);
-
- while (($file = readdir($handle))!==false)
- {
- if (is_file($dir.$file))
- {
- $photo = $file;
- 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 '
';
+
+ print ' ';
+ }
+ }
+ }
}
}
diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 9c5aa6d50cc..f2fcf49ca1d 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);
+ print $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 20125fc5f39..8b072142b01 100644
--- a/htdocs/product/photos.php
+++ b/htdocs/product/photos.php
@@ -147,7 +147,7 @@ if ($_GET["id"])
*/
if ($_GET["id"] && $_GET["action"]=='')
{
- print $product->show_photos($conf->produit->dir_output);
+ print $product->show_photos($conf->produit->dir_output,1);
}
print "
\n";