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