dolibarr  17.0.4
list.php
Go to the documentation of this file.
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 
28 // Load Dolibarr environment
29 require '../../main.inc.php';
30 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
31 
32 // Load translation files required by page
33 $langs->load("users");
34 
35 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
36 $search_group = GETPOST('search_group');
37 $optioncss = GETPOST('optioncss', 'alpha');
38 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
39 $contextpage = GETPOST('optioncss', 'aZ09');
40 
41 // Defini si peux lire/modifier utilisateurs et permisssions
42 $caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
43 // Advanced permissions
44 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
45  $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write"));
46 }
47 
48 // Load variable for pagination
49 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
50 $sortfield = GETPOST('sortfield', 'aZ09comma');
51 $sortorder = GETPOST('sortorder', 'aZ09comma');
52 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
53 if (empty($page) || $page == -1) {
54  $page = 0;
55 }
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 
60 if (!$sortfield) {
61  $sortfield = "g.nom";
62 }
63 if (!$sortorder) {
64  $sortorder = "ASC";
65 }
66 
67 // List of fields to search into when doing a "search in all"
68 $fieldstosearchall = array(
69  'g.nom'=>"Group",
70  'g.note'=>"Note"
71 );
72 
73 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
74  if (!$user->hasRight("user", "group_advance", "read") && !$user->admin) {
76  }
77 }
78 
79 // Users/Groups management only in master entity if transverse mode
80 if (isModEnabled('multicompany') && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE) {
82 }
83 
84 if (!$user->hasRight("user", "user", "read") && !$user->admin) {
86 }
87 
88 
89 /*
90  * Actions
91  */
92 
93 if (GETPOST('cancel', 'alpha')) {
94  $action = 'list'; $massaction = '';
95 }
96 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
97  $massaction = '';
98 }
99 
100 $parameters = array();
101 $reshook = $hookmanager->executeHooks('doActions', $parameters); // Note that $action and $object may have been modified by some hooks
102 if ($reshook < 0) {
103  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
104 }
105 
106 if (empty($reshook)) {
107  // Selection of new fields
108  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
109 
110  // Purge search criteria
111  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
112  $search_label = "";
113  $search_date_creation = "";
114  $search_date_update = "";
115  $search_array_options = array();
116  }
117 }
118 
119 
120 
121 /*
122  * View
123  */
124 $title = $langs->trans("UserGroups");
125 $help_url="";
126 llxHeader('', $title, $help_url);
127 
128 $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";
129 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
130 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
131 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid";
132 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
133  $sql .= " WHERE g.entity IS NOT NULL";
134 } else {
135  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
136 }
137 if (!empty($search_group)) {
138  natural_search(array("g.nom", "g.note"), $search_group);
139 }
140 if ($sall) {
141  $sql .= natural_search(array("g.nom", "g.note"), $sall);
142 }
143 $sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec, g.tms";
144 $sql .= $db->order($sortfield, $sortorder);
145 
146 $resql = $db->query($sql);
147 if ($resql) {
148  $num = $db->num_rows($resql);
149 
150  $nbtotalofrecords = $num;
151 
152  $i = 0;
153 
154  $param = "&amp;search_group=".urlencode($search_group)."&amp;sall=".urlencode($sall);
155  if ($optioncss != '') {
156  $param .= '&amp;optioncss='.$optioncss;
157  }
158 
159  $text = $langs->trans("UserGroups");
160 
161  $newcardbutton = '';
162  if ($caneditperms) {
163  $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu=');
164  }
165 
166  print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
167  if ($optioncss != '') {
168  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
169  }
170  print '<input type="hidden" name="token" value="'.newToken().'">';
171  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
172  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
173  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
174  print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
175 
176  print_barre_liste($text, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, "", $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1);
177 
178  if ($sall) {
179  foreach ($fieldstosearchall as $key => $val) {
180  $fieldstosearchall[$key] = $langs->trans($val);
181  }
182  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
183  }
184 
185  $moreforfilter = '';
186 
187  //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
188  //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
189 
190  print '<div class="div-table-responsive">';
191  print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
192 
193  print '<tr class="liste_titre">';
194  print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder);
195  //multicompany
196  if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
197  print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center ');
198  }
199  print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center ');
200  print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center ');
201  print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center ');
202  print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "g.tms", $param, "", '', $sortfield, $sortorder, 'center ');
203  print_liste_field_titre("", $_SERVER["PHP_SELF"]);
204  print "</tr>\n";
205 
206  $grouptemp = new UserGroup($db);
207 
208  while ($i < $num) {
209  $obj = $db->fetch_object($resql);
210 
211  $grouptemp->id = $obj->rowid;
212  $grouptemp->name = $obj->name;
213  $grouptemp->note = $obj->note;
214 
215  print '<tr class="oddeven">';
216  print '<td>';
217  print $grouptemp->getNomUrl(1);
218  if (isModEnabled('multicompany') && !$obj->entity) {
219  print img_picto($langs->trans("GlobalGroup"), 'redstar');
220  }
221  print "</td>";
222  //multicompany
223  if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
224  $mc->getInfo($obj->entity);
225  print '<td class="center">'.dol_escape_htmltag($mc->label).'</td>';
226  }
227  print '<td class="center">'.$obj->nb.'</td>';
228  print '<td class="center">';
229  print '<a href="'.DOL_URL_ROOT.'/user/group/perms.php?id='.$obj->rowid.'">'.$obj->nbpermissions.'</a>';
230  print '</td>';
231  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), "dayhour").'</td>';
232  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datem), "dayhour").'</td>';
233  print '<td></td>';
234  print "</tr>\n";
235  $i++;
236  }
237  print "</table>";
238 
239  print '</div>';
240  print "</form>\n";
241 
242  $db->free($resql);
243 } else {
244  dol_print_error($db);
245 }
246 
247 // End of page
248 llxFooter();
249 $db->close();
if(GETPOST('button_removefilter_x', 'alpha')||GETPOST('button_removefilter.x', 'alpha')||GETPOST('button_removefilter', 'alpha')) if(GETPOST('button_search_x', 'alpha')||GETPOST('button_search.x', 'alpha')||GETPOST('button_search', 'alpha')) if($action=="save" &&empty($cancel)) $help_url
View.
Definition: agenda.php:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage user groups.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.