card.php 110 KB

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