diff --git a/htdocs/core/class/html.formother.class.php b/htdocs/core/class/html.formother.class.php index 5b04cb43846..83b41a8a0c3 100644 --- a/htdocs/core/class/html.formother.class.php +++ b/htdocs/core/class/html.formother.class.php @@ -462,7 +462,7 @@ class FormOther */ function select_color($set_color='', $prefix='f_color', $form_name='objForm', $showcolorbox=1, $arrayofcolors='') { - print selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors); + print $this->selectColor($set_color, $prefix, $form_name, $showcolorbox, $arrayofcolors); } /** diff --git a/htdocs/core/lib/security2.lib.php b/htdocs/core/lib/security2.lib.php index 3ad369af05f..1c0d87a9e23 100644 --- a/htdocs/core/lib/security2.lib.php +++ b/htdocs/core/lib/security2.lib.php @@ -54,7 +54,7 @@ function checkLoginPassEntity($usertotest,$passwordtotest,$entitytotest,$authmod global $conf,$langs; //global $dolauthmode; // To return authentication finally used - // Check parameetrs + // Check parameters if ($entitytotest == '') $entitytotest=1; dol_syslog("checkLoginPassEntity usertotest=".$usertotest." entitytotest=".$entitytotest." authmode=".join(',',$authmode)); diff --git a/htdocs/core/login/functions_dolibarr.php b/htdocs/core/login/functions_dolibarr.php index 700caf54c07..35042f6f179 100644 --- a/htdocs/core/login/functions_dolibarr.php +++ b/htdocs/core/login/functions_dolibarr.php @@ -36,9 +36,14 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest=1) { global $db,$conf,$langs; + global $mc; dol_syslog("functions_dolibarr::check_user_password_dolibarr usertotest=".$usertotest); + // Force master entity in transversal mode + $entity=$entitytotest; + if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) $entity=1; + $login=''; if (! empty($usertotest)) @@ -48,10 +53,10 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest= $usernamecol = 'login'; $entitycol = 'entity'; - $sql ='SELECT pass, pass_crypted'; + $sql ='SELECT rowid, entity, pass, pass_crypted'; $sql.=' FROM '.$table; $sql.=' WHERE '.$usernamecol." = '".$db->escape($usertotest)."'"; - $sql.=' AND '.$entitycol." IN (0," . ($entitytotest ? $entitytotest : 1) . ")"; + $sql.=' AND '.$entitycol." IN (0," . ($entity ? $entity : 1) . ")"; dol_syslog("functions_dolibarr::check_user_password_dolibarr sql=".$sql); $resql=$db->query($sql); @@ -92,6 +97,12 @@ function check_user_password_dolibarr($usertotest,$passwordtotest,$entitytotest= } } + if ($passok && ! empty($obj->entity) && (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode))) + { + $ret=$mc->checkRight($obj->rowid, $entitytotest); + if ($ret < 0) $passok=false; + } + // Password ok ? if ($passok) { diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index c18cb7e3967..31f22ef81b6 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -358,7 +358,7 @@ if (! defined('NOLOGIN')) // Appel des triggers include_once(DOL_DOCUMENT_ROOT . "/core/class/interfaces.class.php"); $interface=new Interfaces($db); - $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST('entity','int',2)); + $result=$interface->run_triggers('USER_LOGIN_FAILED',$user,$user,$langs,$conf,GETPOST('entity','int')); if ($result < 0) { $error++; } @@ -752,7 +752,7 @@ $heightforframes=52; // Switch to another entity if (! empty($conf->multicompany->enabled) && GETPOST('action') == 'switchentity') { - if ($mc->switchEntity(GETPOST('entity','int',2)) > 0) + if ($mc->switchEntity(GETPOST('entity','int')) > 0) { Header("Location: ".DOL_URL_ROOT.'/'); exit; diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 71a3094ed53..d0ee57086e0 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -150,7 +150,7 @@ class User extends CommonObject $sql.= " u.ref_int, u.ref_ext"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1) + if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)) { $sql.= " WHERE u.entity IS NOT NULL"; } diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 328fd63383c..5903d7e35c3 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -146,11 +146,14 @@ class UserGroup extends CommonObject { while ($obj = $this->db->fetch_object($result)) { - $newgroup=new UserGroup($this->db); - $newgroup->fetch($obj->rowid); - $newgroup->usergroup_entity = $obj->usergroup_entity; + if (! array_key_exists($obj->rowid, $ret)) + { + $newgroup=new UserGroup($this->db); + $newgroup->fetch($obj->rowid); + $ret[$obj->rowid]=$newgroup; + } - $ret[]=$newgroup; + $ret[$obj->rowid]->usergroup_entity[]=$obj->usergroup_entity; } $this->db->free($result); @@ -181,7 +184,7 @@ class UserGroup extends CommonObject $sql.= " ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql.= " WHERE ug.fk_user = u.rowid"; $sql.= " AND ug.fk_usergroup = ".$this->id; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity) + if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && $user->admin && ! $user->entity) { $sql.= " AND u.entity IS NOT NULL"; } @@ -189,17 +192,21 @@ class UserGroup extends CommonObject { $sql.= " AND u.entity IN (0,".$conf->entity.")"; } + dol_syslog(get_class($this)."::listUsersForGroup sql=".$sql,LOG_DEBUG); $result = $this->db->query($sql); if ($result) { while ($obj = $this->db->fetch_object($result)) { - $newuser=new User($this->db); - $newuser->fetch($obj->rowid); - $newuser->usergroup_entity = $obj->usergroup_entity; + if (! array_key_exists($obj->rowid, $ret)) + { + $newuser=new User($this->db); + $newuser->fetch($obj->rowid); + $ret[$obj->rowid]=$newuser; + } - $ret[]=$newuser; + $ret[$obj->rowid]->usergroup_entity[]=$obj->usergroup_entity; } $this->db->free($result); diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 66c26c6660e..780422e8246 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -1394,8 +1394,17 @@ else print ''; if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity) { - $mc->getInfo($group->usergroup_entity); - print ''.$mc->label.""; + print ''; + if (! empty($group->usergroup_entity)) + { + $nb=0; + foreach($group->usergroup_entity as $group_entity) + { + $mc->getInfo($group_entity); + print ($nb > 0 ? ', ' : '').$mc->label; + $nb++; + } + } } print ''; if ($caneditgroup) diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index e7b7a99d932..72186008c3c 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -354,7 +354,7 @@ else if (! empty($object->members)) { - if( !($conf->multicompany->enabled && $conf->multicompany->transverse_mode)) + if (! ($conf->multicompany->enabled && $conf->multicompany->transverse_mode)) { foreach($object->members as $useringroup) { @@ -404,7 +404,7 @@ else print ''.$langs->trans("Login").''; print ''.$langs->trans("Lastname").''; print ''.$langs->trans("Firstname").''; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1) + if (! empty($conf->multicompany->enabled) && $conf->entity == 1) { print ''.$langs->trans("Entity").''; } @@ -428,10 +428,20 @@ else print ''; print ''.$useringroup->lastname.''; print ''.$useringroup->firstname.''; - if(! empty($conf->multicompany->enabled) && $conf->entity == 1) + if (! empty($conf->multicompany->enabled) && $conf->entity == 1) { - $mc->getInfo($useringroup->usergroup_entity); - print ''.$mc->label.""; + print ''; + if (! empty($useringroup->usergroup_entity)) + { + $nb=0; + foreach($useringroup->usergroup_entity as $group_entity) + { + $mc->getInfo($group_entity); + print ($nb > 0 ? ', ' : '').$mc->label; + $nb++; + } + } + print ''; } print ''.$useringroup->getLibStatut(3).''; print ''; diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index f0e34feffc0..fd2857452d0 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -55,10 +55,10 @@ llxHeader(); print_fiche_titre($langs->trans("ListOfGroups")); -$sql = "SELECT g.rowid, g.nom, g.entity, g.datec, COUNT(ugu.rowid) as nb"; +$sql = "SELECT g.rowid, g.nom, g.entity, g.datec, COUNT(DISTINCT ugu.fk_user) as nb"; $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as g"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid"; -if(! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->multicompany->transverse_mode || ($user->admin && ! $user->entity))) +if (! empty($conf->multicompany->enabled) && $conf->entity == 1 && ($conf->multicompany->transverse_mode || ($user->admin && ! $user->entity))) { $sql.= " WHERE g.entity IS NOT NULL"; } @@ -100,13 +100,13 @@ if ($resql) print ""; print ''.img_object($langs->trans("ShowGroup"),"group").' '.$obj->nom.''; - if (!$obj->entity) + if (! $obj->entity) { print img_picto($langs->trans("GlobalGroup"),'redstar'); } print ""; //multicompany - if(! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) + if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1) { $mc->getInfo($obj->entity); print ''.$mc->label.'';