card.php 113 KB

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