card.php 89 KB

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