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