multi-company module enhancement

This commit is contained in:
Regis Houssin 2011-08-19 07:22:17 +00:00
parent bed67a87bb
commit 14e0db6602
8 changed files with 370 additions and 182 deletions

View File

@ -11,6 +11,7 @@
* Copyright (C) 2007 Patrick Raguin <patrick.raguin@gmail.com>
* Copyright (C) 2010 Juanjo Menent <jmenent@2byte.es>
* Copyright (C) 2010 Philippe Grand <philippe.grand@atoo-net.com>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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.= '</option>';
$i++;

View File

@ -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);
}
}

View File

@ -6,6 +6,7 @@
* Copyright (C) 2004 Benoit Mortier <benoit.mortier@opensides.be>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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)
{

View File

@ -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;

View File

@ -5,6 +5,7 @@
* Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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 '<td>';
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 '<input type="checkbox" name="superadmin" value="1"'.$checked.$disabled.' /> '.$langs->trans("SuperAdministrator");
}
}*/
print "</td></tr>\n";
}
//Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
$mc = new ActionsMulticompany($db);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
// Type
print '<tr><td valign="top">'.$langs->trans("Type").'</td>';
@ -1000,6 +1026,19 @@ else
print yn($fuser->admin);
}
print '</td></tr>'."\n";
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0)
{
$mc = new ActionsMulticompany($db);
$mc->getInfo($fuser->entity);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print '<td width="75%" class="valeur">'.$mc->label;
print "</td></tr>\n";
}
}
// Type
print '<tr><td valign="top">'.$langs->trans("Type").'</td><td>';
@ -1146,8 +1185,7 @@ else
print '<div class="tabsAction">';
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 '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a>';
}
@ -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 '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=password">'.$langs->trans("ReinitPassword").'</a>';
}
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 '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=passwordsend">'.$langs->trans("SendNewPassword").'</a>';
else print '<a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendNewPassword").'</a>';
@ -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 '<a class="butAction" href="fiche.php?id='.$fuser->id.'&amp;action=enable">'.$langs->trans("Reactivate").'</a>';
}
// 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 '<a class="butActionDelete" href="fiche.php?action=disable&amp;id='.$fuser->id.'">'.$langs->trans("DisableUser").'</a>';
}
// 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 '<a class="butActionDelete" href="fiche.php?action=delete&amp;id='.$fuser->id.'">'.$langs->trans("DeleteUser").'</a>';
}
@ -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 '<form action="fiche.php?id='.$_GET["id"].'" method="post">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="addgroup">';
print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '<table class="noborder" width="100%">'."\n";
print '<tr class="liste_titre"><td class="liste_titre" width="25%">'.$langs->trans("GroupsToAdd").'</td>'."\n";
print '<td>';
print $form->select_dolgroups('','group',1,$exclude);
print ' &nbsp; ';
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
$mc = new ActionsMulticompany($db);
print '</td><td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
else
print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
print '</td></tr>'."\n";
print '</table></form>'."\n";
@ -1252,6 +1308,8 @@ else
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td class="liste_titre" width="25%">'.$langs->trans("Groups").'</td>';
if($conf->multicompany->enabled && $conf->entity==0)
print '<td class="liste_titre" width="25%">'.$langs->trans("Entity").'</td>';
print "<td>&nbsp;</td></tr>\n";
if (! empty($groupslist))
@ -1273,6 +1331,12 @@ else
print img_object($langs->trans("ShowGroup"),"group").' '.$group->nom;
}
print '</td>';
if($conf->multicompany->enabled && $conf->entity==0)
{
$mc = new ActionsMulticompany($db);
$mc->getInfo($group->usergroup_entity);
print '<td class="valeur">'.$mc->label."</td>";
}
print '<td align="right">';
if ($caneditgroup)
@ -1312,6 +1376,7 @@ else
print '<table width="100%" class="border">';
$rowspan=12;
if ($conf->societe->enabled) $rowspan++;
if ($conf->adherent->enabled) $rowspan++;
if ($conf->webcalendar->enabled) $rowspan++;
@ -1350,6 +1415,7 @@ else
print '</table>';
}
print '</td>';
print '</tr>';
// 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 '<input type="checkbox" name="superadmin" value="1"'.$checked.' /> '.$langs->trans("SuperAdministrator");
}
}*/
}
else
{
$yn = yn($fuser->admin);
print '<input type="hidden" name="admin" value="'.$fuser->admin.'">';
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 '</td></tr>';
}
//Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
$mc = new ActionsMulticompany($db);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($fuser->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
else
{
// Type
print '<tr><td width="25%" valign="top">'.$langs->trans("Type").'</td>';
print '<td>';
@ -1479,7 +1562,7 @@ else
print $langs->trans("Internal");
}
print '</td></tr>';
}
// Tel pro
print "<tr>".'<td valign="top">'.$langs->trans("PhonePro").'</td>';
print '<td>';
@ -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 $');

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2005-2010 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2011 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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 '<table class="border" width="100%">';
print "<tr>".'<td valign="top" class="fieldrequired">'.$langs->trans("Name").'</td>';
print '<td class="valeur"><input size="30" type="text" name="nom" value=""></td></tr>';
// Global group
if ($conf->multicompany->enabled)
{
if ($conf->entity == 1)
{
print "<tr>".'<td valign="top">'.$langs->trans("GlobalGroup").'</td>';
$checked=(empty($_POST['globalgroup']) ? '' : ' checked');
print '<td><input type="checkbox" name="globalgroup" value="1"'.$checked.' /></td>';
}
else
{
print '<input type="hidden" name="globalgroup" value="0" />';
}
}
print "<tr>".'<td valign="top" class="fieldrequired">'.$langs->trans("Name").'</td>';
print '<td class="valeur"><input size="30" type="text" name="nom" value=""></td></tr>';
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
$mc = new ActionsMulticompany($db);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
print "<tr>".'<td valign="top">'.$langs->trans("Note").'</td><td>';
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 '<br>';
}
/*
* 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 '<br>';
}
/*
* Fiche en mode visu
*/
/*
* Fiche en mode visu
*/
if ($action != 'edit')
{
print '<table class="border" width="100%">';
if ($action != 'edit')
{
print '<table class="border" width="100%">';
// Ref
print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
print '<td colspan="2">';
print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin);
print '</td>';
print '</tr>';
// Ref
print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
print '<td colspan="2">';
print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin);
print '</td>';
print '</tr>';
// Name
print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>';
print '<td width="75%" class="valeur">'.$object->nom;
if (empty($object->entity))
{
print img_picto($langs->trans("GlobalGroup"),'redstar');
}
print "</td></tr>\n";
// Name
print '<tr><td width="25%" valign="top">'.$langs->trans("Name").'</td>';
print '<td width="75%" class="valeur">'.$object->nom;
if (empty($object->entity))
{
print img_redstar($langs->trans("GlobalGroup"));
}
print "</td></tr>\n";
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0)
{
$mc = new ActionsMulticompany($db);
$mc->getInfo($object->entity);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print '<td width="75%" class="valeur">'.$mc->label;
print "</td></tr>\n";
}
}
// Note
print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
print '<td class="valeur">'.dol_htmlentitiesbr($object->note).'&nbsp;</td>';
print "</tr>\n";
print "</table>\n";
// Note
print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
print '<td class="valeur">'.dol_htmlentitiesbr($object->note).'&nbsp;</td>';
print "</tr>\n";
print "</table>\n";
print '</div>';
print '</div>';
/*
* Barre d'actions
*/
print '<div class="tabsAction">';
/*
* Barre d'actions
*/
print '<div class="tabsAction">';
if ($caneditperms)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
}
if ($caneditperms)
{
print '<a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a>';
}
if ($candisableperms)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("DeleteGroup").'</a>';
}
if ($candisableperms)
{
print '<a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("DeleteGroup").'</a>';
}
print "</div>\n";
print "<br>\n";
print "</div>\n";
print "<br>\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 '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST">'."\n";
print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
print '<input type="hidden" name="action" value="adduser">';
print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '<table class="noborder" width="100%">'."\n";
print '<tr class="liste_titre"><td class="liste_titre" width="25%">'.$langs->trans("NonAffectedUsers").'</td>'."\n";
print '<td>';
print $form->select_users('','user',1,$exclude);
print ' &nbsp; ';
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 0 && $conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
$mc = new ActionsMulticompany($db);
print '</td><td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($conf->entity);
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
else
print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
print '<input type="submit" class="button" value="'.$langs->trans("Add").'">';
print '</td></tr>'."\n";
print '</table></form>'."\n";
@ -368,6 +407,8 @@ else
print '<table class="noborder" width="100%">';
print '<tr class="liste_titre">';
print '<td class="liste_titre" width="25%">'.$langs->trans("Login").'</td>';
if($conf->multicompany->enabled && $conf->entity==0)
print '<td class="liste_titre" width="25%">'.$langs->trans("Entity").'</td>';
print '<td class="liste_titre" width="25%">'.$langs->trans("Lastname").'</td>';
print '<td class="liste_titre" width="25%">'.$langs->trans("Firstname").'</td>';
print '<td class="liste_titre" align="right">'.$langs->trans("Status").'</td>';
@ -377,34 +418,40 @@ else
if (! empty($userslist))
{
$var=True;
foreach($userslist as $useringroup)
{
$var=!$var;
print "<tr $bc[$var]>";
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$useringroup->id.'">'.img_object($langs->trans("ShowUser"),"user").' '.$useringroup->login.'</a>';
if ($useringroup->admin && ! $useringroup->entity) print img_picto($langs->trans("SuperAdministrator"),'redstar');
else if ($useringroup->admin) print img_picto($langs->trans("Administrator"),'star');
print '</td>';
print '<td>'.ucfirst(stripslashes($useringroup->lastname)).'</td>';
print '<td>'.ucfirst(stripslashes($useringroup->firstname)).'</td>';
print '<td align="right">'.$useringroup->getLibStatut(5).'</td>';
print '<td>&nbsp;</td>';
print '<td align="right">';
if ($user->admin)
{
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'&amp;entity='.$useringroup->usergroup_entity.'">';
print img_delete($langs->trans("RemoveFromGroup"));
}
else
{
print "-";
}
print "</td></tr>\n";
}
$var=True;
foreach($userslist as $useringroup)
{
$var=!$var;
print "<tr $bc[$var]>";
print '<td>';
print '<a href="'.DOL_URL_ROOT.'/user/fiche.php?id='.$useringroup->id.'">'.img_object($langs->trans("ShowUser"),"user").' '.$useringroup->login.'</a>';
if ($useringroup->admin && ! $useringroup->entity) print img_redstar($langs->trans("SuperAdministrator"));
else if ($useringroup->admin) print img_picto($langs->trans("Administrator"),'star');
print '</td>';
if($conf->multicompany->enabled && $conf->entity==0)
{
$mc = new ActionsMulticompany($db);
$mc->getInfo($useringroup->usergroup_entity);
print '<td class="valeur">'.$mc->label."</td>";
}
print '<td>'.ucfirst(stripslashes($useringroup->lastname)).'</td>';
print '<td>'.ucfirst(stripslashes($useringroup->firstname)).'</td>';
print '<td align="right">'.$useringroup->getLibStatut(5).'</td>';
print '<td>&nbsp;</td>';
print '<td align="right">';
if ($user->admin)
{
print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removeuser&amp;user='.$useringroup->id.'&amp;entity='.$useringroup->usergroup_entity.'">';
print img_delete($langs->trans("RemoveFromGroup"));
}
else
{
print "-";
}
print "</td></tr>\n";
}
}
else
{
@ -427,21 +474,21 @@ else
print '<tr><td width="25%" valign="top" class="fieldrequired">'.$langs->trans("Name").'</td>';
print '<td width="75%" class="valeur"><input size="15" type="text" name="group" value="'.$object->nom.'">';
print "</td></tr>\n";
// Global group
// Multicompany
if ($conf->multicompany->enabled)
{
if ($conf->entity == 1)
if ($conf->entity == 0 && !$conf->global->MULTICOMPANY_MODE_TRANVERSAL)
{
print "<tr>".'<td valign="top">'.$langs->trans("GlobalGroup").'</td>';
$checked=(empty($object->entity) ? ' checked' : '');
print '<td><input type="checkbox" name="globalgroup" value="1"'.$checked.' /></td>';
}
else
{
$value=(empty($object->entity) ? 1 : 0);
print '<input type="hidden" name="globalgroup" value="'.$value.'" />';
$mc = new ActionsMulticompany($db);
print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
print "<td>".$mc->select_entities($object->entity);
print "</td></tr>\n";
}
else
{
print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
}
}
print '<tr><td width="25%" valign="top">'.$langs->trans("Note").'</td>';
@ -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 $');
?>

View File

@ -2,6 +2,7 @@
/* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
* Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2005-2010 Regis Houssin <regis@dolibarr.fr>
* Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
*
* 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 "<table class=\"noborder\" width=\"100%\">";
print '<tr class="liste_titre">';
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 "</tr>\n";
@ -93,6 +100,14 @@ if ($resql)
print img_picto($langs->trans("GlobalGroup"),'redstar');
}
print "</td>";
//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 '<td align="center">'.$mc->label.'</td>';
}
print '<td align="center">'.$obj->nb.'</td>';
print '<td align="right" nowrap="nowrap">'.dol_print_date($db->jdate($obj->datec),"dayhour").'</td>';
print "</tr>\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 $');
?>

View File

@ -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 '</td>';
// 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 $');
?>