diff --git a/htdocs/core/lib/functions.lib.php b/htdocs/core/lib/functions.lib.php index f306cf4b372856cedc4b6b0c716712fae85320d2..bc38958fa9ecca6590c57d4f7ccc34b91ef238b7 100644 --- a/htdocs/core/lib/functions.lib.php +++ b/htdocs/core/lib/functions.lib.php @@ -172,7 +172,7 @@ function dol_shutdown() * Return value of a param into GET or POST supervariable * * @param string $paramname Name of parameter to found - * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's text and sign, 'az'=check it's a-z only, 'array'=check it's array) + * @param string $check Type of check (''=no check, 'int'=check it's numeric, 'alpha'=check it's text and sign, 'aZ'=check it's a-z only, 'array'=check it's array) * @param int $method Type of method (0 = get then post, 1 = only get, 2 = only post, 3 = post then get, 4 = post then get then cookie) * @return string||string[] Value found, or '' if check fails */ diff --git a/htdocs/product/class/product.class.php b/htdocs/product/class/product.class.php index a2d2ee36d9c2bc161a42eb3622ad09ecf0b1c149..1ba5f7b2283f955c65d96650aff57e1fc9dcc4eb 100644 --- a/htdocs/product/class/product.class.php +++ b/htdocs/product/class/product.class.php @@ -269,7 +269,7 @@ class Product extends CommonObject // Barcode value $this->barcode=trim($this->barcode); - + // Check parameters if (empty($this->libelle)) { @@ -309,11 +309,11 @@ class Product extends CommonObject // For automatic creation during create action (not used by Dolibarr GUI, can be used by scripts) if ($this->barcode == -1) $this->barcode = $this->get_barcode($this,$this->barcode_type_code); - + // Check more parameters // If error, this->errors[] is filled $result = $this->verify(); - + if ($result >= 0) { $sql = "SELECT count(*) as nb"; @@ -520,7 +520,7 @@ class Product extends CommonObject } $mod = new $module(); - + dol_syslog(get_class($this)."::check_barcode value=".$valuetotest." type=".$typefortest." module=".$module); $result = $mod->verif($this->db, $valuetotest, $this, 0, $typefortest); return $result; @@ -586,7 +586,7 @@ class Product extends CommonObject { $result = $this->verify(); // We don't check when update called during a create because verify was already done } - + if ($result >= 0) { // For automatic creation @@ -600,7 +600,7 @@ class Product extends CommonObject $sql.= ", recuperableonly = " . $this->tva_npr; $sql.= ", localtax1_tx = " . $this->localtax1_tx; $sql.= ", localtax2_tx = " . $this->localtax2_tx; - + $sql.= ", barcode = ". (empty($this->barcode)?"null":"'".$this->db->escape($this->barcode)."'"); $sql.= ", fk_barcode_type = ". (empty($this->barcode_type)?"null":$this->db->escape($this->barcode_type)); @@ -627,7 +627,7 @@ class Product extends CommonObject $sql.= ", accountancy_code_sell= '" . $this->accountancy_code_sell."'"; $sql.= ", desiredstock = " . ((isset($this->desiredstock) && $this->desiredstock != '') ? $this->desiredstock : "null"); $sql.= " WHERE rowid = " . $id; - + dol_syslog(get_class($this)."update sql=".$sql); $resql=$this->db->query($sql); if ($resql) @@ -859,7 +859,7 @@ class Product extends CommonObject } /** - * Update ou cree les traductions des infos produits + * Update or add a translation for a product * * @return int <0 if KO, >0 if OK */ @@ -936,6 +936,29 @@ class Product extends CommonObject return 1; } + /** + * Delete a language for this product + * + * @param string $langtodelete Language to delete + * @return int <0 if KO, >0 if OK + */ + function delMultiLangs($langtodelete) + { + $sql = "DELETE FROM ".MAIN_DB_PREFIX."product_lang"; + $sql.= " WHERE fk_product=".$this->id." AND lang='".$this->db->escape($langtodelete)."'"; + + dol_syslog("Delete translation sql=".$sql); + $result = $this->db->query($sql); + if ($result) + { + return 1; + } + else + { + $this->error="Error: ".$this->db->error()." - ".$sql; + return -1; + } + } /** * Load array this->multilangs @@ -973,7 +996,7 @@ class Product extends CommonObject } else { - $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; + $this->error="Error: ".$this->db->error()." - ".$sql; return -1; } } diff --git a/htdocs/product/traduction.php b/htdocs/product/traduction.php index 045b9c8cf1d0258853a858647dc0eaa2f3adff2f..f273eef35bf3244d9be87b4a91a4b2f78afa3609 100644 --- a/htdocs/product/traduction.php +++ b/htdocs/product/traduction.php @@ -55,6 +55,12 @@ if ($cancel == $langs->trans("Cancel")) $action = ''; } +if ($action == 'delete' && GETPOST('langtodelete','alpha')) +{ + $product = new Product($db); + $product->fetch($id); + $product->delMultiLangs(GETPOST('langtodelete','alpha')); +} // Validation de l'ajout if ($action == 'vadd' && @@ -209,7 +215,7 @@ else { $cnt_trans++; $s=picto_from_langcode($key); - print "<br>".($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b><br>"; + print "<br>".($s?$s.' ':'')." <b>".$langs->trans('Language_'.$key).":</b> ".'<a href="'.$_SERVER["PHP_SELF"].'?id='.$product->id.'&action=delete&langtodelete='.$key.'">'.img_delete('', '')."</a><br>"; print '<table class="border" width="100%">'; print '<tr><td width="15%">'.$langs->trans('Label').'</td><td>'.$product->multilangs[$key]["label"].'</td></tr>'; print '<tr><td width="15%">'.$langs->trans('Description').'</td><td>'.$product->multilangs[$key]["description"].'</td></tr>'; @@ -257,8 +263,8 @@ if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service print '<input type="hidden" name="id" value="'.$_GET["id"].'">'; print '<table class="border" width="100%">'; - print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Translation').'</td><td>'; - print $formadmin->select_language('','forcelangprod',0,$product->multilangs); + print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Language').'</td><td>'; + print $formadmin->select_language('','forcelangprod',0,$product->multilangs,1); print '</td></tr>'; print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Label').'</td><td><input name="libelle" size="40"></td></tr>'; print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td>';