diff --git a/ChangeLog b/ChangeLog
index db519e269b5..c81af41cfa2 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -51,6 +51,7 @@ For users:
- Fix: Add actions events not implemented.
- Fix: Price min of composition is not supplier price min by quantity
- Fix: [ bug #1356 ] Bank accountancy number is limited to 8 numbers
+- New: Add categories translation
TODO
- New: Predefined product and free product use same form.
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index fc250cfe07a..37d8a6c04f8 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -107,6 +107,9 @@ class Categorie extends CommonObject
$this->fetch_optionals($this->id,$extralabels);
$this->db->free($resql);
+
+ // multilangs
+ if (! empty($conf->global->MAIN_MULTILANGS)) $this->getMultiLangs();
return 1;
}
@@ -767,14 +770,21 @@ class Categorie extends CommonObject
*/
function get_full_arbo($type,$markafterid=0)
{
+ global $langs;
+
$this->cats = array();
// Init this->motherof that is array(id_son=>id_parent, ...)
$this->load_motherof();
+ $current_lang = $langs->getDefaultLang();
// Init $this->cats array
$sql = "SELECT DISTINCT c.rowid, c.label, c.description, c.fk_parent"; // Distinct reduce pb with old tables with duplicates
+ if (! empty($conf->global->MAIN_MULTILANGS))
+ $sql.= ", t.label as label_trans, t.description as description_trans";
$sql.= " FROM ".MAIN_DB_PREFIX."categorie as c";
+ if (! empty($conf->global->MAIN_MULTILANGS))
+ $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."categorie_lang as t ON t.fk_category=c.rowid AND t.lang='".$current_lang."'";
$sql.= " WHERE c.entity IN (".getEntity('category',1).")";
$sql.= " AND c.type = ".$type;
@@ -788,8 +798,8 @@ class Categorie extends CommonObject
$this->cats[$obj->rowid]['rowid'] = $obj->rowid;
$this->cats[$obj->rowid]['id'] = $obj->rowid;
$this->cats[$obj->rowid]['fk_parent'] = $obj->fk_parent;
- $this->cats[$obj->rowid]['label'] = $obj->label;
- $this->cats[$obj->rowid]['description'] = $obj->description;
+ $this->cats[$obj->rowid]['label'] = ! empty($obj->label_trans) ? $obj->label_trans : $obj->label;
+ $this->cats[$obj->rowid]['description'] = ! empty($obj->description_trans) ? $obj->description_trans : $obj->description;
$i++;
}
}
@@ -1458,6 +1468,118 @@ class Categorie extends CommonObject
$this->imgHeight = $infoImg[1]; // Hauteur de l'image
}
+ /**
+ * Update ou cree les traductions des infos produits
+ *
+ * @return int <0 if KO, >0 if OK
+ */
+ function setMultiLangs()
+ {
+ global $langs;
+
+ $langs_available = $langs->get_available_languages();
+ $current_lang = $langs->getDefaultLang();
+
+ foreach ($langs_available as $key => $value)
+ {
+ $sql = "SELECT rowid";
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie_lang";
+ $sql.= " WHERE fk_category=".$this->id;
+ $sql.= " AND lang='".$key."'";
+
+ $result = $this->db->query($sql);
+
+ if ($key == $current_lang)
+ {
+ if ($this->db->num_rows($result)) // si aucune ligne dans la base
+ {
+ $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang";
+ $sql2.= " SET label='".$this->db->escape($this->label)."',";
+ $sql2.= " description='".$this->db->escape($this->description)."'";
+ $sql2.= " WHERE fk_category=".$this->id." AND lang='".$key."'";
+ }
+ else
+ {
+ $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."categorie_lang (fk_category, lang, label, description)";
+ $sql2.= " VALUES(".$this->id.",'".$key."','". $this->db->escape($this->label);
+ $sql2.= "','".$this->db->escape($this->multilangs["$key"]["description"])."')";
+ }
+ dol_syslog(get_class($this).'::setMultiLangs sql='.$sql2);
+ if (! $this->db->query($sql2))
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this).'::setMultiLangs error='.$this->error, LOG_ERR);
+ return -1;
+ }
+ }
+ else if (isset($this->multilangs["$key"]))
+ {
+ if ($this->db->num_rows($result)) // si aucune ligne dans la base
+ {
+ $sql2 = "UPDATE ".MAIN_DB_PREFIX."categorie_lang";
+ $sql2.= " SET label='".$this->db->escape($this->multilangs["$key"]["label"])."',";
+ $sql2.= " description='".$this->db->escape($this->multilangs["$key"]["description"])."'";
+ $sql2.= " WHERE fk_category=".$this->id." AND lang='".$key."'";
+ }
+ else
+ {
+ $sql2 = "INSERT INTO ".MAIN_DB_PREFIX."categorie_lang (fk_category, lang, label, description)";
+ $sql2.= " VALUES(".$this->id.",'".$key."','". $this->db->escape($this->multilangs["$key"]["label"]);
+ $sql2.= "','".$this->db->escape($this->multilangs["$key"]["description"])."')";
+ }
+
+ // on ne sauvegarde pas des champs vides
+ if ( $this->multilangs["$key"]["label"] || $this->multilangs["$key"]["description"] || $this->multilangs["$key"]["note"] )
+ dol_syslog(get_class($this).'::setMultiLangs sql='.$sql2);
+ if (! $this->db->query($sql2))
+ {
+ $this->error=$this->db->lasterror();
+ dol_syslog(get_class($this).'::setMultiLangs error='.$this->error, LOG_ERR);
+ return -1;
+ }
+ }
+ }
+ return 1;
+ }
+
+ /**
+ * Load array this->multilangs
+ *
+ * @return int <0 if KO, >0 if OK
+ */
+ function getMultiLangs()
+ {
+ global $langs;
+
+ $current_lang = $langs->getDefaultLang();
+
+ $sql = "SELECT lang, label, description";
+ $sql.= " FROM ".MAIN_DB_PREFIX."categorie_lang";
+ $sql.= " WHERE fk_category=".$this->id;
+
+ $result = $this->db->query($sql);
+ if ($result)
+ {
+ while ( $obj = $this->db->fetch_object($result) )
+ {
+ //print 'lang='.$obj->lang.' current='.$current_lang.'
';
+ if( $obj->lang == $current_lang ) // si on a les traduct. dans la langue courante on les charge en infos principales.
+ {
+ $this->label = $obj->label;
+ $this->description = $obj->description;
+
+ }
+ $this->multilangs["$obj->lang"]["label"] = $obj->label;
+ $this->multilangs["$obj->lang"]["description"] = $obj->description;
+ }
+ return 1;
+ }
+ else
+ {
+ $this->error=$langs->trans("Error")." : ".$this->db->error()." - ".$sql;
+ return -1;
+ }
+ }
/**
* Initialise an instance with random values.
diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php
index 64f526bcb3c..12eaa7e98f0 100644
--- a/htdocs/categories/fiche.php
+++ b/htdocs/categories/fiche.php
@@ -31,9 +31,6 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$langs->load("categories");
-$extrafields = new ExtraFields($db);
-$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
-
// Security check
$socid=GETPOST('socid','int');
if (!$user->rights->categorie->lire) accessforbidden();
@@ -64,6 +61,9 @@ if ($catorigin && $type == 0) $idCatOrigin = $catorigin;
$object = new Categorie($db);
+$extrafields = new ExtraFields($db);
+$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
+
/*
* Actions
*/
@@ -244,7 +244,7 @@ if ($user->rights->categorie->creer)
print '
| '.$langs->trans("AddIn").' | ';
print $form->select_all_categories($type, $catorigin);
print ' |
';
-
+
$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
if (empty($reshook))
{
diff --git a/htdocs/categories/traduction.php b/htdocs/categories/traduction.php
new file mode 100644
index 00000000000..a6dadeb0e1c
--- /dev/null
+++ b/htdocs/categories/traduction.php
@@ -0,0 +1,284 @@
+
+ * Copyright (C) 2007 Rodolphe Quiedeville
+ * Copyright (C) 2010-2012 Destailleur Laurent
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ * or see http://www.gnu.org/
+ */
+
+/**
+ * \file htdocs/product/traduction.php
+ * \ingroup product
+ * \brief Page de traduction des produits
+ */
+
+require '../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
+
+$langs->load("categories");
+$langs->load("languages");
+
+$id = GETPOST('id', 'int');
+$ref = GETPOST('ref', 'alpha');
+$action=GETPOST('action','alpha');
+$cancel=GETPOST('cancel','alpha');
+$type=GETPOST('type');
+
+// Security check
+$fieldvalue = (! empty($id) ? $id : (! empty($ref) ? $ref : ''));
+$fieldtype = (! empty($ref) ? 'ref' : 'rowid');
+
+if ($id == "")
+{
+ dol_print_error('','Missing parameter id');
+ exit();
+}
+
+// Security check
+$result = restrictedArea($user, 'categorie', $id, '&category');
+
+$object = new Categorie($db);
+
+
+/*
+ * Actions
+ */
+
+// retour a l'affichage des traduction si annulation
+if ($cancel == $langs->trans("Cancel"))
+{
+ $action = '';
+}
+
+
+// Validation de l'ajout
+if ($action == 'vadd' &&
+$cancel != $langs->trans("Cancel") &&
+($user->rights->categorie->creer ))
+{
+ $object->fetch($id);
+ $current_lang = $langs->getDefaultLang();
+
+ // update de l'objet
+ if ( $_POST["forcelangprod"] == $current_lang )
+ {
+ $object->label = $_POST["libelle"];
+ $object->description = dol_htmlcleanlastbr($_POST["desc"]);
+ }
+ else
+ {
+ $object->multilangs[$_POST["forcelangprod"]]["label"] = $_POST["libelle"];
+ $object->multilangs[$_POST["forcelangprod"]]["description"] = dol_htmlcleanlastbr($_POST["desc"]);
+ }
+
+ // sauvegarde en base
+ if ( $object->setMultiLangs() > 0 )
+ {
+ $action = '';
+ }
+ else
+ {
+ $action = 'add';
+ $mesg = ''.$object->error.'
';
+ }
+}
+
+// Validation de l'edition
+if ($action == 'vedit' &&
+$cancel != $langs->trans("Cancel") &&
+($user->rights->categorie->creer))
+{
+ $object->fetch($id);
+ $current_lang = $langs->getDefaultLang();
+
+ foreach ( $object->multilangs as $key => $value ) // enregistrement des nouvelles valeurs dans l'objet
+ {
+ if ( $key == $current_lang )
+ {
+ $object->label = $_POST["libelle-".$key];
+ $object->description = dol_htmlcleanlastbr($_POST["desc-".$key]);
+ }
+ else
+ {
+ $object->multilangs[$key]["label"] = $_POST["libelle-".$key];
+ $object->multilangs[$key]["description"] = dol_htmlcleanlastbr($_POST["desc-".$key]);
+ }
+ }
+
+ if ( $object->setMultiLangs() > 0 )
+ {
+ $action = '';
+ }
+ else
+ {
+ $action = 'edit';
+ $mesg = ''.$object->error.'
';
+ }
+}
+
+$result = $object->fetch($id,$ref);
+
+
+/*
+ * View
+ */
+
+llxHeader("","",$langs->trans("Translation"));
+
+$form = new Form($db);
+$formadmin=new FormAdmin($db);
+
+if ($type == 0) $title=$langs->trans("ProductsCategoryShort");
+elseif ($type == 1) $title=$langs->trans("SuppliersCategoryShort");
+elseif ($type == 2) $title=$langs->trans("CustomersCategoryShort");
+elseif ($type == 3) $title=$langs->trans("MembersCategoryShort");
+elseif ($type == 4) $title=$langs->trans("ContactCategoriesShort");
+else $title=$langs->trans("Category");
+
+$head = categories_prepare_head($object,$type);
+dol_fiche_head($head, 'translation', $title, 0, 'category');
+
+if (! empty($mesg)) {
+ dol_htmloutput_mesg($mesg);
+}
+
+print '';
+
+// Reference
+print '';
+print '| '.$langs->trans("Ref").' | ';
+print $object->label;
+print ' | ';
+print '
';
+print '
';
+
+if ($action == 'edit')
+{
+ //WYSIWYG Editor
+ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+
+ print '';
+
+}
+else
+{
+ $cnt_trans = 0;
+ if (! empty($object->multilangs))
+ {
+ foreach ($object->multilangs as $key => $value)
+ {
+ $cnt_trans++;
+ $s=picto_from_langcode($key);
+ print "
".($s?$s.' ':'')." ".$langs->trans('Language_'.$key).":
";
+ print '';
+ print '| '.$langs->trans('Label').' | '.$object->multilangs[$key]["label"].' |
';
+ print '| '.$langs->trans('Description').' | '.$object->multilangs[$key]["description"].' |
';
+ print '| '.$langs->trans('Note').' | '.$object->multilangs[$key]["note"].' |
';
+ print '
';
+ }
+ }
+ if (! $cnt_trans) print '
'. $langs->trans('NoTranslation');
+}
+
+print "\n";
+
+
+/* ************************************************************************** */
+/* */
+/* Barre d'action */
+/* */
+/* ************************************************************************** */
+
+print "\n\n";
+
+
+/*
+ * Form to add a new translation
+ */
+
+if ($action == 'add' && ($user->rights->produit->creer || $user->rights->service->creer))
+{
+ //WYSIWYG Editor
+ require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
+
+ print '
';
+ print '';
+
+ print '
';
+}
+
+llxFooter();
+$db->close();
+?>
\ No newline at end of file
diff --git a/htdocs/core/lib/categories.lib.php b/htdocs/core/lib/categories.lib.php
index 293644be5dc..0e04c7e6b01 100644
--- a/htdocs/core/lib/categories.lib.php
+++ b/htdocs/core/lib/categories.lib.php
@@ -47,6 +47,11 @@ function categories_prepare_head($object,$type)
$head[$h][1] = $langs->trans("Photos");
$head[$h][2] = 'photos';
$h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/categories/traduction.php?id='.$object->id.'&type='.$type;
+ $head[$h][1] = $langs->trans("Translation");
+ $head[$h][2] = 'translation';
+ $h++;
// Show more tabs from modules
// Entries must be declared in modules descriptor with line
diff --git a/htdocs/core/modules/modCategorie.class.php b/htdocs/core/modules/modCategorie.class.php
index 2cfe6bcb19e..33dba7e6ee3 100644
--- a/htdocs/core/modules/modCategorie.class.php
+++ b/htdocs/core/modules/modCategorie.class.php
@@ -63,7 +63,7 @@ class modCategorie extends DolibarrModules
$this->depends = array();
// Config pages
- $this->config_page_url = array('/categories/admin/categorie.php');
+ $this->config_page_url = array('categorie.php@categories');
$this->langfiles = array("products","companies","categories");
// Constantes
diff --git a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
index c288bc1439f..be4d8e0844c 100644
--- a/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
+++ b/htdocs/install/mysql/migration/3.5.0-3.6.0.sql
@@ -1136,3 +1136,16 @@ insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang)
insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (35,'TASK_CREATE','Task created','Executed when a project task is created','project',35);
insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (36,'TASK_MODIFY','Task modified','Executed when a project task is modified','project',36);
insert into llx_c_action_trigger (rowid,code,label,description,elementtype,rang) values (37,'TASK_DELETE','Task deleted','Executed when a project task is deleted','project',37);
+
+-- New : category translation
+create table llx_categorie_lang
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_category integer DEFAULT 0 NOT NULL,
+ lang varchar(5) DEFAULT 0 NOT NULL,
+ label varchar(255) NOT NULL,
+ description text
+)ENGINE=innodb;
+
+ALTER TABLE llx_categorie_lang ADD UNIQUE INDEX uk_category_lang (fk_category, lang);
+ALTER TABLE llx_categorie_lang ADD CONSTRAINT fk_category_lang_fk_category FOREIGN KEY (fk_category) REFERENCES llx_categorie (rowid);
diff --git a/htdocs/install/mysql/tables/llx_categorie_lang.key.sql b/htdocs/install/mysql/tables/llx_categorie_lang.key.sql
new file mode 100644
index 00000000000..0f588e0a173
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_categorie_lang.key.sql
@@ -0,0 +1,20 @@
+-- ============================================================================
+-- Copyright (C) 2014 Jean-François Ferry
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see .
+--
+-- ============================================================================
+
+ALTER TABLE llx_categorie_lang ADD UNIQUE INDEX uk_category_lang (fk_category, lang);
+ALTER TABLE llx_categorie_lang ADD CONSTRAINT fk_category_lang_fk_category FOREIGN KEY (fk_category) REFERENCES llx_categorie (rowid);
\ No newline at end of file
diff --git a/htdocs/install/mysql/tables/llx_categorie_lang.sql b/htdocs/install/mysql/tables/llx_categorie_lang.sql
new file mode 100644
index 00000000000..34dc0a3406e
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_categorie_lang.sql
@@ -0,0 +1,29 @@
+-- ============================================================================
+-- Copyright (C) 2002-2003 Rodolphe Quiedeville
+-- Copyright (C) 2005-2010 Regis Houssin
+-- Copyright (C) 2009 Laurent Destailleur
+-- Copyright (C) 2014 Jean-François Ferry
+--
+-- This program is free software; you can redistribute it and/or modify
+-- it under the terms of the GNU General Public License as published by
+-- the Free Software Foundation; either version 3 of the License, or
+-- (at your option) any later version.
+--
+-- This program is distributed in the hope that it will be useful,
+-- but WITHOUT ANY WARRANTY; without even the implied warranty of
+-- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+-- GNU General Public License for more details.
+--
+-- You should have received a copy of the GNU General Public License
+-- along with this program. If not, see .
+--
+-- ============================================================================
+
+create table llx_categorie_lang
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ fk_category integer DEFAULT 0 NOT NULL,
+ lang varchar(5) DEFAULT 0 NOT NULL,
+ label varchar(255) NOT NULL,
+ description text
+)ENGINE=innodb;