list.php 52 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456
  1. <?php
  2. /* Copyright (C) 2001-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2002-2003 Jean-Louis Bergamo <jlb@j1b.org>
  4. * Copyright (C) 2004-2022 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  6. * Copyright (C) 2014-2016 Juanjo Menent <jmenent@2byte.es>
  7. * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  8. * Copyright (C) 2021-2023 Frédéric France <frederic.france@netlogic.fr>
  9. *
  10. * This program is free software; you can redistribute it and/or modify
  11. * it under the terms of the GNU General Public License as published by
  12. * the Free Software Foundation; either version 3 of the License, or
  13. * (at your option) any later version.
  14. *
  15. * This program is distributed in the hope that it will be useful,
  16. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  17. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  18. * GNU General Public License for more details.
  19. *
  20. * You should have received a copy of the GNU General Public License
  21. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  22. */
  23. /**
  24. * \file htdocs/adherents/list.php
  25. * \ingroup member
  26. * \brief Page to list all members of foundation
  27. */
  28. // Load Dolibarr environment
  29. require '../main.inc.php';
  30. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/adherents/class/adherent_type.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  34. // Load translation files required by the page
  35. $langs->loadLangs(array("members", "companies", "categories"));
  36. // Get parameters
  37. $action = GETPOST('action', 'aZ09');
  38. $massaction = GETPOST('massaction', 'alpha');
  39. $show_files = GETPOST('show_files', 'int');
  40. $confirm = GETPOST('confirm', 'alpha');
  41. $cancel = GETPOST('cancel', 'alpha');
  42. $toselect = GETPOST('toselect', 'array');
  43. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'memberslist'; // To manage different context of search
  44. $backtopage = GETPOST('backtopage', 'alpha');
  45. $optioncss = GETPOST('optioncss', 'aZ');
  46. $mode = GETPOST('mode', 'alpha');
  47. // Search fields
  48. $search = GETPOST("search", 'alpha');
  49. $search_ref = GETPOST("search_ref", 'alpha');
  50. $search_lastname = GETPOST("search_lastname", 'alpha');
  51. $search_firstname = GETPOST("search_firstname", 'alpha');
  52. $search_gender = GETPOST("search_gender", 'alpha');
  53. $search_civility = GETPOST("search_civility", 'alpha');
  54. $search_company = GETPOST('search_company', 'alphanohtml');
  55. $search_login = GETPOST("search_login", 'alpha');
  56. $search_address = GETPOST("search_address", 'alpha');
  57. $search_zip = GETPOST("search_zip", 'alpha');
  58. $search_town = GETPOST("search_town", 'alpha');
  59. $search_state = GETPOST("search_state", 'alpha'); // county / departement / federal state
  60. $search_country = GETPOST("search_country", 'alpha');
  61. $search_phone = GETPOST("search_phone", 'alpha');
  62. $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
  63. $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
  64. $search_type = GETPOST("search_type", 'alpha');
  65. $search_email = GETPOST("search_email", 'alpha');
  66. $search_categ = GETPOST("search_categ", 'int');
  67. $search_morphy = GETPOST("search_morphy", 'alpha');
  68. $search_import_key = trim(GETPOST("search_import_key", 'alpha'));
  69. $catid = GETPOST("catid", 'int');
  70. $socid = GETPOST('socid', 'int');
  71. $search_filter = GETPOST("search_filter", 'alpha');
  72. $search_status = GETPOST("search_status", 'intcomma'); // statut
  73. $filter = GETPOST("filter", 'alpha');
  74. if ($filter) {
  75. $search_filter = $filter; // For backward compatibility
  76. }
  77. $statut = GETPOST("statut", 'alpha');
  78. if ($statut != '') {
  79. $search_status = $statut; // For backward compatibility
  80. }
  81. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  82. if ($search_status < -2) {
  83. $search_status = '';
  84. }
  85. // Pagination parameters
  86. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  87. $sortfield = GETPOST('sortfield', 'aZ09comma');
  88. $sortorder = GETPOST('sortorder', 'aZ09comma');
  89. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  90. if (empty($page) || $page == -1) {
  91. $page = 0;
  92. } // If $page is not defined, or '' or -1
  93. $offset = $limit * $page;
  94. $pageprev = $page - 1;
  95. $pagenext = $page + 1;
  96. if (!$sortorder) {
  97. $sortorder = ($filter == 'outofdate' ? "DESC" : "ASC");
  98. }
  99. if (!$sortfield) {
  100. $sortfield = ($filter == 'outofdate' ? "d.datefin" : "d.lastname");
  101. }
  102. $object = new Adherent($db);
  103. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  104. $hookmanager->initHooks(array('memberlist'));
  105. $extrafields = new ExtraFields($db);
  106. // fetch optionals attributes and labels
  107. $extrafields->fetch_name_optionals_label($object->table_element);
  108. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  109. // List of fields to search into when doing a "search in all"
  110. $fieldstosearchall = array(
  111. 'd.ref'=>'Ref',
  112. 'd.login'=>'Login',
  113. 'd.lastname'=>'Lastname',
  114. 'd.firstname'=>'Firstname',
  115. 'd.societe'=>"Company",
  116. 'd.email'=>'EMail',
  117. 'd.address'=>'Address',
  118. 'd.zip'=>'Zip',
  119. 'd.town'=>'Town',
  120. 'd.phone'=>"Phone",
  121. 'd.phone_perso'=>"PhonePerso",
  122. 'd.phone_mobile'=>"PhoneMobile",
  123. 'd.note_public'=>'NotePublic',
  124. 'd.note_private'=>'NotePrivate',
  125. );
  126. if ($db->type == 'pgsql') {
  127. unset($fieldstosearchall['d.rowid']);
  128. }
  129. $arrayfields = array(
  130. 'd.ref'=>array('label'=>"Ref", 'checked'=>1),
  131. 'd.civility'=>array('label'=>"Civility", 'checked'=>0),
  132. 'd.lastname'=>array('label'=>"Lastname", 'checked'=>1),
  133. 'd.firstname'=>array('label'=>"Firstname", 'checked'=>1),
  134. 'd.gender'=>array('label'=>"Gender", 'checked'=>0),
  135. 'd.company'=>array('label'=>"Company", 'checked'=>1),
  136. 'd.login'=>array('label'=>"Login", 'checked'=>1),
  137. 'd.morphy'=>array('label'=>"MemberNature", 'checked'=>1),
  138. 't.libelle'=>array('label'=>"Type", 'checked'=>1),
  139. 'd.email'=>array('label'=>"Email", 'checked'=>1),
  140. 'd.address'=>array('label'=>"Address", 'checked'=>0),
  141. 'd.zip'=>array('label'=>"Zip", 'checked'=>0),
  142. 'd.town'=>array('label'=>"Town", 'checked'=>0),
  143. 'd.phone'=>array('label'=>"Phone", 'checked'=>0),
  144. 'd.phone_perso'=>array('label'=>"PhonePerso", 'checked'=>0),
  145. 'd.phone_mobile'=>array('label'=>"PhoneMobile", 'checked'=>0),
  146. 'state.nom'=>array('label'=>"State", 'checked'=>0),
  147. 'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
  148. /*'d.note_public'=>array('label'=>"NotePublic", 'checked'=>0),
  149. 'd.note_private'=>array('label'=>"NotePrivate", 'checked'=>0),*/
  150. 'd.datefin'=>array('label'=>"EndSubscription", 'checked'=>1, 'position'=>500),
  151. 'd.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
  152. 'd.birth'=>array('label'=>"Birthday", 'checked'=>0, 'position'=>500),
  153. 'd.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
  154. 'd.statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
  155. 'd.import_key'=>array('label'=>"ImportId", 'checked'=>0, 'position'=>1100),
  156. );
  157. // Extra fields
  158. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  159. // Security check
  160. $result = restrictedArea($user, 'adherent');
  161. /*
  162. * Actions
  163. */
  164. if (GETPOST('cancel', 'alpha')) {
  165. $action = 'list';
  166. $massaction = '';
  167. }
  168. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  169. $massaction = '';
  170. }
  171. $parameters = array('socid'=>isset($socid) ? $socid : null);
  172. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  173. if ($reshook < 0) {
  174. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  175. }
  176. if (empty($reshook)) {
  177. // Selection of new fields
  178. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  179. // Purge search criteria
  180. 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
  181. $statut = '';
  182. $filter = '';
  183. $search = "";
  184. $search_ref = "";
  185. $search_lastname = "";
  186. $search_firstname = "";
  187. $search_gender = "";
  188. $search_civility = "";
  189. $search_login = "";
  190. $search_company = "";
  191. $search_type = "";
  192. $search_email = "";
  193. $search_address = "";
  194. $search_zip = "";
  195. $search_town = "";
  196. $search_state = "";
  197. $search_country = '';
  198. $search_phone = '';
  199. $search_phone_perso = '';
  200. $search_phone_mobile = '';
  201. $search_morphy = "";
  202. $search_categ = "";
  203. $search_filter = "";
  204. $search_status = "";
  205. $search_import_key = '';
  206. $catid = "";
  207. $search_all = "";
  208. $toselect = array();
  209. $search_array_options = array();
  210. }
  211. // Close
  212. if ($massaction == 'close' && $user->hasRight('adherent', 'creer')) {
  213. $tmpmember = new Adherent($db);
  214. $error = 0;
  215. $nbclose = 0;
  216. $db->begin();
  217. foreach ($toselect as $idtoclose) {
  218. $tmpmember->fetch($idtoclose);
  219. $result = $tmpmember->resiliate($user);
  220. if ($result < 0 && !count($tmpmember->errors)) {
  221. setEventMessages($tmpmember->error, $tmpmember->errors, 'errors');
  222. } else {
  223. if ($result > 0) {
  224. $nbclose++;
  225. }
  226. }
  227. }
  228. if (!$error) {
  229. setEventMessages($langs->trans("XMembersClosed", $nbclose), null, 'mesgs');
  230. $db->commit();
  231. } else {
  232. $db->rollback();
  233. }
  234. }
  235. // Create external user
  236. if ($massaction == 'createexternaluser' && $user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer')) {
  237. $tmpmember = new Adherent($db);
  238. $error = 0;
  239. $nbcreated = 0;
  240. $db->begin();
  241. foreach ($toselect as $idtoclose) {
  242. $tmpmember->fetch($idtoclose);
  243. if (!empty($tmpmember->fk_soc)) {
  244. $nuser = new User($db);
  245. $tmpuser = dol_clone($tmpmember);
  246. $result = $nuser->create_from_member($tmpuser, $tmpmember->login);
  247. if ($result < 0 && !count($tmpmember->errors)) {
  248. setEventMessages($tmpmember->error, $tmpmember->errors, 'errors');
  249. } else {
  250. if ($result > 0) {
  251. $nbcreated++;
  252. }
  253. }
  254. }
  255. }
  256. if (!$error) {
  257. setEventMessages($langs->trans("XExternalUserCreated", $nbcreated), null, 'mesgs');
  258. $db->commit();
  259. } else {
  260. $db->rollback();
  261. }
  262. }
  263. // Mass actions
  264. $objectclass = 'Adherent';
  265. $objectlabel = 'Members';
  266. $permissiontoread = $user->hasRight('adherent', 'lire');
  267. $permissiontodelete = $user->hasRight('adherent', 'supprimer');
  268. $permissiontoadd = $user->hasRight('adherent', 'creer');
  269. $uploaddir = $conf->adherent->dir_output;
  270. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  271. }
  272. /*
  273. * View
  274. */
  275. $form = new Form($db);
  276. $formother = new FormOther($db);
  277. $membertypestatic = new AdherentType($db);
  278. $memberstatic = new Adherent($db);
  279. $now = dol_now();
  280. // Page Header
  281. $title = $langs->trans("Members")." - ".$langs->trans("List");
  282. $help_url = 'EN:Module_Foundations|FR:Module_Adh&eacute;rents|ES:M&oacute;dulo_Miembros|DE:Modul_Mitglieder';
  283. $morejs = array();
  284. $morecss = array();
  285. // Build and execute select
  286. // --------------------------------------------------------------------
  287. if ((!empty($search_categ) && $search_categ > 0) || !empty($catid)) {
  288. $sql = "SELECT DISTINCT";
  289. } else {
  290. $sql = "SELECT";
  291. }
  292. $sql .= " d.rowid, d.ref, d.login, d.lastname, d.firstname, d.gender, d.societe as company, d.fk_soc,";
  293. $sql .= " d.civility, d.datefin, d.address, d.zip, d.town, d.state_id, d.country,";
  294. $sql .= " d.email, d.phone, d.phone_perso, d.phone_mobile, d.birth, d.public, d.photo,";
  295. $sql .= " d.fk_adherent_type as type_id, d.morphy, d.statut, d.datec as date_creation, d.tms as date_update,";
  296. $sql .= " d.note_private, d.note_public, d.import_key,";
  297. $sql .= " s.nom,";
  298. $sql .= " ".$db->ifsql("d.societe IS NULL", "s.nom", "d.societe")." as companyname,";
  299. $sql .= " t.libelle as type, t.subscription,";
  300. $sql .= " state.code_departement as state_code, state.nom as state_name";
  301. // Add fields from extrafields
  302. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  303. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  304. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  305. }
  306. }
  307. // Add fields from hooks
  308. $parameters = array();
  309. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  310. $sql .= $hookmanager->resPrint;
  311. $sql = preg_replace('/,\s*$/', '', $sql);
  312. $sqlfields = $sql; // $sql fields to remove for count total
  313. // SQL Aliase adherent
  314. $sql .= " FROM ".MAIN_DB_PREFIX."adherent as d"; // maybe better to use ad (adh) instead od d
  315. if (!empty($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  316. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (d.rowid = ef.fk_object)";
  317. }
  318. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = d.country)";
  319. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = d.state_id)";
  320. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s on (s.rowid = d.fk_soc)";
  321. // SQL Aliase adherent_type
  322. $sql .= ", ".MAIN_DB_PREFIX."adherent_type as t";
  323. $sql .= " WHERE d.fk_adherent_type = t.rowid";
  324. if ($catid && empty($search_categ)) {
  325. $search_categ = $catid;
  326. }
  327. $searchCategoryContactList = $search_categ ? array($search_categ) : array();
  328. $searchCategoryContactOperator = 0;
  329. // Search for tag/category ($searchCategoryContactList is an array of ID)
  330. if (!empty($searchCategoryContactList)) {
  331. $searchCategoryContactSqlList = array();
  332. $listofcategoryid = '';
  333. foreach ($searchCategoryContactList as $searchCategoryContact) {
  334. if (intval($searchCategoryContact) == -2) {
  335. $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_member as ck WHERE d.rowid = ck.fk_member)";
  336. } elseif (intval($searchCategoryContact) > 0) {
  337. if ($searchCategoryContactOperator == 0) {
  338. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_member as ck WHERE d.rowid = ck.fk_member AND ck.fk_categorie = ".((int) $searchCategoryContact).")";
  339. } else {
  340. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact);
  341. }
  342. }
  343. }
  344. if ($listofcategoryid) {
  345. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_categorie FROM ".MAIN_DB_PREFIX."categorie_member as ck WHERE d.rowid = ck.fk_member AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  346. }
  347. if ($searchCategoryContactOperator == 1) {
  348. if (!empty($searchCategoryContactSqlList)) {
  349. $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")";
  350. }
  351. } else {
  352. if (!empty($searchCategoryContactSqlList)) {
  353. $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")";
  354. }
  355. }
  356. }
  357. $sql .= " AND d.entity IN (".getEntity('adherent').")";
  358. if ($search_all) {
  359. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  360. }
  361. if ($search_type > 0) {
  362. $sql .= " AND t.rowid=".((int) $search_type);
  363. }
  364. if ($search_filter == 'withoutsubscription') {
  365. $sql .= " AND (datefin IS NULL)";
  366. }
  367. if ($search_filter == 'waitingsubscription') {
  368. $sql .= " AND (datefin IS NULL AND t.subscription = '1')";
  369. }
  370. if ($search_filter == 'uptodate') {
  371. $sql .= " AND (datefin >= '".$db->idate($now)."' OR (datefin IS NULL AND t.subscription = '0'))";
  372. }
  373. if ($search_filter == 'outofdate') {
  374. $sql .= " AND (datefin < '".$db->idate($now)."')";
  375. }
  376. if ($search_status != '') {
  377. // Peut valoir un nombre ou liste de nombre separes par virgules
  378. $sql .= " AND d.statut in (".$db->sanitize($db->escape($search_status)).")";
  379. }
  380. if ($search_morphy != '' && $search_morphy != '-1') {
  381. $sql .= natural_search("d.morphy", $search_morphy);
  382. }
  383. if ($search_ref) {
  384. $sql .= natural_search("d.ref", $search_ref);
  385. }
  386. if ($search_civility) {
  387. $sql .= natural_search("d.civility", $search_civility);
  388. }
  389. if ($search_firstname) {
  390. $sql .= natural_search("d.firstname", $search_firstname);
  391. }
  392. if ($search_lastname) {
  393. $sql .= natural_search(array("d.firstname", "d.lastname", "d.societe"), $search_lastname);
  394. }
  395. if ($search_gender != '' && $search_gender != '-1') {
  396. $sql .= natural_search("d.gender", $search_gender);
  397. }
  398. if ($search_login) {
  399. $sql .= natural_search("d.login", $search_login);
  400. }
  401. if ($search_company) {
  402. $sql .= natural_search("s.nom", $search_company);
  403. }
  404. if ($search_email) {
  405. $sql .= natural_search("d.email", $search_email);
  406. }
  407. if ($search_address) {
  408. $sql .= natural_search("d.address", $search_address);
  409. }
  410. if ($search_town) {
  411. $sql .= natural_search("d.town", $search_town);
  412. }
  413. if ($search_zip) {
  414. $sql .= natural_search("d.zip", $search_zip);
  415. }
  416. if ($search_state) {
  417. $sql .= natural_search("state.nom", $search_state);
  418. }
  419. if ($search_phone) {
  420. $sql .= natural_search("d.phone", $search_phone);
  421. }
  422. if ($search_phone_perso) {
  423. $sql .= natural_search("d.phone_perso", $search_phone_perso);
  424. }
  425. if ($search_phone_mobile) {
  426. $sql .= natural_search("d.phone_mobile", $search_phone_mobile);
  427. }
  428. if ($search_country) {
  429. $sql .= " AND d.country IN (".$db->sanitize($search_country).')';
  430. }
  431. if ($search_import_key) {
  432. $sql .= natural_search("d.import_key", $search_import_key);
  433. }
  434. // Add where from extra fields
  435. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  436. // Add where from hooks
  437. $parameters = array();
  438. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  439. $sql .= $hookmanager->resPrint;
  440. // Count total nb of records
  441. $nbtotalofrecords = '';
  442. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  443. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  444. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  445. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  446. $resql = $db->query($sqlforcount);
  447. if ($resql) {
  448. $objforcount = $db->fetch_object($resql);
  449. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  450. } else {
  451. dol_print_error($db);
  452. }
  453. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  454. $page = 0;
  455. $offset = 0;
  456. }
  457. $db->free($resql);
  458. }
  459. //print $sql;
  460. // Complete request and execute it with limit
  461. $sql .= $db->order($sortfield, $sortorder);
  462. if ($limit) {
  463. $sql .= $db->plimit($limit + 1, $offset);
  464. }
  465. $resql = $db->query($sql);
  466. if (!$resql) {
  467. dol_print_error($db);
  468. exit;
  469. }
  470. $num = $db->num_rows($resql);
  471. // Direct jump if only one record found
  472. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  473. $obj = $db->fetch_object($resql);
  474. $id = $obj->rowid;
  475. header("Location: ".DOL_URL_ROOT.'/adherents/card.php?id='.$id);
  476. exit;
  477. }
  478. // Output page
  479. // --------------------------------------------------------------------
  480. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
  481. $arrayofselected = is_array($toselect) ? $toselect : array();
  482. if ($search_type > 0) {
  483. $membertype = new AdherentType($db);
  484. $result = $membertype->fetch($search_type);
  485. $title .= " (".$membertype->label.")";
  486. }
  487. // $parameters
  488. $param = '';
  489. if (!empty($mode)) {
  490. $param .= '&mode='.urlencode($mode);
  491. }
  492. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  493. $param .= '&contextpage='.urlencode($contextpage);
  494. }
  495. if ($limit > 0 && $limit != $conf->liste_limit) {
  496. $param .= '&limit='.((int) $limit);
  497. }
  498. if ($optioncss != '') {
  499. $param .= '&optioncss='.urlencode($optioncss);
  500. }
  501. if ($search_all != "") {
  502. $param .= "&search_all=".urlencode($search_all);
  503. }
  504. if ($search_ref) {
  505. $param .= "&search_ref=".urlencode($search_ref);
  506. }
  507. if ($search_civility) {
  508. $param .= "&search_civility=".urlencode($search_civility);
  509. }
  510. if ($search_firstname) {
  511. $param .= "&search_firstname=".urlencode($search_firstname);
  512. }
  513. if ($search_lastname) {
  514. $param .= "&search_lastname=".urlencode($search_lastname);
  515. }
  516. if ($search_gender) {
  517. $param .= "&search_gender=".urlencode($search_gender);
  518. }
  519. if ($search_login) {
  520. $param .= "&search_login=".urlencode($search_login);
  521. }
  522. if ($search_email) {
  523. $param .= "&search_email=".urlencode($search_email);
  524. }
  525. if ($search_categ > 0 || $search_categ == -2) {
  526. $param .= "&search_categ=".urlencode($search_categ);
  527. }
  528. if ($search_company) {
  529. $param .= "&search_company=".urlencode($search_company);
  530. }
  531. if ($search_address != '') {
  532. $param .= "&search_address=".urlencode($search_address);
  533. }
  534. if ($search_town != '') {
  535. $param .= "&search_town=".urlencode($search_town);
  536. }
  537. if ($search_zip != '') {
  538. $param .= "&search_zip=".urlencode($search_zip);
  539. }
  540. if ($search_state != '') {
  541. $param .= "&search_state=".urlencode($search_state);
  542. }
  543. if ($search_country != '') {
  544. $param .= "&search_country=".urlencode($search_country);
  545. }
  546. if ($search_phone != '') {
  547. $param .= "&search_phone=".urlencode($search_phone);
  548. }
  549. if ($search_phone_perso != '') {
  550. $param .= "&search_phone_perso=".urlencode($search_phone_perso);
  551. }
  552. if ($search_phone_mobile != '') {
  553. $param .= "&search_phone_mobile=".urlencode($search_phone_mobile);
  554. }
  555. if ($search_filter && $search_filter != '-1') {
  556. $param .= "&search_filter=".urlencode($search_filter);
  557. }
  558. if ($search_status != "" && $search_status != -3) {
  559. $param .= "&search_status=".urlencode($search_status);
  560. }
  561. if ($search_import_key != '') {
  562. $param .= '&search_import_key='.urlencode($search_import_key);
  563. }
  564. if ($search_type > 0) {
  565. $param .= "&search_type=".urlencode($search_type);
  566. }
  567. // Add $param from extra fields
  568. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  569. // List of mass actions available
  570. $arrayofmassactions = array(
  571. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  572. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  573. );
  574. if ($user->hasRight('adherent', 'creer')) {
  575. $arrayofmassactions['close'] = img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Resiliate");
  576. }
  577. if ($user->hasRight('adherent', 'supprimer')) {
  578. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  579. }
  580. if (isModEnabled('category') && $user->hasRight('adherent', 'creer')) {
  581. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  582. }
  583. if ($user->hasRight('adherent', 'creer') && $user->hasRight('user', 'user', 'creer')) {
  584. $arrayofmassactions['createexternaluser'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("CreateExternalUser");
  585. }
  586. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete', 'preaffecttag'))) {
  587. $arrayofmassactions = array();
  588. }
  589. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  590. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  591. if ($optioncss != '') {
  592. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  593. }
  594. print '<input type="hidden" name="token" value="'.newToken().'">';
  595. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  596. print '<input type="hidden" name="action" value="list">';
  597. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  598. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  599. print '<input type="hidden" name="page" value="'.$page.'">';
  600. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  601. print '<input type="hidden" name="page_y" value="">';
  602. print '<input type="hidden" name="mode" value="'.$mode.'">';
  603. $newcardbutton = '';
  604. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  605. $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'));
  606. if ($user->hasRight('adherent', 'creer')) {
  607. $newcardbutton .= dolGetButtonTitleSeparator();
  608. $newcardbutton .= dolGetButtonTitle($langs->trans('NewMember'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/card.php?action=create');
  609. }
  610. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  611. $topicmail = "Information";
  612. $modelmail = "member";
  613. $objecttmp = new Adherent($db);
  614. $trackid = 'mem'.$object->id;
  615. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  616. if ($search_all) {
  617. $setupstring = '';
  618. foreach ($fieldstosearchall as $key => $val) {
  619. $fieldstosearchall[$key] = $langs->trans($val);
  620. $setupstring .= $key."=".$val.";";
  621. }
  622. print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  623. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  624. }
  625. $moreforfilter = '';
  626. // Filter on categories
  627. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  628. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  629. $moreforfilter .= '<div class="divsearchfield">';
  630. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedlength"').$formother->select_categories(Categorie::TYPE_MEMBER, $search_categ, 'search_categ', 1, $langs->trans("MembersCategoriesShort"));
  631. $moreforfilter .= '</div>';
  632. }
  633. $parameters = array();
  634. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  635. if (empty($reshook)) {
  636. $moreforfilter .= $hookmanager->resPrint;
  637. } else {
  638. $moreforfilter = $hookmanager->resPrint;
  639. }
  640. if (!empty($moreforfilter)) {
  641. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  642. print $moreforfilter;
  643. $parameters = array();
  644. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  645. print $hookmanager->resPrint;
  646. print '</div>';
  647. }
  648. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  649. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  650. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  651. print '<div class="div-table-responsive">';
  652. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  653. // Fields title search
  654. // --------------------------------------------------------------------
  655. print '<tr class="liste_titre_filter">';
  656. // Action column
  657. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  658. print '<td class="liste_titre center maxwidthsearch">';
  659. $searchpicto = $form->showFilterButtons('left');
  660. print $searchpicto;
  661. print '</td>';
  662. }
  663. // Line numbering
  664. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  665. print '<td class="liste_titre">&nbsp;</td>';
  666. }
  667. // Ref
  668. if (!empty($arrayfields['d.ref']['checked'])) {
  669. print '<td class="liste_titre">';
  670. print '<input type="text" class="flat maxwidth75imp" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  671. print '</td>';
  672. }
  673. // Civility
  674. if (!empty($arrayfields['d.civility']['checked'])) {
  675. print '<td class="liste_titre left">';
  676. print '<input class="flat maxwidth50imp" type="text" name="search_civility" value="'.dol_escape_htmltag($search_civility).'"></td>';
  677. }
  678. // First Name
  679. if (!empty($arrayfields['d.firstname']['checked'])) {
  680. print '<td class="liste_titre left">';
  681. print '<input class="flat maxwidth75imp" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'"></td>';
  682. }
  683. // Last Name
  684. if (!empty($arrayfields['d.lastname']['checked'])) {
  685. print '<td class="liste_titre left">';
  686. print '<input class="flat maxwidth75imp" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'"></td>';
  687. }
  688. // Gender
  689. if (!empty($arrayfields['d.gender']['checked'])) {
  690. print '<td class="liste_titre">';
  691. $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
  692. print $form->selectarray('search_gender', $arraygender, $search_gender, 1);
  693. print '</td>';
  694. }
  695. // Company
  696. if (!empty($arrayfields['d.company']['checked'])) {
  697. print '<td class="liste_titre left">';
  698. print '<input class="flat maxwidth75imp" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"></td>';
  699. }
  700. // Login
  701. if (!empty($arrayfields['d.login']['checked'])) {
  702. print '<td class="liste_titre left">';
  703. print '<input class="flat maxwidth75imp" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'"></td>';
  704. }
  705. // Nature
  706. if (!empty($arrayfields['d.morphy']['checked'])) {
  707. print '<td class="liste_titre center">';
  708. $arraymorphy = array('mor'=>$langs->trans("Moral"), 'phy'=>$langs->trans("Physical"));
  709. print $form->selectarray('search_morphy', $arraymorphy, $search_morphy, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
  710. print '</td>';
  711. }
  712. // Member Type
  713. if (!empty($arrayfields['t.libelle']['checked'])) {
  714. print '</td>';
  715. }
  716. if (!empty($arrayfields['t.libelle']['checked'])) {
  717. print '<td class="liste_titre">';
  718. $listetype = $membertypestatic->liste_array();
  719. print $form->selectarray("search_type", $listetype, $search_type, 1, 0, 0, '', 0, 32);
  720. print '</td>';
  721. }
  722. // Address - Street
  723. if (!empty($arrayfields['d.address']['checked'])) {
  724. print '<td class="liste_titre left">';
  725. print '<input class="flat maxwidth75imp" type="text" name="search_address" value="'.dol_escape_htmltag($search_address).'"></td>';
  726. }
  727. // ZIP
  728. if (!empty($arrayfields['d.zip']['checked'])) {
  729. print '<td class="liste_titre left">';
  730. print '<input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  731. }
  732. // Town/City
  733. if (!empty($arrayfields['d.town']['checked'])) {
  734. print '<td class="liste_titre left">';
  735. print '<input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  736. }
  737. // State / County / Departement
  738. if (!empty($arrayfields['state.nom']['checked'])) {
  739. print '<td class="liste_titre">';
  740. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  741. print '</td>';
  742. }
  743. // Country
  744. if (!empty($arrayfields['country.code_iso']['checked'])) {
  745. print '<td class="liste_titre center">';
  746. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  747. print '</td>';
  748. }
  749. // Phone pro
  750. if (!empty($arrayfields['d.phone']['checked'])) {
  751. print '<td class="liste_titre left">';
  752. print '<input class="flat maxwidth75imp" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'"></td>';
  753. }
  754. // Phone perso
  755. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  756. print '<td class="liste_titre left">';
  757. print '<input class="flat maxwidth75imp" type="text" name="search_phone_perso" value="'.dol_escape_htmltag($search_phone_perso).'"></td>';
  758. }
  759. // Phone mobile
  760. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  761. print '<td class="liste_titre left">';
  762. print '<input class="flat maxwidth75imp" type="text" name="search_phone_mobile" value="'.dol_escape_htmltag($search_phone_mobile).'"></td>';
  763. }
  764. // Email
  765. if (!empty($arrayfields['d.email']['checked'])) {
  766. print '<td class="liste_titre left">';
  767. print '<input class="flat maxwidth75imp" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'"></td>';
  768. }
  769. // End of subscription date
  770. if (!empty($arrayfields['d.datefin']['checked'])) {
  771. print '<td class="liste_titre center">';
  772. //$selectarray = array('-1'=>'', 'withoutsubscription'=>$langs->trans("WithoutSubscription"), 'uptodate'=>$langs->trans("UpToDate"), 'outofdate'=>$langs->trans("OutOfDate"));
  773. $selectarray = array('-1'=>'', 'waitingsubscription'=>$langs->trans("WaitingSubscription"), 'uptodate'=>$langs->trans("UpToDate"), 'outofdate'=>$langs->trans("OutOfDate"));
  774. print $form->selectarray('search_filter', $selectarray, $search_filter);
  775. print '</td>';
  776. }
  777. // Extra fields
  778. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  779. // Fields from hook
  780. $parameters = array('arrayfields'=>$arrayfields);
  781. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  782. print $hookmanager->resPrint;
  783. // Date creation
  784. if (!empty($arrayfields['d.datec']['checked'])) {
  785. print '<td class="liste_titre">';
  786. print '</td>';
  787. }
  788. // Birthday
  789. if (!empty($arrayfields['d.birth']['checked'])) {
  790. print '<td class="liste_titre">';
  791. print '</td>';
  792. }
  793. // Date modification
  794. if (!empty($arrayfields['d.tms']['checked'])) {
  795. print '<td class="liste_titre">';
  796. print '</td>';
  797. }
  798. // Status
  799. if (!empty($arrayfields['d.statut']['checked'])) {
  800. print '<td class="liste_titre right parentonrightofpage">';
  801. $liststatus = array(
  802. Adherent::STATUS_DRAFT => $langs->trans("Draft"),
  803. Adherent::STATUS_VALIDATED => $langs->trans("Validated"),
  804. Adherent::STATUS_RESILIATED => $langs->trans("MemberStatusResiliatedShort"),
  805. Adherent::STATUS_EXCLUDED =>$langs->trans("MemberStatusExcludedShort")
  806. );
  807. print $form->selectarray('search_status', $liststatus, $search_status, -3, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
  808. print '</td>';
  809. }
  810. // Import Key
  811. if (!empty($arrayfields['d.import_key']['checked'])) {
  812. print '<td class="liste_titre center">';
  813. print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  814. print '</td>';
  815. }
  816. // Action column
  817. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  818. print '<td class="liste_titre center maxwidthsearch">';
  819. $searchpicto = $form->showFilterButtons();
  820. print $searchpicto;
  821. print '</td>';
  822. }
  823. print '</tr>'."\n";
  824. $totalarray = array();
  825. $totalarray['nbfield'] = 0;
  826. // Fields title label
  827. // --------------------------------------------------------------------
  828. print '<tr class="liste_titre">';
  829. // Action column
  830. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  831. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');
  832. $totalarray['nbfield']++;
  833. }
  834. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  835. print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder);
  836. $totalarray['nbfield']++;
  837. }
  838. if (!empty($arrayfields['d.ref']['checked'])) {
  839. print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], 'd.ref', '', $param, '', $sortfield, $sortorder);
  840. $totalarray['nbfield']++;
  841. }
  842. if (!empty($arrayfields['d.civility']['checked'])) {
  843. print_liste_field_titre($arrayfields['d.civility']['label'], $_SERVER["PHP_SELF"], 'd.civility', '', $param, '', $sortfield, $sortorder);
  844. $totalarray['nbfield']++;
  845. }
  846. if (!empty($arrayfields['d.firstname']['checked'])) {
  847. print_liste_field_titre($arrayfields['d.firstname']['label'], $_SERVER["PHP_SELF"], 'd.firstname', '', $param, '', $sortfield, $sortorder);
  848. $totalarray['nbfield']++;
  849. }
  850. if (!empty($arrayfields['d.lastname']['checked'])) {
  851. print_liste_field_titre($arrayfields['d.lastname']['label'], $_SERVER["PHP_SELF"], 'd.lastname', '', $param, '', $sortfield, $sortorder);
  852. $totalarray['nbfield']++;
  853. }
  854. if (!empty($arrayfields['d.gender']['checked'])) {
  855. print_liste_field_titre($arrayfields['d.gender']['label'], $_SERVER['PHP_SELF'], 'd.gender', $param, "", "", $sortfield, $sortorder);
  856. $totalarray['nbfield']++;
  857. }
  858. if (!empty($arrayfields['d.company']['checked'])) {
  859. print_liste_field_titre($arrayfields['d.company']['label'], $_SERVER["PHP_SELF"], 'companyname', '', $param, '', $sortfield, $sortorder);
  860. $totalarray['nbfield']++;
  861. }
  862. if (!empty($arrayfields['d.login']['checked'])) {
  863. print_liste_field_titre($arrayfields['d.login']['label'], $_SERVER["PHP_SELF"], 'd.login', '', $param, '', $sortfield, $sortorder);
  864. $totalarray['nbfield']++;
  865. }
  866. if (!empty($arrayfields['d.morphy']['checked'])) {
  867. print_liste_field_titre($arrayfields['d.morphy']['label'], $_SERVER["PHP_SELF"], 'd.morphy', '', $param, '', $sortfield, $sortorder);
  868. $totalarray['nbfield']++;
  869. }
  870. if (!empty($arrayfields['t.libelle']['checked'])) {
  871. print_liste_field_titre($arrayfields['t.libelle']['label'], $_SERVER["PHP_SELF"], 't.libelle', '', $param, '', $sortfield, $sortorder);
  872. $totalarray['nbfield']++;
  873. }
  874. if (!empty($arrayfields['d.address']['checked'])) {
  875. print_liste_field_titre($arrayfields['d.address']['label'], $_SERVER["PHP_SELF"], 'd.address', '', $param, '', $sortfield, $sortorder);
  876. $totalarray['nbfield']++;
  877. }
  878. if (!empty($arrayfields['d.zip']['checked'])) {
  879. print_liste_field_titre($arrayfields['d.zip']['label'], $_SERVER["PHP_SELF"], 'd.zip', '', $param, '', $sortfield, $sortorder);
  880. $totalarray['nbfield']++;
  881. }
  882. if (!empty($arrayfields['d.town']['checked'])) {
  883. print_liste_field_titre($arrayfields['d.town']['label'], $_SERVER["PHP_SELF"], 'd.town', '', $param, '', $sortfield, $sortorder);
  884. $totalarray['nbfield']++;
  885. }
  886. if (!empty($arrayfields['state.nom']['checked'])) {
  887. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  888. $totalarray['nbfield']++;
  889. }
  890. if (!empty($arrayfields['country.code_iso']['checked'])) {
  891. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  892. $totalarray['nbfield']++;
  893. }
  894. if (!empty($arrayfields['d.phone']['checked'])) {
  895. print_liste_field_titre($arrayfields['d.phone']['label'], $_SERVER["PHP_SELF"], 'd.phone', '', $param, '', $sortfield, $sortorder);
  896. $totalarray['nbfield']++;
  897. }
  898. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  899. print_liste_field_titre($arrayfields['d.phone_perso']['label'], $_SERVER["PHP_SELF"], 'd.phone_perso', '', $param, '', $sortfield, $sortorder);
  900. $totalarray['nbfield']++;
  901. }
  902. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  903. print_liste_field_titre($arrayfields['d.phone_mobile']['label'], $_SERVER["PHP_SELF"], 'd.phone_mobile', '', $param, '', $sortfield, $sortorder);
  904. $totalarray['nbfield']++;
  905. }
  906. if (!empty($arrayfields['d.email']['checked'])) {
  907. print_liste_field_titre($arrayfields['d.email']['label'], $_SERVER["PHP_SELF"], 'd.email', '', $param, '', $sortfield, $sortorder);
  908. $totalarray['nbfield']++;
  909. }
  910. if (!empty($arrayfields['d.datefin']['checked'])) {
  911. print_liste_field_titre($arrayfields['d.datefin']['label'], $_SERVER["PHP_SELF"], 'd.datefin,t.subscription', '', $param, '', $sortfield, $sortorder, 'center ');
  912. $totalarray['nbfield']++;
  913. }
  914. // Extra fields
  915. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  916. // Hook fields
  917. $parameters = array('arrayfields'=>$arrayfields, 'totalarray'=>&$totalarray, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  918. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  919. print $hookmanager->resPrint;
  920. if (!empty($arrayfields['d.datec']['checked'])) {
  921. print_liste_field_titre($arrayfields['d.datec']['label'], $_SERVER["PHP_SELF"], "d.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  922. $totalarray['nbfield']++;
  923. }
  924. if (!empty($arrayfields['d.birth']['checked'])) {
  925. print_liste_field_titre($arrayfields['d.birth']['label'], $_SERVER["PHP_SELF"], "d.birth", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  926. $totalarray['nbfield']++;
  927. }
  928. if (!empty($arrayfields['d.tms']['checked'])) {
  929. print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  930. $totalarray['nbfield']++;
  931. }
  932. if (!empty($arrayfields['d.statut']['checked'])) {
  933. print_liste_field_titre($arrayfields['d.statut']['label'], $_SERVER["PHP_SELF"], "d.statut,t.subscription,d.datefin", "", $param, 'class="right"', $sortfield, $sortorder);
  934. $totalarray['nbfield']++;
  935. }
  936. if (!empty($arrayfields['d.import_key']['checked'])) {
  937. print_liste_field_titre($arrayfields['d.import_key']['label'], $_SERVER["PHP_SELF"], "d.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  938. $totalarray['nbfield']++;
  939. }
  940. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  941. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  942. $totalarray['nbfield']++;
  943. }
  944. print "</tr>\n";
  945. // Loop on record
  946. // --------------------------------------------------------------------
  947. $i = 0;
  948. $savnbfield = $totalarray['nbfield'];
  949. $totalarray = array();
  950. $totalarray['nbfield'] = 0;
  951. $imaxinloop = ($limit ? min($num, $limit) : $num);
  952. while ($i < $imaxinloop) {
  953. $obj = $db->fetch_object($resql);
  954. if (empty($obj)) {
  955. break; // Should not happen
  956. }
  957. $datefin = $db->jdate($obj->datefin);
  958. $memberstatic->id = $obj->rowid;
  959. $memberstatic->ref = $obj->ref;
  960. $memberstatic->civility_id = $obj->civility;
  961. $memberstatic->login = $obj->login;
  962. $memberstatic->lastname = $obj->lastname;
  963. $memberstatic->firstname = $obj->firstname;
  964. $memberstatic->gender = $obj->gender;
  965. $memberstatic->statut = $obj->statut;
  966. $memberstatic->datefin = $datefin;
  967. $memberstatic->socid = $obj->fk_soc;
  968. $memberstatic->photo = $obj->photo;
  969. $memberstatic->email = $obj->email;
  970. $memberstatic->morphy = $obj->morphy;
  971. $memberstatic->note_public = $obj->note_public;
  972. $memberstatic->note_private = $obj->note_private;
  973. $memberstatic->need_subscription = $obj->subscription;
  974. if (!empty($obj->fk_soc)) {
  975. $memberstatic->fetch_thirdparty();
  976. if ($memberstatic->thirdparty->id > 0) {
  977. $companyname = $memberstatic->thirdparty->name;
  978. $companynametoshow = $memberstatic->thirdparty->getNomUrl(1);
  979. }
  980. } else {
  981. $companyname = $obj->company;
  982. $companynametoshow = $obj->company;
  983. }
  984. $memberstatic->company = $companyname;
  985. if ($mode == 'kanban') {
  986. if ($i == 0) {
  987. print '<tr><td colspan="'.$savnbfield.'">';
  988. print '<div class="box-flex-container kanban">';
  989. }
  990. $membertypestatic->id = $obj->type_id;
  991. $membertypestatic->label = $obj->type;
  992. $memberstatic->type = $membertypestatic->label;
  993. $memberstatic->photo = $obj->photo;
  994. // Output Kanban
  995. print $memberstatic->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
  996. if ($i == (min($num, $limit) - 1)) {
  997. print '</div>';
  998. print '</td></tr>';
  999. }
  1000. } else {
  1001. // Show line of result
  1002. $j = 0;
  1003. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  1004. // Action column
  1005. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1006. print '<td class="nowrap center">';
  1007. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1008. $selected = 0;
  1009. if (in_array($obj->rowid, $arrayofselected)) {
  1010. $selected = 1;
  1011. }
  1012. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1013. }
  1014. print '</td>';
  1015. if (!$i) {
  1016. $totalarray['nbfield']++;
  1017. }
  1018. }
  1019. // Technical ID
  1020. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  1021. print '<td class="center" data-key="id">'.$obj->rowid.'</td>';
  1022. if (!$i) {
  1023. $totalarray['nbfield']++;
  1024. }
  1025. }
  1026. // Ref
  1027. if (!empty($arrayfields['d.ref']['checked'])) {
  1028. print "<td>";
  1029. print $memberstatic->getNomUrl(-1, 0, 'card', 'ref', '', -1, 0, 1);
  1030. print "</td>\n";
  1031. if (!$i) {
  1032. $totalarray['nbfield']++;
  1033. }
  1034. }
  1035. // Civility
  1036. if (!empty($arrayfields['d.civility']['checked'])) {
  1037. print "<td>";
  1038. print $obj->civility;
  1039. print "</td>\n";
  1040. if (!$i) {
  1041. $totalarray['nbfield']++;
  1042. }
  1043. }
  1044. // Firstname
  1045. if (!empty($arrayfields['d.firstname']['checked'])) {
  1046. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">';
  1047. print $memberstatic->getNomUrl(0, 0, 'card', 'firstname');
  1048. //print $obj->firstname;
  1049. print "</td>\n";
  1050. if (!$i) {
  1051. $totalarray['nbfield']++;
  1052. }
  1053. }
  1054. // Lastname
  1055. if (!empty($arrayfields['d.lastname']['checked'])) {
  1056. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">';
  1057. print $memberstatic->getNomUrl(0, 0, 'card', 'lastname');
  1058. //print $obj->lastname;
  1059. print "</td>\n";
  1060. if (!$i) {
  1061. $totalarray['nbfield']++;
  1062. }
  1063. }
  1064. // Gender
  1065. if (!empty($arrayfields['d.gender']['checked'])) {
  1066. print '<td>';
  1067. if ($obj->gender) {
  1068. print $langs->trans("Gender".$obj->gender);
  1069. }
  1070. print '</td>';
  1071. if (!$i) {
  1072. $totalarray['nbfield']++;
  1073. }
  1074. }
  1075. // Company
  1076. if (!empty($arrayfields['d.company']['checked'])) {
  1077. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companyname).'">';
  1078. print $companynametoshow;
  1079. print "</td>\n";
  1080. }
  1081. // Login
  1082. if (!empty($arrayfields['d.login']['checked'])) {
  1083. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.$obj->login."</td>\n";
  1084. if (!$i) {
  1085. $totalarray['nbfield']++;
  1086. }
  1087. }
  1088. // Nature (Moral/Physical)
  1089. if (!empty($arrayfields['d.morphy']['checked'])) {
  1090. print '<td class="center">';
  1091. print $memberstatic->getmorphylib('', 2);
  1092. print "</td>\n";
  1093. if (!$i) {
  1094. $totalarray['nbfield']++;
  1095. }
  1096. }
  1097. // Type label
  1098. if (!empty($arrayfields['t.libelle']['checked'])) {
  1099. $membertypestatic->id = $obj->type_id;
  1100. $membertypestatic->label = $obj->type;
  1101. print '<td class="nowraponall">';
  1102. print $membertypestatic->getNomUrl(1, 32);
  1103. print '</td>';
  1104. if (!$i) {
  1105. $totalarray['nbfield']++;
  1106. }
  1107. }
  1108. // Address
  1109. if (!empty($arrayfields['d.address']['checked'])) {
  1110. print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->address).'">';
  1111. print $obj->address;
  1112. print '</td>';
  1113. if (!$i) {
  1114. $totalarray['nbfield']++;
  1115. }
  1116. }
  1117. // Zip
  1118. if (!empty($arrayfields['d.zip']['checked'])) {
  1119. print '<td class="nocellnopadd">';
  1120. print $obj->zip;
  1121. print '</td>';
  1122. if (!$i) {
  1123. $totalarray['nbfield']++;
  1124. }
  1125. }
  1126. // Town
  1127. if (!empty($arrayfields['d.town']['checked'])) {
  1128. print '<td class="nocellnopadd">';
  1129. print $obj->town;
  1130. print '</td>';
  1131. if (!$i) {
  1132. $totalarray['nbfield']++;
  1133. }
  1134. }
  1135. // State / County / Departement
  1136. if (!empty($arrayfields['state.nom']['checked'])) {
  1137. print "<td>".$obj->state_name."</td>\n";
  1138. if (!$i) {
  1139. $totalarray['nbfield']++;
  1140. }
  1141. }
  1142. // Country
  1143. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1144. $tmparray = getCountry($obj->country, 'all');
  1145. print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($tmparray['label']).'">';
  1146. print dol_escape_htmltag($tmparray['label']);
  1147. print '</td>';
  1148. if (!$i) {
  1149. $totalarray['nbfield']++;
  1150. }
  1151. }
  1152. // Phone pro
  1153. if (!empty($arrayfields['d.phone']['checked'])) {
  1154. print '<td class="nocellnopadd">';
  1155. print $obj->phone;
  1156. print '</td>';
  1157. if (!$i) {
  1158. $totalarray['nbfield']++;
  1159. }
  1160. }
  1161. // Phone perso
  1162. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  1163. print '<td class="nocellnopadd">';
  1164. print $obj->phone_perso;
  1165. print '</td>';
  1166. if (!$i) {
  1167. $totalarray['nbfield']++;
  1168. }
  1169. }
  1170. // Phone mobile
  1171. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  1172. print '<td class="nocellnopadd">';
  1173. print $obj->phone_mobile;
  1174. print '</td>';
  1175. if (!$i) {
  1176. $totalarray['nbfield']++;
  1177. }
  1178. }
  1179. // EMail
  1180. if (!empty($arrayfields['d.email']['checked'])) {
  1181. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->email).'">';
  1182. print dol_print_email($obj->email, 0, 0, 1, 64, 1, 1);
  1183. print "</td>\n";
  1184. if (!$i) {
  1185. $totalarray['nbfield']++;
  1186. }
  1187. }
  1188. // End of subscription date
  1189. $datefin = $db->jdate($obj->datefin);
  1190. if (!empty($arrayfields['d.datefin']['checked'])) {
  1191. print '<td class="nowrap center">';
  1192. if ($datefin) {
  1193. print dol_print_date($datefin, 'day');
  1194. if ($memberstatic->hasDelay()) {
  1195. $textlate = ' ('.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($conf->adherent->subscription->warning_delay / 60 / 60 / 24) >= 0 ? '+' : '').ceil($conf->adherent->subscription->warning_delay / 60 / 60 / 24).' '.$langs->trans("days").')';
  1196. print " ".img_warning($langs->trans("SubscriptionLate").$textlate);
  1197. }
  1198. } else {
  1199. if (!empty($obj->subscription)) {
  1200. print '<span class="opacitymedium">'.$langs->trans("SubscriptionNotReceived").'</span>';
  1201. if ($obj->statut > 0) {
  1202. print " ".img_warning();
  1203. }
  1204. } else {
  1205. print '&nbsp;';
  1206. }
  1207. }
  1208. print '</td>';
  1209. if (!$i) {
  1210. $totalarray['nbfield']++;
  1211. }
  1212. }
  1213. // Extra fields
  1214. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1215. // Fields from hook
  1216. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1217. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1218. print $hookmanager->resPrint;
  1219. // Date creation
  1220. if (!empty($arrayfields['d.datec']['checked'])) {
  1221. print '<td class="nowrap center">';
  1222. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1223. print '</td>';
  1224. if (!$i) {
  1225. $totalarray['nbfield']++;
  1226. }
  1227. }
  1228. // Birth
  1229. if (!empty($arrayfields['d.birth']['checked'])) {
  1230. print '<td class="nowrap center">';
  1231. print dol_print_date($db->jdate($obj->birth), 'day', 'tzuser');
  1232. print '</td>';
  1233. if (!$i) {
  1234. $totalarray['nbfield']++;
  1235. }
  1236. }
  1237. // Date modification
  1238. if (!empty($arrayfields['d.tms']['checked'])) {
  1239. print '<td class="nowrap center">';
  1240. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1241. print '</td>';
  1242. if (!$i) {
  1243. $totalarray['nbfield']++;
  1244. }
  1245. }
  1246. // Status
  1247. if (!empty($arrayfields['d.statut']['checked'])) {
  1248. print '<td class="nowrap right">';
  1249. print $memberstatic->LibStatut($obj->statut, $obj->subscription, $datefin, 5);
  1250. print '</td>';
  1251. if (!$i) {
  1252. $totalarray['nbfield']++;
  1253. }
  1254. }
  1255. if (!empty($arrayfields['d.import_key']['checked'])) {
  1256. print '<td class="tdoverflowmax100 center" title="'.dol_escape_htmltag($obj->import_key).'">';
  1257. print dol_escape_htmltag($obj->import_key);
  1258. print "</td>\n";
  1259. if (!$i) {
  1260. $totalarray['nbfield']++;
  1261. }
  1262. }
  1263. // Action column
  1264. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  1265. print '<td class="center">';
  1266. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1267. $selected = 0;
  1268. if (in_array($obj->rowid, $arrayofselected)) {
  1269. $selected = 1;
  1270. }
  1271. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1272. }
  1273. print '</td>';
  1274. if (!$i) {
  1275. $totalarray['nbfield']++;
  1276. }
  1277. }
  1278. print '</tr>'."\n";
  1279. }
  1280. $i++;
  1281. }
  1282. // Show total line
  1283. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1284. // If no record found
  1285. if ($num == 0) {
  1286. $colspan = 1;
  1287. foreach ($arrayfields as $key => $val) {
  1288. if (!empty($val['checked'])) {
  1289. $colspan++;
  1290. }
  1291. }
  1292. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1293. }
  1294. $db->free($resql);
  1295. $parameters = array('arrayfields'=>$arrayfields, 'sql' => $sql);
  1296. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1297. print $hookmanager->resPrint;
  1298. print '</table>'."\n";
  1299. print '</div>'."\n";
  1300. print '</form>'."\n";
  1301. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  1302. $hidegeneratedfilelistifempty = 1;
  1303. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  1304. $hidegeneratedfilelistifempty = 0;
  1305. }
  1306. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  1307. $formfile = new FormFile($db);
  1308. // Show list of available documents
  1309. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  1310. $urlsource .= str_replace('&amp;', '&', $param);
  1311. $filedir = $diroutputmassaction;
  1312. $genallowed = $permissiontoread;
  1313. $delallowed = $permissiontoadd;
  1314. print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  1315. }
  1316. // End of page
  1317. llxFooter();
  1318. $db->close();