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