Fix: Fix awfull code for subproduct option

This commit is contained in:
Laurent Destailleur 2010-03-04 19:42:01 +00:00
parent b7201c5c5d
commit 87dccc1e76
7 changed files with 172 additions and 75 deletions

View File

@ -541,7 +541,16 @@ if ($_GET["action"] == 'create')
{ {
foreach($prods_arbo as $key => $value) foreach($prods_arbo as $key => $value)
{ {
print $value[0]; //print $value[0];
$img='';
if ($value['stock'] < $value['stock_alert'])
{
$img=img_warning($langs->trans("StockTooLow"));
}
print "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
</a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$value['stock']." ".$img."</td></tr>";
} }
} }
} }

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2003-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2009 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* *
* This program is free software; you can redistribute it and/or modify * This program is free software; you can redistribute it and/or modify
@ -26,6 +26,7 @@
*/ */
require("../main.inc.php"); require("../main.inc.php");
require(DOL_DOCUMENT_ROOT."/commande/commande.class.php");
$langs->load("orders"); $langs->load("orders");
$langs->load("sendings"); $langs->load("sendings");
@ -34,6 +35,9 @@ $langs->load("sendings");
* View * View
*/ */
$orderstatic=new Commande($db);
$companystatic=new Societe($db);
$helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones'; $helpurl='EN:Module_Shipments|FR:Module_Exp&eacute;ditions|ES:M&oacute;dulo_Expediciones';
llxHeader('',$langs->trans("Sendings"),$helpurl); llxHeader('',$langs->trans("Sendings"),$helpurl);
@ -126,13 +130,18 @@ if ( $db->query($sql) )
$var = True; $var = True;
while ($i < $num) while ($i < $num)
{ {
$var=!$var; $var=!$var;
$obj = $db->fetch_object(); $obj = $db->fetch_object();
print "<tr $bc[$var]>"; print "<tr $bc[$var]>";
print '<td nowrap="nowrap">'; print '<td nowrap="nowrap">';
print "<a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '.$obj->ref.'</a></td>'; $orderstatic->id=$obj->rowid;
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.dol_trunc($obj->nom,20).'</a></td></tr>'; $orderstatic->ref=$obj->ref;
$i++; print $orderstatic->getNomUrl(1);
print '</td>';
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.dol_trunc($obj->nom,20).'</a>';
print '</td></tr>';
$i++;
} }
print "</table><br>"; print "</table><br>";
} }
@ -173,12 +182,15 @@ if ( $resql )
$var = True; $var = True;
while ($i < $num) while ($i < $num)
{ {
$var=!$var; $var=!$var;
$obj = $db->fetch_object($resql); $obj = $db->fetch_object($resql);
print "<tr $bc[$var]><td width=\"30%\"><a href=\"commande.php?id=".$obj->rowid."\">".img_object($langs->trans("ShowOrder"),"order").' '; print "<tr $bc[$var]><td width=\"30%\">";
print $obj->ref.'</a></td>'; $orderstatic->id=$obj->rowid;
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td></tr>'; $orderstatic->ref=$obj->ref;
$i++; print $orderstatic->getNomUrl(1);
print '</td>';
print '<td><a href="'.DOL_URL_ROOT.'/comm/fiche.php?socid='.$obj->socid.'">'.$obj->nom.'</a></td></tr>';
$i++;
} }
print "</table><br>"; print "</table><br>";
} }
@ -230,9 +242,11 @@ if ($resql)
print '<td>'; print '<td>';
if ($obj->commande_id) if ($obj->commande_id)
{ {
print '<a href="'.DOL_URL_ROOT.'/commande/fiche.php?id='.$obj->commande_id.'">'; $orderstatic->id=$obj->commande_id;
print img_object($langs->trans("ShowOrder"),"order").' '.$obj->commande_ref.'</a>'; $orderstatic->ref=$obj->commande_ref;
} else print '&nbsp;'; print $orderstatic->getNomUrl(1);
}
else print '&nbsp;';
print '</td></tr>'; print '</td></tr>';
$i++; $i++;
} }

