card.php 82 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158
  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-2015 Regis Houssin <regis.houssin@capnetworks.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 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  11. * Copyright (C) 2013-2015 Alexandre Spangaro <alexandre.spangaro@gmail.com>
  12. *
  13. * This program is free software; you can redistribute it and/or modify
  14. * it under the terms of the GNU General Public License as published by
  15. * the Free Software Foundation; either version 3 of the License, or
  16. * (at your option) any later version.
  17. *
  18. * This program is distributed in the hope that it will be useful,
  19. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  20. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  21. * GNU General Public License for more details.
  22. *
  23. * You should have received a copy of the GNU General Public License
  24. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  25. */
  26. /**
  27. * \file htdocs/user/card.php
  28. * \brief Tab of user card
  29. */
  30. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  39. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  40. if (! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.class.php');
  41. $id = GETPOST('id','int');
  42. $action = GETPOST('action','alpha');
  43. $confirm = GETPOST('confirm','alpha');
  44. $subaction = GETPOST('subaction','alpha');
  45. $group = GETPOST("group","int",3);
  46. // Define value to know what current user can do on users
  47. $canadduser=(! empty($user->admin) || $user->rights->user->user->creer);
  48. $canreaduser=(! empty($user->admin) || $user->rights->user->user->lire);
  49. $canedituser=(! empty($user->admin) || $user->rights->user->user->creer);
  50. $candisableuser=(! empty($user->admin) || $user->rights->user->user->supprimer);
  51. $canreadgroup=$canreaduser;
  52. $caneditgroup=$canedituser;
  53. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  54. {
  55. $canreadgroup=(! empty($user->admin) || $user->rights->user->group_advance->read);
  56. $caneditgroup=(! empty($user->admin) || $user->rights->user->group_advance->write);
  57. }
  58. // Define value to know what current user can do on properties of edited user
  59. if ($id)
  60. {
  61. // $user est le user qui edite, $id est l'id de l'utilisateur edite
  62. $caneditfield=((($user->id == $id) && $user->rights->user->self->creer)
  63. || (($user->id != $id) && $user->rights->user->user->creer));
  64. $caneditpassword=((($user->id == $id) && $user->rights->user->self->password)
  65. || (($user->id != $id) && $user->rights->user->user->password));
  66. }
  67. // Security check
  68. $socid=0;
  69. if ($user->societe_id > 0) $socid = $user->societe_id;
  70. $feature2='user';
  71. if ($user->id == $id) { $feature2=''; $canreaduser=1; } // A user can always read its own card
  72. if (!$canreaduser) {
  73. $result = restrictedArea($user, 'user', $id, '&user', $feature2);
  74. }
  75. if ($user->id <> $id && ! $canreaduser) accessforbidden();
  76. $langs->load("users");
  77. $langs->load("companies");
  78. $langs->load("ldap");
  79. $object = new User($db);
  80. $extrafields = new ExtraFields($db);
  81. // fetch optionals attributes and labels
  82. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  83. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  84. $hookmanager->initHooks(array('usercard','globalcard'));
  85. /**
  86. * Actions
  87. */
  88. if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser)
  89. {
  90. if ($id <> $user->id)
  91. {
  92. $object->fetch($id);
  93. $object->setstatus(0);
  94. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  95. exit;
  96. }
  97. }
  98. if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser)
  99. {
  100. $error = 0;
  101. if ($id <> $user->id)
  102. {
  103. $object->fetch($id);
  104. if (!empty($conf->file->main_limit_users))
  105. {
  106. $nb = $object->getNbOfUsers("active");
  107. if ($nb >= $conf->file->main_limit_users)
  108. {
  109. $error++;
  110. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  111. }
  112. }
  113. if (! $error)
  114. {
  115. $object->setstatus(1);
  116. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  117. exit;
  118. }
  119. }
  120. }
  121. if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser)
  122. {
  123. if ($id <> $user->id)
  124. {
  125. $object = new User($db);
  126. $object->id=$id;
  127. $result = $object->delete();
  128. if ($result < 0)
  129. {
  130. $langs->load("errors");
  131. setEventMessage($langs->trans("ErrorUserCannotBeDelete"), 'errors');
  132. }
  133. else
  134. {
  135. header("Location: index.php");
  136. exit;
  137. }
  138. }
  139. }
  140. // Action Add user
  141. if ($action == 'add' && $canadduser)
  142. {
  143. $error = 0;
  144. if (! $_POST["lastname"])
  145. {
  146. $error++;
  147. setEventMessage($langs->trans("NameNotDefined"), 'errors');
  148. $action="create"; // Go back to create page
  149. }
  150. if (! $_POST["login"])
  151. {
  152. $error++;
  153. setEventMessage($langs->trans("LoginNotDefined"), 'errors');
  154. $action="create"; // Go back to create page
  155. }
  156. if (! empty($conf->file->main_limit_users)) // If option to limit users is set
  157. {
  158. $nb = $object->getNbOfUsers("active");
  159. if ($nb >= $conf->file->main_limit_users)
  160. {
  161. $error++;
  162. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  163. $action="create"; // Go back to create page
  164. }
  165. }
  166. if (!$error) {
  167. $object->lastname = GETPOST("lastname",'alpha');
  168. $object->firstname = GETPOST("firstname",'alpha');
  169. $object->login = GETPOST("login",'alpha');
  170. $object->admin = GETPOST("admin",'alpha');
  171. $object->office_phone = GETPOST("office_phone",'alpha');
  172. $object->office_fax = GETPOST("office_fax",'alpha');
  173. $object->user_mobile = GETPOST("user_mobile");
  174. $object->skype = GETPOST("skype");
  175. $object->email = GETPOST("email",'alpha');
  176. $object->job = GETPOST("job",'alpha');
  177. $object->signature = GETPOST("signature");
  178. $object->accountancy_code = GETPOST("accountancy_code");
  179. $object->note = GETPOST("note");
  180. $object->ldap_sid = GETPOST("ldap_sid");
  181. $object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0;
  182. $object->thm = GETPOST("thm")!=''?GETPOST("thm"):'';
  183. $object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):'';
  184. $object->salary = GETPOST("salary")!=''?GETPOST("salary"):'';
  185. $object->salaryextra = GETPOST("salaryextra")!=''?GETPOST("salaryextra"):'';
  186. $object->weeklyhours = GETPOST("weeklyhours")!=''?GETPOST("weeklyhours"):'';
  187. $object->color = GETPOST("color")!=''?GETPOST("color"):'';
  188. // Fill array 'array_options' with data from add form
  189. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  190. if ($ret < 0) $error++;
  191. // Set entity property
  192. $entity=GETPOST('entity','int');
  193. if (! empty($conf->multicompany->enabled))
  194. {
  195. if (! empty($_POST["superadmin"]))
  196. {
  197. $object->entity = 0;
  198. }
  199. else if ($conf->multicompany->transverse_mode)
  200. {
  201. $object->entity = 1; // all users are forced into master entity
  202. }
  203. else
  204. {
  205. $object->entity = ($entity == '' ? 1 : $entity);
  206. }
  207. }
  208. else
  209. {
  210. $object->entity = ($entity == '' ? 1 : $entity);
  211. }
  212. $db->begin();
  213. $id = $object->create($user);
  214. if ($id > 0)
  215. {
  216. if (isset($_POST['password']) && trim($_POST['password']))
  217. {
  218. $object->setPassword($user,trim($_POST['password']));
  219. }
  220. $db->commit();
  221. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  222. exit;
  223. }
  224. else
  225. {
  226. $langs->load("errors");
  227. $db->rollback();
  228. if (is_array($object->errors) && count($object->errors)) setEventMessage($object->errors,'errors');
  229. else setEventMessage($object->error, 'errors');
  230. $action="create"; // Go back to create page
  231. }
  232. }
  233. }
  234. // Action add usergroup
  235. if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield)
  236. {
  237. if ($group)
  238. {
  239. $editgroup = new UserGroup($db);
  240. $editgroup->fetch($group);
  241. $editgroup->oldcopy=dol_clone($editgroup);
  242. $object->fetch($id);
  243. if ($action == 'addgroup') $object->SetInGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity));
  244. if ($action == 'removegroup') $object->RemoveFromGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity));
  245. if ($result > 0)
  246. {
  247. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  248. exit;
  249. }
  250. else
  251. {
  252. setEventMessage($object->error, 'errors');
  253. }
  254. }
  255. }
  256. if ($action == 'update' && ! $_POST["cancel"])
  257. {
  258. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  259. if ($caneditfield) // Case we can edit all field
  260. {
  261. $error=0;
  262. if (! $_POST["lastname"])
  263. {
  264. setEventMessage($langs->trans("NameNotDefined"), 'errors');
  265. $action="edit"; // Go back to create page
  266. $error++;
  267. }
  268. if (! $_POST["login"])
  269. {
  270. setEventMessage($langs->trans("LoginNotDefined"), 'errors');
  271. $action="edit"; // Go back to create page
  272. $error++;
  273. }
  274. if (! $error)
  275. {
  276. $object->fetch($id);
  277. // Test if new login
  278. if (GETPOST("login") && GETPOST("login") != $object->login)
  279. {
  280. dol_syslog("New login ".$object->login." is requested. We test it does not exists.");
  281. $tmpuser=new User($db);
  282. $result=$tmpuser->fetch(0, GETPOST("login"));
  283. if ($result > 0)
  284. {
  285. setEventMessage($langs->trans("ErrorLoginAlreadyExists", GETPOST('login')), 'errors');
  286. $action="edit"; // Go back to create page
  287. $error++;
  288. }
  289. }
  290. }
  291. if (! $error)
  292. {
  293. $db->begin();
  294. $object->oldcopy=dol_clone($object);
  295. $object->lastname = GETPOST("lastname",'alpha');
  296. $object->firstname = GETPOST("firstname",'alpha');
  297. $object->login = GETPOST("login",'alpha');
  298. $object->pass = GETPOST("password");
  299. $object->admin = empty($user->admin)?0:GETPOST("admin"); // A user can only be set admin by an admin
  300. $object->office_phone=GETPOST("office_phone",'alpha');
  301. $object->office_fax = GETPOST("office_fax",'alpha');
  302. $object->user_mobile= GETPOST("user_mobile");
  303. $object->skype = GETPOST("skype");
  304. $object->email = GETPOST("email",'alpha');
  305. $object->job = GETPOST("job",'alpha');
  306. $object->signature = GETPOST("signature");
  307. $object->accountancy_code = GETPOST("accountancy_code");
  308. $object->openid = GETPOST("openid");
  309. $object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0;
  310. $object->thm = GETPOST("thm")!=''?GETPOST("thm"):'';
  311. $object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):'';
  312. $object->salary = GETPOST("salary")!=''?GETPOST("salary"):'';
  313. $object->salaryextra = GETPOST("salaryextra")!=''?GETPOST("salaryextra"):'';
  314. $object->weeklyhours = GETPOST("weeklyhours")!=''?GETPOST("weeklyhours"):'';
  315. $object->color = GETPOST("color")!=''?GETPOST("color"):'';
  316. // Fill array 'array_options' with data from add form
  317. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  318. if ($ret < 0) $error++;
  319. if (! empty($conf->multicompany->enabled))
  320. {
  321. if (! empty($_POST["superadmin"]))
  322. {
  323. $object->entity = 0;
  324. }
  325. else if ($conf->multicompany->transverse_mode)
  326. {
  327. $object->entity = 1; // all users in master entity
  328. }
  329. else
  330. {
  331. $object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
  332. }
  333. }
  334. else
  335. {
  336. $object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
  337. }
  338. if (GETPOST('deletephoto')) $object->photo='';
  339. if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  340. if (! $error)
  341. {
  342. $ret=$object->update($user);
  343. if ($ret < 0)
  344. {
  345. $error++;
  346. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  347. {
  348. $langs->load("errors");
  349. setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
  350. }
  351. else
  352. {
  353. setEventMessage($object->error, 'errors');
  354. }
  355. }
  356. }
  357. if (! $error && isset($_POST['contactid']))
  358. {
  359. $contactid=GETPOST('contactid');
  360. if ($contactid > 0)
  361. {
  362. $contact=new Contact($db);
  363. $contact->fetch($contactid);
  364. $sql = "UPDATE ".MAIN_DB_PREFIX."user";
  365. $sql.= " SET fk_socpeople=".$db->escape($contactid);
  366. if ($contact->socid) $sql.=", fk_societe=".$db->escape($contact->socid);
  367. $sql.= " WHERE rowid=".$object->id;
  368. }
  369. else
  370. {
  371. $sql = "UPDATE ".MAIN_DB_PREFIX."user";
  372. $sql.= " SET fk_socpeople=NULL, fk_societe=NULL";
  373. $sql.= " WHERE rowid=".$object->id;
  374. }
  375. dol_syslog("fiche::update", LOG_DEBUG);
  376. $resql=$db->query($sql);
  377. if (! $resql)
  378. {
  379. $error++;
  380. setEventMessage($db->lasterror(), 'errors');
  381. }
  382. }
  383. if (! $error && ! count($object->errors))
  384. {
  385. if (GETPOST('deletephoto') && $object->photo)
  386. {
  387. $fileimg=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1).'/logos/'.$object->photo;
  388. $dirthumbs=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1).'/logos/thumbs';
  389. dol_delete_file($fileimg);
  390. dol_delete_dir_recursive($dirthumbs);
  391. }
  392. if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name']))
  393. {
  394. $dir= $conf->user->dir_output . '/' . get_exdir($object->id,2,0,1);
  395. dol_mkdir($dir);
  396. if (@is_dir($dir))
  397. {
  398. $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  399. $result=dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']);
  400. if (! $result > 0)
  401. {
  402. setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
  403. }
  404. else
  405. {
  406. // Create small thumbs for company (Ratio is near 16/9)
  407. // Used on logon for example
  408. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  409. // Create mini thumbs for company (Ratio is near 16/9)
  410. // Used on menu or for setup page for example
  411. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  412. }
  413. }
  414. }
  415. }
  416. if (! $error && ! count($object->errors))
  417. {
  418. setEventMessage($langs->trans("UserModified"));
  419. $db->commit();
  420. $login=$_SESSION["dol_login"];
  421. if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
  422. {
  423. $_SESSION["dol_login"]=$object->login; // Set new login to avoid disconnect at next page
  424. }
  425. }
  426. else
  427. {
  428. $db->rollback();
  429. }
  430. }
  431. }
  432. else if ($caneditpassword) // Case we can edit only password
  433. {
  434. $object->fetch($id);
  435. $object->oldcopy=dol_clone($object);
  436. $ret=$object->setPassword($user,$_POST["password"]);
  437. if ($ret < 0)
  438. {
  439. setEventMessage($object->error, 'errors');
  440. }
  441. }
  442. }
  443. // Change password with a new generated one
  444. if ((($action == 'confirm_password' && $confirm == 'yes')
  445. || ($action == 'confirm_passwordsend' && $confirm == 'yes')) && $caneditpassword)
  446. {
  447. $object->fetch($id);
  448. $newpassword=$object->setPassword($user,'');
  449. if ($newpassword < 0)
  450. {
  451. // Echec
  452. setEventMessage($langs->trans("ErrorFailedToSetNewPassword"), 'errors');
  453. }
  454. else
  455. {
  456. // Succes
  457. if ($action == 'confirm_passwordsend' && $confirm == 'yes')
  458. {
  459. if ($object->send_password($user,$newpassword) > 0)
  460. {
  461. setEventMessage($langs->trans("PasswordChangedAndSentTo",$object->email));
  462. }
  463. else
  464. {
  465. setEventMessage($object->error, 'errors');
  466. }
  467. }
  468. else
  469. {
  470. setEventMessage($langs->trans("PasswordChangedTo",$newpassword), 'errors');
  471. }
  472. }
  473. }
  474. // Action initialisation donnees depuis record LDAP
  475. if ($action == 'adduserldap')
  476. {
  477. $selecteduser = $_POST['users'];
  478. $required_fields = array(
  479. $conf->global->LDAP_KEY_USERS,
  480. $conf->global->LDAP_FIELD_NAME,
  481. $conf->global->LDAP_FIELD_FIRSTNAME,
  482. $conf->global->LDAP_FIELD_LOGIN,
  483. $conf->global->LDAP_FIELD_LOGIN_SAMBA,
  484. $conf->global->LDAP_FIELD_PASSWORD,
  485. $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
  486. $conf->global->LDAP_FIELD_PHONE,
  487. $conf->global->LDAP_FIELD_FAX,
  488. $conf->global->LDAP_FIELD_MOBILE,
  489. $conf->global->LDAP_FIELD_SKYPE,
  490. $conf->global->LDAP_FIELD_MAIL,
  491. $conf->global->LDAP_FIELD_TITLE,
  492. $conf->global->LDAP_FIELD_DESCRIPTION,
  493. $conf->global->LDAP_FIELD_SID);
  494. $ldap = new Ldap();
  495. $result = $ldap->connect_bind();
  496. if ($result >= 0)
  497. {
  498. // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
  499. $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
  500. $ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
  501. //print_r($ldapusers);
  502. if (is_array($ldapusers))
  503. {
  504. foreach ($ldapusers as $key => $attribute)
  505. {
  506. $ldap_lastname = $attribute[$conf->global->LDAP_FIELD_NAME];
  507. $ldap_firstname = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME];
  508. $ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN];
  509. $ldap_loginsmb = $attribute[$conf->global->LDAP_FIELD_LOGIN_SAMBA];
  510. $ldap_pass = $attribute[$conf->global->LDAP_FIELD_PASSWORD];
  511. $ldap_pass_crypted = $attribute[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
  512. $ldap_phone = $attribute[$conf->global->LDAP_FIELD_PHONE];
  513. $ldap_fax = $attribute[$conf->global->LDAP_FIELD_FAX];
  514. $ldap_mobile = $attribute[$conf->global->LDAP_FIELD_MOBILE];
  515. $ldap_skype = $attribute[$conf->global->LDAP_FIELD_SKYPE];
  516. $ldap_mail = $attribute[$conf->global->LDAP_FIELD_MAIL];
  517. $ldap_sid = $attribute[$conf->global->LDAP_FIELD_SID];
  518. }
  519. }
  520. }
  521. else
  522. {
  523. setEventMessage($ldap->error, 'errors');
  524. }
  525. }
  526. /*
  527. * View
  528. */
  529. $form = new Form($db);
  530. $formother=new FormOther($db);
  531. llxHeader('',$langs->trans("UserCard"));
  532. if (($action == 'create') || ($action == 'adduserldap'))
  533. {
  534. /* ************************************************************************** */
  535. /* */
  536. /* Affichage fiche en mode creation */
  537. /* */
  538. /* ************************************************************************** */
  539. print_fiche_titre($langs->trans("NewUser"));
  540. print $langs->trans("CreateInternalUserDesc");
  541. print "<br>";
  542. print "<br>";
  543. if (! empty($conf->ldap->enabled) && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr'))
  544. {
  545. /*
  546. * Affiche formulaire d'ajout d'un compte depuis LDAP
  547. * si on est en synchro LDAP vers Dolibarr
  548. */
  549. $ldap = new Ldap();
  550. $result = $ldap->connect_bind();
  551. if ($result >= 0)
  552. {
  553. $required_fields=array(
  554. $conf->global->LDAP_KEY_USERS,
  555. $conf->global->LDAP_FIELD_FULLNAME,
  556. $conf->global->LDAP_FIELD_NAME,
  557. $conf->global->LDAP_FIELD_FIRSTNAME,
  558. $conf->global->LDAP_FIELD_LOGIN,
  559. $conf->global->LDAP_FIELD_LOGIN_SAMBA,
  560. $conf->global->LDAP_FIELD_PASSWORD,
  561. $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
  562. $conf->global->LDAP_FIELD_PHONE,
  563. $conf->global->LDAP_FIELD_FAX,
  564. $conf->global->LDAP_FIELD_MOBILE,
  565. $conf->global->LDAP_FIELD_SKYPE,
  566. $conf->global->LDAP_FIELD_MAIL,
  567. $conf->global->LDAP_FIELD_TITLE,
  568. $conf->global->LDAP_FIELD_DESCRIPTION,
  569. $conf->global->LDAP_FIELD_SID
  570. );
  571. // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
  572. $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
  573. // Get from LDAP database an array of results
  574. $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
  575. if (is_array($ldapusers))
  576. {
  577. $liste=array();
  578. foreach ($ldapusers as $key => $ldapuser)
  579. {
  580. // Define the label string for this user
  581. $label='';
  582. foreach ($required_fields as $value)
  583. {
  584. if ($value)
  585. {
  586. $label.=$value."=".$ldapuser[$value]." ";
  587. }
  588. }
  589. $liste[$key] = $label;
  590. }
  591. }
  592. else
  593. {
  594. setEventMessage($ldap->error, 'errors');
  595. }
  596. }
  597. else
  598. {
  599. setEventMessage($ldap->error, 'errors');
  600. }
  601. // If user list is full, we show drop-down list
  602. print "\n\n<!-- Form liste LDAP debut -->\n";
  603. print '<form name="add_user_ldap" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  604. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  605. print '<table width="100%" class="border"><tr>';
  606. print '<td width="160">';
  607. print $langs->trans("LDAPUsers");
  608. print '</td>';
  609. print '<td>';
  610. print '<input type="hidden" name="action" value="adduserldap">';
  611. if (is_array($liste) && count($liste))
  612. {
  613. print $form->selectarray('users', $liste, '', 1);
  614. }
  615. print '</td><td align="center">';
  616. print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Get')).'"'.(count($liste)?'':' disabled="disabled"').'>';
  617. print '</td></tr></table>';
  618. print '</form>';
  619. print "\n<!-- Form liste LDAP fin -->\n\n";
  620. print '<br>';
  621. }
  622. print dol_set_focus('#lastname');
  623. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="createuser">';
  624. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  625. print '<input type="hidden" name="action" value="add">';
  626. if (! empty($ldap_sid)) print '<input type="hidden" name="ldap_sid" value="'.dol_escape_htmltag($ldap_sid).'">';
  627. print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
  628. print '<table class="border" width="100%">';
  629. print '<tr>';
  630. // Lastname
  631. print '<td valign="top" width="160"><span class="fieldrequired">'.$langs->trans("Lastname").'</span></td>';
  632. print '<td>';
  633. if (! empty($ldap_lastname))
  634. {
  635. print '<input type="hidden" id="lastname" name="lastname" value="'.$ldap_lastname.'">';
  636. print $ldap_lastname;
  637. }
  638. else
  639. {
  640. print '<input size="30" type="text" id="lastname" name="lastname" value="'.GETPOST('lastname').'">';
  641. }
  642. print '</td></tr>';
  643. // Firstname
  644. print '<tr><td valign="top">'.$langs->trans("Firstname").'</td>';
  645. print '<td>';
  646. if (! empty($ldap_firstname))
  647. {
  648. print '<input type="hidden" name="firstname" value="'.$ldap_firstname.'">';
  649. print $ldap_firstname;
  650. }
  651. else
  652. {
  653. print '<input size="30" type="text" name="firstname" value="'.GETPOST('firstname').'">';
  654. }
  655. print '</td></tr>';
  656. // Position/Job
  657. print '<tr><td valign="top">'.$langs->trans("PostOrFunction").'</td>';
  658. print '<td>';
  659. print '<input size="30" type="text" name="job" value="'.GETPOST('job').'">';
  660. print '</td></tr>';
  661. // Login
  662. print '<tr><td valign="top"><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
  663. print '<td>';
  664. if (! empty($ldap_login))
  665. {
  666. print '<input type="hidden" name="login" value="'.$ldap_login.'">';
  667. print $ldap_login;
  668. }
  669. elseif (! empty($ldap_loginsmb))
  670. {
  671. print '<input type="hidden" name="login" value="'.$ldap_loginsmb.'">';
  672. print $ldap_loginsmb;
  673. }
  674. else
  675. {
  676. print '<input size="20" maxsize="24" type="text" name="login" value="'.GETPOST('login').'">';
  677. }
  678. print '</td></tr>';
  679. $generated_password='';
  680. if (empty($ldap_sid)) // ldap_sid is for activedirectory
  681. {
  682. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  683. $generated_password=getRandomPassword(false);
  684. }
  685. $password=$generated_password;
  686. // Password
  687. print '<tr><td valign="top" class="fieldrequired">'.$langs->trans("Password").'</td>';
  688. print '<td>';
  689. if (! empty($ldap_sid))
  690. {
  691. print 'Mot de passe du domaine';
  692. }
  693. else
  694. {
  695. if (! empty($ldap_pass))
  696. {
  697. print '<input type="hidden" name="password" value="'.$ldap_pass.'">';
  698. print preg_replace('/./i','*',$ldap_pass);
  699. }
  700. else
  701. {
  702. // We do not use a field password but a field text to show new password to use.
  703. print '<input size="30" maxsize="32" type="text" name="password" value="'.$password.'" autocomplete="off">';
  704. }
  705. }
  706. print '</td></tr>';
  707. // Administrator
  708. if (! empty($user->admin))
  709. {
  710. print '<tr><td valign="top">'.$langs->trans("Administrator").'</td>';
  711. print '<td>';
  712. print $form->selectyesno('admin',GETPOST('admin'),1);
  713. if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
  714. {
  715. if (! empty($conf->use_javascript_ajax))
  716. {
  717. print '<script type="text/javascript">
  718. $(function() {
  719. $("select[name=admin]").change(function() {
  720. if ( $(this).val() == 0 ) {
  721. $("input[name=superadmin]")
  722. .attr("disabled", true)
  723. .attr("checked", false);
  724. $("select[name=entity]")
  725. .attr("disabled", false);
  726. } else {
  727. $("input[name=superadmin]")
  728. .attr("disabled", false);
  729. }
  730. });
  731. $("input[name=superadmin]").change(function() {
  732. if ( $(this).attr("checked") == "checked" ) {
  733. $("select[name=entity]")
  734. .attr("disabled", true);
  735. } else {
  736. $("select[name=entity]")
  737. .attr("disabled", false);
  738. }
  739. });
  740. });
  741. </script>';
  742. }
  743. $checked=($_POST["superadmin"]?' checked':'');
  744. $disabled=($_POST["superadmin"]?'':' disabled');
  745. print '<input type="checkbox" name="superadmin" value="1"'.$checked.$disabled.' /> '.$langs->trans("SuperAdministrator");
  746. }
  747. print "</td></tr>\n";
  748. }
  749. // Type
  750. print '<tr><td valign="top">'.$langs->trans("Type").'</td>';
  751. print '<td>';
  752. print $form->textwithpicto($langs->trans("Internal"),$langs->trans("InternalExternalDesc"));
  753. print '</td></tr>';
  754. // Tel
  755. print '<tr><td valign="top">'.$langs->trans("PhonePro").'</td>';
  756. print '<td>';
  757. if (! empty($ldap_phone))
  758. {
  759. print '<input type="hidden" name="office_phone" value="'.$ldap_phone.'">';
  760. print $ldap_phone;
  761. }
  762. else
  763. {
  764. print '<input size="20" type="text" name="office_phone" value="'.GETPOST('office_phone').'">';
  765. }
  766. print '</td></tr>';
  767. // Tel portable
  768. print '<tr><td valign="top">'.$langs->trans("PhoneMobile").'</td>';
  769. print '<td>';
  770. if (! empty($ldap_mobile))
  771. {
  772. print '<input type="hidden" name="user_mobile" value="'.$ldap_mobile.'">';
  773. print $ldap_mobile;
  774. }
  775. else
  776. {
  777. print '<input size="20" type="text" name="user_mobile" value="'.GETPOST('user_mobile').'">';
  778. }
  779. print '</td></tr>';
  780. // Fax
  781. print '<tr><td valign="top">'.$langs->trans("Fax").'</td>';
  782. print '<td>';
  783. if (! empty($ldap_fax))
  784. {
  785. print '<input type="hidden" name="office_fax" value="'.$ldap_fax.'">';
  786. print $ldap_fax;
  787. }
  788. else
  789. {
  790. print '<input size="20" type="text" name="office_fax" value="'.GETPOST('office_fax').'">';
  791. }
  792. print '</td></tr>';
  793. // Skype
  794. if (! empty($conf->skype->enabled))
  795. {
  796. print '<tr><td valign="top">'.$langs->trans("Skype").'</td>';
  797. print '<td>';
  798. if (! empty($ldap_skype))
  799. {
  800. print '<input type="hidden" name="skype" value="'.$ldap_skype.'">';
  801. print $ldap_skype;
  802. }
  803. else
  804. {
  805. print '<input size="40" type="text" name="skype" value="'.GETPOST('skype').'">';
  806. }
  807. print '</td></tr>';
  808. }
  809. // EMail
  810. print '<tr><td valign="top"'.(! empty($conf->global->USER_MAIL_REQUIRED)?' class="fieldrequired"':'').'>'.$langs->trans("EMail").'</td>';
  811. print '<td>';
  812. if (! empty($ldap_mail))
  813. {
  814. print '<input type="hidden" name="email" value="'.$ldap_mail.'">';
  815. print $ldap_mail;
  816. }
  817. else
  818. {
  819. print '<input size="40" type="text" name="email" value="'.GETPOST('email').'">';
  820. }
  821. print '</td></tr>';
  822. // Signature
  823. print '<tr><td valign="top">'.$langs->trans("Signature").'</td>';
  824. print '<td>';
  825. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  826. $doleditor=new DolEditor('signature',GETPOST('signature'),'',138,'dolibarr_mailings','In',true,true,empty($conf->global->FCKEDITOR_ENABLE_USERSIGN)?0:1,ROWS_4,90);
  827. print $doleditor->Create(1);
  828. print '</td></tr>';
  829. // Multicompany
  830. if (! empty($conf->multicompany->enabled))
  831. {
  832. if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity && is_object($mc))
  833. {
  834. print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
  835. print "<td>".$mc->select_entities($conf->entity);
  836. print "</td></tr>\n";
  837. }
  838. else
  839. {
  840. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  841. }
  842. }
  843. // Hierarchy
  844. print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>';
  845. print '<td>';
  846. print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$conf->entity);
  847. print '</td>';
  848. print "</tr>\n";
  849. if ($conf->salaries->enabled && ! empty($user->rights->salaries->read))
  850. {
  851. $langs->load("salaries");
  852. // THM
  853. print '<tr><td valign="top">'.$langs->trans("THM").'</td>';
  854. print '<td>';
  855. print '<input size="8" type="text" name="thm" value="'.GETPOST('thm').'">';
  856. print '</td>';
  857. print "</tr>\n";
  858. // TJM
  859. print '<tr><td valign="top">'.$langs->trans("TJM").'</td>';
  860. print '<td>';
  861. print '<input size="8" type="text" name="tjm" value="'.GETPOST('tjm').'">';
  862. print '</td>';
  863. print "</tr>\n";
  864. // Salary
  865. print '<tr><td valign="top">'.$langs->trans("Salary").'</td>';
  866. print '<td>';
  867. print '<input size="8" type="text" name="salary" value="'.GETPOST('salary').'">';
  868. print '</td>';
  869. print "</tr>\n";
  870. }
  871. // Weeklyhours
  872. print '<tr><td valign="top">'.$langs->trans("WeeklyHours").'</td>';
  873. print '<td>';
  874. print '<input size="8" type="text" name="weeklyhours" value="'.GETPOST('weeklyhours').'">';
  875. print '</td>';
  876. print "</tr>\n";
  877. // Accountancy code
  878. if ($conf->salaries->enabled)
  879. {
  880. print '<tr><td valign="top">'.$langs->trans("AccountancyCode").'</td>';
  881. print '<td>';
  882. print '<input size="30" type="text" name="accountancy_code" value="'.GETPOST('accountancy_code').'">';
  883. print '</td></tr>';
  884. }
  885. // User color
  886. if (! empty($conf->agenda->enabled))
  887. {
  888. print '<tr><td valign="top">'.$langs->trans("ColorUser").'</td>';
  889. print '<td>';
  890. print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', 'usercolorconfig', 1, '', 'hideifnotset');
  891. print '</td></tr>';
  892. }
  893. // Note
  894. print '<tr><td valign="top">';
  895. print $langs->trans("Note");
  896. print '</td><td>';
  897. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  898. $doleditor=new DolEditor('note','','',180,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_4,90);
  899. $doleditor->Create();
  900. print "</td></tr>\n";
  901. // Other attributes
  902. $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
  903. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  904. if (empty($reshook) && ! empty($extrafields->attribute_label))
  905. {
  906. print $object->showOptionals($extrafields,'edit');
  907. }
  908. print "</table>\n";
  909. print '<center><br><input class="button" value="'.$langs->trans("CreateUser").'" name="create" type="submit"></center>';
  910. print "</form>";
  911. }
  912. else
  913. {
  914. /* ************************************************************************** */
  915. /* */
  916. /* View and edition */
  917. /* */
  918. /* ************************************************************************** */
  919. if ($id > 0)
  920. {
  921. $object->fetch($id);
  922. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  923. $res=$object->fetch_optionals($object->id,$extralabels);
  924. // Connexion ldap
  925. // pour recuperer passDoNotExpire et userChangePassNextLogon
  926. if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid))
  927. {
  928. $ldap = new Ldap();
  929. $result=$ldap->connect_bind();
  930. if ($result > 0)
  931. {
  932. $userSearchFilter = '('.$conf->global->LDAP_FILTER_CONNECTION.'('.$ldap->getUserIdentifier().'='.$object->login.'))';
  933. $entries = $ldap->fetch($object->login,$userSearchFilter);
  934. if (! $entries)
  935. {
  936. setEventMessage($ldap->error, 'errors');
  937. }
  938. $passDoNotExpire = 0;
  939. $userChangePassNextLogon = 0;
  940. $userDisabled = 0;
  941. $statutUACF = '';
  942. // Check options of user account
  943. if (count($ldap->uacf) > 0)
  944. {
  945. foreach ($ldap->uacf as $key => $statut)
  946. {
  947. if ($key == 65536)
  948. {
  949. $passDoNotExpire = 1;
  950. $statutUACF = $statut;
  951. }
  952. }
  953. }
  954. else
  955. {
  956. $userDisabled = 1;
  957. $statutUACF = "ACCOUNTDISABLE";
  958. }
  959. if ($ldap->pwdlastset == 0)
  960. {
  961. $userChangePassNextLogon = 1;
  962. }
  963. }
  964. }
  965. // Show tabs
  966. $head = user_prepare_head($object);
  967. $title = $langs->trans("User");
  968. dol_fiche_head($head, 'user', $title, 0, 'user');
  969. /*
  970. * Confirmation reinitialisation mot de passe
  971. */
  972. if ($action == 'password')
  973. {
  974. print $form->formconfirm("card.php?id=$object->id",$langs->trans("ReinitPassword"),$langs->trans("ConfirmReinitPassword",$object->login),"confirm_password", '', 0, 1);
  975. }
  976. /*
  977. * Confirmation envoi mot de passe
  978. */
  979. if ($action == 'passwordsend')
  980. {
  981. print $form->formconfirm("card.php?id=$object->id",$langs->trans("SendNewPassword"),$langs->trans("ConfirmSendNewPassword",$object->login),"confirm_passwordsend", '', 0, 1);
  982. }
  983. /*
  984. * Confirm deactivation
  985. */
  986. if ($action == 'disable')
  987. {
  988. print $form->formconfirm("card.php?id=$object->id",$langs->trans("DisableAUser"),$langs->trans("ConfirmDisableUser",$object->login),"confirm_disable", '', 0, 1);
  989. }
  990. /*
  991. * Confirm activation
  992. */
  993. if ($action == 'enable')
  994. {
  995. print $form->formconfirm("card.php?id=$object->id",$langs->trans("EnableAUser"),$langs->trans("ConfirmEnableUser",$object->login),"confirm_enable", '', 0, 1);
  996. }
  997. /*
  998. * Confirmation suppression
  999. */
  1000. if ($action == 'delete')
  1001. {
  1002. print $form->formconfirm("card.php?id=$object->id",$langs->trans("DeleteAUser"),$langs->trans("ConfirmDeleteUser",$object->login),"confirm_delete", '', 0, 1);
  1003. }
  1004. /*
  1005. * Fiche en mode visu
  1006. */
  1007. if ($action != 'edit')
  1008. {
  1009. $rowspan=19;
  1010. print '<table class="border" width="100%">';
  1011. // Ref
  1012. print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
  1013. print '<td colspan="3">';
  1014. print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin);
  1015. print '</td>';
  1016. print '</tr>'."\n";
  1017. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $rowspan++;
  1018. if (! empty($conf->societe->enabled)) $rowspan++;
  1019. if (! empty($conf->adherent->enabled)) $rowspan++;
  1020. if (! empty($conf->skype->enabled)) $rowspan++;
  1021. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) $rowspan = $rowspan+3;
  1022. if (! empty($conf->agenda->enabled)) $rowspan++;
  1023. // Lastname
  1024. print '<tr><td valign="top">'.$langs->trans("Lastname").'</td>';
  1025. print '<td colspan="2">'.$object->lastname.'</td>';
  1026. // Photo
  1027. print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
  1028. print $form->showphoto('userphoto',$object,100);
  1029. print '</td>';
  1030. print '</tr>'."\n";
  1031. // Firstname
  1032. print '<tr><td valign="top">'.$langs->trans("Firstname").'</td>';
  1033. print '<td colspan="2">'.$object->firstname.'</td>';
  1034. print '</tr>'."\n";
  1035. // Position/Job
  1036. print '<tr><td valign="top">'.$langs->trans("PostOrFunction").'</td>';
  1037. print '<td colspan="2">'.$object->job.'</td>';
  1038. print '</tr>'."\n";
  1039. // Login
  1040. print '<tr><td valign="top">'.$langs->trans("Login").'</td>';
  1041. if (! empty($object->ldap_sid) && $object->statut==0)
  1042. {
  1043. print '<td colspan="2" class="error">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
  1044. }
  1045. else
  1046. {
  1047. print '<td colspan="2">'.$object->login.'</td>';
  1048. }
  1049. print '</tr>'."\n";
  1050. // Password
  1051. print '<tr><td valign="top">'.$langs->trans("Password").'</td>';
  1052. if (! empty($object->ldap_sid))
  1053. {
  1054. if ($passDoNotExpire)
  1055. {
  1056. print '<td colspan="2">'.$langs->trans("LdapUacf_".$statutUACF).'</td>';
  1057. }
  1058. else if($userChangePassNextLogon)
  1059. {
  1060. print '<td colspan="2" class="warning">'.$langs->trans("UserMustChangePassNextLogon",$ldap->domainFQDN).'</td>';
  1061. }
  1062. else if($userDisabled)
  1063. {
  1064. print '<td colspan="2" class="warning">'.$langs->trans("LdapUacf_".$statutUACF,$ldap->domainFQDN).'</td>';
  1065. }
  1066. else
  1067. {
  1068. print '<td colspan="2">'.$langs->trans("DomainPassword").'</td>';
  1069. }
  1070. }
  1071. else
  1072. {
  1073. print '<td colspan="2">';
  1074. if ($object->pass) print preg_replace('/./i','*',$object->pass);
  1075. else
  1076. {
  1077. if ($user->admin) print $langs->trans("Crypted").': '.$object->pass_indatabase_crypted;
  1078. else print $langs->trans("Hidden");
  1079. }
  1080. print "</td>";
  1081. }
  1082. print '</tr>'."\n";
  1083. // Administrator
  1084. print '<tr><td valign="top">'.$langs->trans("Administrator").'</td><td colspan="2">';
  1085. if (! empty($conf->multicompany->enabled) && $object->admin && ! $object->entity)
  1086. {
  1087. print $form->textwithpicto(yn($object->admin),$langs->trans("SuperAdministratorDesc"),1,"superadmin");
  1088. }
  1089. else if ($object->admin)
  1090. {
  1091. print $form->textwithpicto(yn($object->admin),$langs->trans("AdministratorDesc"),1,"admin");
  1092. }
  1093. else
  1094. {
  1095. print yn($object->admin);
  1096. }
  1097. print '</td></tr>'."\n";
  1098. // Type
  1099. print '<tr><td valign="top">'.$langs->trans("Type").'</td><td colspan="2">';
  1100. $type=$langs->trans("Internal");
  1101. if ($object->societe_id) $type=$langs->trans("External");
  1102. print $form->textwithpicto($type,$langs->trans("InternalExternalDesc"));
  1103. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1104. print '</td></tr>'."\n";
  1105. // Ldap sid
  1106. if ($object->ldap_sid)
  1107. {
  1108. print '<tr><td valign="top">'.$langs->trans("Type").'</td><td colspan="2">';
  1109. print $langs->trans("DomainUser",$ldap->domainFQDN);
  1110. print '</td></tr>'."\n";
  1111. }
  1112. // Tel pro
  1113. print '<tr><td valign="top">'.$langs->trans("PhonePro").'</td>';
  1114. print '<td colspan="2">'.dol_print_phone($object->office_phone,'',0,0,1).'</td>';
  1115. print '</tr>'."\n";
  1116. // Tel mobile
  1117. print '<tr><td valign="top">'.$langs->trans("PhoneMobile").'</td>';
  1118. print '<td colspan="2">'.dol_print_phone($object->user_mobile,'',0,0,1).'</td>';
  1119. print '</tr>'."\n";
  1120. // Fax
  1121. print '<tr><td valign="top">'.$langs->trans("Fax").'</td>';
  1122. print '<td colspan="2">'.dol_print_phone($object->office_fax,'',0,0,1).'</td>';
  1123. print '</tr>'."\n";
  1124. // Skype
  1125. if (! empty($conf->skype->enabled))
  1126. {
  1127. print '<tr><td valign="top">'.$langs->trans("Skype").'</td>';
  1128. print '<td colspan="2">'.dol_print_skype($object->skype,0,0,1).'</td>';
  1129. print "</tr>\n";
  1130. }
  1131. // EMail
  1132. print '<tr><td valign="top">'.$langs->trans("EMail").'</td>';
  1133. print '<td colspan="2">'.dol_print_email($object->email,0,0,1).'</td>';
  1134. print "</tr>\n";
  1135. // Signature
  1136. print '<tr><td valign="top">'.$langs->trans('Signature').'</td><td colspan="2">';
  1137. print dol_htmlentitiesbr($object->signature);
  1138. print "</td></tr>\n";
  1139. // Hierarchy
  1140. print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>';
  1141. print '<td colspan="2">';
  1142. if (empty($object->fk_user)) print $langs->trans("None");
  1143. else {
  1144. $huser=new User($db);
  1145. $huser->fetch($object->fk_user);
  1146. print $huser->getNomUrl(1);
  1147. }
  1148. print '</td>';
  1149. print "</tr>\n";
  1150. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
  1151. {
  1152. $langs->load("salaries");
  1153. // THM
  1154. print '<tr><td valign="top">'.$langs->trans("THM").'</td>';
  1155. print '<td colspan="2">';
  1156. print ($object->thm!=''?price($object->thm,'',$langs,1,-1,-1,$conf->currency):'');
  1157. print '</td>';
  1158. print "</tr>\n";
  1159. // TJM
  1160. print '<tr><td valign="top">'.$langs->trans("TJM").'</td>';
  1161. print '<td colspan="2">';
  1162. print ($object->tjm!=''?price($object->tjm,'',$langs,1,-1,-1,$conf->currency):'');
  1163. print '</td>';
  1164. print "</tr>\n";
  1165. // Salary
  1166. print '<tr><td valign="top">'.$langs->trans("Salary").'</td>';
  1167. print '<td colspan="2">';
  1168. print ($object->salary!=''?price($object->salary,'',$langs,1,-1,-1,$conf->currency):'');
  1169. print '</td>';
  1170. print "</tr>\n";
  1171. }
  1172. // Weeklyhours
  1173. print '<tr><td valign="top">'.$langs->trans("WeeklyHours").'</td>';
  1174. print '<td colspan="2">';
  1175. print price2num($object->weeklyhours);
  1176. print '</td>';
  1177. print "</tr>\n";
  1178. // Accountancy code
  1179. if ($conf->salaries->enabled)
  1180. {
  1181. print '<tr><td valign="top">'.$langs->trans("AccountancyCode").'</td>';
  1182. print '<td colspan="2">'.$object->accountancy_code.'</td>';
  1183. }
  1184. // Color user
  1185. if (! empty($conf->agenda->enabled))
  1186. {
  1187. print '<tr><td valign="top">'.$langs->trans("ColorUser").'</td>';
  1188. print '<td colspan="2">';
  1189. if ($object->color) print '<input type="text" disabled="disabled" style="padding: 0; margin-top: 0; margin-bottom: 0; width: 36px; background-color: #'.$object->color.'" value="'.$object->color.'">';
  1190. print '</td>';
  1191. print "</tr>\n";
  1192. }
  1193. // Status
  1194. print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
  1195. print '<td colspan="2">';
  1196. print $object->getLibStatut(4);
  1197. print '</td>';
  1198. print '</tr>'."\n";
  1199. print '<tr><td valign="top">'.$langs->trans("LastConnexion").'</td>';
  1200. print '<td colspan="2">'.dol_print_date($object->datelastlogin,"dayhour").'</td>';
  1201. print "</tr>\n";
  1202. print '<tr><td valign="top">'.$langs->trans("PreviousConnexion").'</td>';
  1203. print '<td colspan="2">'.dol_print_date($object->datepreviouslogin,"dayhour").'</td>';
  1204. print "</tr>\n";
  1205. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER))
  1206. {
  1207. print '<tr><td valign="top">'.$langs->trans("OpenIDURL").'</td>';
  1208. print '<td colspan="2">'.$object->openid.'</td>';
  1209. print "</tr>\n";
  1210. }
  1211. // Company / Contact
  1212. if (! empty($conf->societe->enabled))
  1213. {
  1214. print '<tr><td valign="top">'.$langs->trans("LinkToCompanyContact").'</td>';
  1215. print '<td colspan="2">';
  1216. if (isset($object->societe_id) && $object->societe_id > 0)
  1217. {
  1218. $societe = new Societe($db);
  1219. $societe->fetch($object->societe_id);
  1220. print $societe->getNomUrl(1,'');
  1221. }
  1222. else
  1223. {
  1224. print $langs->trans("ThisUserIsNot");
  1225. }
  1226. if (! empty($object->contact_id))
  1227. {
  1228. $contact = new Contact($db);
  1229. $contact->fetch($object->contact_id);
  1230. if ($object->societe_id > 0) print ' / ';
  1231. else print '<br>';
  1232. print '<a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$object->contact_id.'">'.img_object($langs->trans("ShowContact"),'contact').' '.dol_trunc($contact->getFullName($langs),32).'</a>';
  1233. }
  1234. print '</td>';
  1235. print '</tr>'."\n";
  1236. }
  1237. // Module Adherent
  1238. if (! empty($conf->adherent->enabled))
  1239. {
  1240. $langs->load("members");
  1241. print '<tr><td valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  1242. print '<td colspan="2">';
  1243. if ($object->fk_member)
  1244. {
  1245. $adh=new Adherent($db);
  1246. $adh->fetch($object->fk_member);
  1247. $adh->ref=$adh->getFullname($langs); // Force to show login instead of id
  1248. print $adh->getNomUrl(1);
  1249. }
  1250. else
  1251. {
  1252. print $langs->trans("UserNotLinkedToMember");
  1253. }
  1254. print '</td>';
  1255. print '</tr>'."\n";
  1256. }
  1257. // Multicompany
  1258. // TODO This should be done with hook formObjectOption
  1259. if (is_object($mc))
  1260. {
  1261. if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1262. {
  1263. print '<tr><td valign="top">'.$langs->trans("Entity").'</td><td width="75%" class="valeur">';
  1264. if (empty($object->entity))
  1265. {
  1266. print $langs->trans("AllEntities");
  1267. }
  1268. else
  1269. {
  1270. $mc->getInfo($object->entity);
  1271. print $mc->label;
  1272. }
  1273. print "</td></tr>\n";
  1274. }
  1275. }
  1276. // Other attributes
  1277. $parameters=array('colspan' => ' colspan="2"');
  1278. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1279. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1280. {
  1281. print $object->showOptionals($extrafields);
  1282. }
  1283. print "</table>\n";
  1284. print "</div>\n";
  1285. /*
  1286. * Buttons actions
  1287. */
  1288. print '<div class="tabsAction">';
  1289. if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1290. {
  1291. if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
  1292. {
  1293. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("DisabledInMonoUserMode")).'">'.$langs->trans("Modify").'</a></div>';
  1294. }
  1295. else
  1296. {
  1297. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>';
  1298. }
  1299. }
  1300. elseif ($caneditpassword && ! $object->ldap_sid &&
  1301. (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1302. {
  1303. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a></div>';
  1304. }
  1305. // Si on a un gestionnaire de generation de mot de passe actif
  1306. if ($conf->global->USER_PASSWORD_GENERATED != 'none')
  1307. {
  1308. if ($object->statut == 0)
  1309. {
  1310. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("ReinitPassword").'</a></div>';
  1311. }
  1312. elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
  1313. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1314. {
  1315. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=password">'.$langs->trans("ReinitPassword").'</a></div>';
  1316. }
  1317. if ($object->statut == 0)
  1318. {
  1319. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("SendNewPassword").'</a></div>';
  1320. }
  1321. else if (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
  1322. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1323. {
  1324. 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>';
  1325. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendNewPassword").'</a></div>';
  1326. }
  1327. }
  1328. // Activer
  1329. if ($user->id <> $id && $candisableuser && $object->statut == 0 &&
  1330. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1331. {
  1332. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=enable">'.$langs->trans("Reactivate").'</a></div>';
  1333. }
  1334. // Desactiver
  1335. if ($user->id <> $id && $candisableuser && $object->statut == 1 &&
  1336. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1337. {
  1338. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&amp;id='.$object->id.'">'.$langs->trans("DisableUser").'</a></div>';
  1339. }
  1340. // Delete
  1341. if ($user->id <> $id && $candisableuser &&
  1342. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1343. {
  1344. if ($user->admin || ! $object->admin) // If user edited is admin, delete is possible on for an admin
  1345. {
  1346. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("DeleteUser").'</a></div>';
  1347. }
  1348. else
  1349. {
  1350. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("MustBeAdminToDeleteOtherAdmin")).'">'.$langs->trans("DeleteUser").'</a></div>';
  1351. }
  1352. }
  1353. print "</div>\n";
  1354. print "<br>\n";
  1355. /*
  1356. * Liste des groupes dans lequel est l'utilisateur
  1357. */
  1358. if ($canreadgroup)
  1359. {
  1360. print_fiche_titre($langs->trans("ListOfGroupsForUser"),'','');
  1361. // On selectionne les groupes auquel fait parti le user
  1362. $exclude = array();
  1363. $usergroup=new UserGroup($db);
  1364. $groupslist = $usergroup->listGroupsForUser($object->id);
  1365. if (! empty($groupslist))
  1366. {
  1367. if (! (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)))
  1368. {
  1369. foreach($groupslist as $groupforuser)
  1370. {
  1371. $exclude[]=$groupforuser->id;
  1372. }
  1373. }
  1374. }
  1375. if ($caneditgroup)
  1376. {
  1377. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'."\n";
  1378. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  1379. print '<input type="hidden" name="action" value="addgroup" />';
  1380. print '<table class="noborder" width="100%">'."\n";
  1381. print '<tr class="liste_titre"><th class="liste_titre" width="25%">'.$langs->trans("GroupsToAdd").'</th>'."\n";
  1382. print '<th>';
  1383. print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity);
  1384. print ' &nbsp; ';
  1385. // Multicompany
  1386. if (! empty($conf->multicompany->enabled))
  1387. {
  1388. if ($conf->entity == 1 && $conf->multicompany->transverse_mode)
  1389. {
  1390. print '</td><td valign="top">'.$langs->trans("Entity").'</td>';
  1391. print "<td>".$mc->select_entities($conf->entity);
  1392. }
  1393. else
  1394. {
  1395. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1396. }
  1397. }
  1398. else
  1399. {
  1400. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1401. }
  1402. print '<input type="submit" class="button" value="'.$langs->trans("Add").'" />';
  1403. print '</th></tr>'."\n";
  1404. print '</table></form>'."\n";
  1405. print '<br>';
  1406. }
  1407. /*
  1408. * Groups assigned to user
  1409. */
  1410. print '<table class="noborder" width="100%">';
  1411. print '<tr class="liste_titre">';
  1412. print '<td class="liste_titre" width="25%">'.$langs->trans("Groups").'</td>';
  1413. if(! empty($conf->multicompany->enabled) && !empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1414. {
  1415. print '<td class="liste_titre" width="25%">'.$langs->trans("Entity").'</td>';
  1416. }
  1417. print "<td>&nbsp;</td></tr>\n";
  1418. if (! empty($groupslist))
  1419. {
  1420. $var=true;
  1421. foreach($groupslist as $group)
  1422. {
  1423. $var=!$var;
  1424. print "<tr ".$bc[$var].">";
  1425. print '<td>';
  1426. if ($caneditgroup)
  1427. {
  1428. print '<a href="'.DOL_URL_ROOT.'/user/group/card.php?id='.$group->id.'">'.img_object($langs->trans("ShowGroup"),"group").' '.$group->name.'</a>';
  1429. }
  1430. else
  1431. {
  1432. print img_object($langs->trans("ShowGroup"),"group").' '.$group->name;
  1433. }
  1434. print '</td>';
  1435. if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1436. {
  1437. print '<td class="valeur">';
  1438. if (! empty($group->usergroup_entity))
  1439. {
  1440. $nb=0;
  1441. foreach($group->usergroup_entity as $group_entity)
  1442. {
  1443. $mc->getInfo($group_entity);
  1444. print ($nb > 0 ? ', ' : '').$mc->label;
  1445. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'&amp;entity='.$group_entity.'">';
  1446. print img_delete($langs->trans("RemoveFromGroup"));
  1447. print '</a>';
  1448. $nb++;
  1449. }
  1450. }
  1451. }
  1452. print '<td align="right">';
  1453. if ($caneditgroup && empty($conf->multicompany->transverse_mode))
  1454. {
  1455. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'">';
  1456. print img_delete($langs->trans("RemoveFromGroup"));
  1457. print '</a>';
  1458. }
  1459. else
  1460. {
  1461. print "&nbsp;";
  1462. }
  1463. print "</td></tr>\n";
  1464. }
  1465. }
  1466. else
  1467. {
  1468. print '<tr '.$bc[false].'><td colspan="3">'.$langs->trans("None").'</td></tr>';
  1469. }
  1470. print "</table>";
  1471. print "<br>";
  1472. }
  1473. }
  1474. /*
  1475. * Fiche en mode edition
  1476. */
  1477. if ($action == 'edit' && ($canedituser || $caneditfield || $caneditpassword || ($user->id == $object->id)))
  1478. {
  1479. $rowspan=16;
  1480. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $rowspan++;
  1481. if (! empty($conf->societe->enabled)) $rowspan++;
  1482. if (! empty($conf->adherent->enabled)) $rowspan++;
  1483. if (! empty($conf->skype->enabled)) $rowspan++;
  1484. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) $rowspan = $rowspan+3;
  1485. if (! empty($conf->agenda->enabled)) $rowspan++;
  1486. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="updateuser" enctype="multipart/form-data">';
  1487. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1488. print '<input type="hidden" name="action" value="update">';
  1489. print '<input type="hidden" name="entity" value="'.$object->entity.'">';
  1490. print '<table width="100%" class="border">';
  1491. print '<tr><td width="25%" valign="top">'.$langs->trans("Ref").'</td>';
  1492. print '<td colspan="2">';
  1493. print $object->id;
  1494. print '</td>';
  1495. print '</tr>';
  1496. // Lastname
  1497. print "<tr>";
  1498. print '<td valign="top" class="fieldrequired">'.$langs->trans("Lastname").'</td>';
  1499. print '<td>';
  1500. if ($caneditfield && !$object->ldap_sid)
  1501. {
  1502. print '<input size="30" type="text" class="flat" name="lastname" value="'.$object->lastname.'">';
  1503. }
  1504. else
  1505. {
  1506. print '<input type="hidden" name="lastname" value="'.$object->lastname.'">';
  1507. print $object->lastname;
  1508. }
  1509. print '</td>';
  1510. // Photo
  1511. print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
  1512. print $form->showphoto('userphoto',$object);
  1513. if ($caneditfield)
  1514. {
  1515. if ($object->photo) print "<br>\n";
  1516. print '<table class="nobordernopadding hideonsmartphone">';
  1517. if ($object->photo) print '<tr><td align="center"><input type="checkbox" class="flat" name="deletephoto" id="photodelete"> '.$langs->trans("Delete").'<br><br></td></tr>';
  1518. print '<tr><td>'.$langs->trans("PhotoFile").'</td></tr>';
  1519. print '<tr><td><input type="file" class="flat" name="photo" id="photoinput"></td></tr>';
  1520. print '</table>';
  1521. }
  1522. print '</td>';
  1523. print '</tr>';
  1524. // Firstname
  1525. print "<tr>".'<td valign="top">'.$langs->trans("Firstname").'</td>';
  1526. print '<td>';
  1527. if ($caneditfield && !$object->ldap_sid)
  1528. {
  1529. print '<input size="30" type="text" class="flat" name="firstname" value="'.$object->firstname.'">';
  1530. }
  1531. else
  1532. {
  1533. print '<input type="hidden" name="firstname" value="'.$object->firstname.'">';
  1534. print $object->firstname;
  1535. }
  1536. print '</td></tr>';
  1537. // Position/Job
  1538. print '<tr><td valign="top">'.$langs->trans("PostOrFunction").'</td>';
  1539. print '<td>';
  1540. if ($caneditfield)
  1541. {
  1542. print '<input size="30" type="text" name="job" value="'.$object->job.'">';
  1543. }
  1544. else
  1545. {
  1546. print '<input type="hidden" name="job" value="'.$object->job.'">';
  1547. print $object->job;
  1548. }
  1549. print '</td></tr>';
  1550. // Login
  1551. print "<tr>".'<td valign="top"><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
  1552. print '<td>';
  1553. if ($user->admin && !$object->ldap_sid)
  1554. {
  1555. print '<input size="12" maxlength="24" type="text" class="flat" name="login" value="'.$object->login.'">';
  1556. }
  1557. else
  1558. {
  1559. print '<input type="hidden" name="login" value="'.$object->login.'">';
  1560. print $object->login;
  1561. }
  1562. print '</td>';
  1563. print '</tr>';
  1564. // Pass
  1565. print '<tr><td valign="top">'.$langs->trans("Password").'</td>';
  1566. print '<td>';
  1567. if ($object->ldap_sid)
  1568. {
  1569. $text=$langs->trans("DomainPassword");
  1570. }
  1571. else if ($caneditpassword)
  1572. {
  1573. $text='<input size="12" maxlength="32" type="password" class="flat" name="password" value="'.$object->pass.'" autocomplete="off">';
  1574. if ($dolibarr_main_authentication && $dolibarr_main_authentication == 'http')
  1575. {
  1576. $text=$form->textwithpicto($text,$langs->trans("DolibarrInHttpAuthenticationSoPasswordUseless",$dolibarr_main_authentication),1,'warning');
  1577. }
  1578. }
  1579. else
  1580. {
  1581. $text=preg_replace('/./i','*',$object->pass);
  1582. }
  1583. print $text;
  1584. print "</td></tr>\n";
  1585. // Administrator
  1586. print '<tr><td valign="top">'.$langs->trans("Administrator").'</td>';
  1587. if ($object->societe_id > 0)
  1588. {
  1589. $langs->load("admin");
  1590. print '<td>';
  1591. print '<input type="hidden" name="admin" value="'.$object->admin.'">'.yn($object->admin);
  1592. print ' ('.$langs->trans("ExternalUser").')';
  1593. print '</td></tr>';
  1594. }
  1595. else
  1596. {
  1597. print '<td>';
  1598. $nbSuperAdmin = $user->getNbOfUsers('superadmin');
  1599. if ($user->admin
  1600. && ($user->id != $object->id) // Don't downgrade ourself
  1601. && ($object->entity > 0 || $nbSuperAdmin > 1) // Don't downgrade a superadmin if alone
  1602. )
  1603. {
  1604. print $form->selectyesno('admin',$object->admin,1);
  1605. if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
  1606. {
  1607. if ($conf->use_javascript_ajax)
  1608. {
  1609. print '<script type="text/javascript">
  1610. $(function() {
  1611. var admin = $("select[name=admin]").val();
  1612. if (admin == 0) {
  1613. $("input[name=superadmin]")
  1614. .attr("disabled", true)
  1615. .attr("checked", false);
  1616. }
  1617. if ($("input[name=superadmin]").attr("checked") == "checked") {
  1618. $("select[name=entity]")
  1619. .attr("disabled", true);
  1620. }
  1621. $("select[name=admin]").change(function() {
  1622. if ( $(this).val() == 0 ) {
  1623. $("input[name=superadmin]")
  1624. .attr("disabled", true)
  1625. .attr("checked", false);
  1626. $("select[name=entity]")
  1627. .attr("disabled", false);
  1628. } else {
  1629. $("input[name=superadmin]")
  1630. .attr("disabled", false);
  1631. }
  1632. });
  1633. $("input[name=superadmin]").change(function() {
  1634. if ( $(this).attr("checked") == "checked" ) {
  1635. $("select[name=entity]")
  1636. .attr("disabled", true);
  1637. } else {
  1638. $("select[name=entity]")
  1639. .attr("disabled", false);
  1640. }
  1641. });
  1642. });
  1643. </script>';
  1644. }
  1645. $checked=(($object->admin && ! $object->entity) ? ' checked' : '');
  1646. print '<input type="checkbox" name="superadmin" value="1"'.$checked.' /> '.$langs->trans("SuperAdministrator");
  1647. }
  1648. }
  1649. else
  1650. {
  1651. $yn = yn($object->admin);
  1652. print '<input type="hidden" name="admin" value="'.$object->admin.'">';
  1653. print '<input type="hidden" name="superadmin" value="'.(empty($object->entity) ? 1 : 0).'">';
  1654. if (! empty($conf->multicompany->enabled) && empty($object->entity)) print $form->textwithpicto($yn,$langs->trans("DontDowngradeSuperAdmin"),1,'warning');
  1655. else print $yn;
  1656. }
  1657. print '</td></tr>';
  1658. }
  1659. // Type
  1660. print '<tr><td width="25%" valign="top">'.$langs->trans("Type").'</td>';
  1661. print '<td>';
  1662. if ($user->id == $object->id || ! $user->admin)
  1663. {
  1664. $type=$langs->trans("Internal");
  1665. if ($object->societe_id) $type=$langs->trans("External");
  1666. print $form->textwithpicto($type,$langs->trans("InternalExternalDesc"));
  1667. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1668. }
  1669. else
  1670. {
  1671. $type=0;
  1672. if ($object->contact_id) $type=$object->contact_id;
  1673. print $form->selectcontacts(0,$type,'contactid',2,'','',1,'',false,1);
  1674. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1675. }
  1676. print '</td></tr>';
  1677. // Tel pro
  1678. print "<tr>".'<td valign="top">'.$langs->trans("PhonePro").'</td>';
  1679. print '<td>';
  1680. if ($caneditfield && empty($object->ldap_sid))
  1681. {
  1682. print '<input size="20" type="text" name="office_phone" class="flat" value="'.$object->office_phone.'">';
  1683. }
  1684. else
  1685. {
  1686. print '<input type="hidden" name="office_phone" value="'.$object->office_phone.'">';
  1687. print $object->office_phone;
  1688. }
  1689. print '</td></tr>';
  1690. // Tel mobile
  1691. print "<tr>".'<td valign="top">'.$langs->trans("PhoneMobile").'</td>';
  1692. print '<td>';
  1693. if ($caneditfield && empty($object->ldap_sid))
  1694. {
  1695. print '<input size="20" type="text" name="user_mobile" class="flat" value="'.$object->user_mobile.'">';
  1696. }
  1697. else
  1698. {
  1699. print '<input type="hidden" name="user_mobile" value="'.$object->user_mobile.'">';
  1700. print $object->user_mobile;
  1701. }
  1702. print '</td></tr>';
  1703. // Fax
  1704. print "<tr>".'<td valign="top">'.$langs->trans("Fax").'</td>';
  1705. print '<td>';
  1706. if ($caneditfield && empty($object->ldap_sid))
  1707. {
  1708. print '<input size="20" type="text" name="office_fax" class="flat" value="'.$object->office_fax.'">';
  1709. }
  1710. else
  1711. {
  1712. print '<input type="hidden" name="office_fax" value="'.$object->office_fax.'">';
  1713. print $object->office_fax;
  1714. }
  1715. print '</td></tr>';
  1716. // Skype
  1717. if (! empty($conf->skype->enabled))
  1718. {
  1719. print '<tr><td valign="top">'.$langs->trans("Skype").'</td>';
  1720. print '<td>';
  1721. if ($caneditfield && empty($object->ldap_sid))
  1722. {
  1723. print '<input size="40" type="text" name="skype" class="flat" value="'.$object->skype.'">';
  1724. }
  1725. else
  1726. {
  1727. print '<input type="hidden" name="skype" value="'.$object->skype.'">';
  1728. print $object->skype;
  1729. }
  1730. print '</td></tr>';
  1731. }
  1732. // EMail
  1733. print "<tr>".'<td valign="top"'.(! empty($conf->global->USER_MAIL_REQUIRED)?' class="fieldrequired"':'').'>'.$langs->trans("EMail").'</td>';
  1734. print '<td>';
  1735. if ($caneditfield && empty($object->ldap_sid))
  1736. {
  1737. print '<input size="40" type="text" name="email" class="flat" value="'.$object->email.'">';
  1738. }
  1739. else
  1740. {
  1741. print '<input type="hidden" name="email" value="'.$object->email.'">';
  1742. print $object->email;
  1743. }
  1744. print '</td></tr>';
  1745. // Signature
  1746. print "<tr>".'<td valign="top">'.$langs->trans("Signature").'</td>';
  1747. print '<td>';
  1748. if ($caneditfield)
  1749. {
  1750. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1751. $doleditor=new DolEditor('signature',$object->signature,'',138,'dolibarr_mailings','In',false,true,empty($conf->global->FCKEDITOR_ENABLE_USERSIGN)?0:1,ROWS_4,72);
  1752. print $doleditor->Create(1);
  1753. }
  1754. else
  1755. {
  1756. print dol_htmlentitiesbr($object->signature);
  1757. }
  1758. print '</td></tr>';
  1759. // OpenID url
  1760. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER))
  1761. {
  1762. print "<tr>".'<td valign="top">'.$langs->trans("OpenIDURL").'</td>';
  1763. print '<td>';
  1764. if ($caneditfield)
  1765. {
  1766. print '<input size="40" type="url" name="openid" class="flat" value="'.$object->openid.'">';
  1767. }
  1768. else
  1769. {
  1770. print '<input type="hidden" name="openid" value="'.$object->openid.'">';
  1771. print $object->openid;
  1772. }
  1773. print '</td></tr>';
  1774. }
  1775. // Hierarchy
  1776. print '<tr><td valign="top">'.$langs->trans("HierarchicalResponsible").'</td>';
  1777. print '<td>';
  1778. if ($caneditfield)
  1779. {
  1780. print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$object->entity);
  1781. }
  1782. else
  1783. {
  1784. print '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
  1785. $huser=new User($db);
  1786. $huser->fetch($object->fk_user);
  1787. print $huser->getNomUrl(1);
  1788. }
  1789. print '</td>';
  1790. print "</tr>\n";
  1791. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
  1792. {
  1793. $langs->load("salaries");
  1794. // THM
  1795. print '<tr><td valign="top">'.$langs->trans("THM").'</td>';
  1796. print '<td>';
  1797. print '<input size="8" type="text" name="thm" value="'.price2num(GETPOST('thm')?GETPOST('thm'):$object->thm).'">';
  1798. print '</td>';
  1799. print "</tr>\n";
  1800. // TJM
  1801. print '<tr><td valign="top">'.$langs->trans("TJM").'</td>';
  1802. print '<td>';
  1803. print '<input size="8" type="text" name="tjm" value="'.price2num(GETPOST('tjm')?GETPOST('tjm'):$object->tjm).'">';
  1804. print '</td>';
  1805. print "</tr>\n";
  1806. // Salary
  1807. print '<tr><td valign="top">'.$langs->trans("Salary").'</td>';
  1808. print '<td>';
  1809. print '<input size="8" type="text" name="salary" value="'.price2num(GETPOST('salary')?GETPOST('salary'):$object->salary).'">';
  1810. print '</td>';
  1811. print "</tr>\n";
  1812. }
  1813. // Weeklyhours
  1814. print '<tr><td valign="top">'.$langs->trans("WeeklyHours").'</td>';
  1815. print '<td>';
  1816. print '<input size="8" type="text" name="weeklyhours" value="'.price2num(GETPOST('weeklyhours')?GETPOST('weeklyhours'):$object->weeklyhours).'">';
  1817. print '</td>';
  1818. print "</tr>\n";
  1819. // Accountancy code
  1820. if ($conf->salaries->enabled)
  1821. {
  1822. print "<tr>";
  1823. print '<td valign="top">'.$langs->trans("AccountancyCode").'</td>';
  1824. print '<td>';
  1825. if ($caneditfield)
  1826. {
  1827. print '<input size="30" type="text" class="flat" name="accountancy_code" value="'.$object->accountancy_code.'">';
  1828. }
  1829. else
  1830. {
  1831. print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
  1832. print $object->accountancy_code;
  1833. }
  1834. print '</td>';
  1835. print "</tr>";
  1836. }
  1837. // User color
  1838. if (! empty($conf->agenda->enabled))
  1839. {
  1840. print '<tr><td valign="top">'.$langs->trans("ColorUser").'</td>';
  1841. print '<td>';
  1842. print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', 'usercolorconfig', 1, '', 'hideifnotset');
  1843. print '</td></tr>';
  1844. }
  1845. // Status
  1846. print '<tr><td valign="top">'.$langs->trans("Status").'</td>';
  1847. print '<td>';
  1848. print $object->getLibStatut(4);
  1849. print '</td></tr>';
  1850. // Company / Contact
  1851. if (! empty($conf->societe->enabled))
  1852. {
  1853. print '<tr><td width="25%" valign="top">'.$langs->trans("LinkToCompanyContact").'</td>';
  1854. print '<td>';
  1855. if ($object->societe_id > 0)
  1856. {
  1857. $societe = new Societe($db);
  1858. $societe->fetch($object->societe_id);
  1859. print $societe->getNomUrl(1,'');
  1860. if ($object->contact_id)
  1861. {
  1862. $contact = new Contact($db);
  1863. $contact->fetch($object->contact_id);
  1864. print ' / <a href="'.DOL_URL_ROOT.'/contact/card.php?id='.$object->contact_id.'">'.img_object($langs->trans("ShowContact"),'contact').' '.dol_trunc($contact->getFullName($langs),32).'</a>';
  1865. }
  1866. }
  1867. else
  1868. {
  1869. print $langs->trans("ThisUserIsNot");
  1870. }
  1871. print ' ('.$langs->trans("UseTypeFieldToChange").')';
  1872. print '</td>';
  1873. print "</tr>\n";
  1874. }
  1875. // Module Adherent
  1876. if (! empty($conf->adherent->enabled))
  1877. {
  1878. $langs->load("members");
  1879. print '<tr><td width="25%" valign="top">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  1880. print '<td>';
  1881. if ($object->fk_member)
  1882. {
  1883. $adh=new Adherent($db);
  1884. $adh->fetch($object->fk_member);
  1885. $adh->ref=$adh->login; // Force to show login instead of id
  1886. print $adh->getNomUrl(1);
  1887. }
  1888. else
  1889. {
  1890. print $langs->trans("UserNotLinkedToMember");
  1891. }
  1892. print '</td>';
  1893. print "</tr>\n";
  1894. }
  1895. // Multicompany
  1896. if (! empty($conf->multicompany->enabled))
  1897. {
  1898. if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1899. {
  1900. print "<tr>".'<td valign="top">'.$langs->trans("Entity").'</td>';
  1901. print "<td>".$mc->select_entities($object->entity, 'entity', '', 0, 1); // last parameter 1 means, show also a choice 0=>'all entities'
  1902. print "</td></tr>\n";
  1903. }
  1904. else
  1905. {
  1906. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1907. }
  1908. }
  1909. // Other attributes
  1910. $parameters=array('colspan' => ' colspan="2"');
  1911. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1912. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1913. {
  1914. print $object->showOptionals($extrafields,'edit');
  1915. }
  1916. print '</table>';
  1917. print '<br><center>';
  1918. print '<input value="'.$langs->trans("Save").'" class="button" type="submit" name="save">';
  1919. print ' &nbsp; ';
  1920. print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">';
  1921. print '</center>';
  1922. print '</form>';
  1923. print '</div>';
  1924. }
  1925. if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid)) $ldap->close;
  1926. }
  1927. }
  1928. llxFooter();
  1929. $db->close();