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