View File

@ -528,7 +528,18 @@ if ($id > 0 || ! empty($ref))
foreach($prods_arbo as $key => $value) foreach($prods_arbo as $key => $value)
{ {
print '<tr><td colspan="4">'; print '<tr><td colspan="4">';
$img='';
if ($value['stock'] < $value['stock_alert'])
{
$img=img_warning($langs->trans("StockTooLow"));
}
print "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$value['id']."\">".$value['fullpath']."
</a> (".$value['nb'].")</td><td align=\"center\"> ".$value['nb_total']."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$value['stock']." ".$img."</td></tr>";
print $value[0]; print $value[0];
print '</td></tr>'."\n"; print '</td></tr>'."\n";
} }
} }

View File

@ -106,9 +106,9 @@ ServiceLimitedDuration=If product is a service with limited duration:
MultiPricesAbility=Activate the multi-prices MultiPricesAbility=Activate the multi-prices
MultiPricesNumPrices=Number of price MultiPricesNumPrices=Number of price
MultiPriceLevelsName=Price categories MultiPriceLevelsName=Price categories
AssociatedProductsAbility=Activate the associated products AssociatedProductsAbility=Activate the sub-products
AssociatedProducts=Associated products AssociatedProducts=Sub-products
AssociatedProductsNumber=Number of associated products AssociatedProductsNumber=Number of products composing this product
EditAssociate=Associate EditAssociate=Associate
Translation=Translation Translation=Translation
KeywordFilter=Keyword filter KeywordFilter=Keyword filter

View File

@ -106,10 +106,10 @@ ServiceLimitedDuration=Si produit de type service à durée limitée :
MultiPricesAbility=Prise en charges de prix multiples MultiPricesAbility=Prise en charges de prix multiples
MultiPricesNumPrices=Nombre de prix MultiPricesNumPrices=Nombre de prix
MultiPriceLevelsName=Catégorie de prix MultiPriceLevelsName=Catégorie de prix
AssociatedProductsAbility=Prise en charges des produits associés AssociatedProductsAbility=Prise en charges des produits composés
AssociatedProducts=Produits associés AssociatedProducts=Composition
AssociatedProductsNumber=Nbre de produits associés AssociatedProductsNumber=Nbre de sous-produits composant ce produit
EditAssociate=Associer EditAssociate=Composer
Translation=Traduction Translation=Traduction
KeywordFilter=Filtre par mot-clé KeywordFilter=Filtre par mot-clé
CategoryFilter=Filtre par catégorie CategoryFilter=Filtre par catégorie
@ -117,7 +117,7 @@ ProductToAddSearch=Recherche des produits à ajouter
AddDel=Ajouter/Retirer AddDel=Ajouter/Retirer
Quantity=Quantité Quantity=Quantité
NoMatchFound=Aucun résultat n'a été trouvé NoMatchFound=Aucun résultat n'a été trouvé
ProductAssociationList=Liste des produits/services associés : nom du produit/service (quantité affectée) ProductAssociationList=Liste des produits/services composant ce produit: Le nombre entre paraenthèse est la quantité affectée dans cette composition.
ErrorAssociationIsFatherOfThis=L'un des produits sélectionnés est parent du produit en cours ErrorAssociationIsFatherOfThis=L'un des produits sélectionnés est parent du produit en cours
DeleteProduct=Supprimer un produit/service DeleteProduct=Supprimer un produit/service
ConfirmDeleteProduct=Etes-vous sûr de vouloir supprimer ce produit/service ? ConfirmDeleteProduct=Etes-vous sûr de vouloir supprimer ce produit/service ?

View File

