From cf92f704d8a6cc634369560ee25e7c6a89313318 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 13 Jul 2015 09:54:26 +0200 Subject: [PATCH 1/2] Fix: avoid error if $mc object not exists TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !! --- htdocs/user/card.php | 3 ++- htdocs/user/home.php | 29 +++++++++++++---------------- 2 files changed, 15 insertions(+), 17 deletions(-) diff --git a/htdocs/user/card.php b/htdocs/user/card.php index 102d275b968..6332aab4794 100644 --- a/htdocs/user/card.php +++ b/htdocs/user/card.php @@ -2195,7 +2195,8 @@ else } // Multicompany - if (! empty($conf->multicompany->enabled)) + // TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !! + if (! empty($conf->multicompany->enabled) && is_object($mc)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { diff --git a/htdocs/user/home.php b/htdocs/user/home.php index cb700b9701e..d14c9b8fb21 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -180,21 +180,18 @@ if ($resql) $entity=$obj->entity; $entitystring=''; // TODO Set of entitystring should be done with a hook - if (is_object($mc)) - { - if (! empty($conf->multicompany->enabled)) - { - if (empty($entity)) - { - $entitystring=$langs->trans("AllEntities"); - } - else - { - $mc->getInfo($entity); - $entitystring=$mc->label; - } - } - } + if (! empty($conf->multicompany->enabled) && is_object($mc)) + { + if (empty($entity)) + { + $entitystring=$langs->trans("AllEntities"); + } + else + { + $mc->getInfo($entity); + $entitystring=$mc->label; + } + } print ($entitystring?' ('.$entitystring.')':''); print ''; @@ -259,7 +256,7 @@ if ($canreadperms) print img_picto($langs->trans("GlobalGroup"),'redstar'); } print ""; - if (! empty($conf->multicompany->enabled)) + if (! empty($conf->multicompany->enabled) && is_object($mc)) { $mc->getInfo($obj->entity); print ''; From 6f1645f2f20c64e339e60028bae9d5804ff01772 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Mon, 13 Jul 2015 10:14:04 +0200 Subject: [PATCH 2/2] Fix: check if $mc object exists --- htdocs/user/group/card.php | 12 ++++++------ htdocs/user/group/index.php | 4 ++-- htdocs/user/home.php | 2 +- 3 files changed, 9 insertions(+), 9 deletions(-) diff --git a/htdocs/user/group/card.php b/htdocs/user/group/card.php index 3ecff112b73..3de421e4f4f 100644 --- a/htdocs/user/group/card.php +++ b/htdocs/user/group/card.php @@ -1,7 +1,7 @@ * Copyright (C) 2005-2015 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2011 Herve Prot * Copyright (C) 2012 Florian Henry * @@ -239,7 +239,7 @@ if ($action == 'create') print ''; // Multicompany - if (! empty($conf->multicompany->enabled)) + if (! empty($conf->multicompany->enabled) && is_object($mc)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { @@ -326,7 +326,7 @@ else print "\n"; // Multicompany - if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) + if (! empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { $mc->getInfo($object->entity); print "".''.$langs->trans("Entity").''; @@ -401,7 +401,7 @@ else print $form->select_dolusers('','user',1,$exclude,0,'','',$object->entity); print '   '; // Multicompany - if (! empty($conf->multicompany->enabled)) + if (! empty($conf->multicompany->enabled) && is_object($mc)) { if ($conf->entity == 1 && $conf->multicompany->transverse_mode) { @@ -455,7 +455,7 @@ else print ''; print ''.$useringroup->lastname.''; print ''.$useringroup->firstname.''; - if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) + if (! empty($conf->multicompany->enabled) && is_object($mc) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { print ''; if (! empty($useringroup->usergroup_entity)) @@ -513,7 +513,7 @@ else print "\n"; // Multicompany - if (! empty($conf->multicompany->enabled)) + if (! empty($conf->multicompany->enabled) && is_object($mc)) { if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index 1f06fa3a3c2..7496d7bc816 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -1,7 +1,7 @@ * Copyright (C) 2004-2011 Laurent Destailleur - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2015 Regis Houssin * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify @@ -108,7 +108,7 @@ if ($resql) } print ""; //multicompany - if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) + if (! empty($conf->multicompany->enabled) && is_object($mc) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) { $mc->getInfo($obj->entity); print ''.$mc->label.''; diff --git a/htdocs/user/home.php b/htdocs/user/home.php index d14c9b8fb21..ba3b3c15586 100644 --- a/htdocs/user/home.php +++ b/htdocs/user/home.php @@ -1,6 +1,6 @@ - * Copyright (C) 2005-2012 Regis Houssin + * Copyright (C) 2005-2015 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