FIX remove DISTINCT when MULTICOMPANY_TRANSVERSE_MODE is used (#26143)
* FIX (WIP) remove DISTINCT when MULTICOMPANY_TRANSVERSE_MODE is used * FIX optimize code * FIX replace with $this->db->prefix() * FIX works on uniformize MULTICOMPANY_TRANSVERSE_MODE * FIX syntax error
This commit is contained in:
parent
b220e1acbd
commit
cdf4292415
5 changed files with 33 additions and 39 deletions
|
|
@ -900,22 +900,26 @@ while ($currentdaytoshow < $lastdaytoshow) {
|
|||
}
|
||||
} else {
|
||||
/* Use this list to have for all users */
|
||||
$sql = "SELECT DISTINCT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
|
||||
$sql .= " FROM ".MAIN_DB_PREFIX."user as u";
|
||||
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
$sql .= ", ".MAIN_DB_PREFIX."usergroup_user as ug";
|
||||
$sql = "SELECT u.rowid, u.lastname as lastname, u.firstname, u.statut, u.login, u.admin, u.entity";
|
||||
$sql .= " FROM ".$db->prefix()."user as u";
|
||||
if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
$sql .= " WHERE u.rowid IN (";
|
||||
$sql .= " SELECT ug.fk_user FROM ".$db->prefix()."usergroup_user as ug";
|
||||
$sql .= " WHERE ug.entity IN (".getEntity('usergroup').")";
|
||||
$sql .= " AND ug.fk_user = u.rowid ";
|
||||
if ($usergroup > 0) {
|
||||
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
|
||||
}
|
||||
$sql .= ")";
|
||||
} else {
|
||||
if ($usergroup > 0) {
|
||||
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ug ON u.rowid = ug.fk_user";
|
||||
$sql .= " LEFT JOIN ".$db->prefix()."usergroup_user as ug ON u.rowid = ug.fk_user";
|
||||
}
|
||||
$sql .= " WHERE u.entity IN (".getEntity('user').")";
|
||||
if ($usergroup > 0) {
|
||||
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
|
||||
}
|
||||
}
|
||||
$sql .= " AND u.statut = 1";
|
||||
if ($usergroup > 0) {
|
||||
$sql .= " AND ug.fk_usergroup = ".((int) $usergroup);
|
||||
}
|
||||
if ($user->socid > 0) {
|
||||
// External users should see only contacts of their company
|
||||
$sql .= " AND u.fk_soc = ".((int) $user->socid);
|
||||
|
|
|
|||
|
|
@ -2136,9 +2136,6 @@ abstract class CommonObject
|
|||
$restrictiononfksoc = empty($this->restrictiononfksoc) ? 0 : $this->restrictiononfksoc;
|
||||
$sql = "SELECT MAX(te.".$fieldid.")";
|
||||
$sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te";
|
||||
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
$sql .= ",".$this->db->prefix()."usergroup_user as ug";
|
||||
}
|
||||
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
|
||||
$tmparray = explode('@', $this->ismultientitymanaged);
|
||||
$sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
|
||||
|
|
@ -2174,12 +2171,11 @@ abstract class CommonObject
|
|||
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
|
||||
}
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
||||
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
if ($this->element == 'user' && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
||||
$sql .= " AND te.entity IS NOT NULL"; // Show all users
|
||||
} else {
|
||||
$sql .= " AND ug.fk_user = te.rowid";
|
||||
$sql .= " AND ug.entity IN (".getEntity('usergroup').")";
|
||||
$sql .= " AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
|
||||
}
|
||||
} else {
|
||||
$sql .= ' AND te.entity IN ('.getEntity($this->element).')';
|
||||
|
|
@ -2210,9 +2206,6 @@ abstract class CommonObject
|
|||
|
||||
$sql = "SELECT MIN(te.".$fieldid.")";
|
||||
$sql .= " FROM ".(empty($nodbprefix) ?$this->db->prefix():'').$this->table_element." as te";
|
||||
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
$sql .= ",".$this->db->prefix()."usergroup_user as ug";
|
||||
}
|
||||
if (isset($this->ismultientitymanaged) && !is_numeric($this->ismultientitymanaged)) {
|
||||
$tmparray = explode('@', $this->ismultientitymanaged);
|
||||
$sql .= ", ".$this->db->prefix().$tmparray[1]." as ".($tmparray[1] == 'societe' ? 's' : 'parenttable'); // If we need to link to this table to limit select to entity
|
||||
|
|
@ -2248,12 +2241,11 @@ abstract class CommonObject
|
|||
$sql .= ' AND te.fk_soc = s.rowid'; // If we need to link to societe to limit select to socid
|
||||
}
|
||||
if (isset($this->ismultientitymanaged) && $this->ismultientitymanaged == 1) {
|
||||
if ($this->element == 'user' && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
if ($this->element == 'user' && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
||||
$sql .= " AND te.entity IS NOT NULL"; // Show all users
|
||||
} else {
|
||||
$sql .= " AND ug.fk_user = te.rowid";
|
||||
$sql .= " AND ug.entity IN (".getEntity('usergroup').")";
|
||||
$sql .= " AND te.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
|
||||
}
|
||||
} else {
|
||||
$sql .= ' AND te.entity IN ('.getEntity($this->element).')';
|
||||
|
|
|
|||
|
|
@ -2009,7 +2009,7 @@ class Form
|
|||
* @return array|string HTML select string
|
||||
* @see select_dolgroups()
|
||||
*/
|
||||
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = '0', $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
|
||||
public function select_dolusers($selected = '', $htmlname = 'userid', $show_empty = 0, $exclude = null, $disabled = 0, $include = '', $enableonly = '', $force_entity = 0, $maxlength = 0, $showstatus = 0, $morefilter = '', $show_every = 0, $enableonlytext = '', $morecss = '', $notdisabled = 0, $outputmode = 0, $multiple = false, $forcecombo = 0)
|
||||
{
|
||||
// phpcs:enable
|
||||
global $conf, $user, $langs, $hookmanager;
|
||||
|
|
@ -2056,18 +2056,16 @@ class Form
|
|||
$sql .= " FROM " . $this->db->prefix() . "user as u";
|
||||
if (isModEnabled('multicompany') && $conf->entity == 1 && $user->admin && !$user->entity) {
|
||||
$sql .= " LEFT JOIN " . $this->db->prefix() . "entity as e ON e.rowid = u.entity";
|
||||
if ($force_entity) {
|
||||
if (!empty($force_entity)) {
|
||||
$sql .= " WHERE u.entity IN (0, " . $this->db->sanitize($force_entity) . ")";
|
||||
} else {
|
||||
$sql .= " WHERE u.entity IS NOT NULL";
|
||||
}
|
||||
} else {
|
||||
if (isModEnabled('multicompany') && !empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
$sql .= " LEFT JOIN " . $this->db->prefix() . "usergroup_user as ug";
|
||||
$sql .= " ON ug.fk_user = u.rowid";
|
||||
$sql .= " WHERE ug.entity = " . (int) $conf->entity;
|
||||
if (isModEnabled('multicompany') && getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
$sql .= " WHERE u.rowid IN (SELECT ug.fk_user FROM ".$this->db->prefix()."usergroup_user as ug WHERE ug.entity IN (".getEntity('usergroup')."))";
|
||||
} else {
|
||||
$sql .= " WHERE u.entity IN (0, " . ((int) $conf->entity) . ")";
|
||||
$sql .= " WHERE u.entity IN (" . getEntity('user') . ")";
|
||||
}
|
||||
}
|
||||
if (!empty($user->socid)) {
|
||||
|
|
@ -2173,8 +2171,8 @@ class Form
|
|||
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(') . $langs->trans('Disabled');
|
||||
}
|
||||
}
|
||||
if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
|
||||
if (!$obj->entity) {
|
||||
if (isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && !empty($user->admin) && empty($user->entity)) {
|
||||
if (empty($obj->entity)) {
|
||||
$moreinfo .= ($moreinfo ? ' - ' : ' (') . $langs->trans("AllEntities");
|
||||
$moreinfohtml .= ($moreinfohtml ? ' - ' : ' <span class="opacitymedium">(') . $langs->trans("AllEntities");
|
||||
} else {
|
||||
|
|
@ -2184,9 +2182,9 @@ class Form
|
|||
}
|
||||
}
|
||||
}
|
||||
$moreinfo .= ($moreinfo ? ')' : '');
|
||||
$moreinfohtml .= ($moreinfohtml ? ')</span>' : '');
|
||||
if ($disableline && $disableline != '1') {
|
||||
$moreinfo .= (!empty($moreinfo) ? ')' : '');
|
||||
$moreinfohtml .= (!empty($moreinfohtml) ? ')</span>' : '');
|
||||
if (!empty($disableline) && $disableline != '1') {
|
||||
// Add text from $enableonlytext parameter
|
||||
$moreinfo .= ' - ' . $disableline;
|
||||
$moreinfohtml .= ' - ' . $disableline;
|
||||
|
|
@ -2195,7 +2193,7 @@ class Form
|
|||
$labeltoshowhtml .= $moreinfohtml;
|
||||
|
||||
$out .= '<option value="' . $obj->rowid . '"';
|
||||
if ($disableline) {
|
||||
if (!empty($disableline)) {
|
||||
$out .= ' disabled';
|
||||
}
|
||||
if ((is_object($selected) && $selected->id == $obj->rowid) || (!is_object($selected) && in_array($obj->rowid, $selected))) {
|
||||
|
|
@ -9938,7 +9936,7 @@ class Form
|
|||
$out .= '>';
|
||||
|
||||
$out .= $obj->name;
|
||||
if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
|
||||
if (isModEnabled('multicompany') && !getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1) {
|
||||
$out .= " (" . $obj->label . ")";
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -504,7 +504,7 @@ class FormOther
|
|||
$sql_usr = "SELECT u.rowid, u.lastname, u.firstname, u.statut as status, u.login, u.photo, u.gender, u.entity, u.admin";
|
||||
$sql_usr .= " FROM ".$this->db->prefix()."user as u";
|
||||
|
||||
if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
||||
$sql_usr .= " WHERE u.entity IS NOT NULL"; // Show all users
|
||||
} else {
|
||||
|
|
@ -533,7 +533,7 @@ class FormOther
|
|||
$sql_usr .= "SELECT u2.rowid, u2.lastname, u2.firstname, u2.statut as status, u2.login, u2.photo, u2.gender, u2.entity, u2.admin";
|
||||
$sql_usr .= " FROM ".$this->db->prefix()."user as u2, ".$this->db->prefix()."societe_commerciaux as sc";
|
||||
|
||||
if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
|
||||
if (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE')) {
|
||||
if (!empty($user->admin) && empty($user->entity) && $conf->entity == 1) {
|
||||
$sql_usr .= " WHERE u2.entity IS NOT NULL"; // Show all users
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -528,7 +528,7 @@ class Ldap
|
|||
*/
|
||||
public function add($dn, $info, $user)
|
||||
{
|
||||
dol_syslog(get_class($this)."::add dn=".$dn." info=".json_encode($info));
|
||||
dol_syslog(get_class($this)."::add dn=".$dn." info=".print_r($info, true));
|
||||
|
||||
// Check parameters
|
||||
if (!$this->connection) {
|
||||
|
|
@ -576,7 +576,7 @@ class Ldap
|
|||
*/
|
||||
public function modify($dn, $info, $user)
|
||||
{
|
||||
dol_syslog(get_class($this)."::modify dn=".$dn." info=".join(',', $info));
|
||||
dol_syslog(get_class($this)."::modify dn=".$dn." info=".print_r($info, true));
|
||||
|
||||
// Check parameters
|
||||
if (!$this->connection) {
|
||||
|
|
|
|||
Loading…
Reference in a new issue