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