29 if (!defined(
'CSRFCHECK_WITH_TOKEN')) {
30 define(
'CSRFCHECK_WITH_TOKEN',
'1');
33 require
'../main.inc.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/usergroups.lib.php';
35 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
36 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
39 $langs->loadLangs(array(
'users',
'admin'));
42 $action =
GETPOST(
'action',
'aZ09');
43 $confirm =
GETPOST(
'confirm',
'alpha');
44 $module =
GETPOST(
'module',
'alpha');
45 $rights =
GETPOST(
'rights',
'int');
46 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'userperms';
48 if (!isset($id) || empty($id)) {
53 $canreaduser = ($user->admin || $user->rights->user->user->lire);
55 $caneditperms = ($user->admin || $user->rights->user->user->creer);
57 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
58 $canreaduser = ($user->admin || ($user->rights->user->user->lire && $user->rights->user->user_advance->readperms));
59 $caneditselfperms = ($user->id == $id && $user->rights->user->self_advance->writeperms);
60 $caneditperms = (($caneditperms || $caneditselfperms) ? 1 : 0);
65 if (isset($user->socid) && $user->socid > 0) {
66 $socid = $user->socid;
68 $feature2 = (($socid && $user->rights->user->self->creer) ?
'' :
'user');
70 if ($user->id == $id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->user->self_advance->readperms) && empty($user->admin))) {
74 $result =
restrictedArea($user,
'user', $id,
'user&user', $feature2);
75 if ($user->id <> $id && !$canreaduser) {
79 $object =
new User($db);
80 $object->fetch($id,
'',
'', 1);
83 $entity = $conf->entity;
86 $hookmanager->initHooks(array(
'usercard',
'userperms',
'globalcard'));
93 $parameters = array(
'socid'=>$socid);
94 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
99 if (empty($reshook)) {
100 if ($action ==
'addrights' && $caneditperms && $confirm ==
'yes') {
101 $edituser =
new User($db);
102 $edituser->fetch($object->id);
103 $result = $edituser->addrights($rights, $module,
'', $entity);
109 if ($object->id == $user->id) {
110 $user->clearrights();
112 $menumanager->loadMenu();
115 $object->clearrights();
116 $object->getrights();
119 if ($action ==
'delrights' && $caneditperms && $confirm ==
'yes') {
120 $edituser =
new User($db);
121 $edituser->fetch($object->id);
122 $result = $edituser->delrights($rights, $module,
'', $entity);
128 if ($object->id == $user->id) {
129 $user->clearrights();
131 $menumanager->loadMenu();
134 $object->clearrights();
135 $object->getrights();
146 llxHeader(
'', $langs->trans(
"Permissions"));
150 $title = $langs->trans(
"User");
160 foreach ($modulesdir as $dir) {
162 if (is_resource($handle)) {
163 while (($file = readdir($handle)) !==
false) {
164 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php') {
165 $modName = substr($file, 0,
dol_strlen($file) - 10);
168 include_once $dir.$file;
169 $objMod =
new $modName($db);
172 if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
173 foreach ($objMod->langfiles as $domain) {
174 $langs->load($domain);
178 if ($objMod->rights_class) {
179 $ret = $objMod->insert_permissions(0, $entity);
180 $modules[$objMod->rights_class] = $objMod;
192 $permsuser = array();
194 $sql =
"SELECT DISTINCT ur.fk_id";
195 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur";
196 $sql .=
" WHERE ur.entity = ".((int) $entity);
197 $sql .=
" AND ur.fk_user = ".((int) $object->id);
200 $result = $db->query($sql);
202 $num = $db->num_rows($result);
205 $obj = $db->fetch_object($result);
206 array_push($permsuser, $obj->fk_id);
215 $permsgroupbyentity = array();
217 $sql =
"SELECT DISTINCT gr.fk_id, gu.entity";
218 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as gr,";
219 $sql .=
" ".MAIN_DB_PREFIX.
"usergroup_user as gu";
220 $sql .=
" WHERE gr.entity = ".((int) $entity);
221 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
222 $sql .=
" AND gu.fk_user = ".((int) $object->id);
225 $result = $db->query($sql);
227 $num = $db->num_rows($result);
230 $obj = $db->fetch_object($result);
231 if (!isset($permsgroupbyentity[$obj->entity])) {
232 $permsgroupbyentity[$obj->entity] = array();
234 array_push($permsgroupbyentity[$obj->entity], $obj->fk_id);
249 if ($user->rights->user->user->lire || $user->admin) {
250 $linkback =
'<a href="'.DOL_URL_ROOT.
'/user/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
253 $morehtmlref =
'<a href="'.DOL_URL_ROOT.
'/user/vcard.php?id='.$object->id.
'" class="refid">';
254 $morehtmlref .=
img_picto($langs->trans(
"Download").
' '.$langs->trans(
"VCard"),
'vcard.png',
'class="valignmiddle marginleftonly paddingrightonly"');
255 $morehtmlref .=
'</a>';
257 dol_banner_tab($object,
'id', $linkback, $user->rights->user->user->lire || $user->admin,
'rowid',
'ref', $morehtmlref);
260 print
'<div class="fichecenter">';
262 print
'<div class="underbanner clearboth"></div>';
263 print
'<table class="border centpercent tableforfield">';
266 print
'<tr><td class="titlefield">'.$langs->trans(
"Login").
'</td>';
267 if (!empty($object->ldap_sid) && $object->statut == 0) {
268 print
'<td class="error">';
269 print $langs->trans(
"LoginAccountDisableInDolibarr");
274 if (property_exists($object,
'admin')) {
275 if (!empty($conf->multicompany->enabled) && !empty($object->admin) && empty($object->entity)) {
276 $addadmin .=
img_picto($langs->trans(
"SuperAdministratorDesc"),
"redstar",
'class="paddingleft"');
277 } elseif (!empty($object->admin)) {
278 $addadmin .=
img_picto($langs->trans(
"AdministratorDesc"),
"star",
'class="paddingleft"');
292 print
info_admin($langs->trans(
"WarningOnlyPermissionOfActivatedModules"));
295 if (! empty($object->socid)) {
299 $parameters = array(
'permsgroupbyentity'=>$permsgroupbyentity);
300 $reshook = $hookmanager->executeHooks(
'insertExtraHeader', $parameters, $object, $action);
307 print
'<div class="div-table-responsive-no-min">';
308 print
'<table class="noborder centpercent">';
310 print
'<tr class="liste_titre">';
311 print
'<td>'.$langs->trans(
"Module").
'</td>';
312 if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) {
314 print
'<td class="center nowrap">';
315 print
'<a class="reposition commonlink" title="'.dol_escape_htmltag($langs->trans(
"All")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"All")).
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addrights&token='.
newToken().
'&entity='.$entity.
'&module=allmodules&confirm=yes">'.$langs->trans(
"All").
"</a>";
317 print
'<a class="reposition commonlink" title="'.dol_escape_htmltag($langs->trans(
"None")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"None")).
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delrights&token='.
newToken().
'&entity='.$entity.
'&module=allmodules&confirm=yes">'.$langs->trans(
"None").
"</a>";
320 print
'<td class="center" width="24"> </td>';
322 print
'<td>'.$langs->trans(
"Permissions").
'</td>';
324 print
'<td class="right"></td>';
331 $sql =
"SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
332 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def as r";
333 $sql .=
" WHERE r.libelle NOT LIKE 'tou%'";
334 $sql .=
" AND r.entity = ".((int) $entity);
335 $sql .=
" ORDER BY r.family_position, r.module_position, r.module, r.id";
337 $result = $db->query($sql);
339 $num = $db->num_rows($result);
344 $obj = $db->fetch_object($result);
347 if (!isset($obj->module) || empty($modules[$obj->module])) {
353 if (!empty($conf->reception->enabled)) {
355 if ($obj->module ==
'fournisseur' && $obj->perms ==
'commande' && $obj->subperms ==
'receptionner') {
359 if ($obj->module ==
'fournisseur' && $obj->perms ==
'commande_advance' && $obj->subperms ==
'check') {
365 $objMod = $modules[$obj->module];
368 if (empty($obj->module_position) || (is_object($objMod) && $objMod->isCoreOrExternalModule() ==
'external' && $obj->module_position < 100000)) {
369 if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0)) {
374 $newmoduleposition = $modules[$obj->module]->module_position;
377 $objMod = $modules[$obj->module];
378 if (is_object($objMod) && $objMod->isCoreOrExternalModule() ==
'external' && $newmoduleposition < 100000) {
379 $newmoduleposition += 100000;
382 $sqlupdate =
'UPDATE '.MAIN_DB_PREFIX.
"rights_def SET module_position = ".((int) $newmoduleposition).
",";
383 $sqlupdate .=
" family_position = ".((int) $familyposition);
384 $sqlupdate .=
" WHERE module_position = ".((int) $obj->module_position).
" AND module = '".$db->escape($obj->module).
"'";
386 $db->query($sqlupdate);
395 $sql =
"SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
396 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def as r";
397 $sql .=
" WHERE r.libelle NOT LIKE 'tou%'";
398 $sql .=
" AND r.entity = ".((int) $entity);
399 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
400 $sql .=
" AND r.perms NOT LIKE '%_advance'";
402 $sql .=
" ORDER BY r.family_position, r.module_position, r.module, r.id";
404 $result = $db->query($sql);
406 $num = $db->num_rows($result);
411 $obj = $db->fetch_object($result);
414 if (empty($modules[$obj->module])) {
420 if (!empty($conf->reception->enabled)) {
422 if ($obj->module ==
'fournisseur' && $obj->perms ==
'commande' && $obj->subperms ==
'receptionner') {
426 if ($obj->module ==
'fournisseur' && $obj->perms ==
'commande_advance' && $obj->subperms ==
'check') {
432 $objMod = $modules[$obj->module];
460 if (isset($obj->module) && ($oldmod <> $obj->module)) {
461 $oldmod = $obj->module;
464 $objMod = $modules[$obj->module];
465 $picto = ($objMod->picto ? $objMod->picto :
'generic');
468 print
'<tr class="oddeven trforbreak">';
469 print
'<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
470 print
img_object(
'', $picto,
'class="pictoobjectwidth paddingright"').
' '.$objMod->getName();
471 print
'<a name="'.$objMod->getName().
'"></a>';
473 if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin)) {
475 print
'<td class="center nowrap">';
476 print
'<a class="reposition" title="'.dol_escape_htmltag($langs->trans(
"All")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"All")).
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addrights&token='.
newToken().
'&entity='.$entity.
'&module='.$obj->module.
'&confirm=yes">'.$langs->trans(
"All").
"</a>";
478 print
'<a class="reposition" title="'.dol_escape_htmltag($langs->trans(
"None")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"None")).
'" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delrights&token='.
newToken().
'&entity='.$entity.
'&module='.$obj->module.
'&confirm=yes">'.$langs->trans(
"None").
"</a>";
481 print
'<td> </td>';
484 print
'<td> </td>';
486 print
'<td> </td>';
488 print
'<td> </td>';
492 print
'<td class="right"></td>';
498 print
'<!-- '.$obj->module.
'->'.$obj->perms.($obj->subperms ?
'->'.$obj->subperms :
'').
' -->'.
"\n";
499 print
'<tr class="oddeven">';
502 print
'<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
507 if (!empty($object->admin) && !empty($objMod->rights_admin_allowed)) {
509 print
'<td class="center">'.img_picto($langs->trans(
"Administrator"),
'star').
'</td>';
511 print
'<td class="center nowrap">';
512 print
img_picto($langs->trans(
"Active"),
'tick');
514 } elseif (in_array($obj->id, $permsuser)) {
516 print
'<td class="center"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delrights&token='.
newToken().
'&entity='.$entity.
'&rights='.$obj->id.
'&confirm=yes">';
518 print
img_picto($langs->trans(
"Remove"),
'switch_on');
521 print
'<td class="center nowrap">';
522 print
img_picto($langs->trans(
"Active"),
'tick');
524 } elseif (isset($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
525 if (in_array($obj->id, $permsgroupbyentity[$entity])) {
527 print
'<td class="center">';
528 print
$form->textwithtooltip($langs->trans(
"Inherited"), $langs->trans(
"PermissionInheritedFromAGroup"));
531 print
'<td class="center nowrap">';
532 print
img_picto($langs->trans(
"Active"),
'tick');
537 print
'<td class="center"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addrights&entity='.$entity.
'&rights='.$obj->id.
'&confirm=yes&token='.
newToken().
'">';
539 print
img_picto($langs->trans(
"Add"),
'switch_off');
542 print
'<td> </td>';
547 print
'<td class="center"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addrights&entity='.$entity.
'&rights='.$obj->id.
'&confirm=yes&token='.
newToken().
'">';
549 print
img_picto($langs->trans(
"Add"),
'switch_off');
552 print
'<td> </td>';
556 $permlabel = (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && ($langs->trans(
"PermissionAdvanced".$obj->id) != (
"PermissionAdvanced".$obj->id)) ? $langs->trans(
"PermissionAdvanced".$obj->id) : (($langs->trans(
"Permission".$obj->id) != (
"Permission".$obj->id)) ? $langs->trans(
"Permission".$obj->id) : $langs->trans($obj->label)));
559 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
560 if (preg_match(
'/_advance$/', $obj->perms)) {
561 print
' <span class="opacitymedium">('.$langs->trans(
"AdvancedModeOnly").
')</span>';
568 print
'<td class="right">';
569 $htmltext = $langs->trans(
"ID").
': '.$obj->id;
570 $htmltext .=
'<br>'.$langs->trans(
"Permission").
': user->rights->'.$obj->module.
'->'.$obj->perms.($obj->subperms ?
'->'.$obj->subperms :
'');
571 print
$form->textwithpicto(
'', $htmltext);
586 $parameters = array();
587 $reshook = $hookmanager->executeHooks(
'insertExtraFooter', $parameters, $object, $action);
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow= '')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
dolGetModulesDirs($subdir= '')
Return list of modules directories.
Class to manage Dolibarr users.
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOCSRFCHECK')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
showModulesExludedForExternal($modules)
Show array with constants to edit.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
user_prepare_head(User $object)
Prepare array with list of tabs.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= 'hideonsmartphone', $textfordropdown= '')
Show information for admin users or standard users.
dol_strlen($string, $stringencoding= 'UTF-8')
Make a strlen call.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename= '', $restricttologhandler= '', $logcontext=null)
Write log message into outputs.
img_object($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
accessforbidden($message= '', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
dol_banner_tab($object, $paramid, $morehtml= '', $shownav=1, $fieldid= 'rowid', $fieldref= 'ref', $morehtmlref= '', $moreparam= '', $nodbprefix=0, $morehtmlleft= '', $morehtmlstatus= '', $onlybanner=0, $morehtmlright= '')
Show tab footer of a card.