list.php 43 KB

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