From a95a810d68ffe1217d9e2a1782df1a96e242f547 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:25:37 +0100 Subject: [PATCH 1/9] add categorie user based on contact user --- htdocs/categories/class/categorie.class.php | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index a35fc566ea1..832b1ec3693 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -9,6 +9,7 @@ * Copyright (C) 2013 Philippe Grand * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud + * Copyright (C) 2016 Charlie Benk * * 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 @@ -47,6 +48,7 @@ class Categorie extends CommonObject const TYPE_CUSTOMER = 2; const TYPE_MEMBER = 3; const TYPE_CONTACT = 4; + const TYPE_USER = 4; // categorie contact and user are same /** * @var array ID mapping from type string @@ -59,6 +61,7 @@ class Categorie extends CommonObject 'customer' => 2, 'member' => 3, 'contact' => 4, + 'user' => 4, ); /** * @var array Foreign keys mapping from type string @@ -71,6 +74,7 @@ class Categorie extends CommonObject 'supplier' => 'soc', 'member' => 'member', 'contact' => 'socpeople', + 'user' => 'user', ); /** * @var array Category tables mapping from type string @@ -83,6 +87,7 @@ class Categorie extends CommonObject 'supplier' => 'fournisseur', 'member' => 'member', 'contact' => 'contact', + 'user' => 'user', ); /** * @var array Object class mapping from type string @@ -95,6 +100,7 @@ class Categorie extends CommonObject 'supplier' => 'Fournisseur', 'member' => 'Adherent', 'contact' => 'Contact', + 'user' => 'User', ); /** * @var array Object table mapping from type string @@ -107,6 +113,7 @@ class Categorie extends CommonObject 'supplier' => 'societe', 'member' => 'adherent', 'contact' => 'socpeople', + 'user' => 'user', ); public $element='category'; From c910fd151fac97352e728339df2300f78319f2d7 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:27:12 +0100 Subject: [PATCH 2/9] add setcategorie on user class --- htdocs/user/class/user.class.php | 44 ++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 51aefa8d4de..9266ebb4d7f 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -751,6 +751,50 @@ class User extends CommonObject } } + /** + * Sets object to supplied categories. + * + * Deletes object from existing categories not supplied. + * Adds it to non existing supplied categories. + * Existing categories are left untouch. + * + * @param int[]|int $categories Category or categories IDs + */ + public function setCategories($categories) + { + // Handle single category + if (!is_array($categories)) { + $categories = array($categories); + } + + // Get current categories + require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php'; + $c = new Categorie($this->db); + $existing = $c->containing($this->id, Categorie::TYPE_USER, 'id'); + + // Diff + if (is_array($existing)) { + $to_del = array_diff($existing, $categories); + $to_add = array_diff($categories, $existing); + } else { + $to_del = array(); // Nothing to delete + $to_add = $categories; + } + + // Process + foreach ($to_del as $del) { + if ($c->fetch($del) > 0) { + $c->del_type($this, 'user'); + } + } + foreach ($to_add as $add) { + if ($c->fetch($add) > 0) { + $c->add_type($this, 'user'); + } + } + + return; + } /** * Delete the user From 5e288db0e5036712a91c6083c8ea2dfc1e36df30 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:42:45 +0100 Subject: [PATCH 3/9] add categorie user based on contact user allow to add categorie to user, the same as contact user (because user and contact are persons too) --- htdocs/user/card.php | 99 ++++++++++++++++++++++++++++++++------------ 1 file changed, 72 insertions(+), 27 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 8e3dce72196..99e803e649c 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -11,6 +11,7 @@ * Copyright (C) 2013-2015 Alexandre Spangaro * Copyright (C) 2015 Jean-François Ferry * Copyright (C) 2015 Ari Elbaz (elarifr) + * Copyright (C) 2015 Charlie Benke * * 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 @@ -43,6 +44,8 @@ require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php'; if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php'; if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php'; if (! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.class.php'); +if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php'; + $id = GETPOST('id','int'); $action = GETPOST('action','alpha'); @@ -244,7 +247,11 @@ if (empty($reshook)) { if (isset($_POST['password']) && trim($_POST['password'])) { $object->setPassword($user, trim($_POST['password'])); } - + if (! empty($conf->categorie->enabled)) { + // Categories association + $usercats = GETPOST( 'usercats', 'array' ); + $object->setCategories($usercats); + } $db->commit(); header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id); @@ -472,7 +479,13 @@ if (empty($reshook)) { } } } - + if (! $error && ! count($object->errors)) + { + // Then we add the associated categories + $categories = GETPOST( 'usercats', 'array' ); + $object->setCategories($categories); + } + if (!$error && !count($object->errors)) { setEventMessages($langs->trans("UserModified"), null, 'mesgs'); $db->commit(); @@ -1081,7 +1094,16 @@ if (($action == 'create') || ($action == 'adduserldap')) print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset'); print ''; } - + + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) { + print '' . fieldLabel( 'Categories', 'usercats' ) . ''; + $cate_arbo = $form->select_all_categories( Categorie::TYPE_USER, null, 'parent', null, null, 1 ); + print $form->multiselectarray( 'usercats', $cate_arbo, GETPOST( 'usercats', 'array' ), null, null, null, + null, '90%' ); + print ""; + } + // Note print ''; print $langs->trans("Note"); @@ -1425,7 +1447,16 @@ else print ''; print "\n"; } - + + // Categories + if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire)) + { + print '' . $langs->trans( "Categories" ) . ''; + print ''; + print $form->showCategories( $object->id, 'user', 1 ); + print ''; + } + // Company / Contact if (! empty($conf->societe->enabled)) { @@ -2172,33 +2203,47 @@ else print ''; print "\n"; - // Accountancy code - if ($conf->salaries->enabled) + // Accountancy code + if ($conf->salaries->enabled) + { + print ""; + print ''.$langs->trans("AccountancyCode").''; + print ''; + if ($caneditfield) { - print ""; - print ''.$langs->trans("AccountancyCode").''; - print ''; - if ($caneditfield) - { - print ''; - } - else - { - print ''; - print $object->accountancy_code; - } - print ''; - print ""; + print ''; } + else + { + print ''; + print $object->accountancy_code; + } + print ''; + print ""; + } - // User color - if (! empty($conf->agenda->enabled)) - { - print ''.$langs->trans("ColorUser").''; - print ''; - print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset'); - print ''; + // User color + if (! empty($conf->agenda->enabled)) + { + print ''.$langs->trans("ColorUser").''; + print ''; + print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset'); + print ''; + } + + // Categories + if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire )) { + print '' . fieldLabel( 'Categories', 'usercats' ) . ''; + print ''; + $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 ); + $c = new Categorie( $db ); + $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT ); + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; } + print $form->multiselectarray( 'usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' ); + print ""; + } // Status print ''.$langs->trans("Status").''; From e3444e08a7fad56c992d1b0fea1ddf11402948c9 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:50:46 +0100 Subject: [PATCH 4/9] Create llx_categorie_user.sql --- .../mysql/tables/llx_categorie_user.sql | 27 +++++++++++++++++++ 1 file changed, 27 insertions(+) create mode 100644 htdocs/install/mysql/tables/llx_categorie_user.sql diff --git a/htdocs/install/mysql/tables/llx_categorie_user.sql b/htdocs/install/mysql/tables/llx_categorie_user.sql new file mode 100644 index 00000000000..52ca5adf61f --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_user.sql @@ -0,0 +1,27 @@ +-- ============================================================================ +-- Copyright (C) 2016 Charlie Benke +-- +-- 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 . +-- +-- =========================================================================== +-- +-- Table structure for table `llx_categorie_user` +-- + +CREATE TABLE IF NOT EXISTS `llx_categorie_user` ( + `fk_categorie` int(11) NOT NULL, + `fk_user` int(11) NOT NULL, + `import_key` varchar(14) DEFAULT NULL, + PRIMARY KEY (`fk_categorie`,`fk_user`) +) ENGINE=InnoDB DEFAULT CHARSET=utf8; From b21b5e7bb8f7219f101ffed4f0122c6176381d5e Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:51:24 +0100 Subject: [PATCH 5/9] Create llx_categorie_user.key.sql --- htdocs/install/mysql/tables/llx_categorie_user.key.sql | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 htdocs/install/mysql/tables/llx_categorie_user.key.sql diff --git a/htdocs/install/mysql/tables/llx_categorie_user.key.sql b/htdocs/install/mysql/tables/llx_categorie_user.key.sql new file mode 100644 index 00000000000..ca807397046 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_user.key.sql @@ -0,0 +1,2 @@ +ALTER TABLE llx_categorie_user ADD INDEX `idx_categorie_user_fk_categorie` (`fk_categorie`); +ALTER TABLE llx_categorie_user ADD INDEX `idx_categorie_user_fk_user` (`fk_user`); From 23cb0d437cd5305ccb243640e22ffd1bfc7bfff8 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 10:53:01 +0100 Subject: [PATCH 6/9] Update 3.9.0-4.0.0.sql --- htdocs/install/mysql/migration/3.9.0-4.0.0.sql | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql index 50e0c4d2e56..82c901ef8c1 100644 --- a/htdocs/install/mysql/migration/3.9.0-4.0.0.sql +++ b/htdocs/install/mysql/migration/3.9.0-4.0.0.sql @@ -22,6 +22,17 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + +CREATE TABLE IF NOT EXISTS `llx_categorie_user` ( + `fk_categorie` int(11) NOT NULL, + `fk_user` int(11) NOT NULL, + `import_key` varchar(14) DEFAULT NULL, + PRIMARY KEY (`fk_categorie`,`fk_user`) +) ENGINE=InnoDB; + +ALTER TABLE llx_categorie_user ADD INDEX `idx_categorie_user_fk_categorie` (`fk_categorie`); +ALTER TABLE llx_categorie_user ADD INDEX `idx_categorie_user_fk_user` (`fk_user`); + ALTER TABLE llx_accounting_bookkeeping ADD COLUMN validated tinyint DEFAULT 0 NOT NULL; ALTER TABLE llx_bank_account MODIFY COLUMN accountancy_journal varchar(16) DEFAULT NULL; @@ -211,4 +222,4 @@ ALTER TABLE llx_propaldet ADD COLUMN multicurrency_total_ht double(24,8) DEFAULT ALTER TABLE llx_propaldet ADD COLUMN multicurrency_total_tva double(24,8) DEFAULT 0; ALTER TABLE llx_propaldet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAULT 0; - \ No newline at end of file + From 9f4909d8b1b02cb2297041de576cfc916de0ac4c Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Sat, 13 Feb 2016 17:27:53 +0100 Subject: [PATCH 7/9] Update categorie.class.php --- htdocs/categories/class/categorie.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index 832b1ec3693..5198da7efb2 100644 --- a/htdocs/categories/class/categorie.class.php +++ b/htdocs/categories/class/categorie.class.php @@ -9,7 +9,7 @@ * Copyright (C) 2013 Philippe Grand * Copyright (C) 2015 Marcos García * Copyright (C) 2015 Raphaël Doursenaud - * Copyright (C) 2016 Charlie Benk + * Copyright (C) 2016 Charlie Benke * * 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 From 79b79e2accf0e92e1bb519bae4f76b1fb4a13354 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 15 Feb 2016 09:21:21 +0100 Subject: [PATCH 8/9] Update card.php --- htdocs/user/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 99e803e649c..5e51383f42b 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2237,7 +2237,7 @@ else print ''; $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 ); $c = new Categorie( $db ); - $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT ); + $cats = $c->containing( $object->id, 'user' ); foreach ($cats as $cat) { $arrayselected[] = $cat->id; } From 30a6b546b1c70ba31ff66bc17c5cf08b8f68d933 Mon Sep 17 00:00:00 2001 From: BENKE Charlie Date: Mon, 15 Feb 2016 09:23:36 +0100 Subject: [PATCH 9/9] containing function prefer use text values instead numeric --- htdocs/contact/card.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/contact/card.php b/htdocs/contact/card.php index bd9a4b781f5..32c0c1156b7 100644 --- a/htdocs/contact/card.php +++ b/htdocs/contact/card.php @@ -918,7 +918,7 @@ else print ''; $cate_arbo = $form->select_all_categories( Categorie::TYPE_CONTACT, null, null, null, null, 1 ); $c = new Categorie( $db ); - $cats = $c->containing( $object->id, Categorie::TYPE_CONTACT ); + $cats = $c->containing( $object->id, 'contact' ); foreach ($cats as $cat) { $arrayselected[] = $cat->id; }