FIX missing compatibility with multicompany

This commit is contained in:
Regis Houssin 2019-04-24 08:17:10 +02:00
parent 84ec39f043
commit 41a82023e3
2 changed files with 26 additions and 3 deletions

View File

@ -171,7 +171,7 @@ if ($action == 'presend')
$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');

View File

@ -3206,15 +3206,38 @@ class User extends CommonObject
* @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();