card.php 109 KB

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