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