dolibarr  9.0.0
card.php
Go to the documentation of this file.
1 <?php
2 /* Copyright (C) 2002-2006 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3  * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
4  * Copyright (C) 2004-2015 Laurent Destailleur <eldy@users.sourceforge.net>
5  * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
6  * Copyright (C) 2005-2018 Regis Houssin <regis.houssin@inodbox.com>
7  * Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
8  * Copyright (C) 2011 Herve Prot <herve.prot@symeos.com>
9  * Copyright (C) 2012-2018 Juanjo Menent <jmenent@2byte.es>
10  * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
11  * Copyright (C) 2013-2016 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
12  * Copyright (C) 2015-2017 Jean-François Ferry <jfefe@aternatik.fr>
13  * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
14  * Copyright (C) 2015-2018 Charlene Benke <charlie@patas-monkey.com>
15  * Copyright (C) 2016 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
16  * Copyright (C) 2018 Frédéric France <frederic.france@netlogic.fr>
17  * Copyright (C) 2018 David Beniamine <David.Beniamine@Tetras-Libre.fr>
18  *
19  * This program is free software; you can redistribute it and/or modify
20  * it under the terms of the GNU General Public License as published by
21  * the Free Software Foundation; either version 3 of the License, or
22  * (at your option) any later version.
23  *
24  * This program is distributed in the hope that it will be useful,
25  * but WITHOUT ANY WARRANTY; without even the implied warranty of
26  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
27  * GNU General Public License for more details.
28  *
29  * You should have received a copy of the GNU General Public License
30  * along with this program. If not, see <http://www.gnu.org/licenses/>.
31  */
32 
38 require '../main.inc.php';
39 require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
40 require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
41 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
48 if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
49 if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
50 if (! empty($conf->categorie->enabled)) require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51 
52 $id = GETPOST('id','int');
53 $action = GETPOST('action','aZ09');
54 $mode = GETPOST('mode','alpha');
55 $confirm = GETPOST('confirm','alpha');
56 $subaction = GETPOST('subaction','alpha');
57 $group = GETPOST("group","int",3);
58 $cancel = GETPOST('cancel','alpha');
59 $contextpage= GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'useracard'; // To manage different context of search
60 
61 // Define value to know what current user can do on users
62 $canadduser=(! empty($user->admin) || $user->rights->user->user->creer);
63 $canreaduser=(! empty($user->admin) || $user->rights->user->user->lire);
64 $canedituser=(! empty($user->admin) || $user->rights->user->user->creer);
65 $candisableuser=(! empty($user->admin) || $user->rights->user->user->supprimer);
66 $canreadgroup=$canreaduser;
67 $caneditgroup=$canedituser;
68 if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
69 {
70  $canreadgroup=(! empty($user->admin) || $user->rights->user->group_advance->read);
71  $caneditgroup=(! empty($user->admin) || $user->rights->user->group_advance->write);
72 }
73 
74 // Define value to know what current user can do on properties of edited user
75 if ($id)
76 {
77  // $user est le user qui edite, $id est l'id de l'utilisateur edite
78  $caneditfield=((($user->id == $id) && $user->rights->user->self->creer)
79  || (($user->id != $id) && $user->rights->user->user->creer));
80  $caneditpassword=((($user->id == $id) && $user->rights->user->self->password)
81  || (($user->id != $id) && $user->rights->user->user->password));
82 }
83 
84 // Security check
85 $socid=0;
86 if ($user->societe_id > 0) $socid = $user->societe_id;
87 $feature2='user';
88 if ($user->id == $id) { $feature2=''; $canreaduser=1; } // A user can always read its own card
89 
90 if (! $canreaduser) {
91  $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
92 }
93 
94 if ($user->id <> $id && ! $canreaduser) accessforbidden();
95 
96 // Load translation files required by page
97 $langs->loadLangs(array('users', 'companies', 'ldap', 'admin', 'hrm'));
98 
99 $object = new User($db);
100 $extrafields = new ExtraFields($db);
101 
102 // fetch optionals attributes and labels
103 $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
104 
105 // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
106 $hookmanager->initHooks(array('usercard','globalcard'));
107 
108 
109 
114 $parameters=array('id' => $id, 'socid' => $socid, 'group' => $group, 'caneditgroup' => $caneditgroup);
115 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
116 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
117 
118 if (empty($reshook)) {
119 
120  if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) {
121  if ($id <> $user->id) {
122  $object->fetch($id);
123  $object->setstatus(0);
124  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
125  exit;
126  }
127  }
128  if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser) {
129  $error = 0;
130 
131  if ($id <> $user->id) {
132  $object->fetch($id);
133 
134  if (!empty($conf->file->main_limit_users)) {
135  $nb = $object->getNbOfUsers("active");
136  if ($nb >= $conf->file->main_limit_users) {
137  $error ++;
138  setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
139  }
140  }
141 
142  if (!$error) {
143  $object->setstatus(1);
144  header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
145  exit;
146  }
147  }
148  }
149 
150  if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) {
151  if ($id <> $user->id) {
152  $object = new User($db);
153  $object->fetch($id);
154  $result = $object->delete();
155  if ($result < 0) {
156  $langs->load("errors");
157  setEventMessages($langs->trans("ErrorUserCannotBeDelete"), null, 'errors');
158  } else {
159  header("Location: ".DOL_URL_ROOT."/user/list.php?restore_lastsearch_values=1");
160  exit;
161  }
162  }
163  }
164 
165  // Action Add user
166  if ($action == 'add' && $canadduser) {
167  $error = 0;
168 
169  if (!$_POST["lastname"]) {
170  $error ++;
171  setEventMessages($langs->trans("NameNotDefined"), null, 'errors');
172  $action = "create"; // Go back to create page
173  }
174  if (!$_POST["login"]) {
175  $error ++;
176  setEventMessages($langs->trans("LoginNotDefined"), null, 'errors');
177  $action = "create"; // Go back to create page
178  }
179 
180  if (!empty($conf->file->main_limit_users)) { // If option to limit users is set
181  $nb = $object->getNbOfUsers("active");
182  if ($nb >= $conf->file->main_limit_users) {
183  $error ++;
184  setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
185  $action = "create"; // Go back to create page
186  }
187  }
188 
189  if (!$error) {
190  $object->lastname = GETPOST("lastname", 'alpha');
191  $object->firstname = GETPOST("firstname", 'alpha');
192  $object->login = GETPOST("login", 'alpha');
193  $object->api_key = GETPOST("api_key", 'alpha');
194  $object->gender = GETPOST("gender", 'alpha');
195  $birth = dol_mktime(0, 0, 0, GETPOST('birthmonth'), GETPOST('birthday'), GETPOST('birthyear'));
196  $object->birth = $birth;
197  $object->admin = GETPOST("admin", 'alpha');
198  $object->address = GETPOST('address', 'alphanohtml');
199  $object->zip = GETPOST('zipcode', 'alphanohtml');
200  $object->town = GETPOST('town', 'alphanohtml');
201  $object->country_id = GETPOST('country_id', 'int');
202  $object->state_id = GETPOST('state_id', 'int');
203  $object->office_phone = GETPOST("office_phone", 'alphanohtml');
204  $object->office_fax = GETPOST("office_fax", 'alphanohtml');
205  $object->user_mobile = GETPOST("user_mobile", 'alphanohtml');
206 
207  $object->skype = GETPOST("skype", 'alphanohtml');
208  $object->twitter = GETPOST("twitter", 'alphanohtml');
209  $object->facebook = GETPOST("facebook", 'alphanohtml');
210 
211  $object->email = preg_replace('/\s+/', '', GETPOST("email", 'alpha'));
212  $object->job = GETPOST("job", 'alpha');
213  $object->signature = GETPOST("signature", 'none');
214  $object->accountancy_code = GETPOST("accountancy_code", 'alphanohtml');
215  $object->note = GETPOST("note", 'none');
216  $object->ldap_sid = GETPOST("ldap_sid", 'alphanohtml');
217  $object->fk_user = GETPOST("fk_user", 'int') > 0 ? GETPOST("fk_user", 'int') : 0;
218  $object->employee = GETPOST('employee', 'alphanohtml');
219 
220  $object->thm = GETPOST("thm", 'alphanohtml') != '' ? GETPOST("thm", 'alphanohtml') : '';
221  $object->tjm = GETPOST("tjm", 'alphanohtml') != '' ? GETPOST("tjm", 'alphanohtml') : '';
222  $object->salary = GETPOST("salary", 'alphanohtml') != '' ? GETPOST("salary", 'alphanohtml') : '';
223  $object->salaryextra = GETPOST("salaryextra", 'alphanohtml') != '' ? GETPOST("salaryextra", 'alphanohtml') : '';
224  $object->weeklyhours = GETPOST("weeklyhours", 'alphanohtml') != '' ? GETPOST("weeklyhours", 'alphanohtml') : '';
225 
226  $object->color = GETPOST("color", 'alphanohtml') != '' ? GETPOST("color", 'alphanohtml') : '';
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', 'alphanohtml');
351  $object->town = GETPOST('town', 'alphanohtml');
352  $object->country_id = GETPOST('country_id', 'int');
353  $object->state_id = GETPOST('state_id', 'int');
354  $object->office_phone = GETPOST("office_phone", 'alphanohtml');
355  $object->office_fax = GETPOST("office_fax", 'alphanohtml');
356  $object->user_mobile = GETPOST("user_mobile", 'alphanohtml');
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','int');
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')
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">'.fieldLabel('Address','address').'</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>'.fieldLabel('Zip','zipcode').'</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>'.fieldLabel('Town','town').'</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>'.fieldLabel('Country','selectcountry_id').'</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>'.fieldLabel('State','state_id').'</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>' . fieldLabel('Categories', 'usercats') . '</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" 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" 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" 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" 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" 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" 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>'.fieldLabel('Employee','employee',0).'</td><td>';
2145  if ($caneditfield)
2146  {
2147  print $form->selectyesno("employee",$object->employee,1);
2148  }else{
2149  if ($object->employee){
2150  print $langs->trans("Yes");
2151  }else{
2152  print $langs->trans("No");
2153  }
2154  }
2155  print '</td></tr>';
2156 
2157  // Hierarchy
2158  print '<tr><td class="titlefield">'.$langs->trans("HierarchicalResponsible").'</td>';
2159  print '<td>';
2160  if ($caneditfield)
2161  {
2162  print $form->select_dolusers($object->fk_user, 'fk_user', 1, array($object->id), 0, '', 0, $object->entity, 0, 0, '', 0, '', 'maxwidth300');
2163  }
2164  else
2165  {
2166  print '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
2167  $huser=new User($db);
2168  $huser->fetch($object->fk_user);
2169  print $huser->getNomUrl(1);
2170  }
2171  print '</td>';
2172  print "</tr>\n";
2173 
2174 
2175  print '</table><hr><table class="border centpercent">';
2176 
2177 
2178  // Address
2179  print '<tr><td class="tdtop titlefield">'.fieldLabel('Address','address').'</td>';
2180  print '<td><textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
2181  print $object->address;
2182  print '</textarea></td></tr>';
2183 
2184  // Zip
2185  print '<tr><td>'.fieldLabel('Zip','zipcode').'</td><td>';
2186  print $formcompany->select_ziptown($object->zip, 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
2187  print '</td></tr>';
2188 
2189  // Town
2190  print '<tr><td>'.fieldLabel('Town','town').'</td><td>';
2191  print $formcompany->select_ziptown($object->town, 'town', array('zipcode', 'selectcountry_id', 'state_id'));
2192  print '</td></tr>';
2193 
2194  // Country
2195  print '<tr><td>'.fieldLabel('Country','selectcounty_id').'</td><td>';
2196  print $form->select_country((GETPOST('country_id')!=''?GETPOST('country_id'):$object->country_id),'country_id');
2197  if ($user->admin) print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"),1);
2198  print '</td></tr>';
2199 
2200  // State
2201  if (empty($conf->global->USER_DISABLE_STATE))
2202  {
2203  print '<tr><td class="tdoverflow">'.fieldLabel('State','state_id').'</td><td>';
2204  print $formcompany->select_state($object->state_id,$object->country_code, 'state_id');
2205  print '</td></tr>';
2206  }
2207 
2208  // Tel pro
2209  print "<tr>".'<td>'.$langs->trans("PhonePro").'</td>';
2210  print '<td>';
2211  if ($caneditfield && empty($object->ldap_sid))
2212  {
2213  print '<input size="20" type="text" name="office_phone" class="flat" value="'.$object->office_phone.'">';
2214  }
2215  else
2216  {
2217  print '<input type="hidden" name="office_phone" value="'.$object->office_phone.'">';
2218  print $object->office_phone;
2219  }
2220  print '</td></tr>';
2221 
2222  // Tel mobile
2223  print "<tr>".'<td>'.$langs->trans("PhoneMobile").'</td>';
2224  print '<td>';
2225  if ($caneditfield && empty($object->ldap_sid))
2226  {
2227  print '<input size="20" type="text" name="user_mobile" class="flat" value="'.$object->user_mobile.'">';
2228  }
2229  else
2230  {
2231  print '<input type="hidden" name="user_mobile" value="'.$object->user_mobile.'">';
2232  print $object->user_mobile;
2233  }
2234  print '</td></tr>';
2235 
2236  // Fax
2237  print "<tr>".'<td>'.$langs->trans("Fax").'</td>';
2238  print '<td>';
2239  if ($caneditfield && empty($object->ldap_sid))
2240  {
2241  print '<input size="20" type="text" name="office_fax" class="flat" value="'.$object->office_fax.'">';
2242  }
2243  else
2244  {
2245  print '<input type="hidden" name="office_fax" value="'.$object->office_fax.'">';
2246  print $object->office_fax;
2247  }
2248  print '</td></tr>';
2249 
2250  // Skype
2251  if (! empty($conf->socialnetworks->enabled))
2252  {
2253  print '<tr><td>'.$langs->trans("Skype").'</td>';
2254  print '<td>';
2255  if ($caneditfield && empty($object->ldap_sid))
2256  {
2257  print '<input size="40" type="text" name="skype" class="flat" value="'.$object->skype.'">';
2258  }
2259  else
2260  {
2261  print '<input type="hidden" name="skype" value="'.$object->skype.'">';
2262  print $object->skype;
2263  }
2264  print '</td></tr>';
2265  }
2266 
2267  // Twitter
2268  if (! empty($conf->socialnetworks->enabled))
2269  {
2270  print '<tr><td>'.$langs->trans("Twitter").'</td>';
2271  print '<td>';
2272  if ($caneditfield && empty($object->ldap_sid))
2273  {
2274  print '<input size="40" type="text" name="twitter" class="flat" value="'.$object->twitter.'">';
2275  }
2276  else
2277  {
2278  print '<input type="hidden" name="twitter" value="'.$object->twitter.'">';
2279  print $object->twitter;
2280  }
2281  print '</td></tr>';
2282  }
2283 
2284  // Skype
2285  if (! empty($conf->socialnetworks->enabled))
2286  {
2287  print '<tr><td>'.$langs->trans("Facebook").'</td>';
2288  print '<td>';
2289  if ($caneditfield && empty($object->ldap_sid))
2290  {
2291  print '<input size="40" type="text" name="facebook" class="flat" value="'.$object->facebook.'">';
2292  }
2293  else
2294  {
2295  print '<input type="hidden" name="facebook" value="'.$object->facebook.'">';
2296  print $object->facebook;
2297  }
2298  print '</td></tr>';
2299  }
2300 
2301  // EMail
2302  print "<tr>".'<td'.(! empty($conf->global->USER_MAIL_REQUIRED)?' class="fieldrequired"':'').'>'.$langs->trans("EMail").'</td>';
2303  print '<td>';
2304  if ($caneditfield && empty($object->ldap_sid))
2305  {
2306  print '<input class="minwidth100" type="text" name="email" class="flat" value="'.$object->email.'">';
2307  }
2308  else
2309  {
2310  print '<input type="hidden" name="email" value="'.$object->email.'">';
2311  print $object->email;
2312  }
2313  print '</td></tr>';
2314 
2315  // OpenID url
2316  if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER))
2317  {
2318  print "<tr>".'<td>'.$langs->trans("OpenIDURL").'</td>';
2319  print '<td>';
2320  if ($caneditfield)
2321  {
2322  print '<input class="minwidth100" type="url" name="openid" class="flat" value="'.$object->openid.'">';
2323  }
2324  else
2325  {
2326  print '<input type="hidden" name="openid" value="'.$object->openid.'">';
2327  print $object->openid;
2328  }
2329  print '</td></tr>';
2330  }
2331 
2332  print '</table><hr><table class="border centpercent">';
2333 
2334  // Accountancy code
2335  if ($conf->accounting->enabled)
2336  {
2337  print "<tr>";
2338  print '<td>'.$langs->trans("AccountancyCode").'</td>';
2339  print '<td>';
2340  if ($caneditfield)
2341  {
2342  print '<input size="30" type="text" class="flat" name="accountancy_code" value="'.$object->accountancy_code.'">';
2343  }
2344  else
2345  {
2346  print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
2347  print $object->accountancy_code;
2348  }
2349  print '</td>';
2350  print "</tr>";
2351  }
2352 
2353  // User color
2354  if (! empty($conf->agenda->enabled))
2355  {
2356  print '<tr><td>'.$langs->trans("ColorUser").'</td>';
2357  print '<td>';
2358  if ($caneditfield)
2359  {
2360  print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', null, 1, '', 'hideifnotset');
2361  }else{
2362  print $formother->showColor($object->color, '');
2363  }
2364  print '</td></tr>';
2365  }
2366 
2367  // Photo
2368  print '<tr>';
2369  print '<td>'.$langs->trans("Photo").'</td>';
2370  print '<td>';
2371  print $form->showphoto('userphoto',$object,60,0,$caneditfield,'photowithmargin','small');
2372  print '</td>';
2373  print '</tr>';
2374 
2375  // Categories
2376  if (!empty( $conf->categorie->enabled ) && !empty( $user->rights->categorie->lire ))
2377  {
2378  print '<tr><td>' . fieldLabel( 'Categories', 'usercats' ) . '</td>';
2379  print '<td>';
2380  $cate_arbo = $form->select_all_categories( Categorie::TYPE_USER, null, null, null, null, 1 );
2381  $c = new Categorie( $db );
2382  $cats = $c->containing($object->id, Categorie::TYPE_USER);
2383  foreach ($cats as $cat) {
2384  $arrayselected[] = $cat->id;
2385  }
2386  if ($caneditfield)
2387  {
2388  print $form->multiselectarray( 'usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%' );
2389  }else{
2390  print $form->showCategories( $object->id, 'user', 1 );
2391  }
2392  print "</td></tr>";
2393  }
2394 
2395  // Status
2396  print '<tr><td>'.$langs->trans("Status").'</td>';
2397  print '<td>';
2398  print $object->getLibStatut(4);
2399  print '</td></tr>';
2400 
2401  // Company / Contact
2402  if (! empty($conf->societe->enabled))
2403  {
2404  print '<tr><td width="25%">'.$langs->trans("LinkToCompanyContact").'</td>';
2405  print '<td>';
2406  if ($object->socid > 0)
2407  {
2408  $societe = new Societe($db);
2409  $societe->fetch($object->socid);
2410  print $societe->getNomUrl(1,'');
2411  if ($object->contactid)
2412  {
2413  $contact = new Contact($db);
2414  $contact->fetch($object->contactid);
2415  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>';
2416  }
2417  }
2418  else
2419  {
2420  print $langs->trans("ThisUserIsNot");
2421  }
2422  print ' ('.$langs->trans("UseTypeFieldToChange").')';
2423  print '</td>';
2424  print "</tr>\n";
2425  }
2426 
2427  // Module Adherent
2428  if (! empty($conf->adherent->enabled))
2429  {
2430  $langs->load("members");
2431  print '<tr><td width="25%">'.$langs->trans("LinkedToDolibarrMember").'</td>';
2432  print '<td>';
2433  if ($object->fk_member)
2434  {
2435  $adh=new Adherent($db);
2436  $adh->fetch($object->fk_member);
2437  $adh->ref=$adh->login; // Force to show login instead of id
2438  print $adh->getNomUrl(1);
2439  }
2440  else
2441  {
2442  print $langs->trans("UserNotLinkedToMember");
2443  }
2444  print '</td>';
2445  print "</tr>\n";
2446  }
2447 
2448  // Multicompany
2449  // TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !!
2450  if (! empty($conf->multicompany->enabled) && is_object($mc))
2451  {
2452  // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
2453  if (! method_exists($mc, 'formObjectOptions'))
2454  {
2455  if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
2456  {
2457  print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
2458  print "<td>".$mc->select_entities($object->entity, 'entity', '', 0, 1); // last parameter 1 means, show also a choice 0=>'all entities'
2459  print "</td></tr>\n";
2460  }
2461  else
2462  {
2463  print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
2464  }
2465  }
2466  }
2467 
2468  // Other attributes
2469  $parameters=array('colspan' => ' colspan="2"');
2470  $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
2471  print $hookmanager->resPrint;
2472  if (empty($reshook))
2473  {
2474  if ($caneditfield)
2475  {
2476  print $object->showOptionals($extrafields,'edit');
2477  }else{
2478  print $object->showOptionals($extrafields,'view');
2479  }
2480  }
2481 
2482  // Signature
2483  print "<tr>".'<td class="tdtop">'.$langs->trans("Signature").'</td>';
2484  print '<td>';
2485  if ($caneditfield)
2486  {
2487  require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
2488  $doleditor=new DolEditor('signature',$object->signature,'',138,'dolibarr_notes','In',false,true,empty($conf->global->FCKEDITOR_ENABLE_USERSIGN)?0:1,ROWS_4,'90%');
2489  print $doleditor->Create(1);
2490  }
2491  else
2492  {
2493  print dol_htmlentitiesbr($object->signature);
2494  }
2495  print '</td></tr>';
2496 
2497 
2498  print '</table><hr><table class="border centpercent">';
2499 
2500 
2501  // TODO Move this into tab RH (HierarchicalResponsible must be on both tab)
2502 
2503  // Position/Job
2504  print '<tr><td class="titlefield">'.$langs->trans("PostOrFunction").'</td>';
2505  print '<td>';
2506  if ($caneditfield)
2507  {
2508  print '<input size="30" type="text" name="job" value="'.$object->job.'">';
2509  }
2510  else
2511  {
2512  print '<input type="hidden" name="job" value="'.$object->job.'">';
2513  print $object->job;
2514  }
2515  print '</td></tr>';
2516 
2517  if ((! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
2518  || (! empty($conf->hrm->enabled) && ! empty($user->rights->hrm->employee->read)))
2519  {
2520  $langs->load("salaries");
2521 
2522  // THM
2523  print '<tr><td>';
2524  $text=$langs->trans("THM");
2525  print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
2526  print '</td>';
2527  print '<td>';
2528  if($caneditfield){
2529  print '<input size="8" type="text" name="thm" value="'.price2num(GETPOST('thm')?GETPOST('thm'):$object->thm).'">';
2530  }else{
2531  print ($object->thm!=''?price($object->thm,'',$langs,1,-1,-1,$conf->currency):'');
2532  }
2533  print '</td>';
2534  print "</tr>\n";
2535 
2536  // TJM
2537  print '<tr><td>';
2538  $text=$langs->trans("TJM");
2539  print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm');
2540  print '</td>';
2541  print '<td>';
2542  if($caneditfield)
2543  {
2544  print '<input size="8" type="text" name="tjm" value="'.price2num(GETPOST('tjm')?GETPOST('tjm'):$object->tjm).'">';
2545  }else{
2546  print ($object->tjm!=''?price($object->tjm,'',$langs,1,-1,-1,$conf->currency):'');
2547  }
2548  print '</td>';
2549  print "</tr>\n";
2550 
2551  // Salary
2552  print '<tr><td>'.$langs->trans("Salary").'</td>';
2553  print '<td>';
2554  print '<input size="8" type="text" name="salary" value="'.price2num(GETPOST('salary')?GETPOST('salary'):$object->salary).'">';
2555  print '</td>';
2556  print "</tr>\n";
2557  }
2558 
2559  // Weeklyhours
2560  print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
2561  print '<td>';
2562  if($caneditfield)
2563  {
2564  print '<input size="8" type="text" name="weeklyhours" value="'.price2num(GETPOST('weeklyhours')?GETPOST('weeklyhours'):$object->weeklyhours).'">';
2565  }else{
2566  print price2num($object->weeklyhours);
2567  }
2568  print '</td>';
2569  print "</tr>\n";
2570 
2571  // Date employment
2572  print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
2573  print '<td>';
2574  if($caneditfield)
2575  {
2576  print $form->selectDate(GETPOST('dateemployment')?GETPOST('dateemployment'):$object->dateemployment, 'dateemployment', 0, 0, 1, 'formdateemployment', 1, 0);
2577  }else{
2578  print dol_print_date($object->dateemployment, 'day');
2579  }
2580  print '</td>';
2581  print "</tr>\n";
2582 
2583  // Date employmentEnd
2584  print '<tr><td>'.$langs->trans("DateEmploymentEnd").'</td>';
2585  print '<td>';
2586  if($caneditfield)
2587  {
2588  print $form->selectDate(GETPOST('dateemploymentend')?GETPOST('dateemploymentend'):$object->dateemploymentend, 'dateemploymentend', 0, 0, 1, 'formdateemploymentend', 1, 0);
2589  }else{
2590  print dol_print_date($object->dateemploymentend, 'day');
2591  }
2592  print '</td>';
2593  print "</tr>\n";
2594 
2595 
2596  // Date birth
2597  print '<tr><td>'.$langs->trans("DateToBirth").'</td>';
2598  print '<td>';
2599  if($caneditfield)
2600  {
2601  echo $form->selectDate(GETPOST('birth')?GETPOST('birth'):$object->birth, 'birth', 0, 0, 1, 'updateuser', 1, 0);
2602  }else{
2603  print dol_print_date($object->birth, 'day');
2604  }
2605  print '</td>';
2606  print "</tr>\n";
2607 
2608  print '</table>';
2609 
2610  dol_fiche_end();
2611 
2612  print '<div align="center">';
2613  print '<input value="'.$langs->trans("Save").'" class="button" type="submit" name="save">';
2614  print '&nbsp; &nbsp; &nbsp;';
2615  print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">';
2616  print '</div>';
2617 
2618  print '</form>';
2619  }
2620 
2621  if ($action != 'edit' && $action != 'presend')
2622  {
2623  print '<div class="fichecenter"><div class="fichehalfleft">';
2624  /*
2625  * Documents generes
2626  */
2627  $filename = dol_sanitizeFileName($object->ref);
2628  $filedir = $conf->user->dir_output . "/" . dol_sanitizeFileName($object->ref);
2629  $urlsource = $_SERVER["PHP_SELF"] . "?id=" . $object->id;
2630  $genallowed = $user->rights->user->user->lire;
2631  $delallowed = $user->rights->user->user->creer;
2632 
2633  print $formfile->showdocuments('user', $filename, $filedir, $urlsource, $genallowed, $delallowed, $object->modelpdf, 1, 0, 0, 28, 0, '', 0, '', $soc->default_lang);
2634  $somethingshown = $formfile->numoffiles;
2635 
2636  // Show links to link elements
2637  $linktoelem = $form->showLinkToObjectBlock($object, null, null);
2638  $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
2639 
2640  print '</div><div class="fichehalfright"><div class="ficheaddleft">';
2641 
2642  // List of actions on element
2643  include_once DOL_DOCUMENT_ROOT . '/core/class/html.formactions.class.php';
2644  $formactions = new FormActions($db);
2645  $somethingshown = $formactions->showactions($object, 'user', $socid, 1);
2646 
2647 
2648  print '</div></div></div>';
2649  }
2650 
2651  if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid)) $ldap->close();
2652  }
2653 }
2654 
2655 if (! empty($conf->api->enabled) && ! empty($conf->use_javascript_ajax))
2656 {
2657  print "\n".'<script type="text/javascript">';
2658  print '$(document).ready(function () {
2659  $("#generate_api_key").click(function() {
2660  $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
2661  action: \'getrandompassword\',
2662  generic: true
2663  },
2664  function(token) {
2665  $("#api_key").val(token);
2666  });
2667  });
2668  });';
2669  print '</script>';
2670 }
2671 
2672 // End of page
2673 llxFooter();
2674 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:56
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve')
Convert a html select field into an ajax combobox.
Definition: ajax.lib.php:374
load_fiche_titre($titre, $morehtmlright='', $picto='title_generic.png', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
GETPOST($paramname, $check='none', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
print
Draft customers invoices.
Definition: index.php:91
dol_move_uploaded_file($src_file, $dest_file, $allowoverwrite, $disablevirusscan=0, $uploaderrorcode=0, $nohook=0, $varfiles='addedfile')
Make control on an uploaded file from an GUI page and move it to final destination.
Definition: files.lib.php:996
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
dol_trunc($string, $size=40, $trunc='right', $stringencoding='UTF-8', $nodot=0, $display=0)
Truncate a string to a particular length adding &#39;...&#39; if string larger than length.
if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) if(! empty($conf->don->enabled) && $user->rights->societe->lire) if(! empty($conf->tax->enabled) && $user->rights->tax->charges->lire) if(! empty($conf->facture->enabled) &&! empty($conf->commande->enabled) && $user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(! empty($conf->facture->enabled) && $user->rights->facture->lire) if(! empty($conf->fournisseur->enabled) && $user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1053
user_prepare_head($object)
Prepare array with list of tabs.
Class to manage building of HTML components.
if(preg_match('/set_([a-z0-9_\-]+)/i', $action, $reg)) if(preg_match('/del_([a-z0-9_\-]+)/i', $action, $reg)) if($action=='set') else if($action=='specimen') else if($action=='setmodel') else if($action=='del') else if($action=='setdoc') $formactions
View.
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
Class to manage contact/addresses.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
get_exdir($num, $level, $alpha, $withoutslash, $object, $modulepart)
Return a path to have a the directory according to object where files are stored. ...
dol_banner_tab($object, $paramid, $morehtml='', $shownav=1, $fieldid='rowid', $fieldref='ref', $morehtmlref='', $moreparam='', $nodbprefix=0, $morehtmlleft='', $morehtmlstatus='', $onlybanner=0, $morehtmlright='')
Show tab footer of a card.
Class to manage Dolibarr users.
Definition: user.class.php:41
Class to manage user groups.
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields...
Class to build HTML component for third parties management Only common components are here...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0)
Show a message to say access is forbidden and stop program Calling this function terminate execution ...
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting a parameter.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='')
Write log message into outputs.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage categories.
info_admin($text, $infoonimgalt=0, $nodiv=0, $admin='1', $morecss='')
Show information for admin users or standard users.
dol_fiche_end($notab=0)
Show tab footer of a card.
Classe permettant la generation de composants html autre Only common components are here...
dol_delete_dir_recursive($dir, $count=0, $nophperrors=0, $onlysub=0, &$countdeleted=0)
Remove a directory $dir and its subdirectories (or only files and subdirectories) ...
Definition: files.lib.php:1273
Class to manage members of a foundation.
llxHeader()
Empty header.
Definition: wrapper.php:44
dol_delete_file($file, $disableglob=0, $nophperrors=0, $nohook=0, $object=null, $allowdotdot=false, $indexdatabase=1)
Remove a file or several files with a mask.
Definition: files.lib.php:1139
if($_POST["cancel"]==$langs->trans("Cancel") &&! $id) if($action=='add' && $_POST["cancel"]<> $langs->trans("Cancel")) if($action=='delete') if($id) $form
Actions.
Definition: card.php:153
Class to offer components to list and upload files.
getRandomPassword($generic=false)
Return a generated password using default module.
price($amount, $form=0, $outlangs='', $trunc=1, $rounding=-1, $forcerounding=-1, $currency_code='')
Function to format a value into an amount for visual output Function used into PDF and HTML pages...
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
Class to manage LDAP features.
Definition: ldap.class.php:30
dol_mkdir($dir, $dataroot='', $newmask=null)
Creation of a directory (this can create recursive subdir)
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0)
Check permissions of a user to show a page and an object.
dol_htmlentitiesbr($stringtoencode, $nl2brmode=0, $pagecodefrom='UTF-8', $removelasteolbr=1)
This function is called to encode a string into a HTML string but differs from htmlentities because a...
Class to manage a WYSIWYG editor.
fieldLabel($langkey, $fieldkey, $fieldrequired=0)
Show a string with the label tag dedicated to the HTML edit field.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it&#39;s its name (generic function)
price2num($amount, $rounding='', $alreadysqlnb=0)
Function that return a number with universal decimal format (decimal separator is &#39;...
dol_set_focus($selector)
Set focus onto field with selector (similar behaviour of &#39;autofocus&#39; HTML5 tag)
dol_fiche_head($links=array(), $active='0', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='')
Show tab header of a card.
img_object($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0)
Show a picto called object_picto (generic function)
$parameters
Actions.
Definition: card.php:114