diff --git a/htdocs/product/sousproduits/fiche.php b/htdocs/product/sousproduits/fiche.php
index 63e906e61ea..540c9885157 100644
--- a/htdocs/product/sousproduits/fiche.php
+++ b/htdocs/product/sousproduits/fiche.php
@@ -50,6 +50,12 @@ $id=isset($_GET["id"])?$_GET["id"]:$_POST["id"];
$action=isset($_GET["action"])?$_GET["action"]:$_POST["action"];
$cancel=isset($_GET["cancel"])?$_GET["cancel"]:$_POST["cancel"];
+if ($action <> 're-edit')
+ {
+ $product = new Product($db);
+ if ($id) $result = $product->fetch($id);
+ if ($ref) $result = $product->fetch($ref);
+ }
if (!$user->rights->produit->lire) accessforbidden();
@@ -58,47 +64,43 @@ $html = new Form($db);
$types[0] = $langs->trans("Product");
$types[1] = $langs->trans("Service");
-// Action mise a jour d'un produit ou service
-if ($action == 'update' &&
+// Action association d'un sousproduit
+if ($action == 'add_prod' &&
$cancel <> $langs->trans("Cancel") &&
$user->rights->produit->creer)
{
- $product = new Product($db);
- if ($product->fetch($_POST["id"]))
- {
- $product->ref = stripslashes($_POST["ref"]);
- $product->libelle = stripslashes($_POST["libelle"]);
- if ( isset( $_POST["price"] ) )
- $product->price = stripslashes($_POST["price"]);
- $product->tva_tx = $_POST["tva_tx"];
- $product->description = stripslashes($_POST["desc"]);
- $product->note = stripslashes($_POST["note"]);
- $product->envente = $_POST["statut"];
- $product->seuil_stock_alerte = $_POST["seuil_stock_alerte"];
- $product->duration_value = $_POST["duration_value"];
- $product->duration_unit = $_POST["duration_unit"];
-
- if ($product->check())
- {
- if ($product->update($product->id, $user) > 0)
- {
- $action = '';
- $_GET["id"] = $_POST["id"];
- }
- else
- {
- $action = 're-edit';
- $_GET["id"] = $_POST["id"];
- $mesg = $product->mesg_error;
- }
+
+ for($i=0;$i<$_POST["max_prod"];$i++)
+ {
+ // print "
: ".$_POST["prod_id_chk".$i];
+ if($_POST["prod_id_chk".$i] != "")
+ {
+ if($product->add_sousproduit($id, $_POST["prod_id_".$i],$_POST["prod_qty_".$i]) )
+ {
+ $action = 'edit';
+ }
+ else
+ {
+ $action = 're-edit';
+ $mesg = "erreur";
+ }
+ }
+ else
+ {
+ if($product->del_sousproduit($id, $_POST["prod_id_".$i]))
+ {
+ $action = 'edit';
+ }
+ else
+ {
+ $action = 're-edit';
+ $mesg = "erreur";
+ }
+
+
+ }
}
- else
- {
- $action = 're-edit';
- $_GET["id"] = $_POST["id"];
- $mesg = $langs->trans("ErrorProductBadRefOrLabel");
- }
- }
+
}
// action recherche des produits par mot-clé et/ou par catégorie
if($action == 'search' )
@@ -142,8 +144,6 @@ if ($cancel == $langs->trans("Cancel"))
exit;
}
-
-
llxHeader("","",$langs->trans("ProductServiceCard"));
$html = new Form($db);
@@ -154,13 +154,6 @@ $html = new Form($db);
if ($id || $ref)
{
- if ($action <> 're-edit')
- {
- $product = new Product($db);
- if ($id) $result = $product->fetch($id);
- if ($ref) $result = $product->fetch($ref);
- }
-
if ( $result )
{
@@ -341,7 +334,7 @@ if ($id || $ref)
$product->get_sousproduits_arbo ();
print '
| '.$langs->trans("AssociatedProductsNumber").' | '.sizeof($product->get_arbo_each_prod()).' | ';
print '
';
- print '| '.$langs->trans("ProductSearch").'';
+ print ' |
| '.$langs->trans("ProductToAddSearch").'';
print '';
print ' |
';