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