Fix: Deletion of translation has disappeared.

This commit is contained in:
Laurent Destailleur 2014-06-20 15:05:39 +02:00
parent e1a461b3d6
commit e2afa6853b
3 changed files with 42 additions and 13 deletions

View File

@ -172,7 +172,7 @@ function dol_shutdown()
* Return value of a param into GET or POST supervariable * Return value of a param into GET or POST supervariable
* *
* @param string $paramname Name of parameter to found * @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) * @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 * @return string||string[] Value found, or '' if check fails
*/ */

View File

@ -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 * @return int <0 if KO, >0 if OK
*/ */
@ -936,6 +936,29 @@ class Product extends CommonObject
return 1; 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 * Load array this->multilangs
@ -973,7 +996,7 @@ class Product extends CommonObject
} }
else else
{ {
$this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql; $this->error="Error: ".$this->db->error()." - ".$sql;
return -1; return -1;
} }
} }

View File

@ -55,6 +55,12 @@ if ($cancel == $langs->trans("Cancel"))
$action = ''; $action = '';
} }
if ($action == 'delete' && GETPOST('langtodelete','alpha'))
{
$product = new Product($db);
$product->fetch($id);
$product->delMultiLangs(GETPOST('langtodelete','alpha'));
}
// Validation de l'ajout // Validation de l'ajout
if ($action == 'vadd' && if ($action == 'vadd' &&
@ -209,7 +215,7 @@ else
{ {
$cnt_trans++; $cnt_trans++;
$s=picto_from_langcode($key); $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 '<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('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>'; 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 '<input type="hidden" name="id" value="'.$_GET["id"].'">';
print '<table class="border" width="100%">'; print '<table class="border" width="100%">';
print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Translation').'</td><td>'; print '<tr><td valign="top" width="15%" class="fieldrequired">'.$langs->trans('Language').'</td><td>';
print $formadmin->select_language('','forcelangprod',0,$product->multilangs); print $formadmin->select_language('','forcelangprod',0,$product->multilangs,1);
print '</td></tr>'; 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%" 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>'; print '<tr><td valign="top" width="15%">'.$langs->trans('Description').'</td><td>';