list.php 58 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2003 Eric Seigne <erics@rycks.com>
  4. * Copyright (C) 2004-2012 Laurent Destailleur <eldy@users.sourceforge.net>
  5. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  6. * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
  7. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  8. * Copyright (C) 2013 Alexandre Spangaro <aspangaro@open-dsi.fr>
  9. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  10. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
  11. * Copyright (C) 2018 Juanjo Menent <jmenent@2byte.es>
  12. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  13. * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
  14. * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
  15. *
  16. * This program is free software; you can redistribute it and/or modify
  17. * it under the terms of the GNU General Public License as published by
  18. * the Free Software Foundation; either version 3 of the License, or
  19. * (at your option) any later version.
  20. *
  21. * This program is distributed in the hope that it will be useful,
  22. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  23. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  24. * GNU General Public License for more details.
  25. *
  26. * You should have received a copy of the GNU General Public License
  27. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  28. */
  29. /**
  30. * \file htdocs/contact/list.php
  31. * \ingroup societe
  32. * \brief Page to list all contacts
  33. */
  34. // Load Dolibarr environment
  35. require '../main.inc.php';
  36. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  39. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  40. // Load translation files required by the page
  41. $langs->loadLangs(array("companies", "suppliers", "categories"));
  42. $socialnetworks = getArrayOfSocialNetworks();
  43. // Get parameters
  44. $action = GETPOST('action', 'aZ09');
  45. $massaction = GETPOST('massaction', 'alpha');
  46. $show_files = GETPOST('show_files', 'int');
  47. $confirm = GETPOST('confirm', 'alpha');
  48. $toselect = GETPOST('toselect', 'array');
  49. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contactlist';
  50. // Security check
  51. $id = GETPOST('id', 'int');
  52. $contactid = GETPOST('id', 'int');
  53. $ref = ''; // There is no ref for contacts
  54. if ($user->socid) {
  55. $socid = $user->socid;
  56. }
  57. $result = restrictedArea($user, 'contact', $contactid, '');
  58. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  59. $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
  60. $search_phone = GETPOST("search_phone", 'alpha');
  61. $search_id = GETPOST("search_id", "int");
  62. $search_firstlast_only = GETPOST("search_firstlast_only", 'alpha');
  63. $search_lastname = GETPOST("search_lastname", 'alpha');
  64. $search_firstname = GETPOST("search_firstname", 'alpha');
  65. $search_societe = GETPOST("search_societe", 'alpha');
  66. $search_societe_alias = GETPOST("search_societe_alias", 'alpha');
  67. $search_poste = GETPOST("search_poste", 'alpha');
  68. $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
  69. $search_phone_pro = GETPOST("search_phone_pro", 'alpha');
  70. $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
  71. $search_fax = GETPOST("search_fax", 'alpha');
  72. $search_email = GETPOST("search_email", 'alpha');
  73. if (isModEnabled('mailing')) {
  74. $search_no_email = GETPOSTISSET("search_no_email") ? GETPOST("search_no_email", 'int') : -1;
  75. } else {
  76. $search_no_email = -1;
  77. }
  78. if (isModEnabled('socialnetworks')) {
  79. foreach ($socialnetworks as $key => $value) {
  80. if ($value['active']) {
  81. $search_[$key] = GETPOST("search_".$key, 'alpha');
  82. }
  83. }
  84. }
  85. $search_priv = GETPOST("search_priv", 'alpha');
  86. $search_categ = GETPOST("search_categ", 'int');
  87. $search_categ_thirdparty = GETPOST("search_categ_thirdparty", 'int');
  88. $search_categ_supplier = GETPOST("search_categ_supplier", 'int');
  89. $search_status = GETPOST("search_status", 'int');
  90. $search_type = GETPOST('search_type', 'alpha');
  91. $search_address = GETPOST('search_address', 'alpha');
  92. $search_zip = GETPOST('search_zip', 'alpha');
  93. $search_town = GETPOST('search_town', 'alpha');
  94. $search_import_key = GETPOST("search_import_key", "alpha");
  95. $search_country = GETPOST("search_country", 'intcomma');
  96. $search_roles = GETPOST("search_roles", 'array');
  97. $search_level = GETPOST("search_level", "array");
  98. $search_stcomm = GETPOST('search_stcomm', 'int');
  99. if ($search_status === '') {
  100. $search_status = 1; // always display active customer first
  101. }
  102. if ($search_no_email === '') {
  103. $search_no_email = -1;
  104. }
  105. $optioncss = GETPOST('optioncss', 'alpha');
  106. $type = GETPOST("type", 'aZ');
  107. $view = GETPOST("view", 'alpha');
  108. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  109. $sortfield = GETPOST('sortfield', 'aZ09comma');
  110. $sortorder = GETPOST('sortorder', 'aZ09comma');
  111. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  112. $userid = GETPOST('userid', 'int');
  113. $begin = GETPOST('begin');
  114. if (!$sortorder) {
  115. $sortorder = "ASC";
  116. }
  117. if (!$sortfield) {
  118. $sortfield = "p.lastname";
  119. }
  120. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  121. $page = 0;
  122. }
  123. $offset = $limit * $page;
  124. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  125. if ($type == "p") {
  126. if (empty($contextpage) || $contextpage == 'contactlist') {
  127. $contextpage = 'contactprospectlist';
  128. }
  129. $title .= ' ('.$langs->trans("ThirdPartyProspects").')';
  130. $urlfiche = "card.php";
  131. }
  132. if ($type == "c") {
  133. if (empty($contextpage) || $contextpage == 'contactlist') {
  134. $contextpage = 'contactcustomerlist';
  135. }
  136. $title .= ' ('.$langs->trans("ThirdPartyCustomers").')';
  137. $urlfiche = "card.php";
  138. } elseif ($type == "f") {
  139. if (empty($contextpage) || $contextpage == 'contactlist') {
  140. $contextpage = 'contactsupplierlist';
  141. }
  142. $title .= ' ('.$langs->trans("ThirdPartySuppliers").')';
  143. $urlfiche = "card.php";
  144. } elseif ($type == "o") {
  145. if (empty($contextpage) || $contextpage == 'contactlist') {
  146. $contextpage = 'contactotherlist';
  147. }
  148. $title .= ' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  149. $urlfiche = "";
  150. }
  151. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  152. $object = new Contact($db);
  153. $hookmanager->initHooks(array('contactlist'));
  154. $extrafields = new ExtraFields($db);
  155. // fetch optionals attributes and labels
  156. $extrafields->fetch_name_optionals_label($object->table_element);
  157. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  158. // List of fields to search into when doing a "search in all"
  159. $fieldstosearchall = array();
  160. foreach ($object->fields as $key => $val) {
  161. // don't allow search in private notes for external users when doing "search in all"
  162. if (!empty($user->socid) && $key == "note_private") {
  163. continue;
  164. }
  165. if (empty($val['searchall'])) {
  166. continue;
  167. }
  168. $fieldstosearchall['p.'.$key] = $val['label'];
  169. }
  170. // Add none object fields for "search in all"
  171. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  172. $fieldstosearchall['s.nom'] = "ThirdParty";
  173. $fieldstosearchall['s.name_alias'] = "AliasNames";
  174. }
  175. // Definition of fields for list
  176. $arrayfields = array();
  177. foreach ($object->fields as $key => $val) {
  178. // If $val['visible']==0, then we never show the field
  179. if (empty($val['visible'])) {
  180. continue;
  181. }
  182. $arrayfields['p.'.$key] = array(
  183. 'label'=>$val['label'],
  184. 'checked'=>(($val['visible'] < 0) ? 0 : 1),
  185. 'enabled'=>($val['enabled'] && ($val['visible'] != 3)),
  186. 'position'=>$val['position']);
  187. }
  188. // Add none object fields to fields for list
  189. $arrayfields['country.code_iso'] = array('label'=>"Country", 'position'=>66, 'checked'=>0);
  190. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  191. $arrayfields['s.nom'] = array('label'=>"ThirdParty", 'position'=>113, 'checked'=> 1);
  192. $arrayfields['s.name_alias'] = array('label'=>"AliasNameShort", 'position'=>114, 'checked'=> 1);
  193. }
  194. $arrayfields['unsubscribed'] = array(
  195. 'label'=>'No_Email',
  196. 'checked'=>0,
  197. 'enabled'=>(isModEnabled('mailing')),
  198. 'position'=>111);
  199. if (isModEnabled('socialnetworks')) {
  200. foreach ($socialnetworks as $key => $value) {
  201. if ($value['active']) {
  202. $arrayfields['p.'.$key] = array(
  203. 'label' => $value['label'],
  204. 'checked' => 0,
  205. 'position' => 300
  206. );
  207. }
  208. }
  209. }
  210. // Extra fields
  211. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  212. $object->fields = dol_sort_array($object->fields, 'position');
  213. $arrayfields = dol_sort_array($arrayfields, 'position');
  214. if (($id > 0 || !empty($ref)) && $action != 'add') {
  215. $result = $object->fetch($id, $ref);
  216. if ($result < 0) {
  217. dol_print_error($db);
  218. }
  219. }
  220. /*
  221. * Actions
  222. */
  223. if (GETPOST('cancel', 'alpha')) {
  224. $action = 'list'; $massaction = '';
  225. }
  226. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  227. $massaction = '';
  228. }
  229. $parameters = array();
  230. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  231. if ($reshook < 0) {
  232. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  233. }
  234. if (empty($reshook)) {
  235. // Selection of new fields
  236. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  237. // Did we click on purge search criteria ?
  238. 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
  239. $sall = "";
  240. $search_id = '';
  241. $search_firstlast_only = "";
  242. $search_lastname = "";
  243. $search_firstname = "";
  244. $search_societe = "";
  245. $search_societe_alias = "";
  246. $search_town = "";
  247. $search_address = "";
  248. $search_zip = "";
  249. $search_country = "";
  250. $search_poste = "";
  251. $search_phone = "";
  252. $search_phone_perso = "";
  253. $search_phone_pro = "";
  254. $search_phone_mobile = "";
  255. $search_fax = "";
  256. $search_email = "";
  257. $search_no_email = -1;
  258. if (isModEnabled('socialnetworks')) {
  259. foreach ($socialnetworks as $key => $value) {
  260. if ($value['active']) {
  261. $search_[$key] = "";
  262. }
  263. }
  264. }
  265. $search_priv = "";
  266. $search_stcomm = '';
  267. $search_level = '';
  268. $search_status = -1;
  269. $search_categ = '';
  270. $search_categ_thirdparty = '';
  271. $search_categ_supplier = '';
  272. $search_import_key = '';
  273. $toselect = array();
  274. $search_array_options = array();
  275. $search_roles = array();
  276. }
  277. // Mass actions
  278. $objectclass = 'Contact';
  279. $objectlabel = 'Contact';
  280. $permissiontoread = $user->hasRight('societe', 'lire');
  281. $permissiontodelete = $user->hasRight('societe', 'supprimer');
  282. $permissiontoadd = $user->rights->societe->creer;
  283. $uploaddir = $conf->societe->dir_output;
  284. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  285. if ($action == 'setstcomm') {
  286. $object = new Contact($db);
  287. $result = $object->fetch(GETPOST('stcommcontactid'));
  288. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
  289. $result = $object->update($object->id, $user);
  290. if ($result < 0) {
  291. setEventMessages($object->error, $object->errors, 'errors');
  292. }
  293. $action = '';
  294. }
  295. }
  296. if ($search_priv < 0) {
  297. $search_priv = '';
  298. }
  299. /*
  300. * View
  301. */
  302. $form = new Form($db);
  303. $formother = new FormOther($db);
  304. $formcompany = new FormCompany($db);
  305. $contactstatic = new Contact($db);
  306. $morejs=array();
  307. $morecss = array();
  308. if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
  309. $contactstatic->loadCacheOfProspStatus();
  310. }
  311. // Select every potentiels, and note each potentiels which fit in search parameters
  312. $tab_level = array();
  313. $sql = "SELECT code, label, sortorder";
  314. $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
  315. $sql .= " WHERE active > 0";
  316. $sql .= " ORDER BY sortorder";
  317. $resql = $db->query($sql);
  318. if ($resql) {
  319. while ($obj = $db->fetch_object($resql)) {
  320. // Compute level text
  321. $level = $langs->trans($obj->code);
  322. if ($level == $obj->code) {
  323. $level = $langs->trans($obj->label);
  324. }
  325. $tab_level[$obj->code] = $level;
  326. }
  327. } else {
  328. dol_print_error($db);
  329. }
  330. $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias as alias,";
  331. $sql .= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.address, p.zip, p.town, p.poste, p.email,";
  332. $sql .= " p.socialnetworks, p.photo,";
  333. $sql .= " p.phone as phone_pro, p.phone_mobile, p.phone_perso, p.fax, p.fk_pays, p.priv, p.datec as date_creation, p.tms as date_update,";
  334. $sql .= " p.import_key,";
  335. $sql .= " st.libelle as stcomm, st.picto as stcomm_picto, p.fk_stcommcontact as stcomm_id, p.fk_prospectcontactlevel,";
  336. $sql .= " co.label as country, co.code as country_code";
  337. // Add fields from extrafields
  338. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  339. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  340. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  341. }
  342. }
  343. if (isModEnabled('mailing')) {
  344. $sql .= ", (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) as unsubscribed";
  345. }
  346. // Add fields from hooks
  347. $parameters = array();
  348. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  349. $sql .= $hookmanager->resPrint;
  350. $sqlfields = $sql; // $sql fields to remove for count total
  351. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  352. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  353. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  354. }
  355. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
  356. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  357. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact";
  358. if (empty($user->rights->societe->client->voir) && !$socid) {
  359. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe_commerciaux as sc ON s.rowid = sc.fk_soc";
  360. }
  361. $sql .= ' WHERE p.entity IN ('.getEntity('contact').')';
  362. if (empty($user->rights->societe->client->voir) && !$socid) { //restriction
  363. $sql .= " AND (sc.fk_user = ".((int) $user->id)." OR p.fk_soc IS NULL)";
  364. }
  365. if (!empty($userid)) { // propre au commercial
  366. $sql .= " AND p.fk_user_creat=".((int) $userid);
  367. }
  368. if ($search_level) {
  369. $sql .= natural_search("p.fk_prospectcontactlevel", join(',', $search_level), 3);
  370. }
  371. if ($search_stcomm != '' && $search_stcomm != -2) {
  372. $sql .= natural_search("p.fk_stcommcontact", $search_stcomm, 2);
  373. }
  374. // Filter to exclude not owned private contacts
  375. if ($search_priv != '0' && $search_priv != '1') {
  376. $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".((int) $user->id)."))";
  377. } else {
  378. if ($search_priv == '0') {
  379. $sql .= " AND p.priv='0'";
  380. }
  381. if ($search_priv == '1') {
  382. $sql .= " AND (p.priv='1' AND p.fk_user_creat=".((int) $user->id).")";
  383. }
  384. }
  385. $searchCategoryContactList = $search_categ ? array($search_categ) : array();
  386. $searchCategoryContactOperator = 0;
  387. // Search for tag/category ($searchCategoryContactList is an array of ID)
  388. if (!empty($searchCategoryContactList)) {
  389. $searchCategoryContactSqlList = array();
  390. $listofcategoryid = '';
  391. foreach ($searchCategoryContactList as $searchCategoryContact) {
  392. if (intval($searchCategoryContact) == -2) {
  393. $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople)";
  394. } elseif (intval($searchCategoryContact) > 0) {
  395. if ($searchCategoryContactOperator == 0) {
  396. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie = ".((int) $searchCategoryContact).")";
  397. } else {
  398. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact);
  399. }
  400. }
  401. }
  402. if ($listofcategoryid) {
  403. $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  404. }
  405. if ($searchCategoryContactOperator == 1) {
  406. if (!empty($searchCategoryContactSqlList)) {
  407. $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")";
  408. }
  409. } else {
  410. if (!empty($searchCategoryContactSqlList)) {
  411. $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")";
  412. }
  413. }
  414. }
  415. $searchCategoryCustomerList = $search_categ_thirdparty ? array($search_categ_thirdparty) : array();
  416. $searchCategoryCustomerOperator = 0;
  417. // Search for tag/category ($searchCategoryCustomerList is an array of ID)
  418. if (!empty($searchCategoryCustomerList)) {
  419. $searchCategoryCustomerSqlList = array();
  420. $listofcategoryid = '';
  421. foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
  422. if (intval($searchCategoryCustomer) == -2) {
  423. $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
  424. } elseif (intval($searchCategoryCustomer) > 0) {
  425. if ($searchCategoryCustomerOperator == 0) {
  426. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategoryCustomer).")";
  427. } else {
  428. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
  429. }
  430. }
  431. }
  432. if ($listofcategoryid) {
  433. $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  434. }
  435. if ($searchCategoryCustomerOperator == 1) {
  436. if (!empty($searchCategoryCustomerSqlList)) {
  437. $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
  438. }
  439. } else {
  440. if (!empty($searchCategoryCustomerSqlList)) {
  441. $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
  442. }
  443. }
  444. }
  445. $searchCategorySupplierList = $search_categ_supplier ? array($search_categ_supplier) : array();
  446. $searchCategorySupplierOperator = 0;
  447. // Search for tag/category ($searchCategorySupplierList is an array of ID)
  448. if (!empty($searchCategorySupplierList)) {
  449. $searchCategorySupplierSqlList = array();
  450. $listofcategoryid = '';
  451. foreach ($searchCategorySupplierList as $searchCategorySupplier) {
  452. if (intval($searchCategorySupplier) == -2) {
  453. $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
  454. } elseif (intval($searchCategorySupplier) > 0) {
  455. if ($searchCategorySupplierOperator == 0) {
  456. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
  457. } else {
  458. $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
  459. }
  460. }
  461. }
  462. if ($listofcategoryid) {
  463. $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
  464. }
  465. if ($searchCategorySupplierOperator == 1) {
  466. if (!empty($searchCategorySupplierSqlList)) {
  467. $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
  468. }
  469. } else {
  470. if (!empty($searchCategorySupplierSqlList)) {
  471. $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
  472. }
  473. }
  474. }
  475. if ($sall) {
  476. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  477. }
  478. if (strlen($search_phone)) {
  479. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
  480. }
  481. if (strlen($search_cti)) {
  482. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
  483. }
  484. if (strlen($search_firstlast_only)) {
  485. $sql .= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
  486. }
  487. if ($search_id > 0) {
  488. $sql .= natural_search('p.rowid', $search_id, 1);
  489. }
  490. if ($search_lastname) {
  491. $sql .= natural_search('p.lastname', $search_lastname);
  492. }
  493. if ($search_firstname) {
  494. $sql .= natural_search('p.firstname', $search_firstname);
  495. }
  496. if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
  497. $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
  498. } else {
  499. if ($search_societe) {
  500. $sql .= natural_search('s.nom', $search_societe);
  501. }
  502. if ($search_societe_alias) {
  503. $sql .= natural_search('s.name_alias', $search_societe_alias);
  504. }
  505. }
  506. if ($search_country) {
  507. $sql .= " AND p.fk_pays IN (".$db->sanitize($search_country).')';
  508. }
  509. if (strlen($search_poste)) {
  510. $sql .= natural_search('p.poste', $search_poste);
  511. }
  512. if (strlen($search_phone_perso)) {
  513. $sql .= natural_search('p.phone_perso', $search_phone_perso);
  514. }
  515. if (strlen($search_phone_pro)) {
  516. $sql .= natural_search('p.phone', $search_phone_pro);
  517. }
  518. if (strlen($search_phone_mobile)) {
  519. $sql .= natural_search('p.phone_mobile', $search_phone_mobile);
  520. }
  521. if (strlen($search_fax)) {
  522. $sql .= natural_search('p.fax', $search_fax);
  523. }
  524. if (isModEnabled('socialnetworks')) {
  525. foreach ($socialnetworks as $key => $value) {
  526. if ($value['active'] && strlen($search_[$key])) {
  527. $searchkeyinjsonformat = preg_replace('/"$/', '', preg_replace('/^"/', '', json_encode($search_[$key])));
  528. if (in_array($db->type, array('mysql', 'mysqli'))) {
  529. $sql .= " AND p.socialnetworks REGEXP '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
  530. } elseif ($db->type == 'pgsql') {
  531. $sql .= " AND p.socialnetworks ~ '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
  532. } else {
  533. // Works with all database but not reliable because search only for social network code starting with earched value
  534. $sql .= " AND p.socialnetworks LIKE '%\"".$db->escape($db->escapeforlike($key))."\":\"".$db->escape($db->escapeforlike($searchkeyinjsonformat))."%'";
  535. }
  536. }
  537. }
  538. }
  539. //print $sql;
  540. if (strlen($search_email)) {
  541. $sql .= natural_search('p.email', $search_email);
  542. }
  543. if (strlen($search_address)) {
  544. $sql .= natural_search("p.address", $search_address);
  545. }
  546. if (strlen($search_zip)) {
  547. $sql .= natural_search("p.zip", $search_zip);
  548. }
  549. if (strlen($search_town)) {
  550. $sql .= natural_search("p.town", $search_town);
  551. }
  552. if (count($search_roles) > 0) {
  553. $sql .= " AND p.rowid IN (SELECT sc.fk_socpeople FROM ".MAIN_DB_PREFIX."societe_contacts as sc WHERE sc.fk_c_type_contact IN (".$db->sanitize(implode(',', $search_roles))."))";
  554. }
  555. if ($search_no_email != -1 && $search_no_email > 0) {
  556. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0";
  557. }
  558. if ($search_no_email != -1 && $search_no_email == 0) {
  559. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''";
  560. }
  561. if ($search_status != '' && $search_status >= 0) {
  562. $sql .= " AND p.statut = ".((int) $search_status);
  563. }
  564. if ($search_import_key) {
  565. $sql .= natural_search("p.import_key", $search_import_key);
  566. }
  567. if ($type == "o") { // filtre sur type
  568. $sql .= " AND p.fk_soc IS NULL";
  569. } elseif ($type == "f") { // filtre sur type
  570. $sql .= " AND s.fournisseur = 1";
  571. } elseif ($type == "c") { // filtre sur type
  572. $sql .= " AND s.client IN (1, 3)";
  573. } elseif ($type == "p") { // filtre sur type
  574. $sql .= " AND s.client IN (2, 3)";
  575. }
  576. if (!empty($socid)) {
  577. $sql .= " AND s.rowid = ".((int) $socid);
  578. }
  579. // Add where from extra fields
  580. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  581. // Add where from hooks
  582. $parameters = array();
  583. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  584. $sql .= $hookmanager->resPrint;
  585. //print $sql;
  586. // Count total nb of records
  587. $nbtotalofrecords = '';
  588. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  589. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  590. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  591. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  592. $resql = $db->query($sqlforcount);
  593. if ($resql) {
  594. $objforcount = $db->fetch_object($resql);
  595. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  596. } else {
  597. dol_print_error($db);
  598. }
  599. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  600. $page = 0;
  601. $offset = 0;
  602. }
  603. $db->free($resql);
  604. }
  605. // Complete request and execute it with limit
  606. if ($view == "recent") {
  607. $sql .= $db->order("p.datec", "DESC");
  608. } else {
  609. $sql .= $db->order($sortfield, $sortorder);
  610. }
  611. if ($limit) {
  612. $sql .= $db->plimit($limit + 1, $offset);
  613. }
  614. $resql = $db->query($sql);
  615. if (!$resql) {
  616. dol_print_error($db);
  617. exit;
  618. }
  619. $num = $db->num_rows($resql);
  620. $arrayofselected = is_array($toselect) ? $toselect : array();
  621. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($sall != '' || $search_cti != '')) {
  622. $obj = $db->fetch_object($resql);
  623. $id = $obj->rowid;
  624. header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
  625. exit;
  626. }
  627. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  628. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  629. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
  630. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  631. $param = '';
  632. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  633. $param .= '&contextpage='.urlencode($contextpage);
  634. }
  635. if ($limit > 0 && $limit != $conf->liste_limit) {
  636. $param .= '&limit='.((int) $limit);
  637. }
  638. $param .= '&begin='.urlencode($begin).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
  639. $param .= '&type='.urlencode($type).'&view='.urlencode($view);
  640. if (!empty($search_categ) && $search_categ != '-1') {
  641. $param .= '&search_categ='.urlencode($search_categ);
  642. }
  643. if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
  644. $param .= '&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
  645. }
  646. if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
  647. $param .= '&search_categ_supplier='.urlencode($search_categ_supplier);
  648. }
  649. if ($sall != '') {
  650. $param .= '&sall='.urlencode($sall);
  651. }
  652. if ($search_id > 0) {
  653. $param .= "&search_id=".urlencode($search_id);
  654. }
  655. if ($search_lastname != '') {
  656. $param .= '&search_lastname='.urlencode($search_lastname);
  657. }
  658. if ($search_firstname != '') {
  659. $param .= '&search_firstname='.urlencode($search_firstname);
  660. }
  661. if ($search_societe != '') {
  662. $param .= '&search_societe='.urlencode($search_societe);
  663. }
  664. if ($search_societe_alias != '') {
  665. $param .= '&search_societe_alias='.urlencode($search_societe_alias);
  666. }
  667. if ($search_address != '') {
  668. $param .= '&search_address='.urlencode($search_address);
  669. }
  670. if ($search_zip != '') {
  671. $param .= '&search_zip='.urlencode($search_zip);
  672. }
  673. if ($search_town != '') {
  674. $param .= '&search_town='.urlencode($search_town);
  675. }
  676. if ($search_country != '') {
  677. $param .= "&search_country=".urlencode($search_country);
  678. }
  679. if ($search_poste != '') {
  680. $param .= '&search_poste='.urlencode($search_poste);
  681. }
  682. if ($search_phone_pro != '') {
  683. $param .= '&search_phone_pro='.urlencode($search_phone_pro);
  684. }
  685. if ($search_phone_perso != '') {
  686. $param .= '&search_phone_perso='.urlencode($search_phone_perso);
  687. }
  688. if ($search_phone_mobile != '') {
  689. $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
  690. }
  691. if ($search_fax != '') {
  692. $param .= '&search_fax='.urlencode($search_fax);
  693. }
  694. if ($search_email != '') {
  695. $param .= '&search_email='.urlencode($search_email);
  696. }
  697. if ($search_no_email != '') {
  698. $param .= '&search_no_email='.urlencode($search_no_email);
  699. }
  700. if ($search_status != '') {
  701. $param .= '&search_status='.urlencode($search_status);
  702. }
  703. if ($search_priv == '0' || $search_priv == '1') {
  704. $param .= "&search_priv=".urlencode($search_priv);
  705. }
  706. if ($search_stcomm != '') {
  707. $param .= '&search_stcomm='.urlencode($search_stcomm);
  708. }
  709. if (is_array($search_level) && count($search_level)) {
  710. foreach ($search_level as $slevel) {
  711. $param .= '&search_level[]='.urlencode($slevel);
  712. }
  713. }
  714. if ($search_import_key != '') {
  715. $param .= '&amp;search_import_key='.urlencode($search_import_key);
  716. }
  717. if ($optioncss != '') {
  718. $param .= '&amp;optioncss='.urlencode($optioncss);
  719. }
  720. if (count($search_roles) > 0) {
  721. $param .= implode('&search_roles[]=', $search_roles);
  722. }
  723. // Add $param from extra fields
  724. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  725. // List of mass actions available
  726. $arrayofmassactions = array(
  727. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  728. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  729. );
  730. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  731. if ($user->hasRight('societe', 'supprimer')) {
  732. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  733. }
  734. if (isModEnabled('category') && $user->rights->societe->creer) {
  735. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  736. }
  737. if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  738. $arrayofmassactions = array();
  739. }
  740. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  741. $newcardbutton = dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $user->rights->societe->contact->creer);
  742. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  743. if ($optioncss != '') {
  744. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  745. }
  746. print '<input type="hidden" name="token" value="'.newToken().'">';
  747. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  748. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  749. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  750. //print '<input type="hidden" name="page" value="'.$page.'">';
  751. print '<input type="hidden" name="type" value="'.$type.'">';
  752. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  753. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
  754. $topicmail = "Information";
  755. $modelmail = "contact";
  756. $objecttmp = new Contact($db);
  757. $trackid = 'ctc'.$object->id;
  758. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  759. if ($sall) {
  760. foreach ($fieldstosearchall as $key => $val) {
  761. $fieldstosearchall[$key] = $langs->trans($val);
  762. }
  763. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  764. }
  765. if ($search_firstlast_only) {
  766. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
  767. }
  768. $moreforfilter = '';
  769. if (isModEnabled('categorie') && $user->rights->categorie->lire) {
  770. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  771. $moreforfilter .= '<div class="divsearchfield">';
  772. $tmptitle = $langs->trans('ContactCategoriesShort');
  773. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  774. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
  775. $moreforfilter .= '</div>';
  776. if (empty($type) || $type == 'c' || $type == 'p') {
  777. $moreforfilter .= '<div class="divsearchfield">';
  778. $tmptitle = '';
  779. if ($type == 'c') {
  780. $tmptitle .= $langs->trans('CustomersCategoriesShort');
  781. } elseif ($type == 'p') {
  782. $tmptitle .= $langs->trans('ProspectsCategoriesShort');
  783. } else {
  784. $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
  785. }
  786. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  787. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
  788. $moreforfilter .= '</div>';
  789. }
  790. if (isModEnabled("fournisseur") && (empty($type) || $type == 'f')) {
  791. $moreforfilter .= '<div class="divsearchfield">';
  792. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  793. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  794. $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
  795. $moreforfilter .= '</div>';
  796. }
  797. }
  798. $moreforfilter .= '<div class="divsearchfield">';
  799. $moreforfilter .= $langs->trans('Roles').': ';
  800. $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
  801. $moreforfilter .= '</div>';
  802. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  803. print $moreforfilter;
  804. $parameters = array('type'=>$type);
  805. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  806. print $hookmanager->resPrint;
  807. print '</div>';
  808. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  809. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  810. if ($massactionbutton) {
  811. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  812. }
  813. print '<div class="div-table-responsive">';
  814. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  815. // Lines for filter fields
  816. print '<tr class="liste_titre_filter">';
  817. // Action column
  818. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  819. print '<td class="liste_titre maxwidthsearch">';
  820. $searchpicto = $form->showFilterButtons('left');
  821. print $searchpicto;
  822. print '</td>';
  823. }
  824. if (!empty($arrayfields['p.rowid']['checked'])) {
  825. print '<td class="liste_titre">';
  826. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  827. print '</td>';
  828. }
  829. if (!empty($arrayfields['p.lastname']['checked'])) {
  830. print '<td class="liste_titre">';
  831. print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
  832. print '</td>';
  833. }
  834. if (!empty($arrayfields['p.firstname']['checked'])) {
  835. print '<td class="liste_titre">';
  836. print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
  837. print '</td>';
  838. }
  839. if (!empty($arrayfields['p.poste']['checked'])) {
  840. print '<td class="liste_titre">';
  841. print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
  842. print '</td>';
  843. }
  844. if (!empty($arrayfields['p.address']['checked'])) {
  845. print '<td class="liste_titre">';
  846. print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
  847. print '</td>';
  848. }
  849. if (!empty($arrayfields['p.zip']['checked'])) {
  850. print '<td class="liste_titre">';
  851. print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
  852. print '</td>';
  853. }
  854. if (!empty($arrayfields['p.town']['checked'])) {
  855. print '<td class="liste_titre">';
  856. print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
  857. print '</td>';
  858. }
  859. // State
  860. /*if (!empty($arrayfields['state.nom']['checked']))
  861. {
  862. print '<td class="liste_titre">';
  863. print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  864. print '</td>';
  865. }
  866. // Region
  867. if (!empty($arrayfields['region.nom']['checked']))
  868. {
  869. print '<td class="liste_titre">';
  870. print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
  871. print '</td>';
  872. }*/
  873. // Country
  874. if (!empty($arrayfields['country.code_iso']['checked'])) {
  875. print '<td class="liste_titre center">';
  876. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  877. print '</td>';
  878. }
  879. if (!empty($arrayfields['p.phone']['checked'])) {
  880. print '<td class="liste_titre">';
  881. print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
  882. print '</td>';
  883. }
  884. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  885. print '<td class="liste_titre">';
  886. print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
  887. print '</td>';
  888. }
  889. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  890. print '<td class="liste_titre">';
  891. print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
  892. print '</td>';
  893. }
  894. if (!empty($arrayfields['p.fax']['checked'])) {
  895. print '<td class="liste_titre">';
  896. print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
  897. print '</td>';
  898. }
  899. if (!empty($arrayfields['p.email']['checked'])) {
  900. print '<td class="liste_titre">';
  901. print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
  902. print '</td>';
  903. }
  904. if (!empty($arrayfields['unsubscribed']['checked'])) {
  905. print '<td class="liste_titre center">';
  906. print $form->selectarray('search_no_email', array('-1'=>'', '0'=>$langs->trans('No'), '1'=>$langs->trans('Yes')), $search_no_email);
  907. print '</td>';
  908. }
  909. if (isModEnabled('socialnetworks')) {
  910. foreach ($socialnetworks as $key => $value) {
  911. if ($value['active']) {
  912. if (!empty($arrayfields['p.'.$key]['checked'])) {
  913. print '<td class="liste_titre">';
  914. print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
  915. print '</td>';
  916. }
  917. }
  918. }
  919. }
  920. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  921. print '<td class="liste_titre">';
  922. print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  923. print '</td>';
  924. }
  925. // Alias
  926. if (!empty($arrayfields['s.name_alias']['checked'])) {
  927. print '<td class="liste_titre" align="left">';
  928. print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
  929. print '</td>';
  930. }
  931. if (!empty($arrayfields['p.priv']['checked'])) {
  932. print '<td class="liste_titre center">';
  933. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  934. print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
  935. print '</td>';
  936. }
  937. // Prospect level
  938. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  939. print '<td class="liste_titre center">';
  940. print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
  941. print '</td>';
  942. }
  943. // Prospect status
  944. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  945. print '<td class="liste_titre maxwidthonsmartphone center">';
  946. $arraystcomm = array();
  947. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  948. $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  949. }
  950. print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
  951. print '</td>';
  952. }
  953. // Extra fields
  954. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  955. // Fields from hook
  956. $parameters = array('arrayfields'=>$arrayfields);
  957. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  958. print $hookmanager->resPrint;
  959. // Date creation
  960. if (!empty($arrayfields['p.datec']['checked'])) {
  961. print '<td class="liste_titre">';
  962. print '</td>';
  963. }
  964. // Date modification
  965. if (!empty($arrayfields['p.tms']['checked'])) {
  966. print '<td class="liste_titre">';
  967. print '</td>';
  968. }
  969. // Status
  970. if (!empty($arrayfields['p.statut']['checked'])) {
  971. print '<td class="liste_titre center">';
  972. print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'minwidth75 onrightofpage');
  973. print '</td>';
  974. }
  975. if (!empty($arrayfields['p.import_key']['checked'])) {
  976. print '<td class="liste_titre center">';
  977. print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
  978. print '</td>';
  979. }
  980. // Action column
  981. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  982. print '<td class="liste_titre maxwidthsearch">';
  983. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  984. print $searchpicto;
  985. print '</td>';
  986. }
  987. print '</tr>';
  988. // Ligne des titres
  989. print '<tr class="liste_titre">';
  990. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  991. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  992. }
  993. if (!empty($arrayfields['p.rowid']['checked'])) {
  994. print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
  995. }
  996. if (!empty($arrayfields['p.lastname']['checked'])) {
  997. print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
  998. }
  999. if (!empty($arrayfields['p.firstname']['checked'])) {
  1000. print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
  1001. }
  1002. if (!empty($arrayfields['p.poste']['checked'])) {
  1003. print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
  1004. }
  1005. if (!empty($arrayfields['p.address']['checked'])) {
  1006. print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
  1007. }
  1008. if (!empty($arrayfields['p.zip']['checked'])) {
  1009. print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
  1010. }
  1011. if (!empty($arrayfields['p.town']['checked'])) {
  1012. print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
  1013. }
  1014. //if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  1015. //if (!empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
  1016. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1017. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  1018. }
  1019. if (!empty($arrayfields['p.phone']['checked'])) {
  1020. print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
  1021. }
  1022. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1023. print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
  1024. }
  1025. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1026. print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
  1027. }
  1028. if (!empty($arrayfields['p.fax']['checked'])) {
  1029. print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
  1030. }
  1031. if (!empty($arrayfields['p.email']['checked'])) {
  1032. print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
  1033. }
  1034. if (!empty($arrayfields['unsubscribed']['checked'])) {
  1035. print_liste_field_titre($arrayfields['unsubscribed']['label'], $_SERVER["PHP_SELF"], "unsubscribed", $begin, $param, '', $sortfield, $sortorder, 'center ');
  1036. }
  1037. if (isModEnabled('socialnetworks')) {
  1038. foreach ($socialnetworks as $key => $value) {
  1039. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1040. print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
  1041. }
  1042. }
  1043. }
  1044. if (!empty($arrayfields['p.fk_soc']['checked'])) {
  1045. print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
  1046. }
  1047. if (!empty($arrayfields['s.nom']['checked'])) {
  1048. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
  1049. }
  1050. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1051. print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", $begin, $param, '', $sortfield, $sortorder);
  1052. }
  1053. if (!empty($arrayfields['p.priv']['checked'])) {
  1054. print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
  1055. }
  1056. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  1057. print_liste_field_titre($arrayfields['p.fk_prospectcontactlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectcontactlevel", "", $param, '', $sortfield, $sortorder, 'center ');
  1058. }
  1059. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1060. print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
  1061. }
  1062. // Extra fields
  1063. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  1064. // Hook fields
  1065. $parameters = array(
  1066. 'arrayfields'=>$arrayfields,
  1067. 'param'=>$param,
  1068. 'sortfield'=>$sortfield,
  1069. 'sortorder'=>$sortorder,
  1070. );
  1071. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1072. print $hookmanager->resPrint;
  1073. if (!empty($arrayfields['p.datec']['checked'])) {
  1074. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1075. }
  1076. if (!empty($arrayfields['p.tms']['checked'])) {
  1077. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  1078. }
  1079. if (!empty($arrayfields['p.statut']['checked'])) {
  1080. print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
  1081. }
  1082. if (!empty($arrayfields['p.import_key']['checked'])) {
  1083. print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  1084. }
  1085. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1086. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  1087. }
  1088. print "</tr>\n";
  1089. $i = 0;
  1090. $totalarray = array();
  1091. $totalarray['nbfield'] = 0;
  1092. while ($i < min($num, $limit)) {
  1093. $obj = $db->fetch_object($resql);
  1094. $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
  1095. $contactstatic->lastname = $obj->lastname;
  1096. $contactstatic->firstname = '';
  1097. $contactstatic->id = $obj->rowid;
  1098. $contactstatic->statut = $obj->statut;
  1099. $contactstatic->poste = $obj->poste;
  1100. $contactstatic->email = $obj->email;
  1101. $contactstatic->phone_pro = $obj->phone_pro;
  1102. $contactstatic->phone_perso = $obj->phone_perso;
  1103. $contactstatic->phone_mobile = $obj->phone_mobile;
  1104. $contactstatic->address = $obj->address;
  1105. $contactstatic->zip = $obj->zip;
  1106. $contactstatic->town = $obj->town;
  1107. $contactstatic->socialnetworks = $arraysocialnetworks;
  1108. $contactstatic->country = $obj->country;
  1109. $contactstatic->country_code = $obj->country_code;
  1110. $contactstatic->photo = $obj->photo;
  1111. $contactstatic->import_key = $obj->import_key;
  1112. $contactstatic->fk_prospectlevel = $obj->fk_prospectcontactlevel;
  1113. print '<tr class="oddeven">';
  1114. // Action column
  1115. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1116. print '<td class="nowrap center">';
  1117. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1118. $selected = 0;
  1119. if (in_array($obj->rowid, $arrayofselected)) {
  1120. $selected = 1;
  1121. }
  1122. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1123. }
  1124. print '</td>';
  1125. }
  1126. // ID
  1127. if (!empty($arrayfields['p.rowid']['checked'])) {
  1128. print '<td class="tdoverflowmax50">';
  1129. print dol_escape_htmltag($obj->rowid);
  1130. print "</td>\n";
  1131. if (!$i) {
  1132. $totalarray['nbfield']++;
  1133. }
  1134. }
  1135. // Name
  1136. if (!empty($arrayfields['p.lastname']['checked'])) {
  1137. print '<td class="middle tdoverflowmax150">';
  1138. print $contactstatic->getNomUrl(1);
  1139. print '</td>';
  1140. if (!$i) {
  1141. $totalarray['nbfield']++;
  1142. }
  1143. }
  1144. // Firstname
  1145. if (!empty($arrayfields['p.firstname']['checked'])) {
  1146. print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
  1147. if (!$i) {
  1148. $totalarray['nbfield']++;
  1149. }
  1150. }
  1151. // Job position
  1152. if (!empty($arrayfields['p.poste']['checked'])) {
  1153. print '<td class="tdoverflowmax100">'.dol_escape_htmltag($obj->poste).'</td>';
  1154. if (!$i) {
  1155. $totalarray['nbfield']++;
  1156. }
  1157. }
  1158. // Address
  1159. if (!empty($arrayfields['p.address']['checked'])) {
  1160. print '<td>'.dol_escape_htmltag($obj->address).'</td>';
  1161. if (!$i) {
  1162. $totalarray['nbfield']++;
  1163. }
  1164. }
  1165. // Zip
  1166. if (!empty($arrayfields['p.zip']['checked'])) {
  1167. print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
  1168. if (!$i) {
  1169. $totalarray['nbfield']++;
  1170. }
  1171. }
  1172. // Town
  1173. if (!empty($arrayfields['p.town']['checked'])) {
  1174. print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">'.dol_escape_htmltag($obj->town).'</td>';
  1175. if (!$i) {
  1176. $totalarray['nbfield']++;
  1177. }
  1178. }
  1179. // State
  1180. /*if (!empty($arrayfields['state.nom']['checked']))
  1181. {
  1182. print "<td>".$obj->state_name."</td>\n";
  1183. if (! $i) $totalarray['nbfield']++;
  1184. }
  1185. // Region
  1186. if (!empty($arrayfields['region.nom']['checked']))
  1187. {
  1188. print "<td>".$obj->region_name."</td>\n";
  1189. if (! $i) $totalarray['nbfield']++;
  1190. }*/
  1191. // Country
  1192. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1193. print '<td class="center">';
  1194. $tmparray = getCountry($obj->fk_pays, 'all');
  1195. print dol_escape_htmltag($tmparray['label']);
  1196. print '</td>';
  1197. if (!$i) {
  1198. $totalarray['nbfield']++;
  1199. }
  1200. }
  1201. // Phone
  1202. if (!empty($arrayfields['p.phone']['checked'])) {
  1203. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1204. if (!$i) {
  1205. $totalarray['nbfield']++;
  1206. }
  1207. }
  1208. // Phone perso
  1209. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1210. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1211. if (!$i) {
  1212. $totalarray['nbfield']++;
  1213. }
  1214. }
  1215. // Phone mobile
  1216. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1217. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
  1218. if (!$i) {
  1219. $totalarray['nbfield']++;
  1220. }
  1221. }
  1222. // Fax
  1223. if (!empty($arrayfields['p.fax']['checked'])) {
  1224. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
  1225. if (!$i) {
  1226. $totalarray['nbfield']++;
  1227. }
  1228. }
  1229. // EMail
  1230. if (!empty($arrayfields['p.email']['checked'])) {
  1231. print '<td class="nowraponall tdoverflowmax300">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'</td>';
  1232. if (!$i) {
  1233. $totalarray['nbfield']++;
  1234. }
  1235. }
  1236. // No EMail
  1237. if (!empty($arrayfields['unsubscribed']['checked'])) {
  1238. print '<td class="center">';
  1239. if (empty($obj->email)) {
  1240. //print '<span class="opacitymedium">'.$langs->trans("NoEmail").'</span>';
  1241. } else {
  1242. print yn(($obj->unsubscribed > 0) ? 1 : 0);
  1243. }
  1244. print '</td>';
  1245. if (!$i) {
  1246. $totalarray['nbfield']++;
  1247. }
  1248. }
  1249. if (isModEnabled('socialnetworks')) {
  1250. foreach ($socialnetworks as $key => $value) {
  1251. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1252. print '<td class="tdoverflowmax100">'.(empty($arraysocialnetworks[$key]) ? '' : dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks)).'</td>';
  1253. if (!$i) {
  1254. $totalarray['nbfield']++;
  1255. }
  1256. }
  1257. }
  1258. }
  1259. // Company
  1260. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  1261. print '<td class="tdoverflowmax200">';
  1262. if ($obj->socid) {
  1263. $objsoc = new Societe($db);
  1264. $objsoc->fetch($obj->socid);
  1265. print $objsoc->getNomUrl(1, 'customer', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
  1266. } else {
  1267. print '&nbsp;';
  1268. }
  1269. print '</td>';
  1270. if (!$i) {
  1271. $totalarray['nbfield']++;
  1272. }
  1273. }
  1274. // Alias name
  1275. if (!empty($arrayfields['s.name_alias']['checked'])) {
  1276. print '<td class="nocellnopadd">';
  1277. print $obj->alias;
  1278. print '</td>';
  1279. if (!$i) {
  1280. $totalarray['nbfield']++;
  1281. }
  1282. }
  1283. // Private/Public
  1284. if (!empty($arrayfields['p.priv']['checked'])) {
  1285. print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  1286. if (!$i) {
  1287. $totalarray['nbfield']++;
  1288. }
  1289. }
  1290. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  1291. // Prospect level
  1292. print '<td class="center">';
  1293. print $contactstatic->getLibProspLevel();
  1294. print "</td>";
  1295. if (!$i) {
  1296. $totalarray['nbfield']++;
  1297. }
  1298. }
  1299. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1300. // Prospect status
  1301. print '<td class="center nowrap"><div class="nowrap">';
  1302. print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
  1303. print '</div> - <div class="inline-block">';
  1304. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  1305. $titlealt = 'default';
  1306. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  1307. $titlealt = $val['label'];
  1308. }
  1309. if ($obj->stcomm_id != $val['id']) {
  1310. print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?stcommcontactid='.$obj->rowid.'&stcomm='.urlencode($val['code']).'&action=setstcomm&token='.newToken().$param.($page ? '&page='.urlencode($page) : '').'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
  1311. }
  1312. }
  1313. print '</div></div></td>';
  1314. if (!$i) {
  1315. $totalarray['nbfield']++;
  1316. }
  1317. }
  1318. // Extra fields
  1319. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1320. // Fields from hook
  1321. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1322. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1323. print $hookmanager->resPrint;
  1324. // Date creation
  1325. if (!empty($arrayfields['p.datec']['checked'])) {
  1326. print '<td class="center nowraponall">';
  1327. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1328. print '</td>';
  1329. if (!$i) {
  1330. $totalarray['nbfield']++;
  1331. }
  1332. }
  1333. // Date modification
  1334. if (!empty($arrayfields['p.tms']['checked'])) {
  1335. print '<td class="center nowraponall">';
  1336. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1337. print '</td>';
  1338. if (!$i) {
  1339. $totalarray['nbfield']++;
  1340. }
  1341. }
  1342. // Status
  1343. if (!empty($arrayfields['p.statut']['checked'])) {
  1344. print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
  1345. if (!$i) {
  1346. $totalarray['nbfield']++;
  1347. }
  1348. }
  1349. // Import key
  1350. if (!empty($arrayfields['p.import_key']['checked'])) {
  1351. print '<td class="tdoverflowmax100">';
  1352. print dol_escape_htmltag($obj->import_key);
  1353. print "</td>\n";
  1354. if (!$i) {
  1355. $totalarray['nbfield']++;
  1356. }
  1357. }
  1358. // Action column
  1359. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  1360. print '<td class="nowrap center">';
  1361. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  1362. $selected = 0;
  1363. if (in_array($obj->rowid, $arrayofselected)) {
  1364. $selected = 1;
  1365. }
  1366. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  1367. }
  1368. print '</td>';
  1369. }
  1370. if (!$i) {
  1371. $totalarray['nbfield']++;
  1372. }
  1373. print "</tr>\n";
  1374. $i++;
  1375. }
  1376. // Show total line
  1377. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1378. // If no record found
  1379. if ($num == 0) {
  1380. $colspan = 1;
  1381. foreach ($arrayfields as $key => $val) {
  1382. if (!empty($val['checked'])) {
  1383. $colspan++;
  1384. }
  1385. }
  1386. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1387. }
  1388. $db->free($resql);
  1389. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1390. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1391. print $hookmanager->resPrint;
  1392. print '</table>'."\n";
  1393. print '</div>'."\n";
  1394. print '</form>'."\n";
  1395. // End of page
  1396. llxFooter();
  1397. $db->close();