card.php 86 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270
  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-2015 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2004 Eric Seigne <eric.seigne@ryxeo.com>
  6. * Copyright (C) 2005-2015 Regis Houssin <regis.houssin@capnetworks.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 Juanjo Menent <jmenent@2byte.es>
  10. * Copyright (C) 2013 Florian Henry <florian.henry@open-concept.pro>
  11. * Copyright (C) 2013-2015 Alexandre Spangaro <aspangaro.dolibarr@gmail.com>
  12. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  13. * Copyright (C) 2015 Ari Elbaz (elarifr) <github@accedinfo.com>
  14. *
  15. * This program is free software; you can redistribute it and/or modify
  16. * it under the terms of the GNU General Public License as published by
  17. * the Free Software Foundation; either version 3 of the License, or
  18. * (at your option) any later version.
  19. *
  20. * This program is distributed in the hope that it will be useful,
  21. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  22. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  23. * GNU General Public License for more details.
  24. *
  25. * You should have received a copy of the GNU General Public License
  26. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  27. */
  28. /**
  29. * \file htdocs/user/card.php
  30. * \brief Tab of user card
  31. */
  32. require '../main.inc.php';
  33. require_once DOL_DOCUMENT_ROOT.'/user/class/user.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/user/class/usergroup.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/images.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/usergroups.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  40. if (! empty($conf->ldap->enabled)) require_once DOL_DOCUMENT_ROOT.'/core/class/ldap.class.php';
  41. if (! empty($conf->adherent->enabled)) require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  42. if (! empty($conf->multicompany->enabled)) dol_include_once('/multicompany/class/actions_multicompany.class.php');
  43. $id = GETPOST('id','int');
  44. $action = GETPOST('action','alpha');
  45. $confirm = GETPOST('confirm','alpha');
  46. $subaction = GETPOST('subaction','alpha');
  47. $group = GETPOST("group","int",3);
  48. // Define value to know what current user can do on users
  49. $canadduser=(! empty($user->admin) || $user->rights->user->user->creer);
  50. $canreaduser=(! empty($user->admin) || $user->rights->user->user->lire);
  51. $canedituser=(! empty($user->admin) || $user->rights->user->user->creer);
  52. $candisableuser=(! empty($user->admin) || $user->rights->user->user->supprimer);
  53. $canreadgroup=$canreaduser;
  54. $caneditgroup=$canedituser;
  55. if (! empty($conf->global->MAIN_USE_ADVANCED_PERMS))
  56. {
  57. $canreadgroup=(! empty($user->admin) || $user->rights->user->group_advance->read);
  58. $caneditgroup=(! empty($user->admin) || $user->rights->user->group_advance->write);
  59. }
  60. // Define value to know what current user can do on properties of edited user
  61. if ($id)
  62. {
  63. // $user est le user qui edite, $id est l'id de l'utilisateur edite
  64. $caneditfield=((($user->id == $id) && $user->rights->user->self->creer)
  65. || (($user->id != $id) && $user->rights->user->user->creer));
  66. $caneditpassword=((($user->id == $id) && $user->rights->user->self->password)
  67. || (($user->id != $id) && $user->rights->user->user->password));
  68. }
  69. // Security check
  70. $socid=0;
  71. if ($user->societe_id > 0) $socid = $user->societe_id;
  72. $feature2='user';
  73. if ($user->id == $id) { $feature2=''; $canreaduser=1; } // A user can always read its own card
  74. if (!$canreaduser) {
  75. $result = restrictedArea($user, 'user', $id, 'user&user', $feature2);
  76. }
  77. if ($user->id <> $id && ! $canreaduser) accessforbidden();
  78. $langs->load("users");
  79. $langs->load("companies");
  80. $langs->load("ldap");
  81. $langs->load("admin");
  82. $object = new User($db);
  83. $extrafields = new ExtraFields($db);
  84. // fetch optionals attributes and labels
  85. $extralabels=$extrafields->fetch_name_optionals_label($object->table_element);
  86. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  87. $hookmanager->initHooks(array('usercard','globalcard'));
  88. /**
  89. * Actions
  90. */
  91. if ($action == 'confirm_disable' && $confirm == "yes" && $candisableuser)
  92. {
  93. if ($id <> $user->id)
  94. {
  95. $object->fetch($id);
  96. $object->setstatus(0);
  97. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  98. exit;
  99. }
  100. }
  101. if ($action == 'confirm_enable' && $confirm == "yes" && $candisableuser)
  102. {
  103. $error = 0;
  104. if ($id <> $user->id)
  105. {
  106. $object->fetch($id);
  107. if (!empty($conf->file->main_limit_users))
  108. {
  109. $nb = $object->getNbOfUsers("active");
  110. if ($nb >= $conf->file->main_limit_users)
  111. {
  112. $error++;
  113. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  114. }
  115. }
  116. if (! $error)
  117. {
  118. $object->setstatus(1);
  119. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  120. exit;
  121. }
  122. }
  123. }
  124. if ($action == 'confirm_delete' && $confirm == "yes" && $candisableuser)
  125. {
  126. if ($id <> $user->id)
  127. {
  128. $object = new User($db);
  129. $object->id=$id;
  130. $result = $object->delete();
  131. if ($result < 0)
  132. {
  133. $langs->load("errors");
  134. setEventMessage($langs->trans("ErrorUserCannotBeDelete"), 'errors');
  135. }
  136. else
  137. {
  138. header("Location: index.php");
  139. exit;
  140. }
  141. }
  142. }
  143. // Action Add user
  144. if ($action == 'add' && $canadduser)
  145. {
  146. $error = 0;
  147. if (! $_POST["lastname"])
  148. {
  149. $error++;
  150. setEventMessage($langs->trans("NameNotDefined"), 'errors');
  151. $action="create"; // Go back to create page
  152. }
  153. if (! $_POST["login"])
  154. {
  155. $error++;
  156. setEventMessage($langs->trans("LoginNotDefined"), 'errors');
  157. $action="create"; // Go back to create page
  158. }
  159. if (! empty($conf->file->main_limit_users)) // If option to limit users is set
  160. {
  161. $nb = $object->getNbOfUsers("active");
  162. if ($nb >= $conf->file->main_limit_users)
  163. {
  164. $error++;
  165. setEventMessage($langs->trans("YourQuotaOfUsersIsReached"), 'errors');
  166. $action="create"; // Go back to create page
  167. }
  168. }
  169. if (!$error)
  170. {
  171. $object->lastname = GETPOST("lastname",'alpha');
  172. $object->firstname = GETPOST("firstname",'alpha');
  173. $object->login = GETPOST("login",'alpha');
  174. $object->api_key = GETPOST("api_key",'alpha');
  175. $object->gender = GETPOST("gender",'alpha');
  176. $object->admin = GETPOST("admin",'alpha');
  177. $object->office_phone = GETPOST("office_phone",'alpha');
  178. $object->office_fax = GETPOST("office_fax",'alpha');
  179. $object->user_mobile = GETPOST("user_mobile");
  180. $object->skype = GETPOST("skype");
  181. $object->email = GETPOST("email",'alpha');
  182. $object->job = GETPOST("job",'alpha');
  183. $object->signature = GETPOST("signature");
  184. $object->accountancy_code = GETPOST("accountancy_code");
  185. $object->note = GETPOST("note");
  186. $object->ldap_sid = GETPOST("ldap_sid");
  187. $object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0;
  188. $object->thm = GETPOST("thm")!=''?GETPOST("thm"):'';
  189. $object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):'';
  190. $object->salary = GETPOST("salary")!=''?GETPOST("salary"):'';
  191. $object->salaryextra = GETPOST("salaryextra")!=''?GETPOST("salaryextra"):'';
  192. $object->weeklyhours = GETPOST("weeklyhours")!=''?GETPOST("weeklyhours"):'';
  193. $object->color = GETPOST("color")!=''?GETPOST("color"):'';
  194. // Fill array 'array_options' with data from add form
  195. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  196. if ($ret < 0) $error++;
  197. // Set entity property
  198. $entity=GETPOST('entity','int');
  199. if (! empty($conf->multicompany->enabled))
  200. {
  201. if (! empty($_POST["superadmin"]))
  202. {
  203. $object->entity = 0;
  204. }
  205. else if ($conf->multicompany->transverse_mode)
  206. {
  207. $object->entity = 1; // all users are forced into master entity
  208. }
  209. else
  210. {
  211. $object->entity = ($entity == '' ? 1 : $entity);
  212. }
  213. }
  214. else
  215. {
  216. $object->entity = ($entity == '' ? 1 : $entity);
  217. /*if ($user->admin && $user->entity == 0 && GETPOST("admin",'alpha'))
  218. {
  219. }*/
  220. }
  221. $db->begin();
  222. $id = $object->create($user);
  223. if ($id > 0)
  224. {
  225. if (isset($_POST['password']) && trim($_POST['password']))
  226. {
  227. $object->setPassword($user,trim($_POST['password']));
  228. }
  229. $db->commit();
  230. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  231. exit;
  232. }
  233. else
  234. {
  235. $langs->load("errors");
  236. $db->rollback();
  237. if (is_array($object->errors) && count($object->errors)) setEventMessage($object->errors,'errors');
  238. else setEventMessage($object->error, 'errors');
  239. $action="create"; // Go back to create page
  240. }
  241. }
  242. }
  243. // Action add usergroup
  244. if (($action == 'addgroup' || $action == 'removegroup') && $caneditfield)
  245. {
  246. if ($group)
  247. {
  248. $editgroup = new UserGroup($db);
  249. $editgroup->fetch($group);
  250. $editgroup->oldcopy=dol_clone($editgroup);
  251. $object->fetch($id);
  252. if ($action == 'addgroup') $object->SetInGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity));
  253. if ($action == 'removegroup') $object->RemoveFromGroup($group,($conf->multicompany->transverse_mode?GETPOST("entity"):$editgroup->entity));
  254. if ($result > 0)
  255. {
  256. header("Location: ".$_SERVER['PHP_SELF'].'?id='.$id);
  257. exit;
  258. }
  259. else
  260. {
  261. setEventMessage($object->error, 'errors');
  262. }
  263. }
  264. }
  265. if ($action == 'update' && ! $_POST["cancel"])
  266. {
  267. require_once DOL_DOCUMENT_ROOT.'/core/lib/files.lib.php';
  268. if ($caneditfield) // Case we can edit all field
  269. {
  270. $error=0;
  271. if (! $_POST["lastname"])
  272. {
  273. setEventMessage($langs->trans("NameNotDefined"), 'errors');
  274. $action="edit"; // Go back to create page
  275. $error++;
  276. }
  277. if (! $_POST["login"])
  278. {
  279. setEventMessage($langs->trans("LoginNotDefined"), 'errors');
  280. $action="edit"; // Go back to create page
  281. $error++;
  282. }
  283. if (! $error)
  284. {
  285. $object->fetch($id);
  286. // Test if new login
  287. if (GETPOST("login") && GETPOST("login") != $object->login)
  288. {
  289. dol_syslog("New login ".$object->login." is requested. We test it does not exists.");
  290. $tmpuser=new User($db);
  291. $result=$tmpuser->fetch(0, GETPOST("login"));
  292. if ($result > 0)
  293. {
  294. setEventMessage($langs->trans("ErrorLoginAlreadyExists", GETPOST('login')), 'errors');
  295. $action="edit"; // Go back to create page
  296. $error++;
  297. }
  298. }
  299. }
  300. if (! $error)
  301. {
  302. $db->begin();
  303. $object->oldcopy=dol_clone($object);
  304. $object->lastname = GETPOST("lastname",'alpha');
  305. $object->firstname = GETPOST("firstname",'alpha');
  306. $object->login = GETPOST("login",'alpha');
  307. $object->gender = GETPOST("gender",'alpha');
  308. $object->pass = GETPOST("password");
  309. $object->api_key = (GETPOST("api_key", 'alpha'))?GETPOST("api_key", 'alpha'):$object->api_key;
  310. $object->admin = empty($user->admin)?0:GETPOST("admin"); // A user can only be set admin by an admin
  311. $object->office_phone=GETPOST("office_phone",'alpha');
  312. $object->office_fax = GETPOST("office_fax",'alpha');
  313. $object->user_mobile= GETPOST("user_mobile");
  314. $object->skype = GETPOST("skype");
  315. $object->email = GETPOST("email",'alpha');
  316. $object->job = GETPOST("job",'alpha');
  317. $object->signature = GETPOST("signature");
  318. $object->accountancy_code = GETPOST("accountancy_code");
  319. $object->openid = GETPOST("openid");
  320. $object->fk_user = GETPOST("fk_user")>0?GETPOST("fk_user"):0;
  321. $object->thm = GETPOST("thm")!=''?GETPOST("thm"):'';
  322. $object->tjm = GETPOST("tjm")!=''?GETPOST("tjm"):'';
  323. $object->salary = GETPOST("salary")!=''?GETPOST("salary"):'';
  324. $object->salaryextra = GETPOST("salaryextra")!=''?GETPOST("salaryextra"):'';
  325. $object->weeklyhours = GETPOST("weeklyhours")!=''?GETPOST("weeklyhours"):'';
  326. $object->color = GETPOST("color")!=''?GETPOST("color"):'';
  327. // Fill array 'array_options' with data from add form
  328. $ret = $extrafields->setOptionalsFromPost($extralabels,$object);
  329. if ($ret < 0) $error++;
  330. if (! empty($conf->multicompany->enabled))
  331. {
  332. if (! empty($_POST["superadmin"]))
  333. {
  334. $object->entity = 0;
  335. }
  336. else if ($conf->multicompany->transverse_mode)
  337. {
  338. $object->entity = 1; // all users in master entity
  339. }
  340. else
  341. {
  342. $object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
  343. }
  344. }
  345. else
  346. {
  347. $object->entity = (empty($_POST["entity"]) ? 0 : $_POST["entity"]);
  348. }
  349. if (GETPOST('deletephoto')) $object->photo='';
  350. if (! empty($_FILES['photo']['name'])) $object->photo = dol_sanitizeFileName($_FILES['photo']['name']);
  351. if (! $error)
  352. {
  353. $ret=$object->update($user);
  354. if ($ret < 0)
  355. {
  356. $error++;
  357. if ($db->errno() == 'DB_ERROR_RECORD_ALREADY_EXISTS')
  358. {
  359. $langs->load("errors");
  360. setEventMessage($langs->trans("ErrorLoginAlreadyExists",$object->login), 'errors');
  361. }
  362. else
  363. {
  364. setEventMessages($object->error, $object->errors, 'errors');
  365. }
  366. }
  367. }
  368. if (! $error && isset($_POST['contactid']))
  369. {
  370. $contactid=GETPOST('contactid');
  371. if ($contactid > 0)
  372. {
  373. $contact=new Contact($db);
  374. $contact->fetch($contactid);
  375. $sql = "UPDATE ".MAIN_DB_PREFIX."user";
  376. $sql.= " SET fk_socpeople=".$db->escape($contactid);
  377. if ($contact->socid) $sql.=", fk_soc=".$db->escape($contact->socid);
  378. $sql.= " WHERE rowid=".$object->id;
  379. }
  380. else
  381. {
  382. $sql = "UPDATE ".MAIN_DB_PREFIX."user";
  383. $sql.= " SET fk_socpeople=NULL, fk_soc=NULL";
  384. $sql.= " WHERE rowid=".$object->id;
  385. }
  386. dol_syslog("fiche::update", LOG_DEBUG);
  387. $resql=$db->query($sql);
  388. if (! $resql)
  389. {
  390. $error++;
  391. setEventMessage($db->lasterror(), 'errors');
  392. }
  393. }
  394. if (! $error && ! count($object->errors))
  395. {
  396. if (GETPOST('deletephoto') && $object->photo)
  397. {
  398. $fileimg=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'user').'/logos/'.$object->photo;
  399. $dirthumbs=$conf->user->dir_output.'/'.get_exdir($object->id,2,0,1,$object,'user').'/logos/thumbs';
  400. dol_delete_file($fileimg);
  401. dol_delete_dir_recursive($dirthumbs);
  402. }
  403. if (isset($_FILES['photo']['tmp_name']) && trim($_FILES['photo']['tmp_name']))
  404. {
  405. $dir= $conf->user->dir_output . '/' . get_exdir($object->id,2,0,1,$object,'user');
  406. dol_mkdir($dir);
  407. if (@is_dir($dir))
  408. {
  409. $newfile=$dir.'/'.dol_sanitizeFileName($_FILES['photo']['name']);
  410. $result=dol_move_uploaded_file($_FILES['photo']['tmp_name'],$newfile,1,0,$_FILES['photo']['error']);
  411. if (! $result > 0)
  412. {
  413. setEventMessage($langs->trans("ErrorFailedToSaveFile"), 'errors');
  414. }
  415. else
  416. {
  417. // Create small thumbs for company (Ratio is near 16/9)
  418. // Used on logon for example
  419. $imgThumbSmall = vignette($newfile, $maxwidthsmall, $maxheightsmall, '_small', $quality);
  420. // Create mini thumbs for company (Ratio is near 16/9)
  421. // Used on menu or for setup page for example
  422. $imgThumbMini = vignette($newfile, $maxwidthmini, $maxheightmini, '_mini', $quality);
  423. }
  424. }
  425. else
  426. {
  427. $error++;
  428. $langs->load("errors");
  429. setEventMessages($langs->trans("ErrorFailedToCreateDir", $dir), $mesgs, 'errors');
  430. }
  431. }
  432. }
  433. if (! $error && ! count($object->errors))
  434. {
  435. setEventMessage($langs->trans("UserModified"));
  436. $db->commit();
  437. $login=$_SESSION["dol_login"];
  438. if ($login && $login == $object->oldcopy->login && $object->oldcopy->login != $object->login) // Current user has changed its login
  439. {
  440. $_SESSION["dol_login"]=$object->login; // Set new login to avoid disconnect at next page
  441. }
  442. }
  443. else
  444. {
  445. $db->rollback();
  446. }
  447. }
  448. }
  449. else if ($caneditpassword) // Case we can edit only password
  450. {
  451. $object->fetch($id);
  452. $object->oldcopy=dol_clone($object);
  453. $ret=$object->setPassword($user,$_POST["password"]);
  454. if ($ret < 0)
  455. {
  456. setEventMessage($object->error, 'errors');
  457. }
  458. }
  459. }
  460. // Change password with a new generated one
  461. if ((($action == 'confirm_password' && $confirm == 'yes')
  462. || ($action == 'confirm_passwordsend' && $confirm == 'yes')) && $caneditpassword)
  463. {
  464. $object->fetch($id);
  465. $newpassword=$object->setPassword($user,'');
  466. if ($newpassword < 0)
  467. {
  468. // Echec
  469. setEventMessage($langs->trans("ErrorFailedToSetNewPassword"), 'errors');
  470. }
  471. else
  472. {
  473. // Succes
  474. if ($action == 'confirm_passwordsend' && $confirm == 'yes')
  475. {
  476. if ($object->send_password($user,$newpassword) > 0)
  477. {
  478. setEventMessage($langs->trans("PasswordChangedAndSentTo",$object->email));
  479. }
  480. else
  481. {
  482. setEventMessage($object->error, 'errors');
  483. }
  484. }
  485. else
  486. {
  487. setEventMessage($langs->trans("PasswordChangedTo",$newpassword), 'errors');
  488. }
  489. }
  490. }
  491. // Action initialisation donnees depuis record LDAP
  492. if ($action == 'adduserldap')
  493. {
  494. $selecteduser = $_POST['users'];
  495. $required_fields = array(
  496. $conf->global->LDAP_KEY_USERS,
  497. $conf->global->LDAP_FIELD_NAME,
  498. $conf->global->LDAP_FIELD_FIRSTNAME,
  499. $conf->global->LDAP_FIELD_LOGIN,
  500. $conf->global->LDAP_FIELD_LOGIN_SAMBA,
  501. $conf->global->LDAP_FIELD_PASSWORD,
  502. $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
  503. $conf->global->LDAP_FIELD_PHONE,
  504. $conf->global->LDAP_FIELD_FAX,
  505. $conf->global->LDAP_FIELD_MOBILE,
  506. $conf->global->LDAP_FIELD_SKYPE,
  507. $conf->global->LDAP_FIELD_MAIL,
  508. $conf->global->LDAP_FIELD_TITLE,
  509. $conf->global->LDAP_FIELD_DESCRIPTION,
  510. $conf->global->LDAP_FIELD_SID);
  511. $ldap = new Ldap();
  512. $result = $ldap->connect_bind();
  513. if ($result >= 0)
  514. {
  515. // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
  516. $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
  517. $ldapusers = $ldap->getRecords($selecteduser, $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields);
  518. //print_r($ldapusers);
  519. if (is_array($ldapusers))
  520. {
  521. foreach ($ldapusers as $key => $attribute)
  522. {
  523. $ldap_lastname = $attribute[$conf->global->LDAP_FIELD_NAME];
  524. $ldap_firstname = $attribute[$conf->global->LDAP_FIELD_FIRSTNAME];
  525. $ldap_login = $attribute[$conf->global->LDAP_FIELD_LOGIN];
  526. $ldap_loginsmb = $attribute[$conf->global->LDAP_FIELD_LOGIN_SAMBA];
  527. $ldap_pass = $attribute[$conf->global->LDAP_FIELD_PASSWORD];
  528. $ldap_pass_crypted = $attribute[$conf->global->LDAP_FIELD_PASSWORD_CRYPTED];
  529. $ldap_phone = $attribute[$conf->global->LDAP_FIELD_PHONE];
  530. $ldap_fax = $attribute[$conf->global->LDAP_FIELD_FAX];
  531. $ldap_mobile = $attribute[$conf->global->LDAP_FIELD_MOBILE];
  532. $ldap_skype = $attribute[$conf->global->LDAP_FIELD_SKYPE];
  533. $ldap_mail = $attribute[$conf->global->LDAP_FIELD_MAIL];
  534. $ldap_sid = $attribute[$conf->global->LDAP_FIELD_SID];
  535. }
  536. }
  537. }
  538. else
  539. {
  540. setEventMessage($ldap->error, 'errors');
  541. }
  542. }
  543. /*
  544. * View
  545. */
  546. $form = new Form($db);
  547. $formother=new FormOther($db);
  548. llxHeader('',$langs->trans("UserCard"));
  549. if (($action == 'create') || ($action == 'adduserldap'))
  550. {
  551. /* ************************************************************************** */
  552. /* */
  553. /* Affichage fiche en mode creation */
  554. /* */
  555. /* ************************************************************************** */
  556. print_fiche_titre($langs->trans("NewUser"));
  557. print $langs->trans("CreateInternalUserDesc")."<br>\n";
  558. print "<br>";
  559. if (! empty($conf->ldap->enabled) && (isset($conf->global->LDAP_SYNCHRO_ACTIVE) && $conf->global->LDAP_SYNCHRO_ACTIVE == 'ldap2dolibarr'))
  560. {
  561. /*
  562. * Affiche formulaire d'ajout d'un compte depuis LDAP
  563. * si on est en synchro LDAP vers Dolibarr
  564. */
  565. $ldap = new Ldap();
  566. $result = $ldap->connect_bind();
  567. if ($result >= 0)
  568. {
  569. $required_fields=array(
  570. $conf->global->LDAP_KEY_USERS,
  571. $conf->global->LDAP_FIELD_FULLNAME,
  572. $conf->global->LDAP_FIELD_NAME,
  573. $conf->global->LDAP_FIELD_FIRSTNAME,
  574. $conf->global->LDAP_FIELD_LOGIN,
  575. $conf->global->LDAP_FIELD_LOGIN_SAMBA,
  576. $conf->global->LDAP_FIELD_PASSWORD,
  577. $conf->global->LDAP_FIELD_PASSWORD_CRYPTED,
  578. $conf->global->LDAP_FIELD_PHONE,
  579. $conf->global->LDAP_FIELD_FAX,
  580. $conf->global->LDAP_FIELD_MOBILE,
  581. $conf->global->LDAP_FIELD_SKYPE,
  582. $conf->global->LDAP_FIELD_MAIL,
  583. $conf->global->LDAP_FIELD_TITLE,
  584. $conf->global->LDAP_FIELD_DESCRIPTION,
  585. $conf->global->LDAP_FIELD_SID
  586. );
  587. // Remove from required_fields all entries not configured in LDAP (empty) and duplicated
  588. $required_fields=array_unique(array_values(array_filter($required_fields, "dol_validElement")));
  589. // Get from LDAP database an array of results
  590. $ldapusers = $ldap->getRecords('*', $conf->global->LDAP_USER_DN, $conf->global->LDAP_KEY_USERS, $required_fields, 1);
  591. if (is_array($ldapusers))
  592. {
  593. $liste=array();
  594. foreach ($ldapusers as $key => $ldapuser)
  595. {
  596. // Define the label string for this user
  597. $label='';
  598. foreach ($required_fields as $value)
  599. {
  600. if ($value)
  601. {
  602. $label.=$value."=".$ldapuser[$value]." ";
  603. }
  604. }
  605. $liste[$key] = $label;
  606. }
  607. }
  608. else
  609. {
  610. setEventMessage($ldap->error, 'errors');
  611. }
  612. }
  613. else
  614. {
  615. setEventMessage($ldap->error, 'errors');
  616. }
  617. // If user list is full, we show drop-down list
  618. print "\n\n<!-- Form liste LDAP debut -->\n";
  619. print '<form name="add_user_ldap" action="'.$_SERVER["PHP_SELF"].'" method="post">';
  620. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  621. print '<table width="100%" class="border"><tr>';
  622. print '<td width="160">';
  623. print $langs->trans("LDAPUsers");
  624. print '</td>';
  625. print '<td>';
  626. print '<input type="hidden" name="action" value="adduserldap">';
  627. if (is_array($liste) && count($liste))
  628. {
  629. print $form->selectarray('users', $liste, '', 1);
  630. }
  631. print '</td><td align="center">';
  632. print '<input type="submit" class="button" value="'.dol_escape_htmltag($langs->trans('Get')).'"'.(count($liste)?'':' disabled').'>';
  633. print '</td></tr></table>';
  634. print '</form>';
  635. print "\n<!-- Form liste LDAP fin -->\n\n";
  636. print '<br>';
  637. }
  638. print '<form action="'.$_SERVER['PHP_SELF'].'" method="POST" name="createuser">';
  639. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  640. print '<input type="hidden" name="action" value="add">';
  641. if (! empty($ldap_sid)) print '<input type="hidden" name="ldap_sid" value="'.dol_escape_htmltag($ldap_sid).'">';
  642. print '<input type="hidden" name="entity" value="'.$conf->entity.'">';
  643. dol_fiche_head('', '', '', 0, '');
  644. print dol_set_focus('#lastname');
  645. print '<table class="border" width="100%">';
  646. print '<tr>';
  647. // Lastname
  648. print '<td width="160"><span class="fieldrequired">'.$langs->trans("Lastname").'</span></td>';
  649. print '<td>';
  650. if (! empty($ldap_lastname))
  651. {
  652. print '<input type="hidden" id="lastname" name="lastname" value="'.$ldap_lastname.'">';
  653. print $ldap_lastname;
  654. }
  655. else
  656. {
  657. print '<input size="30" type="text" id="lastname" name="lastname" value="'.GETPOST('lastname').'">';
  658. }
  659. print '</td></tr>';
  660. // Firstname
  661. print '<tr><td>'.$langs->trans("Firstname").'</td>';
  662. print '<td>';
  663. if (! empty($ldap_firstname))
  664. {
  665. print '<input type="hidden" name="firstname" value="'.$ldap_firstname.'">';
  666. print $ldap_firstname;
  667. }
  668. else
  669. {
  670. print '<input size="30" type="text" name="firstname" value="'.GETPOST('firstname').'">';
  671. }
  672. print '</td></tr>';
  673. // Position/Job
  674. print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
  675. print '<td>';
  676. print '<input size="30" type="text" name="job" value="'.GETPOST('job').'">';
  677. print '</td></tr>';
  678. // Gender
  679. print '<tr><td>'.$langs->trans("Gender").'</td>';
  680. print '<td>';
  681. $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman"));
  682. print $form->selectarray('gender', $arraygender, GETPOST('gender'), 1);
  683. print '</td></tr>';
  684. // Login
  685. print '<tr><td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
  686. print '<td>';
  687. if (! empty($ldap_login))
  688. {
  689. print '<input type="hidden" name="login" value="'.$ldap_login.'">';
  690. print $ldap_login;
  691. }
  692. elseif (! empty($ldap_loginsmb))
  693. {
  694. print '<input type="hidden" name="login" value="'.$ldap_loginsmb.'">';
  695. print $ldap_loginsmb;
  696. }
  697. else
  698. {
  699. print '<input size="20" maxsize="24" type="text" name="login" value="'.GETPOST('login').'">';
  700. }
  701. print '</td></tr>';
  702. $generated_password='';
  703. if (empty($ldap_sid)) // ldap_sid is for activedirectory
  704. {
  705. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  706. $generated_password=getRandomPassword(false);
  707. }
  708. $password=$generated_password;
  709. // Password
  710. print '<tr><td class="fieldrequired">'.$langs->trans("Password").'</td>';
  711. print '<td>';
  712. if (! empty($ldap_sid))
  713. {
  714. print 'Mot de passe du domaine';
  715. }
  716. else
  717. {
  718. if (! empty($ldap_pass))
  719. {
  720. print '<input type="hidden" name="password" value="'.$ldap_pass.'">';
  721. print preg_replace('/./i','*',$ldap_pass);
  722. }
  723. else
  724. {
  725. // We do not use a field password but a field text to show new password to use.
  726. print '<input size="30" maxsize="32" type="text" name="password" value="'.$password.'" autocomplete="off">';
  727. }
  728. }
  729. print '</td></tr>';
  730. if(! empty($conf->api->enabled))
  731. {
  732. // API key
  733. $generated_api_key = '';
  734. require_once DOL_DOCUMENT_ROOT.'/core/lib/security2.lib.php';
  735. $generated_password=getRandomPassword(false);
  736. print '<tr><td>'.$langs->trans("ApiKey").'</td>';
  737. print '<td>';
  738. print '<input size="30" maxsize="32" type="text" id="api_key" name="api_key" value="'.$api_key.'" autocomplete="off">';
  739. if (! empty($conf->use_javascript_ajax))
  740. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"');
  741. print '</td></tr>';
  742. }
  743. else
  744. {
  745. // PARTIAL WORKAROUND
  746. $generated_fake_api_key=getRandomPassword(false);
  747. print '<input type="hidden" name="api_key" value="'.$generated_fake_api_key.'">';
  748. }
  749. // Administrator
  750. if (! empty($user->admin))
  751. {
  752. print '<tr><td>'.$langs->trans("Administrator").'</td>';
  753. print '<td>';
  754. print $form->selectyesno('admin',GETPOST('admin'),1);
  755. if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
  756. {
  757. if (! empty($conf->use_javascript_ajax))
  758. {
  759. print '<script type="text/javascript">
  760. $(function() {
  761. $("select[name=admin]").change(function() {
  762. if ( $(this).val() == 0 ) {
  763. $("input[name=superadmin]")
  764. .prop("disabled", true)
  765. .prop("checked", false);
  766. $("select[name=entity]")
  767. .prop("disabled", false);
  768. } else {
  769. $("input[name=superadmin]")
  770. .prop("disabled", false);
  771. }
  772. });
  773. $("input[name=superadmin]").change(function() {
  774. if ( $(this).is(":checked") ) {
  775. $("select[name=entity]")
  776. .prop("disabled", true);
  777. } else {
  778. $("select[name=entity]")
  779. .prop("disabled", false);
  780. }
  781. });
  782. });
  783. </script>';
  784. }
  785. $checked=($_POST["superadmin"]?' checked':'');
  786. $disabled=($_POST["superadmin"]?'':' disabled');
  787. print '<input type="checkbox" name="superadmin" value="1"'.$checked.$disabled.' /> '.$langs->trans("SuperAdministrator");
  788. }
  789. print "</td></tr>\n";
  790. }
  791. // Type
  792. print '<tr><td>'.$langs->trans("Type").'</td>';
  793. print '<td>';
  794. print $form->textwithpicto($langs->trans("Internal"),$langs->trans("InternalExternalDesc"), 1, 'help', '', 0, 2);
  795. print '</td></tr>';
  796. // Tel
  797. print '<tr><td>'.$langs->trans("PhonePro").'</td>';
  798. print '<td>';
  799. if (! empty($ldap_phone))
  800. {
  801. print '<input type="hidden" name="office_phone" value="'.$ldap_phone.'">';
  802. print $ldap_phone;
  803. }
  804. else
  805. {
  806. print '<input size="20" type="text" name="office_phone" value="'.GETPOST('office_phone').'">';
  807. }
  808. print '</td></tr>';
  809. // Tel portable
  810. print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
  811. print '<td>';
  812. if (! empty($ldap_mobile))
  813. {
  814. print '<input type="hidden" name="user_mobile" value="'.$ldap_mobile.'">';
  815. print $ldap_mobile;
  816. }
  817. else
  818. {
  819. print '<input size="20" type="text" name="user_mobile" value="'.GETPOST('user_mobile').'">';
  820. }
  821. print '</td></tr>';
  822. // Fax
  823. print '<tr><td>'.$langs->trans("Fax").'</td>';
  824. print '<td>';
  825. if (! empty($ldap_fax))
  826. {
  827. print '<input type="hidden" name="office_fax" value="'.$ldap_fax.'">';
  828. print $ldap_fax;
  829. }
  830. else
  831. {
  832. print '<input size="20" type="text" name="office_fax" value="'.GETPOST('office_fax').'">';
  833. }
  834. print '</td></tr>';
  835. // Skype
  836. if (! empty($conf->skype->enabled))
  837. {
  838. print '<tr><td>'.$langs->trans("Skype").'</td>';
  839. print '<td>';
  840. if (! empty($ldap_skype))
  841. {
  842. print '<input type="hidden" name="skype" value="'.$ldap_skype.'">';
  843. print $ldap_skype;
  844. }
  845. else
  846. {
  847. print '<input size="40" type="text" name="skype" value="'.GETPOST('skype').'">';
  848. }
  849. print '</td></tr>';
  850. }
  851. // EMail
  852. print '<tr><td'.(! empty($conf->global->USER_MAIL_REQUIRED)?' class="fieldrequired"':'').'>'.$langs->trans("EMail").'</td>';
  853. print '<td>';
  854. if (! empty($ldap_mail))
  855. {
  856. print '<input type="hidden" name="email" value="'.$ldap_mail.'">';
  857. print $ldap_mail;
  858. }
  859. else
  860. {
  861. print '<input size="40" type="text" name="email" value="'.GETPOST('email').'">';
  862. }
  863. print '</td></tr>';
  864. // Signature
  865. print '<tr><td class="tdtop">'.$langs->trans("Signature").'</td>';
  866. print '<td>';
  867. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  868. $doleditor=new DolEditor('signature',GETPOST('signature'),'',138,'dolibarr_mailings','In',true,true,empty($conf->global->FCKEDITOR_ENABLE_USERSIGN)?0:1,ROWS_4,90);
  869. print $doleditor->Create(1);
  870. print '</td></tr>';
  871. // Multicompany
  872. if (! empty($conf->multicompany->enabled))
  873. {
  874. if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity && is_object($mc))
  875. {
  876. print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
  877. print "<td>".$mc->select_entities($conf->entity);
  878. print "</td></tr>\n";
  879. }
  880. else
  881. {
  882. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  883. }
  884. }
  885. // Hierarchy
  886. print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
  887. print '<td>';
  888. print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$conf->entity);
  889. print '</td>';
  890. print "</tr>\n";
  891. if ($conf->salaries->enabled && ! empty($user->rights->salaries->read))
  892. {
  893. $langs->load("salaries");
  894. // THM
  895. print '<tr><td>'.$langs->trans("THM").'</td>';
  896. print '<td>';
  897. print '<input size="8" type="text" name="thm" value="'.GETPOST('thm').'">';
  898. print '</td>';
  899. print "</tr>\n";
  900. // TJM
  901. print '<tr><td>'.$langs->trans("TJM").'</td>';
  902. print '<td>';
  903. print '<input size="8" type="text" name="tjm" value="'.GETPOST('tjm').'">';
  904. print '</td>';
  905. print "</tr>\n";
  906. // Salary
  907. print '<tr><td>'.$langs->trans("Salary").'</td>';
  908. print '<td>';
  909. print '<input size="8" type="text" name="salary" value="'.GETPOST('salary').'">';
  910. print '</td>';
  911. print "</tr>\n";
  912. }
  913. // Weeklyhours
  914. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  915. print '<td>';
  916. print '<input size="8" type="text" name="weeklyhours" value="'.GETPOST('weeklyhours').'">';
  917. print '</td>';
  918. print "</tr>\n";
  919. // Accountancy code
  920. if ($conf->salaries->enabled)
  921. {
  922. print '<tr><td>'.$langs->trans("AccountancyCode").'</td>';
  923. print '<td>';
  924. print '<input size="30" type="text" name="accountancy_code" value="'.GETPOST('accountancy_code').'">';
  925. print '</td></tr>';
  926. }
  927. // User color
  928. if (! empty($conf->agenda->enabled))
  929. {
  930. print '<tr><td>'.$langs->trans("ColorUser").'</td>';
  931. print '<td>';
  932. print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', 'usercolorconfig', 1, '', 'hideifnotset');
  933. print '</td></tr>';
  934. }
  935. // Note
  936. print '<tr><td class="tdtop">';
  937. print $langs->trans("Note");
  938. print '</td><td>';
  939. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  940. $doleditor=new DolEditor('note','','',180,'dolibarr_notes','',false,true,$conf->global->FCKEDITOR_ENABLE_SOCIETE,ROWS_4,90);
  941. $doleditor->Create();
  942. print "</td></tr>\n";
  943. // Other attributes
  944. $parameters=array('objectsrc' => $objectsrc, 'colspan' => ' colspan="3"');
  945. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  946. if (empty($reshook) && ! empty($extrafields->attribute_label))
  947. {
  948. print $object->showOptionals($extrafields,'edit');
  949. }
  950. print "</table>\n";
  951. dol_fiche_end();
  952. print '<div align="center">';
  953. print '<input class="button" value="'.$langs->trans("CreateUser").'" name="create" type="submit">';
  954. //print '&nbsp; &nbsp; &nbsp;';
  955. //print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">';
  956. print '</div>';
  957. print "</form>";
  958. }
  959. else
  960. {
  961. /* ************************************************************************** */
  962. /* */
  963. /* View and edition */
  964. /* */
  965. /* ************************************************************************** */
  966. if ($id > 0)
  967. {
  968. $object->fetch($id);
  969. if ($res < 0) { dol_print_error($db,$object->error); exit; }
  970. $res=$object->fetch_optionals($object->id,$extralabels);
  971. // Connexion ldap
  972. // pour recuperer passDoNotExpire et userChangePassNextLogon
  973. if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid))
  974. {
  975. $ldap = new Ldap();
  976. $result=$ldap->connect_bind();
  977. if ($result > 0)
  978. {
  979. $userSearchFilter = '('.$conf->global->LDAP_FILTER_CONNECTION.'('.$ldap->getUserIdentifier().'='.$object->login.'))';
  980. $entries = $ldap->fetch($object->login,$userSearchFilter);
  981. if (! $entries)
  982. {
  983. setEventMessage($ldap->error, 'errors');
  984. }
  985. $passDoNotExpire = 0;
  986. $userChangePassNextLogon = 0;
  987. $userDisabled = 0;
  988. $statutUACF = '';
  989. // Check options of user account
  990. if (count($ldap->uacf) > 0)
  991. {
  992. foreach ($ldap->uacf as $key => $statut)
  993. {
  994. if ($key == 65536)
  995. {
  996. $passDoNotExpire = 1;
  997. $statutUACF = $statut;
  998. }
  999. }
  1000. }
  1001. else
  1002. {
  1003. $userDisabled = 1;
  1004. $statutUACF = "ACCOUNTDISABLE";
  1005. }
  1006. if ($ldap->pwdlastset == 0)
  1007. {
  1008. $userChangePassNextLogon = 1;
  1009. }
  1010. }
  1011. }
  1012. // Show tabs
  1013. $head = user_prepare_head($object);
  1014. $title = $langs->trans("User");
  1015. /*
  1016. * Confirmation reinitialisation mot de passe
  1017. */
  1018. if ($action == 'password')
  1019. {
  1020. print $form->formconfirm("card.php?id=$object->id",$langs->trans("ReinitPassword"),$langs->trans("ConfirmReinitPassword",$object->login),"confirm_password", '', 0, 1);
  1021. }
  1022. /*
  1023. * Confirmation envoi mot de passe
  1024. */
  1025. if ($action == 'passwordsend')
  1026. {
  1027. print $form->formconfirm("card.php?id=$object->id",$langs->trans("SendNewPassword"),$langs->trans("ConfirmSendNewPassword",$object->login),"confirm_passwordsend", '', 0, 1);
  1028. }
  1029. /*
  1030. * Confirm deactivation
  1031. */
  1032. if ($action == 'disable')
  1033. {
  1034. print $form->formconfirm("card.php?id=$object->id",$langs->trans("DisableAUser"),$langs->trans("ConfirmDisableUser",$object->login),"confirm_disable", '', 0, 1);
  1035. }
  1036. /*
  1037. * Confirm activation
  1038. */
  1039. if ($action == 'enable')
  1040. {
  1041. print $form->formconfirm("card.php?id=$object->id",$langs->trans("EnableAUser"),$langs->trans("ConfirmEnableUser",$object->login),"confirm_enable", '', 0, 1);
  1042. }
  1043. /*
  1044. * Confirmation suppression
  1045. */
  1046. if ($action == 'delete')
  1047. {
  1048. print $form->formconfirm("card.php?id=$object->id",$langs->trans("DeleteAUser"),$langs->trans("ConfirmDeleteUser",$object->login),"confirm_delete", '', 0, 1);
  1049. }
  1050. /*
  1051. * Fiche en mode visu
  1052. */
  1053. if ($action != 'edit')
  1054. {
  1055. dol_fiche_head($head, 'user', $title, 0, 'user');
  1056. $rowspan=19;
  1057. print '<table class="border" width="100%">';
  1058. // Ref
  1059. print '<tr><td width="25%">'.$langs->trans("Ref").'</td>';
  1060. print '<td colspan="3">';
  1061. print $form->showrefnav($object,'id','',$user->rights->user->user->lire || $user->admin);
  1062. print '</td>';
  1063. print '</tr>'."\n";
  1064. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $rowspan++;
  1065. if (! empty($conf->societe->enabled)) $rowspan++;
  1066. if (! empty($conf->adherent->enabled)) $rowspan++;
  1067. if (! empty($conf->skype->enabled)) $rowspan++;
  1068. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) $rowspan = $rowspan+3;
  1069. if (! empty($conf->agenda->enabled)) $rowspan++;
  1070. // Lastname
  1071. print '<tr><td>'.$langs->trans("Lastname").'</td>';
  1072. print '<td colspan="2">'.$object->lastname.'</td>';
  1073. // Photo
  1074. print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
  1075. print $form->showphoto('userphoto',$object,100);
  1076. print '</td>';
  1077. print '</tr>'."\n";
  1078. // Firstname
  1079. print '<tr><td>'.$langs->trans("Firstname").'</td>';
  1080. print '<td colspan="2">'.$object->firstname.'</td>';
  1081. print '</tr>'."\n";
  1082. // Position/Job
  1083. print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
  1084. print '<td colspan="2">'.$object->job.'</td>';
  1085. print '</tr>'."\n";
  1086. // Gender
  1087. print '<tr><td>'.$langs->trans("Gender").'</td>';
  1088. print '<td>';
  1089. if ($object->gender) print $langs->trans("Gender".$object->gender);
  1090. print '</td></tr>';
  1091. // Login
  1092. print '<tr><td>'.$langs->trans("Login").'</td>';
  1093. if (! empty($object->ldap_sid) && $object->statut==0)
  1094. {
  1095. print '<td colspan="2" class="error">'.$langs->trans("LoginAccountDisableInDolibarr").'</td>';
  1096. }
  1097. else
  1098. {
  1099. print '<td colspan="2">'.$object->login.'</td>';
  1100. }
  1101. print '</tr>'."\n";
  1102. // Password
  1103. print '<tr><td>'.$langs->trans("Password").'</td>';
  1104. if (! empty($object->ldap_sid))
  1105. {
  1106. if ($passDoNotExpire)
  1107. {
  1108. print '<td colspan="2">'.$langs->trans("LdapUacf_".$statutUACF).'</td>';
  1109. }
  1110. else if($userChangePassNextLogon)
  1111. {
  1112. print '<td colspan="2" class="warning">'.$langs->trans("UserMustChangePassNextLogon",$ldap->domainFQDN).'</td>';
  1113. }
  1114. else if($userDisabled)
  1115. {
  1116. print '<td colspan="2" class="warning">'.$langs->trans("LdapUacf_".$statutUACF,$ldap->domainFQDN).'</td>';
  1117. }
  1118. else
  1119. {
  1120. print '<td colspan="2">'.$langs->trans("DomainPassword").'</td>';
  1121. }
  1122. }
  1123. else
  1124. {
  1125. print '<td colspan="2">';
  1126. if ($object->pass) print preg_replace('/./i','*',$object->pass);
  1127. else
  1128. {
  1129. if ($user->admin) print $langs->trans("Crypted").': '.$object->pass_indatabase_crypted;
  1130. else print $langs->trans("Hidden");
  1131. }
  1132. print "</td>";
  1133. }
  1134. print '</tr>'."\n";
  1135. // API key
  1136. if(! empty($conf->api->enabled) && $user->admin) {
  1137. print '<tr><td>'.$langs->trans("ApiKey").'</td>';
  1138. print '<td colspan="2">';
  1139. if (! empty($object->api_key))
  1140. print $langs->trans("Hidden");
  1141. print '<td>';
  1142. }
  1143. // Administrator
  1144. print '<tr><td>'.$langs->trans("Administrator").'</td><td colspan="2">';
  1145. if (! empty($conf->multicompany->enabled) && $object->admin && ! $object->entity)
  1146. {
  1147. print $form->textwithpicto(yn($object->admin),$langs->trans("SuperAdministratorDesc"),1,"superadmin");
  1148. }
  1149. else if ($object->admin)
  1150. {
  1151. print $form->textwithpicto(yn($object->admin),$langs->trans("AdministratorDesc"),1,"admin");
  1152. }
  1153. else
  1154. {
  1155. print yn($object->admin);
  1156. }
  1157. print '</td></tr>'."\n";
  1158. // Type
  1159. print '<tr><td>';
  1160. $text=$langs->trans("Type");
  1161. print $form->textwithpicto($text, $langs->trans("InternalExternalDesc"));
  1162. print '</td><td colspan="2">';
  1163. $type=$langs->trans("Internal");
  1164. if ($object->societe_id > 0) $type=$langs->trans("External");
  1165. print $type;
  1166. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1167. print '</td></tr>'."\n";
  1168. // Ldap sid
  1169. if ($object->ldap_sid)
  1170. {
  1171. print '<tr><td>'.$langs->trans("Type").'</td><td colspan="2">';
  1172. print $langs->trans("DomainUser",$ldap->domainFQDN);
  1173. print '</td></tr>'."\n";
  1174. }
  1175. // Tel pro
  1176. print '<tr><td>'.$langs->trans("PhonePro").'</td>';
  1177. print '<td colspan="2">'.dol_print_phone($object->office_phone,'',0,0,1).'</td>';
  1178. print '</tr>'."\n";
  1179. // Tel mobile
  1180. print '<tr><td>'.$langs->trans("PhoneMobile").'</td>';
  1181. print '<td colspan="2">'.dol_print_phone($object->user_mobile,'',0,0,1).'</td>';
  1182. print '</tr>'."\n";
  1183. // Fax
  1184. print '<tr><td>'.$langs->trans("Fax").'</td>';
  1185. print '<td colspan="2">'.dol_print_phone($object->office_fax,'',0,0,1).'</td>';
  1186. print '</tr>'."\n";
  1187. // Skype
  1188. if (! empty($conf->skype->enabled))
  1189. {
  1190. print '<tr><td>'.$langs->trans("Skype").'</td>';
  1191. print '<td colspan="2">'.dol_print_skype($object->skype,0,0,1).'</td>';
  1192. print "</tr>\n";
  1193. }
  1194. // EMail
  1195. print '<tr><td>'.$langs->trans("EMail").'</td>';
  1196. print '<td colspan="2">'.dol_print_email($object->email,0,0,1).'</td>';
  1197. print "</tr>\n";
  1198. // Signature
  1199. print '<tr><td class="tdtop">'.$langs->trans('Signature').'</td><td colspan="2">';
  1200. print dol_htmlentitiesbr($object->signature);
  1201. print "</td></tr>\n";
  1202. // Hierarchy
  1203. print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
  1204. print '<td colspan="2">';
  1205. if (empty($object->fk_user)) print $langs->trans("None");
  1206. else {
  1207. $huser=new User($db);
  1208. $huser->fetch($object->fk_user);
  1209. print $huser->getNomUrl(1);
  1210. }
  1211. print '</td>';
  1212. print "</tr>\n";
  1213. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
  1214. {
  1215. $langs->load("salaries");
  1216. // THM
  1217. print '<tr><td>';
  1218. $text=$langs->trans("THM");
  1219. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  1220. print '</td>';
  1221. print '<td colspan="2">';
  1222. print ($object->thm!=''?price($object->thm,'',$langs,1,-1,-1,$conf->currency):'');
  1223. print '</td>';
  1224. print "</tr>\n";
  1225. // TJM
  1226. print '<tr><td>';
  1227. $text=$langs->trans("TJM");
  1228. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classtjm');
  1229. print '</td>';
  1230. print '<td colspan="2">';
  1231. print ($object->tjm!=''?price($object->tjm,'',$langs,1,-1,-1,$conf->currency):'');
  1232. print '</td>';
  1233. print "</tr>\n";
  1234. // Salary
  1235. print '<tr><td>'.$langs->trans("Salary").'</td>';
  1236. print '<td colspan="2">';
  1237. print ($object->salary!=''?price($object->salary,'',$langs,1,-1,-1,$conf->currency):'');
  1238. print '</td>';
  1239. print "</tr>\n";
  1240. }
  1241. // Weeklyhours
  1242. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  1243. print '<td colspan="2">';
  1244. print price2num($object->weeklyhours);
  1245. print '</td>';
  1246. print "</tr>\n";
  1247. // Accountancy code
  1248. if ($conf->salaries->enabled)
  1249. {
  1250. print '<tr><td>'.$langs->trans("AccountancyCode").'</td>';
  1251. print '<td colspan="2">'.$object->accountancy_code.'</td>';
  1252. }
  1253. // Color user
  1254. if (! empty($conf->agenda->enabled))
  1255. {
  1256. print '<tr><td>'.$langs->trans("ColorUser").'</td>';
  1257. print '<td colspan="2">';
  1258. print $formother->showColor($object->color, '');
  1259. print '</td>';
  1260. print "</tr>\n";
  1261. }
  1262. // Status
  1263. print '<tr><td>'.$langs->trans("Status").'</td>';
  1264. print '<td colspan="2">';
  1265. print $object->getLibStatut(4);
  1266. print '</td>';
  1267. print '</tr>'."\n";
  1268. print '<tr><td>'.$langs->trans("LastConnexion").'</td>';
  1269. print '<td colspan="2">'.dol_print_date($object->datelastlogin,"dayhour").'</td>';
  1270. print "</tr>\n";
  1271. print '<tr><td>'.$langs->trans("PreviousConnexion").'</td>';
  1272. print '<td colspan="2">'.dol_print_date($object->datepreviouslogin,"dayhour").'</td>';
  1273. print "</tr>\n";
  1274. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER))
  1275. {
  1276. print '<tr><td>'.$langs->trans("OpenIDURL").'</td>';
  1277. print '<td colspan="2">'.$object->openid.'</td>';
  1278. print "</tr>\n";
  1279. }
  1280. // Company / Contact
  1281. if (! empty($conf->societe->enabled))
  1282. {
  1283. print '<tr><td>'.$langs->trans("LinkToCompanyContact").'</td>';
  1284. print '<td colspan="2">';
  1285. if (isset($object->societe_id) && $object->societe_id > 0)
  1286. {
  1287. $societe = new Societe($db);
  1288. $societe->fetch($object->societe_id);
  1289. print $societe->getNomUrl(1,'');
  1290. }
  1291. else
  1292. {
  1293. print $langs->trans("ThisUserIsNot");
  1294. }
  1295. if (! empty($object->contact_id))
  1296. {
  1297. $contact = new Contact($db);
  1298. $contact->fetch($object->contact_id);
  1299. if ($object->societe_id > 0) print ' / ';
  1300. else print '<br>';
  1301. 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>';
  1302. }
  1303. print '</td>';
  1304. print '</tr>'."\n";
  1305. }
  1306. // Module Adherent
  1307. if (! empty($conf->adherent->enabled))
  1308. {
  1309. $langs->load("members");
  1310. print '<tr><td>'.$langs->trans("LinkedToDolibarrMember").'</td>';
  1311. print '<td colspan="2">';
  1312. if ($object->fk_member)
  1313. {
  1314. $adh=new Adherent($db);
  1315. $adh->fetch($object->fk_member);
  1316. $adh->ref=$adh->getFullname($langs); // Force to show login instead of id
  1317. print $adh->getNomUrl(1);
  1318. }
  1319. else
  1320. {
  1321. print $langs->trans("UserNotLinkedToMember");
  1322. }
  1323. print '</td>';
  1324. print '</tr>'."\n";
  1325. }
  1326. // Multicompany
  1327. // TODO This should be done with hook formObjectOption
  1328. if (is_object($mc))
  1329. {
  1330. if (! empty($conf->multicompany->enabled) && empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1331. {
  1332. print '<tr><td>'.$langs->trans("Entity").'</td><td width="75%" class="valeur">';
  1333. if (empty($object->entity))
  1334. {
  1335. print $langs->trans("AllEntities");
  1336. }
  1337. else
  1338. {
  1339. $mc->getInfo($object->entity);
  1340. print $mc->label;
  1341. }
  1342. print "</td></tr>\n";
  1343. }
  1344. }
  1345. // Other attributes
  1346. $parameters=array('colspan' => ' colspan="2"');
  1347. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1348. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1349. {
  1350. print $object->showOptionals($extrafields);
  1351. }
  1352. print "</table>\n";
  1353. dol_fiche_end();
  1354. /*
  1355. * Buttons actions
  1356. */
  1357. print '<div class="tabsAction">';
  1358. if ($caneditfield && (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1359. {
  1360. if (! empty($conf->global->MAIN_ONLY_LOGIN_ALLOWED))
  1361. {
  1362. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("DisabledInMonoUserMode")).'">'.$langs->trans("Modify").'</a></div>';
  1363. }
  1364. else
  1365. {
  1366. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("Modify").'</a></div>';
  1367. }
  1368. }
  1369. elseif ($caneditpassword && ! $object->ldap_sid &&
  1370. (empty($conf->multicompany->enabled) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1371. {
  1372. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=edit">'.$langs->trans("EditPassword").'</a></div>';
  1373. }
  1374. // Si on a un gestionnaire de generation de mot de passe actif
  1375. if ($conf->global->USER_PASSWORD_GENERATED != 'none')
  1376. {
  1377. if ($object->statut == 0)
  1378. {
  1379. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("ReinitPassword").'</a></div>';
  1380. }
  1381. elseif (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
  1382. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1383. {
  1384. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=password">'.$langs->trans("ReinitPassword").'</a></div>';
  1385. }
  1386. if ($object->statut == 0)
  1387. {
  1388. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("UserDisabled")).'">'.$langs->trans("SendNewPassword").'</a></div>';
  1389. }
  1390. else if (($user->id != $id && $caneditpassword) && $object->login && !$object->ldap_sid &&
  1391. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1392. {
  1393. if ($object->email) print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=passwordsend">'.$langs->trans("SendNewPassword").'</a></div>';
  1394. else print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("NoEMail")).'">'.$langs->trans("SendNewPassword").'</a></div>';
  1395. }
  1396. }
  1397. // Activer
  1398. if ($user->id <> $id && $candisableuser && $object->statut == 0 &&
  1399. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1400. {
  1401. print '<div class="inline-block divButAction"><a class="butAction" href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=enable">'.$langs->trans("Reactivate").'</a></div>';
  1402. }
  1403. // Desactiver
  1404. if ($user->id <> $id && $candisableuser && $object->statut == 1 &&
  1405. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1406. {
  1407. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=disable&amp;id='.$object->id.'">'.$langs->trans("DisableUser").'</a></div>';
  1408. }
  1409. // Delete
  1410. if ($user->id <> $id && $candisableuser &&
  1411. ((empty($conf->multicompany->enabled) && $object->entity == $user->entity) || ! $user->entity || ($object->entity == $conf->entity) || ($conf->multicompany->transverse_mode && $conf->entity == 1)))
  1412. {
  1413. if ($user->admin || ! $object->admin) // If user edited is admin, delete is possible on for an admin
  1414. {
  1415. print '<div class="inline-block divButAction"><a class="butActionDelete" href="'.$_SERVER['PHP_SELF'].'?action=delete&amp;id='.$object->id.'">'.$langs->trans("DeleteUser").'</a></div>';
  1416. }
  1417. else
  1418. {
  1419. print '<div class="inline-block divButAction"><a class="butActionRefused" href="#" title="'.dol_escape_htmltag($langs->trans("MustBeAdminToDeleteOtherAdmin")).'">'.$langs->trans("DeleteUser").'</a></div>';
  1420. }
  1421. }
  1422. print "</div>\n";
  1423. print "<br>\n";
  1424. /*
  1425. * Liste des groupes dans lequel est l'utilisateur
  1426. */
  1427. if ($canreadgroup)
  1428. {
  1429. print_fiche_titre($langs->trans("ListOfGroupsForUser"),'','');
  1430. // On selectionne les groupes auquel fait parti le user
  1431. $exclude = array();
  1432. $usergroup=new UserGroup($db);
  1433. $groupslist = $usergroup->listGroupsForUser($object->id);
  1434. if (! empty($groupslist))
  1435. {
  1436. if (! (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode)))
  1437. {
  1438. foreach($groupslist as $groupforuser)
  1439. {
  1440. $exclude[]=$groupforuser->id;
  1441. }
  1442. }
  1443. }
  1444. if ($caneditgroup)
  1445. {
  1446. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$id.'" method="POST">'."\n";
  1447. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'" />';
  1448. print '<input type="hidden" name="action" value="addgroup" />';
  1449. print '<table class="noborder" width="100%">'."\n";
  1450. print '<tr class="liste_titre"><th class="liste_titre" width="25%">'.$langs->trans("GroupsToAdd").'</th>'."\n";
  1451. print '<th>';
  1452. print $form->select_dolgroups('', 'group', 1, $exclude, 0, '', '', $object->entity);
  1453. print ' &nbsp; ';
  1454. // Multicompany
  1455. if (! empty($conf->multicompany->enabled))
  1456. {
  1457. if ($conf->entity == 1 && $conf->multicompany->transverse_mode)
  1458. {
  1459. print '</td><td>'.$langs->trans("Entity").'</td>';
  1460. print "<td>".$mc->select_entities($conf->entity);
  1461. }
  1462. else
  1463. {
  1464. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1465. }
  1466. }
  1467. else
  1468. {
  1469. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1470. }
  1471. print '<input type="submit" class="button" value="'.$langs->trans("Add").'" />';
  1472. print '</th></tr>'."\n";
  1473. print '</table></form>'."\n";
  1474. print '<br>';
  1475. }
  1476. /*
  1477. * Groups assigned to user
  1478. */
  1479. print '<table class="noborder" width="100%">';
  1480. print '<tr class="liste_titre">';
  1481. print '<td class="liste_titre" width="25%">'.$langs->trans("Groups").'</td>';
  1482. if(! empty($conf->multicompany->enabled) && !empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1483. {
  1484. print '<td class="liste_titre" width="25%">'.$langs->trans("Entity").'</td>';
  1485. }
  1486. print "<td>&nbsp;</td></tr>\n";
  1487. if (! empty($groupslist))
  1488. {
  1489. $var=true;
  1490. foreach($groupslist as $group)
  1491. {
  1492. $var=!$var;
  1493. print "<tr ".$bc[$var].">";
  1494. print '<td>';
  1495. if ($caneditgroup)
  1496. {
  1497. print '<a href="'.DOL_URL_ROOT.'/user/group/card.php?id='.$group->id.'">'.img_object($langs->trans("ShowGroup"),"group").' '.$group->name.'</a>';
  1498. }
  1499. else
  1500. {
  1501. print img_object($langs->trans("ShowGroup"),"group").' '.$group->name;
  1502. }
  1503. print '</td>';
  1504. if (! empty($conf->multicompany->enabled) && ! empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1505. {
  1506. print '<td class="valeur">';
  1507. if (! empty($group->usergroup_entity))
  1508. {
  1509. $nb=0;
  1510. foreach($group->usergroup_entity as $group_entity)
  1511. {
  1512. $mc->getInfo($group_entity);
  1513. print ($nb > 0 ? ', ' : '').$mc->label;
  1514. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'&amp;entity='.$group_entity.'">';
  1515. print img_delete($langs->trans("RemoveFromGroup"));
  1516. print '</a>';
  1517. $nb++;
  1518. }
  1519. }
  1520. }
  1521. print '<td align="right">';
  1522. if ($caneditgroup && empty($conf->multicompany->transverse_mode))
  1523. {
  1524. print '<a href="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'&amp;action=removegroup&amp;group='.$group->id.'">';
  1525. print img_delete($langs->trans("RemoveFromGroup"));
  1526. print '</a>';
  1527. }
  1528. else
  1529. {
  1530. print "&nbsp;";
  1531. }
  1532. print "</td></tr>\n";
  1533. }
  1534. }
  1535. else
  1536. {
  1537. print '<tr '.$bc[false].'><td colspan="3">'.$langs->trans("None").'</td></tr>';
  1538. }
  1539. print "</table>";
  1540. print "<br>";
  1541. }
  1542. }
  1543. /*
  1544. * Fiche en mode edition
  1545. */
  1546. if ($action == 'edit' && ($canedituser || $caneditfield || $caneditpassword || ($user->id == $object->id)))
  1547. {
  1548. print '<form action="'.$_SERVER['PHP_SELF'].'?id='.$object->id.'" method="POST" name="updateuser" enctype="multipart/form-data">';
  1549. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  1550. print '<input type="hidden" name="action" value="update">';
  1551. print '<input type="hidden" name="entity" value="'.$object->entity.'">';
  1552. dol_fiche_head($head, 'user', $title, 0, 'user');
  1553. $rowspan=17;
  1554. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER)) $rowspan++;
  1555. if (! empty($conf->societe->enabled)) $rowspan++;
  1556. if (! empty($conf->adherent->enabled)) $rowspan++;
  1557. if (! empty($conf->skype->enabled)) $rowspan++;
  1558. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read)) $rowspan = $rowspan+3;
  1559. if (! empty($conf->agenda->enabled)) $rowspan++;
  1560. print '<table width="100%" class="border">';
  1561. print '<tr><td width="25%">'.$langs->trans("Ref").'</td>';
  1562. print '<td colspan="2">';
  1563. print $object->id;
  1564. print '</td>';
  1565. print '</tr>';
  1566. // Lastname
  1567. print "<tr>";
  1568. print '<td class="fieldrequired">'.$langs->trans("Lastname").'</td>';
  1569. print '<td>';
  1570. if ($caneditfield && !$object->ldap_sid)
  1571. {
  1572. print '<input size="30" type="text" class="flat" name="lastname" value="'.$object->lastname.'">';
  1573. }
  1574. else
  1575. {
  1576. print '<input type="hidden" name="lastname" value="'.$object->lastname.'">';
  1577. print $object->lastname;
  1578. }
  1579. print '</td>';
  1580. // Photo
  1581. print '<td align="center" valign="middle" width="25%" rowspan="'.$rowspan.'">';
  1582. print $form->showphoto('userphoto',$object,100,0,$caneditfield);
  1583. print '</td>';
  1584. print '</tr>';
  1585. // Firstname
  1586. print "<tr>".'<td>'.$langs->trans("Firstname").'</td>';
  1587. print '<td>';
  1588. if ($caneditfield && !$object->ldap_sid)
  1589. {
  1590. print '<input size="30" type="text" class="flat" name="firstname" value="'.$object->firstname.'">';
  1591. }
  1592. else
  1593. {
  1594. print '<input type="hidden" name="firstname" value="'.$object->firstname.'">';
  1595. print $object->firstname;
  1596. }
  1597. print '</td></tr>';
  1598. // Position/Job
  1599. print '<tr><td>'.$langs->trans("PostOrFunction").'</td>';
  1600. print '<td>';
  1601. if ($caneditfield)
  1602. {
  1603. print '<input size="30" type="text" name="job" value="'.$object->job.'">';
  1604. }
  1605. else
  1606. {
  1607. print '<input type="hidden" name="job" value="'.$object->job.'">';
  1608. print $object->job;
  1609. }
  1610. print '</td></tr>';
  1611. // Gender
  1612. print '<tr><td>'.$langs->trans("Gender").'</td>';
  1613. print '<td>';
  1614. $arraygender=array('man'=>$langs->trans("Genderman"),'woman'=>$langs->trans("Genderwoman"));
  1615. print $form->selectarray('gender', $arraygender, GETPOST('gender')?GETPOST('gender'):$object->gender, 1);
  1616. print '</td></tr>';
  1617. // Login
  1618. print "<tr>".'<td><span class="fieldrequired">'.$langs->trans("Login").'</span></td>';
  1619. print '<td>';
  1620. if ($user->admin && !$object->ldap_sid)
  1621. {
  1622. print '<input size="12" maxlength="24" type="text" class="flat" name="login" value="'.$object->login.'">';
  1623. }
  1624. else
  1625. {
  1626. print '<input type="hidden" name="login" value="'.$object->login.'">';
  1627. print $object->login;
  1628. }
  1629. print '</td>';
  1630. print '</tr>';
  1631. // Pass
  1632. print '<tr><td>'.$langs->trans("Password").'</td>';
  1633. print '<td>';
  1634. if ($object->ldap_sid)
  1635. {
  1636. $text=$langs->trans("DomainPassword");
  1637. }
  1638. else if ($caneditpassword)
  1639. {
  1640. $text='<input size="12" maxlength="32" type="password" class="flat" name="password" value="'.$object->pass.'" autocomplete="off">';
  1641. if ($dolibarr_main_authentication && $dolibarr_main_authentication == 'http')
  1642. {
  1643. $text=$form->textwithpicto($text,$langs->trans("DolibarrInHttpAuthenticationSoPasswordUseless",$dolibarr_main_authentication),1,'warning');
  1644. }
  1645. }
  1646. else
  1647. {
  1648. $text=preg_replace('/./i','*',$object->pass);
  1649. }
  1650. print $text;
  1651. print "</td></tr>\n";
  1652. // API key
  1653. if(! empty($conf->api->enabled) && $user->admin) {
  1654. print '<tr><td>'.$langs->trans("ApiKey").'</td>';
  1655. print '<td>';
  1656. print '<input size="30" maxsize="32" type="text" id="api_key" name="api_key" value="'.$object->api_key.'" autocomplete="off">';
  1657. if (! empty($conf->use_javascript_ajax))
  1658. print '&nbsp;'.img_picto($langs->trans('Generate'), 'refresh', 'id="generate_api_key" class="linkobject"');
  1659. print '</td></tr>';
  1660. }
  1661. // Administrator
  1662. print '<tr><td>'.$langs->trans("Administrator").'</td>';
  1663. if ($object->societe_id > 0)
  1664. {
  1665. $langs->load("admin");
  1666. print '<td>';
  1667. print '<input type="hidden" name="admin" value="'.$object->admin.'">'.yn($object->admin);
  1668. print ' ('.$langs->trans("ExternalUser").')';
  1669. print '</td></tr>';
  1670. }
  1671. else
  1672. {
  1673. print '<td>';
  1674. $nbSuperAdmin = $user->getNbOfUsers('superadmin');
  1675. if ($user->admin
  1676. && ($user->id != $object->id) // Don't downgrade ourself
  1677. && ($object->entity > 0 || $nbSuperAdmin > 1) // Don't downgrade a superadmin if alone
  1678. )
  1679. {
  1680. print $form->selectyesno('admin',$object->admin,1);
  1681. if (! empty($conf->multicompany->enabled) && ! $user->entity && empty($conf->multicompany->transverse_mode))
  1682. {
  1683. if ($conf->use_javascript_ajax)
  1684. {
  1685. print '<script type="text/javascript">
  1686. $(function() {
  1687. var admin = $("select[name=admin]").val();
  1688. if (admin == 0) {
  1689. $("input[name=superadmin]")
  1690. .prop("disabled", true)
  1691. .prop("checked", false);
  1692. }
  1693. if ($("input[name=superadmin]").is(":checked")) {
  1694. $("select[name=entity]")
  1695. .prop("disabled", true);
  1696. }
  1697. $("select[name=admin]").change(function() {
  1698. if ( $(this).val() == 0 ) {
  1699. $("input[name=superadmin]")
  1700. .prop("disabled", true)
  1701. .prop("checked", false);
  1702. $("select[name=entity]")
  1703. .prop("disabled", false);
  1704. } else {
  1705. $("input[name=superadmin]")
  1706. .prop("disabled", false);
  1707. }
  1708. });
  1709. $("input[name=superadmin]").change(function() {
  1710. if ( $(this).is(":checked")) {
  1711. $("select[name=entity]")
  1712. .prop("disabled", true);
  1713. } else {
  1714. $("select[name=entity]")
  1715. .prop("disabled", false);
  1716. }
  1717. });
  1718. });
  1719. </script>';
  1720. }
  1721. $checked=(($object->admin && ! $object->entity) ? ' checked' : '');
  1722. print '<input type="checkbox" name="superadmin" value="1"'.$checked.' /> '.$langs->trans("SuperAdministrator");
  1723. }
  1724. }
  1725. else
  1726. {
  1727. $yn = yn($object->admin);
  1728. print '<input type="hidden" name="admin" value="'.$object->admin.'">';
  1729. print '<input type="hidden" name="superadmin" value="'.(empty($object->entity) ? 1 : 0).'">';
  1730. if (! empty($conf->multicompany->enabled) && empty($object->entity)) print $form->textwithpicto($yn,$langs->trans("DontDowngradeSuperAdmin"),1,'warning');
  1731. else print $yn;
  1732. }
  1733. print '</td></tr>';
  1734. }
  1735. // Type
  1736. print '<tr><td width="25%">'.$langs->trans("Type").'</td>';
  1737. print '<td>';
  1738. if ($user->id == $object->id || ! $user->admin)
  1739. {
  1740. $type=$langs->trans("Internal");
  1741. if ($object->societe_id) $type=$langs->trans("External");
  1742. print $form->textwithpicto($type,$langs->trans("InternalExternalDesc"));
  1743. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1744. }
  1745. else
  1746. {
  1747. $type=0;
  1748. if ($object->contact_id) $type=$object->contact_id;
  1749. print $form->selectcontacts(0,$type,'contactid',2,'','',1,'',false,1);
  1750. if ($object->ldap_sid) print ' ('.$langs->trans("DomainUser").')';
  1751. }
  1752. print '</td></tr>';
  1753. // Tel pro
  1754. print "<tr>".'<td>'.$langs->trans("PhonePro").'</td>';
  1755. print '<td>';
  1756. if ($caneditfield && empty($object->ldap_sid))
  1757. {
  1758. print '<input size="20" type="text" name="office_phone" class="flat" value="'.$object->office_phone.'">';
  1759. }
  1760. else
  1761. {
  1762. print '<input type="hidden" name="office_phone" value="'.$object->office_phone.'">';
  1763. print $object->office_phone;
  1764. }
  1765. print '</td></tr>';
  1766. // Tel mobile
  1767. print "<tr>".'<td>'.$langs->trans("PhoneMobile").'</td>';
  1768. print '<td>';
  1769. if ($caneditfield && empty($object->ldap_sid))
  1770. {
  1771. print '<input size="20" type="text" name="user_mobile" class="flat" value="'.$object->user_mobile.'">';
  1772. }
  1773. else
  1774. {
  1775. print '<input type="hidden" name="user_mobile" value="'.$object->user_mobile.'">';
  1776. print $object->user_mobile;
  1777. }
  1778. print '</td></tr>';
  1779. // Fax
  1780. print "<tr>".'<td>'.$langs->trans("Fax").'</td>';
  1781. print '<td>';
  1782. if ($caneditfield && empty($object->ldap_sid))
  1783. {
  1784. print '<input size="20" type="text" name="office_fax" class="flat" value="'.$object->office_fax.'">';
  1785. }
  1786. else
  1787. {
  1788. print '<input type="hidden" name="office_fax" value="'.$object->office_fax.'">';
  1789. print $object->office_fax;
  1790. }
  1791. print '</td></tr>';
  1792. // Skype
  1793. if (! empty($conf->skype->enabled))
  1794. {
  1795. print '<tr><td>'.$langs->trans("Skype").'</td>';
  1796. print '<td>';
  1797. if ($caneditfield && empty($object->ldap_sid))
  1798. {
  1799. print '<input size="40" type="text" name="skype" class="flat" value="'.$object->skype.'">';
  1800. }
  1801. else
  1802. {
  1803. print '<input type="hidden" name="skype" value="'.$object->skype.'">';
  1804. print $object->skype;
  1805. }
  1806. print '</td></tr>';
  1807. }
  1808. // EMail
  1809. print "<tr>".'<td'.(! empty($conf->global->USER_MAIL_REQUIRED)?' class="fieldrequired"':'').'>'.$langs->trans("EMail").'</td>';
  1810. print '<td>';
  1811. if ($caneditfield && empty($object->ldap_sid))
  1812. {
  1813. print '<input size="40" type="text" name="email" class="flat" value="'.$object->email.'">';
  1814. }
  1815. else
  1816. {
  1817. print '<input type="hidden" name="email" value="'.$object->email.'">';
  1818. print $object->email;
  1819. }
  1820. print '</td></tr>';
  1821. // Signature
  1822. print "<tr>".'<td class="tdtop">'.$langs->trans("Signature").'</td>';
  1823. print '<td>';
  1824. if ($caneditfield)
  1825. {
  1826. require_once DOL_DOCUMENT_ROOT.'/core/class/doleditor.class.php';
  1827. $doleditor=new DolEditor('signature',$object->signature,'',138,'dolibarr_mailings','In',false,true,empty($conf->global->FCKEDITOR_ENABLE_USERSIGN)?0:1,ROWS_4,72);
  1828. print $doleditor->Create(1);
  1829. }
  1830. else
  1831. {
  1832. print dol_htmlentitiesbr($object->signature);
  1833. }
  1834. print '</td></tr>';
  1835. // OpenID url
  1836. if (isset($conf->file->main_authentication) && preg_match('/openid/',$conf->file->main_authentication) && ! empty($conf->global->MAIN_OPENIDURL_PERUSER))
  1837. {
  1838. print "<tr>".'<td>'.$langs->trans("OpenIDURL").'</td>';
  1839. print '<td>';
  1840. if ($caneditfield)
  1841. {
  1842. print '<input size="40" type="url" name="openid" class="flat" value="'.$object->openid.'">';
  1843. }
  1844. else
  1845. {
  1846. print '<input type="hidden" name="openid" value="'.$object->openid.'">';
  1847. print $object->openid;
  1848. }
  1849. print '</td></tr>';
  1850. }
  1851. // Hierarchy
  1852. print '<tr><td>'.$langs->trans("HierarchicalResponsible").'</td>';
  1853. print '<td>';
  1854. if ($caneditfield)
  1855. {
  1856. print $form->select_dolusers($object->fk_user,'fk_user',1,array($object->id),0,'',0,$object->entity);
  1857. }
  1858. else
  1859. {
  1860. print '<input type="hidden" name="fk_user" value="'.$object->fk_user.'">';
  1861. $huser=new User($db);
  1862. $huser->fetch($object->fk_user);
  1863. print $huser->getNomUrl(1);
  1864. }
  1865. print '</td>';
  1866. print "</tr>\n";
  1867. if (! empty($conf->salaries->enabled) && ! empty($user->rights->salaries->read))
  1868. {
  1869. $langs->load("salaries");
  1870. // THM
  1871. print '<tr><td>';
  1872. $text=$langs->trans("THM");
  1873. print $form->textwithpicto($text, $langs->trans("THMDescription"), 1, 'help', 'classthm');
  1874. print '</td>';
  1875. print '<td>';
  1876. print '<input size="8" type="text" name="thm" value="'.price2num(GETPOST('thm')?GETPOST('thm'):$object->thm).'">';
  1877. print '</td>';
  1878. print "</tr>\n";
  1879. // TJM
  1880. print '<tr><td>';
  1881. $text=$langs->trans("TJM");
  1882. print $form->textwithpicto($text, $langs->trans("TJMDescription"), 1, 'help', 'classthm');
  1883. print '</td>';
  1884. print '<td>';
  1885. print '<input size="8" type="text" name="tjm" value="'.price2num(GETPOST('tjm')?GETPOST('tjm'):$object->tjm).'">';
  1886. print '</td>';
  1887. print "</tr>\n";
  1888. // Salary
  1889. print '<tr><td>'.$langs->trans("Salary").'</td>';
  1890. print '<td>';
  1891. print '<input size="8" type="text" name="salary" value="'.price2num(GETPOST('salary')?GETPOST('salary'):$object->salary).'">';
  1892. print '</td>';
  1893. print "</tr>\n";
  1894. }
  1895. // Weeklyhours
  1896. print '<tr><td>'.$langs->trans("WeeklyHours").'</td>';
  1897. print '<td>';
  1898. print '<input size="8" type="text" name="weeklyhours" value="'.price2num(GETPOST('weeklyhours')?GETPOST('weeklyhours'):$object->weeklyhours).'">';
  1899. print '</td>';
  1900. print "</tr>\n";
  1901. // Accountancy code
  1902. if ($conf->salaries->enabled)
  1903. {
  1904. print "<tr>";
  1905. print '<td>'.$langs->trans("AccountancyCode").'</td>';
  1906. print '<td>';
  1907. if ($caneditfield)
  1908. {
  1909. print '<input size="30" type="text" class="flat" name="accountancy_code" value="'.$object->accountancy_code.'">';
  1910. }
  1911. else
  1912. {
  1913. print '<input type="hidden" name="accountancy_code" value="'.$object->accountancy_code.'">';
  1914. print $object->accountancy_code;
  1915. }
  1916. print '</td>';
  1917. print "</tr>";
  1918. }
  1919. // User color
  1920. if (! empty($conf->agenda->enabled))
  1921. {
  1922. print '<tr><td>'.$langs->trans("ColorUser").'</td>';
  1923. print '<td>';
  1924. print $formother->selectColor(GETPOST('color')?GETPOST('color'):$object->color, 'color', 'usercolorconfig', 1, '', 'hideifnotset');
  1925. print '</td></tr>';
  1926. }
  1927. // Status
  1928. print '<tr><td>'.$langs->trans("Status").'</td>';
  1929. print '<td>';
  1930. print $object->getLibStatut(4);
  1931. print '</td></tr>';
  1932. // Company / Contact
  1933. if (! empty($conf->societe->enabled))
  1934. {
  1935. print '<tr><td width="25%">'.$langs->trans("LinkToCompanyContact").'</td>';
  1936. print '<td>';
  1937. if ($object->societe_id > 0)
  1938. {
  1939. $societe = new Societe($db);
  1940. $societe->fetch($object->societe_id);
  1941. print $societe->getNomUrl(1,'');
  1942. if ($object->contact_id)
  1943. {
  1944. $contact = new Contact($db);
  1945. $contact->fetch($object->contact_id);
  1946. 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>';
  1947. }
  1948. }
  1949. else
  1950. {
  1951. print $langs->trans("ThisUserIsNot");
  1952. }
  1953. print ' ('.$langs->trans("UseTypeFieldToChange").')';
  1954. print '</td>';
  1955. print "</tr>\n";
  1956. }
  1957. // Module Adherent
  1958. if (! empty($conf->adherent->enabled))
  1959. {
  1960. $langs->load("members");
  1961. print '<tr><td width="25%">'.$langs->trans("LinkedToDolibarrMember").'</td>';
  1962. print '<td>';
  1963. if ($object->fk_member)
  1964. {
  1965. $adh=new Adherent($db);
  1966. $adh->fetch($object->fk_member);
  1967. $adh->ref=$adh->login; // Force to show login instead of id
  1968. print $adh->getNomUrl(1);
  1969. }
  1970. else
  1971. {
  1972. print $langs->trans("UserNotLinkedToMember");
  1973. }
  1974. print '</td>';
  1975. print "</tr>\n";
  1976. }
  1977. // Multicompany
  1978. // TODO check if user not linked with the current entity before change entity (thirdparty, invoice, etc.) !!
  1979. if (! empty($conf->multicompany->enabled) && is_object($mc))
  1980. {
  1981. if (empty($conf->multicompany->transverse_mode) && $conf->entity == 1 && $user->admin && ! $user->entity)
  1982. {
  1983. print "<tr>".'<td>'.$langs->trans("Entity").'</td>';
  1984. print "<td>".$mc->select_entities($object->entity, 'entity', '', 0, 1); // last parameter 1 means, show also a choice 0=>'all entities'
  1985. print "</td></tr>\n";
  1986. }
  1987. else
  1988. {
  1989. print '<input type="hidden" name="entity" value="'.$conf->entity.'" />';
  1990. }
  1991. }
  1992. // Other attributes
  1993. $parameters=array('colspan' => ' colspan="2"');
  1994. $reshook=$hookmanager->executeHooks('formObjectOptions',$parameters,$object,$action); // Note that $action and $object may have been modified by hook
  1995. if (empty($reshook) && ! empty($extrafields->attribute_label))
  1996. {
  1997. print $object->showOptionals($extrafields,'edit');
  1998. }
  1999. print '</table>';
  2000. dol_fiche_end();
  2001. print '<div align="center">';
  2002. print '<input value="'.$langs->trans("Save").'" class="button" type="submit" name="save">';
  2003. print '&nbsp; &nbsp; &nbsp;';
  2004. print '<input value="'.$langs->trans("Cancel").'" class="button" type="submit" name="cancel">';
  2005. print '</div>';
  2006. print '</form>';
  2007. }
  2008. if (! empty($conf->ldap->enabled) && ! empty($object->ldap_sid)) $ldap->close;
  2009. }
  2010. }
  2011. if (! empty($conf->api->enabled) && ! empty($conf->use_javascript_ajax))
  2012. {
  2013. print "\n".'<script type="text/javascript">';
  2014. print '$(document).ready(function () {
  2015. $("#generate_api_key").click(function() {
  2016. $.get( "'.DOL_URL_ROOT.'/core/ajax/security.php", {
  2017. action: \'getrandompassword\',
  2018. generic: true
  2019. },
  2020. function(token) {
  2021. $("#api_key").val(token);
  2022. });
  2023. });
  2024. });';
  2025. print '</script>';
  2026. }
  2027. llxFooter();
  2028. $db->close();