dolibarr  19.0.0-dev
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6  * Copyright (C) 2005-2021 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
8  * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
9  * Copyright (C) 2012-2018 Juanjo Menent <jmenent@2byte.es>
10  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11  * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro@open-dsi.fr>
12  * Copyright (C) 2015-2017 Jean-François Ferry <jfefe@aternatik.fr>
13  * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
14  * Copyright (C) 2015-2018 Charlene Benke <charlie@patas-monkey.com>
15  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
16  * Copyright (C) 2018-2023 Frédéric France <frederic.france@netlogic.fr>
17  * Copyright (C) 2018 David Beniamine <David.Beniamine@Tetras-Libre.fr>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <https://www.gnu.org/licenses/>.
31  */
32 
38 // Load Dolibarr environment
39 require '../main.inc.php';
40 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
49 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
50 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
51 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
52 require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
53 if (isModEnabled('ldap')) {
54  require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
55 }
56 if (isModEnabled('adherent')) {
57  require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
58 }
59 if (isModEnabled('categorie')) {
60  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
61 }
62 if (isModEnabled('stock')) {
63  require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
64 }
65 
66 // Load translation files required by page
67 $langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm', 'stocks', 'other'));
68 
69 $id = GETPOST('id', 'int');
70 $action = GETPOST('action', 'aZ09');
71 $mode = GETPOST('mode', 'alpha');
72 $confirm = GETPOST('confirm', 'alpha');
73 $group = GETPOST("group", "int", 3);
74 $cancel = GETPOST('cancel', 'alpha');
75 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'useracard'; // To manage different context of search
76 
77 if (empty($id)) {
78  $id = $user->id;
79 }
80 
81 $dateemployment = dol_mktime(0, 0, 0, GETPOST('dateemploymentmonth', 'int'), GETPOST('dateemploymentday', 'int'), GETPOST('dateemploymentyear', 'int'));
82 $dateemploymentend = dol_mktime(0, 0, 0, GETPOST('dateemploymentendmonth', 'int'), GETPOST('dateemploymentendday', 'int'), GETPOST('dateemploymentendyear', 'int'));
83 $datestartvalidity = dol_mktime(0, 0, 0, GETPOST('datestartvaliditymonth', 'int'), GETPOST('datestartvalidityday', 'int'), GETPOST('datestartvalidityyear', 'int'));
84 $dateendvalidity = dol_mktime(0, 0, 0, GETPOST('dateendvaliditymonth', 'int'), GETPOST('dateendvalidityday', 'int'), GETPOST('dateendvalidityyear', 'int'));
85 $dateofbirth = dol_mktime(0, 0, 0, GETPOST('dateofbirthmonth', 'int'), GETPOST('dateofbirthday', 'int'), GETPOST('dateofbirthyear', 'int'));
86 
87 $childids = $user->getAllChildIds(1); // For later, test on salary visibility
88 
89 $object = new User($db);
90 $extrafields = new ExtraFields($db);
91 
92 // fetch optionals attributes and labels
93 $extrafields->fetch_name_optionals_label($object->table_element);
94 
95 $socialnetworks = getArrayOfSocialNetworks();
96 
97 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
98 $hookmanager->initHooks(array('usercard', 'globalcard'));
99 
100 $error = 0;
101 
102 $acceptlocallinktomedia = (acceptLocalLinktoMedia() > 0 ? 1 : 0);
103 
104 if ($id > 0) {
105  $res = $object->fetch($id, '', '', 1);
106 }
107 
108 // Security check
109 $socid = 0;
110 if ($user->socid > 0) {
111  $socid = $user->socid;
112 }
113 $feature2 = 'user';
114 $result = restrictedArea($user, 'user', $id, 'user', $feature2);
115 
116 // Define value to know what current user can do on users
117 $canadduser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
118 $canreaduser = (!empty($user->admin) || $user->hasRight("user", "user", "read"));
119 $canedituser = (!empty($user->admin) || $user->hasRight("user", "user", "write")); // edit other user
120 $candisableuser = (!empty($user->admin) || $user->hasRight("user", "user", "delete"));
121 $canreadgroup = $canreaduser;
122 $caneditgroup = $canedituser;
123 if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
124  $canreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
125  $caneditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write"));
126 }
127 
128 if ($user->id != $id && !$canreaduser) {
129  accessforbidden();
130 }
131 
132 // Define value to know what current user can do on properties of edited user
133 if ($id > 0) {
134  // $user is the current logged user, $id is the user we want to edit
135  $canedituser = (($user->id == $id) && $user->hasRight("user", "self", "write")) || (($user->id != $id) && $user->hasRight("user", "user", "write"));
136  $caneditfield = ((($user->id == $id) && $user->hasRight("user", "self", "write")) || (($user->id != $id) && $user->hasRight("user", "user", "write")));
137  $caneditpassword = ((($user->id == $id) && $user->hasRight("user", "self", "password")) || (($user->id != $id) && $user->hasRight("user", "user", "password")));
138 }
139 
140 
145 $parameters = array('id' => $id, 'socid' => $socid, 'group' => $group, 'caneditgroup' => $caneditgroup);
146 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
147 if ($reshook < 0) {
148  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
149 }
150 
151 if (empty($reshook)) {
152  $backurlforlist = DOL_URL_ROOT.'/user/list.php';
153 
154  if (empty($backtopage) || ($cancel && empty($id))) {
155  if (empty($backtopage) || ($cancel && strpos($backtopage, '__ID__'))) {
156  if (empty($id) && (($action != 'add' && $action != 'create') || $cancel)) {
157  $backtopage = $backurlforlist;
158  } else {
159  $backtopage = DOL_URL_ROOT.'/user/card.php?id='.((!empty($id) && $id > 0) ? $id : '__ID__');
160  }
161  }
162  }
163 
164  if ($cancel) {
165  if (!empty($backtopageforcancel)) {
166  header("Location: ".$backtopageforcancel);
167  exit;
168  } elseif (!empty($backtopage)) {
169  header("Location: ".$backtopage);
170  exit;
171  }
172  $action = '';
173  }
174 
175  if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) {
176  if ($id != $user->id) { // A user can't disable itself
177  $object->fetch($id);
178  if ($object->admin && empty($user->admin)) {
179  // If user to delete is an admin user and if logged user is not admin, we deny the operation.
180  $error++;
181  setEventMessages($langs->trans("OnlyAdminUsersCanDisableAdminUsers"), null, 'errors');
182  } else {
183  $object->setstatus(0);
184  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
185  exit;
186  }
187  }
188  }
189 
190  if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser) {
191  $error = 0;
192 
193  if ($id != $user->id) {
194  $object->fetch($id);
195 
196  if (!empty($conf->file->main_limit_users)) {
197  $nb = $object->getNbOfUsers("active");
198  if ($nb >= $conf->file->main_limit_users) {
199  $error++;
200  setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
201  }
202  }
203 
204  if (!$error) {
205  $object->setstatus(1);
206  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
207  exit;
208  }
209  }
210  }
211 
212  if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) {
213  if ($id != $user->id) {
214  if (!GETPOSTISSET('token')) {
215  print 'Error, token required for this critical operation';
216  exit;
217  }
218 
219  $object = new User($db);
220  $object->fetch($id);
221  $object->oldcopy = clone $object;
222 
223  $result = $object->delete($user);
224  if ($result < 0) {
225  $langs->load("errors");
226  setEventMessages($langs->trans("ErrorUserCannotBeDelete"), null, 'errors');
227  } else {
228  setEventMessages($langs->trans("RecordDeleted"), null);
229  header("Location: ".DOL_URL_ROOT."/user/list.php?restore_lastsearch_values=1");
230  exit;
231  }
232  }
233  }
234 
235  // Action Add user
236  if ($action == 'add' && $canadduser) {
237  $error = 0;
238 
239  if (!GETPOST("lastname")) {
240  $error++;
241  setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
242  $action = "create"; // Go back to create page
243  }
244  if (!GETPOST("login")) {
245  $error++;
246  setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
247  $action = "create"; // Go back to create page
248  }
249 
250  if (!empty($conf->file->main_limit_users)) { // If option to limit users is set
251  $nb = $object->getNbOfUsers("active");
252  if ($nb >= $conf->file->main_limit_users) {
253  $error++;
254  setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
255  $action = "create"; // Go back to create page
256  }
257  }
258 
259  if (!$error) {
260  $object->civility_code = GETPOST("civility_code", 'aZ09');
261  $object->lastname = GETPOST("lastname", 'alphanohtml');
262  $object->firstname = GETPOST("firstname", 'alphanohtml');
263  $object->ref_employee = GETPOST("ref_employee", 'alphanohtml');
264  $object->national_registration_number = GETPOST("national_registration_number", 'alphanohtml');
265  $object->login = GETPOST("login", 'alphanohtml');
266  $object->api_key = GETPOST("api_key", 'alphanohtml');
267  $object->gender = GETPOST("gender", 'aZ09');
268  $object->admin = GETPOST("admin", 'int');
269  $object->address = GETPOST('address', 'alphanohtml');
270  $object->zip = GETPOST('zipcode', 'alphanohtml');
271  $object->town = GETPOST('town', 'alphanohtml');
272  $object->country_id = GETPOST('country_id', 'int');
273  $object->state_id = GETPOST('state_id', 'int');
274  $object->office_phone = GETPOST("office_phone", 'alphanohtml');
275  $object->office_fax = GETPOST("office_fax", 'alphanohtml');
276  $object->user_mobile = GETPOST("user_mobile", 'alphanohtml');
277 
278  if (isModEnabled('socialnetworks')) {
279  $object->socialnetworks = array();
280  foreach ($socialnetworks as $key => $value) {
281  if (GETPOST($key, 'alphanohtml')) {
282  $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
283  }
284  }
285  }
286 
287  $object->email = preg_replace('/\s+/', '', GETPOST("email", 'alphanohtml'));
288  $object->job = GETPOST("job", 'alphanohtml');
289  $object->signature = GETPOST("signature", 'restricthtml');
290  $object->accountancy_code = GETPOST("accountancy_code", 'alphanohtml');
291  $object->note_public = GETPOST("note_public", 'restricthtml');
292  $object->note_private = GETPOST("note_private", 'restricthtml');
293  $object->ldap_sid = GETPOST("ldap_sid", 'alphanohtml');
294  $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", 'int') : 0;
295  $object->fk_user_expense_validator = GETPOST("fk_user_expense_validator", 'int') > 0 ? GETPOST("fk_user_expense_validator", 'int') : 0;
296  $object->fk_user_holiday_validator = GETPOST("fk_user_holiday_validator", 'int') > 0 ? GETPOST("fk_user_holiday_validator", 'int') : 0;
297  $object->employee = GETPOST('employee', 'alphanohtml');
298 
299  $object->thm = GETPOST("thm", 'alphanohtml') != '' ? GETPOST("thm", 'alphanohtml') : '';
300  $object->thm = price2num($object->thm);
301  $object->tjm = GETPOST("tjm", 'alphanohtml') != '' ? GETPOST("tjm", 'alphanohtml') : '';
302  $object->tjm = price2num($object->tjm);
303  $object->salary = GETPOST("salary", 'alphanohtml') != '' ? GETPOST("salary", 'alphanohtml') : '';
304  $object->salary = price2num($object->salary);
305  $object->salaryextra = GETPOST("salaryextra", 'alphanohtml') != '' ? GETPOST("salaryextra", 'alphanohtml') : '';
306  $object->weeklyhours = GETPOST("weeklyhours", 'alphanohtml') != '' ? GETPOST("weeklyhours", 'alphanohtml') : '';
307 
308  $object->color = GETPOST("color", 'alphanohtml') != '' ? GETPOST("color", 'alphanohtml') : '';
309 
310  $object->dateemployment = $dateemployment;
311  $object->dateemploymentend = $dateemploymentend;
312  $object->datestartvalidity = $datestartvalidity;
313  $object->dateendvalidity = $dateendvalidity;
314  $object->birth = $dateofbirth;
315 
316  $object->fk_warehouse = GETPOST('fk_warehouse', 'int');
317 
318  $object->lang = GETPOST('default_lang', 'aZ09');
319 
320  // Fill array 'array_options' with data from add form
321  $ret = $extrafields->setOptionalsFromPost(null, $object);
322  if ($ret < 0) {
323  $error++;
324  }
325 
326  // Set entity property
327  $entity = GETPOST('entity', 'int');
328  if (isModEnabled('multicompany')) {
329  if (GETPOST('superadmin', 'int')) {
330  $object->entity = 0;
331  } else {
332  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
333  $object->entity = 1; // all users are forced into master entity
334  } else {
335  $object->entity = ($entity == '' ? 1 : $entity);
336  }
337  }
338  } else {
339  $object->entity = ($entity == '' ? 1 : $entity);
340  /*if ($user->admin && $user->entity == 0 && GETPOST("admin",'alpha'))
341  {
342  }*/
343  }
344 
345  $db->begin();
346 
347  $id = $object->create($user);
348  if ($id > 0) {
349  $resPass = 0;
350  if (GETPOST('password', 'none')) {
351  $resPass = $object->setPassword($user, GETPOST('password', 'none'));
352  }
353  if ($resPass < 0) {
354  $langs->load("errors");
355  $db->rollback();
356  setEventMessages($object->error, $object->errors, 'errors');
357  $action = "create"; // Go back to create page
358  } else {
359  if (isModEnabled("categorie")) {
360  // Categories association
361  $usercats = GETPOST('usercats', 'array');
362  $object->setCategories($usercats);
363  }
364  $db->commit();
365 
366  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
367  exit;
368  }
369  } else {
370  $langs->load("errors");
371  $db->rollback();
372  setEventMessages($object->error, $object->errors, 'errors');
373  $action = "create"; // Go back to create page
374  }
375  }
376  }
377 
378  // Action add usergroup
379  if (($action == 'addgroup' || $action == 'removegroup') && $caneditgroup) {
380  if ($group) {
381  $editgroup = new UserGroup($db);
382  $editgroup->fetch($group);
383  $editgroup->oldcopy = clone $editgroup;
384 
385  $object->fetch($id);
386 
387  if ($action == 'addgroup') {
388  $result = $object->SetInGroup($group, $editgroup->entity);
389  }
390  if ($action == 'removegroup') {
391  $result = $object->RemoveFromGroup($group, $editgroup->entity);
392  }
393 
394  if ($result > 0) {
395  $action = '';
396  } else {
397  setEventMessages($object->error, $object->errors, 'errors');
398  }
399  }
400  }
401 
402  if ($action == 'update' && $canedituser) {
403  require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
404 
405  if ($caneditfield) { // Case we can edit all field
406  $error = 0;
407 
408  if (!GETPOST("lastname", 'alpha')) {
409  setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
410  $action = "edit"; // Go back to create page
411  $error++;
412  }
413  if (!GETPOST("login", 'alpha')) {
414  setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
415  $action = "edit"; // Go back to create page
416  $error++;
417  }
418 
419  if (!$error) {
420  $object->fetch($id);
421 
422  $object->oldcopy = clone $object;
423 
424  $db->begin();
425 
426  $object->civility_code = GETPOST("civility_code", 'aZ09');
427  $object->lastname = GETPOST("lastname", 'alphanohtml');
428  $object->firstname = GETPOST("firstname", 'alphanohtml');
429  /*
430  * Protection against deletion of ref_employee while the field is not present in the user tab
431  */
432  if (GETPOSTISSET("ref_employee")) {
433  $object->ref_employee = GETPOST("ref_employee", 'alphanohtml');
434  }
435  /*
436  * Protection against deletion of national_registration_number while the field is not present in the user tab
437  */
438  if (GETPOSTISSET("national_registration_number")) {
439  $object->national_registration_number = GETPOST("national_registration_number", 'alphanohtml');
440  }
441  $object->gender = GETPOST("gender", 'aZ09');
442  if ($caneditpassword) {
443  $object->pass = GETPOST("password", 'none'); // We can keep 'none' for password fields
444  }
445  if ($caneditpassword || $user->hasRight("api", "apikey", "generate")) {
446  $object->api_key = (GETPOST("api_key", 'alphanohtml')) ? GETPOST("api_key", 'alphanohtml') : $object->api_key;
447  }
448  if (!empty($user->admin) && $user->id != $id) {
449  // admin flag can only be set/unset by an admin user and not four ourself
450  // A test is also done later when forging sql request
451  $object->admin = GETPOST("admin", "int");
452  }
453  if ($user->admin && !$object->ldap_sid) { // same test than on edit page
454  $object->login = GETPOST("login", 'alphanohtml');
455  }
456  $object->address = GETPOST('address', 'alphanohtml');
457  $object->zip = GETPOST('zipcode', 'alphanohtml');
458  $object->town = GETPOST('town', 'alphanohtml');
459  $object->country_id = GETPOST('country_id', 'int');
460  $object->state_id = GETPOST('state_id', 'int');
461  $object->office_phone = GETPOST("office_phone", 'alphanohtml');
462  $object->office_fax = GETPOST("office_fax", 'alphanohtml');
463  $object->user_mobile = GETPOST("user_mobile", 'alphanohtml');
464 
465  if (isModEnabled('socialnetworks')) {
466  $object->socialnetworks = array();
467  foreach ($socialnetworks as $key => $value) {
468  if (GETPOST($key, 'alphanohtml')) {
469  $object->socialnetworks[$key] = GETPOST($key, 'alphanohtml');
470  }
471  }
472  }
473 
474  $object->email = preg_replace('/\s+/', '', GETPOST("email", 'alphanohtml'));
475  $object->job = GETPOST("job", 'alphanohtml');
476  $object->signature = GETPOST("signature", 'restricthtml');
477  $object->accountancy_code = GETPOST("accountancy_code", 'alphanohtml');
478  $object->openid = GETPOST("openid", 'alphanohtml');
479  $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", 'int') : 0;
480  $object->fk_user_expense_validator = GETPOST("fk_user_expense_validator", 'int') > 0 ? GETPOST("fk_user_expense_validator", 'int') : 0;
481  $object->fk_user_holiday_validator = GETPOST("fk_user_holiday_validator", 'int') > 0 ? GETPOST("fk_user_holiday_validator", 'int') : 0;
482  $object->employee = GETPOST('employee', 'int');
483 
484  $object->thm = GETPOST("thm", 'alphanohtml') != '' ? GETPOST("thm", 'alphanohtml') : '';
485  $object->thm = price2num($object->thm);
486  $object->tjm = GETPOST("tjm", 'alphanohtml') != '' ? GETPOST("tjm", 'alphanohtml') : '';
487  $object->thm = price2num($object->thm);
488  $object->salary = GETPOST("salary", 'alphanohtml') != '' ? GETPOST("salary", 'alphanohtml') : '';
489  $object->salary = price2num($object->salary);
490  $object->salaryextra = GETPOST("salaryextra", 'alphanohtml') != '' ? GETPOST("salaryextra", 'alphanohtml') : '';
491  $object->salaryextra = price2num($object->salaryextra);
492  $object->weeklyhours = GETPOST("weeklyhours", 'alphanohtml') != '' ? GETPOST("weeklyhours", 'alphanohtml') : '';
493  $object->weeklyhours = price2num($object->weeklyhours);
494 
495  $object->color = GETPOST("color", 'alphanohtml') != '' ? GETPOST("color", 'alphanohtml') : '';
496  $object->dateemployment = $dateemployment;
497  $object->dateemploymentend = $dateemploymentend;
498  $object->datestartvalidity = $datestartvalidity;
499  $object->dateendvalidity = $dateendvalidity;
500  $object->birth = $dateofbirth;
501 
502  if (isModEnabled('stock')) {
503  $object->fk_warehouse = GETPOST('fk_warehouse', 'int');
504  }
505 
506  $object->lang = GETPOST('default_lang', 'aZ09');
507 
508  // Do we update also ->entity ?
509  if (isModEnabled('multicompany') && empty($user->entity) && !empty($user->admin)) { // If multicompany is not enabled, we never update the entity of a user.
510  if (GETPOST('superadmin', 'int')) {
511  $object->entity = 0;
512  } else {
513  if (!empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
514  $object->entity = 1; // all users are in master entity
515  } else {
516  // We try to change the entity of user
517  $object->entity = (GETPOSTISSET('entity') ? GETPOSTINT('entity') : $object->entity);
518  }
519  }
520  }
521 
522  // Fill array 'array_options' with data from add form
523  $ret = $extrafields->setOptionalsFromPost(null, $object, '@GETPOSTISSET');
524  if ($ret < 0) {
525  $error++;
526  }
527 
528  if (GETPOST('deletephoto')) {
529  $object->photo = '';
530  }
531  if (!empty($_FILES['photo']['name'])) {
532  $isimage = image_format_supported($_FILES['photo']['name']);
533  if ($isimage > 0) {
534  $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
535  } else {
536  $error++;
537  $langs->load("errors");
538  setEventMessages($langs->trans("ErrorBadImageFormat"), null, 'errors');
539  dol_syslog($langs->transnoentities("ErrorBadImageFormat"), LOG_INFO);
540  }
541  }
542 
543  if (!$error) {
544  $passwordismodified = 0;
545  if (!empty($object->pass)) {
546  if ($object->pass != $object->pass_indatabase && !dol_verifyHash($object->pass, $object->pass_indatabase_crypted)) {
547  $passwordismodified = 1;
548  }
549  }
550 
551  $ret = $object->update($user); // This may include call to setPassword if password has changed
552  if ($ret < 0) {
553  $error++;
554  if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS') {
555  $langs->load("errors");
556  setEventMessages($langs->trans("ErrorLoginAlreadyExists", $object->login), null, 'errors');
557  } else {
558  setEventMessages($object->error, $object->errors, 'errors');
559  $action = 'edit';
560  }
561  }
562  }
563 
564  if (!$error && GETPOSTISSET('contactid')) {
565  $contactid = GETPOST('contactid', 'int');
566  $socid = GETPOST('socid', 'int');
567 
568  if ($contactid > 0) { // The 'contactid' is used inpriority over the 'socid'
569  $contact = new Contact($db);
570  $contact->fetch($contactid);
571 
572  $sql = "UPDATE ".MAIN_DB_PREFIX."user";
573  $sql .= " SET fk_socpeople=".((int) $contactid);
574  if (!empty($contact->socid)) {
575  $sql .= ", fk_soc=".((int) $contact->socid);
576  } elseif ($socid > 0) {
577  $sql .= ", fk_soc = null";
578  setEventMessages($langs->trans("WarningUserDifferentContactSocid"), null, 'warnings'); // Add message if post socid != $contact->socid
579  }
580  $sql .= " WHERE rowid = ".((int) $object->id);
581  } elseif ($socid > 0) {
582  $sql = "UPDATE ".MAIN_DB_PREFIX."user";
583  $sql .= " SET fk_socpeople=NULL, fk_soc=".((int) $socid);
584  $sql .= " WHERE rowid = ".((int) $object->id);
585  } else {
586  $sql = "UPDATE ".MAIN_DB_PREFIX."user";
587  $sql .= " SET fk_socpeople=NULL, fk_soc=NULL";
588  $sql .= " WHERE rowid = ".((int) $object->id);
589  }
590  dol_syslog("usercard::update", LOG_DEBUG);
591  $resql = $db->query($sql);
592  if (!$resql) {
593  $error++;
594  setEventMessages($db->lasterror(), null, 'errors');
595  }
596  }
597 
598  if (!$error && !count($object->errors)) {
599  if (GETPOST('deletephoto') && $object->oldcopy->photo) {
600  $fileimg = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, 'user').'photos/'.$object->oldcopy->photo;
601  $dirthumbs = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 0, $object, 'user').'photos/thumbs';
602  dol_delete_file($fileimg);
603  dol_delete_dir_recursive($dirthumbs);
604  }
605 
606  if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name'])) {
607  $dir = $conf->user->dir_output.'/'.get_exdir(0, 0, 0, 1, $object, 'user').'/photos';
608 
609  dol_mkdir($dir);
610 
611  if (@is_dir($dir)) {
612  $newfile = $dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
613  $result = dol_move_uploaded_file($_FILES['photo']['tmp_name'], $newfile, 1, 0, $_FILES['photo']['error']);
614 
615  if (!($result > 0)) {
616  setEventMessages($langs->trans("ErrorFailedToSaveFile"), null, 'errors');
617  } else {
618  // Create thumbs
619  $object->addThumbs($newfile);
620  }
621  } else {
622  $error++;
623  $langs->load("errors");
624  setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
625  }
626  }
627  }
628 
629  if (!$error && !count($object->errors)) {
630  // Then we add the associated categories
631  $categories = GETPOST('usercats', 'array');
632  $object->setCategories($categories);
633  }
634 
635  if (!$error && !count($object->errors)) {
636  setEventMessages($langs->trans("UserModified"), null, 'mesgs');
637  $db->commit();
638 
639  $login = $_SESSION["dol_login"];
640  if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) { // Current user has changed its login
641  $error++;
642  $langs->load("errors");
643  setEventMessages($langs->transnoentitiesnoconv("WarningYourLoginWasModifiedPleaseLogin"), null, 'warnings');
644  }
645  if ($passwordismodified && $object->login == $user->login) { // Current user has changed its password
646  $error++;
647  $langs->load("errors");
648  setEventMessages($langs->transnoentitiesnoconv("WarningYourPasswordWasModifiedPleaseLogin"), null, 'warnings');
649  header("Location: ".DOL_URL_ROOT.'/user/card.php?id='.$object->id);
650  exit;
651  }
652  } else {
653  $db->rollback();
654  }
655  }
656  } else {
657  if ($caneditpassword) { // Case we can edit only password
658  dol_syslog("Not allowed to change fields, only password");
659 
660  $object->fetch($id);
661 
662  if (GETPOST("password", "none")) { // If pass is empty, we do not change it.
663  $object->oldcopy = clone $object;
664 
665  $ret = $object->setPassword($user, GETPOST("password", "none"));
666  if ($ret < 0) {
667  setEventMessages($object->error, $object->errors, 'errors');
668  }
669  }
670  }
671  }
672  }
673 
674  // Change password with a new generated one
675  if ((($action == 'confirm_password' && $confirm == 'yes')
676  || ($action == 'confirm_passwordsend' && $confirm == 'yes')) && $caneditpassword
677  ) {
678  $object->fetch($id);
679 
680  $newpassword = $object->setPassword($user, ''); // This will generate a new password
681  if ($newpassword < 0) {
682  // Echec
683  setEventMessages($langs->trans("ErrorFailedToSetNewPassword"), null, 'errors');
684  } else {
685  // Succes
686  if ($action == 'confirm_passwordsend' && $confirm == 'yes') {
687  if ($object->send_password($user, $newpassword) > 0) {
688  setEventMessages($langs->trans("PasswordChangedAndSentTo", $object->email), null, 'mesgs');
689  } else {
690  setEventMessages($object->error, $object->errors, 'errors');
691  }
692  } else {
693  setEventMessages($langs->trans("PasswordChangedTo", $newpassword), null, 'warnings');
694  }
695  }
696  }
697 
698  // Action initialisation donnees depuis record LDAP
699  if ($action == 'adduserldap' && $canadduser) {
700  $selecteduser = GETPOST('users');
701 
702  $required_fields = array(
703  $conf->global->LDAP_KEY_USERS,
704  $conf->global->LDAP_FIELD_NAME,
705  $conf->global->LDAP_FIELD_FIRSTNAME,
706  $conf->global->LDAP_FIELD_LOGIN,
707  $conf->global->LDAP_FIELD_LOGIN_SAMBA,
708  $conf->global->LDAP_FIELD_PASSWORD,
709  $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
710  $conf->global->LDAP_FIELD_PHONE,
711  $conf->global->LDAP_FIELD_FAX,
712  $conf->global->LDAP_FIELD_MOBILE,
713  $conf->global->LDAP_FIELD_SKYPE,
714  $conf->global->LDAP_FIELD_MAIL,
715  $conf->global->LDAP_FIELD_TITLE,
716  $conf->global->LDAP_FIELD_DESCRIPTION,
717  $conf->global->LDAP_FIELD_SID
718  );
719 
720  $ldap = new Ldap();
721  $result = $ldap->connect_bind();
722  if ($result >= 0) {
723  // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
724  $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement")));
725 
726  $ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
727  //print_r($ldapusers);
728 
729  if (is_array($ldapusers)) {
730  foreach ($ldapusers as $key => $attribute) {
731  $ldap_lastname = $attribute[$conf->global->LDAP_FIELD_NAME];
732  $ldap_firstname = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME];
733  $ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN];
734  $ldap_loginsmb = $attribute[$conf->global->LDAP_FIELD_LOGIN_SAMBA];
735  $ldap_pass = $attribute[$conf->global->LDAP_FIELD_PASSWORD];
736  $ldap_pass_crypted = $attribute[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
737  $ldap_phone = $attribute[$conf->global->LDAP_FIELD_PHONE];
738  $ldap_fax = $attribute[$conf->global->LDAP_FIELD_FAX];
739  $ldap_mobile = $attribute[$conf->global->LDAP_FIELD_MOBILE];
740  $ldap_social['skype'] = $attribute[$conf->global->LDAP_FIELD_SKYPE];
741  $ldap_social['twitter'] = $attribute[$conf->global->LDAP_FIELD_TWITTER];
742  $ldap_social['facebook'] = $attribute[$conf->global->LDAP_FIELD_FACEBOOK];
743  $ldap_social['linkedin'] = $attribute[$conf->global->LDAP_FIELD_LINKEDIN];
744  $ldap_mail = $attribute[$conf->global->LDAP_FIELD_MAIL];
745  $ldap_sid = $attribute[$conf->global->LDAP_FIELD_SID];
746  }
747  }
748  } else {
749  setEventMessages($ldap->error, $ldap->errors, 'errors');
750  }
751  }
752 
753  // Actions to send emails
754  $triggersendname = 'USER_SENTBYMAIL';
755  $paramname = 'id'; // Name of param key to open the card
756  $mode = 'emailfromuser';
757  $trackid = 'use'.$id;
758  include DOL_DOCUMENT_ROOT.'/core/actions_sendmails.inc.php';
759 
760  // Actions to build doc
761  $upload_dir = $conf->user->dir_output;
762  $permissiontoadd = $user->hasRight("user", "user", "write");
763  include DOL_DOCUMENT_ROOT.'/core/actions_builddoc.inc.php';
764 }
765 
766 
767 /*
768  * View
769  */
770 
771 $form = new Form($db);
772 $formother = new FormOther($db);
773 $formcompany = new FormCompany($db);
774 $formadmin = new FormAdmin($db);
775 $formfile = new FormFile($db);
776 if (isModEnabled('stock')) {
777  $formproduct = new FormProduct($db);
778 }
779 
780 if ($object->id > 0) {
781  $person_name = !empty($object->firstname) ? $object->lastname.", ".$object->firstname : $object->lastname;
782  $title = $person_name." - ".$langs->trans('Card');
783 } else {
784  $title = $langs->trans("NewUser");
785 }
786 $help_url = '';
787 
788 llxHeader('', $title, $help_url);
789 
790 
791 if ($action == 'create' || $action == 'adduserldap') {
792  print load_fiche_titre($langs->trans("NewUser"), '', 'user');
793 
794  print '<span class="opacitymedium">'.$langs->trans("CreateInternalUserDesc")."</span><br>\n";
795  print "<br>";
796 
797 
798  if (isModEnabled('ldap') && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && getDolGlobalInt('LDAP_SYNCHRO_ACTIVE') === Ldap::SYNCHRO_LDAP_TO_DOLIBARR)) {
799  // Show form to add an account from LDAP if sync LDAP -> Dolibarr is set
800  $ldap = new Ldap();
801  $result = $ldap->connect_bind();
802  if ($result >= 0) {
803  $required_fields = array(
804  $conf->global->LDAP_KEY_USERS,
805  $conf->global->LDAP_FIELD_FULLNAME,
806  $conf->global->LDAP_FIELD_NAME,
807  $conf->global->LDAP_FIELD_FIRSTNAME,
808  $conf->global->LDAP_FIELD_LOGIN,
809  $conf->global->LDAP_FIELD_LOGIN_SAMBA,
810  $conf->global->LDAP_FIELD_PASSWORD,
811  $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
812  $conf->global->LDAP_FIELD_PHONE,
813  $conf->global->LDAP_FIELD_FAX,
814  $conf->global->LDAP_FIELD_MOBILE,
815  $conf->global->LDAP_FIELD_SKYPE,
816  $conf->global->LDAP_FIELD_MAIL,
817  $conf->global->LDAP_FIELD_TITLE,
818  $conf->global->LDAP_FIELD_DESCRIPTION,
819  $conf->global->LDAP_FIELD_SID
820  );
821 
822  // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
823  $required_fields = array_unique(array_values(array_filter($required_fields, "dol_validElement")));
824 
825  // Get from LDAP database an array of results
826  $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
827 
828  if (is_array($ldapusers)) {
829  $liste = array();
830  foreach ($ldapusers as $key => $ldapuser) {
831  // Define the label string for this user
832  $label = '';
833  foreach ($required_fields as $value) {
834  if ($value === $conf->global->LDAP_FIELD_PASSWORD || $value === $conf->global->LDAP_FIELD_PASSWORD_CRYPTED) {
835  $label .= $value."=******* ";
836  } elseif ($value) {
837  $label .= $value."=".$ldapuser[$value]." ";
838  }
839  }
840  $liste[$key] = $label;
841  }
842  } else {
843  setEventMessages($ldap->error, $ldap->errors, 'errors');
844  }
845  } else {
846  setEventMessages($ldap->error, $ldap->errors, 'errors');
847  }
848 
849  // If user list is full, we show drop-down list
850  print "\n\n<!-- Form liste LDAP debut -->\n";
851 
852  print '<form name="add_user_ldap" action="'.$_SERVER["PHP_SELF"].'" method="post">';
853  print '<input type="hidden" name="token" value="'.newToken().'">';
854  print '<table class="border centpercent"><tr>';
855  print '<td width="160">';
856  print $langs->trans("LDAPUsers");
857  print '</td>';
858  print '<td>';
859  print '<input type="hidden" name="action" value="adduserldap">';
860  if (is_array($liste) && count($liste)) {
861  print $form->selectarray('users', $liste, '', 1, 0, 0, '', 0, 0, 0, '', 'maxwidth500');
862  print ajax_combobox('users');
863  }
864  print '</td><td class="center">';
865  print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Get')).'"'.(count($liste) ? '' : ' disabled').'>';
866  print '</td></tr></table>';
867  print '</form>';
868 
869  print "\n<!-- Form liste LDAP fin -->\n\n";
870  print '<br>';
871  }
872 
873 
874  print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="createuser">';
875  print '<input type="hidden" name="token" value="'.newToken().'">';
876  print '<input type="hidden" name="action" value="add">';
877  if (!empty($ldap_sid)) {
878  print '<input type="hidden" name="ldap_sid" value="'.dol_escape_htmltag($ldap_sid).'">';
879  }
880  print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
881 
882  print dol_get_fiche_head('', '', '', 0, '');
883 
884  dol_set_focus('#lastname');
885 
886  print '<table class="border centpercent">';
887 
888  // Civility
889  print '<tr><td><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
890  print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
891  print '</td></tr>';
892 
893  // Lastname
894  print '<tr>';
895  print '<td class="titlefieldcreate"><span class="fieldrequired">'.$langs->trans("Lastname").'</span></td>';
896  print '<td>';
897  if (!empty($ldap_lastname)) {
898  print '<input type="hidden" id="lastname" name="lastname" value="'.dol_escape_htmltag($ldap_lastname).'">';
899  print $ldap_lastname;
900  } else {
901  print '<input class="minwidth100 maxwidth150onsmartphone createloginauto" type="text" id="lastname" name="lastname" value="'.dol_escape_htmltag(GETPOST('lastname', 'alphanohtml')).'">';
902  }
903  print '</td></tr>';
904 
905  // Firstname
906  print '<tr><td>'.$langs->trans("Firstname").'</td>';
907  print '<td>';
908  if (!empty($ldap_firstname)) {
909  print '<input type="hidden" name="firstname" value="'.dol_escape_htmltag($ldap_firstname).'">';
910  print $ldap_firstname;
911  } else {
912  print '<input id="firstname" class="minwidth100 maxwidth150onsmartphone createloginauto" type="text" name="firstname" value="'.dol_escape_htmltag(GETPOST('firstname', 'alphanohtml')).'">';
913  }
914  print '</td></tr>';
915 
916  // Login
917  print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
918  print '<td>';
919  if (!empty($ldap_login)) {
920  print '<input type="hidden" name="login" value="'.dol_escape_htmltag($ldap_login).'">';
921  print $ldap_login;
922  } elseif (!empty($ldap_loginsmb)) {
923  print '<input type="hidden" name="login" value="'.dol_escape_htmltag($ldap_loginsmb).'">';
924  print $ldap_loginsmb;
925  } else {
926  print '<input id="login" class="maxwidth200 maxwidth150onsmartphone" maxsize="24" type="text" name="login" value="'.dol_escape_htmltag(GETPOST('login', 'alphanohtml')).'">';
927  }
928  print '</td></tr>';
929 
930  if (!empty($conf->use_javascript_ajax)) {
931  print '<script>
932  jQuery(document).ready(function() {
933  $(".createloginauto").on("change", function(){
934  lastname = $("#lastname").val();
935  firstname = $("#firstname").val();
936  if($(this).attr("id") == "firstname"){
937  firstname = firstname.toLowerCase();
938  firstname = firstname[0];
939  }
940  lastname = lastname.toLowerCase();
941  console.log("We create a login from firstname and lastname");
942  $("#login").val(firstname+lastname);
943  })
944  });
945  </script>';
946  }
947 
948  $generated_password = '';
949  if (empty($ldap_sid)) { // ldap_sid is for activedirectory
950  $generated_password = getRandomPassword(false);
951  }
952  $password = (GETPOSTISSET('password') ?GETPOST('password') : $generated_password);
953 
954  // Administrator
955  if (!empty($user->admin)) {
956  print '<tr><td>'.$langs->trans("Administrator").'</td>';
957  print '<td>';
958  print $form->selectyesno('admin', GETPOST('admin'), 1, false, 0, 1);
959 
960  if (isModEnabled('multicompany') && !$user->entity) {
961  if (!empty($conf->use_javascript_ajax)) {
962  print '<script type="text/javascript">
963  $(function() {
964  $("select[name=admin]").change(function() {
965  if ( $(this).val() == 0 ) {
966  $("input[name=superadmin]")
967  .prop("disabled", true)
968  .prop("checked", false);
969  $("select[name=entity]")
970  .prop("disabled", false);
971  } else {
972  $("input[name=superadmin]")
973  .prop("disabled", false);
974  }
975  });
976  $("input[name=superadmin]").change(function() {
977  if ( $(this).is(":checked") ) {
978  $("select[name=entity]")
979  .prop("disabled", true);
980  } else {
981  $("select[name=entity]")
982  .prop("disabled", false);
983  }
984  });
985  });
986  </script>';
987  }
988  $checked = (GETPOST('superadmin', 'int') ? ' checked' : '');
989  $disabled = (GETPOST('superadmin', 'int') ? '' : ' disabled');
990  print '<input type="checkbox" name="superadmin" id="superadmin" value="1"'.$checked.$disabled.' /> <label for="superadmin">'.$langs->trans("SuperAdministrator").'</span>';
991  }
992  print "</td></tr>\n";
993  }
994 
995  // Gender
996  print '<tr><td>'.$langs->trans("Gender").'</td>';
997  print '<td>';
998  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
999  print $form->selectarray('gender', $arraygender, GETPOST('gender'), 1);
1000  print '</td></tr>';
1001 
1002  // Employee
1003  $defaultemployee = '1';
1004  print '<tr>';
1005  print '<td>'.$langs->trans('Employee').'</td><td>';
1006  print '<input type="checkbox" name="employee" value="1"'.(GETPOST('employee') == '1' ? ' checked="checked"' : (($defaultemployee && !GETPOSTISSET('login')) ? ' checked="checked"' : '')).'>';
1007  //print $form->selectyesno("employee", (GETPOST('employee') != '' ?GETPOST('employee') : $defaultemployee), 1);
1008  print '</td></tr>';
1009 
1010  // Hierarchy
1011  print '<tr><td class="titlefieldcreate">'.$langs->trans("HierarchicalResponsible").'</td>';
1012  print '<td>';
1013  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $conf->entity, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
1014  print '</td>';
1015  print "</tr>\n";
1016 
1017  // Expense report validator
1018  if (isModEnabled('expensereport')) {
1019  print '<tr><td class="titlefieldcreate">';
1020  $text = $langs->trans("ForceUserExpenseValidator");
1021  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
1022  print '</td>';
1023  print '<td>';
1024  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user_expense_validator, 'fk_user_expense_validator', 1, array($object->id), 0, '', 0, $conf->entity, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
1025  print '</td>';
1026  print "</tr>\n";
1027  }
1028 
1029  // Holiday request validator
1030  if (isModEnabled('holiday')) {
1031  print '<tr><td class="titlefieldcreate">';
1032  $text = $langs->trans("ForceUserHolidayValidator");
1033  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
1034  print '</td>';
1035  print '<td>';
1036  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user_holiday_validator, 'fk_user_holiday_validator', 1, array($object->id), 0, '', 0, $conf->entity, 0, 0, '', 0, '', 'maxwidth300 widthcentpercentminusx');
1037  print '</td>';
1038  print "</tr>\n";
1039  }
1040 
1041  // External user
1042  print '<tr><td>'.$langs->trans("ExternalUser").' ?</td>';
1043  print '<td>';
1044  print $form->textwithpicto($langs->trans("Internal"), $langs->trans("InternalExternalDesc"), 1, 'help', '', 0, 2);
1045  print '</td></tr>';
1046 
1047 
1048  print '</table><hr><table class="border centpercent">';
1049 
1050 
1051  // Date validity
1052  print '<tr><td class="titlefieldcreate">'.$langs->trans("RangeOfLoginValidity").'</td>';
1053  print '<td>';
1054  print $form->selectDate($datestartvalidity, 'datestartvalidity', 0, 0, 1, 'formdatestartvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("from"));
1055 
1056  print ' &nbsp; ';
1057 
1058  print $form->selectDate($dateendvalidity, 'dateendvalidity', 0, 0, 1, 'formdateendvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1059  print '</td>';
1060  print "</tr>\n";
1061 
1062  // Password
1063  print '<tr><td class="fieldrequired">'.$langs->trans("Password").'</td>';
1064  print '<td>';
1065  $valuetoshow = '';
1066  if (preg_match('/ldap/', $dolibarr_main_authentication)) {
1067  $valuetoshow .= ($valuetoshow ? ' + ' : '').$langs->trans("PasswordOfUserInLDAP").' (hidden)';
1068  }
1069  if (preg_match('/http/', $dolibarr_main_authentication)) {
1070  $valuetoshow .= ($valuetoshow ? ' + ' : '').$langs->trans("HTTPBasicPassword");
1071  }
1072  if (preg_match('/dolibarr/', $dolibarr_main_authentication) || preg_match('/forceuser/', $dolibarr_main_authentication)) {
1073  if (!empty($ldap_pass)) { // For very old system comaptibilty. Now clear password can't be viewed from LDAP read
1074  $valuetoshow .= ($valuetoshow ? ' + ' : '').'<input type="hidden" name="password" value="'.dol_escape_htmltag($ldap_pass).'">'; // Dolibarr password is preffiled with LDAP known password
1075  $valuetoshow .= preg_replace('/./i', '*', $ldap_pass);
1076  } else {
1077  // We do not use a field password but a field text to show new password to use.
1078  $valuetoshow .= ($valuetoshow ? ' + '.$langs->trans("DolibarrPassword") : '').'<input class="minwidth300 maxwidth400 widthcentpercentminusx" maxlength="128" type="text" id="password" name="password" value="'.dol_escape_htmltag($password).'" autocomplete="new-password">';
1079  if (!empty($conf->use_javascript_ajax)) {
1080  $valuetoshow .= img_picto($langs->trans('Generate'), 'refresh', 'id="generate_password" class="linkobject paddingleft"');
1081  }
1082  }
1083  }
1084 
1085  // Other form for user password
1086  $parameters = array('valuetoshow' => $valuetoshow, 'password' => $password);
1087  $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1088  if ($reshook > 0) {
1089  $valuetoshow = $hookmanager->resPrint; // to replace
1090  } else {
1091  $valuetoshow .= $hookmanager->resPrint; // to add
1092  }
1093 
1094  print $valuetoshow;
1095  print '</td></tr>';
1096 
1097  if (isModEnabled('api')) {
1098  // API key
1099  //$generated_password = getRandomPassword(false);
1100  print '<tr><td>'.$langs->trans("ApiKey").'</td>';
1101  print '<td>';
1102  print '<input class="minwidth300 maxwidth400 widthcentpercentminusx" minlength="12" maxlength="128" type="text" id="api_key" name="api_key" value="'.GETPOST('api_key', 'alphanohtml').'" autocomplete="off">';
1103  if (!empty($conf->use_javascript_ajax)) {
1104  print img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject paddingleft"');
1105  }
1106  print '</td></tr>';
1107  } else {
1108  // PARTIAL WORKAROUND
1109  $generated_fake_api_key = getRandomPassword(false);
1110  print '<input type="hidden" name="api_key" value="'.$generated_fake_api_key.'">';
1111  }
1112 
1113 
1114  print '</table><hr><table class="border centpercent">';
1115 
1116 
1117  // Address
1118  print '<tr><td class="tdtop titlefieldcreate">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
1119  print '<td><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
1120  print $object->address;
1121  print '</textarea></td></tr>';
1122 
1123  // Zip
1124  print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
1125  print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
1126  print '</td></tr>';
1127 
1128  // Town
1129  print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
1130  print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
1131  print '</td></tr>';
1132 
1133  // Country
1134  print '<tr><td>'.$form->editfieldkey('Country', 'selectcountry_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1135  print img_picto('', 'country', 'class="pictofixedwidth"');
1136  print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id));
1137  if ($user->admin) {
1138  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
1139  }
1140  print '</td></tr>';
1141 
1142  // State
1143  if (empty($conf->global->USER_DISABLE_STATE)) {
1144  print '<tr><td>'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td class="maxwidthonsmartphone">';
1145  print img_picto('', 'state', 'class="pictofixedwidth"');
1146  print $formcompany->select_state($object->state_id, $object->country_code, 'state_id');
1147  print '</td></tr>';
1148  }
1149 
1150  // Tel
1151  print '<tr><td>'.$langs->trans("PhonePro").'</td>';
1152  print '<td>';
1153  print img_picto('', 'object_phoning', 'class="pictofixedwidth"');
1154  if (!empty($ldap_phone)) {
1155  print '<input type="hidden" name="office_phone" value="'.dol_escape_htmltag($ldap_phone).'">';
1156  print $ldap_phone;
1157  } else {
1158  print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="office_phone" value="'.dol_escape_htmltag(GETPOST('office_phone', 'alphanohtml')).'">';
1159  }
1160  print '</td></tr>';
1161 
1162  // Tel portable
1163  print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
1164  print '<td>';
1165  print img_picto('', 'object_phoning_mobile', 'class="pictofixedwidth"');
1166  if (!empty($ldap_mobile)) {
1167  print '<input type="hidden" name="user_mobile" value="'.dol_escape_htmltag($ldap_mobile).'">';
1168  print $ldap_mobile;
1169  } else {
1170  print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="user_mobile" value="'.dol_escape_htmltag(GETPOST('user_mobile', 'alphanohtml')).'">';
1171  }
1172  print '</td></tr>';
1173 
1174  // Fax
1175  print '<tr><td>'.$langs->trans("Fax").'</td>';
1176  print '<td>';
1177  print img_picto('', 'object_phoning_fax', 'class="pictofixedwidth"');
1178  if (!empty($ldap_fax)) {
1179  print '<input type="hidden" name="office_fax" value="'.dol_escape_htmltag($ldap_fax).'">';
1180  print $ldap_fax;
1181  } else {
1182  print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="office_fax" value="'.dol_escape_htmltag(GETPOST('office_fax', 'alphanohtml')).'">';
1183  }
1184  print '</td></tr>';
1185 
1186  // EMail
1187  print '<tr><td'.(!empty($conf->global->USER_MAIL_REQUIRED) ? ' class="fieldrequired"' : '').'>'.$langs->trans("EMail").'</td>';
1188  print '<td>';
1189  print img_picto('', 'object_email', 'class="pictofixedwidth"');
1190  if (!empty($ldap_mail)) {
1191  print '<input type="hidden" name="email" value="'.dol_escape_htmltag($ldap_mail).'">';
1192  print $ldap_mail;
1193  } else {
1194  print '<input type="text" name="email" class="maxwidth500 widthcentpercentminusx" value="'.dol_escape_htmltag(GETPOST('email', 'alphanohtml')).'">';
1195  }
1196  print '</td></tr>';
1197 
1198  // Social networks
1199  if (isModEnabled('socialnetworks')) {
1200  foreach ($socialnetworks as $key => $value) {
1201  if ($value['active']) {
1202  print '<tr><td>'.$langs->trans($value['label']).'</td>';
1203  print '<td>';
1204  if (!empty($value['icon'])) {
1205  print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
1206  }
1207  if (!empty($ldap_social[$key])) {
1208  print '<input type="hidden" name="'.$key.'" value="'.$ldap_social[$key].'">';
1209  print $ldap_social[$key];
1210  } else {
1211  print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="'.$key.'" value="'.GETPOST($key, 'alphanohtml').'">';
1212  }
1213  print '</td></tr>';
1214  } else {
1215  // if social network is not active but value exist we do not want to loose it
1216  if (!empty($ldap_social[$key])) {
1217  print '<input type="hidden" name="'.$key.'" value="'.$ldap_social[$key].'">';
1218  } else {
1219  print '<input type="hidden" name="'.$key.'" value="'.GETPOST($key, 'alphanohtml').'">';
1220  }
1221  }
1222  }
1223  }
1224 
1225  // Accountancy code
1226  if (isModEnabled('accounting')) {
1227  print '<tr><td>'.$langs->trans("AccountancyCode").'</td>';
1228  print '<td>';
1229  print '<input type="text" class="maxwidthonsmartphone" name="accountancy_code" value="'.dol_escape_htmltag(GETPOST('accountancy_code', 'alphanohtml')).'">';
1230  print '</td></tr>';
1231  }
1232 
1233  // User color
1234  if (isModEnabled('agenda')) {
1235  print '<tr><td>'.$langs->trans("ColorUser").'</td>';
1236  print '<td>';
1237  print $formother->selectColor(GETPOSTISSET('color') ?GETPOST('color', 'alphanohtml') : $object->color, 'color', null, 1, '', 'hideifnotset');
1238  print '</td></tr>';
1239  }
1240 
1241  // Categories
1242  if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
1243  print '<tr><td>'.$form->editfieldkey('Categories', 'usercats', '', $object, 0).'</td><td>';
1244  $cate_arbo = $form->select_all_categories('user', null, 'parent', null, null, 1);
1245  print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), 0, 0, 'maxwdith300 widthcentpercentminusx', 0, '90%');
1246  print "</td></tr>";
1247  }
1248 
1249  // Default language
1250  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1251  print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0, 'string', '', 0, 0, 'id', $langs->trans("WarningNotLangOfInterface", $langs->transnoentitiesnoconv("UserGUISetup"))).'</td>';
1252  print '<td class="maxwidthonsmartphone">'."\n";
1253  print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ?GETPOST('default_lang', 'alpha') : ($object->lang ? $object->lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth300 widthcentpercentminusx');
1254  print '</td>';
1255  print '</tr>';
1256  }
1257 
1258  // Multicompany
1259  if (isModEnabled('multicompany') && is_object($mc)) {
1260  // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
1261  if (!method_exists($mc, 'formObjectOptions')) {
1262  if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) { // condition must be same for create and edit mode
1263  print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
1264  print "<td>".$mc->select_entities($conf->entity);
1265  print "</td></tr>\n";
1266  } else {
1267  print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
1268  }
1269  }
1270  }
1271 
1272  // Other attributes
1273  $parameters = array();
1274  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
1275 
1276  // Signature
1277  print '<tr><td class="tdtop">'.$langs->trans("Signature").'</td>';
1278  print '<td class="wordbreak">';
1279  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1280 
1281  $doleditor = new DolEditor('signature', GETPOST('signature', 'restricthtml'), '', 138, 'dolibarr_notes', 'In', true, $acceptlocallinktomedia, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
1282  print $doleditor->Create(1);
1283  print '</td></tr>';
1284 
1285  // Note private
1286  print '<tr><td class="tdtop">';
1287  print $langs->trans("NotePublic");
1288  print '</td><td>';
1289  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1290  $doleditor = new DolEditor('note_public', GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : '', '', 100, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC'), ROWS_3, '90%');
1291  $doleditor->Create();
1292  print "</td></tr>\n";
1293 
1294  // Note private
1295  print '<tr><td class="tdtop">';
1296  print $langs->trans("NotePrivate");
1297  print '</td><td>';
1298  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
1299  $doleditor = new DolEditor('note_private', GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : '', '', 100, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_3, '90%');
1300  $doleditor->Create();
1301  print "</td></tr>\n";
1302 
1303  print '</table><hr><table class="border centpercent">';
1304 
1305 
1306  // TODO Move this into tab RH (HierarchicalResponsible must be on both tab)
1307 
1308  // Default warehouse
1309  if (isModEnabled('stock') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1310  print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
1311  print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
1312  print '</td></tr>';
1313  }
1314 
1315  // Position/Job
1316  print '<tr><td class="titlefieldcreate">'.$langs->trans("PostOrFunction").'</td>';
1317  print '<td>';
1318  print '<input class="maxwidth200 maxwidth150onsmartphone" type="text" name="job" value="'.dol_escape_htmltag(GETPOST('job', 'alphanohtml')).'">';
1319  print '</td></tr>';
1320 
1321  if ((isModEnabled('salaries') && $user->hasRight("salaries", "read") && in_array($id, $childids))
1322  || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
1323  || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
1324  $langs->load("salaries");
1325 
1326  // THM
1327  print '<tr><td>';
1328  $text = $langs->trans("THM");
1329  print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
1330  print '</td>';
1331  print '<td>';
1332  print '<input size="8" type="text" name="thm" value="'.dol_escape_htmltag(GETPOST('thm')).'"> '.$langs->getCurrencySymbol($conf->currency);
1333  print '</td>';
1334  print "</tr>\n";
1335 
1336  // TJM
1337  print '<tr><td>';
1338  $text = $langs->trans("TJM");
1339  print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
1340  print '</td>';
1341  print '<td>';
1342  print '<input size="8" type="text" name="tjm" value="'.dol_escape_htmltag(GETPOST('tjm')).'"> '.$langs->getCurrencySymbol($conf->currency);
1343  print '</td>';
1344  print "</tr>\n";
1345 
1346  // Salary
1347  print '<tr><td>'.$langs->trans("Salary").'</td>';
1348  print '<td>';
1349  print img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<input class="width100" type="text" name="salary" value="'.dol_escape_htmltag(GETPOST('salary')).'"> '.$langs->getCurrencySymbol($conf->currency);
1350  print '</td>';
1351  print "</tr>\n";
1352  }
1353 
1354  // Weeklyhours
1355  print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
1356  print '<td>';
1357  print '<input size="8" type="text" name="weeklyhours" value="'.dol_escape_htmltag(GETPOST('weeklyhours')).'">';
1358  print '</td>';
1359  print "</tr>\n";
1360 
1361  // Date employment
1362  print '<tr><td>'.$langs->trans("DateOfEmployment").'</td>';
1363  print '<td>';
1364  print $form->selectDate($dateemployment, 'dateemployment', 0, 0, 1, 'formdateemployment', 1, 1, 0, '', '', '', '', 1, '', $langs->trans("from"));
1365 
1366  print ' - ';
1367 
1368  print $form->selectDate($dateemploymentend, 'dateemploymentend', 0, 0, 1, 'formdateemploymentend', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
1369  print '</td>';
1370  print "</tr>\n";
1371 
1372  // Date birth
1373  print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
1374  print '<td>';
1375  print $form->selectDate($dateofbirth, 'dateofbirth', 0, 0, 1, 'createuser', 1, 0, 0, '', 0, '', '', 1, '', '', 'tzserver');
1376  print '</td>';
1377  print "</tr>\n";
1378 
1379  print "</table>\n";
1380 
1381  print dol_get_fiche_end();
1382 
1383  print $form->buttonsSaveCancel("CreateUser");
1384 
1385  print "</form>";
1386 } else {
1387  // View and edit mode
1388  if ($id > 0) {
1389  $res = $object->fetch($id, '', '', 1);
1390  if ($res < 0) {
1391  dol_print_error($db, $object->error);
1392  exit;
1393  }
1394  $res = $object->fetch_optionals();
1395 
1396  // Check if user has rights
1397  if (empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
1398  $object->getrights();
1399  if (empty($object->nb_rights) && $object->statut != 0 && empty($object->admin)) {
1400  setEventMessages($langs->trans('UserHasNoPermissions'), null, 'warnings');
1401  }
1402  }
1403 
1404  // Connexion ldap
1405  // pour recuperer passDoNotExpire et userChangePassNextLogon
1406  if (isModEnabled('ldap') && !empty($object->ldap_sid)) {
1407  $ldap = new Ldap();
1408  $result = $ldap->connect_bind();
1409  if ($result > 0) {
1410  $userSearchFilter = '('.$conf->global->LDAP_FILTER_CONNECTION.'('.$ldap->getUserIdentifier().'='.$object->login.'))';
1411  $entries = $ldap->fetch($object->login, $userSearchFilter);
1412  if (!$entries) {
1413  setEventMessages($ldap->error, $ldap->errors, 'errors');
1414  }
1415 
1416  $passDoNotExpire = 0;
1417  $userChangePassNextLogon = 0;
1418  $userDisabled = 0;
1419  $statutUACF = '';
1420 
1421  // Check options of user account
1422  if (count($ldap->uacf) > 0) {
1423  foreach ($ldap->uacf as $key => $statut) {
1424  if ($key == 65536) {
1425  $passDoNotExpire = 1;
1426  $statutUACF = $statut;
1427  }
1428  }
1429  } else {
1430  $userDisabled = 1;
1431  $statutUACF = "ACCOUNTDISABLE";
1432  }
1433 
1434  if ($ldap->pwdlastset == 0) {
1435  $userChangePassNextLogon = 1;
1436  }
1437  }
1438  }
1439 
1440  // Show tabs
1441  if ($mode == 'employee') { // For HRM module development
1442  $title = $langs->trans("Employee");
1443  $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/employee/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1444  } else {
1445  $title = $langs->trans("User");
1446  $linkback = '';
1447 
1448  if ($user->hasRight("user", "user", "read") || $user->admin) {
1449  $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
1450  }
1451  }
1452 
1453  $head = user_prepare_head($object);
1454 
1455  /*
1456  * Confirmation reinitialisation mot de passe
1457  */
1458  if ($action == 'password') {
1459  print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("ReinitPassword"), $langs->trans("ConfirmReinitPassword", $object->login), "confirm_password", '', 0, 1);
1460  }
1461 
1462  /*
1463  * Confirmation envoi mot de passe
1464  */
1465  if ($action == 'passwordsend') {
1466  print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("SendNewPassword"), $langs->trans("ConfirmSendNewPassword", $object->login), "confirm_passwordsend", '', 0, 1);
1467  }
1468 
1469  /*
1470  * Confirm deactivation
1471  */
1472  if ($action == 'disable') {
1473  print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("DisableAUser"), $langs->trans("ConfirmDisableUser", $object->login), "confirm_disable", '', 0, 1);
1474  }
1475 
1476  /*
1477  * Confirm activation
1478  */
1479  if ($action == 'enable') {
1480  print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("EnableAUser"), $langs->trans("ConfirmEnableUser", $object->login), "confirm_enable", '', 0, 1);
1481  }
1482 
1483  /*
1484  * Confirmation suppression
1485  */
1486  if ($action == 'delete') {
1487  print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("DeleteAUser"), $langs->trans("ConfirmDeleteUser", $object->login), "confirm_delete", '', 0, 1);
1488  }
1489 
1490  /*
1491  * Fiche en mode visu
1492  */
1493  if ($action != 'edit') {
1494  print dol_get_fiche_head($head, 'user', $title, -1, 'user');
1495 
1496  $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener" rel="noopener">';
1497  $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard").' ('.$langs->trans("AddToContacts").')', 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
1498  $morehtmlref .= '</a>';
1499 
1500  $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
1501  $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->trans("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
1502 
1503  dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
1504 
1505  print '<div class="fichecenter">';
1506  print '<div class="fichehalfleft">';
1507 
1508  print '<div class="underbanner clearboth"></div>';
1509  print '<table class="border tableforfield centpercent">';
1510 
1511  // Login
1512  print '<tr><td class="titlefieldmiddle">'.$langs->trans("Login").'</td>';
1513  if (!empty($object->ldap_sid) && $object->statut == 0) {
1514  print '<td class="error">';
1515  print $langs->trans("LoginAccountDisableInDolibarr");
1516  print '</td>';
1517  } else {
1518  print '<td>';
1519  $addadmin = '';
1520  if (property_exists($object, 'admin')) {
1521  if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
1522  $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
1523  } elseif (!empty($object->admin)) {
1524  $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
1525  }
1526  }
1527  print showValueWithClipboardCPButton($object->login).$addadmin;
1528  print '</td>';
1529  }
1530  print '</tr>'."\n";
1531 
1532  // Type
1533  print '<tr><td>';
1534  $text = $langs->trans("Type");
1535  print $form->textwithpicto($text, $langs->trans("InternalExternalDesc"));
1536  print '</td><td>';
1537  $type = $langs->trans("Internal");
1538  if ($object->socid > 0) {
1539  $type = $langs->trans("External");
1540  }
1541  print '<span class="badgeneutral">';
1542  print $type;
1543  if ($object->ldap_sid) {
1544  print ' ('.$langs->trans("DomainUser").')';
1545  }
1546  print '</span>';
1547  print '</td></tr>'."\n";
1548 
1549  // Ldap sid
1550  if ($object->ldap_sid) {
1551  print '<tr><td>'.$langs->trans("Type").'</td><td>';
1552  print $langs->trans("DomainUser", $ldap->domainFQDN);
1553  print '</td></tr>'."\n";
1554  }
1555 
1556  // Employee
1557  print '<tr><td>'.$langs->trans("Employee").'</td><td>';
1558  print '<input type="checkbox" disabled name="employee" value="1"'.($object->employee ? ' checked="checked"' : '').'>';
1559  //print yn($object->employee);
1560  print '</td></tr>'."\n";
1561 
1562  // TODO This is also available into the tab RH
1563 
1564  // Hierarchy
1565  print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
1566  print '<td>';
1567  if (empty($object->fk_user)) {
1568  print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
1569  } else {
1570  $huser = new User($db);
1571  if ($object->fk_user > 0) {
1572  $huser->fetch($object->fk_user);
1573  print $huser->getNomUrl(-1);
1574  } else {
1575  print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
1576  }
1577  }
1578  print '</td>';
1579  print "</tr>\n";
1580 
1581  // Expense report validator
1582  if (isModEnabled('expensereport')) {
1583  print '<tr><td>';
1584  $text = $langs->trans("ForceUserExpenseValidator");
1585  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
1586  print '</td>';
1587  print '<td>';
1588  if (!empty($object->fk_user_expense_validator)) {
1589  $evuser = new User($db);
1590  $evuser->fetch($object->fk_user_expense_validator);
1591  print $evuser->getNomUrl(-1);
1592  }
1593  print '</td>';
1594  print "</tr>\n";
1595  }
1596 
1597  // Holiday request validator
1598  if (isModEnabled('holiday')) {
1599  print '<tr><td>';
1600  $text = $langs->trans("ForceUserHolidayValidator");
1601  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
1602  print '</td>';
1603  print '<td>';
1604  if (!empty($object->fk_user_holiday_validator)) {
1605  $hvuser = new User($db);
1606  $hvuser->fetch($object->fk_user_holiday_validator);
1607  print $hvuser->getNomUrl(-1);
1608  }
1609  print '</td>';
1610  print "</tr>\n";
1611  }
1612 
1613  // Position/Job
1614  print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
1615  print '<td>'.dol_escape_htmltag($object->job).'</td>';
1616  print '</tr>'."\n";
1617 
1618  // Weeklyhours
1619  print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
1620  print '<td>';
1621  print price2num($object->weeklyhours);
1622  print '</td>';
1623  print "</tr>\n";
1624 
1625  // Sensitive salary/value information
1626  if ((empty($user->socid) && in_array($id, $childids)) // A user can always see salary/value information for its subordinates
1627  || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
1628  || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
1629  $langs->load("salaries");
1630 
1631  // Salary
1632  print '<tr><td>'.$langs->trans("Salary").'</td>';
1633  print '<td>';
1634  print ($object->salary != '' ? img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<span class="amount">'.price($object->salary, '', $langs, 1, -1, -1, $conf->currency) : '').'</span>';
1635  print '</td>';
1636  print "</tr>\n";
1637 
1638  // THM
1639  print '<tr><td>';
1640  $text = $langs->trans("THM");
1641  print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
1642  print '</td>';
1643  print '<td>';
1644  print ($object->thm != '' ?price($object->thm, '', $langs, 1, -1, -1, $conf->currency) : '');
1645  print '</td>';
1646  print "</tr>\n";
1647 
1648  // TJM
1649  print '<tr><td>';
1650  $text = $langs->trans("TJM");
1651  print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
1652  print '</td>';
1653  print '<td>';
1654  print ($object->tjm != '' ?price($object->tjm, '', $langs, 1, -1, -1, $conf->currency) : '');
1655  print '</td>';
1656  print "</tr>\n";
1657  }
1658 
1659  // Date employment
1660  print '<tr><td>'.$langs->trans("DateOfEmployment").'</td>';
1661  print '<td>';
1662  if ($object->dateemployment) {
1663  print '<span class="opacitymedium">'.$langs->trans("FromDate").'</span> ';
1664  print dol_print_date($object->dateemployment, 'day');
1665  }
1666  if ($object->dateemploymentend) {
1667  print '<span class="opacitymedium"> - '.$langs->trans("To").'</span> ';
1668  print dol_print_date($object->dateemploymentend, 'day');
1669  }
1670  print '</td>';
1671  print "</tr>\n";
1672 
1673  // Date of birth
1674  print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
1675  print '<td>';
1676  print dol_print_date($object->birth, 'day', 'tzserver');
1677  print '</td>';
1678  print "</tr>\n";
1679 
1680  // Default warehouse
1681  if (isModEnabled('stock') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
1682  require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
1683  print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
1684  if ($object->fk_warehouse > 0) {
1685  $warehousestatic = new Entrepot($db);
1686  $warehousestatic->fetch($object->fk_warehouse);
1687  print $warehousestatic->getNomUrl(1);
1688  }
1689  print '</td></tr>';
1690  }
1691 
1692  print '</table>';
1693 
1694  print '</div>';
1695  print '<div class="fichehalfright">';
1696 
1697  print '<div class="underbanner clearboth"></div>';
1698 
1699  print '<table class="border tableforfield centpercent">';
1700 
1701  // Color user
1702  if (isModEnabled('agenda')) {
1703  print '<tr><td class="titlefield">'.$langs->trans("ColorUser").'</td>';
1704  print '<td>';
1705  print $formother->showColor($object->color, '');
1706  print '</td>';
1707  print "</tr>\n";
1708  }
1709 
1710  // Categories
1711  if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
1712  print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td>';
1713  print '<td colspan="3">';
1714  print $form->showCategories($object->id, Categorie::TYPE_USER, 1);
1715  print '</td></tr>';
1716  }
1717 
1718  // Default language
1719  if (getDolGlobalInt('MAIN_MULTILANGS')) {
1720  $langs->load("languages");
1721  require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
1722  print '<tr><td class="titlefield">';
1723  print $form->textwithpicto($langs->trans("DefaultLang"), $langs->trans("WarningNotLangOfInterface", $langs->transnoentitiesnoconv("UserGUISetup")));
1724  print '</td><td>';
1725  //$s=picto_from_langcode($object->default_lang);
1726  //print ($s?$s.' ':'');
1727  $labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
1728  print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
1729  print $labellang;
1730  print '</td></tr>';
1731  }
1732 
1733  if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication) && !empty($conf->global->MAIN_OPENIDURL_PERUSER)) {
1734  print '<tr><td>'.$langs->trans("OpenIDURL").'</td>';
1735  print '<td>'.$object->openid.'</td>';
1736  print "</tr>\n";
1737  }
1738 
1739  // Multicompany
1740  if (isModEnabled('multicompany') && is_object($mc)) {
1741  // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
1742  if (!method_exists($mc, 'formObjectOptions')) {
1743  if (isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE) && $conf->entity == 1 && $user->admin && !$user->entity) {
1744  print '<tr><td>'.$langs->trans("Entity").'</td><td>';
1745  if (empty($object->entity)) {
1746  print $langs->trans("AllEntities");
1747  } else {
1748  $mc->getInfo($object->entity);
1749  print $mc->label;
1750  }
1751  print "</td></tr>\n";
1752  }
1753  }
1754  }
1755 
1756  // Other attributes
1757  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
1758 
1759  // Company / Contact
1760  if (isModEnabled("societe")) {
1761  print '<tr><td>'.$langs->trans("LinkToCompanyContact").'</td>';
1762  print '<td>';
1763  $s = '';
1764  if (isset($object->socid) && $object->socid > 0) {
1765  $societe = new Societe($db);
1766  $societe->fetch($object->socid);
1767  if ($societe->id > 0) {
1768  $s .= $societe->getNomUrl(1, '');
1769  }
1770  } else {
1771  $s .= '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ThisUserIsNot").'</span>';
1772  }
1773  if (!empty($object->contact_id)) {
1774  $contact = new Contact($db);
1775  $contact->fetch($object->contact_id);
1776  if ($contact->id > 0) {
1777  if ($object->socid > 0 && $s) {
1778  $s .= ' / ';
1779  } else {
1780  $s .= '<br>';
1781  }
1782  $s .= $contact->getNomUrl(1, '');
1783  }
1784  }
1785  print $s;
1786  print '</td>';
1787  print '</tr>'."\n";
1788  }
1789 
1790  // Module Adherent
1791  if (isModEnabled('adherent')) {
1792  $langs->load("members");
1793  print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
1794  print '<td>';
1795  if ($object->fk_member) {
1796  $adh = new Adherent($db);
1797  $adh->fetch($object->fk_member);
1798  $adh->ref = $adh->getFullname($langs); // Force to show login instead of id
1799  print $adh->getNomUrl(-1);
1800  } else {
1801  print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("UserNotLinkedToMember").'</span>';
1802  }
1803  print '</td>';
1804  print '</tr>'."\n";
1805  }
1806 
1807  // Signature
1808  print '<tr><td class="tdtop">'.$langs->trans('Signature').'</td><td class="wordbreak">';
1809  print dol_htmlentitiesbr($object->signature);
1810  print "</td></tr>\n";
1811 
1812  print "</table>\n";
1813 
1814 
1815  // Credentials
1816  print '<br>';
1817  print '<div class="div-table-responsive-no-min">';
1818  print '<table class="border tableforfield centpercent">';
1819  print '<tr class="liste_titre"><td class="liste_titre">';
1820  print img_picto('', 'security', 'class="paddingleft pictofixedwidth"').$langs->trans("Credentials");
1821  print '</td>';
1822  print '<td class="liste_titre"></td>';
1823  print '</tr>';
1824 
1825  // Date login validity
1826  print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("RangeOfLoginValidity").'</td>';
1827  print '<td>';
1828  if ($object->datestartvalidity) {
1829  print '<span class="opacitymedium">'.$langs->trans("FromDate").'</span> ';
1830  print dol_print_date($object->datestartvalidity, 'day');
1831  }
1832  if ($object->dateendvalidity) {
1833  print '<span class="opacitymedium"> - '.$langs->trans("To").'</span> ';
1834  print dol_print_date($object->dateendvalidity, 'day');
1835  }
1836  print '</td>';
1837  print "</tr>\n";
1838 
1839  // Password
1840  $valuetoshow = '';
1841  if (preg_match('/ldap/', $dolibarr_main_authentication)) {
1842  if (!empty($object->ldap_sid)) {
1843  if ($passDoNotExpire) {
1844  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("LdapUacf_".$statutUACF);
1845  } elseif ($userChangePassNextLogon) {
1846  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').'<span class="warning">'.$langs->trans("UserMustChangePassNextLogon", $ldap->domainFQDN).'</span>';
1847  } elseif ($userDisabled) {
1848  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').'<span class="warning">'.$langs->trans("LdapUacf_".$statutUACF, $ldap->domainFQDN).'</span>';
1849  } else {
1850  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
1851  }
1852  } else {
1853  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
1854  }
1855  }
1856  if (preg_match('/http/', $dolibarr_main_authentication)) {
1857  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("HTTPBasicPassword");
1858  }
1859  /*
1860  if (preg_match('/dolibarr/', $dolibarr_main_authentication)) {
1861  if ($object->pass) {
1862  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
1863  $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1864  } else {
1865  if ($user->admin && $user->id == $object->id) {
1866  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
1867  $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1868  $valuetoshow .= '<!-- Crypted into '.$object->pass_indatabase_crypted.' -->';
1869  } else {
1870  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
1871  $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
1872  }
1873  }
1874  }
1875  */
1876 
1877  // Other form for user password
1878  $parameters = array('valuetoshow' => $valuetoshow);
1879  $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1880  if ($reshook > 0) {
1881  $valuetoshow = $hookmanager->resPrint; // to replace
1882  } else {
1883  $valuetoshow .= $hookmanager->resPrint; // to add
1884  }
1885 
1886  if (dol_string_nohtmltag($valuetoshow)) { // If there is a real visible content to show
1887  print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("Password").'</td>';
1888  print '<td class="wordbreak">';
1889  print $valuetoshow;
1890  print "</td>";
1891  print '</tr>'."\n";
1892  }
1893 
1894  // API key
1895  if (isModEnabled('api') && ($user->id == $id || $user->admin || $user->hasRight("api", "apikey", "generate"))) {
1896  print '<tr class="nooddeven"><td>'.$langs->trans("ApiKey").'</td>';
1897  print '<td>';
1898  if (!empty($object->api_key)) {
1899  print '<span class="opacitymedium">';
1900  print showValueWithClipboardCPButton($object->api_key, 1, $langs->trans("Hidden")); // TODO Add an option to also reveal the hash, not only copy paste
1901  print '</span>';
1902  }
1903  print '</td></tr>';
1904  }
1905 
1906  print '<tr class="nooddeven"><td>'.$langs->trans("LastConnexion").'</td>';
1907  print '<td>';
1908  if ($object->datepreviouslogin) {
1909  print dol_print_date($object->datepreviouslogin, "dayhour", "tzuserrel").' <span class="opacitymedium">('.$langs->trans("Previous").')</span>, ';
1910  }
1911  if ($object->datelastlogin) {
1912  print dol_print_date($object->datelastlogin, "dayhour", "tzuserrel").' <span class="opacitymedium">('.$langs->trans("Currently").')</span>';
1913  }
1914  print '</td>';
1915  print "</tr>\n";
1916 
1917  print '</table>';
1918  print '</div>';
1919 
1920  print '</div>';
1921 
1922  print '</div>';
1923  print '<div class="clearboth"></div>';
1924 
1925 
1926  print dol_get_fiche_end();
1927 
1928 
1929  /*
1930  * Buttons actions
1931  */
1932  print '<div class="tabsAction">';
1933 
1934  $parameters = array();
1935  $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1936  if (empty($reshook)) {
1937  if (empty($user->socid)) {
1938  $canSendMail = false;
1939  $params = array(
1940  'attr' => array(
1941  'title' => '',
1942  'class' => 'classfortooltip'
1943  )
1944  );
1945  if (!empty($object->email)) {
1946  $langs->load("mails");
1947  $canSendMail = true;
1948  } else {
1949  $langs->load("mails");
1950  $params['attr']['title'] = $langs->trans('NoEMail');
1951  }
1952  print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle', '', $canSendMail, $params);
1953  }
1954 
1955  if ($caneditfield && (!isModEnabled('multicompany') || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
1956  $params = array(
1957  'attr' => array(
1958  'title' => '',
1959  'class' => 'classfortooltip'
1960  )
1961  );
1962  if (!empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED)) {
1963  $params['attr']['title'] = $langs->trans('DisabledInMonoUserMode');
1964  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
1965  } else {
1966  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit&token='.newToken(), '', true, $params);
1967  }
1968  } elseif ($caneditpassword && !$object->ldap_sid &&
1969  (!isModEnabled('multicompany') || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
1970  $params = array(
1971  'attr' => array(
1972  'title' => '',
1973  'class' => 'classfortooltip'
1974  )
1975  );
1976  print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit', '', true, $params);
1977  }
1978 
1979  // Si on a un gestionnaire de generation de mot de passe actif
1980  $params = array(
1981  'attr' => array(
1982  'title' => '',
1983  'class' => 'classfortooltip'
1984  )
1985  );
1986  if ($conf->global->USER_PASSWORD_GENERATED != 'none') {
1987  if ($object->statut == 0) {
1988  $params['attr']['title'] = $langs->trans('UserDisabled');
1989  print dolGetButtonAction($langs->trans('ReinitPassword'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
1990  } elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
1991  ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
1992  print dolGetButtonAction($langs->trans('ReinitPassword'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=password&token='.newToken(), '', true, $params);
1993  }
1994 
1995  if ($object->statut == 0) {
1996  $params['attr']['title'] = $langs->trans('UserDisabled');
1997  print dolGetButtonAction($langs->trans('SendNewPassword'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
1998  } elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
1999  ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
2000  if ($object->email) {
2001  print dolGetButtonAction($langs->trans('SendNewPassword'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=passwordsend&token='.newToken(), '', true, $params);
2002  } else {
2003  $params['attr']['title'] = $langs->trans('NoEMail');
2004  print dolGetButtonAction($langs->trans('SendNewPassword'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
2005  }
2006  }
2007  }
2008 
2009  // Enable user
2010  $params = array(
2011  'attr' => array(
2012  'title' => '',
2013  'class' => 'classfortooltip'
2014  )
2015  );
2016  if ($user->id <> $id && $candisableuser && $object->statut == 0 &&
2017  ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
2018  print dolGetButtonAction($langs->trans('Reactivate'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=enable&token='.newToken(), '', true, $params);
2019  }
2020  // Disable user
2021  if ($user->id <> $id && $candisableuser && $object->statut == 1 &&
2022  ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
2023  print dolGetButtonAction($langs->trans('DisableUser'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=disable&token='.newToken(), '', true, $params);
2024  } else {
2025  if ($user->id == $id) {
2026  $params['attr']['title'] = $langs->trans('CantDisableYourself');
2027  print dolGetButtonAction($langs->trans('DisableUser'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
2028  }
2029  }
2030  // Delete
2031  if ($user->id <> $id && $candisableuser &&
2032  ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
2033  if ($user->admin || !$object->admin) { // If user edited is admin, delete is possible on for an admin
2034  print dolGetButtonAction($langs->trans('DeleteUser'), '', 'default', $_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id, '', true, $params);
2035  } else {
2036  $params['attr']['title'] = $langs->trans('MustBeAdminToDeleteOtherAdmin');
2037  print dolGetButtonAction($langs->trans('DeleteUser'), '', 'default', $_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id, '', false, $params);
2038  }
2039  }
2040  }
2041 
2042  print "</div>\n";
2043 
2044 
2045 
2046  // Select mail models is same action as presend
2047  if (GETPOST('modelselected')) {
2048  $action = 'presend';
2049  }
2050 
2051  // Presend form
2052  $modelmail = 'user';
2053  $defaulttopic = 'Information';
2054  $diroutput = $conf->user->dir_output;
2055  $trackid = 'use'.$object->id;
2056 
2057  include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
2058 
2059  if ($action != 'presend' && $action != 'send') {
2060  /*
2061  * List of groups of user
2062  */
2063 
2064  if ($canreadgroup) {
2065  print '<!-- Group section -->'."\n";
2066 
2067  print load_fiche_titre($langs->trans("ListOfGroupsForUser"), '', '');
2068 
2069  // On selectionne les groupes auquel fait parti le user
2070  $exclude = array();
2071 
2072  $usergroup = new UserGroup($db);
2073  $groupslist = $usergroup->listGroupsForUser($object->id, false);
2074 
2075  if (!empty($groupslist)) {
2076  foreach ($groupslist as $groupforuser) {
2077  $exclude[] = $groupforuser->id;
2078  }
2079  }
2080 
2081  // Other form for add user to group
2082  $parameters = array('caneditgroup' => $caneditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude);
2083  $reshook = $hookmanager->executeHooks('formAddUserToGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2084  print $hookmanager->resPrint;
2085 
2086  if (empty($reshook)) {
2087  if ($caneditgroup) {
2088  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'."\n";
2089  print '<input type="hidden" name="token" value="'.newToken().'" />';
2090  print '<input type="hidden" name="action" value="addgroup" />';
2091  print '<input type="hidden" name="page_y" value="" />';
2092  }
2093 
2094  print '<!-- List of groups of the user -->'."\n";
2095  print '<table class="noborder centpercent">'."\n";
2096  print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans("Groups").'</th>'."\n";
2097  print '<th class="liste_titre right">';
2098  if ($caneditgroup) {
2099  print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity, false, 'maxwidth150');
2100  print ' &nbsp; ';
2101  print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
2102  print '<input type="submit" class="button buttongen button-add reposition" value="'.$langs->trans("Add").'" />';
2103  }
2104  print '</th></tr>'."\n";
2105 
2106  // List of groups of user
2107  if (!empty($groupslist)) {
2108  foreach ($groupslist as $group) {
2109  print '<tr class="oddeven">';
2110  print '<td class="tdoverflowmax150">';
2111  if ($caneditgroup) {
2112  print $group->getNomUrl(1);
2113  } else {
2114  print img_object($langs->trans("ShowGroup"), "group").' '.$group->name;
2115  }
2116  print '</td>';
2117  print '<td class="right">';
2118  if ($caneditgroup) {
2119  print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=removegroup&token='.newToken().'&group='.((int) $group->id).'">';
2120  print img_picto($langs->trans("RemoveFromGroup"), 'unlink');
2121  print '</a>';
2122  } else {
2123  print "&nbsp;";
2124  }
2125  print "</td></tr>\n";
2126  }
2127  } else {
2128  print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
2129  }
2130 
2131  print "</table>";
2132 
2133  if ($caneditgroup) {
2134  print '</form>';
2135  }
2136  print "<br>";
2137  }
2138  }
2139  }
2140  }
2141 
2142  /*
2143  * Card in edit mode
2144  */
2145  if ($action == 'edit' && ($canedituser || $caneditpassword)) {
2146  print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="updateuser" enctype="multipart/form-data">';
2147  print '<input type="hidden" name="token" value="'.newToken().'">';
2148  print '<input type="hidden" name="action" value="update">';
2149  print '<input type="hidden" name="entity" value="'.$object->entity.'">';
2150 
2151  print dol_get_fiche_head($head, 'user', $title, 0, 'user');
2152 
2153  print '<table class="border centpercent">';
2154 
2155  // Ref/ID
2156  if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
2157  print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
2158  print '<td>';
2159  print $object->id;
2160  print '</td>';
2161  print '</tr>';
2162  }
2163 
2164  // Civility
2165  print '<tr><td class="titlefieldcreate"><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
2166  if ($caneditfield && !$object->ldap_sid) {
2167  print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
2168  } elseif ($object->civility_code) {
2169  print $langs->trans("Civility".$object->civility_code);
2170  }
2171  print '</td></tr>';
2172 
2173  // Lastname
2174  print "<tr>";
2175  print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Lastname").'</td>';
2176  print '<td>';
2177  if ($caneditfield && !$object->ldap_sid) {
2178  print '<input class="minwidth100" type="text" class="flat" name="lastname" value="'.$object->lastname.'">';
2179  } else {
2180  print '<input type="hidden" name="lastname" value="'.$object->lastname.'">';
2181  print $object->lastname;
2182  }
2183  print '</td>';
2184  print '</tr>';
2185 
2186  // Firstname
2187  print '<tr><td>'.$langs->trans("Firstname").'</td>';
2188  print '<td>';
2189  if ($caneditfield && !$object->ldap_sid) {
2190  print '<input class="minwidth100" type="text" class="flat" name="firstname" value="'.$object->firstname.'">';
2191  } else {
2192  print '<input type="hidden" name="firstname" value="'.$object->firstname.'">';
2193  print $object->firstname;
2194  }
2195  print '</td></tr>';
2196 
2197  // Login
2198  print "<tr>".'<td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
2199  print '<td>';
2200  if ($user->admin && !$object->ldap_sid) {
2201  print '<input maxlength="50" type="text" class="flat" name="login" value="'.$object->login.'">';
2202  } else {
2203  print '<input type="hidden" name="login" value="'.$object->login.'">';
2204  print $object->login;
2205  }
2206  print '</td>';
2207  print '</tr>';
2208 
2209  // Administrator
2210  print '<tr><td>'.$langs->trans("Administrator").'</td>';
2211  if ($object->socid > 0) {
2212  $langs->load("admin");
2213  print '<td>';
2214  print '<input type="hidden" name="admin" value="'.$object->admin.'">'.yn($object->admin);
2215  print ' <span class="opacitymedium">('.$langs->trans("ExternalUser").')</span>';
2216  print '</td></tr>';
2217  } else {
2218  print '<td>';
2219  $nbAdmin = $user->getNbOfUsers('active', '', 1);
2220  $nbSuperAdmin = $user->getNbOfUsers('active', 'superadmin', 1);
2221  //var_dump($nbAdmin);
2222  //var_dump($nbSuperAdmin);
2223  if ($user->admin // Need to be admin to allow downgrade of an admin
2224  && ($user->id != $object->id) // Don't downgrade ourself
2225  && (
2226  (!isModEnabled('multicompany') && $nbAdmin >= 1)
2227  || (isModEnabled('multicompany') && (($object->entity > 0 || ($user->entity == 0 && $object->entity == 0)) || $nbSuperAdmin > 1)) // Don't downgrade a superadmin if alone
2228  )
2229  ) {
2230  print $form->selectyesno('admin', $object->admin, 1, false, 0, 1);
2231 
2232  if (isModEnabled('multicompany') && !$user->entity) {
2233  if ($conf->use_javascript_ajax) {
2234  print '<script type="text/javascript">
2235  $(function() {
2236  var admin = $("select[name=admin]").val();
2237  if (admin == 0) {
2238  $("input[name=superadmin]")
2239  .prop("disabled", true)
2240  .prop("checked", false);
2241  }
2242  if ($("input[name=superadmin]").is(":checked")) {
2243  $("select[name=entity]")
2244  .prop("disabled", true);
2245  }
2246  $("select[name=admin]").change(function() {
2247  if ( $(this).val() == 0 ) {
2248  $("input[name=superadmin]")
2249  .prop("disabled", true)
2250  .prop("checked", false);
2251  $("select[name=entity]")
2252  .prop("disabled", false);
2253  } else {
2254  $("input[name=superadmin]")
2255  .prop("disabled", false);
2256  }
2257  });
2258  $("input[name=superadmin]").change(function() {
2259  if ( $(this).is(":checked")) {
2260  $("select[name=entity]")
2261  .prop("disabled", true);
2262  } else {
2263  $("select[name=entity]")
2264  .prop("disabled", false);
2265  }
2266  });
2267  });
2268  </script>';
2269  }
2270 
2271  $checked = (($object->admin && !$object->entity) ? ' checked' : '');
2272  print '<input type="checkbox" name="superadmin" id="superadmin" value="1"'.$checked.' /> <label for="superadmin">'.$langs->trans("SuperAdministrator").'</span>';
2273  }
2274  } else {
2275  $yn = yn($object->admin);
2276  print '<input type="hidden" name="admin" value="'.$object->admin.'">';
2277  print '<input type="hidden" name="superadmin" value="'.(empty($object->entity) ? 1 : 0).'">';
2278  if (isModEnabled('multicompany') && empty($object->entity)) {
2279  print $form->textwithpicto($yn, $langs->trans("DontDowngradeSuperAdmin"), 1, 'warning');
2280  } else {
2281  print $yn;
2282  }
2283  }
2284  print '</td></tr>';
2285  }
2286 
2287  // Gender
2288  print '<tr><td>'.$langs->trans("Gender").'</td>';
2289  print '<td>';
2290  $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
2291  if ($caneditfield) {
2292  print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ?GETPOST('gender') : $object->gender, 1);
2293  } else {
2294  print $arraygender[$object->gender];
2295  }
2296  print '</td></tr>';
2297 
2298  // Employee
2299  print '<tr>';
2300  print '<td>'.$form->editfieldkey('Employee', 'employee', '', $object, 0).'</td><td>';
2301  if ($caneditfield) {
2302  print '<input type="checkbox" name="employee" value="1"'.($object->employee ? ' checked="checked"' : '').'>';
2303  //print $form->selectyesno("employee", $object->employee, 1);
2304  } else {
2305  print '<input type="checkbox" name="employee" disabled value="1"'.($object->employee ? ' checked="checked"' : '').'>';
2306  /*if ($object->employee) {
2307  print $langs->trans("Yes");
2308  } else {
2309  print $langs->trans("No");
2310  }*/
2311  }
2312  print '</td></tr>';
2313 
2314  // Hierarchy
2315  print '<tr><td class="titlefieldcreate">'.$langs->trans("HierarchicalResponsible").'</td>';
2316  print '<td>';
2317  if ($caneditfield) {
2318  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
2319  } else {
2320  print '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
2321  $huser = new User($db);
2322  $huser->fetch($object->fk_user);
2323  print $huser->getNomUrl(-1);
2324  }
2325  print '</td>';
2326  print "</tr>\n";
2327 
2328  // Expense report validator
2329  if (isModEnabled('expensereport')) {
2330  print '<tr><td class="titlefieldcreate">';
2331  $text = $langs->trans("ForceUserExpenseValidator");
2332  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
2333  print '</td>';
2334  print '<td>';
2335  if ($caneditfield) {
2336  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user_expense_validator, 'fk_user_expense_validator', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
2337  } else {
2338  print '<input type="hidden" name="fk_user_expense_validator" value="'.$object->fk_user_expense_validator.'">';
2339  $evuser = new User($db);
2340  $evuser->fetch($object->fk_user_expense_validator);
2341  print $evuser->getNomUrl(-1);
2342  }
2343  print '</td>';
2344  print "</tr>\n";
2345  }
2346 
2347  // Holiday request validator
2348  if (isModEnabled('holiday')) {
2349  print '<tr><td class="titlefieldcreate">';
2350  $text = $langs->trans("ForceUserHolidayValidator");
2351  print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
2352  print '</td>';
2353  print '<td>';
2354  if ($caneditfield) {
2355  print img_picto('', 'user', 'class="pictofixedwidth"').$form->select_dolusers($object->fk_user_holiday_validator, 'fk_user_holiday_validator', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
2356  } else {
2357  print '<input type="hidden" name="fk_user_holiday_validator" value="'.$object->fk_user_holiday_validator.'">';
2358  $hvuser = new User($db);
2359  $hvuser->fetch($object->fk_user_holiday_validator);
2360  print $hvuser->getNomUrl(-1);
2361  }
2362  print '</td>';
2363  print "</tr>\n";
2364  }
2365 
2366  // External user ?
2367  print '<tr><td>'.$langs->trans("ExternalUser").' ?</td>';
2368  print '<td>';
2369  if ($user->id == $object->id || !$user->admin) {
2370  // Read mode
2371  $type = $langs->trans("Internal");
2372  if ($object->socid) {
2373  $type = $langs->trans("External");
2374  }
2375  print $form->textwithpicto($type, $langs->trans("InternalExternalDesc"));
2376  if ($object->ldap_sid) {
2377  print ' ('.$langs->trans("DomainUser").')';
2378  }
2379  } else {
2380  // Select mode
2381  $type = 0;
2382  if ($object->contact_id) {
2383  $type = $object->contact_id;
2384  }
2385 
2386  if ($object->socid > 0 && !($object->contact_id > 0)) { // external user but no link to a contact
2387  print img_picto('', 'company').$form->select_company($object->socid, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300');
2388  print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
2389  if ($object->ldap_sid) {
2390  print ' ('.$langs->trans("DomainUser").')';
2391  }
2392  } elseif ($object->socid > 0 && $object->contact_id > 0) { // external user with a link to a contact
2393  print img_picto('', 'company').$form->select_company($object->socid, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
2394  print img_picto('', 'contact').$form->selectcontacts(0, $object->contact_id, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
2395  if ($object->ldap_sid) {
2396  print ' ('.$langs->trans("DomainUser").')';
2397  }
2398  } elseif (!($object->socid > 0) && $object->contact_id > 0) { // internal user with a link to a contact
2399  print img_picto('', 'company').$form->select_company(0, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
2400  print img_picto('', 'contact').$form->selectcontacts(0, $object->contact_id, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
2401  if ($object->ldap_sid) {
2402  print ' ('.$langs->trans("DomainUser").')';
2403  }
2404  } else { // $object->socid is not > 0 here
2405  print img_picto('', 'company').$form->select_company(0, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
2406  print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
2407  }
2408  }
2409  print '</td></tr>';
2410 
2411 
2412  print '</table>';
2413 
2414  print '<hr>';
2415 
2416  print '<table class="border centpercent">';
2417 
2418  // Date access validity
2419  print '<tr><td>'.$langs->trans("RangeOfLoginValidity").'</td>';
2420  print '<td>';
2421  if ($caneditfield) {
2422  print $form->selectDate($datestartvalidity ? $datestartvalidity : $object->datestartvalidity, 'datestartvalidity', 0, 0, 1, 'formdatestartvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("from"));
2423  } else {
2424  print dol_print_date($object->datestartvalidity, 'day');
2425  }
2426  print ' &nbsp; ';
2427 
2428  if ($caneditfield) {
2429  print $form->selectDate($dateendvalidity ? $dateendvalidity : $object->dateendvalidity, 'dateendvalidity', 0, 0, 1, 'formdateendvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
2430  } else {
2431  print dol_print_date($object->dateendvalidity, 'day');
2432  }
2433  print '</td>';
2434  print "</tr>\n";
2435 
2436  // Pass
2437  print '<tr><td class="titlefieldcreate">'.$langs->trans("Password").'</td>';
2438  print '<td>';
2439  $valuetoshow = '';
2440  if (preg_match('/ldap/', $dolibarr_main_authentication)) {
2441  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
2442  }
2443  if (preg_match('/http/', $dolibarr_main_authentication)) {
2444  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$form->textwithpicto($text, $langs->trans("DolibarrInHttpAuthenticationSoPasswordUseless", $dolibarr_main_authentication), 1, 'warning');
2445  }
2446  if (preg_match('/dolibarr/', $dolibarr_main_authentication) || preg_match('/forceuser/', $dolibarr_main_authentication)) {
2447  if ($caneditpassword) {
2448  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').'<input maxlength="128" type="password" class="flat" id="password" name="password" value="'.dol_escape_htmltag($object->pass).'" autocomplete="new-password">';
2449  if (!empty($conf->use_javascript_ajax)) {
2450  $valuetoshow .= img_picto((getDolGlobalString('USER_PASSWORD_GENERATED') === 'none' ? $langs->trans('NoPasswordGenerationRuleConfigured') : $langs->trans('Generate')), 'refresh', 'id="generate_password" class="paddingleft'.(getDolGlobalString('USER_PASSWORD_GENERATED') === 'none' ? ' opacitymedium' : ' linkobject').'"');
2451  }
2452  } else {
2453  $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').preg_replace('/./i', '*', $object->pass);
2454  }
2455  }
2456  // Other form for user password
2457  $parameters = array('valuetoshow' => $valuetoshow, 'caneditpassword' => $caneditpassword);
2458  $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2459  if ($reshook > 0) {
2460  $valuetoshow = $hookmanager->resPrint; // to replace
2461  } else {
2462  $valuetoshow .= $hookmanager->resPrint; // to add
2463  }
2464 
2465  print $valuetoshow;
2466  print "</td></tr>\n";
2467 
2468  // API key
2469  if (isModEnabled('api')) {
2470  print '<tr><td>'.$langs->trans("ApiKey").'</td>';
2471  print '<td>';
2472  if ($caneditpassword || $user->hasRight("api", "apikey", "generate")) {
2473  print '<input class="minwidth300 maxwidth400 widthcentpercentminusx" minlength="12" maxlength="128" type="text" id="api_key" name="api_key" value="'.$object->api_key.'" autocomplete="off">';
2474  if (!empty($conf->use_javascript_ajax)) {
2475  print img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject paddingleft"');
2476  }
2477  }
2478  print '</td></tr>';
2479  }
2480 
2481  // OpenID url
2482  if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication) && !empty($conf->global->MAIN_OPENIDURL_PERUSER)) {
2483  print "<tr>".'<td>'.$langs->trans("OpenIDURL").'</td>';
2484  print '<td>';
2485  if ($caneditfield) {
2486  print '<input class="minwidth100" type="url" name="openid" class="flat" value="'.$object->openid.'">';
2487  } else {
2488  print '<input type="hidden" name="openid" value="'.$object->openid.'">';
2489  print $object->openid;
2490  }
2491  print '</td></tr>';
2492  }
2493 
2494  print '</table><hr><table class="border centpercent">';
2495 
2496 
2497  // Address
2498  print '<tr><td class="tdtop titlefieldcreate">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
2499  print '<td>';
2500  if ($caneditfield) {
2501  print '<textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
2502  }
2503  print $object->address;
2504  if ($caneditfield) {
2505  print '</textarea>';
2506  }
2507  print '</td></tr>';
2508 
2509  // Zip
2510  print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
2511  if ($caneditfield) {
2512  print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
2513  } else {
2514  print $object->zip;
2515  }
2516  print '</td></tr>';
2517 
2518  // Town
2519  print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
2520  if ($caneditfield) {
2521  print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2522  } else {
2523  print $object->town;
2524  }
2525  print '</td></tr>';
2526 
2527  // Country
2528  print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td>';
2529  print img_picto('', 'country', 'class="pictofixedwidth"');
2530  if ($caneditfield) {
2531  print $form->select_country((GETPOST('country_id') != '' ?GETPOST('country_id') : $object->country_id), 'country_id');
2532  if ($user->admin) {
2533  print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
2534  }
2535  } else {
2536  $countrylabel = getCountry($object->country_id, '0');
2537  print $countrylabel;
2538  }
2539  print '</td></tr>';
2540 
2541  // State
2542  if (empty($conf->global->USER_DISABLE_STATE)) {
2543  print '<tr><td class="tdoverflow">'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td>';
2544  if ($caneditfield) {
2545  print img_picto('', 'state', 'class="pictofixedwidth"');
2546  print $formcompany->select_state($object->state_id, $object->country_code, 'state_id');
2547  } else {
2548  print $object->state;
2549  }
2550  print '</td></tr>';
2551  }
2552 
2553  // Tel pro
2554  print "<tr>".'<td>'.$langs->trans("PhonePro").'</td>';
2555  print '<td>';
2556  print img_picto('', 'phoning', 'class="pictofixedwidth"');
2557  if ($caneditfield && empty($object->ldap_sid)) {
2558  print '<input type="text" name="office_phone" class="flat maxwidth200" value="'.$object->office_phone.'">';
2559  } else {
2560  print '<input type="hidden" name="office_phone" value="'.$object->office_phone.'">';
2561  print $object->office_phone;
2562  }
2563  print '</td></tr>';
2564 
2565  // Tel mobile
2566  print "<tr>".'<td>'.$langs->trans("PhoneMobile").'</td>';
2567  print '<td>';
2568  print img_picto('', 'phoning_mobile', 'class="pictofixedwidth"');
2569  if ($caneditfield && empty($object->ldap_sid)) {
2570  print '<input type="text" name="user_mobile" class="flat maxwidth200" value="'.$object->user_mobile.'">';
2571  } else {
2572  print '<input type="hidden" name="user_mobile" value="'.$object->user_mobile.'">';
2573  print $object->user_mobile;
2574  }
2575  print '</td></tr>';
2576 
2577  // Fax
2578  print "<tr>".'<td>'.$langs->trans("Fax").'</td>';
2579  print '<td>';
2580  print img_picto('', 'phoning_fax', 'class="pictofixedwidth"');
2581  if ($caneditfield && empty($object->ldap_sid)) {
2582  print '<input type="text" name="office_fax" class="flat maxwidth200" value="'.$object->office_fax.'">';
2583  } else {
2584  print '<input type="hidden" name="office_fax" value="'.$object->office_fax.'">';
2585  print $object->office_fax;
2586  }
2587  print '</td></tr>';
2588 
2589  // EMail
2590  print "<tr>".'<td'.(!empty($conf->global->USER_MAIL_REQUIRED) ? ' class="fieldrequired"' : '').'>'.$langs->trans("EMail").'</td>';
2591  print '<td>';
2592  print img_picto('', 'object_email', 'class="pictofixedwidth"');
2593  if ($caneditfield && empty($object->ldap_sid)) {
2594  print '<input class="minwidth100 maxwidth500 widthcentpercentminusx" type="text" name="email" class="flat" value="'.$object->email.'">';
2595  } else {
2596  print '<input type="hidden" name="email" value="'.$object->email.'">';
2597  print $object->email;
2598  }
2599  print '</td></tr>';
2600 
2601  if (isModEnabled('socialnetworks')) {
2602  foreach ($socialnetworks as $key => $value) {
2603  if ($value['active']) {
2604  print '<tr><td>'.$langs->trans($value['label']).'</td>';
2605  print '<td>';
2606  if (!empty($value['icon'])) {
2607  print '<span class="fa '.$value['icon'].' pictofixedwidth"></span>';
2608  }
2609  if ($caneditfield && empty($object->ldap_sid)) {
2610  print '<input type="text" name="'.$key.'" class="flat maxwidth200" value="'.(isset($object->socialnetworks[$key])?$object->socialnetworks[$key]:'').'">';
2611  } else {
2612  print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
2613  print $object->socialnetworks[$key];
2614  }
2615  print '</td></tr>';
2616  } else {
2617  // if social network is not active but value exist we do not want to loose it
2618  print '<input type="hidden" name="'.$key.'" value="'.(isset($object->socialnetworks[$key])?$object->socialnetworks[$key]:'').'">';
2619  }
2620  }
2621  }
2622 
2623  print '</table><hr><table class="border centpercent">';
2624 
2625  // Default warehouse
2626  if (isModEnabled('stock') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
2627  print '<tr><td class="titlefield">'.$langs->trans("DefaultWarehouse").'</td><td>';
2628  print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
2629  print ' <a href="'.DOL_URL_ROOT.'/product/stock/card.php?action=create&token='.newToken().'&backtopage='.urlencode($_SERVER['PHP_SELF'].'?id='.$object->id.'&action=edit&token='.newToken()).'"><span class="fa fa-plus-circle valignmiddle paddingleft" title="'.$langs->trans("AddWarehouse").'"></span></a>';
2630  print '</td></tr>';
2631  }
2632 
2633  // Accountancy code
2634  if (isModEnabled('accounting')) {
2635  print "<tr>";
2636  print '<td class="titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
2637  print '<td>';
2638  if ($caneditfield) {
2639  print '<input type="text" class="flat maxwidth300" name="accountancy_code" value="'.$object->accountancy_code.'">';
2640  } else {
2641  print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
2642  print $object->accountancy_code;
2643  }
2644  print '</td>';
2645  print "</tr>";
2646  }
2647 
2648  // User color
2649  if (isModEnabled('agenda')) {
2650  print '<tr><td class="titlefieldcreate">'.$langs->trans("ColorUser").'</td>';
2651  print '<td>';
2652  if ($caneditfield) {
2653  print $formother->selectColor(GETPOSTISSET('color') ?GETPOST('color', 'alphanohtml') : $object->color, 'color', null, 1, '', 'hideifnotset');
2654  } else {
2655  print $formother->showColor($object->color, '');
2656  }
2657  print '</td></tr>';
2658  }
2659 
2660  // Photo
2661  print '<tr>';
2662  print '<td class="titlefieldcreate">'.$langs->trans("Photo").'</td>';
2663  print '<td>';
2664  print $form->showphoto('userphoto', $object, 60, 0, $caneditfield, 'photowithmargin', 'small', 1, 0, 'user', 1);
2665  print '</td>';
2666  print '</tr>';
2667 
2668  // Categories
2669  if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
2670  print '<tr><td>'.$form->editfieldkey('Categories', 'usercats', '', $object, 0).'</td>';
2671  print '<td>';
2672  print img_picto('', 'category', 'class="pictofixedwidth"');
2673  $cate_arbo = $form->select_all_categories(Categorie::TYPE_USER, null, null, null, null, 1);
2674  $c = new Categorie($db);
2675  $cats = $c->containing($object->id, Categorie::TYPE_USER);
2676  $arrayselected = array();
2677  foreach ($cats as $cat) {
2678  $arrayselected[] = $cat->id;
2679  }
2680  if ($caneditfield) {
2681  print $form->multiselectarray('usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
2682  } else {
2683  print $form->showCategories($object->id, Categorie::TYPE_USER, 1);
2684  }
2685  print "</td></tr>";
2686  }
2687 
2688  // Default language
2689  if (getDolGlobalInt('MAIN_MULTILANGS')) {
2690  print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0, 'string', '', 0, 0, 'id', $langs->trans("WarningNotLangOfInterface", $langs->transnoentitiesnoconv("UserGUISetup"))).'</td><td colspan="3">'."\n";
2691  print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->lang, 'default_lang', 0, null, '1', 0, 0, 'widthcentpercentminusx maxwidth300');
2692  print '</td>';
2693  print '</tr>';
2694  }
2695 
2696  // Status
2697  print '<tr><td>'.$langs->trans("Status").'</td>';
2698  print '<td>';
2699  print $object->getLibStatut(4);
2700  print '</td></tr>';
2701 
2702  // Company / Contact
2703  if (isModEnabled("societe")) {
2704  print '<tr><td>'.$langs->trans("LinkToCompanyContact").'</td>';
2705  print '<td>';
2706  if ($object->socid > 0) {
2707  $societe = new Societe($db);
2708  $societe->fetch($object->socid);
2709  print $societe->getNomUrl(1, '');
2710  if ($object->contact_id) {
2711  $contact = new Contact($db);
2712  $contact->fetch($object->contact_id);
2713  print ' / <a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$object->contact_id.'">'.img_object($langs->trans("ShowContact"), 'contact').' '.dol_trunc($contact->getFullName($langs), 32).'</a>';
2714  }
2715  } else {
2716  print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ThisUserIsNot").'</span>';
2717  }
2718  print ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("UseTypeFieldToChange").')</span>';
2719  print '</td>';
2720  print "</tr>\n";
2721  }
2722 
2723  // Module Adherent
2724  if (isModEnabled('adherent')) {
2725  $langs->load("members");
2726  print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
2727  print '<td>';
2728  if ($object->fk_member) {
2729  $adh = new Adherent($db);
2730  $adh->fetch($object->fk_member);
2731  $adh->ref = $adh->login; // Force to show login instead of id
2732  print $adh->getNomUrl(1);
2733  } else {
2734  print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("UserNotLinkedToMember").'</span>';
2735  }
2736  print '</td>';
2737  print "</tr>\n";
2738  }
2739 
2740  // Multicompany
2741  // TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !!
2742  if (isModEnabled('multicompany') && is_object($mc)) {
2743  // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
2744  if (!method_exists($mc, 'formObjectOptions')) {
2745  if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && !$user->entity) {
2746  print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
2747  print "<td>".$mc->select_entities($object->entity, 'entity', '', 0, 1, false, false, 1); // last parameter 1 means, show also a choice 0=>'all entities'
2748  print "</td></tr>\n";
2749  } else {
2750  print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
2751  }
2752  }
2753  }
2754 
2755  // Other attributes
2756  $parameters = array('colspan' => ' colspan="2"');
2757  //include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_edit.tpl.php'; // We do not use common tpl here because we need a special test on $caneditfield
2758  $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2759  print $hookmanager->resPrint;
2760  if (empty($reshook)) {
2761  if ($caneditfield) {
2762  print $object->showOptionals($extrafields, 'edit');
2763  } else {
2764  print $object->showOptionals($extrafields, 'view');
2765  }
2766  }
2767 
2768  // Signature
2769  print '<tr><td class="tdtop">'.$langs->trans("Signature").'</td>';
2770  print '<td>';
2771  if ($caneditfield) {
2772  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2773 
2774  $doleditor = new DolEditor('signature', $object->signature, '', 138, 'dolibarr_notes', 'In', false, $acceptlocallinktomedia, empty($conf->global->FCKEDITOR_ENABLE_USERSIGN) ? 0 : 1, ROWS_4, '90%');
2775  print $doleditor->Create(1);
2776  } else {
2777  print dol_htmlentitiesbr($object->signature);
2778  }
2779  print '</td></tr>';
2780 
2781 
2782  print '</table>';
2783 
2784  print '<hr>';
2785 
2786 
2787  print '<table class="border centpercent">';
2788 
2789 
2790  // TODO Move this into tab RH (HierarchicalResponsible must be on both tab)
2791 
2792  // Position/Job
2793  print '<tr><td class="titlefieldcreate">'.$langs->trans("PostOrFunction").'</td>';
2794  print '<td>';
2795  if ($caneditfield) {
2796  print '<input type="text" class="minwidth300 maxwidth500" name="job" value="'.dol_escape_htmltag($object->job).'">';
2797  } else {
2798  print '<input type="hidden" name="job" value="'.dol_escape_htmltag($object->job).'">';
2799  print dol_escape_htmltag($object->job);
2800  }
2801  print '</td></tr>';
2802 
2803  // Weeklyhours
2804  print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
2805  print '<td>';
2806  if ($caneditfield) {
2807  print '<input size="8" type="text" name="weeklyhours" value="'.price2num(GETPOST('weeklyhours') ?GETPOST('weeklyhours') : $object->weeklyhours).'">';
2808  } else {
2809  print price2num($object->weeklyhours);
2810  }
2811  print '</td>';
2812  print "</tr>\n";
2813 
2814  // Sensitive salary/value information
2815  if ((empty($user->socid) && in_array($id, $childids)) // A user can always see salary/value information for its subordinates
2816  || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
2817  || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
2818  $langs->load("salaries");
2819 
2820  // Salary
2821  print '<tr><td>'.$langs->trans("Salary").'</td>';
2822  print '<td>';
2823  print img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<input size="8" type="text" name="salary" value="'.price2num(GETPOST('salary') ?GETPOST('salary') : $object->salary).'">';
2824  print '</td>';
2825  print "</tr>\n";
2826 
2827  // THM
2828  print '<tr><td>';
2829  $text = $langs->trans("THM");
2830  print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
2831  print '</td>';
2832  print '<td>';
2833  if ($caneditfield) {
2834  print '<input size="8" type="text" name="thm" value="'.price2num(GETPOST('thm') ?GETPOST('thm') : $object->thm).'">';
2835  } else {
2836  print ($object->thm != '' ?price($object->thm, '', $langs, 1, -1, -1, $conf->currency) : '');
2837  }
2838  print '</td>';
2839  print "</tr>\n";
2840 
2841  // TJM
2842  print '<tr><td>';
2843  $text = $langs->trans("TJM");
2844  print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm');
2845  print '</td>';
2846  print '<td>';
2847  if ($caneditfield) {
2848  print '<input size="8" type="text" name="tjm" value="'.price2num(GETPOST('tjm') ?GETPOST('tjm') : $object->tjm).'">';
2849  } else {
2850  print ($object->tjm != '' ?price($object->tjm, '', $langs, 1, -1, -1, $conf->currency) : '');
2851  }
2852  print '</td>';
2853  print "</tr>\n";
2854  }
2855 
2856  // Date employment
2857  print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
2858  print '<td>';
2859  if ($caneditfield) {
2860  print $form->selectDate($dateemployment ? $dateemployment : $object->dateemployment, 'dateemployment', 0, 0, 1, 'formdateemployment', 1, 1, 0, '', '', '', '', 1, '', $langs->trans("from"));
2861  } else {
2862  print dol_print_date($object->dateemployment, 'day');
2863  }
2864 
2865  if ($dateemployment && $dateemploymentend) {
2866  print ' - ';
2867  }
2868 
2869  if ($caneditfield) {
2870  print $form->selectDate($dateemploymentend ? $dateemploymentend : $object->dateemploymentend, 'dateemploymentend', 0, 0, 1, 'formdateemploymentend', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
2871  } else {
2872  print dol_print_date($object->dateemploymentend, 'day');
2873  }
2874  print '</td>';
2875  print "</tr>\n";
2876 
2877  // Date birth
2878  print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
2879  print '<td>';
2880  if ($caneditfield) {
2881  echo $form->selectDate($dateofbirth ? $dateofbirth : $object->birth, 'dateofbirth', 0, 0, 1, 'updateuser', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
2882  } else {
2883  print dol_print_date($object->birth, 'day', 'tzserver');
2884  }
2885  print '</td>';
2886  print "</tr>\n";
2887 
2888  print '</table>';
2889 
2890  print dol_get_fiche_end();
2891 
2892  print '<div class="center">';
2893  print '<input value="'.$langs->trans("Save").'" class="button button-save" type="submit" name="save">';
2894  print '&nbsp; &nbsp; &nbsp;';
2895  print '<input value="'.$langs->trans("Cancel").'" class="button button-cancel" type="submit" name="cancel">';
2896  print '</div>';
2897 
2898  print '</form>';
2899  }
2900 
2901  if ($action != 'edit' && $action != 'presend') {
2902  print '<div class="fichecenter"><div class="fichehalfleft">';
2903 
2904  // Generated documents
2905  $filename = dol_sanitizeFileName($object->ref);
2906  $filedir = $conf->user->dir_output."/".dol_sanitizeFileName($object->ref);
2907  $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
2908  $genallowed = $user->hasRight("user", "user", "read");
2909  $delallowed = $user->hasRight("user", "user", "write");
2910 
2911  print $formfile->showdocuments('user', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->model_pdf, 1, 0, 0, 28, 0, '', 0, '', empty($soc->default_lang) ? '' : $soc->default_lang);
2912  $somethingshown = $formfile->numoffiles;
2913 
2914  // Show links to link elements
2915  $linktoelem = $form->showLinkToObjectBlock($object, null, null);
2916  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2917 
2918  print '</div><div class="fichehalfright">';
2919 
2920  // List of actions on element
2921  include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
2922  $formactions = new FormActions($db);
2923  $somethingshown = $formactions->showactions($object, 'user', $socid, 1, 'listactions', 0, '', '', $object->id);
2924 
2925  print '</div></div>';
2926  }
2927 
2928  if (isModEnabled('ldap') && !empty($object->ldap_sid)) {
2929  $ldap->unbind();
2930  }
2931  }
2932 }
2933 
2934 // Add button to autosuggest a key
2935 include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
2936 print dolJSToSetRandomPassword('password', 'generate_password', 0);
2937 if (isModEnabled('api')) {
2938  print dolJSToSetRandomPassword('api_key', 'generate_api_key', 1);
2939 }
2940 
2941 // End of page
2942 llxFooter();
2943 $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(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') elseif($action=='specimen') elseif($action=='setmodel') elseif($action=='del') elseif($action=='setdoc') $formactions
View.
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:449
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 members of a foundation.
Class to manage categories.
Class to manage contact/addresses.
Class to manage a WYSIWYG editor.
Class to manage warehouses.
Class to manage standard extra fields.
Class to manage building of HTML components.
Class to generate html code for admin pages.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
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 LDAP features.
Definition: ldap.class.php:35
const SYNCHRO_LDAP_TO_DOLIBARR
Ldap to Dolibarr synchronization.
Definition: ldap.class.php:141
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage user groups.
Class to manage Dolibarr users.
Definition: user.class.php:48
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
$parameters
Actions.
Definition: card.php:83
if(isModEnabled('facture') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0, $indexdatabase=1, $nolog=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories)
Definition: files.lib.php:1485
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1, $nolog=0)
Remove a file or several files with a mask.
Definition: files.lib.php:1334
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile', $upload_dir='')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:1196
acceptLocalLinktoMedia()
Check the syntax of some PHP code.
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
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...
picto_from_langcode($codelang, $moreatt='', $notitlealt=0)
Return img flag of country for a language code or country code.
load_fiche_titre($titre, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
showValueWithClipboardCPButton($valuetocopy, $showonlyonhover=1, $texttoshow='')
Create a button to copy $valuetocopy in the clipboard (for copy and paste feature).
GETPOSTINT($paramname, $method=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
price2num($amount, $rounding='', $option=0)
Function that return a number with universal decimal format (decimal separator is '.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolButtonToOpenUrlInDialogPopup($name, $label, $buttonstring, $url, $disabled='', $morecss='classlink button bordertransp', $jsonopen='', $backtopagejsfields='', $accesskey='')
Return HTML code to output a button to open a dialog popup box.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
dol_get_fiche_end($notab=0)
Return tab footer of a card.
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).
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)
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of 'autofocus' HTML5 tag)
newToken()
Return the value of token currently saved into session with name 'newtoken'.
dolGetButtonAction($label, $text='', $actionType='default', $url='', $id='', $userRight=1, $params=array())
Function dolGetButtonAction.
getArrayOfSocialNetworks()
Get array of social network dictionary.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='hideonsmartphone', $textfordropdown='')
Show information for admin users or standard users.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding '…' if string larger than length.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart='')
Return a path to have a the directory according to object where files are stored.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
dol_mkdir($dir, $dataroot='', $newmask='')
Creation of a directory (this can create recursive subdir)
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
image_format_supported($file, $acceptsvg=0)
Return if a filename is file name of a supported image format.
Definition: images.lib.php:80
dolJSToSetRandomPassword($htmlname, $htmlnameofbutton='generate_token', $generic=1)
Ouput javacript to autoset a generated password using default module into a HTML element.
getRandomPassword($generic=false, $replaceambiguouschars=null, $length=32)
Return a generated password using default module.
dol_verifyHash($chain, $hash, $type='0')
Compute a hash and compare it to the given one For backward compatibility reasons,...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
user_prepare_head(User $object)
Prepare array with list of tabs.