Skip to content

Commit

Permalink
FIX missing compatibility with multicompany
Browse files Browse the repository at this point in the history
  • Loading branch information
hregis committed Apr 24, 2019
1 parent 84ec39f commit 41a8202
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion htdocs/core/tpl/card_presend.tpl.php
Expand Up @@ -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');
Expand Down
27 changes: 25 additions & 2 deletions htdocs/user/class/user.class.php
Expand Up @@ -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();
Expand Down

0 comments on commit 41a8202

Please sign in to comment.