list.php 49 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377
  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. $sall = 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. $sall = "";
  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 ($sall) {
  359. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  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 (empty($conf->global->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) && $sall) {
  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 ($sall != "") {
  499. $param .= "&sall=".urlencode($sall);
  500. }
  501. if ($search_ref) {
  502. $param .= "&search_ref=".urlencode($search_ref);
  503. }
  504. if ($search_civility) {
  505. $param .= "&search_civility=".urlencode($search_civility);
  506. }
  507. if ($search_firstname) {
  508. $param .= "&search_firstname=".urlencode($search_firstname);
  509. }
  510. if ($search_lastname) {
  511. $param .= "&search_lastname=".urlencode($search_lastname);
  512. }
  513. if ($search_gender) {
  514. $param .= "&search_gender=".urlencode($search_gender);
  515. }
  516. if ($search_login) {
  517. $param .= "&search_login=".urlencode($search_login);
  518. }
  519. if ($search_email) {
  520. $param .= "&search_email=".urlencode($search_email);
  521. }
  522. if ($search_categ > 0 || $search_categ == -2) {
  523. $param .= "&search_categ=".urlencode($search_categ);
  524. }
  525. if ($search_company) {
  526. $param .= "&search_company=".urlencode($search_company);
  527. }
  528. if ($search_address != '') {
  529. $param .= "&search_address=".urlencode($search_address);
  530. }
  531. if ($search_town != '') {
  532. $param .= "&search_town=".urlencode($search_town);
  533. }
  534. if ($search_zip != '') {
  535. $param .= "&search_zip=".urlencode($search_zip);
  536. }
  537. if ($search_state != '') {
  538. $param .= "&search_state=".urlencode($search_state);
  539. }
  540. if ($search_country != '') {
  541. $param .= "&search_country=".urlencode($search_country);
  542. }
  543. if ($search_phone != '') {
  544. $param .= "&search_phone=".urlencode($search_phone);
  545. }
  546. if ($search_phone_perso != '') {
  547. $param .= "&search_phone_perso=".urlencode($search_phone_perso);
  548. }
  549. if ($search_phone_mobile != '') {
  550. $param .= "&search_phone_mobile=".urlencode($search_phone_mobile);
  551. }
  552. if ($search_filter && $search_filter != '-1') {
  553. $param .= "&search_filter=".urlencode($search_filter);
  554. }
  555. if ($search_status != "" && $search_status != -3) {
  556. $param .= "&search_status=".urlencode($search_status);
  557. }
  558. if ($search_import_key != '') {
  559. $param .= '&search_import_key='.urlencode($search_import_key);
  560. }
  561. if ($search_type > 0) {
  562. $param .= "&search_type=".urlencode($search_type);
  563. }
  564. if ($optioncss != '') {
  565. $param .= '&optioncss='.urlencode($optioncss);
  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. $newcardbutton = '';
  591. $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'));
  592. $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'));
  593. if ($user->hasRight('adherent', 'creer')) {
  594. $newcardbutton .= dolGetButtonTitle($langs->trans('NewMember'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/adherents/card.php?action=create');
  595. }
  596. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
  597. if ($optioncss != '') {
  598. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  599. }
  600. print '<input type="hidden" name="token" value="'.newToken().'">';
  601. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  602. print '<input type="hidden" name="action" value="list">';
  603. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  604. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  605. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  606. print '<input type="hidden" name="mode" value="'.$mode.'">';
  607. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  608. $topicmail = "Information";
  609. $modelmail = "member";
  610. $objecttmp = new Adherent($db);
  611. $trackid = 'mem'.$object->id;
  612. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  613. if ($sall) {
  614. foreach ($fieldstosearchall as $key => $val) {
  615. $fieldstosearchall[$key] = $langs->trans($val);
  616. }
  617. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  618. }
  619. // Filter on categories
  620. $moreforfilter = '';
  621. if (isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
  622. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  623. $moreforfilter .= '<div class="divsearchfield">';
  624. $moreforfilter .= img_picto($langs->trans('Categories'), 'category', 'class="pictofixedlength"').$formother->select_categories(Categorie::TYPE_MEMBER, $search_categ, 'search_categ', 1, $langs->trans("MembersCategoriesShort"));
  625. $moreforfilter .= '</div>';
  626. }
  627. $parameters = array();
  628. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  629. if (empty($reshook)) {
  630. $moreforfilter .= $hookmanager->resPrint;
  631. } else {
  632. $moreforfilter = $hookmanager->resPrint;
  633. }
  634. if (!empty($moreforfilter)) {
  635. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  636. print $moreforfilter;
  637. print '</div>';
  638. }
  639. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  640. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  641. if ($massactionbutton) {
  642. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  643. }
  644. print '<div class="div-table-responsive">';
  645. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  646. // Line for filters fields
  647. print '<tr class="liste_titre_filter">';
  648. // Action column
  649. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  650. print '<td class="liste_titre middle">';
  651. $searchpicto = $form->showFilterButtons('left');
  652. print $searchpicto;
  653. print '</td>';
  654. }
  655. // Line numbering
  656. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  657. print '<td class="liste_titre">&nbsp;</td>';
  658. }
  659. // Ref
  660. if (!empty($arrayfields['d.ref']['checked'])) {
  661. print '<td class="liste_titre">';
  662. print '<input class="flat maxwidth75imp" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
  663. print '</td>';
  664. }
  665. // Civility
  666. if (!empty($arrayfields['d.civility']['checked'])) {
  667. print '<td class="liste_titre left">';
  668. print '<input class="flat maxwidth50imp" type="text" name="search_civility" value="'.dol_escape_htmltag($search_civility).'"></td>';
  669. }
  670. // First Name
  671. if (!empty($arrayfields['d.firstname']['checked'])) {
  672. print '<td class="liste_titre left">';
  673. print '<input class="flat maxwidth75imp" type="text" name="search_firstname" value="'.dol_escape_htmltag($search_firstname).'"></td>';
  674. }
  675. // Last Name
  676. if (!empty($arrayfields['d.lastname']['checked'])) {
  677. print '<td class="liste_titre left">';
  678. print '<input class="flat maxwidth75imp" type="text" name="search_lastname" value="'.dol_escape_htmltag($search_lastname).'"></td>';
  679. }
  680. // Gender
  681. if (!empty($arrayfields['d.gender']['checked'])) {
  682. print '<td class="liste_titre">';
  683. $arraygender = array('man'=>$langs->trans("Genderman"), 'woman'=>$langs->trans("Genderwoman"), 'other'=>$langs->trans("Genderother"));
  684. print $form->selectarray('search_gender', $arraygender, $search_gender, 1);
  685. print '</td>';
  686. }
  687. // Company
  688. if (!empty($arrayfields['d.company']['checked'])) {
  689. print '<td class="liste_titre left">';
  690. print '<input class="flat maxwidth75imp" type="text" name="search_company" value="'.dol_escape_htmltag($search_company).'"></td>';
  691. }
  692. // Login
  693. if (!empty($arrayfields['d.login']['checked'])) {
  694. print '<td class="liste_titre left">';
  695. print '<input class="flat maxwidth75imp" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'"></td>';
  696. }
  697. // Nature
  698. if (!empty($arrayfields['d.morphy']['checked'])) {
  699. print '<td class="liste_titre center">';
  700. $arraymorphy = array('mor'=>$langs->trans("Moral"), 'phy'=>$langs->trans("Physical"));
  701. print $form->selectarray('search_morphy', $arraymorphy, $search_morphy, 1, 0, 0, '', 0, 0, 0, '', 'maxwidth100');
  702. print '</td>';
  703. }
  704. // Member Type
  705. if (!empty($arrayfields['t.libelle']['checked'])) {
  706. print '</td>';
  707. }
  708. if (!empty($arrayfields['t.libelle']['checked'])) {
  709. print '<td class="liste_titre">';
  710. $listetype = $membertypestatic->liste_array();
  711. print $form->selectarray("search_type", $listetype, $search_type, 1, 0, 0, '', 0, 32);
  712. print '</td>';
  713. }
  714. // Address - Street
  715. if (!empty($arrayfields['d.address']['checked'])) {
  716. print '<td class="liste_titre left">';
  717. print '<input class="flat maxwidth75imp" type="text" name="search_address" value="'.dol_escape_htmltag($search_address).'"></td>';
  718. }
  719. // ZIP
  720. if (!empty($arrayfields['d.zip']['checked'])) {
  721. print '<td class="liste_titre left">';
  722. print '<input class="flat maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  723. }
  724. // Town/City
  725. if (!empty($arrayfields['d.town']['checked'])) {
  726. print '<td class="liste_titre left">';
  727. print '<input class="flat maxwidth75imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  728. }
  729. // State / County / Departement
  730. if (!empty($arrayfields['state.nom']['checked'])) {
  731. print '<td class="liste_titre">';
  732. print '<input class="flat searchstring maxwidth75imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  733. print '</td>';
  734. }
  735. // Country
  736. if (!empty($arrayfields['country.code_iso']['checked'])) {
  737. print '<td class="liste_titre center">';
  738. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  739. print '</td>';
  740. }
  741. // Phone pro
  742. if (!empty($arrayfields['d.phone']['checked'])) {
  743. print '<td class="liste_titre left">';
  744. print '<input class="flat maxwidth75imp" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'"></td>';
  745. }
  746. // Phone perso
  747. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  748. print '<td class="liste_titre left">';
  749. print '<input class="flat maxwidth75imp" type="text" name="search_phone_perso" value="'.dol_escape_htmltag($search_phone_perso).'"></td>';
  750. }
  751. // Phone mobile
  752. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  753. print '<td class="liste_titre left">';
  754. print '<input class="flat maxwidth75imp" type="text" name="search_phone_mobile" value="'.dol_escape_htmltag($search_phone_mobile).'"></td>';
  755. }
  756. // Email
  757. if (!empty($arrayfields['d.email']['checked'])) {
  758. print '<td class="liste_titre left">';
  759. print '<input class="flat maxwidth75imp" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'"></td>';
  760. }
  761. // End of subscription date
  762. if (!empty($arrayfields['d.datefin']['checked'])) {
  763. print '<td class="liste_titre center">';
  764. //$selectarray = array('-1'=>'', 'withoutsubscription'=>$langs->trans("WithoutSubscription"), 'uptodate'=>$langs->trans("UpToDate"), 'outofdate'=>$langs->trans("OutOfDate"));
  765. $selectarray = array('-1'=>'', 'waitingsubscription'=>$langs->trans("WaitingSubscription"), 'uptodate'=>$langs->trans("UpToDate"), 'outofdate'=>$langs->trans("OutOfDate"));
  766. print $form->selectarray('search_filter', $selectarray, $search_filter);
  767. print '</td>';
  768. }
  769. // Extra fields
  770. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  771. // Fields from hook
  772. $parameters = array('arrayfields'=>$arrayfields);
  773. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  774. print $hookmanager->resPrint;
  775. // Date creation
  776. if (!empty($arrayfields['d.datec']['checked'])) {
  777. print '<td class="liste_titre">';
  778. print '</td>';
  779. }
  780. // Birthday
  781. if (!empty($arrayfields['d.birth']['checked'])) {
  782. print '<td class="liste_titre">';
  783. print '</td>';
  784. }
  785. // Date modification
  786. if (!empty($arrayfields['d.tms']['checked'])) {
  787. print '<td class="liste_titre">';
  788. print '</td>';
  789. }
  790. // Status
  791. if (!empty($arrayfields['d.statut']['checked'])) {
  792. print '<td class="liste_titre right parentonrightofpage">';
  793. $liststatus = array(
  794. Adherent::STATUS_DRAFT => $langs->trans("Draft"),
  795. Adherent::STATUS_VALIDATED => $langs->trans("Validated"),
  796. Adherent::STATUS_RESILIATED => $langs->trans("MemberStatusResiliatedShort"),
  797. Adherent::STATUS_EXCLUDED =>$langs->trans("MemberStatusExcludedShort")
  798. );
  799. print $form->selectarray('search_status', $liststatus, $search_status, -3, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
  800. print '</td>';
  801. }
  802. // Import Key
  803. if (!empty($arrayfields['d.import_key']['checked'])) {
  804. print '<td class="liste_titre center">';
  805. print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
  806. print '</td>';
  807. }
  808. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  809. // Action column
  810. print '<td class="liste_titre middle">';
  811. $searchpicto = $form->showFilterButtons();
  812. print $searchpicto;
  813. print '</td>';
  814. }
  815. print "</tr>\n";
  816. print '<tr class="liste_titre">';
  817. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  818. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch actioncolumn ');
  819. }
  820. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  821. print_liste_field_titre("ID", $_SERVER["PHP_SELF"], '', '', $param, 'align="center"', $sortfield, $sortorder);
  822. }
  823. if (!empty($arrayfields['d.ref']['checked'])) {
  824. print_liste_field_titre($arrayfields['d.ref']['label'], $_SERVER["PHP_SELF"], 'd.ref', '', $param, '', $sortfield, $sortorder);
  825. }
  826. if (!empty($arrayfields['d.civility']['checked'])) {
  827. print_liste_field_titre($arrayfields['d.civility']['label'], $_SERVER["PHP_SELF"], 'd.civility', '', $param, '', $sortfield, $sortorder);
  828. }
  829. if (!empty($arrayfields['d.firstname']['checked'])) {
  830. print_liste_field_titre($arrayfields['d.firstname']['label'], $_SERVER["PHP_SELF"], 'd.firstname', '', $param, '', $sortfield, $sortorder);
  831. }
  832. if (!empty($arrayfields['d.lastname']['checked'])) {
  833. print_liste_field_titre($arrayfields['d.lastname']['label'], $_SERVER["PHP_SELF"], 'd.lastname', '', $param, '', $sortfield, $sortorder);
  834. }
  835. if (!empty($arrayfields['d.gender']['checked'])) {
  836. print_liste_field_titre($arrayfields['d.gender']['label'], $_SERVER['PHP_SELF'], 'd.gender', $param, "", "", $sortfield, $sortorder);
  837. }
  838. if (!empty($arrayfields['d.company']['checked'])) {
  839. print_liste_field_titre($arrayfields['d.company']['label'], $_SERVER["PHP_SELF"], 'companyname', '', $param, '', $sortfield, $sortorder);
  840. }
  841. if (!empty($arrayfields['d.login']['checked'])) {
  842. print_liste_field_titre($arrayfields['d.login']['label'], $_SERVER["PHP_SELF"], 'd.login', '', $param, '', $sortfield, $sortorder);
  843. }
  844. if (!empty($arrayfields['d.morphy']['checked'])) {
  845. print_liste_field_titre($arrayfields['d.morphy']['label'], $_SERVER["PHP_SELF"], 'd.morphy', '', $param, '', $sortfield, $sortorder);
  846. }
  847. if (!empty($arrayfields['t.libelle']['checked'])) {
  848. print_liste_field_titre($arrayfields['t.libelle']['label'], $_SERVER["PHP_SELF"], 't.libelle', '', $param, '', $sortfield, $sortorder);
  849. }
  850. if (!empty($arrayfields['d.address']['checked'])) {
  851. print_liste_field_titre($arrayfields['d.address']['label'], $_SERVER["PHP_SELF"], 'd.address', '', $param, '', $sortfield, $sortorder);
  852. }
  853. if (!empty($arrayfields['d.zip']['checked'])) {
  854. print_liste_field_titre($arrayfields['d.zip']['label'], $_SERVER["PHP_SELF"], 'd.zip', '', $param, '', $sortfield, $sortorder);
  855. }
  856. if (!empty($arrayfields['d.town']['checked'])) {
  857. print_liste_field_titre($arrayfields['d.town']['label'], $_SERVER["PHP_SELF"], 'd.town', '', $param, '', $sortfield, $sortorder);
  858. }
  859. if (!empty($arrayfields['state.nom']['checked'])) {
  860. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  861. }
  862. if (!empty($arrayfields['country.code_iso']['checked'])) {
  863. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  864. }
  865. if (!empty($arrayfields['d.phone']['checked'])) {
  866. print_liste_field_titre($arrayfields['d.phone']['label'], $_SERVER["PHP_SELF"], 'd.phone', '', $param, '', $sortfield, $sortorder);
  867. }
  868. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  869. print_liste_field_titre($arrayfields['d.phone_perso']['label'], $_SERVER["PHP_SELF"], 'd.phone_perso', '', $param, '', $sortfield, $sortorder);
  870. }
  871. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  872. print_liste_field_titre($arrayfields['d.phone_mobile']['label'], $_SERVER["PHP_SELF"], 'd.phone_mobile', '', $param, '', $sortfield, $sortorder);
  873. }
  874. if (!empty($arrayfields['d.email']['checked'])) {
  875. print_liste_field_titre($arrayfields['d.email']['label'], $_SERVER["PHP_SELF"], 'd.email', '', $param, '', $sortfield, $sortorder);
  876. }
  877. if (!empty($arrayfields['d.datefin']['checked'])) {
  878. print_liste_field_titre($arrayfields['d.datefin']['label'], $_SERVER["PHP_SELF"], 'd.datefin,t.subscription', '', $param, '', $sortfield, $sortorder, 'center ');
  879. }
  880. // Extra fields
  881. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  882. // Hook fields
  883. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  884. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  885. print $hookmanager->resPrint;
  886. if (!empty($arrayfields['d.datec']['checked'])) {
  887. print_liste_field_titre($arrayfields['d.datec']['label'], $_SERVER["PHP_SELF"], "d.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  888. }
  889. if (!empty($arrayfields['d.birth']['checked'])) {
  890. print_liste_field_titre($arrayfields['d.birth']['label'], $_SERVER["PHP_SELF"], "d.birth", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  891. }
  892. if (!empty($arrayfields['d.tms']['checked'])) {
  893. print_liste_field_titre($arrayfields['d.tms']['label'], $_SERVER["PHP_SELF"], "d.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
  894. }
  895. if (!empty($arrayfields['d.statut']['checked'])) {
  896. print_liste_field_titre($arrayfields['d.statut']['label'], $_SERVER["PHP_SELF"], "d.statut,t.subscription,d.datefin", "", $param, 'class="right"', $sortfield, $sortorder);
  897. }
  898. if (!empty($arrayfields['d.import_key']['checked'])) {
  899. print_liste_field_titre($arrayfields['d.import_key']['label'], $_SERVER["PHP_SELF"], "d.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  900. }
  901. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  902. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
  903. }
  904. print "</tr>\n";
  905. $i = 0;
  906. $totalarray = array();
  907. $totalarray['nbfield'] = 0;
  908. $imaxinloop = ($limit ? min($num, $limit) : $num);
  909. while ($i < $imaxinloop) {
  910. $obj = $db->fetch_object($resql);
  911. $datefin = $db->jdate($obj->datefin);
  912. $memberstatic->id = $obj->rowid;
  913. $memberstatic->ref = $obj->ref;
  914. $memberstatic->civility_id = $obj->civility;
  915. $memberstatic->login = $obj->login;
  916. $memberstatic->lastname = $obj->lastname;
  917. $memberstatic->firstname = $obj->firstname;
  918. $memberstatic->gender = $obj->gender;
  919. $memberstatic->statut = $obj->statut;
  920. $memberstatic->datefin = $datefin;
  921. $memberstatic->socid = $obj->fk_soc;
  922. $memberstatic->photo = $obj->photo;
  923. $memberstatic->email = $obj->email;
  924. $memberstatic->morphy = $obj->morphy;
  925. $memberstatic->note_public = $obj->note_public;
  926. $memberstatic->note_private = $obj->note_private;
  927. $memberstatic->need_subscription = $obj->subscription;
  928. if (!empty($obj->fk_soc)) {
  929. $memberstatic->fetch_thirdparty();
  930. if ($memberstatic->thirdparty->id > 0) {
  931. $companyname = $memberstatic->thirdparty->name;
  932. $companynametoshow = $memberstatic->thirdparty->getNomUrl(1);
  933. }
  934. } else {
  935. $companyname = $obj->company;
  936. $companynametoshow = $obj->company;
  937. }
  938. $memberstatic->company = $companyname;
  939. if ($mode == 'kanban') {
  940. if ($i == 0) {
  941. print '<tr><td colspan="12">';
  942. print '<div class="box-flex-container kanban">';
  943. }
  944. $membertypestatic->id = $obj->type_id;
  945. $membertypestatic->label = $obj->type;
  946. $memberstatic->type = $membertypestatic->label;
  947. $memberstatic->photo = $obj->photo;
  948. // Output Kanban
  949. print $memberstatic->getKanbanView('');
  950. if ($i == (min($num, $limit) - 1)) {
  951. print '</div>';
  952. print '</td></tr>';
  953. }
  954. } else {
  955. print '<tr class="oddeven">';
  956. // Action column
  957. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  958. print '<td class="center">';
  959. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  960. $selected = 0;
  961. if (in_array($obj->rowid, $arrayofselected)) {
  962. $selected = 1;
  963. }
  964. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  965. }
  966. print '</td>';
  967. }
  968. // Technical ID
  969. if (!empty($conf->global->MAIN_SHOW_TECHNICAL_ID)) {
  970. print '<td class="center" data-key="id">'.$obj->rowid.'</td>';
  971. if (!$i) {
  972. $totalarray['nbfield']++;
  973. }
  974. }
  975. // Ref
  976. if (!empty($arrayfields['d.ref']['checked'])) {
  977. print "<td>";
  978. print $memberstatic->getNomUrl(-1, 0, 'card', 'ref', '', -1, 0, 1);
  979. print "</td>\n";
  980. if (!$i) {
  981. $totalarray['nbfield']++;
  982. }
  983. }
  984. // Civility
  985. if (!empty($arrayfields['d.civility']['checked'])) {
  986. print "<td>";
  987. print $obj->civility;
  988. print "</td>\n";
  989. if (!$i) {
  990. $totalarray['nbfield']++;
  991. }
  992. }
  993. // Firstname
  994. if (!empty($arrayfields['d.firstname']['checked'])) {
  995. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">';
  996. print $memberstatic->getNomUrl(0, 0, 'card', 'firstname');
  997. //print $obj->firstname;
  998. print "</td>\n";
  999. if (!$i) {
  1000. $totalarray['nbfield']++;
  1001. }
  1002. }
  1003. // Lastname
  1004. if (!empty($arrayfields['d.lastname']['checked'])) {
  1005. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->lastname).'">';
  1006. print $memberstatic->getNomUrl(0, 0, 'card', 'lastname');
  1007. //print $obj->lastname;
  1008. print "</td>\n";
  1009. if (!$i) {
  1010. $totalarray['nbfield']++;
  1011. }
  1012. }
  1013. // Gender
  1014. if (!empty($arrayfields['d.gender']['checked'])) {
  1015. print '<td>';
  1016. if ($obj->gender) {
  1017. print $langs->trans("Gender".$obj->gender);
  1018. }
  1019. print '</td>';
  1020. if (!$i) {
  1021. $totalarray['nbfield']++;
  1022. }
  1023. }
  1024. // Company
  1025. if (!empty($arrayfields['d.company']['checked'])) {
  1026. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companyname).'">';
  1027. print $companynametoshow;
  1028. print "</td>\n";
  1029. }
  1030. // Login
  1031. if (!empty($arrayfields['d.login']['checked'])) {
  1032. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->login).'">'.$obj->login."</td>\n";
  1033. if (!$i) {
  1034. $totalarray['nbfield']++;
  1035. }
  1036. }
  1037. // Nature (Moral/Physical)
  1038. if (!empty($arrayfields['d.morphy']['checked'])) {
  1039. print '<td class="center">';
  1040. print $memberstatic->getmorphylib('', 2);
  1041. print "</td>\n";
  1042. if (!$i) {
  1043. $totalarray['nbfield']++;
  1044. }
  1045. }
  1046. // Type label
  1047. if (!empty($arrayfields['t.libelle']['checked'])) {
  1048. $membertypestatic->id = $obj->type_id;
  1049. $membertypestatic->label = $obj->type;
  1050. print '<td class="nowraponall">';
  1051. print $membertypestatic->getNomUrl(1, 32);
  1052. print '</td>';
  1053. if (!$i) {
  1054. $totalarray['nbfield']++;
  1055. }
  1056. }
  1057. // Address
  1058. if (!empty($arrayfields['d.address']['checked'])) {
  1059. print '<td class="nocellnopadd tdoverflowmax200" title="'.dol_escape_htmltag($obj->address).'">';
  1060. print $obj->address;
  1061. print '</td>';
  1062. if (!$i) {
  1063. $totalarray['nbfield']++;
  1064. }
  1065. }
  1066. // Zip
  1067. if (!empty($arrayfields['d.zip']['checked'])) {
  1068. print '<td class="nocellnopadd">';
  1069. print $obj->zip;
  1070. print '</td>';
  1071. if (!$i) {
  1072. $totalarray['nbfield']++;
  1073. }
  1074. }
  1075. // Town
  1076. if (!empty($arrayfields['d.town']['checked'])) {
  1077. print '<td class="nocellnopadd">';
  1078. print $obj->town;
  1079. print '</td>';
  1080. if (!$i) {
  1081. $totalarray['nbfield']++;
  1082. }
  1083. }
  1084. // State / County / Departement
  1085. if (!empty($arrayfields['state.nom']['checked'])) {
  1086. print "<td>".$obj->state_name."</td>\n";
  1087. if (!$i) {
  1088. $totalarray['nbfield']++;
  1089. }
  1090. }
  1091. // Country
  1092. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1093. $tmparray = getCountry($obj->country, 'all');
  1094. print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($tmparray['label']).'">';
  1095. print dol_escape_htmltag($tmparray['label']);
  1096. print '</td>';
  1097. if (!$i) {
  1098. $totalarray['nbfield']++;
  1099. }
  1100. }
  1101. // Phone pro
  1102. if (!empty($arrayfields['d.phone']['checked'])) {
  1103. print '<td class="nocellnopadd">';
  1104. print $obj->phone;
  1105. print '</td>';
  1106. if (!$i) {
  1107. $totalarray['nbfield']++;
  1108. }
  1109. }
  1110. // Phone perso
  1111. if (!empty($arrayfields['d.phone_perso']['checked'])) {
  1112. print '<td class="nocellnopadd">';
  1113. print $obj->phone_perso;
  1114. print '</td>';
  1115. if (!$i) {
  1116. $totalarray['nbfield']++;
  1117. }
  1118. }
  1119. // Phone mobile
  1120. if (!empty($arrayfields['d.phone_mobile']['checked'])) {
  1121. print '<td class="nocellnopadd">';
  1122. print $obj->phone_mobile;
  1123. print '</td>';
  1124. if (!$i) {
  1125. $totalarray['nbfield']++;
  1126. }
  1127. }
  1128. // EMail
  1129. if (!empty($arrayfields['d.email']['checked'])) {
  1130. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->email).'">';
  1131. print dol_print_email($obj->email, 0, 0, 1, 64, 1, 1);
  1132. print "</td>\n";
  1133. }
  1134. // End of subscription date
  1135. $datefin = $db->jdate($obj->datefin);
  1136. if (!empty($arrayfields['d.datefin']['checked'])) {
  1137. print '<td class="nowrap center">';
  1138. if ($datefin) {
  1139. print dol_print_date($datefin, 'day');
  1140. if ($memberstatic->hasDelay()) {
  1141. $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").')';
  1142. print " ".img_warning($langs->trans("SubscriptionLate").$textlate);
  1143. }
  1144. } else {
  1145. if (!empty($obj->subscription)) {
  1146. print '<span class="opacitymedium">'.$langs->trans("SubscriptionNotReceived").'</span>';
  1147. if ($obj->statut > 0) {
  1148. print " ".img_warning();
  1149. }
  1150. } else {
  1151. print '&nbsp;';
  1152. }
  1153. }
  1154. print '</td>';
  1155. }
  1156. // Extra fields
  1157. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1158. // Fields from hook
  1159. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1160. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  1161. print $hookmanager->resPrint;
  1162. // Date creation
  1163. if (!empty($arrayfields['d.datec']['checked'])) {
  1164. print '<td class="nowrap center">';
  1165. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1166. print '</td>';
  1167. if (!$i) {
  1168. $totalarray['nbfield']++;
  1169. }
  1170. }
  1171. // Birth
  1172. if (!empty($arrayfields['d.birth']['checked'])) {
  1173. print '<td class="nowrap center">';
  1174. print dol_print_date($db->jdate($obj->birth), 'day', 'tzuser');
  1175. print '</td>';
  1176. if (!$i) {
  1177. $totalarray['nbfield']++;
  1178. }
  1179. }
  1180. // Date modification
  1181. if (!empty($arrayfields['d.tms']['checked'])) {
  1182. print '<td class="nowrap center">';
  1183. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1184. print '</td>';
  1185. if (!$i) {
  1186. $totalarray['nbfield']++;
  1187. }
  1188. }
  1189. // Status
  1190. if (!empty($arrayfields['d.statut']['checked'])) {
  1191. print '<td class="nowrap right">';
  1192. print $memberstatic->LibStatut($obj->statut, $obj->subscription, $datefin, 5);
  1193. print '</td>';
  1194. if (!$i) {
  1195. $totalarray['nbfield']++;
  1196. }
  1197. }
  1198. if (!empty($arrayfields['d.import_key']['checked'])) {
  1199. print '<td class="tdoverflowmax100 center" title="'.dol_escape_htmltag($obj->import_key).'">';
  1200. print dol_escape_htmltag($obj->import_key);
  1201. print "</td>\n";
  1202. if (!$i) {
  1203. $totalarray['nbfield']++;
  1204. }
  1205. }
  1206. // Action column
  1207. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1208. print '<td class="center">';
  1209. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1210. $selected = 0;
  1211. if (in_array($obj->rowid, $arrayofselected)) {
  1212. $selected = 1;
  1213. }
  1214. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1215. }
  1216. print '</td>';
  1217. }
  1218. if (!$i) {
  1219. $totalarray['nbfield']++;
  1220. }
  1221. print '</tr>'."\n";
  1222. }
  1223. $i++;
  1224. }
  1225. // Show total line
  1226. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1227. // If no record found
  1228. if ($num == 0) {
  1229. $colspan = 1;
  1230. foreach ($arrayfields as $key => $val) {
  1231. if (!empty($val['checked'])) {
  1232. $colspan++;
  1233. }
  1234. }
  1235. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1236. }
  1237. $db->free($resql);
  1238. $parameters = array('sql' => $sql);
  1239. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  1240. print $hookmanager->resPrint;
  1241. print "</table>\n";
  1242. print "</div>";
  1243. print '</form>';
  1244. // End of page
  1245. llxFooter();
  1246. $db->close();