@ -1478,7 +1478,7 @@ class Product extends CommonObject
* \brief Lie un produit associe au produit/service * \brief Lie un produit associe au produit/service
* \param id_pere Id du produit auquel sera lie le produit a lier * \param id_pere Id du produit auquel sera lie le produit a lier
* \param id_fils Id du produit a lier * \param id_fils Id du produit a lier
* \return int < 0 si erreur, > 0 si ok * \return int < 0 if KO, > 0 if OK
*/ */
function add_sousproduit($id_pere, $id_fils,$qty) function add_sousproduit($id_pere, $id_fils,$qty)
{ {
@ -1839,15 +1839,16 @@ class Product extends CommonObject
} }
/** /**
* \brief fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits * \brief Fonction recursive uniquement utilisee par get_arbo_each_prod, recompose l'arborescence des sousproduits
* \remarks Define value of this->res * \remarks Define value of this->res
* \param multiply Because each sublevel must be multiplicated by parent nb * \param multiply Because each sublevel must be multiplicated by parent nb
* \return void * \return void
*/ */
function fetch_prod_arbo($prod, $compl_path="", $multiply=1, $level=1) function fetch_prod_arbo($prod, $compl_path="", $multiply=1, $level=1)
{ {
global $langs; global $conf,$langs;
$product = new Product($this->db);
foreach($prod as $nom_pere => $desc_pere) foreach($prod as $nom_pere => $desc_pere)
{ {
if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs if (is_array($desc_pere)) // If this parent desc is an array, this is an array of childs
@ -1856,8 +1857,6 @@ class Product extends CommonObject
{ {
//print "XXX ".$desc_pere[1]." multiply=".$multiply; //print "XXX ".$desc_pere[1]." multiply=".$multiply;
$img=""; $img="";
$trueValue=$desc_pere[1]*$multiply;
$product = new Product($this->db);
$this->fetch($desc_pere[0]); $this->fetch($desc_pere[0]);
$this->load_stock(); $this->load_stock();
if ($this->stock_entrepot[1] < $this->seuil_stock_alerte) if ($this->stock_entrepot[1] < $this->seuil_stock_alerte)
@ -1865,18 +1864,35 @@ class Product extends CommonObject
$img=img_warning($langs->trans("StockTooLow")); $img=img_warning($langs->trans("StockTooLow"));
} }
$this->res[]= array( $this->res[]= array(
"<tr><td>&nbsp; &nbsp; &nbsp; -> /* "<tr><td>&nbsp; &nbsp; &nbsp; ->
<a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)." <a href=\"".DOL_URL_ROOT."/product/fiche.php?id=".$desc_pere[0]."\">".$compl_path.stripslashes($nom_pere)."
</a> (".$desc_pere[1].")</td><td align=\"center\"> ".$trueValue."</td><td>&nbsp</td><td>&nbsp</td> </a> (".$desc_pere[1].")</td><td align=\"center\"> ".($desc_pere[1]*$multiply)."</td><td>&nbsp</td><td>&nbsp</td>
<td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>", <td align=\"center\">".$this->stock_entrepot[1]." ".$img."</td></tr>",
$desc_pere[0], $desc_pere[0], // Id product
'fullpath' => $compl_path.$nom_pere); */ 'id'=>$desc_pere[0], // Id product
'nb'=>$desc_pere[1], // Nb of units that compose parent product
'nb_total'=>$desc_pere[1]*$multiply, // Nb of units for all nb of product
'stock'=>$this->stock_entrepot[1], // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
'fullpath' => $compl_path.$nom_pere, // Label
'type'=>$desc_pere[2] // Nb of units that compose parent product
);
} }
else else
{ {
$this->res[]= array($compl_path.$nom_pere." (".$desc_pere[1].")", $this->fetch($desc_pere[0]);
$desc_pere[0], $this->load_stock();
'fullpath' => $compl_path.$nom_pere); $this->res[]= array(
/* $compl_path.$nom_pere." (".$desc_pere[1].")",
$desc_pere[0], // Id product
*/ 'id'=>$desc_pere[0], // Id product
'nb'=>$desc_pere[1], // Nb of units that compose parent product
'nb_total'=>$desc_pere[1], // Nb of units for all nb of product
'stock'=>$this->stock_entrepot[1], // Stock
'stock_alert'=>$this->seuil_stock_alerte, // Stock alert
'fullpath' => $compl_path.$nom_pere, // Label
'type'=>$desc_pere[2] // Nb of units that compose parent product
);
} }
} }
else if($nom_pere != "0" && $nom_pere != "1") else if($nom_pere != "0" && $nom_pere != "1")
@ -1952,15 +1968,15 @@ class Product extends CommonObject
} }
/** /**
* \brief Return all parent products * \brief Return all parent products fo current product
* \return array prod * \return array prod
*/ */
function getParent() function getParent()
{ {
$sql = "SELECT p.label as label,p.rowid,pa.fk_product_pere as id"; $sql = "SELECT p.label as label,p.rowid,pa.fk_product_pere as id,p.fk_product_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa"; $sql.= " FROM ".MAIN_DB_PREFIX."product_association as pa,";
$sql.= ", ".MAIN_DB_PREFIX."product as p"; $sql.= " ".MAIN_DB_PREFIX."product as p";
$sql.= " WHERE p.rowid = pa.fk_product_pere"; $sql.= " WHERE p.rowid = pa.fk_product_pere";
$sql.= " AND p.rowid = ".$this->id; $sql.= " AND p.rowid = ".$this->id;
@ -1982,12 +1998,13 @@ class Product extends CommonObject
} }
/** /**
* \brief Return childs * \brief Return childs of prodcut with if fk_parent
* \return array prod * \param fk_parent Id of product to search childs of
* \return array Prod
*/ */
function getChildsArbo($fk_parent) function getChildsArbo($fk_parent)
{ {
$sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id"; $sql = "SELECT p.rowid, p.label as label, pa.qty as qty, pa.fk_product_fils as id, p.fk_product_type";
$sql.= " FROM ".MAIN_DB_PREFIX."product as p"; $sql.= " FROM ".MAIN_DB_PREFIX."product as p";
$sql.= ", ".MAIN_DB_PREFIX."product_association as pa"; $sql.= ", ".MAIN_DB_PREFIX."product_association as pa";
$sql.= " WHERE p.rowid = pa.fk_product_fils"; $sql.= " WHERE p.rowid = pa.fk_product_fils";
@ -1999,10 +2016,15 @@ class Product extends CommonObject
$prods = array(); $prods = array();
while ($rec = $this->db->fetch_array($res)) while ($rec = $this->db->fetch_array($res))
{ {
//$prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty'],2=>$rec['fk_product_type']);
$prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']); $prods[addslashes($rec['label'])]= array(0=>$rec['id'],1=>$rec['qty']);
foreach($this->getChildsArbo($rec['id']) as $keyChild => $valueChild) $listofchilds=$this->getChildsArbo($rec['id']);
$prods[addslashes($rec['label'])][$keyChild] = $valueChild; foreach($listofchilds as $keyChild => $valueChild)
{
$prods[addslashes($rec['label'])][$keyChild] = $valueChild;
}
} }
//var_dump($prods);
return $prods; return $prods;
} }
else else
@ -2027,6 +2049,7 @@ class Product extends CommonObject
$parent[$key][$keyChild] = $valueChild; $parent[$key][$keyChild] = $valueChild;
} }
} }
//var_dump($parent);
// concatenation // concatenation
foreach($parent as $key => $value) foreach($parent as $key => $value)
{ {

View File

@ -1,6 +1,6 @@
<?php <?php
/* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org> /* Copyright (C) 2001-2007 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2008 Laurent Destailleur <eldy@users.sourceforge.net> * Copyright (C) 2004-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com> * Copyright (C) 2005 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr> * Copyright (C) 2005-2009 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr> * Copyright (C) 2006 Andre Cianfarani <acianfa@free.fr>
@ -67,7 +67,7 @@ if ($action == 'add_prod' &&
$cancel <> $langs->trans("Cancel") && $cancel <> $langs->trans("Cancel") &&
($user->rights->produit->creer || $user->rights->service->creer)) ($user->rights->produit->creer || $user->rights->service->creer))
{ {
$error=0;
for($i=0;$i<$_POST["max_prod"];$i++) for($i=0;$i<$_POST["max_prod"];$i++)
{ {
// print "<br> : ".$_POST["prod_id_chk".$i]; // print "<br> : ".$_POST["prod_id_chk".$i];
@ -79,26 +79,33 @@ $cancel <> $langs->trans("Cancel") &&
} }
else else
{ {
$error++;
$action = 're-edit'; $action = 're-edit';
if($product->error == "isFatherOfThis") if ($product->error == "isFatherOfThis") $mesg = $langs->trans("ErrorAssociationIsFatherOfThis");
$mesg = $langs->trans("ErrorAssociationIsFatherOfThis"); else $mesg=$product->error;
} }
} }
else else
{ {
if($product->del_sousproduit($id, $_POST["prod_id_".$i])) if ($product->del_sousproduit($id, $_POST["prod_id_".$i]) > 0)
{ {
$action = 'edit'; $action = 'edit';
} }
else else
{ {
$error++;
$action = 're-edit'; $action = 're-edit';
$mesg=$product->error;
} }
} }
} }
if (! $error)
{
header("Location: ".$_SERVER["PHP_SELF"].'?id='.$product->id);
exit;
}
} }
// action recherche des produits par mot-cle et/ou par categorie // action recherche des produits par mot-cle et/ou par categorie
if($action == 'search' ) if($action == 'search' )
{ {
@ -180,27 +187,32 @@ if ($id || $ref)
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>'; print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>'; print '</tr>';
// Number of subproducts
$product->get_sousproduits_arbo (); $product->get_sousproduits_arbo ();
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>'; print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>';
// associations sousproduits // List of subproducts
$prods_arbo = $product->get_arbo_each_prod(); $prods_arbo = $product->get_arbo_each_prod();
if(sizeof($prods_arbo) > 0) if(sizeof($prods_arbo) > 0)
{ {
print '<tr><td colspan="2">'; print '<tr><td colspan="2">';
print '<b>'.$langs->trans("ProductAssociationList").'</b><br>'; print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
foreach($prods_arbo as $key => $value) print '<table class="nobordernopadding">';
foreach($prods_arbo as $value)
{ {
$productstatic->id=$value[1]; $productstatic->id=$value['id'];
$productstatic->type=0; $productstatic->type=$value['type'];
//$productstatic->ref=$value[0]; $productstatic->ref=$value['fullpath'];
//var_dump($value); //var_dump($value);
//print '<pre>'.$productstatic->ref.'</pre>'; //print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>'; //print $productstatic->getNomUrl(1).'<br>';
print $value[0]; // This contains a tr line. //print $value[0]; // This contains a tr line.
print '<tr>';
print '<td>'.$productstatic->getNomUrl(1).' ('.$value['nb'].')</td>';
print '<td></td>';
print '</tr>';
} }
print '</table>';
print '</td></tr>'; print '</td></tr>';
} }
@ -225,27 +237,45 @@ if ($id || $ref)
// Reference // Reference
print '<td width="25%">'.$langs->trans("Ref").'</td><td>'; print '<td width="25%">'.$langs->trans("Ref").'</td><td>';
print $html->showrefnav($product,'ref','',1,'ref'); print $html->showrefnav($product,'ref','',1,'ref');
print '</td></tr>';
if ($product->is_photo_available($conf->produit->dir_output))
{
// Photo
print '<td valign="middle" align="center" rowspan="'.$nblignes.'">';
$nbphoto=$product->show_photos($conf->produit->dir_output,1,1,0);
print '</td>'; print '</td>';
}
print '</tr>'; print '</tr>';
// Libelle // Label
print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>'; print '<tr><td>'.$langs->trans("Label").'</td><td>'.$product->libelle.'</td>';
print '</tr>'; print '</tr>';
// Nombre de sousproduits associes // Number of subproducts
$product->get_sousproduits_arbo (); $product->get_sousproduits_arbo ();
print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>'; print '<tr><td>'.$langs->trans("AssociatedProductsNumber").'</td><td>'.sizeof($product->get_arbo_each_prod()).'</td>';
print '</tr>'; print '</tr>';
// List of subproducts
$prods_arbo = $product->get_arbo_each_prod();
//var_dump($prods_arbo);
if(sizeof($prods_arbo) > 0)
{
print '<tr><td colspan="2">';
print '<b>'.$langs->trans("ProductAssociationList").'</b><br>';
print '<table class="nobordernopadding">';
foreach($prods_arbo as $value)
{
$productstatic->id=$value['id'];
$productstatic->type=$value['type'];
$productstatic->ref=$value['fullpath'];
//var_dump($value);
//print '<pre>'.$productstatic->ref.'</pre>';
//print $productstatic->getNomUrl(1).'<br>';
//print $value[0]; // This contains a tr line.
print '<tr>';
print '<td>'.$productstatic->getNomUrl(1).' ('.$value['nb'].')</td>';
print '<td></td>';
print '</tr>';
}
print '</table>';
print '</td></tr>';
}
print '</table>'; print '</table>';
print '<br>'; print '<br>';
@ -253,6 +283,7 @@ if ($id || $ref)
print '<form action="'.DOL_URL_ROOT.'/product/sousproduits/fiche.php?id='.$id.'" method="post">'; print '<form action="'.DOL_URL_ROOT.'/product/sousproduits/fiche.php?id='.$id.'" method="post">';
print '<table class="nobordernopadding">'; print '<table class="nobordernopadding">';
print '<tr><td><b>'.$langs->trans("ProductToAddSearch").'</b></td></tr>'; print '<tr><td><b>'.$langs->trans("ProductToAddSearch").'</b></td></tr>';
print '<tr><td>'; print '<tr><td>';
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">'; print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print $langs->trans("KeywordFilter"); print $langs->trans("KeywordFilter");
@ -299,14 +330,16 @@ if ($id || $ref)
if($objp->rowid != $id) if($objp->rowid != $id)
{ {
// check if a product is not already a parent product of this one // check if a product is not already a parent product of this one
$prod_arbo=new Product($db,$objp->rowid); $prod_arbo=new Product($db);
$prod_arbo->id=$objp->rowid;
if ($prod_arbo->type==2 || $prod_arbo->type==3) if ($prod_arbo->type==2 || $prod_arbo->type==3)
{ {
$is_pere=0; $is_pere=0;
$prod_arbo->get_sousproduits_arbo (); $prod_arbo->get_sousproduits_arbo ();
// associations sousproduits // associations sousproduits
$prods_arbo = $prod_arbo->get_arbo_each_prod(); $prods_arbo = $prod_arbo->get_arbo_each_prod();
if(sizeof($prods_arbo) > 0) { if (sizeof($prods_arbo) > 0)
{
foreach($prods_arbo as $key => $value) foreach($prods_arbo as $key => $value)
{ {
if ($value[1]==$id) if ($value[1]==$id)
@ -354,8 +387,15 @@ if ($id || $ref)
dol_print_error($db); dol_print_error($db);
} }
print '<input type="hidden" name="max_prod" value="'.$i.'">'; print '<input type="hidden" name="max_prod" value="'.$i.'">';
if($num > 0) print '<tr><td colspan="4" align="center"><br><input type="submit" class="button" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'"></td></tr>';
print '</table>'; print '</table>';
if($num > 0)
{
print '<br><center><input type="submit" class="button" value="'.$langs->trans("Add").'/'.$langs->trans("Update").'">';
print ' &nbsp; &nbsp; <input type="submit" class="button" value="'.$langs->trans("Cancel").'">';
print '</center>';
}
print '</form>'; print '</form>';
} }