list.php 50 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339
  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. require '../main.inc.php';
  35. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  38. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  39. // Load translation files required by the page
  40. $langs->loadLangs(array("companies", "suppliers", "categories"));
  41. $socialnetworks = getArrayOfSocialNetworks();
  42. $action = GETPOST('action', 'aZ09');
  43. $massaction = GETPOST('massaction', 'alpha');
  44. $show_files = GETPOST('show_files', 'int');
  45. $confirm = GETPOST('confirm', 'alpha');
  46. $toselect = GETPOST('toselect', 'array');
  47. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contactlist';
  48. // Security check
  49. $id = GETPOST('id', 'int');
  50. $contactid = GETPOST('id', 'int');
  51. $ref = ''; // There is no ref for contacts
  52. if ($user->socid) {
  53. $socid = $user->socid;
  54. }
  55. $result = restrictedArea($user, 'contact', $contactid, '');
  56. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  57. $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
  58. $search_phone = GETPOST("search_phone", 'alpha');
  59. $search_id = GETPOST("search_id", "int");
  60. $search_firstlast_only = GETPOST("search_firstlast_only", 'alpha');
  61. $search_lastname = GETPOST("search_lastname", 'alpha');
  62. $search_firstname = GETPOST("search_firstname", 'alpha');
  63. $search_societe = GETPOST("search_societe", 'alpha');
  64. $search_poste = GETPOST("search_poste", 'alpha');
  65. $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
  66. $search_phone_pro = GETPOST("search_phone_pro", 'alpha');
  67. $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
  68. $search_fax = GETPOST("search_fax", 'alpha');
  69. $search_email = GETPOST("search_email", 'alpha');
  70. if (!empty($conf->mailing->enabled)) {
  71. $search_no_email = GETPOSTISSET("search_no_email") ? GETPOST("search_no_email", 'int') : -1;
  72. } else {
  73. $search_no_email = -1;
  74. }
  75. if (!empty($conf->socialnetworks->enabled)) {
  76. foreach ($socialnetworks as $key => $value) {
  77. if ($value['active']) {
  78. $search_[$key] = GETPOST("search_".$key, 'alpha');
  79. }
  80. }
  81. }
  82. $search_priv = GETPOST("search_priv", 'alpha');
  83. $search_categ = GETPOST("search_categ", 'int');
  84. $search_categ_thirdparty = GETPOST("search_categ_thirdparty", 'int');
  85. $search_categ_supplier = GETPOST("search_categ_supplier", 'int');
  86. $search_status = GETPOST("search_status", 'int');
  87. $search_type = GETPOST('search_type', 'alpha');
  88. $search_address = GETPOST('search_address', 'alpha');
  89. $search_zip = GETPOST('search_zip', 'alpha');
  90. $search_town = GETPOST('search_town', 'alpha');
  91. $search_import_key = GETPOST("search_import_key", "alpha");
  92. $search_country = GETPOST("search_country", 'intcomma');
  93. $search_roles = GETPOST("search_roles", 'array');
  94. $search_level = GETPOST("search_level", "array");
  95. $search_stcomm = GETPOST('search_stcomm', 'int');
  96. if ($search_status === '') {
  97. $search_status = 1; // always display active customer first
  98. }
  99. if ($search_no_email === '') {
  100. $search_no_email = -1;
  101. }
  102. $optioncss = GETPOST('optioncss', 'alpha');
  103. $type = GETPOST("type", 'aZ');
  104. $view = GETPOST("view", 'alpha');
  105. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  106. $sortfield = GETPOST('sortfield', 'aZ09comma');
  107. $sortorder = GETPOST('sortorder', 'aZ09comma');
  108. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  109. $userid = GETPOST('userid', 'int');
  110. $begin = GETPOST('begin');
  111. if (!$sortorder) {
  112. $sortorder = "ASC";
  113. }
  114. if (!$sortfield) {
  115. $sortfield = "p.lastname";
  116. }
  117. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  118. $page = 0;
  119. }
  120. $offset = $limit * $page;
  121. $titre = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("ListOfContacts") : $langs->trans("ListOfContactsAddresses"));
  122. if ($type == "p") {
  123. if (empty($contextpage) || $contextpage == 'contactlist') {
  124. $contextpage = 'contactprospectlist';
  125. }
  126. $titre .= ' ('.$langs->trans("ThirdPartyProspects").')';
  127. $urlfiche = "card.php";
  128. }
  129. if ($type == "c") {
  130. if (empty($contextpage) || $contextpage == 'contactlist') {
  131. $contextpage = 'contactcustomerlist';
  132. }
  133. $titre .= ' ('.$langs->trans("ThirdPartyCustomers").')';
  134. $urlfiche = "card.php";
  135. } elseif ($type == "f") {
  136. if (empty($contextpage) || $contextpage == 'contactlist') {
  137. $contextpage = 'contactsupplierlist';
  138. }
  139. $titre .= ' ('.$langs->trans("ThirdPartySuppliers").')';
  140. $urlfiche = "card.php";
  141. } elseif ($type == "o") {
  142. if (empty($contextpage) || $contextpage == 'contactlist') {
  143. $contextpage = 'contactotherlist';
  144. }
  145. $titre .= ' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
  146. $urlfiche = "";
  147. }
  148. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  149. $object = new Contact($db);
  150. $hookmanager->initHooks(array('contactlist'));
  151. $extrafields = new ExtraFields($db);
  152. // fetch optionals attributes and labels
  153. $extrafields->fetch_name_optionals_label($object->table_element);
  154. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  155. // List of fields to search into when doing a "search in all"
  156. $fieldstosearchall = array();
  157. foreach ($object->fields as $key => $val) {
  158. // don't allow search in private notes for external users when doing "search in all"
  159. if (!empty($user->socid) && $key == "note_private") {
  160. continue;
  161. }
  162. if (empty($val['searchall'])) {
  163. continue;
  164. }
  165. $fieldstosearchall['p.'.$key] = $val['label'];
  166. }
  167. // Add none object fields for "search in all"
  168. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  169. $fieldstosearchall['s.nom'] = "ThirdParty";
  170. }
  171. // Definition of fields for list
  172. $arrayfields = array();
  173. foreach ($object->fields as $key => $val) {
  174. // If $val['visible']==0, then we never show the field
  175. if (empty($val['visible'])) {
  176. continue;
  177. }
  178. $arrayfields['p.'.$key] = array(
  179. 'label'=>$val['label'],
  180. 'checked'=>(($val['visible'] < 0) ? 0 : 1),
  181. 'enabled'=>($val['enabled'] && ($val['visible'] != 3)),
  182. 'position'=>$val['position']);
  183. }
  184. // Add none object fields to fields for list
  185. $arrayfields['country.code_iso'] = array('label'=>"Country", 'position'=>22, 'checked'=>0);
  186. if (empty($conf->global->SOCIETE_DISABLE_CONTACTS)) {
  187. $arrayfields['s.nom'] = array('label'=>"ThirdParty", 'position'=>25, 'checked'=>1);
  188. }
  189. $arrayfields['unsubscribed'] = array(
  190. 'label'=>'No_Email',
  191. 'checked'=>0,
  192. 'enabled'=>(!empty($conf->mailing->enabled)),
  193. 'position'=>41);
  194. if (!empty($conf->socialnetworks->enabled)) {
  195. foreach ($socialnetworks as $key => $value) {
  196. if ($value['active']) {
  197. $arrayfields['p.'.$key] = array(
  198. 'label' => $value['label'],
  199. 'checked' => 0,
  200. 'position' => 300
  201. );
  202. }
  203. }
  204. }
  205. // Extra fields
  206. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  207. $object->fields = dol_sort_array($object->fields, 'position');
  208. $arrayfields = dol_sort_array($arrayfields, 'position');
  209. if (($id > 0 || !empty($ref)) && $action != 'add') {
  210. $result = $object->fetch($id, $ref);
  211. if ($result < 0) {
  212. dol_print_error($db);
  213. }
  214. }
  215. /*
  216. * Actions
  217. */
  218. if (GETPOST('cancel', 'alpha')) {
  219. $action = 'list'; $massaction = '';
  220. }
  221. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  222. $massaction = '';
  223. }
  224. $parameters = array();
  225. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  226. if ($reshook < 0) {
  227. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  228. }
  229. if (empty($reshook)) {
  230. // Selection of new fields
  231. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  232. // Did we click on purge search criteria ?
  233. 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
  234. $sall = "";
  235. $search_id = '';
  236. $search_firstlast_only = "";
  237. $search_lastname = "";
  238. $search_firstname = "";
  239. $search_societe = "";
  240. $search_town = "";
  241. $search_address = "";
  242. $search_zip = "";
  243. $search_country = "";
  244. $search_poste = "";
  245. $search_phone = "";
  246. $search_phone_perso = "";
  247. $search_phone_pro = "";
  248. $search_phone_mobile = "";
  249. $search_fax = "";
  250. $search_email = "";
  251. $search_no_email = -1;
  252. if (!empty($conf->socialnetworks->enabled)) {
  253. foreach ($socialnetworks as $key => $value) {
  254. if ($value['active']) {
  255. $search_[$key] = "";
  256. }
  257. }
  258. }
  259. $search_priv = "";
  260. $search_stcomm = '';
  261. $search_level = '';
  262. $search_status = -1;
  263. $search_categ = '';
  264. $search_categ_thirdparty = '';
  265. $search_categ_supplier = '';
  266. $search_import_key = '';
  267. $toselect = array();
  268. $search_array_options = array();
  269. $search_roles = array();
  270. }
  271. // Mass actions
  272. $objectclass = 'Contact';
  273. $objectlabel = 'Contact';
  274. $permissiontoread = $user->rights->societe->lire;
  275. $permissiontodelete = $user->rights->societe->supprimer;
  276. $permissiontoadd = $user->rights->societe->creer;
  277. $uploaddir = $conf->societe->dir_output;
  278. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  279. if ($action == 'setstcomm') {
  280. $object = new Contact($db);
  281. $result = $object->fetch(GETPOST('stcommcontactid'));
  282. $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
  283. $result = $object->update($object->id, $user);
  284. if ($result < 0) {
  285. setEventMessages($object->error, $object->errors, 'errors');
  286. }
  287. $action = '';
  288. }
  289. }
  290. if ($search_priv < 0) {
  291. $search_priv = '';
  292. }
  293. /*
  294. * View
  295. */
  296. $form = new Form($db);
  297. $formother = new FormOther($db);
  298. $formcompany = new FormCompany($db);
  299. $contactstatic = new Contact($db);
  300. if (!empty($conf->global->THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES)) {
  301. $contactstatic->loadCacheOfProspStatus();
  302. }
  303. $title = (!empty($conf->global->SOCIETE_ADDRESSES_MANAGEMENT) ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
  304. // Select every potentiels, and note each potentiels which fit in search parameters
  305. $tab_level = array();
  306. $sql = "SELECT code, label, sortorder";
  307. $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
  308. $sql .= " WHERE active > 0";
  309. $sql .= " ORDER BY sortorder";
  310. $resql = $db->query($sql);
  311. if ($resql) {
  312. while ($obj = $db->fetch_object($resql)) {
  313. // Compute level text
  314. $level = $langs->trans($obj->code);
  315. if ($level == $obj->code) {
  316. $level = $langs->trans($obj->label);
  317. }
  318. $tab_level[$obj->code] = $level;
  319. }
  320. } else {
  321. dol_print_error($db);
  322. }
  323. $sql = "SELECT s.rowid as socid, s.nom as name,";
  324. $sql .= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.address, p.zip, p.town, p.poste, p.email,";
  325. $sql .= " p.socialnetworks, p.photo,";
  326. $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,";
  327. $sql .= " st.libelle as stcomm, st.picto as stcomm_picto, p.fk_stcommcontact as stcomm_id, p.fk_prospectcontactlevel,";
  328. $sql .= " co.label as country, co.code as country_code";
  329. // Add fields from extrafields
  330. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  331. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  332. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  333. }
  334. }
  335. if (!empty($conf->mailing->enabled)) {
  336. $sql .= ", (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) as unsubscribed";
  337. }
  338. // Add fields from hooks
  339. $parameters = array();
  340. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  341. $sql .= $hookmanager->resPrint;
  342. $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
  343. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  344. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
  345. }
  346. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
  347. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
  348. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact";
  349. if (!empty($search_categ) && $search_categ != '-1') {
  350. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_contact as cc ON p.rowid = cc.fk_socpeople"; // We need this table joined to the select in order to filter by categ
  351. }
  352. if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
  353. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cs ON s.rowid = cs.fk_soc"; // We need this table joined to the select in order to filter by categ
  354. }
  355. if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
  356. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_fournisseur as cs2 ON s.rowid = cs2.fk_soc"; // We need this table joined to the select in order to filter by categ
  357. }
  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. if ($search_categ > 0) {
  386. $sql .= " AND cc.fk_categorie = ".((int) $search_categ);
  387. }
  388. if ($search_categ == -2) {
  389. $sql .= " AND cc.fk_categorie IS NULL";
  390. }
  391. if ($search_categ_thirdparty > 0) {
  392. $sql .= " AND cs.fk_categorie = ".((int) $search_categ_thirdparty);
  393. }
  394. if ($search_categ_thirdparty == -2) {
  395. $sql .= " AND cs.fk_categorie IS NULL";
  396. }
  397. if ($search_categ_supplier > 0) {
  398. $sql .= " AND cs2.fk_categorie = ".((int) $search_categ_supplier);
  399. }
  400. if ($search_categ_supplier == -2) {
  401. $sql .= " AND cs2.fk_categorie IS NULL";
  402. }
  403. if ($sall) {
  404. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  405. }
  406. if (strlen($search_phone)) {
  407. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
  408. }
  409. if (strlen($search_cti)) {
  410. $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
  411. }
  412. if (strlen($search_firstlast_only)) {
  413. $sql .= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
  414. }
  415. if ($search_id > 0) {
  416. $sql .= natural_search('p.rowid', $search_id, 1);
  417. }
  418. if ($search_lastname) {
  419. $sql .= natural_search('p.lastname', $search_lastname);
  420. }
  421. if ($search_firstname) {
  422. $sql .= natural_search('p.firstname', $search_firstname);
  423. }
  424. if ($search_societe) {
  425. $sql .= natural_search(empty($conf->global->SOCIETE_DISABLE_CONTACTS) ? 's.nom' : 'p.fk_soc', $search_societe);
  426. }
  427. if ($search_country) {
  428. $sql .= " AND p.fk_pays IN (".$db->sanitize($search_country).')';
  429. }
  430. if (strlen($search_poste)) {
  431. $sql .= natural_search('p.poste', $search_poste);
  432. }
  433. if (strlen($search_phone_perso)) {
  434. $sql .= natural_search('p.phone_perso', $search_phone_perso);
  435. }
  436. if (strlen($search_phone_pro)) {
  437. $sql .= natural_search('p.phone', $search_phone_pro);
  438. }
  439. if (strlen($search_phone_mobile)) {
  440. $sql .= natural_search('p.phone_mobile', $search_phone_mobile);
  441. }
  442. if (strlen($search_fax)) {
  443. $sql .= natural_search('p.fax', $search_fax);
  444. }
  445. if (!empty($conf->socialnetworks->enabled)) {
  446. foreach ($socialnetworks as $key => $value) {
  447. if ($value['active'] && strlen($search_[$key])) {
  448. $sql .= " AND p.socialnetworks LIKE '%\"".$key."\":\"".$search_[$key]."%'";
  449. }
  450. }
  451. }
  452. if (strlen($search_email)) {
  453. $sql .= natural_search('p.email', $search_email);
  454. }
  455. if (strlen($search_address)) {
  456. $sql .= natural_search("p.address", $search_address);
  457. }
  458. if (strlen($search_zip)) {
  459. $sql .= natural_search("p.zip", $search_zip);
  460. }
  461. if (strlen($search_town)) {
  462. $sql .= natural_search("p.town", $search_town);
  463. }
  464. if (count($search_roles) > 0) {
  465. $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))."))";
  466. }
  467. if ($search_no_email != -1 && $search_no_email > 0) {
  468. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0";
  469. }
  470. if ($search_no_email != -1 && $search_no_email == 0) {
  471. $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''";
  472. }
  473. if ($search_status != '' && $search_status >= 0) {
  474. $sql .= " AND p.statut = ".((int) $search_status);
  475. }
  476. if ($search_import_key) {
  477. $sql .= natural_search("p.import_key", $search_import_key);
  478. }
  479. if ($type == "o") { // filtre sur type
  480. $sql .= " AND p.fk_soc IS NULL";
  481. } elseif ($type == "f") { // filtre sur type
  482. $sql .= " AND s.fournisseur = 1";
  483. } elseif ($type == "c") { // filtre sur type
  484. $sql .= " AND s.client IN (1, 3)";
  485. } elseif ($type == "p") { // filtre sur type
  486. $sql .= " AND s.client IN (2, 3)";
  487. }
  488. if (!empty($socid)) {
  489. $sql .= " AND s.rowid = ".((int) $socid);
  490. }
  491. // Add where from extra fields
  492. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  493. // Add where from hooks
  494. $parameters = array();
  495. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  496. $sql .= $hookmanager->resPrint;
  497. // Add order
  498. if ($view == "recent") {
  499. $sql .= $db->order("p.datec", "DESC");
  500. } else {
  501. $sql .= $db->order($sortfield, $sortorder);
  502. }
  503. // Count total nb of records
  504. $nbtotalofrecords = '';
  505. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  506. $resql = $db->query($sql);
  507. $nbtotalofrecords = $db->num_rows($resql);
  508. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  509. $page = 0;
  510. $offset = 0;
  511. }
  512. }
  513. $sql .= $db->plimit($limit + 1, $offset);
  514. $resql = $db->query($sql);
  515. if (!$resql) {
  516. dol_print_error($db);
  517. exit;
  518. }
  519. $num = $db->num_rows($resql);
  520. $arrayofselected = is_array($toselect) ? $toselect : array();
  521. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($sall != '' || $search_cti != '')) {
  522. $obj = $db->fetch_object($resql);
  523. $id = $obj->rowid;
  524. header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
  525. exit;
  526. }
  527. $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
  528. llxHeader('', $title, $help_url);
  529. $param = '';
  530. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  531. $param .= '&contextpage='.urlencode($contextpage);
  532. }
  533. if ($limit > 0 && $limit != $conf->liste_limit) {
  534. $param .= '&limit='.((int) $limit);
  535. }
  536. $param .= '&begin='.urlencode($begin).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
  537. $param .= '&type='.urlencode($type).'&view='.urlencode($view);
  538. if (!empty($search_categ) && $search_categ != '-1') {
  539. $param .= '&search_categ='.urlencode($search_categ);
  540. }
  541. if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
  542. $param .= '&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
  543. }
  544. if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
  545. $param .= '&search_categ_supplier='.urlencode($search_categ_supplier);
  546. }
  547. if ($sall != '') {
  548. $param .= '&sall='.urlencode($sall);
  549. }
  550. if ($search_id > 0) {
  551. $param .= "&search_id=".urlencode($search_id);
  552. }
  553. if ($search_lastname != '') {
  554. $param .= '&search_lastname='.urlencode($search_lastname);
  555. }
  556. if ($search_firstname != '') {
  557. $param .= '&search_firstname='.urlencode($search_firstname);
  558. }
  559. if ($search_societe != '') {
  560. $param .= '&search_societe='.urlencode($search_societe);
  561. }
  562. if ($search_address != '') {
  563. $param .= '&search_address='.urlencode($search_address);
  564. }
  565. if ($search_zip != '') {
  566. $param .= '&search_zip='.urlencode($search_zip);
  567. }
  568. if ($search_town != '') {
  569. $param .= '&search_town='.urlencode($search_town);
  570. }
  571. if ($search_country != '') {
  572. $param .= "&search_country=".urlencode($search_country);
  573. }
  574. if ($search_poste != '') {
  575. $param .= '&search_poste='.urlencode($search_poste);
  576. }
  577. if ($search_phone_pro != '') {
  578. $param .= '&search_phone_pro='.urlencode($search_phone_pro);
  579. }
  580. if ($search_phone_perso != '') {
  581. $param .= '&search_phone_perso='.urlencode($search_phone_perso);
  582. }
  583. if ($search_phone_mobile != '') {
  584. $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
  585. }
  586. if ($search_fax != '') {
  587. $param .= '&search_fax='.urlencode($search_fax);
  588. }
  589. if ($search_email != '') {
  590. $param .= '&search_email='.urlencode($search_email);
  591. }
  592. if ($search_no_email != '') {
  593. $param .= '&search_no_email='.urlencode($search_no_email);
  594. }
  595. if ($search_status != '') {
  596. $param .= '&search_status='.urlencode($search_status);
  597. }
  598. if ($search_priv == '0' || $search_priv == '1') {
  599. $param .= "&search_priv=".urlencode($search_priv);
  600. }
  601. if ($search_stcomm != '') {
  602. $param .= '&search_stcomm='.urlencode($search_stcomm);
  603. }
  604. if (is_array($search_level) && count($search_level)) {
  605. foreach ($search_level as $slevel) {
  606. $param .= '&search_level[]='.urlencode($slevel);
  607. }
  608. }
  609. if ($search_import_key != '') {
  610. $param .= '&amp;search_import_key='.urlencode($search_import_key);
  611. }
  612. if ($optioncss != '') {
  613. $param .= '&amp;optioncss='.urlencode($optioncss);
  614. }
  615. if (count($search_roles) > 0) {
  616. $param .= implode('&search_roles[]=', $search_roles);
  617. }
  618. // Add $param from extra fields
  619. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  620. // List of mass actions available
  621. $arrayofmassactions = array(
  622. // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  623. // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  624. );
  625. //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
  626. if ($user->rights->societe->supprimer) {
  627. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  628. }
  629. if ($user->rights->societe->creer) {
  630. $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
  631. }
  632. if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
  633. $arrayofmassactions = array();
  634. }
  635. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  636. $newcardbutton = dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $user->rights->societe->contact->creer);
  637. print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
  638. if ($optioncss != '') {
  639. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  640. }
  641. print '<input type="hidden" name="token" value="'.newToken().'">';
  642. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  643. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  644. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  645. //print '<input type="hidden" name="page" value="'.$page.'">';
  646. print '<input type="hidden" name="type" value="'.$type.'">';
  647. print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
  648. print_barre_liste($titre, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
  649. $topicmail = "Information";
  650. $modelmail = "contact";
  651. $objecttmp = new Contact($db);
  652. $trackid = 'ctc'.$object->id;
  653. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  654. if ($sall) {
  655. foreach ($fieldstosearchall as $key => $val) {
  656. $fieldstosearchall[$key] = $langs->trans($val);
  657. }
  658. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  659. }
  660. if ($search_firstlast_only) {
  661. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
  662. }
  663. $moreforfilter = '';
  664. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
  665. require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  666. $moreforfilter .= '<div class="divsearchfield">';
  667. $tmptitle = $langs->trans('ContactCategoriesShort');
  668. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  669. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
  670. $moreforfilter .= '</div>';
  671. if (empty($type) || $type == 'c' || $type == 'p') {
  672. $moreforfilter .= '<div class="divsearchfield">';
  673. $tmptitle = '';
  674. if ($type == 'c') {
  675. $tmptitle .= $langs->trans('CustomersCategoriesShort');
  676. } elseif ($type == 'p') {
  677. $tmptitle .= $langs->trans('ProspectsCategoriesShort');
  678. } else {
  679. $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
  680. }
  681. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  682. $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
  683. $moreforfilter .= '</div>';
  684. }
  685. if (!empty($conf->fournisseur->enabled) && (empty($type) || $type == 'f')) {
  686. $moreforfilter .= '<div class="divsearchfield">';
  687. $tmptitle = $langs->trans('SuppliersCategoriesShort');
  688. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  689. $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
  690. $moreforfilter .= '</div>';
  691. }
  692. }
  693. $moreforfilter .= '<div class="divsearchfield">';
  694. $moreforfilter .= $langs->trans('Roles').': ';
  695. $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
  696. $moreforfilter .= '</div>';
  697. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  698. print $moreforfilter;
  699. $parameters = array('type'=>$type);
  700. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  701. print $hookmanager->resPrint;
  702. print '</div>';
  703. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  704. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  705. if ($massactionbutton) {
  706. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  707. }
  708. print '<div class="div-table-responsive">';
  709. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  710. // Lines for filter fields
  711. print '<tr class="liste_titre_filter">';
  712. if (!empty($arrayfields['p.rowid']['checked'])) {
  713. print '<td class="liste_titre">';
  714. print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
  715. print '</td>';
  716. }
  717. if (!empty($arrayfields['p.lastname']['checked'])) {
  718. print '<td class="liste_titre">';
  719. print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
  720. print '</td>';
  721. }
  722. if (!empty($arrayfields['p.firstname']['checked'])) {
  723. print '<td class="liste_titre">';
  724. print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
  725. print '</td>';
  726. }
  727. if (!empty($arrayfields['p.poste']['checked'])) {
  728. print '<td class="liste_titre">';
  729. print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
  730. print '</td>';
  731. }
  732. if (!empty($arrayfields['p.address']['checked'])) {
  733. print '<td class="liste_titre">';
  734. print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
  735. print '</td>';
  736. }
  737. if (!empty($arrayfields['p.zip']['checked'])) {
  738. print '<td class="liste_titre">';
  739. print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
  740. print '</td>';
  741. }
  742. if (!empty($arrayfields['p.town']['checked'])) {
  743. print '<td class="liste_titre">';
  744. print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
  745. print '</td>';
  746. }
  747. // State
  748. /*if (! empty($arrayfields['state.nom']['checked']))
  749. {
  750. print '<td class="liste_titre">';
  751. print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  752. print '</td>';
  753. }
  754. // Region
  755. if (! empty($arrayfields['region.nom']['checked']))
  756. {
  757. print '<td class="liste_titre">';
  758. print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
  759. print '</td>';
  760. }*/
  761. // Country
  762. if (!empty($arrayfields['country.code_iso']['checked'])) {
  763. print '<td class="liste_titre center">';
  764. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  765. print '</td>';
  766. }
  767. if (!empty($arrayfields['p.phone']['checked'])) {
  768. print '<td class="liste_titre">';
  769. print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
  770. print '</td>';
  771. }
  772. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  773. print '<td class="liste_titre">';
  774. print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
  775. print '</td>';
  776. }
  777. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  778. print '<td class="liste_titre">';
  779. print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
  780. print '</td>';
  781. }
  782. if (!empty($arrayfields['p.fax']['checked'])) {
  783. print '<td class="liste_titre">';
  784. print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
  785. print '</td>';
  786. }
  787. if (!empty($arrayfields['p.email']['checked'])) {
  788. print '<td class="liste_titre">';
  789. print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
  790. print '</td>';
  791. }
  792. if (!empty($arrayfields['unsubscribed']['checked'])) {
  793. print '<td class="liste_titre center">';
  794. print $form->selectarray('search_no_email', array('-1'=>'', '0'=>$langs->trans('No'), '1'=>$langs->trans('Yes')), $search_no_email);
  795. print '</td>';
  796. }
  797. if (!empty($conf->socialnetworks->enabled)) {
  798. foreach ($socialnetworks as $key => $value) {
  799. if ($value['active']) {
  800. if (!empty($arrayfields['p.'.$key]['checked'])) {
  801. print '<td class="liste_titre">';
  802. print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
  803. print '</td>';
  804. }
  805. }
  806. }
  807. }
  808. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  809. print '<td class="liste_titre">';
  810. print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
  811. print '</td>';
  812. }
  813. if (!empty($arrayfields['p.priv']['checked'])) {
  814. print '<td class="liste_titre center">';
  815. $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
  816. print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
  817. print '</td>';
  818. }
  819. // Prospect level
  820. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  821. print '<td class="liste_titre center">';
  822. print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
  823. print '</td>';
  824. }
  825. // Prospect status
  826. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  827. print '<td class="liste_titre maxwidthonsmartphone center">';
  828. $arraystcomm = array();
  829. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  830. $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
  831. }
  832. print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
  833. print '</td>';
  834. }
  835. // Extra fields
  836. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  837. // Fields from hook
  838. $parameters = array('arrayfields'=>$arrayfields);
  839. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  840. print $hookmanager->resPrint;
  841. // Date creation
  842. if (!empty($arrayfields['p.datec']['checked'])) {
  843. print '<td class="liste_titre">';
  844. print '</td>';
  845. }
  846. // Date modification
  847. if (!empty($arrayfields['p.tms']['checked'])) {
  848. print '<td class="liste_titre">';
  849. print '</td>';
  850. }
  851. // Status
  852. if (!empty($arrayfields['p.statut']['checked'])) {
  853. print '<td class="liste_titre center">';
  854. print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status);
  855. print '</td>';
  856. }
  857. if (!empty($arrayfields['p.import_key']['checked'])) {
  858. print '<td class="liste_titre center">';
  859. print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
  860. print '</td>';
  861. }
  862. // Action column
  863. print '<td class="liste_titre maxwidthsearch">';
  864. $searchpicto = $form->showFilterAndCheckAddButtons(0);
  865. print $searchpicto;
  866. print '</td>';
  867. print '</tr>';
  868. // Ligne des titres
  869. print '<tr class="liste_titre">';
  870. if (!empty($arrayfields['p.rowid']['checked'])) {
  871. print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
  872. }
  873. if (!empty($arrayfields['p.lastname']['checked'])) {
  874. print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
  875. }
  876. if (!empty($arrayfields['p.firstname']['checked'])) {
  877. print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
  878. }
  879. if (!empty($arrayfields['p.poste']['checked'])) {
  880. print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
  881. }
  882. if (!empty($arrayfields['p.address']['checked'])) {
  883. print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
  884. }
  885. if (!empty($arrayfields['p.zip']['checked'])) {
  886. print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
  887. }
  888. if (!empty($arrayfields['p.town']['checked'])) {
  889. print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
  890. }
  891. //if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
  892. //if (! empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
  893. if (!empty($arrayfields['country.code_iso']['checked'])) {
  894. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  895. }
  896. if (!empty($arrayfields['p.phone']['checked'])) {
  897. print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
  898. }
  899. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  900. print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
  901. }
  902. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  903. print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
  904. }
  905. if (!empty($arrayfields['p.fax']['checked'])) {
  906. print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
  907. }
  908. if (!empty($arrayfields['p.email']['checked'])) {
  909. print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
  910. }
  911. if (!empty($arrayfields['unsubscribed']['checked'])) {
  912. print_liste_field_titre($arrayfields['unsubscribed']['label'], $_SERVER["PHP_SELF"], "unsubscribed", $begin, $param, '', $sortfield, $sortorder, 'center ');
  913. }
  914. if (!empty($conf->socialnetworks->enabled)) {
  915. foreach ($socialnetworks as $key => $value) {
  916. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  917. print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
  918. }
  919. }
  920. }
  921. if (!empty($arrayfields['p.fk_soc']['checked'])) {
  922. print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
  923. }
  924. if (!empty($arrayfields['s.nom']['checked'])) {
  925. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
  926. }
  927. if (!empty($arrayfields['p.priv']['checked'])) {
  928. print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
  929. }
  930. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  931. print_liste_field_titre($arrayfields['p.fk_prospectcontactlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectcontactlevel", "", $param, '', $sortfield, $sortorder, 'center ');
  932. }
  933. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  934. print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
  935. }
  936. // Extra fields
  937. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  938. // Hook fields
  939. $parameters = array(
  940. 'arrayfields'=>$arrayfields,
  941. 'param'=>$param,
  942. 'sortfield'=>$sortfield,
  943. 'sortorder'=>$sortorder,
  944. );
  945. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  946. print $hookmanager->resPrint;
  947. if (!empty($arrayfields['p.datec']['checked'])) {
  948. print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  949. }
  950. if (!empty($arrayfields['p.tms']['checked'])) {
  951. print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  952. }
  953. if (!empty($arrayfields['p.statut']['checked'])) {
  954. print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
  955. }
  956. if (!empty($arrayfields['p.import_key']['checked'])) {
  957. print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
  958. }
  959. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  960. print "</tr>\n";
  961. $i = 0;
  962. $totalarray = array();
  963. $totalarray['nbfield'] = 0;
  964. while ($i < min($num, $limit)) {
  965. $obj = $db->fetch_object($resql);
  966. $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
  967. $contactstatic->lastname = $obj->lastname;
  968. $contactstatic->firstname = '';
  969. $contactstatic->id = $obj->rowid;
  970. $contactstatic->statut = $obj->statut;
  971. $contactstatic->poste = $obj->poste;
  972. $contactstatic->email = $obj->email;
  973. $contactstatic->phone_pro = $obj->phone_pro;
  974. $contactstatic->phone_perso = $obj->phone_perso;
  975. $contactstatic->phone_mobile = $obj->phone_mobile;
  976. $contactstatic->address = $obj->address;
  977. $contactstatic->zip = $obj->zip;
  978. $contactstatic->town = $obj->town;
  979. $contactstatic->socialnetworks = $arraysocialnetworks;
  980. $contactstatic->country = $obj->country;
  981. $contactstatic->country_code = $obj->country_code;
  982. $contactstatic->photo = $obj->photo;
  983. $contactstatic->fk_prospectlevel = $obj->fk_prospectcontactlevel;
  984. print '<tr class="oddeven">';
  985. // ID
  986. if (!empty($arrayfields['p.rowid']['checked'])) {
  987. print '<td class="tdoverflowmax50">';
  988. print $obj->rowid;
  989. print "</td>\n";
  990. if (!$i) {
  991. $totalarray['nbfield']++;
  992. }
  993. }
  994. // Name
  995. if (!empty($arrayfields['p.lastname']['checked'])) {
  996. print '<td class="middle tdoverflowmax200">';
  997. print $contactstatic->getNomUrl(1);
  998. print '</td>';
  999. if (!$i) {
  1000. $totalarray['nbfield']++;
  1001. }
  1002. }
  1003. // Firstname
  1004. if (!empty($arrayfields['p.firstname']['checked'])) {
  1005. print '<td class="tdoverflowmax200">'.$obj->firstname.'</td>';
  1006. if (!$i) {
  1007. $totalarray['nbfield']++;
  1008. }
  1009. }
  1010. // Job position
  1011. if (!empty($arrayfields['p.poste']['checked'])) {
  1012. print '<td class="tdoverflowmax100">'.$obj->poste.'</td>';
  1013. if (!$i) {
  1014. $totalarray['nbfield']++;
  1015. }
  1016. }
  1017. // Address
  1018. if (!empty($arrayfields['p.address']['checked'])) {
  1019. print '<td>'.$obj->address.'</td>';
  1020. if (!$i) {
  1021. $totalarray['nbfield']++;
  1022. }
  1023. }
  1024. // Zip
  1025. if (!empty($arrayfields['p.zip']['checked'])) {
  1026. print '<td>'.$obj->zip.'</td>';
  1027. if (!$i) {
  1028. $totalarray['nbfield']++;
  1029. }
  1030. }
  1031. // Town
  1032. if (!empty($arrayfields['p.town']['checked'])) {
  1033. print '<td>'.$obj->town.'</td>';
  1034. if (!$i) {
  1035. $totalarray['nbfield']++;
  1036. }
  1037. }
  1038. // State
  1039. /*if (! empty($arrayfields['state.nom']['checked']))
  1040. {
  1041. print "<td>".$obj->state_name."</td>\n";
  1042. if (! $i) $totalarray['nbfield']++;
  1043. }
  1044. // Region
  1045. if (! empty($arrayfields['region.nom']['checked']))
  1046. {
  1047. print "<td>".$obj->region_name."</td>\n";
  1048. if (! $i) $totalarray['nbfield']++;
  1049. }*/
  1050. // Country
  1051. if (!empty($arrayfields['country.code_iso']['checked'])) {
  1052. print '<td class="center">';
  1053. $tmparray = getCountry($obj->fk_pays, 'all');
  1054. print $tmparray['label'];
  1055. print '</td>';
  1056. if (!$i) {
  1057. $totalarray['nbfield']++;
  1058. }
  1059. }
  1060. // Phone
  1061. if (!empty($arrayfields['p.phone']['checked'])) {
  1062. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1063. if (!$i) {
  1064. $totalarray['nbfield']++;
  1065. }
  1066. }
  1067. // Phone perso
  1068. if (!empty($arrayfields['p.phone_perso']['checked'])) {
  1069. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
  1070. if (!$i) {
  1071. $totalarray['nbfield']++;
  1072. }
  1073. }
  1074. // Phone mobile
  1075. if (!empty($arrayfields['p.phone_mobile']['checked'])) {
  1076. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
  1077. if (!$i) {
  1078. $totalarray['nbfield']++;
  1079. }
  1080. }
  1081. // Fax
  1082. if (!empty($arrayfields['p.fax']['checked'])) {
  1083. print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
  1084. if (!$i) {
  1085. $totalarray['nbfield']++;
  1086. }
  1087. }
  1088. // EMail
  1089. if (!empty($arrayfields['p.email']['checked'])) {
  1090. print '<td class="nowraponall tdoverflowmax300">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'</td>';
  1091. if (!$i) {
  1092. $totalarray['nbfield']++;
  1093. }
  1094. }
  1095. // No EMail
  1096. if (!empty($arrayfields['unsubscribed']['checked'])) {
  1097. print '<td class="center">';
  1098. if (empty($obj->email)) {
  1099. //print '<span class="opacitymedium">'.$langs->trans("NoEmail").'</span>';
  1100. } else {
  1101. print yn(($obj->unsubscribed > 0) ? 1 : 0);
  1102. }
  1103. print '</td>';
  1104. if (!$i) {
  1105. $totalarray['nbfield']++;
  1106. }
  1107. }
  1108. if (!empty($conf->socialnetworks->enabled)) {
  1109. foreach ($socialnetworks as $key => $value) {
  1110. if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
  1111. print '<td>'.dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks).'</td>';
  1112. if (!$i) {
  1113. $totalarray['nbfield']++;
  1114. }
  1115. }
  1116. }
  1117. }
  1118. // Company
  1119. if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
  1120. print '<td class="tdoverflowmax200">';
  1121. if ($obj->socid) {
  1122. $objsoc = new Societe($db);
  1123. $objsoc->fetch($obj->socid);
  1124. print $objsoc->getNomUrl(1);
  1125. } else {
  1126. print '&nbsp;';
  1127. }
  1128. print '</td>';
  1129. if (!$i) {
  1130. $totalarray['nbfield']++;
  1131. }
  1132. }
  1133. // Private/Public
  1134. if (!empty($arrayfields['p.priv']['checked'])) {
  1135. print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
  1136. if (!$i) {
  1137. $totalarray['nbfield']++;
  1138. }
  1139. }
  1140. if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
  1141. // Prospect level
  1142. print '<td class="center">';
  1143. print $contactstatic->getLibProspLevel();
  1144. print "</td>";
  1145. if (!$i) {
  1146. $totalarray['nbfield']++;
  1147. }
  1148. }
  1149. if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
  1150. // Prospect status
  1151. print '<td class="center nowrap"><div class="nowrap">';
  1152. print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
  1153. print '</div> - <div class="inline-block">';
  1154. foreach ($contactstatic->cacheprospectstatus as $key => $val) {
  1155. $titlealt = 'default';
  1156. if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
  1157. $titlealt = $val['label'];
  1158. }
  1159. if ($obj->stcomm_id != $val['id']) {
  1160. 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>';
  1161. }
  1162. }
  1163. print '</div></div></td>';
  1164. if (!$i) {
  1165. $totalarray['nbfield']++;
  1166. }
  1167. }
  1168. // Extra fields
  1169. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  1170. // Fields from hook
  1171. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  1172. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1173. print $hookmanager->resPrint;
  1174. // Date creation
  1175. if (!empty($arrayfields['p.datec']['checked'])) {
  1176. print '<td class="center">';
  1177. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  1178. print '</td>';
  1179. if (!$i) {
  1180. $totalarray['nbfield']++;
  1181. }
  1182. }
  1183. // Date modification
  1184. if (!empty($arrayfields['p.tms']['checked'])) {
  1185. print '<td class="center">';
  1186. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  1187. print '</td>';
  1188. if (!$i) {
  1189. $totalarray['nbfield']++;
  1190. }
  1191. }
  1192. // Status
  1193. if (!empty($arrayfields['p.statut']['checked'])) {
  1194. print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
  1195. if (!$i) {
  1196. $totalarray['nbfield']++;
  1197. }
  1198. }
  1199. if (!empty($arrayfields['p.import_key']['checked'])) {
  1200. print '<td class="tdoverflowmax100">';
  1201. print $obj->import_key;
  1202. print "</td>\n";
  1203. if (!$i) {
  1204. $totalarray['nbfield']++;
  1205. }
  1206. }
  1207. // Action column
  1208. print '<td class="nowrap 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. if (!$i) {
  1218. $totalarray['nbfield']++;
  1219. }
  1220. print "</tr>\n";
  1221. $i++;
  1222. }
  1223. // Show total line
  1224. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  1225. // If no record found
  1226. if ($num == 0) {
  1227. $colspan = 1;
  1228. foreach ($arrayfields as $key => $val) {
  1229. if (!empty($val['checked'])) {
  1230. $colspan++;
  1231. }
  1232. }
  1233. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  1234. }
  1235. $db->free($resql);
  1236. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  1237. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  1238. print $hookmanager->resPrint;
  1239. print '</table>'."\n";
  1240. print '</div>'."\n";
  1241. print '</form>'."\n";
  1242. // End of page
  1243. llxFooter();
  1244. $db->close();