card.php 117 KB

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