list.php 51 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304
  1. <?php
  2. /* Copyright (C) 2002-2005 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2021 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2017 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2015 Alexandre Spangaro <aspangaro@open-dsi.fr>
  6. * Copyright (C) 2016 Marcos García <marcosgdf@gmail.com>
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. */
  21. /**
  22. * \file htdocs/user/list.php
  23. * \ingroup core
  24. * \brief Page of users
  25. */
  26. // Load Dolibarr environment
  27. require '../main.inc.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  29. if (isModEnabled('categorie')) {
  30. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  31. }
  32. // Load translation files required by page
  33. $langs->loadLangs(array('users', 'companies', 'hrm', 'salaries'));
  34. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  35. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  36. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  37. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  38. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'userlist'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. $mode = GETPOST("mode", 'alpha');
  44. // Security check (for external users)
  45. $socid = 0;
  46. if ($user->socid > 0) {
  47. $socid = $user->socid;
  48. }
  49. // Load variable for pagination
  50. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  55. // If $page is not defined, or '' or -1 or if we click on clear filters
  56. $page = 0;
  57. }
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  62. $object = new User($db);
  63. $extrafields = new ExtraFields($db);
  64. $diroutputmassaction = $conf->user->dir_output.'/temp/massgeneration/'.$user->id;
  65. $hookmanager->initHooks(array('userlist'));
  66. // Fetch optionals attributes and labels
  67. $extrafields->fetch_name_optionals_label($object->table_element);
  68. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  69. if (!$sortfield) {
  70. $sortfield = "u.login";
  71. }
  72. if (!$sortorder) {
  73. $sortorder = "ASC";
  74. }
  75. // Initialize array of search criterias
  76. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  77. $search = array();
  78. foreach ($object->fields as $key => $val) {
  79. if (GETPOST('search_'.$key, 'alpha') !== '') {
  80. $search[$key] = GETPOST('search_'.$key, 'alpha');
  81. }
  82. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  83. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  84. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  85. }
  86. }
  87. $userstatic = new User($db);
  88. $companystatic = new Societe($db);
  89. $form = new Form($db);
  90. // List of fields to search into when doing a "search in all"
  91. $fieldstosearchall = array(
  92. 'u.login'=>"Login",
  93. 'u.lastname'=>"Lastname",
  94. 'u.firstname'=>"Firstname",
  95. 'u.accountancy_code'=>"AccountancyCode",
  96. 'u.office_phone'=>"PhonePro",
  97. 'u.user_mobile'=>"PhoneMobile",
  98. 'u.email'=>"EMail",
  99. 'u.note_public'=>"NotePublic",
  100. 'u.note_private'=>"NotePrivate"
  101. );
  102. if (!empty($conf->api->enabled)) {
  103. $fieldstosearchall['u.api_key'] = "ApiKey";
  104. }
  105. // Definition of fields for list
  106. $arrayfields = array(
  107. 'u.login'=>array('label'=>"Login", 'checked'=>1, 'position'=>10),
  108. 'u.lastname'=>array('label'=>"Lastname", 'checked'=>1, 'position'=>15),
  109. 'u.firstname'=>array('label'=>"Firstname", 'checked'=>1, 'position'=>20),
  110. 'u.entity'=>array('label'=>"Entity", 'checked'=>1, 'position'=>50, 'enabled'=>(isModEnabled('multicompany') && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE))),
  111. 'u.gender'=>array('label'=>"Gender", 'checked'=>0, 'position'=>22),
  112. 'u.employee'=>array('label'=>"Employee", 'checked'=>($contextpage == 'employeelist' ? 1 : 0), 'position'=>25),
  113. 'u.fk_user'=>array('label'=>"HierarchicalResponsible", 'checked'=>1, 'position'=>27),
  114. 'u.accountancy_code'=>array('label'=>"AccountancyCode", 'checked'=>0, 'position'=>30),
  115. 'u.office_phone'=>array('label'=>"PhonePro", 'checked'=>1, 'position'=>31),
  116. 'u.user_mobile'=>array('label'=>"PhoneMobile", 'checked'=>1, 'position'=>32),
  117. 'u.email'=>array('label'=>"EMail", 'checked'=>1, 'position'=>35),
  118. 'u.api_key'=>array('label'=>"ApiKey", 'checked'=>0, 'position'=>40, "enabled"=>(!empty($conf->api->enabled) && $user->admin)),
  119. 'u.fk_soc'=>array('label'=>"Company", 'checked'=>($contextpage == 'employeelist' ? 0 : 1), 'position'=>45),
  120. 'u.job'=>array('label'=>"PostOrFunction", 'checked'=>-1, 'position'=>50),
  121. 'u.salary'=>array('label'=>"Salary", 'checked'=>1, 'position'=>80, 'enabled'=>(!empty($conf->salaries->enabled) && $user->hasRight("salaries", "readall"))),
  122. 'u.datelastlogin'=>array('label'=>"LastConnexion", 'checked'=>1, 'position'=>100),
  123. 'u.datepreviouslogin'=>array('label'=>"PreviousConnexion", 'checked'=>0, 'position'=>110),
  124. 'u.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  125. 'u.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  126. 'u.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  127. );
  128. // Extra fields
  129. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  130. $object->fields = dol_sort_array($object->fields, 'position');
  131. $arrayfields = dol_sort_array($arrayfields, 'position');
  132. // Init search fields
  133. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  134. $search_user = GETPOST('search_user', 'alpha');
  135. $search_login = GETPOST('search_login', 'alpha');
  136. $search_lastname = GETPOST('search_lastname', 'alpha');
  137. $search_firstname = GETPOST('search_firstname', 'alpha');
  138. $search_gender = GETPOST('search_gender', 'alpha');
  139. $search_employee = GETPOST('search_employee', 'alpha');
  140. $search_accountancy_code = GETPOST('search_accountancy_code', 'alpha');
  141. $search_phonepro = GETPOST('search_phonepro', 'alpha');
  142. $search_phonemobile = GETPOST('search_phonemobile', 'alpha');
  143. $search_email = GETPOST('search_email', 'alpha');
  144. $search_api_key = GETPOST('search_api_key', 'alphanohtml');
  145. $search_statut = GETPOST('search_statut', 'intcomma');
  146. $search_thirdparty = GETPOST('search_thirdparty', 'alpha');
  147. $search_job = GETPOST('search_job', 'alpha');
  148. $search_warehouse = GETPOST('search_warehouse', 'alpha');
  149. $search_supervisor = GETPOST('search_supervisor', 'intcomma');
  150. $search_categ = GETPOST("search_categ", 'int');
  151. $searchCategoryUserOperator = 0;
  152. if (GETPOSTISSET('formfilteraction')) {
  153. $searchCategoryUserOperator = GETPOSTINT('search_category_user_operator');
  154. } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
  155. $searchCategoryUserOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  156. }
  157. $searchCategoryUserList = GETPOST('search_category_user_list', 'array');
  158. $catid = GETPOST('catid', 'int');
  159. if (!empty($catid) && empty($searchCategoryUserList)) {
  160. $searchCategoryUserList = array($catid);
  161. }
  162. $catid = GETPOST('catid', 'int');
  163. if (!empty($catid) && empty($search_categ)) {
  164. $search_categ = $catid;
  165. }
  166. // Default search
  167. if ($search_statut == '') {
  168. $search_statut = '1';
  169. }
  170. if ($contextpage == 'employeelist' && !GETPOSTISSET('search_employee')) {
  171. $search_employee = 1;
  172. }
  173. // Define value to know what current user can do on users
  174. $permissiontoadd = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
  175. $canreaduser = (!empty($user->admin) || $user->hasRight("user", "user", "read"));
  176. $canedituser = (!empty($user->admin) || $user->hasRight("user", "user", "write"));
  177. $candisableuser = (!empty($user->admin) || $user->hasRight("user", "user", "delete"));
  178. $canreadgroup = $canreaduser;
  179. $caneditgroup = $canedituser;
  180. if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  181. $canreadgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "read"));
  182. $caneditgroup = (!empty($user->admin) || $user->hasRight("user", "group_advance", "write"));
  183. }
  184. $error = 0;
  185. // Permission to list
  186. if ($contextpage == 'employeelist' && $search_employee == 1) {
  187. if (!$user->hasRight("salaries", "read")) {
  188. accessforbidden();
  189. }
  190. } else {
  191. if (!$user->hasRight("user", "user", "read") && empty($user->admin)) {
  192. accessforbidden();
  193. }
  194. }
  195. $childids = $user->getAllChildIds(1);
  196. /*
  197. * Actions
  198. */
  199. if (GETPOST('cancel', 'alpha')) {
  200. $action = 'list';
  201. $massaction = '';
  202. }
  203. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  204. $massaction = '';
  205. }
  206. $parameters = array();
  207. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  208. if ($reshook < 0) {
  209. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  210. }
  211. if (empty($reshook)) {
  212. // Selection of new fields
  213. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  214. // Purge search criteria
  215. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  216. $search_user = "";
  217. $search_login = "";
  218. $search_lastname = "";
  219. $search_firstname = "";
  220. $search_gender = "";
  221. $search_employee = "";
  222. $search_accountancy_code = "";
  223. $search_phonepro = "";
  224. $search_phonemobile = "";
  225. $search_email = "";
  226. $search_statut = "";
  227. $search_thirdparty = "";
  228. $search_job = "";
  229. $search_warehouse = "";
  230. $search_supervisor = "";
  231. $search_api_key = "";
  232. $search_datelastlogin = "";
  233. $search_datepreviouslogin = "";
  234. $search_date_creation = "";
  235. $search_date_update = "";
  236. $search_categ = 0;
  237. $toselect = array();
  238. $search_array_options = array();
  239. }
  240. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  241. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  242. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  243. }
  244. // Mass actions
  245. $objectclass = 'User';
  246. $objectlabel = 'User';
  247. $uploaddir = $conf->user->dir_output;
  248. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  249. // Disable or Enable records
  250. if (!$error && ($massaction == 'disable' || $massaction == 'reactivate') && $permissiontoadd) {
  251. $objecttmp = new User($db);
  252. if (!$error) {
  253. $db->begin();
  254. $nbok = 0;
  255. foreach ($toselect as $toselectid) {
  256. if ($toselectid == $user->id) {
  257. setEventMessages($langs->trans($massaction == 0 ? 'CantDisableYourself' : 'CanEnableYourself'), null, 'errors');
  258. $error++;
  259. break;
  260. }
  261. $result = $objecttmp->fetch($toselectid);
  262. if ($result > 0) {
  263. if ($objecttmp->admin) {
  264. setEventMessages($langs->trans($massaction == 0 ? 'CantDisableAnAdminUserWithMassActions' : 'CantEnableAnAdminUserWithMassActions', $objecttmp->login), null, 'errors');
  265. $error++;
  266. break;
  267. }
  268. $result = $objecttmp->setstatus($massaction == 'disable' ? 0 : 1);
  269. if ($result == 0) {
  270. // Nothing is done
  271. } elseif ($result < 0) {
  272. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  273. $error++;
  274. break;
  275. } else {
  276. $nbok++;
  277. }
  278. } else {
  279. setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
  280. $error++;
  281. break;
  282. }
  283. }
  284. if (!$error && !empty($conf->file->main_limit_users)) {
  285. $nb = $object->getNbOfUsers("active");
  286. if ($nb >= $conf->file->main_limit_users) {
  287. $error++;
  288. setEventMessages($langs->trans("YourQuotaOfUsersIsReached"), null, 'errors');
  289. }
  290. }
  291. if (!$error) {
  292. if ($nbok > 1) {
  293. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  294. } else {
  295. setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
  296. }
  297. $db->commit();
  298. } else {
  299. $db->rollback();
  300. }
  301. }
  302. }
  303. }
  304. /*
  305. * View
  306. */
  307. $formother = new FormOther($db);
  308. $user2 = new User($db);
  309. $now = dol_now();
  310. $help_url = 'EN:Module_Users|FR:Module_Utilisateurs|ES:M&oacute;dulo_Usuarios|DE:Modul_Benutzer';
  311. if ($contextpage == 'employeelist' && $search_employee == 1) {
  312. $title = $langs->trans("Employees");
  313. } else {
  314. $title = $langs->trans("Users");
  315. }
  316. $morejs = array();
  317. $morecss = array();
  318. $morehtmlright = "";
  319. // Build and execute select
  320. // --------------------------------------------------------------------
  321. $sql = "SELECT DISTINCT u.rowid, u.lastname, u.firstname, u.admin, u.fk_soc, u.login, u.office_phone, u.user_mobile, u.email, u.api_key, u.accountancy_code, u.gender, u.employee, u.photo,";
  322. $sql .= " u.fk_user,";
  323. $sql .= " u.job, u.salary, u.datelastlogin, u.datepreviouslogin,";
  324. $sql .= " u.ldap_sid, u.statut as status, u.entity,";
  325. $sql .= " u.tms as date_update, u.datec as date_creation,";
  326. $sql .= " u2.rowid as id2, u2.login as login2, u2.firstname as firstname2, u2.lastname as lastname2, u2.admin as admin2, u2.fk_soc as fk_soc2, u2.office_phone as ofice_phone2, u2.user_mobile as user_mobile2, u2.email as email2, u2.gender as gender2, u2.photo as photo2, u2.entity as entity2, u2.statut as status2,";
  327. $sql .= " s.nom as name, s.canvas";
  328. // Add fields from extrafields
  329. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  330. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  331. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  332. }
  333. }
  334. // Add fields from hooks
  335. $parameters = array();
  336. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  337. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  338. $sql = preg_replace('/,\s*$/', '', $sql);
  339. $sqlfields = $sql; // $sql fields to remove for count total
  340. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as u";
  341. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  342. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (u.rowid = ef.fk_object)";
  343. }
  344. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON u.fk_soc = s.rowid";
  345. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."user as u2 ON u.fk_user = u2.rowid";
  346. // Add table from hooks
  347. $parameters = array();
  348. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  349. $sql .= $hookmanager->resPrint;
  350. if ($reshook > 0) {
  351. $sql .= $hookmanager->resPrint;
  352. }
  353. $sql .= " WHERE u.entity IN (".getEntity($object->element).")";
  354. if ($socid > 0) {
  355. $sql .= " AND u.fk_soc = ".((int) $socid);
  356. }
  357. //if ($search_user != '') $sql.=natural_search(array('u.login', 'u.lastname', 'u.firstname'), $search_user);
  358. if ($search_supervisor > 0) {
  359. $sql .= " AND u.fk_user IN (".$db->sanitize($search_supervisor).")";
  360. }
  361. if ($search_thirdparty != '') {
  362. $sql .= natural_search(array('s.nom'), $search_thirdparty);
  363. }
  364. if ($search_warehouse > 0) {
  365. $sql .= natural_search(array('u.fk_warehouse'), $search_warehouse);
  366. }
  367. if ($search_login != '') {
  368. $sql .= natural_search("u.login", $search_login);
  369. }
  370. if ($search_lastname != '') {
  371. $sql .= natural_search("u.lastname", $search_lastname);
  372. }
  373. if ($search_firstname != '') {
  374. $sql .= natural_search("u.firstname", $search_firstname);
  375. }
  376. if ($search_gender != '' && $search_gender != '-1') {
  377. $sql .= " AND u.gender = '".$db->escape($search_gender)."'"; // Cannot use natural_search as looking for %man% also includes woman
  378. }
  379. if (is_numeric($search_employee) && $search_employee >= 0) {
  380. $sql .= ' AND u.employee = '.(int) $search_employee;
  381. }
  382. if ($search_accountancy_code != '') {
  383. $sql .= natural_search("u.accountancy_code", $search_accountancy_code);
  384. }
  385. if ($search_phonepro != '') {
  386. $sql .= natural_search("u.office_phone", $search_phonepro);
  387. }
  388. if ($search_phonemobile != '') {
  389. $sql .= natural_search("u.user_mobile", $search_phonemobile);
  390. }
  391. if ($search_email != '') {
  392. $sql .= natural_search("u.email", $search_email);
  393. }
  394. if ($search_api_key != '') {
  395. $sql .= natural_search("u.api_key", $search_api_key);
  396. }
  397. if ($search_job != '') {
  398. $sql .= natural_search(array('u.job'), $search_job);
  399. }
  400. if ($search_statut != '' && $search_statut >= 0) {
  401. $sql .= " AND u.statut IN (".$db->sanitize($search_statut).")";
  402. }
  403. if ($sall) {
  404. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  405. }
  406. // Search for tag/category ($searchCategoryUserList is an array of ID)
  407. $searchCategoryUserList = array($search_categ);
  408. if (!empty($searchCategoryUserList)) {
  409. $searchCategoryUserSqlList = array();
  410. $listofcategoryid = '';
  411. foreach ($searchCategoryUserList as $searchCategoryUser) {
  412. if (intval($searchCategoryUser) == -2) {
  413. $searchCategoryUserSqlList[] = "NOT EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user)";
  414. } elseif (intval($searchCategoryUser) > 0) {
  415. if ($searchCategoryUserOperator == 0) {
  416. $searchCategoryUserSqlList[] = " EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user AND ck.fk_categorie = ".((int) $searchCategoryUser).")";
  417. } else {
  418. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryUser);
  419. }
  420. }
  421. }
  422. if ($listofcategoryid) {
  423. $searchCategoryUserSqlList[] = " EXISTS (SELECT ck.fk_user FROM ".MAIN_DB_PREFIX."categorie_user as ck WHERE u.rowid = ck.fk_user AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  424. }
  425. if ($searchCategoryUserOperator == 1) {
  426. if (!empty($searchCategoryUserSqlList)) {
  427. $sql .= " AND (".implode(' OR ', $searchCategoryUserSqlList).")";
  428. }
  429. } else {
  430. if (!empty($searchCategoryUserSqlList)) {
  431. $sql .= " AND (".implode(' AND ', $searchCategoryUserSqlList).")";
  432. }
  433. }
  434. }
  435. if ($search_warehouse > 0) {
  436. $sql .= " AND u.fk_warehouse = ".((int) $search_warehouse);
  437. }
  438. if ($contextpage == 'employeelist' && !$user->hasRight("salaries", "readall")) {
  439. $sql .= " AND u.rowid IN (".$db->sanitize(join(',', $childids)).")";
  440. }
  441. // Add where from extra fields
  442. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  443. // Add where from hooks
  444. $parameters = array();
  445. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  446. $sql .= $hookmanager->resPrint;
  447. // Count total nb of records
  448. $nbtotalofrecords = '';
  449. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  450. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  451. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  452. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  453. $resql = $db->query($sqlforcount);
  454. if ($resql) {
  455. $objforcount = $db->fetch_object($resql);
  456. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  457. } else {
  458. dol_print_error($db);
  459. }
  460. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  461. $page = 0;
  462. $offset = 0;
  463. }
  464. $db->free($resql);
  465. }
  466. // Complete request and execute it with limit
  467. $sql .= $db->order($sortfield, $sortorder);
  468. if ($limit) {
  469. $sql .= $db->plimit($limit + 1, $offset);
  470. }
  471. $resql = $db->query($sql);
  472. if (!$resql) {
  473. dol_print_error($db);
  474. exit;
  475. }
  476. $num = $db->num_rows($resql);
  477. // Direct jump if only one record found
  478. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  479. $obj = $db->fetch_object($resql);
  480. $id = $obj->rowid;
  481. header("Location: ".DOL_URL_ROOT.'/user/card.php?id='.$id);
  482. exit;
  483. }
  484. // Output page
  485. // --------------------------------------------------------------------
  486. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  487. $arrayofselected = is_array($toselect) ? $toselect : array();
  488. $param = '';
  489. if (!empty($mode)) {
  490. $param .= '&amp;mode='.urlencode($mode);
  491. }
  492. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  493. $param .= '&amp;contextpage='.urlencode($contextpage);
  494. }
  495. if ($limit > 0 && $limit != $conf->liste_limit) {
  496. $param .= '&amp;limit='.urlencode($limit);
  497. }
  498. if ($sall != '') {
  499. $param .= '&amp;sall='.urlencode($sall);
  500. }
  501. if ($search_user != '') {
  502. $param .= "&amp;search_user=".urlencode($search_user);
  503. }
  504. if ($search_login != '') {
  505. $param .= "&amp;search_login=".urlencode($search_login);
  506. }
  507. if ($search_lastname != '') {
  508. $param .= "&amp;search_lastname=".urlencode($search_lastname);
  509. }
  510. if ($search_firstname != '') {
  511. $param .= "&amp;search_firstname=".urlencode($search_firstname);
  512. }
  513. if ($search_gender != '' && $search_gender != '-1') {
  514. $param .= "&amp;search_gender=".urlencode($search_gender);
  515. }
  516. if ($search_employee != '' && $search_employee != '-1') {
  517. $param .= "&amp;search_employee=".urlencode($search_employee);
  518. }
  519. if ($search_accountancy_code != '') {
  520. $param .= "&amp;search_accountancy_code=".urlencode($search_accountancy_code);
  521. }
  522. if ($search_phonepro != '') {
  523. $param .= "&amp;search_phonepro=".urlencode($search_phonepro);
  524. }
  525. if ($search_phonemobile != '') {
  526. $param .= "&amp;search_phonemobile=".urlencode($search_phonemobile);
  527. }
  528. if ($search_email != '') {
  529. $param .= "&amp;search_email=".urlencode($search_email);
  530. }
  531. if ($search_api_key != '') {
  532. $param .= "&amp;search_api_key=".urlencode($search_api_key);
  533. }
  534. if ($search_supervisor > 0) {
  535. $param .= "&amp;search_supervisor=".urlencode($search_supervisor);
  536. }
  537. if ($search_statut != '') {
  538. $param .= "&amp;search_statut=".urlencode($search_statut);
  539. }
  540. if ($optioncss != '') {
  541. $param .= '&amp;optioncss='.urlencode($optioncss);
  542. }
  543. if ($search_categ > 0) {
  544. $param .= '&amp;search_categ='.urlencode($search_categ);
  545. }
  546. if ($search_warehouse > 0) {
  547. $param .= '&amp;search_warehouse='.urlencode($search_warehouse);
  548. }
  549. // Add $param from extra fields
  550. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  551. // List of mass actions available
  552. $arrayofmassactions = array();
  553. if ($permissiontoadd) {
  554. $arrayofmassactions['disable'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("DisableUser");
  555. }
  556. if ($permissiontoadd) {
  557. $arrayofmassactions['reactivate'] = img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Reactivate");
  558. }
  559. if (isModEnabled('category') && $permissiontoadd) {
  560. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  561. }
  562. if ($permissiontoadd) {
  563. $arrayofmassactions['presetsupervisor'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("SetSupervisor");
  564. }
  565. //if ($permissiontodelete) $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  566. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete', 'preaffecttag', 'presetsupervisor'))) {
  567. $arrayofmassactions = array();
  568. }
  569. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  570. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  571. if ($optioncss != '') {
  572. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  573. }
  574. print '<input type="hidden" name="token" value="'.newToken().'">';
  575. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  576. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  577. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  578. print '<input type="hidden" name="page" value="'.$page.'">';
  579. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  580. print '<input type="hidden" name="mode" value="'.$mode.'">';
  581. $url = DOL_URL_ROOT.'/user/card.php?action=create'.($contextpage == 'employeelist' ? '&search_employee=1' : '').'&leftmenu=';
  582. if (!empty($socid)) {
  583. $url .= '&socid='.urlencode($socid);
  584. }
  585. $newcardbutton = '';
  586. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  587. $newcardbutton .= dolGetButtonTitle($langs->trans('HierarchicView'), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php?mode=hierarchy'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', (($mode == 'hierarchy') ? 2 : 1), array('morecss'=>'reposition'));
  588. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  589. $newcardbutton .= dolGetButtonTitleSeparator();
  590. $newcardbutton .= dolGetButtonTitle($langs->trans('NewUser'), '', 'fa fa-plus-circle', $url, '', $permissiontoadd);
  591. /*$moreparam = array('morecss'=>'btnTitleSelected');
  592. $morehtmlright = dolGetButtonTitle($langs->trans("List"), '', 'fa fa-list paddingleft imgforviewmode', DOL_URL_ROOT.'/user/list.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''), '', 1, $moreparam);
  593. $moreparam = array('morecss'=>'marginleftonly');
  594. $morehtmlright .= dolGetButtonTitle($langs->trans("HierarchicView"), '', 'fa fa-stream paddingleft imgforviewmode', DOL_URL_ROOT.'/user/hierarchy.php'.(($search_statut != '' && $search_statut >= 0) ? '?search_statut='.$search_statut : ''), '', 1, $moreparam);
  595. */
  596. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'user', 0, $morehtmlright.' '.$newcardbutton, '', $limit, 0, 0, 1);
  597. // Add code for pre mass action (confirmation or email presend form)
  598. $topicmail = "SendUserRef";
  599. $modelmail = "user";
  600. $objecttmp = new User($db);
  601. $trackid = 'use'.$object->id;
  602. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  603. if (!empty($catid)) {
  604. print "<div id='ways'>";
  605. $c = new Categorie($db);
  606. $ways = $c->print_all_ways(' &gt; ', 'user/list.php');
  607. print " &gt; ".$ways[0]."<br>\n";
  608. print "</div><br>";
  609. }
  610. if ($search_all) {
  611. foreach ($fieldstosearchall as $key => $val) {
  612. $fieldstosearchall[$key] = $langs->trans($val);
  613. }
  614. print '<!-- Search done like if USER_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  615. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  616. }
  617. $moreforfilter = '';
  618. /*$moreforfilter.='<div class="divsearchfield">';
  619. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  620. $moreforfilter.= '</div>';*/
  621. // Filter on categories
  622. if (isModEnabled('categorie') && $user->hasRight("categorie", "read")) {
  623. $moreforfilter .= '<div class="divsearchfield">';
  624. $tmptitle = $langs->trans('Category');
  625. $moreforfilter .= img_picto($langs->trans("Category"), 'category', 'class="pictofixedwidth"').$formother->select_categories(Categorie::TYPE_USER, $search_categ, 'search_categ', 1, $tmptitle);
  626. $moreforfilter .= '</div>';
  627. }
  628. // Filter on warehouse
  629. if (isModEnabled('stock') && !empty($conf->global->MAIN_DEFAULT_WAREHOUSE_USER)) {
  630. require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
  631. $formproduct = new FormProduct($db);
  632. $moreforfilter .= '<div class="divsearchfield">';
  633. $tmptitle = $langs->trans('Warehouse');
  634. $moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', $tmptitle, 0, 0, $tmptitle);
  635. $moreforfilter .= '</div>';
  636. }
  637. $parameters = array();
  638. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  639. if (empty($reshook)) {
  640. $moreforfilter .= $hookmanager->resPrint;
  641. } else {
  642. $moreforfilter = $hookmanager->resPrint;
  643. }
  644. if (!empty($moreforfilter)) {
  645. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  646. print $moreforfilter;
  647. print '</div>';
  648. }
  649. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  650. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  651. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  652. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  653. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  654. // Fields title search
  655. // --------------------------------------------------------------------
  656. print '<tr class="liste_titre">';
  657. // Action column
  658. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  659. print '<td class="liste_titre maxwidthsearch">';
  660. $searchpicto = $form->showFilterButtons('left');
  661. print $searchpicto;
  662. print '</td>';
  663. }
  664. if (!empty($arrayfields['u.login']['checked'])) {
  665. print '<td class="liste_titre"><input type="text" name="search_login" class="maxwidth50" value="'.$search_login.'"></td>';
  666. }
  667. if (!empty($arrayfields['u.lastname']['checked'])) {
  668. print '<td class="liste_titre"><input type="text" name="search_lastname" class="maxwidth50" value="'.$search_lastname.'"></td>';
  669. }
  670. if (!empty($arrayfields['u.firstname']['checked'])) {
  671. print '<td class="liste_titre"><input type="text" name="search_firstname" class="maxwidth50" value="'.$search_firstname.'"></td>';
  672. }
  673. if (!empty($arrayfields['u.gender']['checked'])) {
  674. print '<td class="liste_titre center">';
  675. $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
  676. print $form->selectarray('search_gender', $arraygender, $search_gender, 1);
  677. print '</td>';
  678. }
  679. if (!empty($arrayfields['u.employee']['checked'])) {
  680. print '<td class="liste_titre">';
  681. print $form->selectyesno('search_employee', $search_employee, 1, false, 1);
  682. print '</td>';
  683. }
  684. // Supervisor
  685. if (!empty($arrayfields['u.fk_user']['checked'])) {
  686. print '<td class="liste_titre">';
  687. print $form->select_dolusers($search_supervisor, 'search_supervisor', 1, array(), 0, '', 0, 0, 0, 0, '', 0, '', 'maxwidth150');
  688. print '</td>';
  689. }
  690. if (!empty($arrayfields['u.accountancy_code']['checked'])) {
  691. print '<td class="liste_titre"><input type="text" name="search_accountancy_code" class="maxwidth50" value="'.$search_accountancy_code.'"></td>';
  692. }
  693. if (!empty($arrayfields['u.office_phone']['checked'])) {
  694. print '<td class="liste_titre"><input type="text" name="search_phonepro" class="maxwidth50" value="'.$search_phonepro.'"></td>';
  695. }
  696. if (!empty($arrayfields['u.user_mobile']['checked'])) {
  697. print '<td class="liste_titre"><input type="text" name="search_phonemobile" class="maxwidth50" value="'.$search_phonemobile.'"></td>';
  698. }
  699. if (!empty($arrayfields['u.email']['checked'])) {
  700. print '<td class="liste_titre"><input type="text" name="search_email" class="maxwidth75" value="'.$search_email.'"></td>';
  701. }
  702. if (!empty($arrayfields['u.api_key']['checked'])) {
  703. print '<td class="liste_titre"><input type="text" name="search_api_key" class="maxwidth50" value="'.$search_api_key.'"></td>';
  704. }
  705. if (!empty($arrayfields['u.fk_soc']['checked'])) {
  706. print '<td class="liste_titre"><input type="text" name="search_thirdparty" class="maxwidth75" value="'.$search_thirdparty.'"></td>';
  707. }
  708. if (!empty($arrayfields['u.entity']['checked'])) {
  709. print '<td class="liste_titre"></td>';
  710. }
  711. if (!empty($arrayfields['u.job']['checked'])) {
  712. print '<td class="liste_titre"><input type="text" name="search_job" class="maxwidth75" value="'.$search_job.'"></td>';
  713. }
  714. if (!empty($arrayfields['u.salary']['checked'])) {
  715. print '<td class="liste_titre"></td>';
  716. }
  717. if (!empty($arrayfields['u.datelastlogin']['checked'])) {
  718. print '<td class="liste_titre"></td>';
  719. }
  720. if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
  721. print '<td class="liste_titre"></td>';
  722. }
  723. // Extra fields
  724. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  725. // Fields from hook
  726. $parameters = array('arrayfields'=>$arrayfields);
  727. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  728. print $hookmanager->resPrint;
  729. if (!empty($arrayfields['u.datec']['checked'])) {
  730. // Date creation
  731. print '<td class="liste_titre">';
  732. print '</td>';
  733. }
  734. if (!empty($arrayfields['u.tms']['checked'])) {
  735. // Date modification
  736. print '<td class="liste_titre">';
  737. print '</td>';
  738. }
  739. if (!empty($arrayfields['u.statut']['checked'])) {
  740. // Status
  741. print '<td class="liste_titre center">';
  742. print $form->selectarray('search_statut', array('-1'=>'', '0'=>$langs->trans('Disabled'), '1'=>$langs->trans('Enabled')), $search_statut, 0, 0, 0, '', 0, 0, 0, '', 'search_status minwidth75imp maxwidth125 onrightofpage');
  743. print '</td>';
  744. }
  745. // Action column
  746. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  747. print '<td class="liste_titre maxwidthsearch">';
  748. $searchpicto = $form->showFilterButtons();
  749. print $searchpicto;
  750. print '</td>';
  751. }
  752. print '</tr>'."\n";
  753. $totalarray = array();
  754. $totalarray['nbfield'] = 0;
  755. // Fields title label
  756. // --------------------------------------------------------------------
  757. print '<tr class="liste_titre">';
  758. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  759. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  760. $totalarray['nbfield']++;
  761. }
  762. if (!empty($arrayfields['u.login']['checked'])) {
  763. print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER['PHP_SELF'], "u.login", $param, "", "", $sortfield, $sortorder);
  764. $totalarray['nbfield']++;
  765. }
  766. if (!empty($arrayfields['u.lastname']['checked'])) {
  767. print_liste_field_titre("Lastname", $_SERVER['PHP_SELF'], "u.lastname", $param, "", "", $sortfield, $sortorder);
  768. $totalarray['nbfield']++;
  769. }
  770. if (!empty($arrayfields['u.firstname']['checked'])) {
  771. print_liste_field_titre("FirstName", $_SERVER['PHP_SELF'], "u.firstname", $param, "", "", $sortfield, $sortorder);
  772. $totalarray['nbfield']++;
  773. }
  774. if (!empty($arrayfields['u.gender']['checked'])) {
  775. print_liste_field_titre("Gender", $_SERVER['PHP_SELF'], "u.gender", $param, "", "", $sortfield, $sortorder, 'center ');
  776. $totalarray['nbfield']++;
  777. }
  778. if (!empty($arrayfields['u.employee']['checked'])) {
  779. print_liste_field_titre("Employee", $_SERVER['PHP_SELF'], "u.employee", $param, "", "", $sortfield, $sortorder, 'center ');
  780. $totalarray['nbfield']++;
  781. }
  782. if (!empty($arrayfields['u.fk_user']['checked'])) {
  783. print_liste_field_titre("HierarchicalResponsible", $_SERVER['PHP_SELF'], "u.fk_user", $param, "", "", $sortfield, $sortorder);
  784. $totalarray['nbfield']++;
  785. }
  786. if (!empty($arrayfields['u.accountancy_code']['checked'])) {
  787. print_liste_field_titre("AccountancyCode", $_SERVER['PHP_SELF'], "u.accountancy_code", $param, "", "", $sortfield, $sortorder);
  788. $totalarray['nbfield']++;
  789. }
  790. if (!empty($arrayfields['u.office_phone']['checked'])) {
  791. print_liste_field_titre("PhonePro", $_SERVER['PHP_SELF'], "u.office_phone", $param, "", "", $sortfield, $sortorder);
  792. $totalarray['nbfield']++;
  793. }
  794. if (!empty($arrayfields['u.user_mobile']['checked'])) {
  795. print_liste_field_titre("PhoneMobile", $_SERVER['PHP_SELF'], "u.user_mobile", $param, "", "", $sortfield, $sortorder);
  796. $totalarray['nbfield']++;
  797. }
  798. if (!empty($arrayfields['u.email']['checked'])) {
  799. print_liste_field_titre("EMail", $_SERVER['PHP_SELF'], "u.email", $param, "", "", $sortfield, $sortorder);
  800. $totalarray['nbfield']++;
  801. }
  802. if (!empty($arrayfields['u.api_key']['checked'])) {
  803. print_liste_field_titre("ApiKey", $_SERVER['PHP_SELF'], "u.api_key", $param, "", "", $sortfield, $sortorder);
  804. $totalarray['nbfield']++;
  805. }
  806. if (!empty($arrayfields['u.fk_soc']['checked'])) {
  807. print_liste_field_titre("Company", $_SERVER['PHP_SELF'], "u.fk_soc", $param, "", "", $sortfield, $sortorder);
  808. $totalarray['nbfield']++;
  809. }
  810. if (!empty($arrayfields['u.entity']['checked'])) {
  811. print_liste_field_titre($arrayfields['u.entity']['label'], $_SERVER['PHP_SELF'], "u.entity", $param, "", "", $sortfield, $sortorder);
  812. $totalarray['nbfield']++;
  813. }
  814. if (!empty($arrayfields['u.job']['checked'])) {
  815. print_liste_field_titre($arrayfields['u.job']['label'], $_SERVER['PHP_SELF'], "u.job", $param, "", "", $sortfield, $sortorder);
  816. $totalarray['nbfield']++;
  817. }
  818. if (!empty($arrayfields['u.salary']['checked'])) {
  819. print_liste_field_titre("Salary", $_SERVER['PHP_SELF'], "u.salary", $param, "", "", $sortfield, $sortorder, 'right ');
  820. $totalarray['nbfield']++;
  821. }
  822. if (!empty($arrayfields['u.datelastlogin']['checked'])) {
  823. print_liste_field_titre("LastConnexion", $_SERVER['PHP_SELF'], "u.datelastlogin", $param, "", '', $sortfield, $sortorder, 'center ');
  824. $totalarray['nbfield']++;
  825. }
  826. if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
  827. print_liste_field_titre("PreviousConnexion", $_SERVER['PHP_SELF'], "u.datepreviouslogin", $param, "", '', $sortfield, $sortorder, 'center ');
  828. $totalarray['nbfield']++;
  829. }
  830. // Extra fields
  831. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  832. // Hook fields
  833. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  834. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  835. print $hookmanager->resPrint;
  836. if (!empty($arrayfields['u.datec']['checked'])) {
  837. print_liste_field_titre("DateCreationShort", $_SERVER["PHP_SELF"], "u.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  838. $totalarray['nbfield']++;
  839. }
  840. if (!empty($arrayfields['u.tms']['checked'])) {
  841. print_liste_field_titre("DateModificationShort", $_SERVER["PHP_SELF"], "u.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  842. $totalarray['nbfield']++;
  843. }
  844. if (!empty($arrayfields['u.statut']['checked'])) {
  845. print_liste_field_titre("Status", $_SERVER["PHP_SELF"], "u.statut", "", $param, '', $sortfield, $sortorder, 'center ');
  846. $totalarray['nbfield']++;
  847. }
  848. // Action column
  849. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  850. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  851. $totalarray['nbfield']++;
  852. }
  853. print '</tr>'."\n";
  854. // Detect if we need a fetch on each output line
  855. $needToFetchEachLine = 0;
  856. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  857. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  858. if (preg_match('/\$object/', $val)) {
  859. $needToFetchEachLine++; // There is at least one compute field that use $object
  860. }
  861. }
  862. }
  863. // Loop on record
  864. // --------------------------------------------------------------------
  865. $i = 0;
  866. $savnbfield = $totalarray['nbfield'];
  867. $totalarray['nbfield'] = 0;
  868. $imaxinloop = ($limit ? min($num, $limit) : $num);
  869. while ($i < $imaxinloop) {
  870. $obj = $db->fetch_object($resql);
  871. if (empty($obj)) {
  872. break; // Should not happen
  873. }
  874. if (empty($obj->country_code)) $obj->country_code = ''; // TODO Add join in select with country table to get country_code
  875. // Store properties in $object
  876. $object->setVarsFromFetchObj($obj);
  877. $object->id = $obj->rowid;
  878. $object->admin = $obj->admin;
  879. $object->ref = $obj->rowid;
  880. $object->login = $obj->login;
  881. $object->statut = $obj->status;
  882. $object->status = $obj->status;
  883. $object->office_phone = $obj->office_phone;
  884. $object->user_mobile = $obj->user_mobile;
  885. $object->job = $obj->job;
  886. $object->email = $obj->email;
  887. $object->gender = $obj->gender;
  888. $object->socid = $obj->fk_soc;
  889. $object->firstname = $obj->firstname;
  890. $object->lastname = $obj->lastname;
  891. $object->employee = $obj->employee;
  892. $object->photo = $obj->photo;
  893. $li = $object->getNomUrl(-1, '', 0, 0, 24, 1, 'login', '', 1);
  894. $canreadhrmdata = 0;
  895. if ((!empty($conf->salaries->enabled) && $user->hasRight("salaries", "read") && in_array($obj->rowid, $childids))
  896. || (!empty($conf->salaries->enabled) && $user->hasRight("salaries", "readall"))
  897. || (isModEnabled('hrm') && $user->hasRight("hrm", "employee", "read"))) {
  898. $canreadhrmdata = 1;
  899. }
  900. $canreadsecretapi = 0;
  901. if ($user->id == $obj->rowid || !empty($user->admin)) { // Current user or admin
  902. $canreadsecretapi = 1;
  903. }
  904. if ($mode == 'kanban') {
  905. if ($i == 0) {
  906. print '<tr><td colspan="'.$savnbfield.'">';
  907. print '<div class="box-flex-container">';
  908. }
  909. // Output Kanban
  910. print $object->getKanbanView('');
  911. if ($i == ($imaxinloop - 1)) {
  912. print '</div>';
  913. print '</td></tr>';
  914. }
  915. } else {
  916. // Show here line of result
  917. $j = 0;
  918. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  919. // Action column
  920. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  921. print '<td class="nowrap center">';
  922. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  923. $selected = 0;
  924. if (in_array($object->id, $arrayofselected)) {
  925. $selected = 1;
  926. }
  927. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  928. }
  929. print '</td>';
  930. }
  931. // Login
  932. if (!empty($arrayfields['u.login']['checked'])) {
  933. print '<td class="nowraponall tdoverflowmax150">';
  934. print $li;
  935. if (isModEnabled('multicompany') && $obj->admin && !$obj->entity) {
  936. print img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingleft"');
  937. } elseif ($obj->admin) {
  938. print img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingleft"');
  939. }
  940. print '</td>';
  941. if (!$i) {
  942. $totalarray['nbfield']++;
  943. }
  944. }
  945. if (!empty($arrayfields['u.lastname']['checked'])) {
  946. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->lastname).'</td>';
  947. if (!$i) {
  948. $totalarray['nbfield']++;
  949. }
  950. }
  951. if (!empty($arrayfields['u.firstname']['checked'])) {
  952. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
  953. if (!$i) {
  954. $totalarray['nbfield']++;
  955. }
  956. }
  957. if (!empty($arrayfields['u.gender']['checked'])) {
  958. print '<td class="center">';
  959. if ($obj->gender) {
  960. // Preparing gender's display if there is one
  961. $addgendertxt = '';
  962. switch ($obj->gender) {
  963. case 'man':
  964. $addgendertxt .= '<i class="fas fa-mars" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
  965. break;
  966. case 'woman':
  967. $addgendertxt .= '<i class="fas fa-venus" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
  968. break;
  969. case 'other':
  970. $addgendertxt .= '<i class="fas fa-transgender" title="'.dol_escape_htmltag($langs->trans("Gender".$obj->gender)).'"></i>';
  971. break;
  972. }
  973. print $addgendertxt;
  974. //print $langs->trans("Gender".$obj->gender);
  975. }
  976. print '</td>';
  977. if (!$i) {
  978. $totalarray['nbfield']++;
  979. }
  980. }
  981. // Employee yes/no
  982. if (!empty($arrayfields['u.employee']['checked'])) {
  983. print '<td class="center">'.yn($obj->employee).'</td>';
  984. if (!$i) {
  985. $totalarray['nbfield']++;
  986. }
  987. }
  988. // Supervisor
  989. if (!empty($arrayfields['u.fk_user']['checked'])) {
  990. // Resp
  991. print '<td class="nowrap">';
  992. if ($obj->login2) {
  993. $user2->id = $obj->id2;
  994. $user2->login = $obj->login2;
  995. $user2->lastname = $obj->lastname2;
  996. $user2->firstname = $obj->firstname2;
  997. $user2->gender = $obj->gender2;
  998. $user2->photo = $obj->photo2;
  999. $user2->admin = $obj->admin2;
  1000. $user2->office_phone = $obj->office_phone;
  1001. $user2->user_mobile = $obj->user_mobile;
  1002. $user2->email = $obj->email2;
  1003. $user2->socid = $obj->fk_soc2;
  1004. $user2->statut = $obj->status2;
  1005. $user2->status = $obj->status2;
  1006. print $user2->getNomUrl(-1, '', 0, 0, 24, 0, '', '', 1);
  1007. if (isModEnabled('multicompany') && $obj->admin2 && !$obj->entity2) {
  1008. print img_picto($langs->trans("SuperAdministrator"), 'redstar', 'class="valignmiddle paddingleft"');
  1009. } elseif ($obj->admin2) {
  1010. print img_picto($langs->trans("Administrator"), 'star', 'class="valignmiddle paddingleft"');
  1011. }
  1012. }
  1013. print '</td>';
  1014. if (!$i) {
  1015. $totalarray['nbfield']++;
  1016. }
  1017. }
  1018. if (!empty($arrayfields['u.accountancy_code']['checked'])) {
  1019. print '<td>'.$obj->accountancy_code.'</td>';
  1020. if (!$i) {
  1021. $totalarray['nbfield']++;
  1022. }
  1023. }
  1024. // Phone
  1025. if (!empty($arrayfields['u.office_phone']['checked'])) {
  1026. print '<td class="tdoverflowmax125">'.dol_print_phone($obj->office_phone, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."</td>\n";
  1027. if (!$i) {
  1028. $totalarray['nbfield']++;
  1029. }
  1030. }
  1031. if (!empty($arrayfields['u.user_mobile']['checked'])) {
  1032. print '<td class="tdoverflowmax125">'.dol_print_phone($obj->user_mobile, $obj->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'mobile')."</td>\n";
  1033. if (!$i) {
  1034. $totalarray['nbfield']++;
  1035. }
  1036. }
  1037. if (!empty($arrayfields['u.email']['checked'])) {
  1038. print '<td class="tdoverflowmax150">'.dol_print_email($obj->email, $obj->rowid, $obj->fk_soc, 'AC_EMAIL', 0, 0, 1)."</td>\n";
  1039. if (!$i) {
  1040. $totalarray['nbfield']++;
  1041. }
  1042. }
  1043. if (!empty($arrayfields['u.api_key']['checked'])) {
  1044. $api_key = dolDecrypt($obj->api_key);
  1045. print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($api_key).'">';
  1046. if ($api_key) {
  1047. if ($canreadsecretapi) {
  1048. print '<span class="opacitymedium">';
  1049. print showValueWithClipboardCPButton($object->api_key, 1, dol_trunc($api_key, 3)); // TODO Add an option to also reveal the hash, not only copy paste
  1050. print '</span>';
  1051. } else {
  1052. print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  1053. }
  1054. }
  1055. print '</td>';
  1056. if (!$i) {
  1057. $totalarray['nbfield']++;
  1058. }
  1059. }
  1060. if (!empty($arrayfields['u.fk_soc']['checked'])) {
  1061. print '<td class="tdoverflowmax150">';
  1062. if ($obj->fk_soc > 0) {
  1063. $companystatic->id = $obj->fk_soc;
  1064. $companystatic->name = $obj->name;
  1065. $companystatic->canvas = $obj->canvas;
  1066. print $companystatic->getNomUrl(1);
  1067. } elseif ($obj->ldap_sid) {
  1068. print '<span class="opacitymedium">'.$langs->trans("DomainUser").'</span>';
  1069. } else {
  1070. print '<span class="opacitymedium">'.$langs->trans("InternalUser").'</span>';
  1071. }
  1072. print '</td>';
  1073. if (!$i) {
  1074. $totalarray['nbfield']++;
  1075. }
  1076. }
  1077. // Multicompany enabled
  1078. if (isModEnabled('multicompany') && is_object($mc) && empty($conf->global->MULTICOMPANY_TRANSVERSE_MODE)) {
  1079. if (!empty($arrayfields['u.entity']['checked'])) {
  1080. print '<td>';
  1081. if (!$obj->entity) {
  1082. print $langs->trans("AllEntities");
  1083. } else {
  1084. $mc->getInfo($obj->entity);
  1085. print $mc->label;
  1086. }
  1087. print '</td>';
  1088. if (!$i) {
  1089. $totalarray['nbfield']++;
  1090. }
  1091. }
  1092. }
  1093. // Job position
  1094. if (!empty($arrayfields['u.job']['checked'])) {
  1095. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->job).'">';
  1096. print dol_escape_htmltag($obj->job);
  1097. print '</td>';
  1098. if (!$i) {
  1099. $totalarray['nbfield']++;
  1100. }
  1101. }
  1102. // Salary
  1103. if (!empty($arrayfields['u.salary']['checked'])) {
  1104. print '<td class="nowraponall right amount">';
  1105. if ($obj->salary) {
  1106. if ($canreadhrmdata) {
  1107. print price($obj->salary);
  1108. } else {
  1109. print '<span class="opacitymedium">'.$langs->trans("Hidden").'</span>';
  1110. }
  1111. }
  1112. print '</td>';
  1113. if (!$i) {
  1114. $totalarray['nbfield']++;
  1115. }
  1116. }
  1117. // Date last login
  1118. if (!empty($arrayfields['u.datelastlogin']['checked'])) {
  1119. print '<td class="nowrap center">'.dol_print_date($db->jdate($obj->datelastlogin), "dayhour").'</td>';
  1120. if (!$i) {
  1121. $totalarray['nbfield']++;
  1122. }
  1123. }
  1124. // Date previous login
  1125. if (!empty($arrayfields['u.datepreviouslogin']['checked'])) {
  1126. print '<td class="nowrap center">'.dol_print_date($db->jdate($obj->datepreviouslogin), "dayhour").'</td>';
  1127. if (!$i) {
  1128. $totalarray['nbfield']++;
  1129. }
  1130. }
  1131. // Extra fields
  1132. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1133. // Fields from hook
  1134. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1135. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  1136. print $hookmanager->resPrint;
  1137. // Date creation
  1138. if (!empty($arrayfields['u.datec']['checked'])) {
  1139. print '<td class="center">';
  1140. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1141. print '</td>';
  1142. if (!$i) {
  1143. $totalarray['nbfield']++;
  1144. }
  1145. }
  1146. // Date modification
  1147. if (!empty($arrayfields['u.tms']['checked'])) {
  1148. print '<td class="center">';
  1149. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1150. print '</td>';
  1151. if (!$i) {
  1152. $totalarray['nbfield']++;
  1153. }
  1154. }
  1155. // Status
  1156. if (!empty($arrayfields['u.statut']['checked'])) {
  1157. print '<td class="center">'.$object->getLibStatut(5).'</td>';
  1158. if (!$i) {
  1159. $totalarray['nbfield']++;
  1160. }
  1161. }
  1162. // Action column
  1163. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1164. print '<td class="nowrap center">';
  1165. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1166. $selected = 0;
  1167. if (in_array($object->id, $arrayofselected)) {
  1168. $selected = 1;
  1169. }
  1170. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  1171. }
  1172. print '</td>';
  1173. }
  1174. if (!$i) {
  1175. $totalarray['nbfield']++;
  1176. }
  1177. print '</tr>'."\n";
  1178. }
  1179. $i++;
  1180. }
  1181. // Show total line
  1182. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1183. // If no record found
  1184. if ($num == 0) {
  1185. $colspan = 1;
  1186. foreach ($arrayfields as $key => $val) {
  1187. if (!empty($val['checked'])) {
  1188. $colspan++;
  1189. }
  1190. }
  1191. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1192. }
  1193. $db->free($resql);
  1194. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1195. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  1196. print $hookmanager->resPrint;
  1197. print '</table>'."\n";
  1198. print '</div>'."\n";
  1199. print '</form>'."\n";
  1200. // End of page
  1201. llxFooter();
  1202. $db->close();