Merge branch 'patch-100' of https://github.com/defrance/dolibarr into

defrance-patch-100

Conflicts:
	htdocs/install/mysql/migration/3.9.0-4.0.0.sql
	htdocs/user/card.php
This commit is contained in:
Laurent Destailleur 2016-02-16 13:54:56 +01:00
commit 8fb0f8d9d1
8 changed files with 194 additions and 28 deletions

View File

@ -9,6 +9,7 @@
* Copyright (C) 2013 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2015 Marcos García <marcosgdf@gmail.com>
* Copyright (C) 2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
* Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
*
* 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';

View File

@ -918,7 +918,7 @@ else
print '<td colspan="3">';
$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;
}

View File

@ -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;

View File

@ -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;

View File

@ -0,0 +1,25 @@
-- ============================================================================
-- Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ============================================================================
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);

View File

@ -0,0 +1,24 @@
-- ============================================================================
-- Copyright (C) 2016 Charlie Benke <charlie@patas-monkey.com>
--
-- 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 <http://www.gnu.org/licenses/>.
--
-- ===========================================================================
CREATE TABLE llx_categorie_user
(
fk_categorie integer NOT NULL,
fk_user integer NOT NULL,
import_key varchar(14)
) ENGINE=innodb;

View File

@ -11,6 +11,7 @@
* Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
* Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
* Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
* Copyright (C) 2015 Charlie Benke <charlie@patas-monkey.com>
*
* 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 '</td></tr>';
}
// Categories
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
{
print '<tr><td>' . fieldLabel( 'Categories', 'usercats' ) . '</td><td colspan="3">';
$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 "</td></tr>";
}
// Note
print '<tr><td class="tdtop">';
print $langs->trans("Note");
@ -1425,7 +1448,16 @@ else
print '</td>';
print "</tr>\n";
}
// Categories
if (! empty($conf->categorie->enabled) && ! empty($user->rights->categorie->lire))
{
print '<tr><td>' . $langs->trans( "Categories" ) . '</td>';
print '<td colspan="3">';
print $form->showCategories( $object->id, 'user', 1 );
print '</td></tr>';
}
// 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 '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
$huser=new User($db);
$huser->fetch($object->fk_user);
@ -2174,31 +2206,46 @@ else
// Accountancy code
if ($conf->accounting->enabled)
{
print "<tr>";
print '<td>'.$langs->trans("AccountancyCode").'</td>';
print '<td>';
if ($caneditfield)
{
print "<tr>";
print '<td>'.$langs->trans("AccountancyCode").'</td>';
print '<td>';
if ($caneditfield)
{
print '<input size="30" type="text" class="flat" name="accountancy_code" value="'.$object->accountancy_code.'">';
}
else
{
print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
print $object->accountancy_code;
}
print '</td>';
print "</tr>";
print '<input size="30" type="text" class="flat" name="accountancy_code" value="'.$object->accountancy_code.'">';
}
else
{
print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
print $object->accountancy_code;
}
print '</td>';
print "</tr>";
}
// User color
if (! empty($conf->agenda->enabled))
{
print '<tr><td>'.$langs->trans("ColorUser").'</td>';
print '<td>';
print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset');
print '</td></tr>';
// User color
if (! empty($conf->agenda->enabled))
{
print '<tr><td>'.$langs->trans("ColorUser").'</td>';
print '<td>';
print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset');
print '</td></tr>';
}
// Categories
if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire ))
{
print '<tr><td>' . fieldLabel( 'Categories', 'usercats' ) . '</td>';
print '<td>';
$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 "</td></tr>";
}
// Status
print '<tr><td>'.$langs->trans("Status").'</td>';

View File

@ -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