list.php 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2018 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
  6. * Copyright (C) 2019-2021 Frédéric France <frederic.france@netlogic.fr>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/user/group/list.php
  23. * \ingroup core
  24. * \brief Page of user groups
  25. */
  26. // Load Dolibarr environment
  27. require '../../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  29. // Load translation files required by page
  30. $langs->load("users");
  31. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  32. $search_group = GETPOST('search_group');
  33. $optioncss = GETPOST('optioncss', 'alpha');
  34. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  35. $contextpage = GETPOST('optioncss', 'aZ09');
  36. // Defini si peux lire/modifier utilisateurs et permisssions
  37. $caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
  38. // Advanced permissions
  39. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  40. $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write"));
  41. }
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page == -1) {
  48. $page = 0;
  49. }
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. if (!$sortfield) {
  54. $sortfield = "g.nom";
  55. }
  56. if (!$sortorder) {
  57. $sortorder = "ASC";
  58. }
  59. // List of fields to search into when doing a "search in all"
  60. $fieldstosearchall = array(
  61. 'g.nom'=>"Group",
  62. 'g.note'=>"Note"
  63. );
  64. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  65. if (!$user->hasRight("user", "group_advance", "read") && !$user->admin) {
  66. accessforbidden();
  67. }
  68. }
  69. // Users/Groups management only in master entity if transverse mode
  70. if (isModEnabled('multicompany') && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE) {
  71. accessforbidden();
  72. }
  73. if (!$user->hasRight("user", "user", "read") && !$user->admin) {
  74. accessforbidden();
  75. }
  76. /*
  77. * Actions
  78. */
  79. if (GETPOST('cancel', 'alpha')) {
  80. $action = 'list'; $massaction = '';
  81. }
  82. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  83. $massaction = '';
  84. }
  85. $parameters = array();
  86. $reshook = $hookmanager->executeHooks('doActions', $parameters); // Note that $action and $object may have been modified by some hooks
  87. if ($reshook < 0) {
  88. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  89. }
  90. if (empty($reshook)) {
  91. // Selection of new fields
  92. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  93. // Purge search criteria
  94. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
  95. $search_label = "";
  96. $search_date_creation = "";
  97. $search_date_update = "";
  98. $search_array_options = array();
  99. }
  100. }
  101. /*
  102. * View
  103. */
  104. $title = $langs->trans("ListOfGroups");
  105. $help_url="";
  106. llxHeader('', $title, $help_url);
  107. $sql = "SELECT g.rowid, g.nom as name, g.note, g.entity, g.datec, g.tms as datem, COUNT(DISTINCT ugu.fk_user) as nb, COUNT(DISTINCT ugr.fk_id) as nbpermissions";
  108. $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
  109. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
  110. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid";
  111. if (isModEnabled('multicompany') && $conf->entity == 1 && ($conf->global->MULTICOMPANY_TRANSVERSE_MODE || ($user->admin && !$user->entity))) {
  112. $sql .= " WHERE g.entity IS NOT NULL";
  113. } else {
  114. $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
  115. }
  116. if (!empty($search_group)) {
  117. natural_search(array("g.nom", "g.note"), $search_group);
  118. }
  119. if ($sall) {
  120. $sql .= natural_search(array("g.nom", "g.note"), $sall);
  121. }
  122. $sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec, g.tms";
  123. $sql .= $db->order($sortfield, $sortorder);
  124. $resql = $db->query($sql);
  125. if ($resql) {
  126. $num = $db->num_rows($resql);
  127. $nbtotalofrecords = $num;
  128. $i = 0;
  129. $param = "&amp;search_group=".urlencode($search_group)."&amp;sall=".urlencode($sall);
  130. if ($optioncss != '') {
  131. $param .= '&amp;optioncss='.$optioncss;
  132. }
  133. $text = $langs->trans("ListOfGroups");
  134. $newcardbutton = '';
  135. if ($caneditperms) {
  136. $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu=');
  137. }
  138. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  139. if ($optioncss != '') {
  140. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  141. }
  142. print '<input type="hidden" name="token" value="'.newToken().'">';
  143. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  144. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  145. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  146. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  147. print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1);
  148. if ($sall) {
  149. foreach ($fieldstosearchall as $key => $val) {
  150. $fieldstosearchall[$key] = $langs->trans($val);
  151. }
  152. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  153. }
  154. $moreforfilter = '';
  155. //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  156. //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  157. print '<div class="div-table-responsive">';
  158. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  159. print '<tr class="liste_titre">';
  160. print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder);
  161. //multicompany
  162. if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
  163. print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center ');
  164. }
  165. print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center ');
  166. print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center ');
  167. print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center ');
  168. print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "g.tms", $param, "", '', $sortfield, $sortorder, 'center ');
  169. print_liste_field_titre("", $_SERVER["PHP_SELF"]);
  170. print "</tr>\n";
  171. $grouptemp = new UserGroup($db);
  172. while ($i < $num) {
  173. $obj = $db->fetch_object($resql);
  174. $grouptemp->id = $obj->rowid;
  175. $grouptemp->name = $obj->name;
  176. $grouptemp->note = $obj->note;
  177. print '<tr class="oddeven">';
  178. print '<td>';
  179. print $grouptemp->getNomUrl(1);
  180. if (isModEnabled('multicompany') && !$obj->entity) {
  181. print img_picto($langs->trans("GlobalGroup"), 'redstar');
  182. }
  183. print "</td>";
  184. //multicompany
  185. if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
  186. $mc->getInfo($obj->entity);
  187. print '<td class="center">'.dol_escape_htmltag($mc->label).'</td>';
  188. }
  189. print '<td class="center">'.$obj->nb.'</td>';
  190. print '<td class="center">';
  191. print '<a href="'.DOL_URL_ROOT.'/user/group/perms.php?id='.$obj->rowid.'">'.$obj->nbpermissions.'</a>';
  192. print '</td>';
  193. print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), "dayhour").'</td>';
  194. print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datem), "dayhour").'</td>';
  195. print '<td></td>';
  196. print "</tr>\n";
  197. $i++;
  198. }
  199. print "</table>";
  200. print '</div>';
  201. print "</form>\n";
  202. $db->free($resql);
  203. } else {
  204. dol_print_error($db);
  205. }
  206. // End of page
  207. llxFooter();
  208. $db->close();