Fix: La liste des vignettes qd plusieurs photo affichaient toujours le meme nom de fichier

This commit is contained in:
Laurent Destailleur 2006-07-14 14:53:46 +00:00
parent 5dbf26a344
commit 54b48dc64d
7 changed files with 110 additions and 68 deletions

View File

@ -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

View File

@ -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>";

View File

@ -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"].'&amp;action=delete&amp;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).'%">&nbsp;</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";
}

View File

@ -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;
}
/**

View File

@ -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>';
}

View File

@ -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>';

View File

@ -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>';
}