dolibarr  x.y.z
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 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
36 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
37 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
38 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
39 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
40 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
41 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
43 $optioncss = GETPOST('optioncss', 'aZ09'); // Option for the css output (always '' except when 'print')
44 $mode = GETPOST('mode', 'aZ');
45 
46 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
47 $search_group = GETPOST('search_group');
48 
49 // Load variable for pagination
50 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
51 $sortfield = GETPOST('sortfield', 'aZ09comma');
52 $sortorder = GETPOST('sortorder', 'aZ09comma');
53 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
54 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
55  // If $page is not defined, or '' or -1 or if we click on clear filters
56  $page = 0;
57 }
58 $offset = $limit * $page;
59 $pageprev = $page - 1;
60 $pagenext = $page + 1;
61 
62 // Initialize technical objects
63 $object = new UserGroup($db);
64 $extrafields = new ExtraFields($db);
65 //$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
66 //$hookmanager->initHooks(array('myobjectlist')); // Note that conf->hooks_modules contains array
67 
68 // Fetch optionals attributes and labels
69 $extrafields->fetch_name_optionals_label($object->table_element);
70 //$extrafields->fetch_name_optionals_label($object->table_element_line);
71 
72 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
73 
74 if (!$sortfield) {
75  $sortfield = "g.nom";
76 }
77 if (!$sortorder) {
78  $sortorder = "ASC";
79 }
80 
81 // List of fields to search into when doing a "search in all"
82 $fieldstosearchall = array(
83  'g.nom'=>"Group",
84  'g.note'=>"Note"
85 );
86 
87 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
88  if (!$user->hasRight("user", "group_advance", "read") && !$user->admin) {
90  }
91 }
92 
93 // Users/Groups management only in master entity if transverse mode
94 if (isModEnabled('multicompany') && $conf->entity > 1 && $conf->global->MULTICOMPANY_TRANSVERSE_MODE) {
96 }
97 
98 if (!$user->hasRight("user", "user", "read") && !$user->admin) {
100 }
101 
102 // Defini si peux lire/modifier utilisateurs et permisssions
103 $caneditperms = ($user->admin || $user->hasRight("user", "user", "write"));
104 // Advanced permissions
105 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
106  $caneditperms = ($user->admin || $user->hasRight("user", "group_advance", "write"));
107 }
108 
109 
110 /*
111  * Actions
112  */
113 
114 if (GETPOST('cancel', 'alpha')) {
115  $action = 'list';
116  $massaction = '';
117 }
118 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
119  $massaction = '';
120 }
121 
122 $parameters = array();
123 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
124 if ($reshook < 0) {
125  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
126 }
127 
128 if (empty($reshook)) {
129  // Selection of new fields
130  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
131 
132  // Purge search criteria
133  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
134  foreach ($object->fields as $key => $val) {
135  $search[$key] = '';
136  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
137  $search[$key.'_dtstart'] = '';
138  $search[$key.'_dtend'] = '';
139  }
140  }
141  $toselect = array();
142  $search_array_options = array();
143  }
144  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
145  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
146  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
147  }
148 }
149 
150 
151 /*
152  * View
153  */
154 
155 $help_url="";
156 $title = $langs->trans("UserGroups");
157 $morejs = array();
158 $morecss = array();
159 
160 
161 $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";
162 $sql .= " FROM ".MAIN_DB_PREFIX."usergroup as g";
163 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_user as ugu ON ugu.fk_usergroup = g.rowid";
164 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."usergroup_rights as ugr ON ugr.fk_usergroup = g.rowid";
165 if (isModEnabled('multicompany') && $conf->entity == 1 && (getDolGlobalInt('MULTICOMPANY_TRANSVERSE_MODE') || ($user->admin && !$user->entity))) {
166  $sql .= " WHERE g.entity IS NOT NULL";
167 } else {
168  $sql .= " WHERE g.entity IN (0,".$conf->entity.")";
169 }
170 if (!empty($search_group)) {
171  natural_search(array("g.nom", "g.note"), $search_group);
172 }
173 if ($search_all) {
174  $sql .= natural_search(array("g.nom", "g.note"), $search_all);
175 }
176 $sql .= " GROUP BY g.rowid, g.nom, g.note, g.entity, g.datec, g.tms";
177 
178 // Complete request and execute it with limit
179 $sql .= $db->order($sortfield, $sortorder);
180 if ($limit) {
181  $sql .= $db->plimit($limit + 1, $offset);
182 }
183 
184 $resql = $db->query($sql);
185 if (!$resql) {
186  dol_print_error($db);
187  exit;
188 }
189 
190 $num = $db->num_rows($resql);
191 
192 
193 $nbtotalofrecords = $num;
194 
195 $i = 0;
196 
197 
198 // Output page
199 // --------------------------------------------------------------------
200 
201 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
202 
203 $arrayofselected = is_array($toselect) ? $toselect : array();
204 
205 $param = "&search_group=".urlencode($search_group)."&search_all=".urlencode($search_all);
206 if (!empty($mode)) {
207  $param .= '&mode='.urlencode($mode);
208 }
209 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
210  $param .= '&contextpage='.urlencode($contextpage);
211 }
212 if ($limit > 0 && $limit != $conf->liste_limit) {
213  $param .= '&limit='.urlencode($limit);
214 }
215 foreach ($search as $key => $val) {
216  if (is_array($search[$key])) {
217  foreach ($search[$key] as $skey) {
218  if ($skey != '') {
219  $param .= '&search_'.$key.'[]='.urlencode($skey);
220  }
221  }
222  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
223  $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
224  $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
225  $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
226  } elseif ($search[$key] != '') {
227  $param .= '&search_'.$key.'='.urlencode($search[$key]);
228  }
229 }
230 if ($optioncss != '') {
231  $param .= '&optioncss='.urlencode($optioncss);
232 }
233 
234 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
235 if ($optioncss != '') {
236  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
237 }
238 print '<input type="hidden" name="token" value="'.newToken().'">';
239 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
240 print '<input type="hidden" name="action" value="list">';
241 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
242 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
243 print '<input type="hidden" name="page" value="'.$page.'">';
244 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
245 print '<input type="hidden" name="mode" value="'.$mode.'">';
246 
247 $newcardbutton = '';
248 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
249 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
250 
251 if ($caneditperms) {
252  $newcardbutton .= dolGetButtonTitle($langs->trans('NewGroup'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/user/group/card.php?action=create&leftmenu=');
253 }
254 
255 
256 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_group', 0, $newcardbutton, '', $limit, 0, 0, 1);
257 
258 if ($search_all) {
259  $setupstring = '';
260  foreach ($fieldstosearchall as $key => $val) {
261  $fieldstosearchall[$key] = $langs->trans($val);
262  $setupstring .= $key."=".$val.";";
263  }
264  print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
265  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
266 }
267 
268 $moreforfilter = '';
269 
270 //$varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
271 //$selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
272 
273 print '<div class="div-table-responsive">';
274 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
275 
276 // Fields title search
277 // --------------------------------------------------------------------
278 // ...
279 
280 // Fields title label
281 // --------------------------------------------------------------------
282 print '<tr class="liste_titre">';
283 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
284  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
285 }
286 print_liste_field_titre("Group", $_SERVER["PHP_SELF"], "g.nom", $param, "", "", $sortfield, $sortorder);
287 $totalarray['nbfield']++;
288 //multicompany
289 if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
290  print_liste_field_titre("Entity", $_SERVER["PHP_SELF"], "g.entity", $param, "", '', $sortfield, $sortorder, 'center ');
291  $totalarray['nbfield']++;
292 }
293 print_liste_field_titre("NbOfUsers", $_SERVER["PHP_SELF"], "nb", $param, "", '', $sortfield, $sortorder, 'center ');
294 $totalarray['nbfield']++;
295 print_liste_field_titre("NbOfPermissions", $_SERVER["PHP_SELF"], "nbpermissions", $param, "", '', $sortfield, $sortorder, 'center ');
296 $totalarray['nbfield']++;
297 print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "g.datec", $param, "", '', $sortfield, $sortorder, 'center ');
298 $totalarray['nbfield']++;
299 print_liste_field_titre("DateLastModification", $_SERVER["PHP_SELF"], "g.tms", $param, "", '', $sortfield, $sortorder, 'center ');
300 $totalarray['nbfield']++;
301 print_liste_field_titre("", $_SERVER["PHP_SELF"]);
302 $totalarray['nbfield']++; // For the column action
303 print "</tr>\n";
304 
305 
306 
307 $i = 0;
308 $savnbfield = $totalarray['nbfield'];
309 $totalarray = array();
310 $totalarray['nbfield'] = 0;
311 $imaxinloop = ($limit ? min($num, $limit) : $num);
312 while ($i < $imaxinloop) {
313  $obj = $db->fetch_object($resql);
314  if (empty($obj)) {
315  break; // Should not happen
316  }
317 
318  // Store properties in $object
319  $object->setVarsFromFetchObj($obj);
320 
321  $object->name = $obj->name;
322  $object->note = $obj->note;
323  $object->members = $obj->nb;
324  $object->nb_rights = $obj->nbpermissions;
325 
326  if ($mode == 'kanban') {
327  if ($i == 0) {
328  print '<tr><td colspan="'.$savnbfield.'">';
329  print '<div class="box-flex-container">';
330  }
331  // Output Kanban
332  print $object->getKanbanView('');
333  if ($i == ($imaxinloop - 1)) {
334  print '</div>';
335  print '</td></tr>';
336  }
337  } else {
338  // Show here line of result
339  $j = 0;
340  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
341  // Action column
342  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
343  print '<td class="nowrap center">';
344  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
345  $selected = 0;
346  if (in_array($object->id, $arrayofselected)) {
347  $selected = 1;
348  }
349  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
350  }
351  print '</td>';
352  }
353 
354  print '<td>';
355  print $object->getNomUrl(1);
356  if (isModEnabled('multicompany') && !$obj->entity) {
357  print img_picto($langs->trans("GlobalGroup"), 'redstar');
358  }
359  print "</td>";
360  //multicompany
361  if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1) {
362  $mc->getInfo($obj->entity);
363  print '<td class="center">'.dol_escape_htmltag($mc->label).'</td>';
364  }
365  print '<td class="center">'.$obj->nb.'</td>';
366  print '<td class="center">';
367  print '<a href="'.DOL_URL_ROOT.'/user/group/perms.php?id='.$obj->rowid.'">'.$obj->nbpermissions.'</a>';
368  print '</td>';
369  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datec), "dayhour").'</td>';
370  print '<td class="center nowrap">'.dol_print_date($db->jdate($obj->datem), "dayhour").'</td>';
371  // Action column
372  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
373  print '<td class="nowrap center">';
374  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
375  $selected = 0;
376  if (in_array($object->id, $arrayofselected)) {
377  $selected = 1;
378  }
379  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
380  }
381  print '</td>';
382  }
383  if (!$i) {
384  $totalarray['nbfield']++;
385  }
386 
387  print "</tr>\n";
388  }
389  $i++;
390 }
391 print "</table>";
392 
393 print '</div>';
394 print "</form>\n";
395 
396 $db->free($resql);
397 
398 // End of page
399 llxFooter();
400 $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 standard extra fields.
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.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get 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.