From d5b1097d135c79bd4bad84e3b5c59688a10dcfc9 Mon Sep 17 00:00:00 2001
From: Laurent Destailleur <eldy@users.sourceforge.net>
Date: Wed, 17 Feb 2010 18:57:08 +0000
Subject: [PATCH] Qual: Mutualize common code

---
 htdocs/product/fiche.php  |  8 ++---
 htdocs/product/photos.php | 69 +++------------------------------------
 htdocs/product/price.php  | 28 ++++++++++------
 3 files changed, 26 insertions(+), 79 deletions(-)

diff --git a/htdocs/product/fiche.php b/htdocs/product/fiche.php
index 46bb90f2efd..263d7678cb7 100644
--- a/htdocs/product/fiche.php
+++ b/htdocs/product/fiche.php
@@ -844,12 +844,12 @@ if ($_GET["id"] || $_GET["ref"])
 			// En mode visu
 			print '<table class="border" width="100%"><tr>';
 
-			// Reference
+			// Ref
 			print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
 			print $html->showrefnav($product,'ref','',1,'ref');
 			print '</td>';
 
-			$nblignes=4;
+			$nblignes=3;
 			if (! empty($conf->global->PRODUIT_MULTIPRICES_LIMIT) && empty($socid)) $nblignes+=$conf->global->PRODUIT_MULTIPRICES_LIMIT;
 			else $nblignes+=3;
 
@@ -862,7 +862,7 @@ if ($_GET["id"] || $_GET["ref"])
 			}
 			print '</tr>';
 
-			// Libelle
+			// Label
 			print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td></tr>';
 
 			// MultiPrix
@@ -988,7 +988,7 @@ if ($_GET["id"] || $_GET["ref"])
 			print '</td></tr>';
 
 			// Description
-			print '<tr><td valign="top">'.$langs->trans("Description").'</td><td>'.nl2br($product->description).'</td></tr>';
+			print '<tr><td valign="top">'.$langs->trans("Description").'</td><td colspan="2">'.nl2br($product->description).'</td></tr>';
 
 			// Nature
 			if($product->type!=1)
diff --git a/htdocs/product/photos.php b/htdocs/product/photos.php
index f2373082425..792762c5393 100644
--- a/htdocs/product/photos.php
+++ b/htdocs/product/photos.php
@@ -189,77 +189,16 @@ if ($_GET["id"] || $_GET["ref"])
 			$maxWidth = 160;
 			$maxHeight = 120;
 
