list.php 49 KB

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