28if (!defined(
'CSRFCHECK_WITH_TOKEN')) {
 
   29  define(
'CSRFCHECK_WITH_TOKEN', 
'1'); 
 
   33require 
'../../main.inc.php';
 
   34require_once DOL_DOCUMENT_ROOT.
'/user/class/usergroup.class.php';
 
   35require_once DOL_DOCUMENT_ROOT.
'/core/lib/usergroups.lib.php';
 
   36require_once DOL_DOCUMENT_ROOT.
'/core/lib/functions2.lib.php';
 
   37require_once DOL_DOCUMENT_ROOT.
'/core/lib/admin.lib.php';
 
   40$langs->loadLangs(array(
'users', 
'admin'));
 
   43$action = 
GETPOST(
'action', 
'aZ09');
 
   44$confirm = 
GETPOST(
'confirm', 
'alpha');
 
   45$module = 
GETPOST(
'module', 
'alpha');
 
   46$rights = 
GETPOST(
'rights', 
'int');
 
   47$contextpage = 
GETPOST(
'contextpage', 
'aZ') ?
GETPOST(
'contextpage', 
'aZ') : 
'groupperms'; 
 
   49if (!isset($id) || empty($id)) {
 
   54$canreadperms = ($user->admin || $user->hasRight(
"user", 
"user", 
"read"));
 
   56$caneditperms = ($user->admin || $user->hasRight(
"user", 
"user", 
"write"));
 
   58$advancedpermsactive = 
false;
 
   59if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
 
   60  $advancedpermsactive = 
true;
 
   61  $canreadperms = ($user->admin || ($user->hasRight(
"user", 
"group_advance", 
"read") && $user->hasRight(
"user", 
"group_advance", 
"readperms")));
 
   62  $caneditperms = ($user->admin || $user->hasRight(
"user", 
"group_advance", 
"write"));
 
   75$entity = $conf->entity;
 
   78$hookmanager->initHooks(array(
'groupperms', 
'globalcard'));
 
   86$reshook = $hookmanager->executeHooks(
'doActions', $parameters, $object, $action); 
 
   92  if ($action == 
'addrights' && $caneditperms) {
 
   94    $result = $editgroup->fetch($object->id);
 
   96      $result = $editgroup->addrights($rights, $module, 
'', $entity);
 
  104    $user->clearrights();
 
  108  if ($action == 
'delrights' && $caneditperms) {
 
  110    $result = $editgroup->fetch($id);
 
  112      $result = $editgroup->delrights($rights, $module, 
'', $entity);
 
  120    $user->clearrights();
 
  130$form = 
new Form($db);
 
  132$title = $object->name.
" - ".$langs->trans(
'Permissions');
 
  136if ($object->id > 0) {
 
  138  $title = $langs->trans(
"Group");
 
  147  foreach ($modulesdir as $dir) {
 
  149    if (is_resource($handle)) {
 
  150      while (($file = readdir($handle)) !== 
false) {
 
  151        if (is_readable($dir.$file) && substr($file, 0, 3) == 
'mod' && substr($file, 
dol_strlen($file) - 10) == 
'.class.php') {
 
  152          $modName = substr($file, 0, 
dol_strlen($file) - 10);
 
  155            include_once $dir.$file;
 
  156            $objMod = 
new $modName($db);
 
  158            if (isset($objMod->langfiles) && is_array($objMod->langfiles)) {
 
  159              foreach ($objMod->langfiles as $domain) {
 
  160                $langs->load($domain);
 
  164            if ($objMod->rights_class) {
 
  165              $ret = $objMod->insert_permissions(0, $entity);
 
  166              $modules[$objMod->rights_class] = $objMod;
 
  177  $permsgroupbyentity = array();
 
  179  $sql = 
"SELECT DISTINCT r.id, r.libelle, r.module, gr.entity";
 
  180  $sql .= 
" FROM ".MAIN_DB_PREFIX.
"rights_def as r,";
 
  181  $sql .= 
" ".MAIN_DB_PREFIX.
"usergroup_rights as gr";
 
  182  $sql .= 
" WHERE gr.fk_id = r.id";
 
  183  $sql .= 
" AND gr.entity = ".((int) $entity);
 
  184  $sql .= 
" AND gr.fk_usergroup = ".((int) $object->id);
 
  187  $result = $db->query($sql);
 
  189    $num = $db->num_rows($result);
 
  192      $obj = $db->fetch_object($result);
 
  193      if (!isset($permsgroupbyentity[$obj->entity])) {
 
  194        $permsgroupbyentity[$obj->entity] = array();
 
  196        array_push($permsgroupbyentity[$obj->entity], $obj->id);
 
  208  $linkback = 
'<a href="'.DOL_URL_ROOT.
'/user/group/list.php?restore_lastsearch_values=1">'.$langs->trans(
"BackToList").
'</a>';
 
  210  dol_banner_tab($object, 
'id', $linkback, $user->hasRight(
"user", 
"user", 
"read") || $user->admin);
 
  212  print 
'<div class="fichecenter">';
 
  213  print 
'<div class="fichehalfleft">';
 
  214  print 
'<div class="underbanner clearboth"></div>';
 
  217  print 
'<table class="border centpercent tableforfield">';
 
  220  if (!empty($conf->mutlicompany->enabled)) {
 
  221    print 
'<tr><td class="titlefield">'.$langs->trans(
"Name").
'</td>';
 
  222    print 
'<td class="valeur">'.dol_escape_htmltag($object->name);
 
  223    if (empty($object->entity)) {
 
  224      print 
img_picto($langs->trans(
"GlobalGroup"), 
'redstar');
 
  226    print 
"</td></tr>\n";
 
  230  if (isModEnabled(
'multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
 
  231    $mc->getInfo($object->entity);
 
  232    print 
"<tr>".
'<td class="titlefield">'.$langs->trans(
"Entity").
'</td>';
 
  233    print 
'<td class="valeur">'.dol_escape_htmltag($mc->label);
 
  234    print 
"</td></tr>\n";
 
  237  unset($object->fields[
'nom']); 
 
  241  include DOL_DOCUMENT_ROOT.
'/core/tpl/commonfields_view.tpl.php';
 
  244  include DOL_DOCUMENT_ROOT.
'/core/tpl/extrafields_view.tpl.php';
 
  250  print 
'<div class="clearboth"></div>';
 
  255    print 
info_admin($langs->trans(
"WarningOnlyPermissionOfActivatedModules"));
 
  258  $parameters = array();
 
  259  $reshook = $hookmanager->executeHooks(
'insertExtraHeader', $parameters, $object, $action); 
 
  265  print 
'<div class="div-table-responsive-no-min">';
 
  266  print 
'<table class="noborder centpercent">';
 
  267  print 
'<tr class="liste_titre">';
 
  268  print 
'<td>'.$langs->trans(
"Module").
'</td>';
 
  270    print 
'<td class="center nowrap">';
 
  271    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>";
 
  273    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>";
 
  278  print 
'<td class="center" width="24"></td>';
 
  280  print 
'<td class="center"></td>';
 
  282  print 
'<td class="right nowrap">';
 
  283  print 
'<a class="showallperms" title="'.dol_escape_htmltag($langs->trans(
"ShowAllPerms")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"ShowAllPerms")).
'" href="#">'.
img_picto(
'', 
'folder-open', 
'class="paddingright"').
'<span class="hideonsmartphone">'.$langs->trans(
"ExpandAll").
'</span></a>';
 
  285  print 
'<a class="hideallperms" title="'.dol_escape_htmltag($langs->trans(
"HideAllPerms")).
'" alt="'.
dol_escape_htmltag($langs->trans(
"HideAllPerms")).
'" href="#">'.
img_picto(
'', 
'folder', 
'class="paddingright"').
'<span class="hideonsmartphone">'.$langs->trans(
"UndoExpandAll").
'</span></a>';
 
  289  $sql = 
"SELECT r.id, r.libelle as label, r.module, r.perms, r.subperms, r.module_position, r.bydefault";
 
  290  $sql .= 
" FROM ".MAIN_DB_PREFIX.
"rights_def as r";
 
  291  $sql .= 
" WHERE r.libelle NOT LIKE 'tou%'"; 
 
  292  $sql .= 
" AND r.entity = ".((int) $entity);
 
  293  if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
 
  294    $sql .= 
" AND r.perms NOT LIKE '%_advance'"; 
 
  296  $sql .= 
" ORDER BY r.family_position, r.module_position, r.module, r.id";
 
  298  $result = $db->query($sql);
 
  300    $num = $db->num_rows($result);
 
  304    $cookietohidegroup = (empty($_COOKIE[
"DOLUSER_PERMS_HIDE_GRP"]) ? 
'' : preg_replace(
'/^,/', 
'', $_COOKIE[
"DOLUSER_PERMS_HIDE_GRP"]));
 
  305    $cookietohidegrouparray = explode(
',', $cookietohidegroup);
 
  308      $obj = $db->fetch_object($result);
 
  311      if (empty($modules[$obj->module])) {
 
  316      $objMod = $modules[$obj->module];
 
  318      if (GETPOSTISSET(
'forbreakperms_'.$obj->module)) {
 
  319        $ishidden = 
GETPOST(
'forbreakperms_'.$obj->module, 
'int');
 
  320      } elseif (in_array($j, $cookietohidegrouparray)) {  
 
  325      $isexpanded = ! $ishidden;
 
  328      if (isset($obj->module) && ($oldmod <> $obj->module)) {
 
  329        $oldmod = $obj->module;
 
  332        if (GETPOSTISSET(
'forbreakperms_'.$obj->module)) {
 
  333          $ishidden = 
GETPOST(
'forbreakperms_'.$obj->module, 
'int');
 
  334        } elseif (in_array($j, $cookietohidegrouparray)) {  
 
  339        $isexpanded = ! $ishidden;
 
  341        $objMod = $modules[$obj->module];
 
  342        $picto = ($objMod->picto ? $objMod->picto : 
'generic');
 
  345        print 
'<tr class="oddeven trforbreakperms" data-hide-perms="'.$obj->module.
'" data-j="'.$j.
'">';
 
  347        print 
'<td class="maxwidthonsmartphone tdoverflowonsmartphone tdforbreakperms" data-hide-perms="'.$obj->module.
'">';
 
  348        print 
img_object(
'', $picto, 
'class="pictoobjectwidth paddingright"').
' '.$objMod->getName();
 
  349        print 
'<a name="'.$objMod->getName().
'"></a>';
 
  353          print 
'<td class="center wraponsmartphone">';
 
  354          print 
'<span class="permtohide_'.$obj->module.
'" '.(!$isexpanded ? 
' style="display:none"' : 
'').
'>';
 
  355          print 
'<a class="reposition alink addexpandedmodulesinparamlist" 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&updatedmodulename='.$obj->module.
'">'.$langs->trans(
"All").
"</a>";
 
  357          print 
'<a class="reposition alink addexpandedmodulesinparamlist" 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&updatedmodulename='.$obj->module.
'">'.$langs->trans(
"None").
"</a>";
 
  360          print 
'<td class="tdforbreakperms" data-hide-perms="'.$obj->module.
'">';
 
  363          print 
'<td class="tdforbreakperms" data-hide-perms="'.$obj->module.
'"></td>';
 
  364          print 
'<td class="tdforbreakperms" data-hide-perms="'.$obj->module.
'"></td>';
 
  367        print 
'<td class="tdforbreakperms" data-hide-perms="'.$obj->module.
'"></td>';
 
  368        print 
'<td class="maxwidthonsmartphone right tdforbreakperms" data-hide-perms="'.$obj->module.
'">';
 
  369        print 
'<div class="switchfolderperms folderperms_'.$obj->module.
'"'.($isexpanded ? 
' style="display:none;"' : 
'').
'>';
 
  370        print 
img_picto(
'', 
'folder', 
'class="marginright"');
 
  372        print 
'<div class="switchfolderperms folderopenperms_'.$obj->module.
'"'.(!$isexpanded ? 
' style="display:none;"' : 
'').
'>';
 
  373        print 
img_picto(
'', 
'folder-open', 
'class="marginright"');
 
  379      print 
'<!-- '.$obj->module.
'->'.$obj->perms.($obj->subperms ? 
'->'.$obj->subperms : 
'').
' -->'.
"\n";
 
  380      print 
'<tr class="oddeven trtohide_'.$obj->module.
'"'.(!$isexpanded ? 
' style="display:none"' : 
'').
'>';
 
  384      print 
'<td class="maxwidthonsmartphone tdoverflowonsmartphone">';
 
  385      print 
'<input type="hidden" name="forbreakperms_'.$obj->module.
'" id="idforbreakperms_'.$obj->module.
'" css="cssforfieldishiden" data-j="'.$j.
'" value="'.($isexpanded ? 
'0' : 
"1").
'">';
 
  390      if (!empty($permsgroupbyentity[$entity]) && is_array($permsgroupbyentity[$entity])) {
 
  391        if (in_array($obj->id, $permsgroupbyentity[$entity])) {
 
  394            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">';
 
  396            print 
img_picto($langs->trans(
"Remove"), 
'switch_on');
 
  399          print 
'<td class="center nowrap">';
 
  400          print 
img_picto($langs->trans(
"Active"), 
'tick');
 
  405            print 
'<td class="center"><a class="reposition" href="'.$_SERVER[
"PHP_SELF"].
'?id='.$object->id.
'&action=addrights&token='.newToken().
'&entity='.$entity.
'&rights='.$obj->id.
'&confirm=yes">';
 
  407            print 
img_picto($langs->trans(
"Add"), 
'switch_off');
 
  410          print 
'<td> </td>';
 
  415          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().
'">';
 
  417          print 
img_picto($langs->trans(
"Add"), 
'switch_off');
 
  420          print 
'<td> </td>';
 
  422        print 
'<td> </td>';
 
  426      $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)));
 
  429      if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
 
  430        if (preg_match(
'/_advance$/', $obj->perms)) {
 
  431          print 
' <span class="opacitymedium">('.$langs->trans(
"AdvancedModeOnly").
')</span>';
 
  438        print 
'<td class="right">';
 
  439        $htmltext = $langs->trans(
"ID").
': '.$obj->id;
 
  440        $htmltext .= 
'<br>'.$langs->trans(
"Permission").
': user->rights->'.$obj->module.
'->'.$obj->perms.($obj->subperms ? 
'->'.$obj->subperms : 
'');
 
  441        print $form->textwithpicto(
'', $htmltext);
 
  445        print 
'<td> </td>';
 
  457  print 
'$(".tdforbreakperms:not(.alink)").on("click", function(){ 
  458    console.log("Click on tdforbreakperms"); 
  459    moduletohide = $(this).data("hide-perms"); 
  460    j = $(this).data("j"); 
  461    if ($("#idforbreakperms_"+moduletohide).val() == 1) { 
  462      console.log("idforbreakperms_"+moduletohide+" has value hidden=1"); 
  463      $(".trtohide_"+moduletohide).show(); 
  464      $(".permtoshow_"+moduletohide).hide(); 
  465      $(".permtohide_"+moduletohide).show(); 
  466      $(".folderperms_"+moduletohide).hide(); 
  467      $(".folderopenperms_"+moduletohide).show(); 
  468      $("#idforbreakperms_"+moduletohide).val("0"); 
  470      console.log("idforbreakperms_"+moduletohide+" has value hidden=0"); 
  471      $(".trtohide_"+moduletohide).hide(); 
  472      $(".folderopenperms_"+moduletohide).hide(); 
  473      $(".folderperms_"+moduletohide).show(); 
  474      $(".permtoshow_"+moduletohide).show(); 
  475      $(".permtohide_"+moduletohide).hide(); 
  476      $("#idforbreakperms_"+moduletohide).val("1"); 
  479    // Now rebuild the value for cookie 
  481    $(".trforbreakperms").each(function(index) { 
  482      //console.log( index + ": " + $( this ).data("j") + " " + $( this ).data("hide-perms") + " " + $("input[data-j="+(index+1)+"]").val()); 
  483      if ($("input[data-j="+(index+1)+"]").val() == 1) { 
  484        hideuserperm=hideuserperm+","+(index+1); 
  488    date = new Date(); date.setTime(date.getTime()+(30*86400000)); 
  490      console.log("set cookie DOLUSER_PERMS_HIDE_GRP="+hideuserperm); 
  491      document.cookie = "DOLUSER_PERMS_HIDE_GRP=" + hideuserperm + "; expires=" + date.toGMTString() + "; path=/ "; 
  493      console.log("delete cookie DOLUSER_PERMS_HIDE_GRP"); 
  494      document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ "; 
  499  print 
'$(".showallperms").on("click", function(){ 
  500    console.log("Click on showallperms"); 
  502    console.log("delete cookie DOLUSER_PERMS_HIDE_GRP from showallperms click"); 
  503    document.cookie = "DOLUSER_PERMS_HIDE_GRP=; expires=Thu, 01-Jan-70 00:00:01 GMT; path=/ "; 
  504    $(".tdforbreakperms").each( function(){ 
  505      moduletohide = $(this).data("hide-perms"); 
  506      //console.log(moduletohide); 
  507      if ($("#idforbreakperms_"+moduletohide).val() != 0) { 
  508        $(this).trigger("click"); // emulate the click, so the cooki will be resaved 
  513  $(".hideallperms").on("click", function(){ 
  514    console.log("Click on hideallperms"); 
  516    $(".tdforbreakperms").each( function(){ 
  517      moduletohide = $(this).data("hide-perms"); 
  518      //console.log(moduletohide); 
  519      if ($("#idforbreakperms_"+moduletohide).val() != 1) { 
  520        $(this).trigger("click"); // emulate the click, so the cooki will be resaved 
  528  print 
'.switchfolderperms{ 
  534  $parameters = array();
 
  535  $reshook = $hookmanager->executeHooks(
'insertExtraFooter', $parameters, $object, $action); 
 
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Class to manage user groups.
dolGetModulesDirs($subdir='')
Return list of modules directories.
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.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_osencode($str)
Return a string encoded into OS filesystem encoding.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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)
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
group_prepare_head($object)
Prepare array with list of tabs.