card.php 115 KB

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