dolibarr  x.y.z
list.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
6  * Copyright (C) 2016 Marcos GarcĂ­a <marcosgdf@gmail.com>
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.'/core/class/html.formother.class.php';
31 if (isModEnabled('categorie')) {
32  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
33 }
34 
35 // Load translation files required by page
36 $langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
37 
38 $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
39 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
40 $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
41 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
42 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
43 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
44 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
45 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
46 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
47 $mode = GETPOST("mode", 'alpha');
48 
49 // Security check (for external users)
50 $socid = 0;
51 if ($user->socid > 0) {
52  $socid = $user->socid;
53 }
54 
55 // Load variable for pagination
56 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
57 $sortfield = GETPOST('sortfield', 'aZ09comma');
58 $sortorder = GETPOST('sortorder', 'aZ09comma');
59 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
60 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
61  // If $page is not defined, or '' or -1 or if we click on clear filters
62  $page = 0;
63 }
64 $offset = $limit * $page;
65 $pageprev = $page - 1;
66 $pagenext = $page + 1;
67 
68 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
69 $object = new User($db);
70 $extrafields = new ExtraFields($db);
71 $diroutputmassaction = $conf->user->dir_output.'/temp/massgeneration/'.$user->id;
72 $hookmanager->initHooks(array('userlist'));
73 
74 // Fetch optionals attributes and labels
75 $extrafields->fetch_name_optionals_label($object->table_element);
76 
77 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
78 
79 if (!$sortfield) {
80  $sortfield = "u.login";
81 }
82 if (!$sortorder) {
83  $sortorder = "ASC";
84 }
85 
86 // Initialize array of search criterias
87 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
88 $search = array();
89 foreach ($object->fields as $key => $val) {
90  if (GETPOST('search_'.$key, 'alpha') !== '') {
91  $search[$key] = GETPOST('search_'.$key, 'alpha');
92  }
93  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
94  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
95  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
96  }
97 }
98 
99 $userstatic = new User($db);
100 $companystatic = new Societe($db);
101 $form = new Form($db);
102 
103 // List of fields to search into when doing a "search in all"
104 $fieldstosearchall = array(
105  'u.login'=>"Login",
106  'u.lastname'=>"Lastname",
107  'u.firstname'=>"Firstname",
108  'u.accountancy_code'=>"AccountancyCode",
109  'u.office_phone'=>"PhonePro",
110  'u.user_mobile'=>"PhoneMobile",
111  'u.email'=>"EMail",
112  'u.note_public'=>"NotePublic",
113  'u.note_private'=>"NotePrivate"
114 );
115 if (!empty($conf->api->enabled)) {
116  $fieldstosearchall['u.api_key'] = "ApiKey";
117 }
118 
119 // Definition of fields for list
120 $arrayfields = array(
121  'u.login'=>array('label'=>"Login", 'checked'=>1, 'position'=>10),
122  'u.lastname'=>array('label'=>"Lastname", 'checked'=>1, 'position'=>15),
123  'u.firstname'=>array('label'=>"Firstname", 'checked'=>1, 'position'=>20),
124  'u.entity'=>array('label'=>"Entity", 'checked'=>1, 'position'=>50, 'enabled'=>(isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))),
125  'u.gender'=>array('label'=>"Gender", 'checked'=>0, 'position'=>22),
126  'u.employee'=>array('label'=>"Employee", 'checked'=>($contextpage == 'employeelist' ? 1 : 0), 'position'=>25),
127  'u.fk_user'=>array('label'=>"HierarchicalResponsible", 'checked'=>1, 'position'=>27),
128  'u.accountancy_code'=>array('label'=>"AccountancyCode", 'checked'=>0, 'position'=>30),
129  'u.office_phone'=>array('label'=>"PhonePro", 'checked'=>1, 'position'=>31),
130  'u.user_mobile'=>array('label'=>"PhoneMobile", 'checked'=>1, 'position'=>32),
131  'u.email'=>array('label'=>"EMail", 'checked'=>1, 'position'=>35),
132  'u.api_key'=>array('label'=>"ApiKey", 'checked'=>0, 'position'=>40, "enabled"=>(!empty($conf->api->enabled) && $user->admin)),
133  'u.fk_soc'=>array('label'=>"Company", 'checked'=>($contextpage == 'employeelist' ? 0 : 1), 'position'=>45),
134  'u.salary'=>array('label'=>"Salary", 'checked'=>1, 'position'=>80, 'enabled'=>(!empty($conf->salaries->enabled) && $user->hasRight("salaries", "readall"))),
135  'u.datelastlogin'=>array('label'=>"LastConnexion", 'checked'=>1, 'position'=>100),
136  'u.datepreviouslogin'=>array('label'=>"PreviousConnexion", 'checked'=>0, 'position'=>110),
137  'u.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
138  'u.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
139  'u.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
140 );
141 // Extra fields
142 include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
143 
144 $object->fields = dol_sort_array($object->fields, 'position');
145 $arrayfields = dol_sort_array($arrayfields, 'position');
146 
147 // Init search fields
148 $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
149 $search_user = GETPOST('search_user', 'alpha');
150 $search_login = GETPOST('search_login', 'alpha');
151 $search_lastname = GETPOST('search_lastname', 'alpha');
152 $search_firstname = GETPOST('search_firstname', 'alpha');
153 $search_gender = GETPOST('search_gender', 'alpha');
154 $search_employee = GETPOST('search_employee', 'alpha');
155 $search_accountancy_code = GETPOST('search_accountancy_code', 'alpha');
156 $search_phonepro = GETPOST('search_phonepro', 'alpha');
157 $search_phonemobile = GETPOST('search_phonemobile', 'alpha');
158 $search_email = GETPOST('search_email', 'alpha');
159 $search_api_key = GETPOST('search_api_key', 'alphanohtml');
160 $search_statut = GETPOST('search_statut', 'intcomma');
161 $search_thirdparty = GETPOST('search_thirdparty', 'alpha');
162 $search_warehouse = GETPOST('search_warehouse', 'alpha');
163 $search_supervisor = GETPOST('search_supervisor', 'intcomma');
164 $search_categ = GETPOST("search_categ", 'int');
165 $searchCategoryUserOperator = 0;
166 if (GETPOSTISSET('formfilteraction')) {
167  $searchCategoryUserOperator = GETPOSTINT('search_category_user_operator');
168 } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
169  $searchCategoryUserOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
170 }
171 $searchCategoryUserList = GETPOST('search_category_user_list', 'array');
172 $catid = GETPOST('catid', 'int');
173 if (!empty($catid) && empty($searchCategoryUserList)) {
174  $searchCategoryUserList = array($catid);
175 }
176 $catid = GETPOST('catid', 'int');
177 if (!empty($catid) && empty($search_categ)) {
178  $search_categ = $catid;
179 }
180 
181 // Default search
182 if ($search_statut == '') {
183  $search_statut = '1';
184 }
185 if ($contextpage == 'employeelist' && !GETPOSTISSET('search_employee')) {
186  $search_employee = 1;
187 }
188 
189 // Define value to know what current user can do on users
190 $permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
191 $canreaduser = (!empty($user->admin) || $user->hasRight("user", "user", "read"));
192 $canedituser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
193 $candisableuser = (!empty($user->admin) || $user->hasRight("user", "user", "delete"));
194 $canreadgroup = $canreaduser;
195 $caneditgroup = $canedituser;
196 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
197  $canreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
198  $caneditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write"));
199 }
200 
201 $error = 0;
202 
203 // Permission to list
204 if ($contextpage == 'employeelist' && $search_employee == 1) {
205  if (!$user->hasRight("salaries", "read")) {
206  accessforbidden();
207  }
208 } else {
209  if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
210  accessforbidden();
211  }
212 }
213 
214 $childids = $user->getAllChildIds(1);
215 
216 
217 /*
218  * Actions
219  */
220 
221 if (GETPOST('cancel', 'alpha')) {
222  $action = 'list';
223  $massaction = '';
224 }
225 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
226  $massaction = '';
227 }
228 
229 $parameters = array();
230 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
231 if ($reshook < 0) {
232  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
233 }
234 
235 if (empty($reshook)) {
236  // Selection of new fields
237  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
238 
239  // Purge search criteria
240  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
241  $search_user = "";
242  $search_login = "";
243  $search_lastname = "";
244  $search_firstname = "";
245  $search_gender = "";
246  $search_employee = "";
247  $search_accountancy_code = "";
248  $search_phonepro = "";
249  $search_phonemobile = "";
250  $search_email = "";
251  $search_statut = "";
252  $search_thirdparty = "";
253  $search_warehouse = "";
254  $search_supervisor = "";
255  $search_api_key = "";
256  $search_datelastlogin = "";
257  $search_datepreviouslogin = "";
258  $search_date_creation = "";
259  $search_date_update = "";
260  $search_categ = 0;
261  $toselect = array();
262  $search_array_options = array();
263  }
264  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
265  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
266  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
267  }
268 
269  // Mass actions
270  $objectclass = 'User';
271  $objectlabel = 'User';
272  $uploaddir = $conf->user->dir_output;
273  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
274 
275  // Disable or Enable records
276  if (!$error && ($massaction == 'disable' || $massaction == 'reactivate') && $permissiontoadd) {
277  $objecttmp = new User($db);
278 
279  if (!$error) {
280  $db->begin();
281 
282  $nbok = 0;
283  foreach ($toselect as $toselectid) {
284  if ($toselectid == $user->id) {
285  setEventMessages($langs->trans($massaction == 0 ? 'CantDisableYourself' : 'CanEnableYourself'), null, 'errors');
286  $error++;
287  break;
288  }
289 
290  $result = $objecttmp->fetch($toselectid);
291  if ($result > 0) {
292  if ($objecttmp->admin) {
293  setEventMessages($langs->trans($massaction == 0 ? 'CantDisableAnAdminUserWithMassActions' : 'CantEnableAnAdminUserWithMassActions', $objecttmp->login), null, 'errors');
294  $error++;
295  break;
296  }
297 
298  $result = $objecttmp->setstatus($massaction == 'disable' ? 0 : 1);
299  if ($result == 0) {
300  // Nothing is done
301  } elseif ($result < 0) {
302  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
303  $error++;
304  break;
305  } else {
306  $nbok++;
307  }
308  } else {
309  setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
310  $error++;
311  break;
312  }
313  }
314 
315  if (!$error && !empty($conf->file->main_limit_users)) {
316  $nb = $object->getNbOfUsers("active");
317  if ($nb >= $conf->file->main_limit_users) {
318  $error++;
319  setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
320  }
321  }
322 
323  if (!$error) {
324  if ($nbok > 1) {
325  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
326  } else {
327  setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
328  }
329  $db->commit();
330  } else {
331  $db->rollback();
332  }
333  }
334  }
335 }
336 
337 
338 /*
339  * View
340  */
341 
342 $formother = new FormOther($db);
343 $user2 = new User($db);
344 
345 $now = dol_now();
346 
347 $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
348 if ($contextpage == 'employeelist' && $search_employee == 1) {
349  $title = $langs->trans("Employees");
350 } else {
351  $title = $langs->trans("Users");
352 }
353 $morejs = array();
354 $morecss = array();
355 $morehtmlright = "";
356 
357 // Build and execute select
358 // --------------------------------------------------------------------
359 $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.office_phone, u.user_mobile, u.email, u.api_key, u.accountancy_code, u.gender, u.employee, u.photo,";
360 $sql .= " u.salary, u.datelastlogin, u.datepreviouslogin,";
361 $sql .= " u.ldap_sid, u.statut as status, u.entity,";
362 $sql .= " u.tms as date_update, u.datec as date_creation,";
363 $sql .= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.office_phone as ofice_phone2, u2.user_mobile as user_mobile2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2, u2.statut as status2,";
364 $sql .= " s.nom as name, s.canvas";
365 // Add fields from extrafields
366 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
367  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
368  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
369  }
370 }
371 // Add fields from hooks
372 $parameters = array();
373 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
374 $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
375 $sql = preg_replace('/,\s*$/', '', $sql);
376 
377 $sqlfields = $sql; // $sql fields to remove for count total
378 
379 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as u";
380 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
381  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (u.rowid = ef.fk_object)";
382 }
383 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
384 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid";
385 // Add table from hooks
386 $parameters = array();
387 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
388 $sql .= $hookmanager->resPrint;
389 if ($reshook > 0) {
390  $sql .= $hookmanager->resPrint;
391 }
392 $sql .= " WHERE u.entity IN (".getEntity($object->element).")";
393 if ($socid > 0) {
394  $sql .= " AND u.fk_soc = ".((int) $socid);
395 }
396 //if ($search_user != '') $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_user);
397 if ($search_supervisor > 0) {
398  $sql .= " AND u.fk_user IN (".$db->sanitize($search_supervisor).")";
399 }
400 if ($search_thirdparty != '') {
401  $sql .= natural_search(array('s.nom'), $search_thirdparty);
402 }
403 if ($search_warehouse > 0) {
404  $sql .= natural_search(array('u.fk_warehouse'), $search_warehouse);
405 }
406 if ($search_login != '') {
407  $sql .= natural_search("u.login", $search_login);
408 }
409 if ($search_lastname != '') {
410  $sql .= natural_search("u.lastname", $search_lastname);
411 }
412 if ($search_firstname != '') {
413  $sql .= natural_search("u.firstname", $search_firstname);
414 }
415 if ($search_gender != '' && $search_gender != '-1') {
416  $sql .= " AND u.gender = '".$db->escape($search_gender)."'"; // Cannot use natural_search as looking for %man% also includes woman
417 }
418 if (is_numeric($search_employee) && $search_employee >= 0) {
419  $sql .= ' AND u.employee = '.(int) $search_employee;
420 }
421 if ($search_accountancy_code != '') {
422  $sql .= natural_search("u.accountancy_code", $search_accountancy_code);
423 }
424 if ($search_phonepro != '') {
425  $sql .= natural_search("u.office_phone", $search_phonepro);
426 }
427 if ($search_phonemobile != '') {
428  $sql .= natural_search("u.user_mobile", $search_phonemobile);
429 }
430 if ($search_email != '') {
431  $sql .= natural_search("u.email", $search_email);
432 }
433 if ($search_api_key != '') {
434  $sql .= natural_search("u.api_key", $search_api_key);
435 }
436 if ($search_statut != '' && $search_statut >= 0) {
437  $sql .= " AND u.statut IN (".$db->sanitize($search_statut).")";
438 }
439 if ($sall) {
440  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
441 }
442 // Search for tag/category ($searchCategoryUserList is an array of ID)
443 $searchCategoryUserList = array($search_categ);
444 if (!empty($searchCategoryUserList)) {
445  $searchCategoryUserSqlList = array();
446  $listofcategoryid = '';
447  foreach ($searchCategoryUserList as $searchCategoryUser) {
448  if (intval($searchCategoryUser) == -2) {
449  $searchCategoryUserSqlList[] = "NOT EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user)";
450  } elseif (intval($searchCategoryUser) > 0) {
451  if ($searchCategoryUserOperator == 0) {
452  $searchCategoryUserSqlList[] = " EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user AND ck.fk_categorie = ".((int) $searchCategoryUser).")";
453  } else {
454  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryUser);
455  }
456  }
457  }
458  if ($listofcategoryid) {
459  $searchCategoryUserSqlList[] = " EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
460  }
461  if ($searchCategoryUserOperator == 1) {
462  if (!empty($searchCategoryUserSqlList)) {
463  $sql .= " AND (".implode(' OR ', $searchCategoryUserSqlList).")";
464  }
465  } else {
466  if (!empty($searchCategoryUserSqlList)) {
467  $sql .= " AND (".implode(' AND ', $searchCategoryUserSqlList).")";
468  }
469  }
470 }
471 if ($search_warehouse > 0) {
472  $sql .= " AND u.fk_warehouse = ".((int) $search_warehouse);
473 }
474 if ($contextpage == 'employeelist' && !$user->hasRight("salaries", "readall")) {
475  $sql .= " AND u.rowid IN (".$db->sanitize(join(',', $childids)).")";
476 }
477 // Add where from extra fields
478 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
479 // Add where from hooks
480 $parameters = array();
481 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
482 $sql .= $hookmanager->resPrint;
483 
484 // Count total nb of records
485 $nbtotalofrecords = '';
486 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
487  /* The fast and low memory method to get and count full list converts the sql into a sql count */
488  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
489  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
490  $resql = $db->query($sqlforcount);
491  if ($resql) {
492  $objforcount = $db->fetch_object($resql);
493  $nbtotalofrecords = $objforcount->nbtotalofrecords;
494  } else {
495  dol_print_error($db);
496  }
497 
498  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
499  $page = 0;
500  $offset = 0;
501  }
502  $db->free($resql);
503 }
504 
505 // Complete request and execute it with limit
506 $sql .= $db->order($sortfield, $sortorder);
507 if ($limit) {
508  $sql .= $db->plimit($limit + 1, $offset);
509 }
510 
511 $resql = $db->query($sql);
512 if (!$resql) {
513  dol_print_error($db);
514  exit;
515 }
516 
517 $num = $db->num_rows($resql);
518 
519 // Direct jump if only one record found
520 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
521  $obj = $db->fetch_object($resql);
522  $id = $obj->rowid;
523  header("Location: ".DOL_URL_ROOT.'/user/card.php?id='.$id);
524  exit;
525 }
526 
527 // Output page
528 // --------------------------------------------------------------------
529 
530 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
531 
532 $arrayofselected = is_array($toselect) ? $toselect : array();
533 
534 $param = '';
535 if (!empty($mode)) {
536  $param .= '&amp;mode='.urlencode($mode);
537 }
538 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
539  $param .= '&amp;contextpage='.urlencode($contextpage);
540 }
541 if ($limit > 0 && $limit != $conf->liste_limit) {
542  $param .= '&amp;limit='.urlencode($limit);
543 }
544 if ($sall != '') {
545  $param .= '&amp;sall='.urlencode($sall);
546 }
547 if ($search_user != '') {
548  $param .= "&amp;search_user=".urlencode($search_user);
549 }
550 if ($search_login != '') {
551  $param .= "&amp;search_login=".urlencode($search_login);
552 }
553 if ($search_lastname != '') {
554  $param .= "&amp;search_lastname=".urlencode($search_lastname);
555 }
556 if ($search_firstname != '') {
557  $param .= "&amp;search_firstname=".urlencode($search_firstname);
558 }
559 if ($search_gender != '' && $search_gender != '-1') {
560  $param .= "&amp;search_gender=".urlencode($search_gender);
561 }
562 if ($search_employee != '' && $search_employee != '-1') {
563  $param .= "&amp;search_employee=".urlencode($search_employee);
564 }
565 if ($search_accountancy_code != '') {
566  $param .= "&amp;search_accountancy_code=".urlencode($search_accountancy_code);
567 }
568 if ($search_phonepro != '') {
569  $param .= "&amp;search_phonepro=".urlencode($search_phonepro);
570 }
571 if ($search_phonemobile != '') {
572  $param .= "&amp;search_phonemobile=".urlencode($search_phonemobile);
573 }
574 if ($search_email != '') {
575  $param .= "&amp;search_email=".urlencode($search_email);
576 }
577 if ($search_api_key != '') {
578  $param .= "&amp;search_api_key=".urlencode($search_api_key);
579 }
580 if ($search_supervisor > 0) {
581  $param .= "&amp;search_supervisor=".urlencode($search_supervisor);
582 }
583 if ($search_statut != '') {
584  $param .= "&amp;search_statut=".urlencode($search_statut);
585 }
586 if ($optioncss != '') {
587  $param .= '&amp;optioncss='.urlencode($optioncss);
588 }
589 if ($search_categ > 0) {
590  $param .= '&amp;search_categ='.urlencode($search_categ);
591 }
592 if ($search_warehouse > 0) {
593  $param .= '&amp;search_warehouse='.urlencode($search_warehouse);
594 }
595 // Add $param from extra fields
596 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
597 
598 // List of mass actions available
599 $arrayofmassactions = array();
600 if ($permissiontoadd) {
601  $arrayofmassactions['disable'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("DisableUser");
602 }
603 if ($permissiontoadd) {
604  $arrayofmassactions['reactivate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Reactivate");
605 }
606 if (isModEnabled('category') && $permissiontoadd) {
607  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
608 }
609 if ($permissiontoadd) {
610  $arrayofmassactions['presetsupervisor'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("SetSupervisor");
611 }
612 //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
613 
614 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete', 'preaffecttag', 'presetsupervisor'))) {
615  $arrayofmassactions = array();
616 }
617 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
618 
619 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
620 if ($optioncss != '') {
621  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
622 }
623 print '<input type="hidden" name="token" value="'.newToken().'">';
624 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
625 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
626 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
627 print '<input type="hidden" name="page" value="'.$page.'">';
628 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
629 print '<input type="hidden" name="mode" value="'.$mode.'">';
630 
631 $url = DOL_URL_ROOT.'/user/card.php?action=create'.($contextpage == 'employeelist' ? '&search_employee=1' : '').'&leftmenu=';
632 if (!empty($socid)) {
633  $url .= '&socid='.urlencode($socid);
634 }
635 
636 $newcardbutton = '';
637 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
638 $newcardbutton .= dolGetButtonTitle($langs->trans('HierarchicView'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php?mode=hierarchy'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', (($mode == 'hierarchy') ? 2 : 1), array('morecss'=>'reposition'));
639 $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'));
640 $newcardbutton .= dolGetButtonTitleSeparator();
641 $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
642 
643 /*$moreparam = array('morecss'=>'btnTitleSelected');
644 $morehtmlright = dolGetButtonTitle($langs->trans("List"), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''), '', 1, $moreparam);
645 $moreparam = array('morecss'=>'marginleftonly');
646 $morehtmlright .= dolGetButtonTitle($langs->trans("HierarchicView"), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''), '', 1, $moreparam);
647 */
648 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $morehtmlright.' '.$newcardbutton, '', $limit, 0, 0, 1);
649 
650 
651 
652 // Add code for pre mass action (confirmation or email presend form)
653 $topicmail = "SendUserRef";
654 $modelmail = "user";
655 $objecttmp = new User($db);
656 $trackid = 'use'.$object->id;
657 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
658 
659 if (!empty($catid)) {
660  print "<div id='ways'>";
661  $c = new Categorie($db);
662  $ways = $c->print_all_ways(' &gt; ', 'user/list.php');
663  print " &gt; ".$ways[0]."<br>\n";
664  print "</div><br>";
665 }
666 
667 if ($search_all) {
668  foreach ($fieldstosearchall as $key => $val) {
669  $fieldstosearchall[$key] = $langs->trans($val);
670  }
671  print '<!-- Search done like if USER_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
672  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
673 }
674 
675 $moreforfilter = '';
676 /*$moreforfilter.='<div class="divsearchfield">';
677  $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
678  $moreforfilter.= '</div>';*/
679 
680 // Filter on categories
681 if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
682  $moreforfilter .= '<div class="divsearchfield">';
683  $tmptitle = $langs->trans('Category');
684  $moreforfilter .= img_picto($langs->trans("Category"), 'category', 'class="pictofixedwidth"').$formother->select_categories(Categorie::TYPE_USER, $search_categ, 'search_categ', 1, $tmptitle);
685  $moreforfilter .= '</div>';
686 }
687 // Filter on warehouse
688 if (isModEnabled('stock') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
689  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
690  $formproduct = new FormProduct($db);
691  $moreforfilter .= '<div class="divsearchfield">';
692  $tmptitle = $langs->trans('Warehouse');
693  $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', $tmptitle, 0, 0, $tmptitle);
694  $moreforfilter .= '</div>';
695 }
696 
697 $parameters = array();
698 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
699 if (empty($reshook)) {
700  $moreforfilter .= $hookmanager->resPrint;
701 } else {
702  $moreforfilter = $hookmanager->resPrint;
703 }
704 
705 if (!empty($moreforfilter)) {
706  print '<div class="liste_titre liste_titre_bydiv centpercent">';
707  print $moreforfilter;
708  print '</div>';
709 }
710 
711 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
712 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
713 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
714 
715 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
716 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
717 
718 // Fields title search
719 // --------------------------------------------------------------------
720 print '<tr class="liste_titre">';
721 // Action column
722 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
723  print '<td class="liste_titre maxwidthsearch">';
724  $searchpicto = $form->showFilterButtons('left');
725  print $searchpicto;
726  print '</td>';
727 }
728 if (!empty($arrayfields['u.login']['checked'])) {
729  print '<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.$search_login.'"></td>';
730 }
731 if (!empty($arrayfields['u.lastname']['checked'])) {
732  print '<td class="liste_titre"><input type="text" name="search_lastname" class="maxwidth50" value="'.$search_lastname.'"></td>';
733 }
734 if (!empty($arrayfields['u.firstname']['checked'])) {
735  print '<td class="liste_titre"><input type="text" name="search_firstname" class="maxwidth50" value="'.$search_firstname.'"></td>';
736 }
737 if (!empty($arrayfields['u.gender']['checked'])) {
738  print '<td class="liste_titre center">';
739  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
740  print $form->selectarray('search_gender', $arraygender, $search_gender, 1);
741  print '</td>';
742 }
743 if (!empty($arrayfields['u.employee']['checked'])) {
744  print '<td class="liste_titre">';
745  print $form->selectyesno('search_employee', $search_employee, 1, false, 1);
746  print '</td>';
747 }
748 // Supervisor
749 if (!empty($arrayfields['u.fk_user']['checked'])) {
750  print '<td class="liste_titre">';
751  print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, array(), 0, '', 0, 0, 0, 0, '', 0, '', 'maxwidth150');
752  print '</td>';
753 }
754 if (!empty($arrayfields['u.accountancy_code']['checked'])) {
755  print '<td class="liste_titre"><input type="text" name="search_accountancy_code" class="maxwidth50" value="'.$search_accountancy_code.'"></td>';
756 }
757 if (!empty($arrayfields['u.office_phone']['checked'])) {
758  print '<td class="liste_titre"><input type="text" name="search_phonepro" class="maxwidth50" value="'.$search_phonepro.'"></td>';
759 }
760 if (!empty($arrayfields['u.user_mobile']['checked'])) {
761  print '<td class="liste_titre"><input type="text" name="search_phonemobile" class="maxwidth50" value="'.$search_phonemobile.'"></td>';
762 }
763 if (!empty($arrayfields['u.email']['checked'])) {
764  print '<td class="liste_titre"><input type="text" name="search_email" class="maxwidth75" value="'.$search_email.'"></td>';
765 }
766 if (!empty($arrayfields['u.api_key']['checked'])) {
767  print '<td class="liste_titre"><input type="text" name="search_api_key" class="maxwidth50" value="'.$search_api_key.'"></td>';
768 }
769 if (!empty($arrayfields['u.fk_soc']['checked'])) {
770  print '<td class="liste_titre"><input type="text" name="search_thirdparty" class="maxwidth75" value="'.$search_thirdparty.'"></td>';
771 }
772 if (!empty($arrayfields['u.entity']['checked'])) {
773  print '<td class="liste_titre"></td>';
774 }
775 if (!empty($arrayfields['u.salary']['checked'])) {
776  print '<td class="liste_titre"></td>';
777 }
778 if (!empty($arrayfields['u.datelastlogin']['checked'])) {
779  print '<td class="liste_titre"></td>';
780 }
781 if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
782  print '<td class="liste_titre"></td>';
783 }
784 // Extra fields
785 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
786 // Fields from hook
787 $parameters = array('arrayfields'=>$arrayfields);
788 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
789 print $hookmanager->resPrint;
790 if (!empty($arrayfields['u.datec']['checked'])) {
791  // Date creation
792  print '<td class="liste_titre">';
793  print '</td>';
794 }
795 if (!empty($arrayfields['u.tms']['checked'])) {
796  // Date modification
797  print '<td class="liste_titre">';
798  print '</td>';
799 }
800 if (!empty($arrayfields['u.statut']['checked'])) {
801  // Status
802  print '<td class="liste_titre center">';
803  print $form->selectarray('search_statut', array('-1'=>'', '0'=>$langs->trans('Disabled'), '1'=>$langs->trans('Enabled')), $search_statut, 0, 0, 0, '', 0, 0, 0, '', 'search_status minwidth75imp maxwidth125 onrightofpage');
804  print '</td>';
805 }
806 // Action column
807 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
808  print '<td class="liste_titre maxwidthsearch">';
809  $searchpicto = $form->showFilterButtons();
810  print $searchpicto;
811  print '</td>';
812 }
813 print '</tr>'."\n";
814 
815 $totalarray = array();
816 $totalarray['nbfield'] = 0;
817 
818 // Fields title label
819 // --------------------------------------------------------------------
820 print '<tr class="liste_titre">';
821 if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
822  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
823  $totalarray['nbfield']++;
824 }
825 if (!empty($arrayfields['u.login']['checked'])) {
826  print_liste_field_titre("Login", $_SERVER['PHP_SELF'], "u.login", $param, "", "", $sortfield, $sortorder);
827  $totalarray['nbfield']++;
828 }
829 if (!empty($arrayfields['u.lastname']['checked'])) {
830  print_liste_field_titre("Lastname", $_SERVER['PHP_SELF'], "u.lastname", $param, "", "", $sortfield, $sortorder);
831  $totalarray['nbfield']++;
832 }
833 if (!empty($arrayfields['u.firstname']['checked'])) {
834  print_liste_field_titre("FirstName", $_SERVER['PHP_SELF'], "u.firstname", $param, "", "", $sortfield, $sortorder);
835  $totalarray['nbfield']++;
836 }
837 if (!empty($arrayfields['u.gender']['checked'])) {
838  print_liste_field_titre("Gender", $_SERVER['PHP_SELF'], "u.gender", $param, "", "", $sortfield, $sortorder, 'center ');
839  $totalarray['nbfield']++;
840 }
841 if (!empty($arrayfields['u.employee']['checked'])) {
842  print_liste_field_titre("Employee", $_SERVER['PHP_SELF'], "u.employee", $param, "", "", $sortfield, $sortorder, 'center ');
843  $totalarray['nbfield']++;
844 }
845 if (!empty($arrayfields['u.fk_user']['checked'])) {
846  print_liste_field_titre("HierarchicalResponsible", $_SERVER['PHP_SELF'], "u.fk_user", $param, "", "", $sortfield, $sortorder);
847  $totalarray['nbfield']++;
848 }
849 if (!empty($arrayfields['u.accountancy_code']['checked'])) {
850  print_liste_field_titre("AccountancyCode", $_SERVER['PHP_SELF'], "u.accountancy_code", $param, "", "", $sortfield, $sortorder);
851  $totalarray['nbfield']++;
852 }
853 if (!empty($arrayfields['u.office_phone']['checked'])) {
854  print_liste_field_titre("PhonePro", $_SERVER['PHP_SELF'], "u.office_phone", $param, "", "", $sortfield, $sortorder);
855  $totalarray['nbfield']++;
856 }
857 if (!empty($arrayfields['u.user_mobile']['checked'])) {
858  print_liste_field_titre("PhoneMobile", $_SERVER['PHP_SELF'], "u.user_mobile", $param, "", "", $sortfield, $sortorder);
859  $totalarray['nbfield']++;
860 }
861 if (!empty($arrayfields['u.email']['checked'])) {
862  print_liste_field_titre("EMail", $_SERVER['PHP_SELF'], "u.email", $param, "", "", $sortfield, $sortorder);
863  $totalarray['nbfield']++;
864 }
865 if (!empty($arrayfields['u.api_key']['checked'])) {
866  print_liste_field_titre("ApiKey", $_SERVER['PHP_SELF'], "u.api_key", $param, "", "", $sortfield, $sortorder);
867  $totalarray['nbfield']++;
868 }
869 if (!empty($arrayfields['u.fk_soc']['checked'])) {
870  print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "u.fk_soc", $param, "", "", $sortfield, $sortorder);
871  $totalarray['nbfield']++;
872 }
873 if (!empty($arrayfields['u.entity']['checked'])) {
874  print_liste_field_titre("Entity", $_SERVER['PHP_SELF'], "u.entity", $param, "", "", $sortfield, $sortorder);
875  $totalarray['nbfield']++;
876 }
877 if (!empty($arrayfields['u.salary']['checked'])) {
878  print_liste_field_titre("Salary", $_SERVER['PHP_SELF'], "u.salary", $param, "", "", $sortfield, $sortorder, 'right ');
879  $totalarray['nbfield']++;
880 }
881 if (!empty($arrayfields['u.datelastlogin']['checked'])) {
882  print_liste_field_titre("LastConnexion", $_SERVER['PHP_SELF'], "u.datelastlogin", $param, "", '', $sortfield, $sortorder, 'center ');
883  $totalarray['nbfield']++;
884 }
885 if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
886  print_liste_field_titre("PreviousConnexion", $_SERVER['PHP_SELF'], "u.datepreviouslogin", $param, "", '', $sortfield, $sortorder, 'center ');
887  $totalarray['nbfield']++;
888 }
889 // Extra fields
890 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
891 // Hook fields
892 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
893 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
894 print $hookmanager->resPrint;
895 if (!empty($arrayfields['u.datec']['checked'])) {
896  print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "u.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
897  $totalarray['nbfield']++;
898 }
899 if (!empty($arrayfields['u.tms']['checked'])) {
900  print_liste_field_titre("DateModificationShort", $_SERVER["PHP_SELF"], "u.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
901  $totalarray['nbfield']++;
902 }
903 if (!empty($arrayfields['u.statut']['checked'])) {
904  print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "u.statut", "", $param, '', $sortfield, $sortorder, 'center ');
905  $totalarray['nbfield']++;
906 }
907 // Action column
908 if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
909  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
910  $totalarray['nbfield']++;
911 }
912 print '</tr>'."\n";
913 
914 
915 // Detect if we need a fetch on each output line
916 $needToFetchEachLine = 0;
917 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
918  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
919  if (preg_match('/\$object/', $val)) {
920  $needToFetchEachLine++; // There is at least one compute field that use $object
921  }
922  }
923 }
924 
925 
926 // Loop on record
927 // --------------------------------------------------------------------
928 $i = 0;
929 $savnbfield = $totalarray['nbfield'];
930 $totalarray['nbfield'] = 0;
931 $imaxinloop = ($limit ? min($num, $limit) : $num);
932 while ($i < $imaxinloop) {
933  $obj = $db->fetch_object($resql);
934  if (empty($obj)) {
935  break; // Should not happen
936  }
937 
938  if (empty($obj->country_code)) $obj->country_code = ''; // TODO Add join in select with country table to get country_code
939 
940  // Store properties in $object
941  $object->setVarsFromFetchObj($obj);
942 
943  $object->id = $obj->rowid;
944  $object->admin = $obj->admin;
945  $object->ref = $obj->rowid;
946  $object->login = $obj->login;
947  $object->statut = $obj->status;
948  $object->status = $obj->status;
949  $object->office_phone = $obj->office_phone;
950  $object->user_mobile = $obj->user_mobile;
951  $object->email = $obj->email;
952  $object->gender = $obj->gender;
953  $object->socid = $obj->fk_soc;
954  $object->firstname = $obj->firstname;
955  $object->lastname = $obj->lastname;
956  $object->employee = $obj->employee;
957  $object->photo = $obj->photo;
958 
959  $li = $object->getNomUrl(-1, '', 0, 0, 24, 1, 'login', '', 1);
960 
961  $canreadhrmdata = 0;
962  if ((!empty($conf->salaries->enabled) && $user->hasRight("salaries", "read") && in_array($obj->rowid, $childids))
963  || (!empty($conf->salaries->enabled) && $user->hasRight("salaries", "readall"))
964  || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
965  $canreadhrmdata = 1;
966  }
967  $canreadsecretapi = 0;
968  if ($user->id == $obj->rowid || !empty($user->admin)) { // Current user or admin
969  $canreadsecretapi = 1;
970  }
971 
972  if ($mode == 'kanban') {
973  if ($i == 0) {
974  print '<tr><td colspan="'.$savnbfield.'">';
975  print '<div class="box-flex-container">';
976  }
977 
978  // Output Kanban
979  print $object->getKanbanView('');
980  if ($i == ($imaxinloop - 1)) {
981  print '</div>';
982  print '</td></tr>';
983  }
984  } else {
985  // Show here line of result
986  $j = 0;
987  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
988  // Action column
989  if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
990  print '<td class="nowrap center">';
991  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
992  $selected = 0;
993  if (in_array($object->id, $arrayofselected)) {
994  $selected = 1;
995  }
996  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
997  }
998  print '</td>';
999  }
1000  // Login
1001  if (!empty($arrayfields['u.login']['checked'])) {
1002  print '<td class="nowraponall tdoverflowmax150">';
1003  print $li;
1004  if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
1005  print img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingleft"');
1006  } elseif ($obj->admin) {
1007  print img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingleft"');
1008  }
1009  print '</td>';
1010  if (!$i) {
1011  $totalarray['nbfield']++;
1012  }
1013  }
1014  if (!empty($arrayfields['u.lastname']['checked'])) {
1015  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>';
1016  if (!$i) {
1017  $totalarray['nbfield']++;
1018  }
1019  }
1020  if (!empty($arrayfields['u.firstname']['checked'])) {
1021  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
1022  if (!$i) {
1023  $totalarray['nbfield']++;
1024  }
1025  }
1026  if (!empty($arrayfields['u.gender']['checked'])) {
1027  print '<td class="center">';
1028  if ($obj->gender) {
1029  // Preparing gender's display if there is one
1030  $addgendertxt = '';
1031  switch ($obj->gender) {
1032  case 'man':
1033  $addgendertxt .= '<i class="fas fa-mars" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
1034  break;
1035  case 'woman':
1036  $addgendertxt .= '<i class="fas fa-venus" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
1037  break;
1038  case 'other':
1039  $addgendertxt .= '<i class="fas fa-transgender" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
1040  break;
1041  }
1042  print $addgendertxt;
1043  //print $langs->trans("Gender".$obj->gender);
1044  }
1045  print '</td>';
1046  if (!$i) {
1047  $totalarray['nbfield']++;
1048  }
1049  }
1050  // Employee yes/no
1051  if (!empty($arrayfields['u.employee']['checked'])) {
1052  print '<td class="center">'.yn($obj->employee).'</td>';
1053  if (!$i) {
1054  $totalarray['nbfield']++;
1055  }
1056  }
1057 
1058  // Supervisor
1059  if (!empty($arrayfields['u.fk_user']['checked'])) {
1060  // Resp
1061  print '<td class="nowrap">';
1062  if ($obj->login2) {
1063  $user2->id = $obj->id2;
1064  $user2->login = $obj->login2;
1065  $user2->lastname = $obj->lastname2;
1066  $user2->firstname = $obj->firstname2;
1067  $user2->gender = $obj->gender2;
1068  $user2->photo = $obj->photo2;
1069  $user2->admin = $obj->admin2;
1070  $user2->office_phone = $obj->office_phone;
1071  $user2->user_mobile = $obj->user_mobile;
1072  $user2->email = $obj->email2;
1073  $user2->socid = $obj->fk_soc2;
1074  $user2->statut = $obj->status2;
1075  $user2->status = $obj->status2;
1076  print $user2->getNomUrl(-1, '', 0, 0, 24, 0, '', '', 1);
1077  if (isModEnabled('multicompany') && $obj->admin2 && !$obj->entity2) {
1078  print img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingleft"');
1079  } elseif ($obj->admin2) {
1080  print img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingleft"');
1081  }
1082  }
1083  print '</td>';
1084  if (!$i) {
1085  $totalarray['nbfield']++;
1086  }
1087  }
1088 
1089  if (!empty($arrayfields['u.accountancy_code']['checked'])) {
1090  print '<td>'.$obj->accountancy_code.'</td>';
1091  if (!$i) {
1092  $totalarray['nbfield']++;
1093  }
1094  }
1095 
1096  // Phone
1097  if (!empty($arrayfields['u.office_phone']['checked'])) {
1098  print '<td class="tdoverflowmax125">'.dol_print_phone($obj->office_phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."</td>\n";
1099  if (!$i) {
1100  $totalarray['nbfield']++;
1101  }
1102  }
1103  if (!empty($arrayfields['u.user_mobile']['checked'])) {
1104  print '<td class="tdoverflowmax125">'.dol_print_phone($obj->user_mobile, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'mobile')."</td>\n";
1105  if (!$i) {
1106  $totalarray['nbfield']++;
1107  }
1108  }
1109  if (!empty($arrayfields['u.email']['checked'])) {
1110  print '<td class="tdoverflowmax150">'.dol_print_email($obj->email, $obj->rowid, $obj->fk_soc, 'AC_EMAIL', 0, 0, 1)."</td>\n";
1111  if (!$i) {
1112  $totalarray['nbfield']++;
1113  }
1114  }
1115  if (!empty($arrayfields['u.api_key']['checked'])) {
1116  print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($obj->api_key).'">';
1117  if ($obj->api_key) {
1118  if ($canreadsecretapi) {
1119  print dol_escape_htmltag($obj->api_key);
1120  } else {
1121  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1122  }
1123  }
1124  print '</td>';
1125  if (!$i) {
1126  $totalarray['nbfield']++;
1127  }
1128  }
1129  if (!empty($arrayfields['u.fk_soc']['checked'])) {
1130  print '<td class="tdoverflowmax150">';
1131  if ($obj->fk_soc > 0) {
1132  $companystatic->id = $obj->fk_soc;
1133  $companystatic->name = $obj->name;
1134  $companystatic->canvas = $obj->canvas;
1135  print $companystatic->getNomUrl(1);
1136  } elseif ($obj->ldap_sid) {
1137  print '<span class="opacitymedium">'.$langs->trans("DomainUser").'</span>';
1138  } else {
1139  print '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
1140  }
1141  print '</td>';
1142  if (!$i) {
1143  $totalarray['nbfield']++;
1144  }
1145  }
1146  // Multicompany enabled
1147  if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1148  if (!empty($arrayfields['u.entity']['checked'])) {
1149  print '<td>';
1150  if (!$obj->entity) {
1151  print $langs->trans("AllEntities");
1152  } else {
1153  $mc->getInfo($obj->entity);
1154  print $mc->label;
1155  }
1156  print '</td>';
1157  if (!$i) {
1158  $totalarray['nbfield']++;
1159  }
1160  }
1161  }
1162 
1163  // Salary
1164  if (!empty($arrayfields['u.salary']['checked'])) {
1165  print '<td class="nowraponall right amount">';
1166  if ($obj->salary) {
1167  if ($canreadhrmdata) {
1168  print price($obj->salary);
1169  } else {
1170  print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1171  }
1172  }
1173  print '</td>';
1174  if (!$i) {
1175  $totalarray['nbfield']++;
1176  }
1177  }
1178 
1179  // Date last login
1180  if (!empty($arrayfields['u.datelastlogin']['checked'])) {
1181  print '<td class="nowrap center">'.dol_print_date($db->jdate($obj->datelastlogin), "dayhour").'</td>';
1182  if (!$i) {
1183  $totalarray['nbfield']++;
1184  }
1185  }
1186  // Date previous login
1187  if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
1188  print '<td class="nowrap center">'.dol_print_date($db->jdate($obj->datepreviouslogin), "dayhour").'</td>';
1189  if (!$i) {
1190  $totalarray['nbfield']++;
1191  }
1192  }
1193 
1194  // Extra fields
1195  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1196  // Fields from hook
1197  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1198  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
1199  print $hookmanager->resPrint;
1200  // Date creation
1201  if (!empty($arrayfields['u.datec']['checked'])) {
1202  print '<td class="center">';
1203  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1204  print '</td>';
1205  if (!$i) {
1206  $totalarray['nbfield']++;
1207  }
1208  }
1209  // Date modification
1210  if (!empty($arrayfields['u.tms']['checked'])) {
1211  print '<td class="center">';
1212  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1213  print '</td>';
1214  if (!$i) {
1215  $totalarray['nbfield']++;
1216  }
1217  }
1218  // Status
1219  if (!empty($arrayfields['u.statut']['checked'])) {
1220  print '<td class="center">'.$object->getLibStatut(5).'</td>';
1221  if (!$i) {
1222  $totalarray['nbfield']++;
1223  }
1224  }
1225  // Action column
1226  if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
1227  print '<td class="nowrap center">';
1228  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1229  $selected = 0;
1230  if (in_array($object->id, $arrayofselected)) {
1231  $selected = 1;
1232  }
1233  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
1234  }
1235  print '</td>';
1236  }
1237  if (!$i) {
1238  $totalarray['nbfield']++;
1239  }
1240 
1241  print '</tr>'."\n";
1242  }
1243 
1244  $i++;
1245 }
1246 
1247 // Show total line
1248 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1249 
1250 // If no record found
1251 if ($num == 0) {
1252  $colspan = 1;
1253  foreach ($arrayfields as $key => $val) {
1254  if (!empty($val['checked'])) {
1255  $colspan++;
1256  }
1257  }
1258  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1259 }
1260 
1261 
1262 $db->free($resql);
1263 
1264 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1265 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
1266 print $hookmanager->resPrint;
1267 
1268 print '</table>'."\n";
1269 print '</div>'."\n";
1270 
1271 print '</form>'."\n";
1272 
1273 
1274 // End of page
1275 llxFooter();
1276 $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 categories.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
Classe permettant la generation de composants html autre Only common components are here.
Class with static methods for building HTML components related to products Only components common to ...
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
Definition: user.class.php:45
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
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
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.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
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.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
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.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
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.