diff --git a/htdocs/html.form.class.php b/htdocs/html.form.class.php
index eef83f7e046..96dabeb322f 100644
--- a/htdocs/html.form.class.php
+++ b/htdocs/html.form.class.php
@@ -3570,6 +3570,28 @@ class Form
dolibarr_print_error($this->db);
}
}
+
+ /**
+ * \brief Affiche formulaire de selection du type de code barre
+ * \param page Page
+ * \param selected Id condition présélectionnée
+ * \param htmlname Nom du formulaire select
+ */
+ function form_barcode_type($page, $selected='', $htmlname='barcodetype_id')
+ {
+ global $langs,$conf;
+ if ($htmlname != "none")
+ {
+ print '
';
+ }
+ }
}
diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index d6b55aa1173..592f58916b7 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -2493,6 +2493,52 @@ class Product
return -1;
}
}
+
+ /**
+ * \brief Mise à jour du code barre
+ * \param user Utilisateur qui fait la modification
+ */
+ function update_barcode($user)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."product";
+ $sql .= " SET barcode = '".$this->barcode."'";
+ $sql .= " WHERE rowid = ".$this->id;
+
+ dolibarr_syslog("Product::update_barcode sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ return 1;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ return -1;
+ }
+ }
+
+/**
+ * \brief Mise à jour du type de code barre
+ * \param user Utilisateur qui fait la modification
+ */
+ function update_barcode_type($user)
+ {
+ $sql = "UPDATE ".MAIN_DB_PREFIX."product";
+ $sql .= " SET fk_barcode_type = '".$this->barcode_type."'";
+ $sql .= " WHERE rowid = ".$this->id;
+
+ dolibarr_syslog("Product::update_barcode_type sql=".$sql);
+ $resql=$this->db->query($sql);
+ if ($resql)
+ {
+ return 1;
+ }
+ else
+ {
+ dolibarr_print_error($this->db);
+ return -1;
+ }
+ }
/**
\brief Affecte les valeurs smarty
diff --git a/htdocs/product/barcode.php b/htdocs/product/barcode.php
index d55fd7d1a4b..a9722e74f93 100644
--- a/htdocs/product/barcode.php
+++ b/htdocs/product/barcode.php
@@ -41,9 +41,38 @@ if (!$user->rights->barcode->lire)
accessforbidden();
/*
- * Affiche historique prix
+ * Actions
*/
+// Modification du type de code barre
+if ($_POST['action'] == 'setbarcodetype' && $user->rights->barcode->creer)
+{
+ $product = new Product($db);
+ $product->fetch($_GET["id"]);
+ $product->barcode_type = $_POST['barcodetype_id'];
+ $result = $product->update_barcode_type($user);
+ Header("Location: barcode.php?id=".$_GET["id"]);
+ exit;
+}
+
+// Modification du code barre
+if ($_POST['action'] == 'setbarcode' && $user->rights->barcode->creer)
+{
+ $product = new Product($db);
+ $product->fetch($_GET["id"]);
+ $product->barcode = $_POST['barcode']; //Todo: ajout vérification de la validité du code barre en fonction du type
+ $result = $product->update_barcode($user);
+ Header("Location: barcode.php?id=".$_GET["id"]);
+ exit;
+}
+
+
+/* *****************************************/
+/* */
+/* Mode vue et edition */
+/* */
+/* *************************************** */
+
llxHeader("","",$langs->trans("BarCode"));
$html = new Form($db);
@@ -92,18 +121,46 @@ print '| '.$langs->trans("Status").' | ';
print $product->getLibStatut(2);
print ' |
';
-// Barcode type
-print '| '.$langs->trans("BarcodeType").' | ';
-print $product->barcode_type_label;
+// Barcode type
+print ' |
| ';
+print '';
+print ' | ';
+if ($_GET['action'] == 'editbarcodetype')
+{
+ $html->form_barcode_type($_SERVER['PHP_SELF'].'?id='.$product->id,$product->barcode_type,'barcodetype_id');
+}
+else
+{
+ print $product->barcode_type_label;
+}
print ' |
';
// Barcode
-print '| '.$langs->trans("Barcode").' | ';
-print $product->barcode;
+print ' |
| ';
+print '';
+print ' | ';
+if ($_GET['action'] == 'editbarcode')
+{
+ print ' |
';
print "\n";
-
print "\n";