card.php 117 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432243324342435243624372438243924402441244224432444244524462447244824492450245124522453245424552456245724582459246024612462246324642465246624672468246924702471247224732474247524762477247824792480248124822483248424852486248724882489249024912492249324942495249624972498249925002501250225032504250525062507250825092510251125122513251425152516251725182519252025212522252325242525252625272528252925302531253225332534253525362537253825392540254125422543254425452546254725482549255025512552255325542555255625572558255925602561256225632564256525662567256825692570257125722573257425752576257725782579258025812582258325842585258625872588258925902591259225932594259525962597259825992600260126022603260426052606260726082609261026112612261326142615261626172618261926202621262226232624262526262627262826292630263126322633263426352636263726382639264026412642264326442645264626472648264926502651265226532654265526562657265826592660266126622663266426652666266726682669267026712672267326742675267626772678267926802681268226832684268526862687268826892690269126922693269426952696269726982699270027012702270327042705270627072708270927102711271227132714271527162717271827192720272127222723272427252726272727282729273027312732273327342735273627372738273927402741274227432744274527462747274827492750275127522753275427552756275727582759276027612762276327642765276627672768276927702771277227732774277527762777277827792780278127822783278427852786278727882789279027912792279327942795279627972798279928002801280228032804280528062807280828092810281128122813281428152816281728182819282028212822282328242825282628272828282928302831283228332834283528362837283828392840284128422843284428452846284728482849285028512852285328542855285628572858285928602861286228632864286528662867286828692870287128722873287428752876287728782879288028812882288328842885288628872888288928902891289228932894289528962897289828992900290129022903290429052906290729082909291029112912291329142915291629172918291929202921292229232924292529262927292829292930293129322933293429352936293729382939294029412942294329442945294629472948294929502951295229532954
  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 = GETPOSTINT("admin");
  234. $object->address = GETPOST('address', 'alphanohtml');
  235. $object->zip = GETPOST('zipcode', 'alphanohtml');
  236. $object->town = GETPOST('town', 'alphanohtml');
  237. $object->country_id = GETPOSTINT('country_id');
  238. $object->state_id = GETPOSTINT('state_id');
  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 = GETPOSTINT('fk_warehouse');
  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->tjm = price2num($object->tjm);
  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="fab '.$value['icon'].' pictofixedwidth"></span>';
  1063. }
  1064. if (!empty($ldap_social[$key])) {
  1065. print '<input type="hidden" name="'.$key.'" value="'.$ldap_social[$key].'">';
  1066. print $ldap_social[$key];
  1067. } else {
  1068. print '<input class="maxwidth200 widthcentpercentminusx" type="text" name="'.$key.'" value="'.GETPOST($key, 'alphanohtml').'">';
  1069. }
  1070. print '</td></tr>';
  1071. } else {
  1072. // if social network is not active but value exist we do not want to loose it
  1073. if (!empty($ldap_social[$key])) {
  1074. print '<input type="hidden" name="'.$key.'" value="'.$ldap_social[$key].'">';
  1075. } else {
  1076. print '<input type="hidden" name="'.$key.'" value="'.GETPOST($key, 'alphanohtml').'">';
  1077. }
  1078. }
  1079. }
  1080. }
  1081. // Accountancy code
  1082. if (isModEnabled('accounting')) {
  1083. print '<tr><td>'.$langs->trans("AccountancyCode").'</td>';
  1084. print '<td>';
  1085. print '<input type="text" class="maxwidthonsmartphone" name="accountancy_code" value="'.dol_escape_htmltag(GETPOST('accountancy_code', 'alphanohtml')).'">';
  1086. print '</td></tr>';
  1087. }
  1088. // User color
  1089. if (isModEnabled('agenda')) {
  1090. print '<tr><td>'.$langs->trans("ColorUser").'</td>';
  1091. print '<td>';
  1092. print $formother->selectColor(GETPOSTISSET('color') ? GETPOST('color', 'alphanohtml') : $object->color, 'color', null, 1, '', 'hideifnotset');
  1093. print '</td></tr>';
  1094. }
  1095. // Categories
  1096. if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
  1097. print '<tr><td>'.$form->editfieldkey('Categories', 'usercats', '', $object, 0).'</td><td>';
  1098. $cate_arbo = $form->select_all_categories('user', null, 'parent', null, null, 1);
  1099. print img_picto('', 'category', 'class="pictofixedwidth"').$form->multiselectarray('usercats', $cate_arbo, GETPOST('usercats', 'array'), 0, 0, 'maxwdith300 widthcentpercentminusx', 0, '90%');
  1100. print "</td></tr>";
  1101. }
  1102. // Default language
  1103. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1104. print '<tr><td>'.$form->editfieldkey('DefaultLang', 'default_lang', '', $object, 0, 'string', '', 0, 0, 'id', $langs->trans("WarningNotLangOfInterface", $langs->transnoentitiesnoconv("UserGUISetup"))).'</td>';
  1105. print '<td class="maxwidthonsmartphone">'."\n";
  1106. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language(GETPOST('default_lang', 'alpha') ? GETPOST('default_lang', 'alpha') : ($object->lang ? $object->lang : ''), 'default_lang', 0, 0, 1, 0, 0, 'maxwidth300 widthcentpercentminusx');
  1107. print '</td>';
  1108. print '</tr>';
  1109. }
  1110. // Multicompany
  1111. if (isModEnabled('multicompany') && is_object($mc)) {
  1112. // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
  1113. if (!method_exists($mc, 'formObjectOptions')) {
  1114. if (!getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && $user->admin && !$user->entity) { // condition must be same for create and edit mode
  1115. print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
  1116. print "<td>".$mc->select_entities($conf->entity);
  1117. print "</td></tr>\n";
  1118. } else {
  1119. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1120. }
  1121. }
  1122. }
  1123. // Other attributes
  1124. $parameters = array();
  1125. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_add.tpl.php';
  1126. // Signature
  1127. print '<tr><td class="tdtop">'.$langs->trans("Signature").'</td>';
  1128. print '<td class="wordbreak">';
  1129. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1130. $doleditor = new DolEditor('signature', GETPOST('signature', 'restricthtml'), '', 138, 'dolibarr_notes', 'In', true, $acceptlocallinktomedia, !getDolGlobalString('FCKEDITOR_ENABLE_USERSIGN') ? 0 : 1, ROWS_4, '90%');
  1131. print $doleditor->Create(1);
  1132. print '</td></tr>';
  1133. // Note private
  1134. print '<tr><td class="tdtop">';
  1135. print $langs->trans("NotePublic");
  1136. print '</td><td>';
  1137. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1138. $doleditor = new DolEditor('note_public', GETPOSTISSET('note_public') ? GETPOST('note_public', 'restricthtml') : '', '', 100, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PUBLIC'), ROWS_3, '90%');
  1139. $doleditor->Create();
  1140. print "</td></tr>\n";
  1141. // Note private
  1142. print '<tr><td class="tdtop">';
  1143. print $langs->trans("NotePrivate");
  1144. print '</td><td>';
  1145. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1146. $doleditor = new DolEditor('note_private', GETPOSTISSET('note_private') ? GETPOST('note_private', 'restricthtml') : '', '', 100, 'dolibarr_notes', '', false, true, getDolGlobalString('FCKEDITOR_ENABLE_NOTE_PRIVATE'), ROWS_3, '90%');
  1147. $doleditor->Create();
  1148. print "</td></tr>\n";
  1149. print '</table><hr><table class="border centpercent">';
  1150. // TODO Move this into tab RH (HierarchicalResponsible must be on both tab)
  1151. // Default warehouse
  1152. if (isModEnabled('stock') && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE_USER')) {
  1153. print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
  1154. print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
  1155. print '</td></tr>';
  1156. }
  1157. // Position/Job
  1158. print '<tr><td class="titlefieldcreate">'.$langs->trans("PostOrFunction").'</td>';
  1159. print '<td>';
  1160. print '<input class="maxwidth200 maxwidth150onsmartphone" type="text" name="job" value="'.dol_escape_htmltag(GETPOST('job', 'alphanohtml')).'">';
  1161. print '</td></tr>';
  1162. if ((isModEnabled('salaries') && $user->hasRight("salaries", "read") && in_array($id, $childids))
  1163. || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
  1164. || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
  1165. $langs->load("salaries");
  1166. // THM
  1167. print '<tr><td>';
  1168. $text = $langs->trans("THM");
  1169. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  1170. print '</td>';
  1171. print '<td>';
  1172. print '<input size="8" type="text" name="thm" value="'.dol_escape_htmltag(GETPOST('thm')).'"> '.$langs->getCurrencySymbol($conf->currency);
  1173. print '</td>';
  1174. print "</tr>\n";
  1175. // TJM
  1176. print '<tr><td>';
  1177. $text = $langs->trans("TJM");
  1178. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
  1179. print '</td>';
  1180. print '<td>';
  1181. print '<input size="8" type="text" name="tjm" value="'.dol_escape_htmltag(GETPOST('tjm')).'"> '.$langs->getCurrencySymbol($conf->currency);
  1182. print '</td>';
  1183. print "</tr>\n";
  1184. // Salary
  1185. print '<tr><td>'.$langs->trans("Salary").'</td>';
  1186. print '<td>';
  1187. print img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<input class="width100" type="text" name="salary" value="'.dol_escape_htmltag(GETPOST('salary')).'"> '.$langs->getCurrencySymbol($conf->currency);
  1188. print '</td>';
  1189. print "</tr>\n";
  1190. }
  1191. // Weeklyhours
  1192. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  1193. print '<td>';
  1194. print '<input size="8" type="text" name="weeklyhours" value="'.dol_escape_htmltag(GETPOST('weeklyhours')).'">';
  1195. print '</td>';
  1196. print "</tr>\n";
  1197. // Date employment
  1198. print '<tr><td>'.$langs->trans("DateOfEmployment").'</td>';
  1199. print '<td>';
  1200. print $form->selectDate($dateemployment, 'dateemployment', 0, 0, 1, 'formdateemployment', 1, 1, 0, '', '', '', '', 1, '', $langs->trans("from"));
  1201. print ' - ';
  1202. print $form->selectDate($dateemploymentend, 'dateemploymentend', 0, 0, 1, 'formdateemploymentend', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  1203. print '</td>';
  1204. print "</tr>\n";
  1205. // Date birth
  1206. print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
  1207. print '<td>';
  1208. print $form->selectDate($dateofbirth, 'dateofbirth', 0, 0, 1, 'createuser', 1, 0, 0, '', 0, '', '', 1, '', '', 'tzserver');
  1209. print '</td>';
  1210. print "</tr>\n";
  1211. print "</table>\n";
  1212. print dol_get_fiche_end();
  1213. print $form->buttonsSaveCancel("CreateUser");
  1214. print "</form>";
  1215. } else {
  1216. // View and edit mode
  1217. if ($id > 0) {
  1218. $res = $object->fetch($id, '', '', 1);
  1219. if ($res < 0) {
  1220. dol_print_error($db, $object->error);
  1221. exit;
  1222. }
  1223. $res = $object->fetch_optionals();
  1224. // Check if user has rights
  1225. if (!getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE')) {
  1226. $object->getrights();
  1227. if (empty($object->nb_rights) && $object->statut != 0 && empty($object->admin)) {
  1228. setEventMessages($langs->trans('UserHasNoPermissions'), null, 'warnings');
  1229. }
  1230. }
  1231. // Connexion ldap
  1232. // pour recuperer passDoNotExpire et userChangePassNextLogon
  1233. if (isModEnabled('ldap') && !empty($object->ldap_sid)) {
  1234. $ldap = new Ldap();
  1235. $result = $ldap->connect_bind();
  1236. if ($result > 0) {
  1237. $userSearchFilter = '(' . getDolGlobalString('LDAP_FILTER_CONNECTION').'('.$ldap->getUserIdentifier().'='.$object->login.'))';
  1238. $entries = $ldap->fetch($object->login, $userSearchFilter);
  1239. if (!$entries) {
  1240. setEventMessages($ldap->error, $ldap->errors, 'errors');
  1241. }
  1242. $passDoNotExpire = 0;
  1243. $userChangePassNextLogon = 0;
  1244. $userDisabled = 0;
  1245. $statutUACF = '';
  1246. // Check options of user account
  1247. if (count($ldap->uacf) > 0) {
  1248. foreach ($ldap->uacf as $key => $statut) {
  1249. if ($key == 65536) {
  1250. $passDoNotExpire = 1;
  1251. $statutUACF = $statut;
  1252. }
  1253. }
  1254. } else {
  1255. $userDisabled = 1;
  1256. $statutUACF = "ACCOUNTDISABLE";
  1257. }
  1258. if ($ldap->pwdlastset == 0) {
  1259. $userChangePassNextLogon = 1;
  1260. }
  1261. }
  1262. }
  1263. // Show tabs
  1264. if ($mode == 'employee') { // For HRM module development
  1265. $title = $langs->trans("Employee");
  1266. $linkback = '<a href="'.DOL_URL_ROOT.'/hrm/employee/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1267. } else {
  1268. $title = $langs->trans("User");
  1269. $linkback = '';
  1270. if ($user->hasRight("user", "user", "read") || $user->admin) {
  1271. $linkback = '<a href="'.DOL_URL_ROOT.'/user/list.php?restore_lastsearch_values=1">'.$langs->trans("BackToList").'</a>';
  1272. }
  1273. }
  1274. $head = user_prepare_head($object);
  1275. /*
  1276. * Confirmation reinitialisation mot de passe
  1277. */
  1278. if ($action == 'password') {
  1279. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("ReinitPassword"), $langs->trans("ConfirmReinitPassword", $object->login), "confirm_password", '', 0, 1);
  1280. }
  1281. /*
  1282. * Confirmation envoi mot de passe
  1283. */
  1284. if ($action == 'passwordsend') {
  1285. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("SendNewPassword"), $langs->trans("ConfirmSendNewPassword", $object->login), "confirm_passwordsend", '', 0, 1);
  1286. }
  1287. /*
  1288. * Confirm deactivation
  1289. */
  1290. if ($action == 'disable') {
  1291. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("DisableAUser"), $langs->trans("ConfirmDisableUser", $object->login), "confirm_disable", '', 0, 1);
  1292. }
  1293. /*
  1294. * Confirm activation
  1295. */
  1296. if ($action == 'enable') {
  1297. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("EnableAUser"), $langs->trans("ConfirmEnableUser", $object->login), "confirm_enable", '', 0, 1);
  1298. }
  1299. /*
  1300. * Confirmation suppression
  1301. */
  1302. if ($action == 'delete') {
  1303. print $form->formconfirm($_SERVER['PHP_SELF']."?id=$object->id", $langs->trans("DeleteAUser"), $langs->trans("ConfirmDeleteUser", $object->login), "confirm_delete", '', 0, 1);
  1304. }
  1305. /*
  1306. * View mode
  1307. */
  1308. if ($action != 'edit') {
  1309. print dol_get_fiche_head($head, 'user', $title, -1, 'user');
  1310. $morehtmlref = '<a href="'.DOL_URL_ROOT.'/user/vcard.php?id='.$object->id.'&output=file&file='.urlencode(dol_sanitizeFileName($object->getFullName($langs).'.vcf')).'" class="refid" rel="noopener" rel="noopener">';
  1311. $morehtmlref .= img_picto($langs->trans("Download").' '.$langs->trans("VCard").' ('.$langs->trans("AddToContacts").')', 'vcard.png', 'class="valignmiddle marginleftonly paddingrightonly"');
  1312. $morehtmlref .= '</a>';
  1313. $urltovirtualcard = '/user/virtualcard.php?id='.((int) $object->id);
  1314. $morehtmlref .= dolButtonToOpenUrlInDialogPopup('publicvirtualcard', $langs->transnoentitiesnoconv("PublicVirtualCardUrl").' - '.$object->getFullName($langs), img_picto($langs->trans("PublicVirtualCardUrl"), 'card', 'class="valignmiddle marginleftonly paddingrightonly"'), $urltovirtualcard, '', 'nohover');
  1315. dol_banner_tab($object, 'id', $linkback, $user->hasRight("user", "user", "read") || $user->admin, 'rowid', 'ref', $morehtmlref);
  1316. print '<div class="fichecenter">';
  1317. print '<div class="fichehalfleft">';
  1318. print '<div class="underbanner clearboth"></div>';
  1319. print '<table class="border tableforfield centpercent">';
  1320. // Login
  1321. print '<tr><td class="titlefieldmiddle">'.$langs->trans("Login").'</td>';
  1322. if (!empty($object->ldap_sid) && $object->statut == 0) {
  1323. print '<td class="error">';
  1324. print $langs->trans("LoginAccountDisableInDolibarr");
  1325. print '</td>';
  1326. } else {
  1327. print '<td>';
  1328. $addadmin = '';
  1329. if (property_exists($object, 'admin')) {
  1330. if (isModEnabled('multicompany') && !empty($object->admin) && empty($object->entity)) {
  1331. $addadmin .= img_picto($langs->trans("SuperAdministratorDesc"), "redstar", 'class="paddingleft"');
  1332. } elseif (!empty($object->admin)) {
  1333. $addadmin .= img_picto($langs->trans("AdministratorDesc"), "star", 'class="paddingleft"');
  1334. }
  1335. }
  1336. print showValueWithClipboardCPButton($object->login).$addadmin;
  1337. print '</td>';
  1338. }
  1339. print '</tr>'."\n";
  1340. // Type
  1341. print '<tr><td>';
  1342. $text = $langs->trans("Type");
  1343. print $form->textwithpicto($text, $langs->trans("InternalExternalDesc"));
  1344. print '</td><td>';
  1345. $type = $langs->trans("Internal");
  1346. if ($object->socid > 0) {
  1347. $type = $langs->trans("External");
  1348. }
  1349. print '<span class="badgeneutral">';
  1350. print $type;
  1351. if ($object->ldap_sid) {
  1352. print ' ('.$langs->trans("DomainUser").')';
  1353. }
  1354. print '</span>';
  1355. print '</td></tr>'."\n";
  1356. // Ldap sid
  1357. if ($object->ldap_sid) {
  1358. print '<tr><td>'.$langs->trans("Type").'</td><td>';
  1359. print $langs->trans("DomainUser", $ldap->domainFQDN);
  1360. print '</td></tr>'."\n";
  1361. }
  1362. // Employee
  1363. print '<tr><td>'.$langs->trans("Employee").'</td><td>';
  1364. print '<input type="checkbox" disabled name="employee" value="1"'.($object->employee ? ' checked="checked"' : '').'>';
  1365. //print yn($object->employee);
  1366. print '</td></tr>'."\n";
  1367. // TODO This is also available into the tab RH
  1368. // Hierarchy
  1369. print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
  1370. print '<td>';
  1371. if (empty($object->fk_user)) {
  1372. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  1373. } else {
  1374. $huser = new User($db);
  1375. if ($object->fk_user > 0) {
  1376. $huser->fetch($object->fk_user);
  1377. print $huser->getNomUrl(-1);
  1378. } else {
  1379. print '<span class="opacitymedium">'.$langs->trans("None").'</span>';
  1380. }
  1381. }
  1382. print '</td>';
  1383. print "</tr>\n";
  1384. // Expense report validator
  1385. if (isModEnabled('expensereport')) {
  1386. print '<tr><td>';
  1387. $text = $langs->trans("ForceUserExpenseValidator");
  1388. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  1389. print '</td>';
  1390. print '<td>';
  1391. if (!empty($object->fk_user_expense_validator)) {
  1392. $evuser = new User($db);
  1393. $evuser->fetch($object->fk_user_expense_validator);
  1394. print $evuser->getNomUrl(-1);
  1395. }
  1396. print '</td>';
  1397. print "</tr>\n";
  1398. }
  1399. // Holiday request validator
  1400. if (isModEnabled('holiday')) {
  1401. print '<tr><td>';
  1402. $text = $langs->trans("ForceUserHolidayValidator");
  1403. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  1404. print '</td>';
  1405. print '<td>';
  1406. if (!empty($object->fk_user_holiday_validator)) {
  1407. $hvuser = new User($db);
  1408. $hvuser->fetch($object->fk_user_holiday_validator);
  1409. print $hvuser->getNomUrl(-1);
  1410. }
  1411. print '</td>';
  1412. print "</tr>\n";
  1413. }
  1414. // Position/Job
  1415. print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
  1416. print '<td>'.dol_escape_htmltag($object->job).'</td>';
  1417. print '</tr>'."\n";
  1418. // Weeklyhours
  1419. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  1420. print '<td>';
  1421. print price2num($object->weeklyhours);
  1422. print '</td>';
  1423. print "</tr>\n";
  1424. // Sensitive salary/value information
  1425. if ((empty($user->socid) && in_array($id, $childids)) // A user can always see salary/value information for its subordinates
  1426. || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
  1427. || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
  1428. $langs->load("salaries");
  1429. // Salary
  1430. print '<tr><td>'.$langs->trans("Salary").'</td>';
  1431. print '<td>';
  1432. print($object->salary != '' ? img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<span class="amount">'.price($object->salary, '', $langs, 1, -1, -1, $conf->currency) : '').'</span>';
  1433. print '</td>';
  1434. print "</tr>\n";
  1435. // THM
  1436. print '<tr><td>';
  1437. $text = $langs->trans("THM");
  1438. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  1439. print '</td>';
  1440. print '<td>';
  1441. print($object->thm != '' ? price($object->thm, '', $langs, 1, -1, -1, $conf->currency) : '');
  1442. print '</td>';
  1443. print "</tr>\n";
  1444. // TJM
  1445. print '<tr><td>';
  1446. $text = $langs->trans("TJM");
  1447. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
  1448. print '</td>';
  1449. print '<td>';
  1450. print($object->tjm != '' ? price($object->tjm, '', $langs, 1, -1, -1, $conf->currency) : '');
  1451. print '</td>';
  1452. print "</tr>\n";
  1453. }
  1454. // Date employment
  1455. print '<tr><td>'.$langs->trans("DateOfEmployment").'</td>';
  1456. print '<td>';
  1457. if ($object->dateemployment) {
  1458. print '<span class="opacitymedium">'.$langs->trans("FromDate").'</span> ';
  1459. print dol_print_date($object->dateemployment, 'day');
  1460. }
  1461. if ($object->dateemploymentend) {
  1462. print '<span class="opacitymedium"> - '.$langs->trans("To").'</span> ';
  1463. print dol_print_date($object->dateemploymentend, 'day');
  1464. }
  1465. print '</td>';
  1466. print "</tr>\n";
  1467. // Date of birth
  1468. print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
  1469. print '<td>';
  1470. print dol_print_date($object->birth, 'day', 'tzserver');
  1471. print '</td>';
  1472. print "</tr>\n";
  1473. // Default warehouse
  1474. if (isModEnabled('stock') && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE_USER')) {
  1475. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/entrepot.class.php';
  1476. print '<tr><td>'.$langs->trans("DefaultWarehouse").'</td><td>';
  1477. if ($object->fk_warehouse > 0) {
  1478. $warehousestatic = new Entrepot($db);
  1479. $warehousestatic->fetch($object->fk_warehouse);
  1480. print $warehousestatic->getNomUrl(1);
  1481. }
  1482. print '</td></tr>';
  1483. }
  1484. print '</table>';
  1485. print '</div>';
  1486. print '<div class="fichehalfright">';
  1487. print '<div class="underbanner clearboth"></div>';
  1488. print '<table class="border tableforfield centpercent">';
  1489. // Color user
  1490. if (isModEnabled('agenda')) {
  1491. print '<tr><td class="titlefield">'.$langs->trans("ColorUser").'</td>';
  1492. print '<td>';
  1493. print $formother->showColor($object->color, '');
  1494. print '</td>';
  1495. print "</tr>\n";
  1496. }
  1497. // Categories
  1498. if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
  1499. print '<tr><td class="titlefield">'.$langs->trans("Categories").'</td>';
  1500. print '<td colspan="3">';
  1501. print $form->showCategories($object->id, Categorie::TYPE_USER, 1);
  1502. print '</td></tr>';
  1503. }
  1504. // Default language
  1505. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  1506. $langs->load("languages");
  1507. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
  1508. print '<tr><td class="titlefield">';
  1509. print $form->textwithpicto($langs->trans("DefaultLang"), $langs->trans("WarningNotLangOfInterface", $langs->transnoentitiesnoconv("UserGUISetup")));
  1510. print '</td><td>';
  1511. //$s=picto_from_langcode($object->default_lang);
  1512. //print ($s?$s.' ':'');
  1513. $labellang = ($object->lang ? $langs->trans('Language_'.$object->lang) : '');
  1514. print picto_from_langcode($object->lang, 'class="paddingrightonly saturatemedium opacitylow"');
  1515. print $labellang;
  1516. print '</td></tr>';
  1517. }
  1518. if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication) && getDolGlobalString('MAIN_OPENIDURL_PERUSER')) {
  1519. print '<tr><td>'.$langs->trans("OpenIDURL").'</td>';
  1520. print '<td>'.$object->openid.'</td>';
  1521. print "</tr>\n";
  1522. }
  1523. // Multicompany
  1524. if (isModEnabled('multicompany') && is_object($mc)) {
  1525. // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
  1526. if (!method_exists($mc, 'formObjectOptions')) {
  1527. if (isModEnabled('multicompany') && !getDolGlobalString('MULTICOMPANY_TRANSVERSE_MODE') && $conf->entity == 1 && $user->admin && !$user->entity) {
  1528. print '<tr><td>'.$langs->trans("Entity").'</td><td>';
  1529. if (empty($object->entity)) {
  1530. print $langs->trans("AllEntities");
  1531. } else {
  1532. $mc->getInfo($object->entity);
  1533. print $mc->label;
  1534. }
  1535. print "</td></tr>\n";
  1536. }
  1537. }
  1538. }
  1539. // Other attributes
  1540. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_view.tpl.php';
  1541. // Company / Contact
  1542. if (isModEnabled("societe")) {
  1543. print '<tr><td>'.$langs->trans("LinkToCompanyContact").'</td>';
  1544. print '<td>';
  1545. $s = '';
  1546. if (isset($object->socid) && $object->socid > 0) {
  1547. $societe = new Societe($db);
  1548. $societe->fetch($object->socid);
  1549. if ($societe->id > 0) {
  1550. $s .= $societe->getNomUrl(1, '');
  1551. }
  1552. } else {
  1553. $s .= '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ThisUserIsNot").'</span>';
  1554. }
  1555. if (!empty($object->contact_id)) {
  1556. $contact = new Contact($db);
  1557. $contact->fetch($object->contact_id);
  1558. if ($contact->id > 0) {
  1559. if ($object->socid > 0 && $s) {
  1560. $s .= ' / ';
  1561. } else {
  1562. $s .= '<br>';
  1563. }
  1564. $s .= $contact->getNomUrl(1, '');
  1565. }
  1566. }
  1567. print $s;
  1568. print '</td>';
  1569. print '</tr>'."\n";
  1570. }
  1571. // Module Adherent
  1572. if (isModEnabled('adherent')) {
  1573. $langs->load("members");
  1574. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  1575. print '<td>';
  1576. if ($object->fk_member) {
  1577. $adh = new Adherent($db);
  1578. $adh->fetch($object->fk_member);
  1579. $adh->ref = $adh->getFullname($langs); // Force to show login instead of id
  1580. print $adh->getNomUrl(-1);
  1581. } else {
  1582. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("UserNotLinkedToMember").'</span>';
  1583. }
  1584. print '</td>';
  1585. print '</tr>'."\n";
  1586. }
  1587. // Signature
  1588. print '<tr><td class="tdtop">'.$langs->trans('Signature').'</td><td class="wordbreak">';
  1589. print dol_htmlentitiesbr($object->signature);
  1590. print "</td></tr>\n";
  1591. print "</table>\n";
  1592. // Credentials section
  1593. print '<br>';
  1594. print '<div class="div-table-responsive-no-min">';
  1595. print '<table class="border tableforfield centpercent">';
  1596. print '<tr class="liste_titre"><td class="liste_titre">';
  1597. print img_picto('', 'security', 'class="paddingleft pictofixedwidth"').$langs->trans("Credentials");
  1598. print '</td>';
  1599. print '<td class="liste_titre"></td>';
  1600. print '</tr>';
  1601. // Date login validity
  1602. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("RangeOfLoginValidity").'</td>';
  1603. print '<td>';
  1604. if ($object->datestartvalidity) {
  1605. print '<span class="opacitymedium">'.$langs->trans("FromDate").'</span> ';
  1606. print dol_print_date($object->datestartvalidity, 'day');
  1607. }
  1608. if ($object->dateendvalidity) {
  1609. print '<span class="opacitymedium"> - '.$langs->trans("To").'</span> ';
  1610. print dol_print_date($object->dateendvalidity, 'day');
  1611. }
  1612. print '</td>';
  1613. print "</tr>\n";
  1614. // Alternative email for OAUth2 login
  1615. if (!empty($object->email_oauth2) && preg_match('/googleoauth/', $dolibarr_main_authentication)) {
  1616. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("AlternativeEmailForOAuth2").'</td>';
  1617. print '<td>';
  1618. print dol_print_email($object->email_oauth2);
  1619. print '</td>';
  1620. print "</tr>\n";
  1621. }
  1622. // Password
  1623. $valuetoshow = '';
  1624. if (preg_match('/ldap/', $dolibarr_main_authentication)) {
  1625. if (!empty($object->ldap_sid)) {
  1626. if ($passDoNotExpire) {
  1627. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("LdapUacf_".$statutUACF);
  1628. } elseif ($userChangePassNextLogon) {
  1629. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').'<span class="warning">'.$langs->trans("UserMustChangePassNextLogon", $ldap->domainFQDN).'</span>';
  1630. } elseif ($userDisabled) {
  1631. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').'<span class="warning">'.$langs->trans("LdapUacf_".$statutUACF, $ldap->domainFQDN).'</span>';
  1632. } else {
  1633. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
  1634. }
  1635. } else {
  1636. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
  1637. }
  1638. }
  1639. if (preg_match('/http/', $dolibarr_main_authentication)) {
  1640. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("HTTPBasicPassword");
  1641. }
  1642. /*
  1643. if (preg_match('/dolibarr/', $dolibarr_main_authentication)) {
  1644. if ($object->pass) {
  1645. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
  1646. $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  1647. } else {
  1648. if ($user->admin && $user->id == $object->id) {
  1649. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
  1650. $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  1651. $valuetoshow .= '<!-- Crypted into '.$object->pass_indatabase_crypted.' -->';
  1652. } else {
  1653. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '');
  1654. $valuetoshow .= '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  1655. }
  1656. }
  1657. }
  1658. */
  1659. // Other form for user password
  1660. $parameters = array('valuetoshow' => $valuetoshow);
  1661. $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1662. if ($reshook > 0) {
  1663. $valuetoshow = $hookmanager->resPrint; // to replace
  1664. } else {
  1665. $valuetoshow .= $hookmanager->resPrint; // to add
  1666. }
  1667. if (dol_string_nohtmltag($valuetoshow)) { // If there is a real visible content to show
  1668. print '<tr class="nooddeven"><td class="titlefield">'.$langs->trans("Password").'</td>';
  1669. print '<td class="wordbreak">';
  1670. print $valuetoshow;
  1671. print "</td>";
  1672. print '</tr>'."\n";
  1673. }
  1674. // API key
  1675. if (isModEnabled('api') && ($user->id == $id || $user->admin || $user->hasRight("api", "apikey", "generate"))) {
  1676. print '<tr class="nooddeven"><td>'.$langs->trans("ApiKey").'</td>';
  1677. print '<td>';
  1678. if (!empty($object->api_key)) {
  1679. print '<span class="opacitymedium">';
  1680. print showValueWithClipboardCPButton($object->api_key, 1, $langs->trans("Hidden")); // TODO Add an option to also reveal the hash, not only copy paste
  1681. print '</span>';
  1682. }
  1683. print '</td></tr>';
  1684. }
  1685. print '<tr class="nooddeven"><td>'.$langs->trans("LastConnexion").'</td>';
  1686. print '<td>';
  1687. if ($object->datepreviouslogin) {
  1688. print dol_print_date($object->datepreviouslogin, "dayhour", "tzuserrel").' <span class="opacitymedium">('.$langs->trans("Previous").')</span>, ';
  1689. }
  1690. if ($object->datelastlogin) {
  1691. print dol_print_date($object->datelastlogin, "dayhour", "tzuserrel").' <span class="opacitymedium">('.$langs->trans("Currently").')</span>';
  1692. }
  1693. print '</td>';
  1694. print "</tr>\n";
  1695. print '</table>';
  1696. print '</div>';
  1697. print '</div>';
  1698. print '</div>';
  1699. print '<div class="clearboth"></div>';
  1700. print dol_get_fiche_end();
  1701. /*
  1702. * Buttons actions
  1703. */
  1704. print '<div class="tabsAction">';
  1705. $parameters = array();
  1706. $reshook = $hookmanager->executeHooks('addMoreActionsButtons', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1707. if (empty($reshook)) {
  1708. $params = array(
  1709. 'attr' => array(
  1710. 'title' => '',
  1711. 'class' => 'classfortooltip'
  1712. )
  1713. );
  1714. if (empty($user->socid)) {
  1715. $canSendMail = false;
  1716. if (!empty($object->email)) {
  1717. $langs->load("mails");
  1718. $canSendMail = true;
  1719. unset($params['attr']['title']);
  1720. } else {
  1721. $langs->load("mails");
  1722. $params['attr']['title'] = $langs->trans('NoEMail');
  1723. }
  1724. print dolGetButtonAction('', $langs->trans('SendMail'), 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=presend&mode=init#formmailbeforetitle', '', $canSendMail, $params);
  1725. }
  1726. if ($caneditfield && (!isModEnabled('multicompany') || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1727. if (getDolGlobalString('MAIN_ONLY_LOGIN_ALLOWED')) {
  1728. $params['attr']['title'] = $langs->trans('DisabledInMonoUserMode');
  1729. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
  1730. } else {
  1731. unset($params['attr']['title']);
  1732. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit&token='.newToken(), '', true, $params);
  1733. }
  1734. } elseif ($caneditpasswordandsee && !$object->ldap_sid &&
  1735. (!isModEnabled('multicompany') || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1736. unset($params['attr']['title']);
  1737. print dolGetButtonAction($langs->trans('Modify'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit', '', true, $params);
  1738. }
  1739. // If we have a password generator engine enabled
  1740. $params = array(
  1741. 'attr' => array(
  1742. 'title' => '',
  1743. 'class' => 'classfortooltip'
  1744. )
  1745. );
  1746. if (getDolGlobalString('USER_PASSWORD_GENERATED') != 'none') {
  1747. if ($object->status == $object::STATUS_DISABLED) {
  1748. $params['attr']['title'] = $langs->trans('UserDisabled');
  1749. print dolGetButtonAction($langs->trans('ReinitPassword'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
  1750. } elseif (($user->id != $id && $caneditpasswordandsee) && $object->login && !$object->ldap_sid &&
  1751. ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1752. unset($params['attr']['title']);
  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. unset($params['attr']['title']);
  1762. print dolGetButtonAction($langs->trans('SendNewPassword'), '', 'default', $_SERVER['PHP_SELF'].'?id='.$object->id.'&action=passwordsend&token='.newToken(), '', true, $params);
  1763. } else {
  1764. $params['attr']['title'] = $langs->trans('NoEMail');
  1765. print dolGetButtonAction($langs->trans('SendNewPassword'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
  1766. }
  1767. }
  1768. }
  1769. if ($user->id != $id && $candisableuser && $object->statut == 0 &&
  1770. ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1771. unset($params['attr']['title']);
  1772. print dolGetButtonAction($langs->trans('Reactivate'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=enable&token='.newToken(), '', true, $params);
  1773. }
  1774. // Disable user
  1775. if ($user->id != $id && $candisableuser && $object->statut == 1 &&
  1776. ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1777. unset($params['attr']['title']);
  1778. print dolGetButtonAction($langs->trans('DisableUser'), '', 'default', $_SERVER['PHP_SELF'] . '?id=' . $object->id . '&action=disable&token='.newToken(), '', true, $params);
  1779. } else {
  1780. if ($user->id == $id) {
  1781. $params['attr']['title'] = $langs->trans('CantDisableYourself');
  1782. print dolGetButtonAction($langs->trans('DisableUser'), '', 'default', $_SERVER['PHP_SELF'].'#', '', false, $params);
  1783. }
  1784. }
  1785. // Delete
  1786. if ($user->id != $id && $candisableuser &&
  1787. ((!isModEnabled('multicompany') && $object->entity == $user->entity) || !$user->entity || ($object->entity == $conf->entity) || ($conf->global->MULTICOMPANY_TRANSVERSE_MODE && $object->entity == 1))) {
  1788. if ($user->admin || !$object->admin) { // If user edited is admin, delete is possible on for an admin
  1789. unset($params['attr']['title']);
  1790. print dolGetButtonAction($langs->trans('DeleteUser'), '', 'default', $_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id, '', true, $params);
  1791. } else {
  1792. $params['attr']['title'] = $langs->trans('MustBeAdminToDeleteOtherAdmin');
  1793. print dolGetButtonAction($langs->trans('DeleteUser'), '', 'default', $_SERVER['PHP_SELF'].'?action=delete&token='.newToken().'&id='.$object->id, '', false, $params);
  1794. }
  1795. }
  1796. }
  1797. print "</div>\n";
  1798. // Select mail models is same action as presend
  1799. if (GETPOST('modelselected')) {
  1800. $action = 'presend';
  1801. }
  1802. // Presend form
  1803. $modelmail = 'user';
  1804. $defaulttopic = 'Information';
  1805. $diroutput = $conf->user->dir_output;
  1806. $trackid = 'use'.$object->id;
  1807. include DOL_DOCUMENT_ROOT.'/core/tpl/card_presend.tpl.php';
  1808. if ($action != 'presend' && $action != 'send') {
  1809. /*
  1810. * List of groups of user
  1811. */
  1812. if ($canreadgroup) {
  1813. print '<!-- Group section -->'."\n";
  1814. print load_fiche_titre($langs->trans("ListOfGroupsForUser"), '', '');
  1815. // On selectionne les groupes auquel fait parti le user
  1816. $exclude = array();
  1817. $usergroup = new UserGroup($db);
  1818. $groupslist = $usergroup->listGroupsForUser($object->id, false);
  1819. if (!empty($groupslist)) {
  1820. foreach ($groupslist as $groupforuser) {
  1821. $exclude[] = $groupforuser->id;
  1822. }
  1823. }
  1824. // Other form for add user to group
  1825. $parameters = array('caneditgroup' => $caneditgroup, 'groupslist' => $groupslist, 'exclude' => $exclude);
  1826. $reshook = $hookmanager->executeHooks('formAddUserToGroup', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1827. print $hookmanager->resPrint;
  1828. if (empty($reshook)) {
  1829. if ($caneditgroup) {
  1830. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'."\n";
  1831. print '<input type="hidden" name="token" value="'.newToken().'" />';
  1832. print '<input type="hidden" name="action" value="addgroup" />';
  1833. print '<input type="hidden" name="page_y" value="" />';
  1834. }
  1835. print '<!-- List of groups of the user -->'."\n";
  1836. print '<table class="noborder centpercent">'."\n";
  1837. print '<tr class="liste_titre"><th class="liste_titre">'.$langs->trans("Groups").'</th>'."\n";
  1838. print '<th class="liste_titre right">';
  1839. if ($caneditgroup) {
  1840. print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity, false, 'maxwidth150');
  1841. print ' &nbsp; ';
  1842. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1843. print '<input type="submit" class="button buttongen button-add reposition" value="'.$langs->trans("Add").'" />';
  1844. }
  1845. print '</th></tr>'."\n";
  1846. // List of groups of user
  1847. if (!empty($groupslist)) {
  1848. foreach ($groupslist as $group) {
  1849. print '<tr class="oddeven">';
  1850. print '<td class="tdoverflowmax150">';
  1851. if ($caneditgroup) {
  1852. print $group->getNomUrl(1);
  1853. } else {
  1854. print img_object($langs->trans("ShowGroup"), "group").' '.$group->name;
  1855. }
  1856. print '</td>';
  1857. print '<td class="right">';
  1858. if ($caneditgroup) {
  1859. print '<a class="reposition" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&action=removegroup&token='.newToken().'&group='.((int) $group->id).'">';
  1860. print img_picto($langs->trans("RemoveFromGroup"), 'unlink');
  1861. print '</a>';
  1862. } else {
  1863. print "&nbsp;";
  1864. }
  1865. print "</td></tr>\n";
  1866. }
  1867. } else {
  1868. print '<tr class="oddeven"><td colspan="3"><span class="opacitymedium">'.$langs->trans("None").'</span></td></tr>';
  1869. }
  1870. print "</table>";
  1871. if ($caneditgroup) {
  1872. print '</form>';
  1873. }
  1874. print "<br>";
  1875. }
  1876. }
  1877. }
  1878. }
  1879. /*
  1880. * Edit mode
  1881. */
  1882. if ($action == 'edit' && ($canedituser || $caneditpasswordandsee)) {
  1883. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="updateuser" enctype="multipart/form-data">';
  1884. print '<input type="hidden" name="token" value="'.newToken().'">';
  1885. print '<input type="hidden" name="action" value="update">';
  1886. print '<input type="hidden" name="entity" value="'.$object->entity.'">';
  1887. print dol_get_fiche_head($head, 'user', $title, 0, 'user');
  1888. print '<table class="border centpercent">';
  1889. // Ref/ID
  1890. if (getDolGlobalString('MAIN_SHOW_TECHNICAL_ID')) {
  1891. print '<tr><td class="titlefieldcreate">'.$langs->trans("Ref").'</td>';
  1892. print '<td>';
  1893. print $object->id;
  1894. print '</td>';
  1895. print '</tr>';
  1896. }
  1897. // Civility
  1898. print '<tr><td class="titlefieldcreate"><label for="civility_code">'.$langs->trans("UserTitle").'</label></td><td>';
  1899. if ($caneditfield && !$object->ldap_sid) {
  1900. print $formcompany->select_civility(GETPOSTISSET("civility_code") ? GETPOST("civility_code", 'aZ09') : $object->civility_code, 'civility_code');
  1901. } elseif ($object->civility_code) {
  1902. print $langs->trans("Civility".$object->civility_code);
  1903. }
  1904. print '</td></tr>';
  1905. // Lastname
  1906. print "<tr>";
  1907. print '<td class="titlefieldcreate fieldrequired">'.$langs->trans("Lastname").'</td>';
  1908. print '<td>';
  1909. if ($caneditfield && !$object->ldap_sid) {
  1910. print '<input class="minwidth100" type="text" class="flat" name="lastname" value="'.$object->lastname.'">';
  1911. } else {
  1912. print '<input type="hidden" name="lastname" value="'.$object->lastname.'">';
  1913. print $object->lastname;
  1914. }
  1915. print '</td>';
  1916. print '</tr>';
  1917. // Firstname
  1918. print '<tr><td>'.$langs->trans("Firstname").'</td>';
  1919. print '<td>';
  1920. if ($caneditfield && !$object->ldap_sid) {
  1921. print '<input class="minwidth100" type="text" class="flat" name="firstname" value="'.$object->firstname.'">';
  1922. } else {
  1923. print '<input type="hidden" name="firstname" value="'.$object->firstname.'">';
  1924. print $object->firstname;
  1925. }
  1926. print '</td></tr>';
  1927. // Login
  1928. print "<tr>".'<td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
  1929. print '<td>';
  1930. if ($user->admin && !$object->ldap_sid) {
  1931. print '<input maxlength="50" type="text" class="flat" name="login" value="'.$object->login.'">';
  1932. } else {
  1933. print '<input type="hidden" name="login" value="'.$object->login.'">';
  1934. print $object->login;
  1935. }
  1936. print '</td>';
  1937. print '</tr>';
  1938. // Administrator
  1939. print '<tr><td>'.$form->textwithpicto($langs->trans("Administrator"), $langs->trans("AdministratorDesc")).'</td>';
  1940. if ($object->socid > 0) {
  1941. $langs->load("admin");
  1942. print '<td>';
  1943. print '<input type="hidden" name="admin" value="'.$object->admin.'">'.yn($object->admin);
  1944. print ' <span class="opacitymedium">('.$langs->trans("ExternalUser").')</span>';
  1945. print '</td></tr>';
  1946. } else {
  1947. print '<td>';
  1948. $nbAdmin = $user->getNbOfUsers('active', '', 1);
  1949. $nbSuperAdmin = $user->getNbOfUsers('active', 'superadmin', 1);
  1950. //var_dump($nbAdmin);
  1951. //var_dump($nbSuperAdmin);
  1952. if ($user->admin // Need to be admin to allow downgrade of an admin
  1953. && ($user->id != $object->id) // Don't downgrade ourself
  1954. && (
  1955. (!isModEnabled('multicompany') && $nbAdmin >= 1)
  1956. || (isModEnabled('multicompany') && (($object->entity > 0 || ($user->entity == 0 && $object->entity == 0)) || $nbSuperAdmin > 1)) // Don't downgrade a superadmin if alone
  1957. )
  1958. ) {
  1959. print $form->selectyesno('admin', $object->admin, 1, false, 0, 1);
  1960. if (isModEnabled('multicompany') && !$user->entity) {
  1961. if ($conf->use_javascript_ajax) {
  1962. print '<script type="text/javascript">
  1963. $(function() {
  1964. var admin = $("select[name=admin]").val();
  1965. if (admin == 0) {
  1966. $("input[name=superadmin]")
  1967. .prop("disabled", true)
  1968. .prop("checked", false);
  1969. }
  1970. if ($("input[name=superadmin]").is(":checked")) {
  1971. $("select[name=entity]")
  1972. .prop("disabled", true);
  1973. }
  1974. $("select[name=admin]").change(function() {
  1975. if ( $(this).val() == 0 ) {
  1976. $("input[name=superadmin]")
  1977. .prop("disabled", true)
  1978. .prop("checked", false);
  1979. $("select[name=entity]")
  1980. .prop("disabled", false);
  1981. } else {
  1982. $("input[name=superadmin]")
  1983. .prop("disabled", false);
  1984. }
  1985. });
  1986. $("input[name=superadmin]").change(function() {
  1987. if ( $(this).is(":checked")) {
  1988. $("select[name=entity]")
  1989. .prop("disabled", true);
  1990. } else {
  1991. $("select[name=entity]")
  1992. .prop("disabled", false);
  1993. }
  1994. });
  1995. });
  1996. </script>';
  1997. }
  1998. $checked = (($object->admin && !$object->entity) ? ' checked' : '');
  1999. print '<input type="checkbox" name="superadmin" id="superadmin" value="1"'.$checked.' /> <label for="superadmin">'.$langs->trans("SuperAdministrator").'</span>';
  2000. }
  2001. } else {
  2002. $yn = yn($object->admin);
  2003. print '<input type="hidden" name="admin" value="'.$object->admin.'">';
  2004. print '<input type="hidden" name="superadmin" value="'.(empty($object->entity) ? 1 : 0).'">';
  2005. if (isModEnabled('multicompany') && empty($object->entity)) {
  2006. print $form->textwithpicto($yn, $langs->trans("DontDowngradeSuperAdmin"), 1, 'warning');
  2007. } else {
  2008. print $yn;
  2009. }
  2010. }
  2011. print '</td></tr>';
  2012. }
  2013. // Gender
  2014. print '<tr><td>'.$langs->trans("Gender").'</td>';
  2015. print '<td>';
  2016. $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
  2017. if ($caneditfield) {
  2018. print $form->selectarray('gender', $arraygender, GETPOSTISSET('gender') ? GETPOST('gender') : $object->gender, 1);
  2019. } else {
  2020. print $arraygender[$object->gender];
  2021. }
  2022. print '</td></tr>';
  2023. // Employee
  2024. print '<tr>';
  2025. print '<td>'.$form->editfieldkey('Employee', 'employee', '', $object, 0).'</td><td>';
  2026. if ($caneditfield) {
  2027. print '<input type="checkbox" name="employee" value="1"'.($object->employee ? ' checked="checked"' : '').'>';
  2028. //print $form->selectyesno("employee", $object->employee, 1);
  2029. } else {
  2030. print '<input type="checkbox" name="employee" disabled value="1"'.($object->employee ? ' checked="checked"' : '').'>';
  2031. /*if ($object->employee) {
  2032. print $langs->trans("Yes");
  2033. } else {
  2034. print $langs->trans("No");
  2035. }*/
  2036. }
  2037. print '</td></tr>';
  2038. // Hierarchy
  2039. print '<tr><td class="titlefieldcreate">'.$langs->trans("HierarchicalResponsible").'</td>';
  2040. print '<td>';
  2041. if ($caneditfield) {
  2042. 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');
  2043. } else {
  2044. print '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
  2045. $huser = new User($db);
  2046. $huser->fetch($object->fk_user);
  2047. print $huser->getNomUrl(-1);
  2048. }
  2049. print '</td>';
  2050. print "</tr>\n";
  2051. // Expense report validator
  2052. if (isModEnabled('expensereport')) {
  2053. print '<tr><td class="titlefieldcreate">';
  2054. $text = $langs->trans("ForceUserExpenseValidator");
  2055. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  2056. print '</td>';
  2057. print '<td>';
  2058. if ($caneditfield) {
  2059. 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');
  2060. } else {
  2061. print '<input type="hidden" name="fk_user_expense_validator" value="'.$object->fk_user_expense_validator.'">';
  2062. $evuser = new User($db);
  2063. $evuser->fetch($object->fk_user_expense_validator);
  2064. print $evuser->getNomUrl(-1);
  2065. }
  2066. print '</td>';
  2067. print "</tr>\n";
  2068. }
  2069. // Holiday request validator
  2070. if (isModEnabled('holiday')) {
  2071. print '<tr><td class="titlefieldcreate">';
  2072. $text = $langs->trans("ForceUserHolidayValidator");
  2073. print $form->textwithpicto($text, $langs->trans("ValidatorIsSupervisorByDefault"), 1, 'help');
  2074. print '</td>';
  2075. print '<td>';
  2076. if ($caneditfield) {
  2077. 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');
  2078. } else {
  2079. print '<input type="hidden" name="fk_user_holiday_validator" value="'.$object->fk_user_holiday_validator.'">';
  2080. $hvuser = new User($db);
  2081. $hvuser->fetch($object->fk_user_holiday_validator);
  2082. print $hvuser->getNomUrl(-1);
  2083. }
  2084. print '</td>';
  2085. print "</tr>\n";
  2086. }
  2087. // External user ?
  2088. print '<tr><td>'.$langs->trans("ExternalUser").' ?</td>';
  2089. print '<td>';
  2090. if ($user->id == $object->id || !$user->admin) {
  2091. // Read mode
  2092. $type = $langs->trans("Internal");
  2093. if ($object->socid) {
  2094. $type = $langs->trans("External");
  2095. }
  2096. print $form->textwithpicto($type, $langs->trans("InternalExternalDesc"));
  2097. if ($object->ldap_sid) {
  2098. print ' ('.$langs->trans("DomainUser").')';
  2099. }
  2100. } else {
  2101. // Select mode
  2102. $type = 0;
  2103. if ($object->contact_id) {
  2104. $type = $object->contact_id;
  2105. }
  2106. if ($object->socid > 0 && !($object->contact_id > 0)) { // external user but no link to a contact
  2107. print img_picto('', 'company').$form->select_company($object->socid, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300');
  2108. print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
  2109. if ($object->ldap_sid) {
  2110. print ' ('.$langs->trans("DomainUser").')';
  2111. }
  2112. } elseif ($object->socid > 0 && $object->contact_id > 0) { // external user with a link to a contact
  2113. print img_picto('', 'company').$form->select_company($object->socid, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
  2114. print img_picto('', 'contact').$form->selectcontacts(0, $object->contact_id, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
  2115. if ($object->ldap_sid) {
  2116. print ' ('.$langs->trans("DomainUser").')';
  2117. }
  2118. } elseif (!($object->socid > 0) && $object->contact_id > 0) { // internal user with a link to a contact
  2119. print img_picto('', 'company').$form->select_company(0, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
  2120. print img_picto('', 'contact').$form->selectcontacts(0, $object->contact_id, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
  2121. if ($object->ldap_sid) {
  2122. print ' ('.$langs->trans("DomainUser").')';
  2123. }
  2124. } else { // $object->socid is not > 0 here
  2125. print img_picto('', 'company').$form->select_company(0, 'socid', '', '&nbsp;', 0, 0, null, 0, 'maxwidth300'); // We keep thirdparty empty, contact is already set
  2126. print img_picto('', 'contact').$form->selectcontacts(0, 0, 'contactid', 1, '', '', 1, 'maxwidth300', false, 1);
  2127. }
  2128. }
  2129. print '</td></tr>';
  2130. print '</table>';
  2131. print '<hr>';
  2132. print '<table class="border centpercent">';
  2133. // Date access validity
  2134. print '<tr><td>'.$langs->trans("RangeOfLoginValidity").'</td>';
  2135. print '<td>';
  2136. if ($caneditfield) {
  2137. print $form->selectDate($datestartvalidity ? $datestartvalidity : $object->datestartvalidity, 'datestartvalidity', 0, 0, 1, 'formdatestartvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("from"));
  2138. } else {
  2139. print dol_print_date($object->datestartvalidity, 'day');
  2140. }
  2141. print ' &nbsp; ';
  2142. if ($caneditfield) {
  2143. print $form->selectDate($dateendvalidity ? $dateendvalidity : $object->dateendvalidity, 'dateendvalidity', 0, 0, 1, 'formdateendvalidity', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  2144. } else {
  2145. print dol_print_date($object->dateendvalidity, 'day');
  2146. }
  2147. print '</td>';
  2148. print "</tr>\n";
  2149. // Pass
  2150. print '<tr><td class="titlefieldcreate">'.$langs->trans("Password").'</td>';
  2151. print '<td>';
  2152. $valuetoshow = '';
  2153. if (preg_match('/ldap/', $dolibarr_main_authentication)) {
  2154. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$langs->trans("PasswordOfUserInLDAP");
  2155. }
  2156. if (preg_match('/http/', $dolibarr_main_authentication)) {
  2157. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').$form->textwithpicto($text, $langs->trans("DolibarrInHttpAuthenticationSoPasswordUseless", $dolibarr_main_authentication), 1, 'warning');
  2158. }
  2159. if (preg_match('/dolibarr/', $dolibarr_main_authentication) || preg_match('/forceuser/', $dolibarr_main_authentication)) {
  2160. if ($caneditpasswordandsee) {
  2161. $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">';
  2162. if (!empty($conf->use_javascript_ajax)) {
  2163. $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').'"');
  2164. }
  2165. } else {
  2166. $valuetoshow .= ($valuetoshow ? (' '.$langs->trans("or").' ') : '').preg_replace('/./i', '*', $object->pass);
  2167. }
  2168. }
  2169. // Other form for user password
  2170. $parameters = array('valuetoshow' => $valuetoshow, 'caneditpasswordandsee' => $caneditpasswordandsee, 'caneditpasswordandsend' => $caneditpasswordandsend);
  2171. $reshook = $hookmanager->executeHooks('printUserPasswordField', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2172. if ($reshook > 0) {
  2173. $valuetoshow = $hookmanager->resPrint; // to replace
  2174. } else {
  2175. $valuetoshow .= $hookmanager->resPrint; // to add
  2176. }
  2177. print $valuetoshow;
  2178. print "</td></tr>\n";
  2179. // API key
  2180. if (isModEnabled('api')) {
  2181. print '<tr><td>'.$langs->trans("ApiKey").'</td>';
  2182. print '<td>';
  2183. if ($caneditpasswordandsee || $user->hasRight("api", "apikey", "generate")) {
  2184. print '<input class="minwidth300 maxwidth400 widthcentpercentminusx" minlength="12" maxlength="128" type="text" id="api_key" name="api_key" value="'.$object->api_key.'" autocomplete="off">';
  2185. if (!empty($conf->use_javascript_ajax)) {
  2186. print img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject paddingleft"');
  2187. }
  2188. }
  2189. print '</td></tr>';
  2190. }
  2191. // OpenID url
  2192. if (isset($conf->file->main_authentication) && preg_match('/openid/', $conf->file->main_authentication) && getDolGlobalString('MAIN_OPENIDURL_PERUSER')) {
  2193. print "<tr>".'<td>'.$langs->trans("OpenIDURL").'</td>';
  2194. print '<td>';
  2195. if ($caneditfield) {
  2196. print '<input class="minwidth100" type="url" name="openid" class="flat" value="'.$object->openid.'">';
  2197. } else {
  2198. print '<input type="hidden" name="openid" value="'.$object->openid.'">';
  2199. print $object->openid;
  2200. }
  2201. print '</td></tr>';
  2202. }
  2203. print '</table><hr><table class="border centpercent">';
  2204. // Address
  2205. print '<tr><td class="tdtop titlefieldcreate">'.$form->editfieldkey('Address', 'address', '', $object, 0).'</td>';
  2206. print '<td>';
  2207. if ($caneditfield) {
  2208. print '<textarea name="address" id="address" class="quatrevingtpercent" rows="3" wrap="soft">';
  2209. }
  2210. print dol_escape_htmltag(GETPOSTISSET('address') ? GETPOST('address') : $object->address, 0, 1);
  2211. if ($caneditfield) {
  2212. print '</textarea>';
  2213. }
  2214. print '</td></tr>';
  2215. // Zip
  2216. print '<tr><td>'.$form->editfieldkey('Zip', 'zipcode', '', $object, 0).'</td><td>';
  2217. if ($caneditfield) {
  2218. print $formcompany->select_ziptown((GETPOSTISSET('zipcode') ? GETPOST('zipcode') : $object->zip), 'zipcode', array('town', 'selectcountry_id', 'state_id'), 6);
  2219. } else {
  2220. print $object->zip;
  2221. }
  2222. print '</td></tr>';
  2223. // Town
  2224. print '<tr><td>'.$form->editfieldkey('Town', 'town', '', $object, 0).'</td><td>';
  2225. if ($caneditfield) {
  2226. print $formcompany->select_ziptown((GETPOSTISSET('town') ? GETPOST('town') : $object->town), 'town', array('zipcode', 'selectcountry_id', 'state_id'));
  2227. } else {
  2228. print $object->town;
  2229. }
  2230. print '</td></tr>';
  2231. // Country
  2232. print '<tr><td>'.$form->editfieldkey('Country', 'selectcounty_id', '', $object, 0).'</td><td>';
  2233. print img_picto('', 'country', 'class="pictofixedwidth"');
  2234. if ($caneditfield) {
  2235. print $form->select_country((GETPOST('country_id') != '' ? GETPOST('country_id') : $object->country_id), 'country_id');
  2236. if ($user->admin) {
  2237. print info_admin($langs->trans("YouCanChangeValuesForThisListFromDictionarySetup"), 1);
  2238. }
  2239. } else {
  2240. $countrylabel = getCountry($object->country_id, '0');
  2241. print $countrylabel;
  2242. }
  2243. print '</td></tr>';
  2244. // State
  2245. if (!getDolGlobalString('USER_DISABLE_STATE')) {
  2246. print '<tr><td class="tdoverflow">'.$form->editfieldkey('State', 'state_id', '', $object, 0).'</td><td>';
  2247. if ($caneditfield) {
  2248. print img_picto('', 'state', 'class="pictofixedwidth"');
  2249. print $formcompany->select_state_ajax('country_id', $object->state_id, $object->country_id, 'state_id');
  2250. } else {
  2251. print $object->state;
  2252. }
  2253. print '</td></tr>';
  2254. }
  2255. // Tel pro
  2256. print "<tr>".'<td>'.$langs->trans("PhonePro").'</td>';
  2257. print '<td>';
  2258. print img_picto('', 'phoning', 'class="pictofixedwidth"');
  2259. if ($caneditfield && empty($object->ldap_sid)) {
  2260. print '<input type="text" name="office_phone" class="flat maxwidth200" value="'.$object->office_phone.'">';
  2261. } else {
  2262. print '<input type="hidden" name="office_phone" value="'.$object->office_phone.'">';
  2263. print $object->office_phone;
  2264. }
  2265. print '</td></tr>';
  2266. // Tel mobile
  2267. print "<tr>".'<td>'.$langs->trans("PhoneMobile").'</td>';
  2268. print '<td>';
  2269. print img_picto('', 'phoning_mobile', 'class="pictofixedwidth"');
  2270. if ($caneditfield && empty($object->ldap_sid)) {
  2271. print '<input type="text" name="user_mobile" class="flat maxwidth200" value="'.$object->user_mobile.'">';
  2272. } else {
  2273. print '<input type="hidden" name="user_mobile" value="'.$object->user_mobile.'">';
  2274. print $object->user_mobile;
  2275. }
  2276. print '</td></tr>';
  2277. // Fax
  2278. print "<tr>".'<td>'.$langs->trans("Fax").'</td>';
  2279. print '<td>';
  2280. print img_picto('', 'phoning_fax', 'class="pictofixedwidth"');
  2281. if ($caneditfield && empty($object->ldap_sid)) {
  2282. print '<input type="text" name="office_fax" class="flat maxwidth200" value="'.$object->office_fax.'">';
  2283. } else {
  2284. print '<input type="hidden" name="office_fax" value="'.$object->office_fax.'">';
  2285. print $object->office_fax;
  2286. }
  2287. print '</td></tr>';
  2288. // EMail
  2289. print "<tr>".'<td'.(getDolGlobalString('USER_MAIL_REQUIRED') ? ' class="fieldrequired"' : '').'>'.$langs->trans("EMail").'</td>';
  2290. print '<td>';
  2291. print img_picto('', 'object_email', 'class="pictofixedwidth"');
  2292. if ($caneditfield && empty($object->ldap_sid)) {
  2293. print '<input class="minwidth100 maxwidth500 widthcentpercentminusx" type="text" name="email" class="flat" value="'.$object->email.'">';
  2294. } else {
  2295. print '<input type="hidden" name="email" value="'.$object->email.'">';
  2296. print $object->email;
  2297. }
  2298. print '</td></tr>';
  2299. if (isModEnabled('socialnetworks')) {
  2300. foreach ($socialnetworks as $key => $value) {
  2301. if ($value['active']) {
  2302. print '<tr><td>'.$langs->trans($value['label']).'</td>';
  2303. print '<td>';
  2304. if (!empty($value['icon'])) {
  2305. print '<span class="fab '.$value['icon'].' pictofixedwidth"></span>';
  2306. }
  2307. if ($caneditfield && empty($object->ldap_sid)) {
  2308. print '<input type="text" name="'.$key.'" class="flat maxwidth200" value="'.(isset($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : '').'">';
  2309. } else {
  2310. print '<input type="hidden" name="'.$key.'" value="'.$object->socialnetworks[$key].'">';
  2311. print $object->socialnetworks[$key];
  2312. }
  2313. print '</td></tr>';
  2314. } else {
  2315. // if social network is not active but value exist we do not want to loose it
  2316. print '<input type="hidden" name="'.$key.'" value="'.(isset($object->socialnetworks[$key]) ? $object->socialnetworks[$key] : '').'">';
  2317. }
  2318. }
  2319. }
  2320. print '</table><hr><table class="border centpercent">';
  2321. // Default warehouse
  2322. if (isModEnabled('stock') && getDolGlobalString('MAIN_DEFAULT_WAREHOUSE_USER')) {
  2323. print '<tr><td class="titlefield">'.$langs->trans("DefaultWarehouse").'</td><td>';
  2324. print $formproduct->selectWarehouses($object->fk_warehouse, 'fk_warehouse', 'warehouseopen', 1);
  2325. 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>';
  2326. print '</td></tr>';
  2327. }
  2328. // Accountancy code
  2329. if (isModEnabled('accounting')) {
  2330. print "<tr>";
  2331. print '<td class="titlefieldcreate">'.$langs->trans("AccountancyCode").'</td>';
  2332. print '<td>';
  2333. if ($caneditfield) {
  2334. print '<input type="text" class="flat maxwidth300" name="accountancy_code" value="'.$object->accountancy_code.'">';
  2335. } else {
  2336. print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
  2337. print $object->accountancy_code;
  2338. }
  2339. print '</td>';
  2340. print "</tr>";
  2341. }
  2342. // User color
  2343. if (isModEnabled('agenda')) {
  2344. print '<tr><td class="titlefieldcreate">'.$langs->trans("ColorUser").'</td>';
  2345. print '<td>';
  2346. if ($caneditfield) {
  2347. print $formother->selectColor(GETPOSTISSET('color') ? GETPOST('color', 'alphanohtml') : $object->color, 'color', null, 1, '', 'hideifnotset');
  2348. } else {
  2349. print $formother->showColor($object->color, '');
  2350. }
  2351. print '</td></tr>';
  2352. }
  2353. // Photo
  2354. print '<tr>';
  2355. print '<td class="titlefieldcreate">'.$langs->trans("Photo").'</td>';
  2356. print '<td>';
  2357. print $form->showphoto('userphoto', $object, 60, 0, $caneditfield, 'photowithmargin', 'small', 1, 0, 'user', 1);
  2358. print '</td>';
  2359. print '</tr>';
  2360. // Categories
  2361. if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
  2362. print '<tr><td>'.$form->editfieldkey('Categories', 'usercats', '', $object, 0).'</td>';
  2363. print '<td>';
  2364. print img_picto('', 'category', 'class="pictofixedwidth"');
  2365. $cate_arbo = $form->select_all_categories(Categorie::TYPE_USER, null, null, null, null, 1);
  2366. $c = new Categorie($db);
  2367. $cats = $c->containing($object->id, Categorie::TYPE_USER);
  2368. $arrayselected = array();
  2369. foreach ($cats as $cat) {
  2370. $arrayselected[] = $cat->id;
  2371. }
  2372. if ($caneditfield) {
  2373. print $form->multiselectarray('usercats', $cate_arbo, $arrayselected, '', 0, '', 0, '90%');
  2374. } else {
  2375. print $form->showCategories($object->id, Categorie::TYPE_USER, 1);
  2376. }
  2377. print "</td></tr>";
  2378. }
  2379. // Default language
  2380. if (getDolGlobalInt('MAIN_MULTILANGS')) {
  2381. 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";
  2382. print img_picto('', 'language', 'class="pictofixedwidth"').$formadmin->select_language($object->lang, 'default_lang', 0, null, '1', 0, 0, 'widthcentpercentminusx maxwidth300');
  2383. print '</td>';
  2384. print '</tr>';
  2385. }
  2386. // Status
  2387. print '<tr><td>'.$langs->trans("Status").'</td>';
  2388. print '<td>';
  2389. print $object->getLibStatut(4);
  2390. print '</td></tr>';
  2391. // Company / Contact
  2392. if (isModEnabled("societe")) {
  2393. print '<tr><td>'.$langs->trans("LinkToCompanyContact").'</td>';
  2394. print '<td>';
  2395. if ($object->socid > 0) {
  2396. $societe = new Societe($db);
  2397. $societe->fetch($object->socid);
  2398. print $societe->getNomUrl(1, '');
  2399. if ($object->contact_id) {
  2400. $contact = new Contact($db);
  2401. $contact->fetch($object->contact_id);
  2402. 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>';
  2403. }
  2404. } else {
  2405. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("ThisUserIsNot").'</span>';
  2406. }
  2407. print ' <span class="opacitymedium hideonsmartphone">('.$langs->trans("UseTypeFieldToChange").')</span>';
  2408. print '</td>';
  2409. print "</tr>\n";
  2410. }
  2411. // Module Adherent
  2412. if (isModEnabled('adherent')) {
  2413. $langs->load("members");
  2414. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  2415. print '<td>';
  2416. if ($object->fk_member) {
  2417. $adh = new Adherent($db);
  2418. $adh->fetch($object->fk_member);
  2419. $adh->ref = $adh->login; // Force to show login instead of id
  2420. print $adh->getNomUrl(1);
  2421. } else {
  2422. print '<span class="opacitymedium hideonsmartphone">'.$langs->trans("UserNotLinkedToMember").'</span>';
  2423. }
  2424. print '</td>';
  2425. print "</tr>\n";
  2426. }
  2427. // Multicompany
  2428. // TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !!
  2429. if (isModEnabled('multicompany') && is_object($mc)) {
  2430. // This is now done with hook formObjectOptions. Keep this code for backward compatibility with old multicompany module
  2431. if (!method_exists($mc, 'formObjectOptions')) {
  2432. if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && !$user->entity) {
  2433. print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
  2434. print "<td>".$mc->select_entities($object->entity, 'entity', '', 0, 1, false, false, 1); // last parameter 1 means, show also a choice 0=>'all entities'
  2435. print "</td></tr>\n";
  2436. } else {
  2437. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  2438. }
  2439. }
  2440. }
  2441. // Other attributes
  2442. $parameters = array('colspan' => ' colspan="2"');
  2443. //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
  2444. $reshook = $hookmanager->executeHooks('formObjectOptions', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  2445. print $hookmanager->resPrint;
  2446. if (empty($reshook)) {
  2447. if ($caneditfield) {
  2448. print $object->showOptionals($extrafields, 'edit');
  2449. } else {
  2450. print $object->showOptionals($extrafields, 'view');
  2451. }
  2452. }
  2453. // Signature
  2454. print '<tr><td class="tdtop">'.$langs->trans("Signature").'</td>';
  2455. print '<td>';
  2456. if ($caneditfield) {
  2457. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  2458. $doleditor = new DolEditor('signature', $object->signature, '', 138, 'dolibarr_notes', 'In', false, $acceptlocallinktomedia, !getDolGlobalString('FCKEDITOR_ENABLE_USERSIGN') ? 0 : 1, ROWS_4, '90%');
  2459. print $doleditor->Create(1);
  2460. } else {
  2461. print dol_htmlentitiesbr($object->signature);
  2462. }
  2463. print '</td></tr>';
  2464. print '</table>';
  2465. print '<hr>';
  2466. print '<table class="border centpercent">';
  2467. // TODO Move this into tab RH (HierarchicalResponsible must be on both tab)
  2468. // Position/Job
  2469. print '<tr><td class="titlefieldcreate">'.$langs->trans("PostOrFunction").'</td>';
  2470. print '<td>';
  2471. if ($caneditfield) {
  2472. print '<input type="text" class="minwidth300 maxwidth500" name="job" value="'.dol_escape_htmltag($object->job).'">';
  2473. } else {
  2474. print '<input type="hidden" name="job" value="'.dol_escape_htmltag($object->job).'">';
  2475. print dol_escape_htmltag($object->job);
  2476. }
  2477. print '</td></tr>';
  2478. // Weeklyhours
  2479. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  2480. print '<td>';
  2481. if ($caneditfield) {
  2482. print '<input size="8" type="text" name="weeklyhours" value="'.price2num(GETPOST('weeklyhours') ? GETPOST('weeklyhours') : $object->weeklyhours).'">';
  2483. } else {
  2484. print price2num($object->weeklyhours);
  2485. }
  2486. print '</td>';
  2487. print "</tr>\n";
  2488. // Sensitive salary/value information
  2489. if ((empty($user->socid) && in_array($id, $childids)) // A user can always see salary/value information for its subordinates
  2490. || (isModEnabled('salaries') && $user->hasRight("salaries", "readall"))
  2491. || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
  2492. $langs->load("salaries");
  2493. // Salary
  2494. print '<tr><td>'.$langs->trans("Salary").'</td>';
  2495. print '<td>';
  2496. print img_picto('', 'salary', 'class="pictofixedwidth paddingright"').'<input size="8" type="text" name="salary" value="'.price2num(GETPOST('salary') ? GETPOST('salary') : $object->salary).'">';
  2497. print '</td>';
  2498. print "</tr>\n";
  2499. // THM
  2500. print '<tr><td>';
  2501. $text = $langs->trans("THM");
  2502. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  2503. print '</td>';
  2504. print '<td>';
  2505. if ($caneditfield) {
  2506. print '<input size="8" type="text" name="thm" value="'.price2num(GETPOST('thm') ? GETPOST('thm') : $object->thm).'">';
  2507. } else {
  2508. print($object->thm != '' ? price($object->thm, '', $langs, 1, -1, -1, $conf->currency) : '');
  2509. }
  2510. print '</td>';
  2511. print "</tr>\n";
  2512. // TJM
  2513. print '<tr><td>';
  2514. $text = $langs->trans("TJM");
  2515. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm');
  2516. print '</td>';
  2517. print '<td>';
  2518. if ($caneditfield) {
  2519. print '<input size="8" type="text" name="tjm" value="'.price2num(GETPOST('tjm') ? GETPOST('tjm') : $object->tjm).'">';
  2520. } else {
  2521. print($object->tjm != '' ? price($object->tjm, '', $langs, 1, -1, -1, $conf->currency) : '');
  2522. }
  2523. print '</td>';
  2524. print "</tr>\n";
  2525. }
  2526. // Date employment
  2527. print '<tr><td>'.$langs->trans("DateEmployment").'</td>';
  2528. print '<td>';
  2529. if ($caneditfield) {
  2530. print $form->selectDate($dateemployment ? $dateemployment : $object->dateemployment, 'dateemployment', 0, 0, 1, 'formdateemployment', 1, 1, 0, '', '', '', '', 1, '', $langs->trans("from"));
  2531. } else {
  2532. print dol_print_date($object->dateemployment, 'day');
  2533. }
  2534. if ($dateemployment && $dateemploymentend) {
  2535. print ' - ';
  2536. }
  2537. if ($caneditfield) {
  2538. print $form->selectDate($dateemploymentend ? $dateemploymentend : $object->dateemploymentend, 'dateemploymentend', 0, 0, 1, 'formdateemploymentend', 1, 0, 0, '', '', '', '', 1, '', $langs->trans("to"));
  2539. } else {
  2540. print dol_print_date($object->dateemploymentend, 'day');
  2541. }
  2542. print '</td>';
  2543. print "</tr>\n";
  2544. // Date birth
  2545. print '<tr><td>'.$langs->trans("DateOfBirth").'</td>';
  2546. print '<td>';
  2547. if ($caneditfield) {
  2548. echo $form->selectDate($dateofbirth ? $dateofbirth : $object->birth, 'dateofbirth', 0, 0, 1, 'updateuser', 1, 0, 0, '', '', '', '', 1, '', '', 'tzserver');
  2549. } else {
  2550. print dol_print_date($object->birth, 'day', 'tzserver');
  2551. }
  2552. print '</td>';
  2553. print "</tr>\n";
  2554. print '</table>';
  2555. print dol_get_fiche_end();
  2556. print '<div class="center">';
  2557. print '<input value="'.$langs->trans("Save").'" class="button button-save" type="submit" name="save">';
  2558. print '&nbsp; &nbsp; &nbsp;';
  2559. print '<input value="'.$langs->trans("Cancel").'" class="button button-cancel" type="submit" name="cancel">';
  2560. print '</div>';
  2561. print '</form>';
  2562. }
  2563. if ($action != 'edit' && $action != 'presend') {
  2564. print '<div class="fichecenter"><div class="fichehalfleft">';
  2565. // Generated documents
  2566. $filename = dol_sanitizeFileName($object->ref);
  2567. $filedir = $conf->user->dir_output."/".dol_sanitizeFileName($object->ref);
  2568. $urlsource = $_SERVER["PHP_SELF"]."?id=".$object->id;
  2569. $genallowed = $user->hasRight("user", "user", "read");
  2570. $delallowed = $user->hasRight("user", "user", "write");
  2571. 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);
  2572. $somethingshown = $formfile->numoffiles;
  2573. // Show links to link elements
  2574. $linktoelem = $form->showLinkToObjectBlock($object, null, null);
  2575. $somethingshown = $form->showLinkedObjectBlock($object, $linktoelem);
  2576. print '</div><div class="fichehalfright">';
  2577. // List of actions on element
  2578. include_once DOL_DOCUMENT_ROOT.'/core/class/html.formactions.class.php';
  2579. $formactions = new FormActions($db);
  2580. $somethingshown = $formactions->showactions($object, 'user', $socid, 1, 'listactions', 0, '', '', $object->id);
  2581. print '</div></div>';
  2582. }
  2583. if (isModEnabled('ldap') && !empty($object->ldap_sid)) {
  2584. $ldap->unbind();
  2585. }
  2586. }
  2587. }
  2588. // Add button to autosuggest a key
  2589. include_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  2590. print dolJSToSetRandomPassword('password', 'generate_password', 0);
  2591. if (isModEnabled('api')) {
  2592. print dolJSToSetRandomPassword('api_key', 'generate_api_key', 1);
  2593. }
  2594. // End of page
  2595. llxFooter();
  2596. $db->close();