diff --git a/htdocs/categories/admin/categorie.php b/htdocs/categories/admin/categorie.php
index b762e1b1fcc..085c5b7f5e1 100644
--- a/htdocs/categories/admin/categorie.php
+++ b/htdocs/categories/admin/categorie.php
@@ -29,7 +29,7 @@ require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
if (!$user->admin)
accessforbidden();
-$langs->load("cateogries");
+$langs->load("categories");
$action=GETPOST("action");
@@ -95,7 +95,7 @@ $form = new Form($db);
$var=!$var;
print '
';
print '| '.$langs->trans("CategorieRecursiv").' | ';
-print ' | ';
+print ''. $form->textwithpicto('',$langs->trans("CategorieRecursivHelp"),1,'help').' | ';
print '';
if ($conf->use_javascript_ajax)
diff --git a/htdocs/categories/admin/categorie_extrafields.php b/htdocs/categories/admin/categorie_extrafields.php
new file mode 100644
index 00000000000..7ff0c854dcf
--- /dev/null
+++ b/htdocs/categories/admin/categorie_extrafields.php
@@ -0,0 +1,151 @@
+
+ * Copyright (C) 2003 Jean-Louis Bergamo
+ * Copyright (C) 2004-2012 Laurent Destailleur
+ * Copyright (C) 2012 Regis Houssin
+ *
+ * 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 .
+ */
+
+/**
+ * \file htdocs/categories/admin/categorie_extrafields.php
+ * \ingroup societe
+ * \brief Page to setup extra fields of category
+ */
+
+require '../../main.inc.php';
+require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
+$langs->load("categories");
+$langs->load("admin");
+
+$extrafields = new ExtraFields($db);
+$form = new Form($db);
+
+// List of supported format
+$tmptype2label=getStaticMember(get_class($extrafields),'type2label');
+$type2label=array('');
+foreach ($tmptype2label as $key => $val) $type2label[$key]=$langs->trans($val);
+
+$action=GETPOST('action', 'alpha');
+$attrname=GETPOST('attrname', 'alpha');
+$elementtype='categories'; //Must be the $element of the class that manage extrafield
+
+if (!$user->admin) accessforbidden();
+
+
+/*
+ * Actions
+ */
+require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
+
+
+/*
+ * View
+ */
+
+$textobject=$langs->transnoentitiesnoconv("Categories");
+
+$help_url='EN:Module Third Parties setup|FR:Paramétrage_du_module_Tiers';
+llxHeader('',$langs->trans("CompanySetup"),$help_url);
+
+
+$linkback=''.$langs->trans("BackToModuleList").'';
+print_fiche_titre($langs->trans("CategoriesSetup"),$linkback,'setup');
+
+$head = categoriesadmin_prepare_head(null);
+
+dol_fiche_head($head, 'attributes_categories', $langs->trans("Categories"), 0, 'categoriesadmin');
+
+print $langs->trans("DefineHereComplementaryAttributes",$textobject).' '."\n";
+print ' ';
+
+// Load attribute_label
+$extrafields->fetch_name_optionals_label($elementtype);
+
+print "";
+
+print '';
+print '| '.$langs->trans("Label").' | ';
+print ''.$langs->trans("AttributeCode").' | ';
+print ''.$langs->trans("Type").' | ';
+print ''.$langs->trans("Size").' | ';
+print ''.$langs->trans("Unique").' | ';
+print ''.$langs->trans("Required").' | ';
+print ' | ';
+print " \n";
+
+$var=True;
+foreach($extrafields->attribute_type as $key => $value)
+{
+ $var=!$var;
+ print "";
+ print "| ".$extrafields->attribute_label[$key]." | \n";
+ print "".$key." | \n";
+ print "".$type2label[$extrafields->attribute_type[$key]]." | \n";
+ print ''.$extrafields->attribute_size[$key]." | \n";
+ print ''.yn($extrafields->attribute_unique[$key])." | \n";
+ print ''.yn($extrafields->attribute_required[$key])." | \n";
+ print ''.img_edit().'';
+ print " ".img_delete()." | \n";
+ print " ";
+ // $i++;
+}
+
+print " ";
+
+dol_fiche_end();
+
+
+// Buttons
+if ($action != 'create' && $action != 'edit')
+{
+ print '";
+}
+
+
+/* ************************************************************************** */
+/* */
+/* Creation d'un champ optionnel
+ /* */
+/* ************************************************************************** */
+
+if ($action == 'create')
+{
+ print " ";
+ print_titre($langs->trans('NewAttribute'));
+
+ require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
+}
+
+/* ************************************************************************** */
+/* */
+/* Edition d'un champ optionnel */
+/* */
+/* ************************************************************************** */
+if ($action == 'edit' && ! empty($attrname))
+{
+ print " ";
+ print_titre($langs->trans("FieldEdition", $attrname));
+
+ require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
+}
+
+llxFooter();
+
+$db->close();
+?>
diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php
index 244b1987448..4c15c006cab 100644
--- a/htdocs/categories/class/categorie.class.php
+++ b/htdocs/categories/class/categorie.class.php
@@ -28,6 +28,7 @@
* \brief File of class to manage categories
*/
+require_once DOL_DOCUMENT_ROOT.'/core/class/commonobject.class.php';
require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
require_once DOL_DOCUMENT_ROOT.'/fourn/class/fournisseur.class.php';
require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
@@ -36,10 +37,10 @@ require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
/**
* Class to manage categories
*/
-class Categorie
+class Categorie extends CommonObject
{
public $element='category';
- public $table_element='category';
+ public $table_element='categories';
var $id;
var $fk_parent;
@@ -102,6 +103,8 @@ class Categorie
$this->visible = $res['visible'];
$this->type = $res['type'];
$this->entity = $res['entity'];
+
+ $this->fetch_optionals($this->id,$extralabels);
$this->db->free($resql);
@@ -130,7 +133,7 @@ class Categorie
*/
function create($user='')
{
- global $conf,$langs;
+ global $conf,$langs,$hookmanager;
$langs->load('categories');
$error=0;
@@ -188,6 +191,24 @@ class Categorie
if ($id > 0)
{
$this->id = $id;
+
+ // Actions on extra fields (by external module or standard code)
+ // FIXME le hook fait double emploi avec le trigger !!
+ $hookmanager->initHooks(array('HookModuleNamedao'));
+ $parameters=array('socid'=>$this->id);
+ $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
+ if (empty($reshook))
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+ }
+ else if ($reshook < 0) $error++;
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
@@ -224,7 +245,7 @@ class Categorie
*/
function update($user='')
{
- global $conf, $langs;
+ global $conf, $langs,$hookmanager;
$error=0;
@@ -257,8 +278,28 @@ class Categorie
dol_syslog(get_class($this)."::update sql=".$sql);
if ($this->db->query($sql))
{
+
+ // Actions on extra fields (by external module or standard code)
+ // FIXME le hook fait double emploi avec le trigger !!
+ $hookmanager->initHooks(array('HookCategorydao'));
+ $parameters=array();
+ $reshook=$hookmanager->executeHooks('insertExtraFields',$parameters,$this,$action); // Note that $action and $object may have been modified by some hooks
+ if (empty($reshook))
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$this->insertExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ }
+ }
+ }
+ else if ($reshook < 0) $error++;
+
$this->db->commit();
+
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
@@ -361,6 +402,19 @@ class Categorie
}
else
{
+ // Removed extrafields
+ if (! $error)
+ {
+ if (empty($conf->global->MAIN_EXTRAFIELDS_DISABLED)) // For avoid conflicts if trigger used
+ {
+ $result=$this->deleteExtraFields();
+ if ($result < 0)
+ {
+ $error++;
+ dol_syslog(get_class($this)."::delete erreur ".$errorflag." ".$this->error, LOG_ERR);
+ }
+ }
+ }
// Appel des triggers
include_once DOL_DOCUMENT_ROOT . '/core/class/interfaces.class.php';
$interface=new Interfaces($this->db);
diff --git a/htdocs/categories/edit.php b/htdocs/categories/edit.php
index 388cf47436a..de85a6ca6e2 100644
--- a/htdocs/categories/edit.php
+++ b/htdocs/categories/edit.php
@@ -26,6 +26,7 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
$langs->load("categories");
@@ -50,7 +51,10 @@ if ($id == "")
// Security check
$result = restrictedArea($user, 'categorie', $id, '&category');
+$object = new Categorie($db);
+$extrafields = new ExtraFields($db);
+$extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
/*
* Actions
@@ -85,6 +89,8 @@ if ($action == 'update' && $user->rights->categorie->creer)
}
if (empty($categorie->error))
{
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$categorie);
+
if ($categorie->update($user) > 0)
{
header('Location: '.DOL_URL_ROOT.'/categories/viewcat.php?id='.$categorie->id.'&type='.$type);
@@ -115,7 +121,6 @@ print_fiche_titre($langs->trans("ModifCat"));
dol_htmloutput_errors($mesg);
-$object = new Categorie($db);
$object->fetch($id);
$form = new Form($db);
@@ -153,6 +158,12 @@ print '| '.$langs->trans("In").' | ';
print $form->select_all_categories($type,$object->fk_parent,'parent',64,$object->id);
print ' | ';
+$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+if (empty($reshook) && ! empty($extrafields->attribute_label))
+{
+ print $object->showOptionals($extrafields,'edit');
+}
+
print '';
print ' ';
diff --git a/htdocs/categories/fiche.php b/htdocs/categories/fiche.php
index d43c4df9a3d..64f526bcb3c 100644
--- a/htdocs/categories/fiche.php
+++ b/htdocs/categories/fiche.php
@@ -27,9 +27,12 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
+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');
@@ -59,6 +62,7 @@ if ($origin)
if ($catorigin && $type == 0) $idCatOrigin = $catorigin;
+$object = new Categorie($db);
/*
* Actions
@@ -112,7 +116,7 @@ if ($action == 'add' && $user->rights->categorie->creer)
}
}
- $object = new Categorie($db);
+
$object->label = $label;
$object->description = dol_htmlcleanlastbr($description);
@@ -121,6 +125,8 @@ if ($action == 'add' && $user->rights->categorie->creer)
$object->type = $type;
if ($parent != "-1") $object->fk_parent = $parent;
+
+ $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
if (! $object->label)
{
@@ -238,6 +244,12 @@ 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))
+ {
+ print $object->showOptionals($extrafields,'edit');
+ }
print '';
diff --git a/htdocs/categories/viewcat.php b/htdocs/categories/viewcat.php
index 53bd6179000..bec834e1ff9 100644
--- a/htdocs/categories/viewcat.php
+++ b/htdocs/categories/viewcat.php
@@ -27,6 +27,8 @@
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/categories.lib.php';
+require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
+
$langs->load("categories");
@@ -49,6 +51,7 @@ $result = restrictedArea($user, 'categorie', $id, '&category');
$object = new Categorie($db);
$result=$object->fetch($id);
+$object->fetch_optionals($id,$extralabels);
if ($result <= 0)
{
dol_print_error($db,$object->error);
@@ -57,6 +60,8 @@ if ($result <= 0)
$type=$object->type;
+$extrafields = new ExtraFields($db);
+$extralabels = $extrafields->fetch_name_optionals_label($object->table_element);
/*
* Actions
@@ -166,6 +171,12 @@ print $langs->trans("Description").' | ';
print nl2br($object->description);
print ' |
';
+$reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
+if (empty($reshook) && ! empty($extrafields->attribute_label))
+{
+ print $object->showOptionals($extrafields);
+}
+
print '';
print '';
diff --git a/htdocs/core/lib/categories.lib.php b/htdocs/core/lib/categories.lib.php
index dc4b5aaac20..179ff317294 100644
--- a/htdocs/core/lib/categories.lib.php
+++ b/htdocs/core/lib/categories.lib.php
@@ -78,6 +78,11 @@ function categoriesadmin_prepare_head()
$head[$h][1] = $langs->trans("Setup");
$head[$h][2] = 'setup';
$h++;
+
+ $head[$h][0] = DOL_URL_ROOT.'/categories/admin/categorie_extrafields.php';
+ $head[$h][1] = $langs->trans("ExtraFieldsCategories");
+ $head[$h][2] = 'attributes_categories';
+ $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 2eccc4701b3..030b40a09f4 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();
+ $this->config_page_url = array('categorie_extrafields.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 214fbe4c89d..e8c9d18f3ba 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
@@ -980,18 +980,17 @@ create table llx_product_customer_price
recuperableonly integer NOT NULL DEFAULT '0', -- Other NPR VAT
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax2_tx double(6,3) DEFAULT 0, -- Other local VAT 2
- fk_user integer,
- import_key varchar(14) -- Import key
+ fk_user integer,
+ import_key varchar(14) -- Import key
)ENGINE=innodb;
ALTER TABLE llx_product_customer_price ADD INDEX idx_product_customer_price_fk_user (fk_user);
-
-ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
-
+ALTER TABLE llx_product_customer_price ADD INDEX idx_product_customer_price_fk_soc (fk_soc);
ALTER TABLE llx_product_customer_price ADD UNIQUE INDEX uk_customer_price_fk_product_fk_soc (fk_product, fk_soc);
-ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_customer_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product(rowid) ON DELETE CASCADE;
-ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_customer_price_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid) ON DELETE CASCADE;
+ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_product_customer_price_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid);
+ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_customer_price_fk_product FOREIGN KEY (fk_product) REFERENCES llx_product(rowid);
+ALTER TABLE llx_product_customer_price ADD CONSTRAINT fk_customer_price_fk_soc FOREIGN KEY (fk_soc) REFERENCES llx_societe(rowid);
ALTER TABLE llx_user ADD COLUMN barcode varchar(255) DEFAULT NULL;
ALTER TABLE llx_user ADD COLUMN fk_barcode_type integer DEFAULT 0;
@@ -1011,7 +1010,7 @@ create table llx_product_customer_price_log
price_min_ttc double(24,8) DEFAULT 0,
price_base_type varchar(3) DEFAULT 'HT',
tva_tx double(6,3),
- recuperableonly integer NOT NULL DEFAULT '0', -- Other NPR VAT
+ recuperableonly integer NOT NULL DEFAULT 0, -- Other NPR VAT
localtax1_tx double(6,3) DEFAULT 0, -- Other local VAT 1
localtax2_tx double(6,3) DEFAULT 0, -- Other local VAT 2
fk_user integer,
@@ -1028,7 +1027,7 @@ CREATE TABLE llx_product_batch (
eatby datetime DEFAULT NULL,
sellby datetime DEFAULT NULL,
batch varchar(30) DEFAULT NULL,
- qty double NOT NULL DEFAULT '0',
+ qty double NOT NULL DEFAULT 0,
import_key varchar(14) DEFAULT NULL,
KEY ix_fk_product_stock (fk_product_stock)
) ENGINE=InnoDB;
@@ -1039,7 +1038,7 @@ CREATE TABLE llx_expeditiondet_batch (
eatby date DEFAULT NULL,
sellby date DEFAULT NULL,
batch varchar(30) DEFAULT NULL,
- qty double NOT NULL DEFAULT '0',
+ qty double NOT NULL DEFAULT 0,
fk_origin_stock integer NOT NULL,
KEY ix_fk_expeditiondet (fk_expeditiondet)
) ENGINE=InnoDB;
@@ -1069,3 +1068,15 @@ ALTER TABLE llx_stock_mouvement ADD origintype VARCHAR(32);
--New 1300 : Add THM on user
ALTER TABLE llx_user ADD thm double(24,8);
ALTER TABLE llx_projet_task_time ADD thm double(24,8);
+
+
+-- New : extrafield on categories
+create table llx_categories_extrafields
+(
+ rowid integer AUTO_INCREMENT PRIMARY KEY,
+ tms timestamp,
+ fk_object integer NOT NULL,
+ import_key varchar(14) -- import key
+) ENGINE=innodb;
+
+ALTER TABLE llx_categories_extrafields ADD INDEX idx_categories_extrafields (fk_object);
diff --git a/htdocs/install/mysql/tables/llx_categories_extrafields.key.sql b/htdocs/install/mysql/tables/llx_categories_extrafields.key.sql
new file mode 100644
index 00000000000..6089f886028
--- /dev/null
+++ b/htdocs/install/mysql/tables/llx_categories_extrafields.key.sql
@@ -0,0 +1,20 @@
+-- ===================================================================
+-- Copyright (C) 2014 Jean-François Ferry