PageRenderTime 130ms CodeModel.GetById 14ms RepoModel.GetById 1ms app.codeStats 1ms

/htdocs/user/fiche.php

https://bitbucket.org/speedealing/speedealing
PHP | 1156 lines | 855 code | 174 blank | 127 comment | 238 complexity | 20dede5a8da7bbb9efc8fb2504dd72cc MD5 | raw file
Possible License(s): LGPL-3.0, LGPL-2.1, GPL-3.0, MIT
  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-2011 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2013 Regis Houssin <regis.houssin@capnetworks.com>
  7. * Copyright (C) 2005 Lionel Cousteix <etm_ltd@tiscali.co.uk>
  8. * Copyright (C) 2011-2013 Herve Prot <herve.prot@symeos.com>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  22. */
  23. require '../main.inc.php';
  24. require_once DOL_DOCUMENT_ROOT . '/user/class/user.class.php';
  25. require_once DOL_DOCUMENT_ROOT . '/user/class/usergroup.class.php';
  26. require_once DOL_DOCUMENT_ROOT . '/contact/class/contact.class.php';
  27. require_once DOL_DOCUMENT_ROOT . '/core/lib/images.lib.php';
  28. require_once DOL_DOCUMENT_ROOT . '/core/lib/usergroups.lib.php';
  29. if (!empty($conf->ldap->enabled))
  30. require_once DOL_DOCUMENT_ROOT . '/core/class/ldap.class.php';
  31. if (!empty($conf->adherent->enabled))
  32. require_once DOL_DOCUMENT_ROOT . '/adherent/class/adherent.class.php';
  33. if (!empty($conf->multicompany->enabled))
  34. dol_include_once("/multicompany/class/actions_multicompany.class.php");
  35. $id = GETPOST('id');
  36. $action = GETPOST("action");
  37. $group = GETPOST("group", "alpha");
  38. $confirm = GETPOST("confirm");
  39. // Define value to know what current user can do on users
  40. $canadduser = ($user->admin || $user->rights->user->user->creer);
  41. $canreaduser = ($user->admin || $user->rights->user->user->lire);
  42. $canedituser = ($user->admin || $user->id == $id);
  43. $candisableuser = ($user->admin || $user->rights->user->user->supprimer);
  44. $caneditperms = ($user->admin || $user->rights->user->user->creer);
  45. $canreadgroup = $canreaduser;
  46. $caneditgroup = $canedituser;
  47. // Define value to know what current user can do on properties of edited user
  48. if ($id) {
  49. // $user est le user qui edite, $_GET["id"] est l'id de l'utilisateur edite
  50. $caneditfield = ((($user->id == $id) && $user->rights->user->self->creer) || (($user->id != $id) && $user->rights->user->user->creer));
  51. $caneditpassword = ((($user->id == $id) && $user->rights->user->self->password) || (($user->id != $id) && $user->rights->user->user->password));
  52. }
  53. // Security check
  54. $socid = 0;
  55. if ($user->societe_id > 0)
  56. $socid = $user->societe_id;
  57. $feature2 = 'user';
  58. if ($user->id == $id) {
  59. $feature2 = '';
  60. $canreaduser = 1;
  61. } // A user can always read its own card
  62. $result = restrictedArea($user, 'user', $id, '&user', $feature2);
  63. if ($user->id <> $id && !$canreaduser)
  64. accessforbidden();
  65. $langs->load("users");
  66. $langs->load("companies");
  67. $langs->load("ldap");
  68. $form = new Form($db);
  69. $edituser = new User($db);
  70. $fuser = new User($db);
  71. /**
  72. * Actions
  73. */
  74. if ($action == 'add_right' && $caneditperms) {
  75. try {
  76. $fuser->load($id);
  77. // For avoid error in strict mode
  78. if (!is_object($fuser->rights))
  79. $fuser->rights = new stdClass();
  80. $fuser->rights->$_GET['pid'] = true;
  81. $fuser->record(); // TODO BUG FIX DOESN'T WORK
  82. } catch (Exception $e) {
  83. $mesg = $e->getMessage();
  84. setEventMessage($mesg, 'errors');
  85. }
  86. Header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
  87. exit;
  88. }
  89. if ($action == 'remove_right' && $caneditperms) {
  90. try {
  91. $fuser->load($id);
  92. unset($fuser->rights->$_GET['pid']);
  93. $fuser->record();
  94. } catch (Exception $e) {
  95. $mesg = $e->getMessage();
  96. setEventMessage($mesg, 'errors');
  97. }
  98. Header("Location: " . $_SERVER['PHP_SELF'] . "?id=" . $id);
  99. exit;
  100. }
  101. if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser) {
  102. if ($id <> $user->id) {
  103. $edituser->load($id);
  104. $edituser->setstatus(0);
  105. Header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $id);
  106. exit;
  107. }
  108. }
  109. if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser) {
  110. if ($id <> $user->id) {
  111. $error = 0;
  112. $edituser->load($id);
  113. if (!empty($conf->file->main_limit_users)) {
  114. $nb = $edituser->getNbOfUsers("active", 1);
  115. if ($nb >= $conf->file->main_limit_users) {
  116. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  117. $error++;
  118. }
  119. }
  120. if (!$error) {
  121. $edituser->setstatus(1);
  122. Header("Location: " . $_SERVER['PHP_SELF'] . '?id=' . $id);
  123. exit;
  124. }
  125. }
  126. }
  127. if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser) {
  128. if ($id <> $user->id) {
  129. $edituser->id = $id;
  130. $result = $edituser->delete();
  131. if ($result < 0) {
  132. $langs->load("errors");
  133. setEventMessage($langs->trans("ErrorUserCannotBeDelete"), 'errors');
  134. } else {
  135. Header("Location: index.php");
  136. exit;
  137. }
  138. }
  139. }
  140. // Action ajout user
  141. if ((($action == 'add' && $canadduser) || ($action == 'update' && $canedituser)) && !$_POST["cancel"]) {
  142. $error = 0;
  143. if (!$_POST["nom"]) {
  144. setEventMessage($langs->trans("NameNotDefined"), 'errors');
  145. $error++;
  146. if ($action == 'add')
  147. $action = "create"; // Go back to create page
  148. else
  149. $action = "edit";
  150. }
  151. if (!$_POST["login"]) {
  152. setEventMessage($langs->trans("LoginNotDefined"), 'errors');
  153. $error++;
  154. if ($action == 'add')
  155. $action = "create"; // Go back to create page
  156. else
  157. $action = "edit";
  158. }
  159. if (!isValidEMail($_POST["email"])) {
  160. $langs->load("errors");
  161. setEventMessage($langs->trans("ErrorBadEMail"), 'errors');
  162. $error++;
  163. if ($action == 'add')
  164. $action = "create"; // Go back to create page
  165. else
  166. $action = "edit";
  167. }
  168. if (!empty($conf->file->main_limit_users) && $action == 'add') { // If option to limit users is set
  169. $nb = $edituser->getNbOfUsers("active", 1);
  170. if ($nb >= $conf->file->main_limit_users) {
  171. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  172. $action = "create"; // Go back to create page
  173. $error++;
  174. }
  175. }
  176. if (!$error) {
  177. if ($action == "update")
  178. $edituser->load($id);
  179. $edituser->Lastname = $_POST["nom"];
  180. $edituser->Firstname = $_POST["prenom"];
  181. $edituser->name = $_POST["login"];
  182. $edituser->pass = $_POST["password"];
  183. $edituser->admin = (bool) $_POST["admin"];
  184. $edituser->PhonePro = $_POST["PhonePro"];
  185. $edituser->Fax = $_POST["Fax"];
  186. $edituser->PhoneMobile = $_POST["user_mobile"];
  187. $edituser->email = $_POST["email"];
  188. $edituser->Signature = $_POST["signature"];
  189. $edituser->entity = $_POST["default_entity"];
  190. if (GETPOST('deletephoto')) {
  191. $del_photo = $edituser->Photo;
  192. unset($edituser->Photo);
  193. } elseif (!empty($_FILES['photo']['name']))
  194. $edituser->Photo = dol_sanitizeFileName($_FILES['photo']['name']);
  195. $id = $edituser->update($user, 0, $action);
  196. if ($id == $user->name)
  197. dol_delcache("user:" . $id);
  198. //print $id;
  199. if ($id == $edituser->id) {
  200. $file_OK = is_uploaded_file($_FILES['photo']['tmp_name']);
  201. if (GETPOST('deletephoto') && !empty($del_photo)) {
  202. $edituser->deleteFile($del_photo);
  203. }
  204. if ($file_OK) {
  205. if (image_format_supported($_FILES['photo']['name']) > 0) {
  206. $edituser->storeFile('photo');
  207. } else {
  208. $errmsgs[] = "ErrorBadImageFormat";
  209. }
  210. }
  211. Header("Location: " . $_SERVER['PHP_SELF'] . '?id=user:' . $id);
  212. exit;
  213. } else {
  214. $langs->load("errors");
  215. if (is_array($edituser->errors) && count($edituser->errors))
  216. setEventMessage(join('<br>', $langs->trans($edituser->errors)), 'errors');
  217. else
  218. setEventMessage($langs->trans($edituser->error), 'errors');
  219. //print $edituser->error;
  220. if ($action == "add")
  221. $action = "create"; // Go back to create page
  222. if ($action == "update")
  223. $action = "edit"; // Go back to create page
  224. }
  225. }
  226. }
  227. // Action ajout groupe utilisateur
  228. if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield) {
  229. if ($group) {
  230. $edituser->load($id);
  231. if ($action == 'addgroup') {
  232. $edituser->roles[] = $group;
  233. $edituser->addRoleToUser($group);
  234. }
  235. if ($action == 'removegroup') {
  236. unset($edituser->roles[array_search($group, $edituser->roles)]);
  237. $edituser->roles = array_merge($edituser->roles);
  238. $edituser->removeRoleFromUser($group);
  239. }
  240. $edituser->record($edituser->id == $user->id);
  241. header("Location: fiche.php?id=" . $id);
  242. exit;
  243. }
  244. }
  245. /*
  246. * View
  247. */
  248. llxHeader('', $langs->trans("UserCard"));
  249. $form = new Form($db);
  250. if (($action == 'create') || ($action == 'adduserldap')) {
  251. /*
  252. * Affichage fiche en mode creation
  253. */
  254. print_fiche_titre($langs->trans("NewUser"));
  255. print '<div class="with-padding">';
  256. print $langs->trans("CreateInternalUserDesc");
  257. print "<br>";
  258. print "<br>";
  259. print '<form action="' . $_SERVER["PHP_SELF"] . '" method="post" name="createuser">';
  260. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  261. print '<input type="hidden" name="action" value="add">';
  262. if ($ldap_sid)
  263. print '<input type="hidden" name="ldap_sid" value="' . $ldap_sid . '">';
  264. print '<input type="hidden" name="default_entity" value="' . $conf->Couchdb->name . '">';
  265. print '<table class="border" width="100%">';
  266. print '<tr>';
  267. // Nom
  268. print '<td valign="top" width="160"><span class="fieldrequired">' . $langs->trans("Lastname") . '</span></td>';
  269. print '<td>';
  270. if ($ldap_nom) {
  271. print '<input type="hidden" name="nom" value="' . $ldap_nom . '">';
  272. print $ldap_nom;
  273. } else {
  274. print '<input size="30" type="text" name="nom" value="' . $_POST["nom"] . '">';
  275. }
  276. print '</td></tr>';
  277. // Prenom
  278. print '<tr><td valign="top">' . $langs->trans("Firstname") . '</td>';
  279. print '<td>';
  280. if ($ldap_prenom) {
  281. print '<input type="hidden" name="prenom" value="' . $ldap_prenom . '">';
  282. print $ldap_prenom;
  283. } else {
  284. print '<input size="30" type="text" name="prenom" value="' . $_POST["prenom"] . '">';
  285. }
  286. print '</td></tr>';
  287. // Login
  288. print '<tr><td valign="top"><span class="fieldrequired">' . $langs->trans("Login") . '</span></td>';
  289. print '<td>';
  290. if ($ldap_login) {
  291. print '<input type="hidden" name="login" value="' . $ldap_login . '">';
  292. print $ldap_login;
  293. } elseif ($ldap_loginsmb) {
  294. print '<input type="hidden" name="login" value="' . $ldap_loginsmb . '">';
  295. print $ldap_loginsmb;
  296. } else {
  297. print '<input size="20" maxsize="24" type="text" name="login" value="' . $_POST["login"] . '">';
  298. }
  299. print '</td></tr>';
  300. $generated_password = '';
  301. if (!$ldap_sid) { // ldap_sid is for activedirectory
  302. require_once(DOL_DOCUMENT_ROOT . "/core/lib/security2.lib.php");
  303. $generated_password = getRandomPassword('');
  304. }
  305. $password = $generated_password;
  306. // Mot de passe
  307. print '<tr><td valign="top">' . $langs->trans("Password") . '</td>';
  308. print '<td>';
  309. // We do not use a field password but a field text to show new password to use.
  310. print '<input size="30" maxsize="32" type="text" name="password" value="' . $password . '">';
  311. print '</td></tr>';
  312. // Administrateur
  313. if ($user->admin) {
  314. print '<tr><td valign="top">' . $langs->trans("Administrator") . '</td>';
  315. print '<td>';
  316. print $form->selectyesno('admin', $_POST["admin"], 1);
  317. print "</td></tr>\n";
  318. }
  319. // Type
  320. print '<tr><td valign="top">' . $langs->trans("Type") . '</td>';
  321. print '<td>';
  322. print $form->textwithpicto($langs->trans("Internal"), $langs->trans("InternalExternalDesc"));
  323. print '</td></tr>';
  324. // Tel
  325. print '<tr><td valign="top">' . $langs->trans("PhonePro") . '</td>';
  326. print '<td>';
  327. if ($ldap_phone) {
  328. print '<input type="hidden" name="office_phone" value="' . $ldap_phone . '">';
  329. print $ldap_phone;
  330. } else {
  331. print '<input size="20" type="text" name="office_phone" value="' . $_POST["office_phone"] . '">';
  332. }
  333. print '</td></tr>';
  334. // Tel portable
  335. print '<tr><td valign="top">' . $langs->trans("PhoneMobile") . '</td>';
  336. print '<td>';
  337. if ($ldap_mobile) {
  338. print '<input type="hidden" name="user_mobile" value="' . $ldap_mobile . '">';
  339. print $ldap_mobile;
  340. } else {
  341. print '<input size="20" type="text" name="user_mobile" value="' . $_POST["user_mobile"] . '">';
  342. }
  343. print '</td></tr>';
  344. // Fax
  345. print '<tr><td valign="top">' . $langs->trans("Fax") . '</td>';
  346. print '<td>';
  347. if ($ldap_fax) {
  348. print '<input type="hidden" name="office_fax" value="' . $ldap_fax . '">';
  349. print $ldap_fax;
  350. } else {
  351. print '<input size="20" type="text" name="office_fax" value="' . $_POST["office_fax"] . '">';
  352. }
  353. print '</td></tr>';
  354. // EMail
  355. print '<tr><td valign="top" class="fieldrequired">' . $langs->trans("email") . '</td>';
  356. print '<td>';
  357. print '<input size="40" type="text" name="email" value="' . $_POST["email"] . '">';
  358. print '</td></tr>';
  359. // Signature
  360. print '<tr><td valign="top">' . $langs->trans("Signature") . '</td>';
  361. print '<td>';
  362. print '<textarea rows="' . ROWS_5 . '" cols="90" name="signature">' . $_POST["signature"] . '</textarea>';
  363. print '</td></tr>';
  364. print "</table>\n";
  365. print '<center><br><input class="button" value="' . $langs->trans("CreateUser") . '" name="create" type="submit"></center>';
  366. print "</form>";
  367. print "</div>";
  368. } else {
  369. /*
  370. * Visu et edition
  371. */
  372. if ($id) {
  373. $fuser = new User($db);
  374. $fuser->load($id);
  375. $fuser->getrights();
  376. // Show tabs
  377. $head = user_prepare_head($fuser);
  378. $title = $langs->trans("User");
  379. print_fiche_titre($title);
  380. print '<div class="with-padding">';
  381. print '<div class="columns">';
  382. print column_start();
  383. dol_fiche_head($head, 'user', $title, 0, 'user');
  384. /*
  385. * Confirmation desactivation
  386. */
  387. if ($action == 'disable') {
  388. $ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?id=$fuser->id", $langs->trans("DisableAUser"), $langs->trans("ConfirmDisableUser", $fuser->login), "confirm_disable", '', 0, 1);
  389. if ($ret == 'html')
  390. print '<br>';
  391. }
  392. /*
  393. * Confirmation activation
  394. */
  395. if ($action == 'enable') {
  396. $ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?id=$fuser->id", $langs->trans("EnableAUser"), $langs->trans("ConfirmEnableUser", $fuser->login), "confirm_enable", '', 0, 1);
  397. if ($ret == 'html')
  398. print '<br>';
  399. }
  400. /*
  401. * Confirmation suppression
  402. */
  403. if ($action == 'delete') {
  404. $ret = $form->form_confirm($_SERVER["PHP_SELF"] . "?id=$fuser->id", $langs->trans("DeleteAUser"), $langs->trans("ConfirmDeleteUser", $fuser->login), "confirm_delete", '', 0, 1);
  405. if ($ret == 'html')
  406. print '<br>';
  407. }
  408. /*
  409. * Fiche en mode visu
  410. */
  411. if ($action != 'edit') {
  412. print '<table class="border" width="100%">';
  413. // Ref
  414. print '<tr><td width="25%" valign="top">' . $langs->trans("Ref") . '</td>';
  415. print '<td colspan="2">';
  416. print $form->showrefnav($fuser, 'id', '', $user->rights->user->user->lire || $user->admin);
  417. print '</td>';
  418. print '</tr>' . "\n";
  419. $rowspan = 14;
  420. if ($conf->societe->enabled)
  421. $rowspan++;
  422. if ($conf->adherent->enabled)
  423. $rowspan++;
  424. // Lastname
  425. print '<tr><td valign="top">' . $langs->trans("Lastname") . '</td>';
  426. print '<td>' . $fuser->Lastname . '</td>';
  427. // Photo
  428. print '<td align="center" valign="middle" width="25%" rowspan="' . $rowspan . '">';
  429. print $form->showphoto('userphoto', $fuser, 100);
  430. print '</td>';
  431. print '</tr>' . "\n";
  432. // Firstname
  433. print '<tr><td valign="top">' . $langs->trans("Firstname") . '</td>';
  434. print '<td>' . $fuser->Firstname . '</td>';
  435. print '</tr>' . "\n";
  436. // Login
  437. print '<tr><td valign="top">' . $langs->trans("Login") . '</td>';
  438. if ($fuser->ldap_sid && $fuser->statut == 0) {
  439. print '<td class="error">' . $langs->trans("LoginAccountDisableInSpeedealing") . '</td>';
  440. } else {
  441. print '<td>' . $fuser->name . '</td>';
  442. }
  443. print '</tr>' . "\n";
  444. // Password
  445. print '<tr><td valign="top">' . $langs->trans("Password") . '</td>';
  446. print '<td>';
  447. print $langs->trans("Hidden");
  448. print "</td>";
  449. print '</tr>' . "\n";
  450. // Administrator
  451. $name = $fuser->name;
  452. if ($user->admin) {
  453. $admins = $fuser->getUserAdmins();
  454. if (isset($admins->$name))
  455. $fuser->admin = true;
  456. else
  457. $fuser->admin = false;
  458. }
  459. else
  460. $fuser->admin = false;
  461. print '<tr><td valign="top">' . $langs->trans("Administrator") . '</td><td>';
  462. if ($fuser->admin) {
  463. print $form->textwithpicto(yn($fuser->admin), $langs->trans("AdministratorDesc"), 1, "admin");
  464. } else {
  465. print yn($fuser->admin);
  466. }
  467. print '</td></tr>' . "\n";
  468. // Default entity
  469. print '<tr><td valign="top">' . $langs->trans("Entity") . '</td><td>';
  470. print $fuser->entity;
  471. print '</td></tr>' . "\n";
  472. // Tel pro
  473. print '<tr><td valign="top">' . $langs->trans("PhonePro") . '</td>';
  474. print '<td>' . dol_print_phone($fuser->PhonePro, '', 0, 0, 1) . '</td>';
  475. print '</tr>' . "\n";
  476. // Tel mobile
  477. print '<tr><td valign="top">' . $langs->trans("PhoneMobile") . '</td>';
  478. print '<td>' . dol_print_phone($fuser->PhoneMobile, '', 0, 0, 1) . '</td>';
  479. print '</tr>' . "\n";
  480. // Fax
  481. print '<tr><td valign="top">' . $langs->trans("Fax") . '</td>';
  482. print '<td>' . dol_print_phone($fuser->Fax, '', 0, 0, 1) . '</td>';
  483. print '</tr>' . "\n";
  484. // EMail
  485. print '<tr><td valign="top">' . $langs->trans("EMail") . '</td>';
  486. print '<td>' . dol_print_email($fuser->email, 0, 0, 1) . '</td>';
  487. print "</tr>\n";
  488. // Signature
  489. print '<tr><td valign="top">' . $langs->trans('Signature') . '</td>';
  490. print '<td>' . $fuser->Signature . '</td>';
  491. print "</tr>\n";
  492. // Statut
  493. print '<tr><td valign="top">' . $langs->trans("Status") . '</td>';
  494. print '<td>';
  495. print $fuser->getLibStatus();
  496. print '</td>';
  497. print '</tr>' . "\n";
  498. print '<tr><td valign="top">' . $langs->trans("LastConnexion") . '</td>';
  499. print '<td>' . dol_print_date($fuser->datelastlogin, "dayhour") . '</td>';
  500. print "</tr>\n";
  501. print '<tr><td valign="top">' . $langs->trans("PreviousConnexion") . '</td>';
  502. print '<td>' . dol_print_date($fuser->datepreviouslogin, "dayhour") . '</td>';
  503. print "</tr>\n";
  504. if (preg_match('/myopenid/', $conf->authmode)) {
  505. print '<tr><td valign="top">' . $langs->trans("url_openid") . '</td>';
  506. print '<td>' . $fuser->openid . '</td>';
  507. print "</tr>\n";
  508. }
  509. // Autres caracteristiques issus des autres modules
  510. // Company / Contact
  511. if ($conf->societe->enabled) {
  512. print '<tr><td valign="top">' . $langs->trans("LinkToCompanyContact") . '</td>';
  513. print '<td>';
  514. if ($fuser->societe_id > 0) {
  515. $societe = new Societe($db);
  516. $societe->fetch($fuser->societe_id);
  517. print $societe->getNomUrl(1, '');
  518. } else {
  519. print $langs->trans("ThisUserIsNot");
  520. }
  521. if ($fuser->contact_id) {
  522. $contact = new Contact($db);
  523. $contact->fetch($fuser->contact_id);
  524. if ($fuser->societe_id > 0)
  525. print ' / ';
  526. else
  527. print '<br>';
  528. print '<a href="' . DOL_URL_ROOT . '/contact/fiche.php?id=' . $fuser->contact_id . '">' . img_object($langs->trans("ShowContact"), 'contact') . ' ' . dol_trunc($contact->getFullName($langs), 32) . '</a>';
  529. }
  530. print '</td>';
  531. print '</tr>' . "\n";
  532. }
  533. // Module Adherent
  534. if ($conf->adherent->enabled) {
  535. $langs->load("members");
  536. print '<tr><td valign="top">' . $langs->trans("LinkedToSpeedealingMember") . '</td>';
  537. print '<td>';
  538. if ($fuser->fk_member) {
  539. $adh = new Adherent($db);
  540. $adh->fetch($fuser->fk_member);
  541. $adh->ref = $adh->getFullname($langs); // Force to show login instead of id
  542. print $adh->getNomUrl(1);
  543. } else {
  544. print $langs->trans("UserNotLinkedToMember");
  545. }
  546. print '</td>';
  547. print '</tr>' . "\n";
  548. }
  549. print "</table>\n";
  550. /*
  551. * Buttons actions
  552. */
  553. print '<div class="tabsAction">';
  554. print '<span class="button-group">';
  555. if ($caneditfield) {
  556. print '<a class="button icon-pencil" href="' . $_SERVER["PHP_SELF"] . '?id=' . $fuser->id . '&amp;action=edit">' . $langs->trans("Modify") . '</a>';
  557. }
  558. // Activer
  559. if ($candisableuser && $fuser->Status != "ENABLE") {
  560. print '<a class="button icon-lock" href="' . $_SERVER["PHP_SELF"] . '?id=' . $fuser->id . '&amp;action=enable">' . $langs->trans("Reactivate") . '</a>';
  561. }
  562. // Desactiver
  563. if ($candisableuser && $fuser->Status == "ENABLE") {
  564. print '<a class="button icon-unlock" href="' . $_SERVER["PHP_SELF"] . '?action=disable&amp;id=' . $fuser->id . '">' . $langs->trans("DisableUser") . '</a>';
  565. }
  566. // Delete
  567. if ($user->id <> $id && $candisableuser) {
  568. print '<a class="button red-gradient icon-trash" href="' . $_SERVER["PHP_SELF"] . '?action=delete&amp;id=' . $fuser->id . '">' . $langs->trans("DeleteUser") . '</a>';
  569. }
  570. print "</span></div>";
  571. print '</div>';
  572. print column_end();
  573. /*
  574. * Liste des groupes dans lequel est l'utilisateur
  575. */
  576. if ($canreadgroup) {
  577. print column_start();
  578. print start_box($langs->trans("ListOfGroups"), "16-Users-2.png");
  579. // On selectionne les users qui ne sont pas deja dans le groupe
  580. $exclude = array();
  581. if (!empty($fuser->roles)) {
  582. foreach ($fuser->roles as $useringroup) {
  583. $exclude[] = $useringroup;
  584. }
  585. }
  586. print '<form action="' . $_SERVER['PHP_SELF'] . '?id=' . $fuser->id . '" method="POST">' . "\n";
  587. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  588. print '<input type="hidden" name="action" value="addgroup">';
  589. print '<table class="noborder" width="100%">' . "\n";
  590. print '<tr class="liste_titre"><td class="liste_titre" width="25%">' . $langs->trans("NonAffectedUsers") . '</td>' . "\n";
  591. print '<td>';
  592. print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '');
  593. print '</td>';
  594. //print '<td valign="top">' . $langs->trans("Administrator") . '</td>';
  595. //print "<td>" . $form->selectyesno('admin', 0, 1);
  596. //print "</td>\n";
  597. print '<td><input type="submit" class="button tiny" value="' . $langs->trans("Add") . '">';
  598. print '</td></tr>' . "\n";
  599. print '</table></form>' . "\n";
  600. print '<br>';
  601. /*
  602. * Groupes affectes
  603. */
  604. print '<table class="display" id="group">';
  605. print '<thead>';
  606. print '<tr>';
  607. print '<th>' . $langs->trans("Group") . '</th>';
  608. $obj->aoColumns[$i] = new stdClass();
  609. $obj->aoColumns[$i]->mDataProp = "";
  610. $i++;
  611. print '<th>' . $langs->trans("Action") . '</th>';
  612. $obj->aoColumns[$i] = new stdClass();
  613. $obj->aoColumns[$i]->mDataProp = "";
  614. $obj->aoColumns[$i]->sClass = "fright content_actions";
  615. $i++;
  616. print "</tr>\n";
  617. print '</thead>';
  618. print '<tbody>';
  619. if (!empty($fuser->roles)) {
  620. $var = True;
  621. foreach ($fuser->roles as $aRow) {
  622. $var = !$var;
  623. $useringroup = new UserGroup($db);
  624. try {
  625. $useringroup->load("group:" . $aRow);
  626. } catch (Exception $e) {
  627. $useringroup->name = "Deleted";
  628. }
  629. print "<tr $bc[$var]>";
  630. print '<td>';
  631. print '<a href="' . DOL_URL_ROOT . '/user/group/fiche.php?id=' . $useringroup->id . '">' . img_object($langs->trans("ShowGroup"), "group") . ' ' . $useringroup->name . '</a>';
  632. if ($useringroup->admin)
  633. print img_picto($langs->trans("Administrator"), 'star');
  634. print '</td>';
  635. print '<td>';
  636. if ($user->admin) {
  637. print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $fuser->id . '&amp;action=removegroup&amp;group=' . $useringroup->name . '">';
  638. print img_delete($langs->trans("RemoveFromGroup"));
  639. } else {
  640. print "-";
  641. }
  642. print "</td></tr>\n";
  643. }
  644. }
  645. print '<tbody>';
  646. print "</table>";
  647. $obj->aaSorting = array(array(0, "asc"));
  648. $obj->sDom = 'l<fr>t<\"clear\"rtip>';
  649. $fuser->datatablesCreate($obj, "group");
  650. print end_box();
  651. print column_end();
  652. print column_start();
  653. print start_box($langs->trans("Permissions"), "16-User-2.png");
  654. // Search all modules with permission and reload permissions def.
  655. /*
  656. * Ecran ajout/suppression permission
  657. */
  658. if ($user->admin)
  659. print info_admin($langs->trans("WarningOnlyPermissionOfActivatedModules"));
  660. $i = 0;
  661. $obj = new stdClass();
  662. print '<table class="display dt_act" id="perm_rights">';
  663. print'<thead>';
  664. print'<tr>';
  665. print'<th>';
  666. print'</th>';
  667. $obj->aoColumns[$i] = new stdClass();
  668. $obj->aoColumns[$i]->mDataProp = "id";
  669. $obj->aoColumns[$i]->sDefaultContent = "";
  670. $obj->aoColumns[$i]->bVisible = false;
  671. $i++;
  672. print'<th class="essential">';
  673. print $langs->trans("Module");
  674. print'</th>';
  675. $obj->aoColumns[$i] = new stdClass();
  676. $obj->aoColumns[$i]->mDataProp = "name";
  677. $obj->aoColumns[$i]->sDefaultContent = "";
  678. $obj->aoColumns[$i]->sWidth = "18em";
  679. $i++;
  680. print'<th>';
  681. print $langs->trans("Permission");
  682. print'</th>';
  683. $obj->aoColumns[$i] = new stdClass();
  684. $obj->aoColumns[$i]->mDataProp = "desc";
  685. $obj->aoColumns[$i]->sDefaultContent = "";
  686. $obj->aoColumns[$i]->bVisible = true;
  687. $i++;
  688. print'<th class="essential">';
  689. print $langs->trans("Enabled");
  690. print'</th>';
  691. $obj->aoColumns[$i] = new stdClass();
  692. $obj->aoColumns[$i]->mDataProp = "Status";
  693. $obj->aoColumns[$i]->sDefaultContent = "false";
  694. $obj->aoColumns[$i]->sClass = "center";
  695. print'</tr>';
  696. print'</thead>';
  697. $obj->fnDrawCallback = "function(oSettings){
  698. if ( oSettings.aiDisplay.length == 0 )
  699. {
  700. return;
  701. }
  702. var nTrs = jQuery('#perm_rights tbody tr');
  703. var iColspan = nTrs[0].getElementsByTagName('td').length;
  704. var sLastGroup = '';
  705. for ( var i=0 ; i<nTrs.length ; i++ )
  706. {
  707. var iDisplayIndex = oSettings._iDisplayStart + i;
  708. var sGroup = oSettings.aoData[ oSettings.aiDisplay[iDisplayIndex] ]._aData['name'];
  709. if (sGroup!=null && sGroup!='' && sGroup != sLastGroup)
  710. {
  711. var nGroup = document.createElement('tr');
  712. var nCell = document.createElement('td');
  713. nCell.colSpan = iColspan;
  714. nCell.className = 'group';
  715. nCell.innerHTML = sGroup;
  716. nGroup.appendChild( nCell );
  717. nTrs[i].parentNode.insertBefore( nGroup, nTrs[i] );
  718. sLastGroup = sGroup;
  719. }
  720. }
  721. }";
  722. $i = 0;
  723. print'<tfoot>';
  724. print'</tfoot>';
  725. print'<tbody>';
  726. $object = new DolibarrModules($db);
  727. try {
  728. $result = $object->getView("default_right");
  729. } catch (Exception $exc) {
  730. print $exc->getMessage();
  731. }
  732. if (count($result->rows)) {
  733. foreach ($result->rows as $aRow) {
  734. print'<tr>';
  735. $object->name = $aRow->value->name;
  736. $object->numero = $aRow->value->numero;
  737. $object->rights_class = $aRow->value->rights_class;
  738. $object->id = $aRow->value->id;
  739. $object->perm = $aRow->value->perm;
  740. $object->desc = $aRow->value->desc;
  741. $object->Status = ($aRow->value->Status == true ? "true" : "false");
  742. print '<td>' . $aRow->value->id . '</td>';
  743. print '<td>' . img_object('', $aRow->value->picto) . " " . $object->getName() . '</td>';
  744. print '<td>' . $object->getPermDesc() . '<a name="' . $aRow->value->id . '">&nbsp;</a></td>';
  745. print '<td>';
  746. $perm = $aRow->value->id;
  747. $perm0 = (string) $object->perm[0];
  748. $perm1 = $object->perm[1];
  749. $right_class = $object->rights_class;
  750. /* if ($caneditperms) { */
  751. if ($aRow->value->Status)
  752. print $object->getLibStatus(); // Enable by default
  753. elseif (count($object->perm) == 1 && $fuser->rights->$right_class->$perm0) {
  754. $object->Status = "true";
  755. print $object->getLibStatus();
  756. } elseif (count($object->perm) == 2 && $fuser->rights->$right_class->$perm0->$perm1) {
  757. $object->Status = "true";
  758. print $object->getLibStatus();
  759. }
  760. //print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $fuser->id . '&pid=' . $aRow->value->id . '&amp;action=remove_right#' . $aRow->value->id . '">' . img_edit_remove() . '</a>';
  761. //else
  762. //print '<a href="' . $_SERVER['PHP_SELF'] . '?id=' . $fuser->id . '&pid=' . $aRow->value->id . '&amp;action=add_right#' . $aRow->value->id . '">' . img_edit_add() . '</a>';
  763. //}
  764. else {
  765. print $object->getLibStatus();
  766. }
  767. print '</td>';
  768. print'</tr>';
  769. }
  770. }
  771. print'</tbody>';
  772. print'</table>';
  773. $obj->aaSorting = array(array(1, 'asc'));
  774. $obj->sDom = 'l<fr>t<\"clear\"rtip>';
  775. $obj->iDisplayLength = 50;
  776. print $object->datatablesCreate($obj, "perm_rights");
  777. print end_box();
  778. print column_end();
  779. }
  780. }
  781. /*
  782. * Fiche en mode edition
  783. */
  784. if ($action == 'edit' && ($canedituser || ($user->id == $fuser->id))) {
  785. print '<form action="' . $_SERVER['PHP_SELF'] . '?id=' . $fuser->id . '" method="POST" name="updateuser" enctype="multipart/form-data">';
  786. print '<input type="hidden" name="token" value="' . $_SESSION['newtoken'] . '">';
  787. print '<input type="hidden" name="action" value="update">';
  788. print '<table width="100%" class="border">';
  789. $rowspan = 12;
  790. if ($conf->societe->enabled)
  791. $rowspan++;
  792. if ($conf->adherent->enabled)
  793. $rowspan++;
  794. print '<tr><td width="25%" valign="top">' . $langs->trans("Ref") . '</td>';
  795. print '<td colspan="2">';
  796. print $fuser->id;
  797. print '</td>';
  798. print '</tr>';
  799. // Lastname
  800. print "<tr>";
  801. print '<td valign="top" class="fieldrequired">' . $langs->trans("Lastname") . '</td>';
  802. print '<td>';
  803. if ($caneditfield && !$fuser->ldap_sid) {
  804. print '<input size="30" type="text" class="flat" name="nom" value="' . $fuser->Lastname . '">';
  805. } else {
  806. print '<input type="hidden" name="nom" value="' . $fuser->Lastname . '">';
  807. print $fuser->Lastname;
  808. }
  809. print '</td>';
  810. // Photo
  811. print '<td align="center" valign="middle" width="25%" rowspan="' . $rowspan . '">';
  812. print $form->showphoto('userphoto', $fuser);
  813. if ($caneditfield) {
  814. if ($fuser->Photo)
  815. print "<br>\n";
  816. print '<table class="nobordernopadding">';
  817. if ($fuser->Photo)
  818. print '<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> ' . $langs->trans("Delete") . '<br><br></td></tr>';
  819. print '<tr><td>' . $langs->trans("PhotoFile") . '</td></tr>';
  820. print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
  821. print '</table>';
  822. }
  823. print '</td>';
  824. print '</tr>';
  825. // Firstname
  826. print '<tr><td valign="top">' . $langs->trans("Firstname") . '</td>';
  827. print '<td>';
  828. if ($caneditfield && !$fuser->ldap_sid) {
  829. print '<input size="30" type="text" class="flat" name="prenom" value="' . $fuser->Firstname . '">';
  830. } else {
  831. print '<input type="hidden" name="prenom" value="' . $fuser->Firstname . '">';
  832. print $fuser->Firstname;
  833. }
  834. print '</td></tr>';
  835. // Login
  836. print '<tr><td valign="top"><span class="fieldrequired">' . $langs->trans("Login") . '</span></td>';
  837. print '<td>';
  838. if (!$user->name) {
  839. print '<input size="12" maxlength="24" type="text" class="flat" name="login" value="' . $fuser->name . '">';
  840. } else {
  841. print '<input type="hidden" name="login" value="' . $fuser->name . '">';
  842. print $fuser->name;
  843. }
  844. print '</td>';
  845. print '</tr>';
  846. // Pass
  847. print '<tr><td valign="top">' . $langs->trans("Password") . '</td>';
  848. print '<td>';
  849. if ($caneditpassword) {
  850. $text = '<input size="12" maxlength="32" type="password" class="flat" name="password" value="' . $fuser->pass . '">';
  851. if ($dolibarr_main_authentication && $dolibarr_main_authentication == 'http') {
  852. $text = $form->textwithpicto($text, $langs->trans("SpeedealingInHttpAuthenticationSoPasswordUseless", $dolibarr_main_authentication), 1, 'warning');
  853. }
  854. } else {
  855. $text = preg_replace('/./i', '*', $fuser->password_sha);
  856. }
  857. print $text;
  858. print "</td></tr>\n";
  859. // Administrator
  860. $name = $fuser->name;
  861. $admins = $fuser->getUserAdmins();
  862. if (isset($admins->$name))
  863. $fuser->admin = true;
  864. else
  865. $fuser->admin = false;
  866. print '<tr><td valign="top">' . $langs->trans("Administrator") . '</td>';
  867. print '<td>';
  868. if ($user->admin && $user->id != $fuser->id) { // Don't downgrade ourself
  869. print $form->selectyesno('admin', $fuser->admin, 1);
  870. } else {
  871. $yn = yn($fuser->admin);
  872. print '<input type="hidden" name="admin" value="' . $fuser->admin . '">';
  873. print $yn;
  874. }
  875. print '</td></tr>';
  876. // Entity by default
  877. print '<tr><td width="25%" valign="top">' . $langs->trans("Entity") . '</td>';
  878. print '<td>';
  879. print '<input type="text" name="default_entity" value="' . $conf->Couchdb->name . '">';
  880. print '</td></tr>';
  881. // Tel pro
  882. print '<tr><td valign="top">' . $langs->trans("PhonePro") . '</td>';
  883. print '<td>';
  884. if ($caneditfield && !$fuser->ldap_sid) {
  885. print '<input size="20" type="text" name="PhonePro" class="flat" value="' . $fuser->PhonePro . '">';
  886. } else {
  887. print '<input type="hidden" name="PhonePro" value="' . $fuser->PhonePro . '">';
  888. print $fuser->PhonePro;
  889. }
  890. print '</td></tr>';
  891. // Tel mobile
  892. print '<tr><td valign="top">' . $langs->trans("PhoneMobile") . '</td>';
  893. print '<td>';
  894. if ($caneditfield && !$fuser->ldap_sid) {
  895. print '<input size="20" type="text" name="PhoneMobile" class="flat" value="' . $fuser->PhoneMobile . '">';
  896. } else {
  897. print '<input type="hidden" name="user_mobile" value="' . $fuser->PhoneMobile . '">';
  898. print $fuser->PhoneMobile;
  899. }
  900. print '</td></tr>';
  901. // Fax
  902. print '<tr><td valign="top">' . $langs->trans("Fax") . '</td>';
  903. print '<td>';
  904. if ($caneditfield && !$fuser->ldap_sid) {
  905. print '<input size="20" type="text" name="office_fax" class="flat" value="' . $fuser->Fax . '">';
  906. } else {
  907. print '<input type="hidden" name="Fax" value="' . $fuser->Fax . '">';
  908. print $fuser->Fax;
  909. }
  910. print '</td></tr>';
  911. // EMail
  912. print '<tr><td valign="top" class="fieldrequired">' . $langs->trans("EMail") . '</td>';
  913. print '<td>';
  914. if ($caneditfield) {
  915. print '<input size="40" type="text" name="email" class="flat" value="' . $fuser->email . '">';
  916. } else {
  917. print '<input type="hidden" name="email" value="' . $fuser->email . '">';
  918. print $fuser->email;
  919. }
  920. print '</td></tr>';
  921. // Signature
  922. print '<tr><td valign="top">' . $langs->trans("Signature") . '</td>';
  923. print '<td>';
  924. print '<textarea name="Signature" rows="5" cols="90">' . dol_htmlentitiesbr_decode($fuser->Signature) . '</textarea>';
  925. print '</td></tr>';
  926. // Statut
  927. print '<tr><td valign="top">' . $langs->trans("Status") . '</td>';
  928. print '<td>';
  929. print $fuser->getLibStatus();
  930. print '</td></tr>';
  931. // Company / Contact
  932. if ($conf->societe->enabled) {
  933. print '<tr><td width="25%" valign="top">' . $langs->trans("LinkToCompanyContact") . '</td>';
  934. print '<td>';
  935. if ($fuser->societe_id > 0) {
  936. $societe = new Societe($db);
  937. $societe->fetch($fuser->societe_id);
  938. print $societe->getNomUrl(1, '');
  939. if ($fuser->contact_id) {
  940. $contact = new Contact($db);
  941. $contact->fetch($fuser->contact_id);
  942. print ' / <a href="' . DOL_URL_ROOT . '/contact/fiche.php?id=' . $fuser->contact_id . '">' . img_object($langs->trans("ShowContact"), 'contact') . ' ' . dol_trunc($contact->getFullName($langs), 32) . '</a>';
  943. }
  944. } else {
  945. print $langs->trans("ThisUserIsNot");
  946. }
  947. print '</td>';
  948. print "</tr>\n";
  949. }
  950. // Module Adherent
  951. if ($conf->adherent->enabled) {
  952. $langs->load("members");
  953. print '<tr><td width="25%" valign="top">' . $langs->trans("LinkedToSpeedealingMember") . '</td>';
  954. print '<td>';
  955. if ($fuser->fk_member) {
  956. $adh = new Adherent($db);
  957. $adh->fetch($fuser->fk_member);
  958. $adh->ref = $adh->login; // Force to show login instead of id
  959. print $adh->getNomUrl(1);
  960. } else {
  961. print $langs->trans("UserNotLinkedToMember");
  962. }
  963. print '</td>';
  964. print "</tr>\n";
  965. }
  966. print '</table>';
  967. print '<br><center>';
  968. print '<input value="' . $langs->trans("Save") . '" class="button" type="submit" name="save">';
  969. print ' &nbsp; ';
  970. print '<input value="' . $langs->trans("Cancel") . '" class="button" type="submit" name="cancel">';
  971. print '</center>';
  972. print '</form>';
  973. print '</div>';
  974. }
  975. $ldap->close;
  976. }
  977. }
  978. print end_box();
  979. print '</div>';
  980. dol_fiche_end();
  981. llxFooter();
  982. ?>