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