dolibarr  16.0.1
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  $sql .= " AND p.socialnetworks LIKE '%\"".$key."\":\"".$search_[$key]."%'";
504  }
505  }
506 }
507 if (strlen($search_email)) {
508  $sql .= natural_search('p.email', $search_email);
509 }
510 if (strlen($search_address)) {
511  $sql .= natural_search("p.address", $search_address);
512 }
513 if (strlen($search_zip)) {
514  $sql .= natural_search("p.zip", $search_zip);
515 }
516 if (strlen($search_town)) {
517  $sql .= natural_search("p.town", $search_town);
518 }
519 if (count($search_roles) > 0) {
520  $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))."))";
521 }
522 if ($search_no_email != -1 && $search_no_email > 0) {
523  $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0";
524 }
525 if ($search_no_email != -1 && $search_no_email == 0) {
526  $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''";
527 }
528 if ($search_status != '' && $search_status >= 0) {
529  $sql .= " AND p.statut = ".((int) $search_status);
530 }
531 if ($search_import_key) {
532  $sql .= natural_search("p.import_key", $search_import_key);
533 }
534 if ($type == "o") { // filtre sur type
535  $sql .= " AND p.fk_soc IS NULL";
536 } elseif ($type == "f") { // filtre sur type
537  $sql .= " AND s.fournisseur = 1";
538 } elseif ($type == "c") { // filtre sur type
539  $sql .= " AND s.client IN (1, 3)";
540 } elseif ($type == "p") { // filtre sur type
541  $sql .= " AND s.client IN (2, 3)";
542 }
543 if (!empty($socid)) {
544  $sql .= " AND s.rowid = ".((int) $socid);
545 }
546 // Add where from extra fields
547 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
548 // Add where from hooks
549 $parameters = array();
550 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
551 $sql .= $hookmanager->resPrint;
552 // Add order
553 if ($view == "recent") {
554  $sql .= $db->order("p.datec", "DESC");
555 } else {
556  $sql .= $db->order($sortfield, $sortorder);
557 }
558 
559 // Count total nb of records
560 $nbtotalofrecords = '';
561 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
562  $resql = $db->query($sql);
563  $nbtotalofrecords = $db->num_rows($resql);
564  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
565  $page = 0;
566  $offset = 0;
567  }
568 }
569 
570 $sql .= $db->plimit($limit + 1, $offset);
571 
572 $resql = $db->query($sql);
573 if (!$resql) {
574  dol_print_error($db);
575  exit;
576 }
577 
578 $num = $db->num_rows($resql);
579 
580 $arrayofselected = is_array($toselect) ? $toselect : array();
581 
582 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && ($sall != '' || $search_cti != '')) {
583  $obj = $db->fetch_object($resql);
584  $id = $obj->rowid;
585  header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
586  exit;
587 }
588 
589 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
590 llxHeader('', $title, $help_url);
591 
592 $param = '';
593 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
594  $param .= '&contextpage='.urlencode($contextpage);
595 }
596 if ($limit > 0 && $limit != $conf->liste_limit) {
597  $param .= '&limit='.((int) $limit);
598 }
599 $param .= '&begin='.urlencode($begin).'&userid='.urlencode($userid).'&contactname='.urlencode($sall);
600 $param .= '&type='.urlencode($type).'&view='.urlencode($view);
601 if (!empty($search_categ) && $search_categ != '-1') {
602  $param .= '&search_categ='.urlencode($search_categ);
603 }
604 if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
605  $param .= '&search_categ_thirdparty='.urlencode($search_categ_thirdparty);
606 }
607 if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
608  $param .= '&search_categ_supplier='.urlencode($search_categ_supplier);
609 }
610 if ($sall != '') {
611  $param .= '&sall='.urlencode($sall);
612 }
613 if ($search_id > 0) {
614  $param .= "&search_id=".urlencode($search_id);
615 }
616 if ($search_lastname != '') {
617  $param .= '&search_lastname='.urlencode($search_lastname);
618 }
619 if ($search_firstname != '') {
620  $param .= '&search_firstname='.urlencode($search_firstname);
621 }
622 if ($search_societe != '') {
623  $param .= '&search_societe='.urlencode($search_societe);
624 }
625 if ($search_address != '') {
626  $param .= '&search_address='.urlencode($search_address);
627 }
628 if ($search_zip != '') {
629  $param .= '&search_zip='.urlencode($search_zip);
630 }
631 if ($search_town != '') {
632  $param .= '&search_town='.urlencode($search_town);
633 }
634 if ($search_country != '') {
635  $param .= "&search_country=".urlencode($search_country);
636 }
637 if ($search_poste != '') {
638  $param .= '&search_poste='.urlencode($search_poste);
639 }
640 if ($search_phone_pro != '') {
641  $param .= '&search_phone_pro='.urlencode($search_phone_pro);
642 }
643 if ($search_phone_perso != '') {
644  $param .= '&search_phone_perso='.urlencode($search_phone_perso);
645 }
646 if ($search_phone_mobile != '') {
647  $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
648 }
649 if ($search_fax != '') {
650  $param .= '&search_fax='.urlencode($search_fax);
651 }
652 if ($search_email != '') {
653  $param .= '&search_email='.urlencode($search_email);
654 }
655 if ($search_no_email != '') {
656  $param .= '&search_no_email='.urlencode($search_no_email);
657 }
658 if ($search_status != '') {
659  $param .= '&search_status='.urlencode($search_status);
660 }
661 if ($search_priv == '0' || $search_priv == '1') {
662  $param .= "&search_priv=".urlencode($search_priv);
663 }
664 if ($search_stcomm != '') {
665  $param .= '&search_stcomm='.urlencode($search_stcomm);
666 }
667 if (is_array($search_level) && count($search_level)) {
668  foreach ($search_level as $slevel) {
669  $param .= '&search_level[]='.urlencode($slevel);
670  }
671 }
672 if ($search_import_key != '') {
673  $param .= '&amp;search_import_key='.urlencode($search_import_key);
674 }
675 if ($optioncss != '') {
676  $param .= '&amp;optioncss='.urlencode($optioncss);
677 }
678 if (count($search_roles) > 0) {
679  $param .= implode('&search_roles[]=', $search_roles);
680 }
681 
682 // Add $param from extra fields
683 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
684 
685 // List of mass actions available
686 $arrayofmassactions = array(
687 // 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
688 // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
689 );
690 //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
691 if ($user->rights->societe->supprimer) {
692  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
693 }
694 if (isModEnabled('category') && $user->rights->societe->creer) {
695  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
696 }
697 if (in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
698  $arrayofmassactions = array();
699 }
700 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
701 
702 $newcardbutton = dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $user->rights->societe->contact->creer);
703 
704 print '<form method="post" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
705 if ($optioncss != '') {
706  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
707 }
708 print '<input type="hidden" name="token" value="'.newToken().'">';
709 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
710 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
711 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
712 //print '<input type="hidden" name="page" value="'.$page.'">';
713 print '<input type="hidden" name="type" value="'.$type.'">';
714 print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
715 
716 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
717 
718 $topicmail = "Information";
719 $modelmail = "contact";
720 $objecttmp = new Contact($db);
721 $trackid = 'ctc'.$object->id;
722 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
723 
724 if ($sall) {
725  foreach ($fieldstosearchall as $key => $val) {
726  $fieldstosearchall[$key] = $langs->trans($val);
727  }
728  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
729 }
730 if ($search_firstlast_only) {
731  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
732 }
733 
734 $moreforfilter = '';
735 if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
736  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
737  $moreforfilter .= '<div class="divsearchfield">';
738  $tmptitle = $langs->trans('ContactCategoriesShort');
739  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
740  $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
741  $moreforfilter .= '</div>';
742  if (empty($type) || $type == 'c' || $type == 'p') {
743  $moreforfilter .= '<div class="divsearchfield">';
744  $tmptitle = '';
745  if ($type == 'c') {
746  $tmptitle .= $langs->trans('CustomersCategoriesShort');
747  } elseif ($type == 'p') {
748  $tmptitle .= $langs->trans('ProspectsCategoriesShort');
749  } else {
750  $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
751  }
752  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
753  $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
754  $moreforfilter .= '</div>';
755  }
756 
757  if (!empty($conf->fournisseur->enabled) && (empty($type) || $type == 'f')) {
758  $moreforfilter .= '<div class="divsearchfield">';
759  $tmptitle = $langs->trans('SuppliersCategoriesShort');
760  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
761  $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
762  $moreforfilter .= '</div>';
763  }
764 }
765 
766 $moreforfilter .= '<div class="divsearchfield">';
767 $moreforfilter .= $langs->trans('Roles').': ';
768 $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
769 $moreforfilter .= '</div>';
770 
771 print '<div class="liste_titre liste_titre_bydiv centpercent">';
772 print $moreforfilter;
773 $parameters = array('type'=>$type);
774 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
775 print $hookmanager->resPrint;
776 print '</div>';
777 
778 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
779 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
780 if ($massactionbutton) {
781  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
782 }
783 
784 print '<div class="div-table-responsive">';
785 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
786 
787 // Lines for filter fields
788 print '<tr class="liste_titre_filter">';
789 if (!empty($arrayfields['p.rowid']['checked'])) {
790  print '<td class="liste_titre">';
791  print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
792  print '</td>';
793 }
794 if (!empty($arrayfields['p.lastname']['checked'])) {
795  print '<td class="liste_titre">';
796  print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
797  print '</td>';
798 }
799 if (!empty($arrayfields['p.firstname']['checked'])) {
800  print '<td class="liste_titre">';
801  print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
802  print '</td>';
803 }
804 if (!empty($arrayfields['p.poste']['checked'])) {
805  print '<td class="liste_titre">';
806  print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
807  print '</td>';
808 }
809 if (!empty($arrayfields['p.address']['checked'])) {
810  print '<td class="liste_titre">';
811  print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
812  print '</td>';
813 }
814 if (!empty($arrayfields['p.zip']['checked'])) {
815  print '<td class="liste_titre">';
816  print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
817  print '</td>';
818 }
819 if (!empty($arrayfields['p.town']['checked'])) {
820  print '<td class="liste_titre">';
821  print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
822  print '</td>';
823 }
824 // State
825 /*if (! empty($arrayfields['state.nom']['checked']))
826  {
827  print '<td class="liste_titre">';
828  print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
829  print '</td>';
830  }
831  // Region
832  if (! empty($arrayfields['region.nom']['checked']))
833  {
834  print '<td class="liste_titre">';
835  print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
836  print '</td>';
837  }*/
838 // Country
839 if (!empty($arrayfields['country.code_iso']['checked'])) {
840  print '<td class="liste_titre center">';
841  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
842  print '</td>';
843 }
844 if (!empty($arrayfields['p.phone']['checked'])) {
845  print '<td class="liste_titre">';
846  print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
847  print '</td>';
848 }
849 if (!empty($arrayfields['p.phone_perso']['checked'])) {
850  print '<td class="liste_titre">';
851  print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
852  print '</td>';
853 }
854 if (!empty($arrayfields['p.phone_mobile']['checked'])) {
855  print '<td class="liste_titre">';
856  print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
857  print '</td>';
858 }
859 if (!empty($arrayfields['p.fax']['checked'])) {
860  print '<td class="liste_titre">';
861  print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
862  print '</td>';
863 }
864 if (!empty($arrayfields['p.email']['checked'])) {
865  print '<td class="liste_titre">';
866  print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
867  print '</td>';
868 }
869 if (!empty($arrayfields['unsubscribed']['checked'])) {
870  print '<td class="liste_titre center">';
871  print $form->selectarray('search_no_email', array('-1'=>'', '0'=>$langs->trans('No'), '1'=>$langs->trans('Yes')), $search_no_email);
872  print '</td>';
873 }
874 if (!empty($conf->socialnetworks->enabled)) {
875  foreach ($socialnetworks as $key => $value) {
876  if ($value['active']) {
877  if (!empty($arrayfields['p.'.$key]['checked'])) {
878  print '<td class="liste_titre">';
879  print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
880  print '</td>';
881  }
882  }
883  }
884 }
885 if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
886  print '<td class="liste_titre">';
887  print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
888  print '</td>';
889 }
890 if (!empty($arrayfields['p.priv']['checked'])) {
891  print '<td class="liste_titre center">';
892  $selectarray = array('0'=>$langs->trans("ContactPublic"), '1'=>$langs->trans("ContactPrivate"));
893  print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
894  print '</td>';
895 }
896 // Prospect level
897 if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
898  print '<td class="liste_titre center">';
899  print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
900  print '</td>';
901 }
902 // Prospect status
903 if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
904  print '<td class="liste_titre maxwidthonsmartphone center">';
905  $arraystcomm = array();
906  foreach ($contactstatic->cacheprospectstatus as $key => $val) {
907  $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
908  }
909  print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
910  print '</td>';
911 }
912 // Extra fields
913 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
914 
915 // Fields from hook
916 $parameters = array('arrayfields'=>$arrayfields);
917 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
918 print $hookmanager->resPrint;
919 // Date creation
920 if (!empty($arrayfields['p.datec']['checked'])) {
921  print '<td class="liste_titre">';
922  print '</td>';
923 }
924 // Date modification
925 if (!empty($arrayfields['p.tms']['checked'])) {
926  print '<td class="liste_titre">';
927  print '</td>';
928 }
929 // Status
930 if (!empty($arrayfields['p.statut']['checked'])) {
931  print '<td class="liste_titre center">';
932  print $form->selectarray('search_status', array('-1'=>'', '0'=>$langs->trans('ActivityCeased'), '1'=>$langs->trans('InActivity')), $search_status);
933  print '</td>';
934 }
935 if (!empty($arrayfields['p.import_key']['checked'])) {
936  print '<td class="liste_titre center">';
937  print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
938  print '</td>';
939 }
940 // Action column
941 print '<td class="liste_titre maxwidthsearch">';
942 $searchpicto = $form->showFilterAndCheckAddButtons(0);
943 print $searchpicto;
944 print '</td>';
945 
946 print '</tr>';
947 
948 // Ligne des titres
949 print '<tr class="liste_titre">';
950 if (!empty($arrayfields['p.rowid']['checked'])) {
951  print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
952 }
953 if (!empty($arrayfields['p.lastname']['checked'])) {
954  print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
955 }
956 if (!empty($arrayfields['p.firstname']['checked'])) {
957  print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
958 }
959 if (!empty($arrayfields['p.poste']['checked'])) {
960  print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
961 }
962 if (!empty($arrayfields['p.address']['checked'])) {
963  print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
964 }
965 if (!empty($arrayfields['p.zip']['checked'])) {
966  print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
967 }
968 if (!empty($arrayfields['p.town']['checked'])) {
969  print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
970 }
971 //if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
972 //if (! empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
973 if (!empty($arrayfields['country.code_iso']['checked'])) {
974  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
975 }
976 if (!empty($arrayfields['p.phone']['checked'])) {
977  print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
978 }
979 if (!empty($arrayfields['p.phone_perso']['checked'])) {
980  print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
981 }
982 if (!empty($arrayfields['p.phone_mobile']['checked'])) {
983  print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
984 }
985 if (!empty($arrayfields['p.fax']['checked'])) {
986  print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
987 }
988 if (!empty($arrayfields['p.email']['checked'])) {
989  print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
990 }
991 if (!empty($arrayfields['unsubscribed']['checked'])) {
992  print_liste_field_titre($arrayfields['unsubscribed']['label'], $_SERVER["PHP_SELF"], "unsubscribed", $begin, $param, '', $sortfield, $sortorder, 'center ');
993 }
994 if (!empty($conf->socialnetworks->enabled)) {
995  foreach ($socialnetworks as $key => $value) {
996  if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
997  print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
998  }
999  }
1000 }
1001 if (!empty($arrayfields['p.fk_soc']['checked'])) {
1002  print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
1003 }
1004 if (!empty($arrayfields['s.nom']['checked'])) {
1005  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
1006 }
1007 if (!empty($arrayfields['p.priv']['checked'])) {
1008  print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
1009 }
1010 if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
1011  print_liste_field_titre($arrayfields['p.fk_prospectcontactlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectcontactlevel", "", $param, '', $sortfield, $sortorder, 'center ');
1012 }
1013 if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
1014  print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
1015 }
1016 // Extra fields
1017 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1018 // Hook fields
1019 $parameters = array(
1020  'arrayfields'=>$arrayfields,
1021  'param'=>$param,
1022  'sortfield'=>$sortfield,
1023  'sortorder'=>$sortorder,
1024 );
1025 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1026 print $hookmanager->resPrint;
1027 if (!empty($arrayfields['p.datec']['checked'])) {
1028  print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1029 }
1030 if (!empty($arrayfields['p.tms']['checked'])) {
1031  print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1032 }
1033 if (!empty($arrayfields['p.statut']['checked'])) {
1034  print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
1035 }
1036 if (!empty($arrayfields['p.import_key']['checked'])) {
1037  print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1038 }
1039 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1040 print "</tr>\n";
1041 
1042 
1043 $i = 0;
1044 $totalarray = array();
1045 $totalarray['nbfield'] = 0;
1046 while ($i < min($num, $limit)) {
1047  $obj = $db->fetch_object($resql);
1048 
1049  $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
1050  $contactstatic->lastname = $obj->lastname;
1051  $contactstatic->firstname = '';
1052  $contactstatic->id = $obj->rowid;
1053  $contactstatic->statut = $obj->statut;
1054  $contactstatic->poste = $obj->poste;
1055  $contactstatic->email = $obj->email;
1056  $contactstatic->phone_pro = $obj->phone_pro;
1057  $contactstatic->phone_perso = $obj->phone_perso;
1058  $contactstatic->phone_mobile = $obj->phone_mobile;
1059  $contactstatic->address = $obj->address;
1060  $contactstatic->zip = $obj->zip;
1061  $contactstatic->town = $obj->town;
1062  $contactstatic->socialnetworks = $arraysocialnetworks;
1063  $contactstatic->country = $obj->country;
1064  $contactstatic->country_code = $obj->country_code;
1065  $contactstatic->photo = $obj->photo;
1066  $contactstatic->import_key = $obj->import_key;
1067 
1068  $contactstatic->fk_prospectlevel = $obj->fk_prospectcontactlevel;
1069 
1070  print '<tr class="oddeven">';
1071 
1072  // ID
1073  if (!empty($arrayfields['p.rowid']['checked'])) {
1074  print '<td class="tdoverflowmax50">';
1075  print dol_escape_htmltag($obj->rowid);
1076  print "</td>\n";
1077  if (!$i) {
1078  $totalarray['nbfield']++;
1079  }
1080  }
1081  // Name
1082  if (!empty($arrayfields['p.lastname']['checked'])) {
1083  print '<td class="middle tdoverflowmax150">';
1084  print $contactstatic->getNomUrl(1);
1085  print '</td>';
1086  if (!$i) {
1087  $totalarray['nbfield']++;
1088  }
1089  }
1090  // Firstname
1091  if (!empty($arrayfields['p.firstname']['checked'])) {
1092  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
1093  if (!$i) {
1094  $totalarray['nbfield']++;
1095  }
1096  }
1097  // Job position
1098  if (!empty($arrayfields['p.poste']['checked'])) {
1099  print '<td class="tdoverflowmax100">'.dol_escape_htmltag($obj->poste).'</td>';
1100  if (!$i) {
1101  $totalarray['nbfield']++;
1102  }
1103  }
1104  // Address
1105  if (!empty($arrayfields['p.address']['checked'])) {
1106  print '<td>'.dol_escape_htmltag($obj->address).'</td>';
1107  if (!$i) {
1108  $totalarray['nbfield']++;
1109  }
1110  }
1111  // Zip
1112  if (!empty($arrayfields['p.zip']['checked'])) {
1113  print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
1114  if (!$i) {
1115  $totalarray['nbfield']++;
1116  }
1117  }
1118  // Town
1119  if (!empty($arrayfields['p.town']['checked'])) {
1120  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">'.dol_escape_htmltag($obj->town).'</td>';
1121  if (!$i) {
1122  $totalarray['nbfield']++;
1123  }
1124  }
1125  // State
1126  /*if (! empty($arrayfields['state.nom']['checked']))
1127  {
1128  print "<td>".$obj->state_name."</td>\n";
1129  if (! $i) $totalarray['nbfield']++;
1130  }
1131  // Region
1132  if (! empty($arrayfields['region.nom']['checked']))
1133  {
1134  print "<td>".$obj->region_name."</td>\n";
1135  if (! $i) $totalarray['nbfield']++;
1136  }*/
1137  // Country
1138  if (!empty($arrayfields['country.code_iso']['checked'])) {
1139  print '<td class="center">';
1140  $tmparray = getCountry($obj->fk_pays, 'all');
1141  print dol_escape_htmltag($tmparray['label']);
1142  print '</td>';
1143  if (!$i) {
1144  $totalarray['nbfield']++;
1145  }
1146  }
1147  // Phone
1148  if (!empty($arrayfields['p.phone']['checked'])) {
1149  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
1150  if (!$i) {
1151  $totalarray['nbfield']++;
1152  }
1153  }
1154  // Phone perso
1155  if (!empty($arrayfields['p.phone_perso']['checked'])) {
1156  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
1157  if (!$i) {
1158  $totalarray['nbfield']++;
1159  }
1160  }
1161  // Phone mobile
1162  if (!empty($arrayfields['p.phone_mobile']['checked'])) {
1163  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
1164  if (!$i) {
1165  $totalarray['nbfield']++;
1166  }
1167  }
1168  // Fax
1169  if (!empty($arrayfields['p.fax']['checked'])) {
1170  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
1171  if (!$i) {
1172  $totalarray['nbfield']++;
1173  }
1174  }
1175  // EMail
1176  if (!empty($arrayfields['p.email']['checked'])) {
1177  print '<td class="nowraponall tdoverflowmax300">'.dol_print_email($obj->email, $obj->rowid, $obj->socid, 'AC_EMAIL', 18, 0, 1).'</td>';
1178  if (!$i) {
1179  $totalarray['nbfield']++;
1180  }
1181  }
1182  // No EMail
1183  if (!empty($arrayfields['unsubscribed']['checked'])) {
1184  print '<td class="center">';
1185  if (empty($obj->email)) {
1186  //print '<span class="opacitymedium">'.$langs->trans("NoEmail").'</span>';
1187  } else {
1188  print yn(($obj->unsubscribed > 0) ? 1 : 0);
1189  }
1190  print '</td>';
1191  if (!$i) {
1192  $totalarray['nbfield']++;
1193  }
1194  }
1195  if (!empty($conf->socialnetworks->enabled)) {
1196  foreach ($socialnetworks as $key => $value) {
1197  if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
1198  print '<td class="tdoverflowmax100">'.dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks).'</td>';
1199  if (!$i) {
1200  $totalarray['nbfield']++;
1201  }
1202  }
1203  }
1204  }
1205  // Company
1206  if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
1207  print '<td class="tdoverflowmax200">';
1208  if ($obj->socid) {
1209  $objsoc = new Societe($db);
1210  $objsoc->fetch($obj->socid);
1211  print $objsoc->getNomUrl(1);
1212  } else {
1213  print '&nbsp;';
1214  }
1215  print '</td>';
1216  if (!$i) {
1217  $totalarray['nbfield']++;
1218  }
1219  }
1220 
1221  // Private/Public
1222  if (!empty($arrayfields['p.priv']['checked'])) {
1223  print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
1224  if (!$i) {
1225  $totalarray['nbfield']++;
1226  }
1227  }
1228 
1229  if (!empty($arrayfields['p.fk_prospectcontactlevel']['checked'])) {
1230  // Prospect level
1231  print '<td class="center">';
1232  print $contactstatic->getLibProspLevel();
1233  print "</td>";
1234  if (!$i) {
1235  $totalarray['nbfield']++;
1236  }
1237  }
1238 
1239  if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
1240  // Prospect status
1241  print '<td class="center nowrap"><div class="nowrap">';
1242  print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
1243  print '</div> - <div class="inline-block">';
1244  foreach ($contactstatic->cacheprospectstatus as $key => $val) {
1245  $titlealt = 'default';
1246  if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1247  $titlealt = $val['label'];
1248  }
1249  if ($obj->stcomm_id != $val['id']) {
1250  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>';
1251  }
1252  }
1253  print '</div></div></td>';
1254  if (!$i) {
1255  $totalarray['nbfield']++;
1256  }
1257  }
1258 
1259  // Extra fields
1260  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1261  // Fields from hook
1262  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1263  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1264  print $hookmanager->resPrint;
1265  // Date creation
1266  if (!empty($arrayfields['p.datec']['checked'])) {
1267  print '<td class="center nowraponall">';
1268  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1269  print '</td>';
1270  if (!$i) {
1271  $totalarray['nbfield']++;
1272  }
1273  }
1274  // Date modification
1275  if (!empty($arrayfields['p.tms']['checked'])) {
1276  print '<td class="center nowraponall">';
1277  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1278  print '</td>';
1279  if (!$i) {
1280  $totalarray['nbfield']++;
1281  }
1282  }
1283  // Status
1284  if (!empty($arrayfields['p.statut']['checked'])) {
1285  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1286  if (!$i) {
1287  $totalarray['nbfield']++;
1288  }
1289  }
1290  // Import key
1291  if (!empty($arrayfields['p.import_key']['checked'])) {
1292  print '<td class="tdoverflowmax100">';
1293  print dol_escape_htmltag($obj->import_key);
1294  print "</td>\n";
1295  if (!$i) {
1296  $totalarray['nbfield']++;
1297  }
1298  }
1299 
1300  // Action column
1301  print '<td class="nowrap center">';
1302  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1303  $selected = 0;
1304  if (in_array($obj->rowid, $arrayofselected)) {
1305  $selected = 1;
1306  }
1307  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1308  }
1309  print '</td>';
1310  if (!$i) {
1311  $totalarray['nbfield']++;
1312  }
1313 
1314  print "</tr>\n";
1315  $i++;
1316 }
1317 
1318 // Show total line
1319 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1320 
1321 // If no record found
1322 if ($num == 0) {
1323  $colspan = 1;
1324  foreach ($arrayfields as $key => $val) {
1325  if (!empty($val['checked'])) {
1326  $colspan++;
1327  }
1328  }
1329  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1330 }
1331 
1332 $db->free($resql);
1333 
1334 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1335 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1336 print $hookmanager->resPrint;
1337 
1338 print '</table>'."\n";
1339 print '</div>'."\n";
1340 
1341 print '</form>'."\n";
1342 
1343 // End of page
1344 llxFooter();
1345 $db->close();
GETPOST($paramname, $check= 'alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
yn($yesno, $case=1, $color=0)
Return yes or no in current language.
if($cancel &&!$id) if($action== 'add'&&!$cancel) if($action== 'delete') if($id) $form
Actions.
Definition: card.php:142
Class to manage contact/addresses.
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.
getArrayOfSocialNetworks()
Get array of social network dictionary.
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
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...
dol_getIdFromCode($db, $key, $tablename, $fieldkey= 'code', $fieldid= 'id', $entityfilter=0, $filters= '')
Return an id or code from a code or id.
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
img_action($titlealt, $numaction, $picto= '')
Show logo action.
Class to build HTML component for third parties management Only common components are here...
Class to manage standard extra fields.
setEventMessages($mesg, $mesgs, $style= 'mesgs', $messagekey= '')
Set event messages in dol_events session object.
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.
Class to manage generation of HTML components Only common components must be here.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form...
Class to manage third parties objects (customers, suppliers, prospects...)
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt= '', $morecss= '', $marginleftonlyshort=2)
Show picto whatever it&#39;s its name (generic function)
Classe permettant la generation de composants html autre Only common components are here...
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...
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.
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
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...
dol_print_date($time, $format= '', $tzoutput= 'auto', $outputlangs= '', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_error($db= '', $error= '', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
newToken()
Return the value of token currently saved into session with name &#39;newtoken&#39;.
isModEnabled($module)
Is Dolibarr module enabled.
llxFooter()
Empty footer.
Definition: wrapper.php:73
getCountry($searchkey, $withcode= '', $dbtouse=0, $outputlangs= '', $entconv=1, $searchlabel= '')
Return country label, code or id from an id, code or label.