29 if (!defined(
'CSRFCHECK_WITH_TOKEN')) define(
'CSRFCHECK_WITH_TOKEN',
'1');
31 require
'../main.inc.php';
32 require_once DOL_DOCUMENT_ROOT.
'/core/lib/usergroups.lib.php';
33 require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
34 require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
37 $langs->loadLangs(array(
'users',
'admin'));
40 $action =
GETPOST(
'action',
'aZ09');
41 $confirm =
GETPOST(
'confirm',
'alpha');
42 $module =
GETPOST(
'module',
'alpha');
43 $rights =
GETPOST(
'rights',
'int');
44 $contextpage =
GETPOST(
'contextpage',
'aZ') ?
GETPOST(
'contextpage',
'aZ') :
'userperms';
49 $canreaduser = ($user->admin || $user->rights->user->user->lire);
51 $caneditperms = ($user->admin || $user->rights->user->user->creer);
53 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS))
55 $canreaduser = ($user->admin || ($user->rights->user->user->lire && $user->rights->user->user_advance->readperms));
56 $caneditselfperms = ($user->id == $id && $user->rights->user->self_advance->writeperms);
57 $caneditperms = (($caneditperms || $caneditselfperms) ? 1 : 0);
62 if (isset($user->socid) && $user->socid > 0) $socid = $user->socid;
63 $feature2 = (($socid && $user->rights->user->self->creer) ?
'' :
'user');
65 if ($user->id == $id && (!empty($conf->global->MAIN_USE_ADVANCED_PERMS) && empty($user->rights->user->self_advance->readperms) && empty($user->admin)))
70 $result =
restrictedArea($user,
'user', $id,
'user&user', $feature2);
73 $object =
new User($db);
74 $object->fetch($id,
'',
'', 1);
77 $entity = $conf->entity;
80 $hookmanager->initHooks(array(
'usercard',
'userperms',
'globalcard'));
87 $parameters = array(
'id'=>$socid);
88 $reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action);
89 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
91 if (empty($reshook)) {
92 if ($action ==
'addrights' && $caneditperms && $confirm ==
'yes') {
93 $edituser =
new User($db);
94 $edituser->fetch($object->id);
95 $result = $edituser->addrights($rights, $module,
'', $entity);
102 if ($object->id == $user->id) {
103 $user->clearrights();
108 $object->clearrights();
109 $object->getrights();
112 if ($action ==
'delrights' && $caneditperms && $confirm ==
'yes') {
113 $edituser =
new User($db);
114 $edituser->fetch($object->id);
115 $result = $edituser->delrights($rights, $module,
'', $entity);
122 if ($object->id == $user->id) {
123 $user->clearrights();
128 $object->clearrights();
129 $object->getrights();
138 $form =
new Form($db);
140 llxHeader(
'', $langs->trans(
"Permissions"));
144 $title = $langs->trans(
"User");
154 foreach ($modulesdir as $dir)
157 if (is_resource($handle))
159 while (($file = readdir($handle)) !==
false)
161 if (is_readable($dir.$file) && substr($file, 0, 3) ==
'mod' && substr($file,
dol_strlen($file) - 10) ==
'.class.php')
163 $modName = substr($file, 0,
dol_strlen($file) - 10);
167 include_once $dir.$file;
168 $objMod =
new $modName($db);
171 if (isset($objMod->langfiles) && is_array($objMod->langfiles))
173 foreach ($objMod->langfiles as $domain)
175 $langs->load($domain);
179 if ($objMod->rights_class)
181 $ret = $objMod->insert_permissions(0, $entity);
182 $modules[$objMod->rights_class] = $objMod;
194 $permsuser = array();
196 $sql =
"SELECT DISTINCT ur.fk_id";
197 $sql .=
" FROM ".MAIN_DB_PREFIX.
"user_rights as ur";
198 $sql .=
" WHERE ur.entity = ".$entity;
199 $sql .=
" AND ur.fk_user = ".$object->id;
202 $result = $db->query($sql);
205 $num = $db->num_rows($result);
209 $obj = $db->fetch_object($result);
210 array_push($permsuser, $obj->fk_id);
219 $permsgroupbyentity = array();
221 $sql =
"SELECT DISTINCT gr.fk_id, gu.entity";
222 $sql .=
" FROM ".MAIN_DB_PREFIX.
"usergroup_rights as gr,";
223 $sql .=
" ".MAIN_DB_PREFIX.
"usergroup_user as gu";
224 $sql .=
" WHERE gr.entity = ".$entity;
225 $sql .=
" AND gr.fk_usergroup = gu.fk_usergroup";
226 $sql .=
" AND gu.fk_user = ".$object->id;
229 $result = $db->query($sql);
232 $num = $db->num_rows($result);
236 $obj = $db->fetch_object($result);
237 if (!isset($permsgroupbyentity[$obj->entity]))
238 $permsgroupbyentity[$obj->entity] = array();
239 array_push($permsgroupbyentity[$obj->entity], $obj->fk_id);
254 if ($user->rights->user->user->lire || $user->admin) {
255 $linkback =
'<a href="'.DOL_URL_ROOT.
'/user/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
258 dol_banner_tab($object,
'id', $linkback, $user->rights->user->user->lire || $user->admin);
261 print '<div class="underbanner clearboth"></div>';
263 if ($user->admin)
print info_admin($langs->trans(
"WarningOnlyPermissionOfActivatedModules"));
267 $parameters = array(
'permsgroupbyentity'=>$permsgroupbyentity);
268 $reshook = $hookmanager->executeHooks(
'insertExtraHeader', $parameters, $object, $action);
269 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
273 print '<div class="div-table-responsive-no-min">';
274 print '<table class="noborder centpercent">';
276 print '<tr class="liste_titre">';
277 print '<td>'.$langs->trans(
"Module").
'</td>';
278 if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin))
282 print '<td class="center nowrap">';
283 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&entity='.$entity.
'&module=allmodules&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"All").
"</a>";
285 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&entity='.$entity.
'&module=allmodules&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"None").
"</a>";
288 print '<td class="center" width="24"> </td>';
290 print '<td>'.$langs->trans(
"Permissions").
'</td>';
291 if ($user->admin)
print '<td class="right">'.$langs->trans(
"ID").
'</td>';
295 $sql =
"SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position";
296 $sql .=
" FROM ".MAIN_DB_PREFIX.
"rights_def as r";
297 $sql .=
" WHERE r.libelle NOT LIKE 'tou%'";
298 $sql .=
" AND r.entity = ".$entity;
299 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) $sql .=
" AND r.perms NOT LIKE '%_advance'";
300 $sql .=
" ORDER BY r.family_position, r.module_position, r.module, r.id";
302 $result = $db->query($sql);
305 $num = $db->num_rows($result);
311 $obj = $db->fetch_object($result);
314 if (empty($modules[$obj->module]))
321 if (empty($obj->module_position))
323 if (is_object($modules[$obj->module]) && ($modules[$obj->module]->module_position > 0))
326 $family = $modules[$obj->module]->family_position;
328 $sqlupdate =
'UPDATE '.MAIN_DB_PREFIX.
"rights_def SET module_position = ".((int) $modules[$obj->module]->module_position).
",";
329 $sqlupdate .=
" family_position = ".((int) $familyposition);
330 $sqlupdate .=
" WHERE module_position = 0 AND module = '".$db->escape($obj->module).
"'";
331 $db->query($sqlupdate);
335 if (isset($obj->module) && ($oldmod <> $obj->module))
337 $oldmod = $obj->module;
340 $objMod = $modules[$obj->module];
341 $picto = ($objMod->picto ? $objMod->picto :
'generic');
344 print '<tr class="oddeven trforbreak">';
345 print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
346 print img_object(
'', $picto,
'class="pictoobjectwidth paddingright"').
' '.$objMod->getName();
347 print '<a name="'.$objMod->getName().
'"></a>';
349 if (($caneditperms && empty($objMod->rights_admin_allowed)) || empty($object->admin))
353 print '<td class="center nowrap">';
354 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&entity='.$entity.
'&module='.$obj->module.
'&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"All").
"</a>";
356 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&entity='.$entity.
'&module='.$obj->module.
'&confirm=yes&token='.
newToken().
'">'.$langs->trans(
"None").
"</a>";
359 print '<td> </td>';
363 print '<td> </td>';
365 print '<td> </td>';
367 print '<td> </td>';
370 if ($user->admin)
print '<td class="right"></td>';
375 print '<!-- '.$obj->module.
'->'.$obj->perms.($obj->subperms ?
'->'.$obj->subperms :
'').
' -->'.
"\n";
376 print '<tr class="oddeven">';
379 print '<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
384 if (!empty($object->admin) && !empty($objMod->rights_admin_allowed))
388 print '<td class="center">'.img_picto($langs->trans(
"Administrator"),
'star').
'</td>';
390 print '<td class="center nowrap">';
393 } elseif (in_array($obj->id, $permsuser))
397 print '<td class="center"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=delrights&entity='.$entity.
'&rights='.$obj->id.
'&confirm=yes&token='.
newToken().
'">';
402 print '<td class="center nowrap">';
405 } elseif (is_array($permsgroupbyentity[$entity]))
407 if (in_array($obj->id, $permsgroupbyentity[$entity]))
411 print '<td class="center">';
412 print $form->textwithtooltip($langs->trans(
"Inherited"), $langs->trans(
"PermissionInheritedFromAGroup"));
415 print '<td class="center nowrap">';
422 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().
'">';
427 print '<td> </td>';
433 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().
'">';
438 print '<td> </td>';
442 $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)));
443 print '<td class="maxwidthonsmartphone">';
445 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
446 if (preg_match(
'/_advance$/', $obj->perms)) {
447 print ' <span class="opacitymedium">('.$langs->trans(
"AdvancedModeOnly").
')</span>';
453 if ($user->admin)
print '<td class="right"><span class="opacitymedium">'.$obj->id.
'</span></td>';
463 $parameters = array();
464 $reshook = $hookmanager->executeHooks(
'insertExtraFooter', $parameters, $object, $action);
465 if ($reshook < 0)
setEventMessages($hookmanager->error, $hookmanager->errors,
'errors');
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.
user_prepare_head($object)
Prepare array with list of tabs.
dolGetModulesDirs($subdir= '')
Return list of modules directories.
Class to manage Dolibarr users.
showModulesExludedForExternal($modules)
Show array with constants to edit.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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)
restrictedArea($user, $features, $objectid=0, $tableandshare= '', $feature2= '', $dbt_keyfield= 'fk_soc', $dbt_select= 'rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
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 ...
print $_SERVER["PHP_SELF"]
Edit parameters.
dol_get_fiche_head($links=array(), $active= '', $title= '', $notab=0, $picto= '', $pictoisfullpath=0, $morehtmlright= '', $morecss= '', $limittoshow=0, $moretabssuffix= '')
Show tabs of a record.
print
Draft customers invoices.
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.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin= '1', $morecss= '', $textfordropdown= '')
Show information for admin users or standard users.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $keepmoretags= '', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...