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