list.php 51 KB

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