Passed
Push — master ( fa5a21...043752 )
by Alxarafe
27:01
created

dolibarr/htdocs/user/card.php (1 issue)

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