diff --git a/htdocs/product.class.php b/htdocs/product.class.php
index 7021230e0d4..4458d086679 100644
--- a/htdocs/product.class.php
+++ b/htdocs/product.class.php
@@ -353,49 +353,62 @@ class Product
}
/**
- * \brief update ou crée les traductions des infos produits
- */
+ * \brief update ou crée les traductions des infos produits
+ */
function setMultiLangs()
{
global $langs;
- $langs_available = $langs->get_available_languages();
+ $langs_available = $langs->get_available_languages();
$current_lang = $langs->getDefaultLang();
foreach ($langs_available as $value)
{
+ $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."product_det";
+ $sql.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
+
+ $result = $this->db->query($sql);
+
if ($value == $current_lang)
{
- $sqlU = "UPDATE ".MAIN_DB_PREFIX."product_det";
- $sqlU.= " SET label='".$this->libelle."'";
- $sqlU.= " description='".$this->description."'";
- $sqlU.= " note='".$this->note."'";
- $sqlU.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
-
- $sqlI = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
- $sqlI.= " VALUES(".$this->id.",'".$value."','". $this->libelle;
- $sqlI.= "','".$this->description;
- $sqlI.= "','".$this->note."')";
-
+ if (mysql_num_rows($result)) // si aucune ligne dans la base
+ {
+ $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_det";
+ $sql2.= " SET label='".$this->libelle."',";
+ $sql2.= " description='".$this->description."',";
+ $sql2.= " note='".$this->note."'";
+ $sql2.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
+ }
+ else
+ {
+ $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
+ $sql2.= " VALUES(".$this->id.",'".$value."','". $this->libelle;
+ $sql2.= "','".$this->description;
+ $sql2.= "','".$this->note."')";
+ }
+ if (!$this->db->query($sql2)) return -1;
}
else
{
- $sqlU = "UPDATE ".MAIN_DB_PREFIX."product_det";
- $sqlU.= " SET label='".$this->multilangs["$value"]["libelle"]."'";
- $sqlU.= " description='".$this->multilangs["$value"]["libelle"]."'";
- $sqlU.= " note='".$this->multilangs["$value"]["note"]."'";
- $sqlU.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
-
- $sqlI = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
- $sqlI.= " VALUES(".$this->id.",'".$value."','". $this->multilangs["$value"]["libelle"];
- $sqlI.= "','".$this->multilangs["$value"]["description"];
- $sqlI.= "','".$this->multilangs["$value"]["note"]."')";
+ if (mysql_num_rows($result)) // si aucune ligne dans la base
+ {
+ $sql2 = "UPDATE ".MAIN_DB_PREFIX."product_det";
+ $sql2.= " SET label='".$this->multilangs["$value"]["libelle"]."',";
+ $sql2.= " description='".$this->multilangs["$value"]["description"]."',";
+ $sql2.= " note='".$this->multilangs["$value"]["note"]."'";
+ $sql2.= " WHERE fk_product=".$this->id." AND lang='".$value."'";
+ }
+ else
+ {
+ $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."product_det (fk_product, lang, label, description, note)";
+ $sql2.= " VALUES(".$this->id.",'".$value."','". $this->multilangs["$value"]["libelle"];
+ $sql2.= "','".$this->multilangs["$value"]["description"];
+ $sql2.= "','".$this->multilangs["$value"]["note"]."')";
+ }
+ // on ne sauvegarde pas des champs vides
+ if ( $this->multilangs["$value"]["libelle"] || $this->multilangs["$value"]["description"] || $this->multilangs["$value"]["note"] )
+ if (!$this->db->query($sql2)) return -1;
}
-
- // on ne sauvegarde pas des champs vides
- if ( $this->multilangs["$value"]["libelle"] || $this->multilangs["$value"]["description"] || $this->multilangs["$value"]["note"] )
- if (!$this->db->query($sqlU)) // si aucun champ n'est mis a jour
- if (!$this->db->query($sqlI)) return -1;
}
return 1;
}
@@ -425,16 +438,16 @@ class Product
{
while ( $obj = $this->db->fetch_object($result) )
{
- $this->multilangs["$obj->lang"]["libelle"] = $obj->label;
- $this->multilangs["$obj->lang"]["description"] = $obj->description;
- $this->multilangs["$obj->lang"]["note"] = $obj->note;
-
if( $obj->lang == $current_lang ) // si on a les traduct. dans la langue courant on les charge en infos principales.
{
$this->libelle = $obj->label;
$this->description = $obj->description;
$this->note = $obj->note;
}
+ $this->multilangs["$obj->lang"]["libelle"] = $obj->label;
+ $this->multilangs["$obj->lang"]["description"] = $obj->description;
+ $this->multilangs["$obj->lang"]["note"] = $obj->note;
+
}
}
else
diff --git a/htdocs/product/traduction.php b/htdocs/product/traduction.php
index a7e97c0fbdd..905b80cce96 100644
--- a/htdocs/product/traduction.php
+++ b/htdocs/product/traduction.php
@@ -77,7 +77,7 @@ if ($_POST["action"] == 'vadd' &&
}
// sauvegarde en base
- if ( $product->update($product->id, $user) > 0 )
+ if ( $product->setMultiLangs() > 0 )
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
@@ -108,13 +108,13 @@ if ($_POST["action"] == 'vedit' &&
}
else
{
- $value["libelle"] = $_POST["libelle-".$key];
- $value["description"] = $_POST["desc-".$key];
- $value["note"] = $_POST["note-".$key];
+ $product->multilangs[$key]["libelle"] = $_POST["libelle-".$key];
+ $product->multilangs[$key]["description"] = $_POST["desc-".$key];
+ $product->multilangs[$key]["note"] = $_POST["note-".$key];
}
}
- if ( $product->update($product->id, $user) > 0 )
+ if ( $product->setMultiLangs() > 0 )
{
$_GET["action"] = '';
$mesg = 'Fiche mise à jour';
@@ -271,16 +271,18 @@ if ($_GET["action"] == 'edit')
}
else
{
+ $cnt_trans = 0;
foreach ( $product->multilangs as $key => $value)
{
+ $cnt_trans++;
print "
$key :
";
print '
';
print '| '.$langs->trans('Label').' | '.$product->multilangs[$key]["libelle"].' |
';
print '| '.$langs->trans('Description').' | '.$product->multilangs[$key]["description"].' |
';
print '| '.$langs->trans('Note').' | '.$product->multilangs[$key]["note"].' |
';
- print '';
print '
';
}
+ if ( !$cnt_trans ) print '
'. $langs->trans('NoTranslation');
}
print "\n";
@@ -322,10 +324,7 @@ if ($_GET["action"] == 'add' || $user->rights->produit->modifier)
print '';
print '';
print '