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