card.php 117 KB

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