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