From 14e0db66023674771c03d5e59db08ec9fd425823 Mon Sep 17 00:00:00 2001 From: Regis Houssin Date: Fri, 19 Aug 2011 07:22:17 +0000 Subject: [PATCH] multi-company module enhancement --- htdocs/core/class/html.form.class.php | 31 ++- htdocs/main.inc.php | 34 +-- htdocs/user/class/user.class.php | 8 +- htdocs/user/class/usergroup.class.php | 16 +- htdocs/user/fiche.php | 131 +++++++++--- htdocs/user/group/fiche.php | 291 +++++++++++++++----------- htdocs/user/group/index.php | 21 +- htdocs/user/index.php | 20 +- 8 files changed, 370 insertions(+), 182 deletions(-) diff --git a/htdocs/core/class/html.form.class.php b/htdocs/core/class/html.form.class.php index 1cf6973102e..fdcd213a5d0 100644 --- a/htdocs/core/class/html.form.class.php +++ b/htdocs/core/class/html.form.class.php @@ -11,6 +11,7 @@ * Copyright (C) 2007 Patrick Raguin * Copyright (C) 2010 Juanjo Menent * Copyright (C) 2010 Philippe Grand + * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -30,7 +31,7 @@ * \file htdocs/core/class/html.form.class.php * \ingroup core * \brief File of class with all html predefined components - * \version $Id: html.form.class.php,v 1.196 2011/08/17 15:56:23 eldy Exp $ + * \version $Id: html.form.class.php,v 1.197 2011/08/19 07:22:17 hregis Exp $ */ @@ -794,8 +795,16 @@ class Form // On recherche les utilisateurs $sql = "SELECT u.rowid, u.name, u.firstname, u.login, u.admin"; + if($conf->entity==0) + $sql.=" ,e.label"; $sql.= " FROM ".MAIN_DB_PREFIX ."user as u"; - $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; + if($conf->entity==0) + { + $sql.=" LEFT JOIN ".MAIN_DB_PREFIX ."entity as e on e.rowid=u.entity"; + $sql.=" WHERE u.entity IS NOT NULL"; + } + else + $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; if (is_array($exclude) && $excludeUsers) $sql.= " AND u.rowid NOT IN ('".$excludeUsers."')"; if (is_array($include) && $includeUsers) $sql.= " AND u.rowid IN ('".$includeUsers."')"; $sql.= " ORDER BY u.name ASC"; @@ -836,6 +845,8 @@ class Form $out.= '>'; } $out.= $userstatic->getFullName($langs); + if($conf->entity==0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) + $out.=" (".$obj->label.")"; //if ($obj->admin) $out.= ' *'; if ($conf->global->MAIN_SHOW_LOGIN) $out.= ' ('.$obj->login.')'; @@ -3504,9 +3515,17 @@ class Form // On recherche les groupes $sql = "SELECT ug.rowid, ug.nom "; - $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug "; - $sql.= " WHERE ug.entity IN (0,".$conf->entity.")"; - if (is_array($exclude) && $excludeGroups) $sql.= " AND ug.rowid NOT IN ('".$excludeGroups."')"; + if($conf->entity==0) + $sql.= ", e.label"; + $sql.= " FROM ".MAIN_DB_PREFIX."usergroup as ug "; + if($conf->entity==0) + { + $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."entity as e on e.rowid=ug.entity"; + $sql.= " WHERE ug.entity IS NOT NULL"; + } + else + $sql.= " WHERE ug.entity IN (0,".$conf->entity.")"; + if (is_array($exclude) && $excludeGroups) $sql.= " AND ug.rowid NOT IN ('".$excludeGroups."')"; if (is_array($include) && $includeGroups) $sql.= " AND ug.rowid IN ('".$includeGroups."')"; $sql.= " ORDER BY ug.nom ASC"; @@ -3535,6 +3554,8 @@ class Form $out.= '>'; $out.= $obj->nom; + if($conf->entity==0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) + $out.= " (".$obj->label.")"; $out.= ''; $i++; diff --git a/htdocs/main.inc.php b/htdocs/main.inc.php index da32bbc8ff8..bd7b1d4d629 100644 --- a/htdocs/main.inc.php +++ b/htdocs/main.inc.php @@ -25,7 +25,7 @@ * \file htdocs/main.inc.php * \ingroup core * \brief File that defines environment for Dolibarr pages only (variables not required by scripts) - * \version $Id: main.inc.php,v 1.765 2011/08/18 23:17:23 cdelambert Exp $ + * \version $Id: main.inc.php,v 1.766 2011/08/19 07:22:17 hregis Exp $ */ @ini_set('memory_limit', '64M'); // This may be useless if memory is hard limited by your PHP @@ -751,16 +751,19 @@ $heightforframes=48; // Switch to another entity if (!empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { - if (GETPOST('action') == 'switchentity' && $user->admin && ! $user->entity) + if (GETPOST('action') == 'switchentity') { - require_once("../class/actions_multicompany.class.php"); - - $mc = new ActionsMulticompany($db); - - if($mc->switchEntity(GETPOST('entity')) > 0) + $res = @dol_include_once("/multicompany/class/actions_multicompany.class.php"); + + if ($res) { - Header("Location: ".DOL_URL_ROOT.'/'); - exit; + $mc = new ActionsMulticompany($db); + + if($mc->switchEntity(GETPOST('entity')) >= 0) + { + Header("Location: ".DOL_URL_ROOT.'/'); + exit; + } } } } @@ -1237,15 +1240,12 @@ function top_menu($head, $title='', $target='', $disablejs=0, $disablehead=0, $a // Select entity if (! empty($conf->global->MAIN_MODULE_MULTICOMPANY)) { - if ($user->admin && ! $user->entity) - { - $res=@dol_include_once('/multicompany/class/actions_multicompany.class.php'); + $res=@dol_include_once('/multicompany/class/actions_multicompany.class.php'); - if ($res) - { - $mc = new ActionsMulticompany($db); - $mc->showInfo($conf->entity); - } + if ($res) + { + $mc = new ActionsMulticompany($db); + $mc->showInfo($conf->entity); } } diff --git a/htdocs/user/class/user.class.php b/htdocs/user/class/user.class.php index 393d9710a48..e0d030da0a2 100644 --- a/htdocs/user/class/user.class.php +++ b/htdocs/user/class/user.class.php @@ -6,6 +6,7 @@ * Copyright (C) 2004 Benoit Mortier * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2005 Lionel Cousteix + * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -24,7 +25,7 @@ /** * \file htdocs/user/class/user.class.php * \brief Fichier de la classe utilisateur - * \version $Id: user.class.php,v 1.47 2011/07/31 23:21:26 eldy Exp $ + * \version $Id: user.class.php,v 1.48 2011/08/19 07:22:17 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT ."/core/class/commonobject.class.php"); @@ -143,7 +144,10 @@ class User extends CommonObject $sql.= " u.photo as photo,"; $sql.= " u.openid as openid"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; - $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; + if($conf->entity==0) + $sql.= " WHERE u.entity IS NOT NULL"; + else + $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; if ($sid) { diff --git a/htdocs/user/class/usergroup.class.php b/htdocs/user/class/usergroup.class.php index 74c1970c7f6..8823ac96979 100644 --- a/htdocs/user/class/usergroup.class.php +++ b/htdocs/user/class/usergroup.class.php @@ -21,7 +21,7 @@ * \file htdocs/user/class/usergroup.class.php * \brief Fichier de la classe des groupes d'utilisateur * \author Rodolphe Qiedeville - * \version $Id: usergroup.class.php,v 1.12 2011/07/31 23:21:26 eldy Exp $ + * \version $Id: usergroup.class.php,v 1.13 2011/08/19 07:22:17 hregis Exp $ */ require_once(DOL_DOCUMENT_ROOT."/core/class/commonobject.class.php"); @@ -129,7 +129,10 @@ class UserGroup extends CommonObject $sql.= " ".MAIN_DB_PREFIX."usergroup_user as ug"; $sql.= " WHERE ug.fk_usergroup = g.rowid"; $sql.= " AND ug.fk_user = ".$userid; - $sql.= " AND ug.entity IN (0,".$conf->entity.")"; + if($conf->entity==0) + $sql.= " AND ug.entity IS NOT NULL"; + else + $sql.= " AND ug.entity IN (0,".$conf->entity.")"; $sql.= " ORDER BY g.nom"; dol_syslog("UserGroup::listGroupsForUser sql=".$sql,LOG_DEBUG); @@ -172,7 +175,10 @@ 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; - $sql.= " AND u.entity IN (0,".$conf->entity.")"; + if($conf->entity==0) + $sql.= " AND u.entity IS NOT NULL"; + else + $sql.= " AND u.entity IN (0,".$conf->entity.")"; dol_syslog("UserGroup::listUsersForGroup sql=".$sql,LOG_DEBUG); $result = $this->db->query($sql); @@ -512,7 +518,7 @@ class UserGroup extends CommonObject $sql.= ") VALUES ("; $sql.= "'".$this->db->idate($now)."'"; $sql.= ",'".$this->db->escape($this->nom)."'"; - $sql.= ",".($this->globalgroup ? 0 : $conf->entity); + $sql.= ",".($conf->entity==0 ? $this->entity : $conf->entity); $sql.= ")"; dol_syslog("UserGroup::Create sql=".$sql, LOG_DEBUG); @@ -556,7 +562,7 @@ class UserGroup extends CommonObject $sql = "UPDATE ".MAIN_DB_PREFIX."usergroup SET "; $sql.= " nom = '".$this->db->escape($this->nom)."'"; - $sql.= ", entity = ".(empty($this->globalgroup) ? $conf->entity : 0); + $sql.= ", entity = ".($conf->entity==0 ? $this->entity : $conf->entity); $sql.= ", note = '".$this->db->escape($this->note)."'"; $sql.= " WHERE rowid = ".$this->id; diff --git a/htdocs/user/fiche.php b/htdocs/user/fiche.php index 4531214e886..ef07782f78e 100644 --- a/htdocs/user/fiche.php +++ b/htdocs/user/fiche.php @@ -5,6 +5,7 @@ * Copyright (C) 2004 Eric Seigne * Copyright (C) 2005-2011 Regis Houssin * Copyright (C) 2005 Lionel Cousteix + * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -23,7 +24,7 @@ /** * \file htdocs/user/fiche.php * \brief Tab of user card - * \version $Id: fiche.php,v 1.275 2011/07/31 23:19:43 eldy Exp $ + * \version $Id: fiche.php,v 1.276 2011/08/19 07:22:17 hregis Exp $ */ require("../main.inc.php"); @@ -34,6 +35,7 @@ require_once(DOL_DOCUMENT_ROOT."/lib/images.lib.php"); require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); if ($conf->ldap->enabled) require_once(DOL_DOCUMENT_ROOT."/lib/ldap.class.php"); if ($conf->adherent->enabled) require_once(DOL_DOCUMENT_ROOT."/adherents/class/adherent.class.php"); +if ($conf->multicompany->enabled) require_once(DOL_DOCUMENT_ROOT."/multicompany/class/actions_multicompany.class.php"); // Define value to know what current user can do on users $canadduser=($user->admin || $user->rights->user->user->creer); @@ -47,6 +49,14 @@ if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $canreadgroup=($user->admin || $user->rights->user->group_advance->read); $caneditgroup=($user->admin || $user->rights->user->group_advance->write); } + +//Multicompany in mode transversal +if($conf->multicompany->enabled && $conf->entity > 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL) +{ + accessforbidden(); +} + + // Define value to know what current user can do on properties of edited user if ($_GET["id"]) { @@ -193,7 +203,7 @@ if ($_POST["action"] == 'add' && $canadduser) $edituser->note = $_POST["note"]; $edituser->ldap_sid = $_POST["ldap_sid"]; // If multicompany is off, admin users must all be on entity 0. - $edituser->entity = ( ! empty($_POST["admin"]) && (! empty($_POST["superadmin"]) || empty($conf->multicompany->enabled)) ? 0 : $_POST["entity"]); + $edituser->entity = (empty($_POST["entity"]) || empty($conf->multicompany->enabled) ? 0 : $_POST["entity"]); $db->begin(); @@ -233,8 +243,8 @@ if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) $edituser = new User($db); $edituser->fetch($_GET["id"]); - if ($action == 'addgroup') $edituser->SetInGroup($group,GETPOST('entity')); - if ($action == 'removegroup') $edituser->RemoveFromGroup($group,GETPOST('entity')); + if ($action == 'addgroup') $edituser->SetInGroup($group,($conf->global->MULTICOMPANY_MODE_TRANVERSAL?$_POST["entity"]:$editgroup->entity)); + if ($action == 'removegroup') $edituser->RemoveFromGroup($group,($conf->global->MULTICOMPANY_MODE_TRANVERSAL?$_GET["entity"]:$editgroup->entity)); if ($result > 0) { @@ -289,7 +299,7 @@ if ($action == 'update' && ! $_POST["cancel"]) $edituser->webcal_login = $_POST["webcal_login"]; $edituser->phenix_login = $_POST["phenix_login"]; $edituser->phenix_pass = $_POST["phenix_pass"]; - $edituser->entity = ( (! empty($_POST["superadmin"]) && ! empty($_POST["admin"])) ? 0 : $_POST["entity"]); + $edituser->entity = ( empty($_POST["entity"]) ? 0 : $_POST["entity"]); if (GETPOST('deletephoto')) $edituser->photo=''; if (! empty($_FILES['photo']['name'])) $edituser->photo = dol_sanitizeFileName($_FILES['photo']['name']); @@ -656,7 +666,7 @@ if (($action == 'create') || ($action == 'adduserldap')) print ''; print $form->selectyesno('admin',$_POST["admin"],1); - if (! empty($conf->multicompany->enabled) && ! $user->entity) + /*if (! empty($conf->multicompany->enabled) && ! $user->entity) { if ($conf->use_javascript_ajax) { @@ -678,9 +688,25 @@ if (($action == 'create') || ($action == 'adduserldap')) $checked=($_POST["superadmin"]?' checked':''); $disabled=($_POST["superadmin"]?'':' disabled'); print ' '.$langs->trans("SuperAdministrator"); - } + }*/ print "\n"; } + + //Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) + { + $mc = new ActionsMulticompany($db); + print "".''.$langs->trans("Entity").''; + print "".$mc->select_entities($conf->entity); + print "\n"; + } + else + { + print ''; + } + } // Type print ''.$langs->trans("Type").''; @@ -1000,6 +1026,19 @@ else print yn($fuser->admin); } print ''."\n"; + + // Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0) + { + $mc = new ActionsMulticompany($db); + $mc->getInfo($fuser->entity); + print "".''.$langs->trans("Entity").''; + print ''.$mc->label; + print "\n"; + } + } // Type print ''.$langs->trans("Type").''; @@ -1146,8 +1185,7 @@ else print '
'; - if ($caneditfield && - (empty($conf->multicompany->enabled) || (($fuser->entity == $conf->entity) || $fuser->entity == $user->entity)) ) + if ($caneditfield && (empty($conf->multicompany->enabled) || (($fuser->entity == $conf->entity) || $fuser->entity == $user->entity) || $conf->entity==0) ) { if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) { @@ -1159,7 +1197,7 @@ else } } elseif ($caneditpassword && ! $fuser->ldap_sid && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity)) ) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0) ) { print ''.$langs->trans("EditPassword").''; } @@ -1168,13 +1206,13 @@ else if ($conf->global->USER_PASSWORD_GENERATED != 'none') { if (($user->id != $_GET["id"] && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity))) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0)) { print ''.$langs->trans("ReinitPassword").''; } if (($user->id != $_GET["id"] && $caneditpassword) && $fuser->login && !$fuser->ldap_sid && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity)) ) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0) ) { if ($fuser->email) print ''.$langs->trans("SendNewPassword").''; else print ''.$langs->trans("SendNewPassword").''; @@ -1183,19 +1221,19 @@ else // Activer if ($user->id <> $_GET["id"] && $candisableuser && $fuser->statut == 0 && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity)) ) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0) ) { print ''.$langs->trans("Reactivate").''; } // Desactiver if ($user->id <> $_GET["id"] && $candisableuser && $fuser->statut == 1 && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity)) ) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0) ) { print ''.$langs->trans("DisableUser").''; } // Delete if ($user->id <> $_GET["id"] && $candisableuser && - (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity)) ) + (empty($conf->multicompany->enabled) || ($fuser->entity == $conf->entity) || $conf->entity==0) ) { print ''.$langs->trans("DeleteUser").''; } @@ -1221,9 +1259,12 @@ else if (! empty($groupslist)) { - foreach($groupslist as $groupforuser) + if( !($conf->multicompany->enabled && $conf->global->MULTICOMPANY_MODE_TRANVERSAL)) { - $exclude[]=$groupforuser->id; + foreach($groupslist as $groupforuser) + { + $exclude[]=$groupforuser->id; + } } } @@ -1233,12 +1274,27 @@ else print '
'."\n"; print ''; print ''; - print ''; print ''."\n"; print ''."\n"; print ''; + print "'."\n"; print '
'.$langs->trans("GroupsToAdd").''; print $form->select_dolgroups('','group',1,$exclude); print '   '; + // Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL) + { + $mc = new ActionsMulticompany($db); + print ''.$langs->trans("Entity").'".$mc->select_entities($conf->entity); + } + else + { + print ''; + } + } + else + print ''; print ''; print '
'."\n"; @@ -1252,6 +1308,8 @@ else print ''; print ''; print ''; + if($conf->multicompany->enabled && $conf->entity==0) + print ''; print "\n"; if (! empty($groupslist)) @@ -1273,6 +1331,12 @@ else print img_object($langs->trans("ShowGroup"),"group").' '.$group->nom; } print ''; + if($conf->multicompany->enabled && $conf->entity==0) + { + $mc = new ActionsMulticompany($db); + $mc->getInfo($group->usergroup_entity); + print '"; + } print ''; + print ''; // Firstname @@ -1423,7 +1489,7 @@ else { print $form->selectyesno('admin',$fuser->admin,1); - if (! empty($conf->multicompany->enabled) && ! $user->entity) + /*if (! empty($conf->multicompany->enabled) && ! $user->entity) { if ($conf->use_javascript_ajax) { @@ -1451,18 +1517,35 @@ else $checked=(($fuser->admin && ! $fuser->entity) ? ' checked' : ''); print ' '.$langs->trans("SuperAdministrator"); - } + }*/ } else { $yn = yn($fuser->admin); print ''; - if (! empty($conf->multicompany->enabled) && ! $fuser->entity) print $html->textwithpicto($yn,$langs->trans("DontDowngradeSuperAdmin"),1,'warning'); - else print $yn; + //if (! empty($conf->multicompany->enabled) && ! $fuser->entity) print $html->textwithpicto($yn,$langs->trans("DontDowngradeSuperAdmin"),1,'warning'); + //else print $yn; } print ''; } + //Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) + { + $mc = new ActionsMulticompany($db); + print "".''; + print "\n"; + } + else + { + print ''; + } + } + else + { // Type print ''; print ''; - + } // Tel pro print "".''; print '
'.$langs->trans("Groups").''.$langs->trans("Entity").' 
'.$mc->label."'; if ($caneditgroup) @@ -1312,6 +1376,7 @@ else print ''; $rowspan=12; + if ($conf->societe->enabled) $rowspan++; if ($conf->adherent->enabled) $rowspan++; if ($conf->webcalendar->enabled) $rowspan++; @@ -1350,6 +1415,7 @@ else print '
'; } print '
'.$langs->trans("Entity").'".$mc->select_entities($fuser->entity); + print "
'.$langs->trans("Type").''; @@ -1479,7 +1562,7 @@ else print $langs->trans("Internal"); } print '
'.$langs->trans("PhonePro").''; @@ -1659,7 +1742,7 @@ else $db->close(); -llxFooter('$Date: 2011/07/31 23:19:43 $ - $Revision: 1.275 $'); +llxFooter('$Date: 2011/08/19 07:22:17 $ - $Revision: 1.276 $'); diff --git a/htdocs/user/group/fiche.php b/htdocs/user/group/fiche.php index 60cec3b409d..ec628b0fe4a 100644 --- a/htdocs/user/group/fiche.php +++ b/htdocs/user/group/fiche.php @@ -2,6 +2,7 @@ /* Copyright (C) 2005 Rodolphe Quiedeville * Copyright (C) 2005-2010 Laurent Destailleur * Copyright (C) 2005-2011 Regis Houssin + * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -20,12 +21,13 @@ /** * \file htdocs/user/group/fiche.php * \brief Onglet groupes utilisateurs - * \version $Id: fiche.php,v 1.70 2011/08/17 15:56:24 eldy Exp $ + * \version $Id: fiche.php,v 1.71 2011/08/19 07:22:18 hregis Exp $ */ require("../../main.inc.php"); require_once(DOL_DOCUMENT_ROOT."/user/class/usergroup.class.php"); require_once(DOL_DOCUMENT_ROOT."/lib/usergroups.lib.php"); +if($conf->multicompany->enabled) require_once(DOL_DOCUMENT_ROOT."/multicompany/class/actions_multicompany.class.php"); // Defini si peux lire/modifier utilisateurs et permisssions $canreadperms=($user->admin || $user->rights->user->user->lire); @@ -45,6 +47,11 @@ $langs->load("other"); // Security check $result = restrictedArea($user, 'user', $_GET["id"], 'usergroup', 'user'); +if($conf->multicompany->enabled && $conf->entity > 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL) +{ + accessforbidden(); +} + $action=GETPOST("action"); $confirm=GETPOST("confirm"); $userid=GETPOST("user","int"); @@ -84,11 +91,11 @@ if ($_POST["action"] == 'add') $action="create"; // Go back to create page } - if (! $message) - { - $object->nom = trim($_POST["nom"]); - $object->globalgroup = $_POST["globalgroup"]; - $object->note = trim($_POST["note"]); + if (! $message) + { + $object->nom = trim($_POST["nom"]); + $object->entity = $_POST["entity"]; + $object->note = trim($_POST["note"]); $db->begin(); @@ -127,10 +134,10 @@ if ($action == 'adduser' || $action =='removeuser') $object->fetch($_GET["id"]); $object->oldcopy=dol_clone($object); - $edituser = new User($db); - $edituser->fetch($userid); - if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,GETPOST('entity')); - if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,GETPOST('entity')); + $edituser = new User($db); + $edituser->fetch($userid); + if ($action == 'adduser') $result=$edituser->SetInGroup($object->id,($conf->global->MULTICOMPANY_MODE_TRANVERSAL?$_POST["entity"]:$object->entity)); + if ($action == 'removeuser') $result=$edituser->RemoveFromGroup($object->id,($conf->global->MULTICOMPANY_MODE_TRANVERSAL?$_GET["entity"]:$object->entity)); if ($result > 0) { @@ -162,9 +169,9 @@ if ($_POST["action"] == 'update') $object->oldcopy=dol_clone($object); - $object->nom = trim($_POST["group"]); - $object->globalgroup = $_POST["globalgroup"]; - $object->note = dol_htmlcleanlastbr($_POST["note"]); + $object->nom = trim($_POST["group"]); + $object->entity = $_POST["entity"]; + $object->note = dol_htmlcleanlastbr($_POST["note"]); $ret=$object->update(); @@ -208,23 +215,24 @@ if ($action == 'create') print ''; - print "".''; - print ''; - - // Global group - if ($conf->multicompany->enabled) - { - if ($conf->entity == 1) - { - print "".''; - $checked=(empty($_POST['globalgroup']) ? '' : ' checked'); - print ''; - } - else - { - print ''; - } - } + print "".''; + print ''; + + // Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) + { + $mc = new ActionsMulticompany($db); + print "".''; + print "\n"; + } + else + { + print ''; + } + } print "".''; + print ''; + print "\n"; + print "
'.$langs->trans("Name").'
'.$langs->trans("GlobalGroup").'
'.$langs->trans("Name").'
'.$langs->trans("Entity").'".$mc->select_entities($conf->entity); + print "
'.$langs->trans("Note").''; if ($conf->fckeditor->enabled && $conf->global->FCKEDITOR_ENABLE_USER) @@ -264,64 +272,77 @@ else $title = $langs->trans("Group"); dol_fiche_head($head, 'group', $title, 0, 'group'); - /* - * Confirmation suppression - */ - if ($action == 'delete') - { - $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAGroup"),$langs->trans("ConfirmDeleteGroup",$object->name),"confirm_delete", '',0,1); - if ($ret == 'html') print '
'; - } + /* + * Confirmation suppression + */ + if ($action == 'delete') + { + $ret=$form->form_confirm($_SERVER['PHP_SELF']."?id=".$object->id,$langs->trans("DeleteAGroup"),$langs->trans("ConfirmDeleteGroup",$object->name),"confirm_delete", '',0,1); + if ($ret == 'html') print '
'; + } - /* - * Fiche en mode visu - */ + /* + * Fiche en mode visu + */ - if ($action != 'edit') - { - print ''; + if ($action != 'edit') + { + print '
'; - // Ref - print ''; - print ''; - print ''; + // Ref + print ''; + print ''; + print ''; - // Name - print ''; - print '\n"; + // Name + print ''; + print '\n"; + + // Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0) + { + $mc = new ActionsMulticompany($db); + $mc->getInfo($object->entity); + print "".''; + print '\n"; + } + } - // Note - print ''; - print ''; - print "\n"; - print "
'.$langs->trans("Ref").''; - print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin); - print '
'.$langs->trans("Ref").''; + print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin); + print '
'.$langs->trans("Name").''.$object->nom; - if (empty($object->entity)) - { - print img_picto($langs->trans("GlobalGroup"),'redstar'); - } - print "
'.$langs->trans("Name").''.$object->nom; + if (empty($object->entity)) + { + print img_redstar($langs->trans("GlobalGroup")); + } + print "
'.$langs->trans("Entity").''.$mc->label; + print "
'.$langs->trans("Note").''.dol_htmlentitiesbr($object->note).' 
\n"; + // Note + print '
'.$langs->trans("Note").''.dol_htmlentitiesbr($object->note).' 
\n"; - print ''; + print ''; - /* - * Barre d'actions - */ - print '
'; + /* + * Barre d'actions + */ + print '
'; - if ($caneditperms) - { - print ''.$langs->trans("Modify").''; - } + if ($caneditperms) + { + print ''.$langs->trans("Modify").''; + } - if ($candisableperms) - { - print ''.$langs->trans("DeleteGroup").''; - } + if ($candisableperms) + { + print ''.$langs->trans("DeleteGroup").''; + } - print "
\n"; - print "
\n"; + print "
\n"; + print "
\n"; dol_htmloutput_errors($message); @@ -336,12 +357,15 @@ else $exclude = array(); $userslist = $object->listUsersForGroup(); - + if (! empty($userslist)) { - foreach($userslist as $useringroup) + if( !($conf->multicompany->enabled && $conf->global->MULTICOMPANY_MODE_TRANVERSAL)) { - $exclude[]=$useringroup->id; + foreach($userslist as $useringroup) + { + $exclude[]=$useringroup->id; + } } } @@ -350,12 +374,27 @@ else print '
'."\n"; print ''; print ''; - print ''; print ''."\n"; print ''."\n"; print ''; + print "'."\n"; print '
'.$langs->trans("NonAffectedUsers").''; print $form->select_users('','user',1,$exclude); print '   '; + // Multicompany + if ($conf->multicompany->enabled) + { + if ($conf->entity == 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL) + { + $mc = new ActionsMulticompany($db); + print ''.$langs->trans("Entity").'".$mc->select_entities($conf->entity); + } + else + { + print ''; + } + } + else + print ''; print ''; print '
'."\n"; @@ -368,6 +407,8 @@ else print ''; print ''; print ''; + if($conf->multicompany->enabled && $conf->entity==0) + print ''; print ''; print ''; print ''; @@ -377,34 +418,40 @@ else if (! empty($userslist)) { - $var=True; - - foreach($userslist as $useringroup) - { - $var=!$var; - - print ""; - print ''; - print ''; - print ''; - print ''; - print ''; - print '\n"; - } + $var=True; + + foreach($userslist as $useringroup) + { + $var=!$var; + + print ""; + print ''; + if($conf->multicompany->enabled && $conf->entity==0) + { + $mc = new ActionsMulticompany($db); + $mc->getInfo($useringroup->usergroup_entity); + print '"; + } + print ''; + print ''; + print ''; + print ''; + print '\n"; + } } else { @@ -427,21 +474,21 @@ else print ''; print '\n"; - - // Global group + + // Multicompany if ($conf->multicompany->enabled) { - if ($conf->entity == 1) + if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL) { - print "".''; - $checked=(empty($object->entity) ? ' checked' : ''); - print ''; - } - else - { - $value=(empty($object->entity) ? 1 : 0); - print ''; + $mc = new ActionsMulticompany($db); + print "".''; + print "\n"; } + else + { + print ''; + } } print ''; @@ -473,5 +520,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/17 15:56:24 $ - $Revision: 1.70 $'); +llxFooter('$Date: 2011/08/19 07:22:18 $ - $Revision: 1.71 $'); ?> diff --git a/htdocs/user/group/index.php b/htdocs/user/group/index.php index 2c6ccbd1606..55e4a9bbea7 100644 --- a/htdocs/user/group/index.php +++ b/htdocs/user/group/index.php @@ -2,6 +2,7 @@ /* Copyright (C) 2002-2003 Rodolphe Quiedeville * Copyright (C) 2004-2011 Laurent Destailleur * Copyright (C) 2005-2010 Regis Houssin + * Copyright (C) 2011 Herve Prot * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -21,7 +22,7 @@ * \file htdocs/user/group/index.php * \ingroup core * \brief Page of user groups - * \version $Id: index.php,v 1.25 2011/08/17 15:56:24 eldy Exp $ + * \version $Id: index.php,v 1.26 2011/08/19 07:22:18 hregis Exp $ */ require("../../main.inc.php"); @@ -58,7 +59,10 @@ print_fiche_titre($langs->trans("ListOfGroups")); $sql = "SELECT g.rowid, g.nom, g.entity, g.datec, COUNT(ugu.rowid) 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"; -$sql.= " WHERE g.entity IN (0,".$conf->entity.")"; +if($conf->entity==0) + $sql.= " WHERE g.entity IS NOT NULL"; +else + $sql.= " WHERE g.entity IN (0,".$conf->entity.")"; if ($_POST["search_group"]) { $sql .= " AND (g.nom like '%".$_POST["search_group"]."%' OR g.note like '%".$_POST["search_group"]."%')"; @@ -77,6 +81,9 @@ if ($resql) print "
'.$langs->trans("Login").''.$langs->trans("Entity").''.$langs->trans("Lastname").''.$langs->trans("Firstname").''.$langs->trans("Status").'
'; - print ''.img_object($langs->trans("ShowUser"),"user").' '.$useringroup->login.''; - if ($useringroup->admin && ! $useringroup->entity) print img_picto($langs->trans("SuperAdministrator"),'redstar'); - else if ($useringroup->admin) print img_picto($langs->trans("Administrator"),'star'); - print ''.ucfirst(stripslashes($useringroup->lastname)).''.ucfirst(stripslashes($useringroup->firstname)).''.$useringroup->getLibStatut(5).' '; - if ($user->admin) - { - print ''; - print img_delete($langs->trans("RemoveFromGroup")); - } - else - { - print "-"; - } - print "
'; + print ''.img_object($langs->trans("ShowUser"),"user").' '.$useringroup->login.''; + if ($useringroup->admin && ! $useringroup->entity) print img_redstar($langs->trans("SuperAdministrator")); + else if ($useringroup->admin) print img_picto($langs->trans("Administrator"),'star'); + print ''.$mc->label."'.ucfirst(stripslashes($useringroup->lastname)).''.ucfirst(stripslashes($useringroup->firstname)).''.$useringroup->getLibStatut(5).' '; + if ($user->admin) + { + print ''; + print img_delete($langs->trans("RemoveFromGroup")); + } + else + { + print "-"; + } + print "
'.$langs->trans("Name").''; print "
'.$langs->trans("GlobalGroup").'
'.$langs->trans("Entity").'".$mc->select_entities($object->entity); + print "
'.$langs->trans("Note").'
"; print ''; print_liste_field_titre($langs->trans("Group"),$_SERVER["PHP_SELF"],"g.nom",$param,"","",$sortfield,$sortorder); + //multicompany + if($conf->multicompany->enabled && $conf->entity==0) + print_liste_field_titre($langs->trans("Entity"),$_SERVER["PHP_SELF"],"g.entity",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("NbOfUsers"),$_SERVER["PHP_SELF"],"g.nb",$param,"",'align="center"',$sortfield,$sortorder); print_liste_field_titre($langs->trans("DateCreation"),$_SERVER["PHP_SELF"],"g.datec",$param,"",'align="right"',$sortfield,$sortorder); print "\n"; @@ -93,6 +100,14 @@ if ($resql) print img_picto($langs->trans("GlobalGroup"),'redstar'); } print ""; + //multicompany + if($conf->multicompany->enabled && $conf->entity==0) + { + require_once(DOL_DOCUMENT_ROOT."/multicompany/class/actions_multicompany.class.php"); + $mc = new ActionsMulticompany($db); + $mc->getInfo($obj->entity); + print ''; + } print ''; print ''; print "\n"; @@ -108,6 +123,6 @@ else $db->close(); -llxFooter('$Date: 2011/08/17 15:56:24 $ - $Revision: 1.25 $'); +llxFooter('$Date: 2011/08/19 07:22:18 $ - $Revision: 1.26 $'); ?> diff --git a/htdocs/user/index.php b/htdocs/user/index.php index f13127df380..e9e315b4540 100644 --- a/htdocs/user/index.php +++ b/htdocs/user/index.php @@ -21,10 +21,12 @@ * \file htdocs/user/index.php * \ingroup core * \brief Page of users - * \version $Id: index.php,v 1.52 2011/08/17 15:56:25 eldy Exp $ + * \version $Id: index.php,v 1.53 2011/08/19 07:22:17 hregis Exp $ */ require("../main.inc.php"); +if($conf->multicompany->enabled) dol_include_once("/multicompany/class/actions_multicompany.class.php"); + if (! $user->rights->user->user->lire && ! $user->admin) accessforbidden(); @@ -67,7 +69,10 @@ $sql.= " u.ldap_sid, u.statut, u.entity,"; $sql.= " s.nom, s.canvas"; $sql.= " FROM ".MAIN_DB_PREFIX."user as u"; $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_societe = s.rowid"; -$sql.= " WHERE u.entity IN (0,".$conf->entity.")"; +if($conf->entity==0) + $sql.= " WHERE u.entity IS NOT NULL"; +else + $sql.= " WHERE u.entity IN (0,".$conf->entity.")"; if (!empty($socid)) $sql.= " AND u.fk_societe = ".$socid; if ($_POST["search_user"]) { @@ -120,11 +125,18 @@ if ($result) $companystatic->canvas=$obj->canvas; print $companystatic->getNomUrl(1); } + else if ($conf->multicompany->enabled) + { + $mc = new ActionsMulticompany($db); + $mc->getInfo($obj->entity); + print $mc->label; + } else if ($obj->ldap_sid) { print $langs->trans("DomainUser"); } - else print $langs->trans("InternalUser"); + else + print $langs->trans("InternalUser"); print ''; // Date creation @@ -149,5 +161,5 @@ else $db->close(); -llxFooter('$Date: 2011/08/17 15:56:25 $ - $Revision: 1.52 $'); +llxFooter('$Date: 2011/08/19 07:22:17 $ - $Revision: 1.53 $'); ?>
'.$mc->label.''.$obj->nb.''.dol_print_date($db->jdate($obj->datec),"dayhour").'