diff --git a/htdocs/categories/class/categorie.class.php b/htdocs/categories/class/categorie.class.php index a35fc566ea1..5198da7efb2 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 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 @@ -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'; 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; } 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 e7ad861b4c8..43b2c4cf7c1 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,23 @@ -- -- VMYSQL4.1 DELETE FROM llx_usergroup_user WHERE fk_usergroup NOT IN (SELECT rowid from llx_usergroup); + +CREATE TABLE llx_categorie_user +( + fk_categorie integer NOT NULL, + fk_user integer NOT NULL, + import_key varchar(14) +) ENGINE=innodb; + +ALTER TABLE llx_categorie_user ADD PRIMARY KEY pk_categorie_user (fk_categorie, fk_user); +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_categorie_user ADD CONSTRAINT fk_categorie_user_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_user ADD CONSTRAINT fk_categorie_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); + + + 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; @@ -215,6 +232,7 @@ ALTER TABLE llx_propaldet ADD COLUMN multicurrency_total_tva double(24,8) DEFAUL ALTER TABLE llx_propaldet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAULT 0; +-- Add for recurring template invoices ALTER TABLE llx_facture_rec ADD COLUMN auto_validate integer DEFAULT 0; ALTER TABLE llx_facture_rec ADD COLUMN fk_account integer DEFAULT 0; @@ -239,3 +257,4 @@ ALTER TABLE llx_contratdet ADD COLUMN multicurrency_subprice double(24,8) DEFAUL ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_ht double(24,8) DEFAULT 0; ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_tva double(24,8) DEFAULT 0; ALTER TABLE llx_contratdet ADD COLUMN multicurrency_total_ttc double(24,8) DEFAULT 0; + diff --git a/htdocs/install/mysql/tables/llx_categorie_societe.sql b/htdocs/install/mysql/tables/llx_categorie_societe.sql index c347d40c372..948eae8707c 100644 --- a/htdocs/install/mysql/tables/llx_categorie_societe.sql +++ b/htdocs/install/mysql/tables/llx_categorie_societe.sql @@ -20,6 +20,6 @@ create table llx_categorie_societe ( fk_categorie integer NOT NULL, - fk_soc integer NOT NULL, + fk_soc integer NOT NULL, import_key varchar(14) )ENGINE=innodb; 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..599230edd04 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_user.key.sql @@ -0,0 +1,25 @@ +-- ============================================================================ +-- 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 . +-- +-- ============================================================================ + +ALTER TABLE llx_categorie_user ADD PRIMARY KEY pk_categorie_user (fk_categorie, fk_user); +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_categorie_user ADD CONSTRAINT fk_categorie_user_categorie_rowid FOREIGN KEY (fk_categorie) REFERENCES llx_categorie (rowid); +ALTER TABLE llx_categorie_user ADD CONSTRAINT fk_categorie_user_fk_user FOREIGN KEY (fk_user) REFERENCES llx_user (rowid); + 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..42068188db0 --- /dev/null +++ b/htdocs/install/mysql/tables/llx_categorie_user.sql @@ -0,0 +1,24 @@ +-- ============================================================================ +-- 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 . +-- +-- =========================================================================== + +CREATE TABLE llx_categorie_user +( + fk_categorie integer NOT NULL, + fk_user integer NOT NULL, + import_key varchar(14) +) ENGINE=innodb; diff --git a/htdocs/user/card.php b/htdocs/user/card.php index e428d53a6e2..2723fce2a67 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -11,6 +11,7 @@ * Copyright (C) 2013-2016 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,17 @@ 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 +1448,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)) { @@ -2124,7 +2156,7 @@ else print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'maxwidth300'); } else - { + { print ''; $huser=new User($db); $huser->fetch($object->fk_user); @@ -2174,31 +2206,46 @@ else // Accountancy code if ($conf->accounting->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, 'user' ); + foreach ($cats as $cat) { + $arrayselected[] = $cat->id; } + print $form->multiselectarray( 'usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' ); + print ""; + } // Status print ''.$langs->trans("Status").''; 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