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