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