FIX php8 compatibility

This commit is contained in:
Philippe GRAND 2022-08-28 14:40:36 +02:00
parent 0aba1f6753
commit 5aba964726

View File

@ -466,14 +466,14 @@ class User extends CommonObject
$sql .= " LEFT JOIN ".$this->db->prefix()."c_departements as d ON u.fk_state = d.rowid";
if ($entity < 0) {
if ((empty($conf->multicompany->enabled) || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
if ((!isModEnabled('multicompany') || empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) && (!empty($user->entity))) {
$sql .= " WHERE u.entity IN (0, ".((int) $conf->entity).")";
} else {
$sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
}
} else {
// The fetch was forced on an entity
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= " WHERE u.entity IS NOT NULL"; // multicompany is on in transverse mode or user making fetch is on entity 0, so user is allowed to fetch anywhere into database
} else {
$sql .= " WHERE u.entity IN (0, ".((int) (($entity != '' && $entity >= 0) ? $entity : $conf->entity)).")"; // search in entity provided in parameter
@ -588,7 +588,7 @@ class User extends CommonObject
// Protection when module multicompany was set, admin was set to first entity and then, the module was disabled,
// in such case, this admin user must be admin for ALL entities.
if (empty($conf->multicompany->enabled) && $this->admin && $this->entity == 1) {
if (!isModEnabled('multicompany') && $this->admin && $this->entity == 1) {
$this->entity = 0;
}
@ -1130,7 +1130,7 @@ class User extends CommonObject
$sql .= " WHERE r.id = ur.fk_id";
if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
// on old version, we use entity defined into table r only
$sql .= " AND r.entity IN (0,".(!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "").$conf->entity.")";
$sql .= " AND r.entity IN (0,".(isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) ? "1," : "").$conf->entity.")";
} else {
// On table r=rights_def, the unique key is (id, entity) because id is hard coded into module descriptor and insert during module activation.
// So we must include the filter on entity on both table r. and ur.
@ -1188,7 +1188,7 @@ class User extends CommonObject
$sql .= " ".$this->db->prefix()."rights_def as r";
$sql .= " WHERE r.id = gr.fk_id";
if (!empty($conf->global->MULTICOMPANY_BACKWARD_COMPATIBILITY)) {
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= " AND gu.entity IN (0,".$conf->entity.")";
} else {
$sql .= " AND r.entity = ".((int) $conf->entity);
@ -3661,7 +3661,7 @@ class User extends CommonObject
$sql = "SELECT COUNT(DISTINCT u.rowid) as nb";
$sql .= " FROM ".$this->db->prefix()."user as u";
if (!empty($conf->multicompany->enabled) && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
$sql .= ", ".$this->db->prefix()."usergroup_user as ug";
$sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
$sql .= " AND ug.fk_user = u.rowid";