diff --git a/htdocs/product.class.php b/htdocs/product.class.php index ab0493a9019..ccf0a29ae89 100644 --- a/htdocs/product.class.php +++ b/htdocs/product.class.php @@ -1029,6 +1029,7 @@ class Product * \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) { @@ -1057,6 +1058,7 @@ class Product $photo_vignette=eregi_replace($regs[0],'',$photo)."_small".$regs[0]; } + if ($nbbyrow && $nbphoto == 1) print ''; if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print ''; @@ -1076,6 +1078,7 @@ class Product if ($nbbyrow) print ''; if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; + } if ($size == 0) // Format origine @@ -1102,6 +1105,51 @@ class Product 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; + + // 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 continue ou on arrete de boucler ? + if ($nbmax && $nbphoto >= $nbmax) break; + } + } + + closedir($handle); + } + + return $tabobj; + } } ?> diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php index 1bb0b815731..79c70d68d6c 100644 --- a/htdocs/product/photos.php +++ b/htdocs/product/photos.php @@ -49,7 +49,7 @@ $types[1] = $langs->trans("Service"); * Actions */ -if ( $_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) +if ($_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) { if ($_GET["id"]) { @@ -64,10 +64,16 @@ if ( $_POST["sendit"] && defined('MAIN_UPLOAD_DOC') && MAIN_UPLOAD_DOC == 1) } } +if ($_GET["action"] == 'delete' && $_GET["file"]) +{ + unlink($conf->produit->dir_output."/".$_GET["file"]); +} + /* * */ + llxHeader("","",$langs->trans("CardProduct0")); @@ -186,16 +192,58 @@ if ($_GET["id"]) print ''; } - // Affiche photos - if ($_GET["action"] != 'ajout_photo') { - //print '
'; - //print '
'; - $nbphoto=$product->show_photos($conf->produit->dir_output,1,0,5); + if ($_GET["action"] != 'ajout_photo') + { + $nbphoto=0; + $nbbyrow=5; + + $pdir = get_exdir($product->id) . $product->id ."/photos/"; + $dir = $conf->produit->dir_output . '/'. $pdir; + print '
'; + + foreach ($product->liste_photos($dir) as $obj) + { + $nbphoto++; - if ($nbphoto < 1) print $langs->trans("NoPhotoYet")."

"; - //print ''; +// if ($nbbyrow && $nbphoto == 1) print '
'; + + if ($nbbyrow && ($nbphoto % $nbbyrow == 1)) print ''; + if ($nbbyrow) print ''; + if ($nbbyrow && ($nbphoto % $nbbyrow == 0)) print ''; + } + + // Ferme tableau + while ($nbphoto % $nbbyrow) + { + print ''; + $nbphoto++; + } + + if ($nbphoto < 1) + { + print '
'; + + 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; + print ''; + + print ''; + print '
'.$langs->trans("File").': '.dolibarr_trunc($filename,16); + if ($user->rights->produit->creer) + { + print '
'.''.img_delete().''; + } + if ($nbbyrow) print '
 
'; + print "
".$langs->trans("NoPhotoYet")."

"; + print '
'; + } + + print ''; } } }