From 54b48dc64d59d331be7b5335fd82f11964385c6f Mon Sep 17 00:00:00 2001 From: Laurent Destailleur <eldy@users.sourceforge.net> Date: Fri, 14 Jul 2006 14:53:46 +0000 Subject: [PATCH] Fix: La liste des vignettes qd plusieurs photo affichaient toujours le meme nom de fichier --- htdocs/fourn/product/fiche.php | 2 +- htdocs/fourn/product/fourn.php | 2 +- htdocs/fourn/product/photos.php | 58 ++++++++++++++- htdocs/product.class.php | 100 ++++++++++++-------------- htdocs/product/fiche.php | 2 +- htdocs/product/photos.php | 10 +-- htdocs/product/sousproduits/fiche.php | 4 +- 7 files changed, 110 insertions(+), 68 deletions(-) diff --git a/htdocs/fourn/product/fiche.php b/htdocs/fourn/product/fiche.php index dda521e71bc..892138ce82e 100644 --- a/htdocs/fourn/product/fiche.php +++ b/htdocs/fourn/product/fiche.php @@ -371,7 +371,7 @@ else if ($product->type == 1) $nblignefour++; print '<td valign="middle" align="center" rowspan="'.$nblignefour.'">'; - $product->show_photo($conf->produit->dir_output,1); + $product->show_photos($conf->produit->dir_output,1,1,0); print '</td></tr>'; // Description diff --git a/htdocs/fourn/product/fourn.php b/htdocs/fourn/product/fourn.php index e92a2c1932d..eeb449fddd5 100644 --- a/htdocs/fourn/product/fourn.php +++ b/htdocs/fourn/product/fourn.php @@ -110,7 +110,7 @@ if ($_GET["id"]) print '<tr><td width="20%">'.$langs->trans("InternalRef").'</td><td width="40%">'.$product->ref.'</td>'; print '<td class="photo" valign="top" rowspan="6">'; - $product->show_photo($conf->produit->dir_output); + $product->show_photos($conf->produit->dir_output,1,1,0); print '</td></tr>'; print "<tr>"; diff --git a/htdocs/fourn/product/photos.php b/htdocs/fourn/product/photos.php index efb14a23974..b6a226de1da 100644 --- a/htdocs/fourn/product/photos.php +++ b/htdocs/fourn/product/photos.php @@ -139,9 +139,61 @@ if ($_GET["id"]) } - // Affiche photos - $nbphoto=$product->show_photos($conf->produit->dir_output,1); - if ($nbphoto < 1) print $langs->trans("NoPhotoYet")."<br><br>"; + // Affiche photos + if ($_GET["action"] != 'ajout_photo') + { + $nbphoto=0; + $nbbyrow=5; + + $pdir = get_exdir($product->id) . $product->id ."/photos/"; + $dir = $conf->produit->dir_output . '/'. $pdir; + + print '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; + + foreach ($product->liste_photos($dir) as $obj) + { + $nbphoto++; + +// if ($nbbyrow && $nbphoto == 1) print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; + + if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>'; + if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; + + print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">'; + + // Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine + if ($obj['photo_vignette']) $filename=$obj['photo_vignette']; + else $filename=$obj['photo']; + print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">'; + + print '</a>'; + print '<br>'.$langs->trans("File").': '.dolibarr_trunc($filename,16); + if ($user->rights->produit->creer) + { + print '<br>'.'<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&action=delete&file='.urlencode($pdir.$filename).'">'.img_delete().'</a>'; + } + if ($nbbyrow) print '</td>'; + if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print '</tr>'; + } + + // Ferme tableau + while ($nbphoto % $nbbyrow) + { + print '<td width="'.ceil(100/$nbbyrow).'%"> </td>'; + $nbphoto++; + } + + if ($nbphoto < 1) + { + print '<tr align=center valign=middle border=1><td class="photo">'; + print "<br>".$langs->trans("NoPhotoYet")."<br><br>"; + print '</td></tr></table>'; + } + + print '</table>'; + } + + print "</div>\n"; } diff --git a/htdocs/product.class.php b/htdocs/product.class.php index 1f693d1527f..593fc9a7f78 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1963,18 +1963,6 @@ function get_each_prod() } - /** - * \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) - { - return $this->show_photos($sdir,$size,1,0); - } - - /** * \brief Affiche toutes les photos du produit (nbmax maximum) * \param sdir R�pertoire � scanner @@ -1982,7 +1970,6 @@ function get_each_prod() * \param nbmax Nombre maximum de photos (0=pas de max) * \param nbbyrow Nombre vignettes par ligne (si mode vignette) * \return int Nombre de photos affich�es - * \todo A virer, seule la methode avec size=0 sert encore. */ function show_photos($sdir,$size=0,$nbmax=0,$nbbyrow=5) { @@ -2059,50 +2046,53 @@ function get_each_prod() return $nbphoto; } - /** - * \brief Retourne tableau de toutes les photos du produit - * \param dir R�pertoire � scanner - * \param nbmax Nombre maximum de photos (0=pas de max) - * \return array Tableau de photos - */ - function liste_photos($dir,$nbmax=0) - { - $nbphoto=0; - $tabobj=array(); - - if (file_exists($dir)) - { - $handle=opendir($dir); - - while (($file = readdir($handle)) != false) - { - if (is_file($dir.$file)) - { - $nbphoto++; - $photo = $file; + /** + * \brief Retourne tableau de toutes les photos du produit + * \param dir R�pertoire � scanner + * \param nbmax Nombre maximum de photos (0=pas de max) + * \return array Tableau de photos + */ + function liste_photos($dir,$nbmax=0) + { + $nbphoto=0; + $tabobj=array(); + + if (file_exists($dir)) + { + $handle=opendir($dir); + + while (($file = readdir($handle)) != false) + { + if (is_file($dir.$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->photo=$photo; - if ($photo_vignette && is_file($photo_vignette)) $obj->photo_vignette=$photo_vignette; - else $obj->photo_vignette=""; - $tabobj[$nbphoto-1]=$obj; + // 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']=""; - // On continue ou on arrete de boucler ? - if ($nbmax && $nbphoto >= $nbmax) break; - } - } - - closedir($handle); - } - - return $tabobj; - } + $tabobj[$nbphoto-1]=$obj; + + // On continue ou on arrete de boucler ? + if ($nbmax && $nbphoto >= $nbmax) break; + } + } + + closedir($handle); + } + + return $tabobj; + } /** diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php index 75000cccb21..41521d76c68 100644 --- a/htdocs/product/fiche.php +++ b/htdocs/product/fiche.php @@ -616,7 +616,7 @@ if ($_GET["id"] || $_GET["ref"]) { // Photo print '<td valign="middle" align="center" rowspan="'.$nblignes.'">'; - $nbphoto=$product->show_photo($conf->produit->dir_output,1); + $nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0); print '</td>'; } diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 5d1d58410f1..bf5ce99d84f 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -262,8 +262,8 @@ if ($_GET["id"] || $_GET["ref"]) $dir = $conf->produit->dir_output . '/'. $pdir; print '<br><table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">'; - - foreach ($product->liste_photos($dir) as $obj) + + foreach ($product->liste_photos($dir) as $key => $obj) { $nbphoto++; @@ -272,11 +272,11 @@ if ($_GET["id"] || $_GET["ref"]) if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print '<tr align=center valign=middle border=1>'; if ($nbbyrow) print '<td width="'.ceil(100/$nbbyrow).'%" class="photo">'; - print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$obj->photo).'" alt="Taille origine" target="_blank">'; + print '<a href="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$obj['photo']).'" alt="Taille origine" target="_blank">'; // 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']; + else $filename=$obj['photo']; print '<img border="0" height="120" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">'; print '</a>'; diff --git a/htdocs/product/sousproduits/fiche.php b/htdocs/product/sousproduits/fiche.php index ea24f8168aa..6d2e4550298 100644 --- a/htdocs/product/sousproduits/fiche.php +++ b/htdocs/product/sousproduits/fiche.php @@ -267,7 +267,7 @@ if ($id || $ref) { // Photo print '<td valign="middle" align="center" rowspan="'.$nblignes.'">'; - $nbphoto=$product->show_photo($conf->produit->dir_output,1); + $nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0); print '</td>'; } @@ -331,7 +331,7 @@ if ($id || $ref) { // Photo print '<td valign="middle" align="center" rowspan="'.$nblignes.'">'; - $nbphoto=$product->show_photo($conf->produit->dir_output,1); + $nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0); print '</td>'; } -- GitLab