-			$pdir = get_exdir($product->id,2) . $product->id ."/photos/";
-			$dir = $conf->produit->dir_output . '/'. $pdir;
-
-			print '<br>';
-			print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
-
-			foreach ($product->liste_photos($dir) as $key => $obj)
-			{
-				$nbphoto++;
-
-				//                if ($nbbyrow && $nbphoto == 1) print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';
-
-				// Do not use show_photo because there is more information to show
-				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="'.dol_escape_htmltag($langs->trans("OriginalSize")).'" target="_blank">';
-
-				// Si fichier vignette disponible, on l'utilise, sinon on utilise photo origine
-				if ($obj['photo_vignette'])
-				{
-					$filename='thumbs/'.$obj['photo_vignette'];
-				}
-				else
-				{
-					$filename=$obj['photo'];
-				}
-
-				// Nom affiche
-				$viewfilename=$obj['photo'];
-
-				// Taille de l'image
-				$product->get_image_size($dir.$filename);
-				$imgWidth = ($product->imgWidth < $maxWidth) ? $product->imgWidth : $maxWidth;
-				$imgHeight = ($product->imgHeight < $maxHeight) ? $product->imgHeight : $maxHeight;
-
-				print '<img class="photo" border="0" width="'.$imgWidth.'" height="'.$imgHeight.'" src="'.DOL_URL_ROOT.'/viewimage.php?modulepart=product&file='.urlencode($pdir.$filename).'">';
-
-				print '</a>';
-				print '<br>'.$viewfilename;
-				print '<br>';
-
-				// On propose la generation de la vignette si elle n'existe pas et si la taille est superieure aux limites
-				if (!$obj['photo_vignette'] && preg_match('/(\.bmp|\.gif|\.jpg|\.jpeg|\.png)$/i',$obj['photo']) && ($product->imgWidth > $maxWidth || $product->imgHeight > $maxHeight))
-				{
-					print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=addthumb&amp;file='.urlencode($pdir.$viewfilename).'">'.img_refresh($langs->trans('GenerateThumb')).'&nbsp;&nbsp;</a>';
-				}
-				if ($user->rights->produit->creer || $user->rights->service->creer)
-				{
-					print '<a href="'.$_SERVER["PHP_SELF"].'?id='.$_GET["id"].'&amp;action=delete&amp;file='.urlencode($pdir.$viewfilename).'">';
-					print 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++;
-			}
+			$nbphoto=$product->show_photos($conf->produit->dir_output,1,1000,$nbbyrow,1,1);
 
 			if ($nbphoto < 1)
 			{
-				print '<tr align=center valign=middle border=1><td class="photo">';
+				print '<br>';
+				print '<table width="100%" valign="top" align="center" border="0" cellpadding="2" cellspacing="2">';				print '<tr align=center valign=middle border=1><td class="photo">';
 				print "<br>".$langs->trans("NoPhotoYet")."<br><br>";
 				print '</td></tr>';
+				print '</table>';
 			}
-
-			print '</table>';
 		}
 	}
 }
diff --git a/htdocs/product/price.php b/htdocs/product/price.php
index 8cb60c8f8fc..a67f4318334 100644
--- a/htdocs/product/price.php
+++ b/htdocs/product/price.php
@@ -23,7 +23,7 @@
 /**
  *	\file       htdocs/product/price.php
  *	\ingroup    product
- *	\brief      Page de la fiche produit
+ *	\brief      Page to show product prices
  *	\version    $Id$
  */
 
@@ -126,17 +126,26 @@ dol_fiche_head($head, 'price', $titre, 0, $picto);
 
 print '<table class="border" width="100%">';
 
-// Reference
-print '<tr>';
-print '<td width="15%">'.$langs->trans("Ref").'</td><td colspan="2">';
+// Ref
+print '<td width="15%">'.$langs->trans("Ref").'</td><td>';
 print $html->showrefnav($product,'ref','',1,'ref');
 print '</td>';
-print '</tr>';
 
-// Libelle
-print '<tr><td>'.$langs->trans("Label").'</td><td colspan="2">'.$product->libelle.'</td>';
+$nblignes=3;
+if (! empty($conf->global->PRODUIT_MULTIPRICES_LIMIT) && empty($socid)) $nblignes+=$conf->global->PRODUIT_MULTIPRICES_LIMIT;
+else $nblignes+=3;
+
+if ($product->is_photo_available($conf->produit->dir_output))
+{
+	// Photo
+	print '<td valign="middle" align="center" width="30%" rowspan="'.$nblignes.'">';
+	$nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0);
+	print '</td>';
+}
 print '</tr>';
 
+// Label
+print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td></tr>';
 
 // MultiPrix
 if($conf->global->PRODUIT_MULTIPRICES)
@@ -252,12 +261,11 @@ else
 	print '</td></tr>';
 
 	// TVA
-	print '<tr><td>'.$langs->trans("VATRate").'</td><td colspan="2">'.vatrate($product->tva_tx,true).'</td></tr>';
-
+	print '<tr><td>'.$langs->trans("VATRate").'</td><td>'.vatrate($product->tva_tx,true).'</td></tr>';
 }
 
 // Statut
-print '<tr><td>'.$langs->trans("Status").'</td><td colspan="2">';
+print '<tr><td>'.$langs->trans("Status").'</td><td>';
 print $product->getLibStatut(2);
 print '</td></tr>';
 
-- 
GitLab