From 41a82023e385046afbb9d68ff5eb308040288a7a Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 Apr 2019 08:17:10 +0200 Subject: [PATCH 1/2] FIX missing compatibility with multicompany --- htdocs/core/tpl/card_presend.tpl.php | 2 +- htdocs/user/class/user.class.php | 27 +++++++++++++++++++++++++-- 2 files changed, 26 insertions(+), 3 deletions(-) diff --git a/htdocs/core/tpl/card_presend.tpl.php b/htdocs/core/tpl/card_presend.tpl.php index 58758daab09bf..54464488f0b0e 100644 --- a/htdocs/core/tpl/card_presend.tpl.php +++ b/htdocs/core/tpl/card_presend.tpl.php @@ -171,7 +171,7 @@ $listeuser=array(); $fuserdest = new User($db); - $result= $fuserdest->fetchAll('ASC', 't.lastname', 0, 0, array('customsql'=>'t.statut=1 AND t.employee=1 AND t.email IS NOT NULL AND t.email<>\'\'')); + $result= $fuserdest->fetchAll('ASC', 't.lastname', 0, 0, array('customsql'=>'t.statut=1 AND t.employee=1 AND t.email IS NOT NULL AND t.email<>\'\''), 'AND', true); if ($result>0 && is_array($fuserdest->users) && count($fuserdest->users)>0) { foreach($fuserdest->users as $uuserdest) { $listeuser[$uuserdest->id] = $uuserdest->user_get_property($uuserdest->id,'email'); diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index a02b4916c91df..8fd87c839c7a7 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3206,15 +3206,38 @@ function user_get_property($rowid,$mode) * @param int $offset page * @param array $filter Filter array. Example array('field'=>'valueforlike', 'customurl'=>...) * @param string $filtermode Filter mode (AND or OR) + * @param bool $entityfilter Activate entity filter * @return int <0 if KO, >0 if OK */ - function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND') + function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND', $entityfilter=false) { global $conf; $sql="SELECT t.rowid"; $sql.= ' FROM '.MAIN_DB_PREFIX .$this->table_element.' as t '; - $sql.= " WHERE 1"; + + if ($entityfilter) + { + if (! empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) + { + if (! empty($user->admin) && empty($user->entity) && $conf->entity == 1) { + $sql.= " WHERE t.entity IS NOT NULL"; // Show all users + } else { + $sql.= ",".MAIN_DB_PREFIX."usergroup_user as ug"; + $sql.= " WHERE ((ug.fk_user = t.rowid"; + $sql.= " AND ug.entity IN (".getEntity('user')."))"; + $sql.= " OR t.entity = 0)"; // Show always superadmin + } + } + else + { + $sql.= " WHERE t.entity IN (".getEntity('user').")"; + } + } + else + { + $sql.= " WHERE 1"; + } // Manage filter $sqlwhere = array(); From 740fddcd429398b54b09455e1762a9312c00b6a6 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Wed, 24 Apr 2019 08:22:00 +0200 Subject: [PATCH 2/2] FIX missing global $user --- htdocs/user/class/user.class.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 8fd87c839c7a7..1bfaa24c06642 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -3211,7 +3211,7 @@ function user_get_property($rowid,$mode) */ function fetchAll($sortorder='', $sortfield='', $limit=0, $offset=0, $filter=array(), $filtermode='AND', $entityfilter=false) { - global $conf; + global $conf, $user; $sql="SELECT t.rowid"; $sql.= ' FROM '.MAIN_DB_PREFIX .$this->table_element.' as t ';