Fix: compatibility with multicompany
This commit is contained in:
parent
3bfd9182e0
commit
ca62c3dba8
@ -114,7 +114,6 @@ foreach ($modulesdir as $dir)
|
|||||||
if ($objMod->rights_class)
|
if ($objMod->rights_class)
|
||||||
{
|
{
|
||||||
$ret=$objMod->insert_permissions(0);
|
$ret=$objMod->insert_permissions(0);
|
||||||
|
|
||||||
$modules[$objMod->rights_class]=$objMod;
|
$modules[$objMod->rights_class]=$objMod;
|
||||||
//print "modules[".$objMod->rights_class."]=$objMod;";
|
//print "modules[".$objMod->rights_class."]=$objMod;";
|
||||||
}
|
}
|
||||||
@ -130,7 +129,7 @@ $db->commit();
|
|||||||
$sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
|
$sql = "SELECT r.id, r.libelle, r.module, r.perms, r.subperms, r.bydefault";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
|
||||||
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
|
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
|
||||||
$sql.= " AND entity in (".(!empty($conf->multicompany->transverse_mode)?"1,":"").$conf->entity.")";
|
$sql.= " AND entity IN (".(! empty($conf->multicompany->transverse_mode)?"1,":"").$conf->entity.")";
|
||||||
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
|
if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql.= " AND r.perms NOT LIKE '%_advance'"; // Hide advanced perms if option is not enabled
|
||||||
$sql.= " ORDER BY r.module, r.id";
|
$sql.= " ORDER BY r.module, r.id";
|
||||||
|
|
||||||
|
|||||||
@ -176,15 +176,12 @@ class Conf
|
|||||||
{
|
{
|
||||||
$modulename = strtolower($reg[1]);
|
$modulename = strtolower($reg[1]);
|
||||||
$partname = strtolower($reg[2]);
|
$partname = strtolower($reg[2]);
|
||||||
//$varname = $partname.'_modules'; // TODO deprecated
|
|
||||||
//if (! isset($this->$varname) || ! is_array($this->$varname)) { $this->$varname = array(); } // TODO deprecated
|
|
||||||
if (! isset($this->modules_parts[$partname]) || ! is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
|
if (! isset($this->modules_parts[$partname]) || ! is_array($this->modules_parts[$partname])) { $this->modules_parts[$partname] = array(); }
|
||||||
$arrValue = json_decode($value,true);
|
$arrValue = json_decode($value,true);
|
||||||
if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue;
|
if (is_array($arrValue) && ! empty($arrValue)) $value = $arrValue;
|
||||||
else if (in_array($partname,array('login','menus','substitutions','triggers','tpl','theme'))) $value = '/'.$modulename.'/core/'.$partname.'/';
|
else if (in_array($partname,array('login','menus','substitutions','triggers','tpl','theme'))) $value = '/'.$modulename.'/core/'.$partname.'/';
|
||||||
else if (in_array($partname,array('models'))) $value = '/'.$modulename.'/';
|
else if (in_array($partname,array('models'))) $value = '/'.$modulename.'/';
|
||||||
else if ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/';
|
else if ($value == 1) $value = '/'.$modulename.'/core/modules/'.$partname.'/';
|
||||||
//$this->$varname = array_merge($this->$varname, array($modulename => $value)); // TODO deprecated
|
|
||||||
$this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value));
|
$this->modules_parts[$partname] = array_merge($this->modules_parts[$partname], array($modulename => $value));
|
||||||
}
|
}
|
||||||
// If this is a module constant (must be at end)
|
// If this is a module constant (must be at end)
|
||||||
|
|||||||
@ -970,7 +970,7 @@ class Form
|
|||||||
$sql.= " FROM ".MAIN_DB_PREFIX ."user as u";
|
$sql.= " FROM ".MAIN_DB_PREFIX ."user as u";
|
||||||
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.= " LEFT JOIN ".MAIN_DB_PREFIX ."entity as e on e.rowid=u.entity";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX ."entity as e ON e.rowid=u.entity";
|
||||||
if ($force_entity) $sql.= " WHERE u.entity IN (0,".$force_entity.")";
|
if ($force_entity) $sql.= " WHERE u.entity IN (0,".$force_entity.")";
|
||||||
else $sql.= " WHERE u.entity IS NOT NULL";
|
else $sql.= " WHERE u.entity IS NOT NULL";
|
||||||
}
|
}
|
||||||
@ -3763,7 +3763,7 @@ class Form
|
|||||||
$sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug ";
|
$sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug ";
|
||||||
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.= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e on e.rowid=ug.entity";
|
$sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e ON e.rowid=ug.entity";
|
||||||
if ($force_entity) $sql.= " WHERE ug.entity IN (0,".$force_entity.")";
|
if ($force_entity) $sql.= " WHERE ug.entity IN (0,".$force_entity.")";
|
||||||
else $sql.= " WHERE ug.entity IS NOT NULL";
|
else $sql.= " WHERE ug.entity IS NOT NULL";
|
||||||
}
|
}
|
||||||
|
|||||||
@ -879,21 +879,21 @@ abstract class DolibarrModules
|
|||||||
* Insert permissions definitions related to the module into llx_rights_def
|
* Insert permissions definitions related to the module into llx_rights_def
|
||||||
*
|
*
|
||||||
* @param int $reinitadminperms If 1, we also grant them to all admin users
|
* @param int $reinitadminperms If 1, we also grant them to all admin users
|
||||||
|
* @param int $force_entity Force current entity
|
||||||
* @return int Number of error (0 if OK)
|
* @return int Number of error (0 if OK)
|
||||||
*/
|
*/
|
||||||
function insert_permissions($reinitadminperms=0)
|
function insert_permissions($reinitadminperms=0, $force_entity=null)
|
||||||
{
|
{
|
||||||
global $conf,$user;
|
global $conf,$user;
|
||||||
|
|
||||||
$err=0;
|
$err=0;
|
||||||
|
$entity=(! empty($force_entity) ? $force_entity : $conf->entity);
|
||||||
//print $this->rights_class." ".count($this->rights)."<br>";
|
|
||||||
|
|
||||||
// Test if module is activated
|
// Test if module is activated
|
||||||
$sql_del = "SELECT ".$this->db->decrypt('value')." as value";
|
$sql_del = "SELECT ".$this->db->decrypt('value')." as value";
|
||||||
$sql_del.= " FROM ".MAIN_DB_PREFIX."const";
|
$sql_del.= " FROM ".MAIN_DB_PREFIX."const";
|
||||||
$sql_del.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
|
$sql_del.= " WHERE ".$this->db->decrypt('name')." = '".$this->const_name."'";
|
||||||
$sql_del.= " AND entity IN (0,".$conf->entity.")";
|
$sql_del.= " AND entity IN (0,".$entity.")";
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::insert_permissions sql=".$sql_del);
|
dol_syslog(get_class($this)."::insert_permissions sql=".$sql_del);
|
||||||
$resql=$this->db->query($sql_del);
|
$resql=$this->db->query($sql_del);
|
||||||
@ -922,14 +922,14 @@ abstract class DolibarrModules
|
|||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
||||||
$sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
|
$sql.= " (id, entity, libelle, module, type, bydefault, perms, subperms)";
|
||||||
$sql.= " VALUES ";
|
$sql.= " VALUES ";
|
||||||
$sql.= "(".$r_id.",".$conf->entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')";
|
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."','".$r_subperms."')";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def";
|
||||||
$sql.= " (id, entity, libelle, module, type, bydefault, perms)";
|
$sql.= " (id, entity, libelle, module, type, bydefault, perms)";
|
||||||
$sql.= " VALUES ";
|
$sql.= " VALUES ";
|
||||||
$sql.= "(".$r_id.",".$conf->entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')";
|
$sql.= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.",'".$r_perms."')";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@ -937,7 +937,7 @@ abstract class DolibarrModules
|
|||||||
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
|
$sql = "INSERT INTO ".MAIN_DB_PREFIX."rights_def ";
|
||||||
$sql .= " (id, entity, libelle, module, type, bydefault)";
|
$sql .= " (id, entity, libelle, module, type, bydefault)";
|
||||||
$sql .= " VALUES ";
|
$sql .= " VALUES ";
|
||||||
$sql .= "(".$r_id.",".$conf->entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")";
|
$sql .= "(".$r_id.",".$entity.",'".$this->db->escape($r_desc)."','".$r_modul."','".$r_type."',".$r_def.")";
|
||||||
}
|
}
|
||||||
|
|
||||||
dol_syslog(get_class($this)."::insert_permissions sql=".$sql, LOG_DEBUG);
|
dol_syslog(get_class($this)."::insert_permissions sql=".$sql, LOG_DEBUG);
|
||||||
@ -959,7 +959,7 @@ abstract class DolibarrModules
|
|||||||
if ($reinitadminperms)
|
if ($reinitadminperms)
|
||||||
{
|
{
|
||||||
include_once(DOL_DOCUMENT_ROOT.'/user/class/user.class.php');
|
include_once(DOL_DOCUMENT_ROOT.'/user/class/user.class.php');
|
||||||
$sql="SELECT rowid from ".MAIN_DB_PREFIX."user where admin = 1";
|
$sql="SELECT rowid FROM ".MAIN_DB_PREFIX."user WHERE admin = 1";
|
||||||
dol_syslog(get_class($this)."::insert_permissions Search all admin users sql=".$sql);
|
dol_syslog(get_class($this)."::insert_permissions Search all admin users sql=".$sql);
|
||||||
$resqlseladmin=$this->db->query($sql,1);
|
$resqlseladmin=$this->db->query($sql,1);
|
||||||
if ($resqlseladmin)
|
if ($resqlseladmin)
|
||||||
|
|||||||
@ -1227,7 +1227,7 @@ else
|
|||||||
|
|
||||||
print '<div class="tabsAction">';
|
print '<div class="tabsAction">';
|
||||||
|
|
||||||
if ($caneditfield && (empty($conf->multicompany->enabled) || (($fuser->entity == $conf->entity) || $fuser->entity == $user->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
|
if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
|
||||||
{
|
{
|
||||||
@ -1239,7 +1239,7 @@ else
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
elseif ($caneditpassword && ! $fuser->ldap_sid &&
|
elseif ($caneditpassword && ! $fuser->ldap_sid &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=edit">'.$langs->trans("EditPassword").'</a>';
|
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=edit">'.$langs->trans("EditPassword").'</a>';
|
||||||
}
|
}
|
||||||
@ -1252,7 +1252,7 @@ else
|
|||||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("ReinitPassword").'</a>';
|
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("ReinitPassword").'</a>';
|
||||||
}
|
}
|
||||||
elseif (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid &&
|
elseif (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=password">'.$langs->trans("ReinitPassword").'</a>';
|
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=password">'.$langs->trans("ReinitPassword").'</a>';
|
||||||
}
|
}
|
||||||
@ -1262,7 +1262,7 @@ else
|
|||||||
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("SendNewPassword").'</a>';
|
print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("SendNewPassword").'</a>';
|
||||||
}
|
}
|
||||||
else if (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid &&
|
else if (($user->id != $id && $caneditpassword) && $fuser->login && !$fuser->ldap_sid &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
if ($fuser->email) print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=passwordsend">'.$langs->trans("SendNewPassword").'</a>';
|
if ($fuser->email) print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=passwordsend">'.$langs->trans("SendNewPassword").'</a>';
|
||||||
else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendNewPassword").'</a>';
|
else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendNewPassword").'</a>';
|
||||||
@ -1271,19 +1271,19 @@ else
|
|||||||
|
|
||||||
// Activer
|
// Activer
|
||||||
if ($user->id <> $id && $candisableuser && $fuser->statut == 0 &&
|
if ($user->id <> $id && $candisableuser && $fuser->statut == 0 &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=enable">'.$langs->trans("Reactivate").'</a>';
|
print '<a class="butAction" href="fiche.php?id='.$fuser->id.'&action=enable">'.$langs->trans("Reactivate").'</a>';
|
||||||
}
|
}
|
||||||
// Desactiver
|
// Desactiver
|
||||||
if ($user->id <> $id && $candisableuser && $fuser->statut == 1 &&
|
if ($user->id <> $id && $candisableuser && $fuser->statut == 1 &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
print '<a class="butActionDelete" href="fiche.php?action=disable&id='.$fuser->id.'">'.$langs->trans("DisableUser").'</a>';
|
print '<a class="butActionDelete" href="fiche.php?action=disable&id='.$fuser->id.'">'.$langs->trans("DisableUser").'</a>';
|
||||||
}
|
}
|
||||||
// Delete
|
// Delete
|
||||||
if ($user->id <> $id && $candisableuser &&
|
if ($user->id <> $id && $candisableuser &&
|
||||||
(empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)) )
|
(empty($conf->multicompany->enabled) || ! $user->entity || ($fuser->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
|
||||||
{
|
{
|
||||||
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$fuser->id.'">'.$langs->trans("DeleteUser").'</a>';
|
print '<a class="butActionDelete" href="fiche.php?action=delete&id='.$fuser->id.'">'.$langs->trans("DeleteUser").'</a>';
|
||||||
}
|
}
|
||||||
@ -1602,7 +1602,7 @@ else
|
|||||||
if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
|
if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
|
||||||
{
|
{
|
||||||
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
|
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
|
||||||
print "<td>".$mc->select_entities($conf->entity);
|
print "<td>".$mc->select_entities($fuser->entity);
|
||||||
print "</td></tr>\n";
|
print "</td></tr>\n";
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
|||||||
@ -126,7 +126,8 @@ if ($id)
|
|||||||
// Load all permissions
|
// Load all permissions
|
||||||
if ($objMod->rights_class)
|
if ($objMod->rights_class)
|
||||||
{
|
{
|
||||||
$ret=$objMod->insert_permissions(0);
|
$entity=((! empty($conf->multicompany->enabled) && ! empty($fgroup->entity)) ? $fgroup->entity : null);
|
||||||
|
$ret=$objMod->insert_permissions(0, $entity);
|
||||||
$modules[$objMod->rights_class]=$objMod;
|
$modules[$objMod->rights_class]=$objMod;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -148,7 +149,7 @@ if ($id)
|
|||||||
{
|
{
|
||||||
if (empty($conf->multicompany->transverse_mode))
|
if (empty($conf->multicompany->transverse_mode))
|
||||||
{
|
{
|
||||||
$sql.= " AND r.entity = ".$conf->entity;
|
$sql.= " AND r.entity = ".$fgroup->entity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
@ -224,12 +225,11 @@ if ($id)
|
|||||||
$sql = "SELECT r.id, r.libelle, r.module";
|
$sql = "SELECT r.id, r.libelle, r.module";
|
||||||
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
|
$sql.= " FROM ".MAIN_DB_PREFIX."rights_def as r";
|
||||||
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
|
$sql.= " WHERE r.libelle NOT LIKE 'tou%'"; // On ignore droits "tous"
|
||||||
//$sql.= " AND r.entity = ".(empty($conf->multicompany->enabled) ? $conf->entity : $fgroup->entity);
|
|
||||||
if(! empty($conf->multicompany->enabled))
|
if(! empty($conf->multicompany->enabled))
|
||||||
{
|
{
|
||||||
if (empty($conf->multicompany->transverse_mode))
|
if (empty($conf->multicompany->transverse_mode))
|
||||||
{
|
{
|
||||||
$sql.= " AND r.entity = ".$conf->entity;
|
$sql.= " AND r.entity = ".$fgroup->entity;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@ -152,8 +152,8 @@ foreach($modulesdir as $dir)
|
|||||||
// Load all permissions
|
// Load all permissions
|
||||||
if ($objMod->rights_class)
|
if ($objMod->rights_class)
|
||||||
{
|
{
|
||||||
$ret=$objMod->insert_permissions(0);
|
$entity=((! empty($conf->multicompany->enabled) && ! empty($fuser->entity)) ? $fuser->entity : null);
|
||||||
|
$ret=$objMod->insert_permissions(0, $entity);
|
||||||
$modules[$objMod->rights_class]=$objMod;
|
$modules[$objMod->rights_class]=$objMod;
|
||||||
//print "modules[".$objMod->rights_class."]=$objMod;";
|
//print "modules[".$objMod->rights_class."]=$objMod;";
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user