dolibarr  20.0.0-alpha
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@free.fr>
13  * Copyright (C) 2019 Josep Lluís Amador <joseplluis@lliuretic.cat>
14  * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
15  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
16  * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
17  *
18  * This program is free software; you can redistribute it and/or modify
19  * it under the terms of the GNU General Public License as published by
20  * the Free Software Foundation; either version 3 of the License, or
21  * (at your option) any later version.
22  *
23  * This program is distributed in the hope that it will be useful,
24  * but WITHOUT ANY WARRANTY; without even the implied warranty of
25  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26  * GNU General Public License for more details.
27  *
28  * You should have received a copy of the GNU General Public License
29  * along with this program. If not, see <https://www.gnu.org/licenses/>.
30  */
31 
39 // Load Dolibarr environment
40 require '../main.inc.php';
41 require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
42 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
43 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45 
46 // Load translation files required by the page
47 $langs->loadLangs(array("companies", "suppliers", "categories"));
48 
49 $socialnetworks = getArrayOfSocialNetworks();
50 
51 // Get parameters
52 $action = GETPOST('action', 'aZ09');
53 $massaction = GETPOST('massaction', 'alpha');
54 $show_files = GETPOSTINT('show_files');
55 $confirm = GETPOST('confirm', 'alpha');
56 $toselect = GETPOST('toselect', 'array');
57 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contactlist';
58 $mode = GETPOST('mode', 'alpha');
59 
60 if ($contextpage == 'poslist') {
61  $optioncss = 'print';
62 }
63 
64 // Security check
65 $id = GETPOSTINT('id');
66 $contactid = GETPOSTINT('id');
67 $ref = ''; // There is no ref for contacts
68 if ($user->socid) {
69  $socid = $user->socid;
70 }
71 $result = restrictedArea($user, 'contact', $contactid, '');
72 
73 $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
74 $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
75 $search_phone = GETPOST("search_phone", 'alpha');
76 
77 $search_id = GETPOST("search_id", "intcomma");
78 $search_firstlast_only = GETPOST("search_firstlast_only", 'alpha');
79 $search_lastname = GETPOST("search_lastname", 'alpha');
80 $search_firstname = GETPOST("search_firstname", 'alpha');
81 $search_societe = GETPOST("search_societe", 'alpha');
82 $search_societe_alias = GETPOST("search_societe_alias", 'alpha');
83 $search_poste = GETPOST("search_poste", 'alpha');
84 $search_phone_perso = GETPOST("search_phone_perso", 'alpha');
85 $search_phone_pro = GETPOST("search_phone_pro", 'alpha');
86 $search_phone_mobile = GETPOST("search_phone_mobile", 'alpha');
87 $search_fax = GETPOST("search_fax", 'alpha');
88 $search_email = GETPOST("search_email", 'alpha');
89 if (isModEnabled('mailing')) {
90  $search_no_email = GETPOSTISSET("search_no_email") ? GETPOSTINT("search_no_email") : -1;
91 } else {
92  $search_no_email = -1;
93 }
94 
95 $search_ = array();
96 
97 if (isModEnabled('socialnetworks')) {
98  foreach ($socialnetworks as $key => $value) {
99  if ($value['active']) {
100  $search_[$key] = GETPOST("search_".$key, 'alpha');
101  }
102  }
103 }
104 $search_priv = GETPOST("search_priv", 'alpha');
105 $search_sale = GETPOST('search_sale', 'intcomma');
106 $search_categ = GETPOST("search_categ", 'intcomma');
107 $search_categ_thirdparty = GETPOST("search_categ_thirdparty", 'intcomma');
108 $search_categ_supplier = GETPOST("search_categ_supplier", 'intcomma');
109 $search_status = GETPOST("search_status", "intcomma");
110 $search_type = GETPOST('search_type', 'alpha');
111 $search_address = GETPOST('search_address', 'alpha');
112 $search_zip = GETPOST('search_zip', 'alpha');
113 $search_town = GETPOST('search_town', 'alpha');
114 $search_import_key = GETPOST("search_import_key", 'alpha');
115 $search_country = GETPOST("search_country", 'aZ09');
116 $search_roles = GETPOST("search_roles", 'array');
117 $search_level = GETPOST("search_level", 'array');
118 $search_stcomm = GETPOST('search_stcomm', 'intcomma');
119 $search_birthday_start = dol_mktime(0, 0, 0, GETPOSTINT('search_birthday_startmonth'), GETPOSTINT('search_birthday_startday'), GETPOSTINT('search_birthday_startyear'));
120 $search_birthday_end = dol_mktime(23, 59, 59, GETPOSTINT('search_birthday_endmonth'), GETPOSTINT('search_birthday_endday'), GETPOSTINT('search_birthday_endyear'));
121 
122 if ($search_status === '') {
123  $search_status = 1; // always display active customer first
124 }
125 if ($search_no_email === '') {
126  $search_no_email = -1;
127 }
128 
129 $optioncss = GETPOST('optioncss', 'alpha');
130 
131 $place = GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'; // $place is string id of table for Bar or Restaurant
132 
133 $type = GETPOST("type", 'aZ');
134 $view = GETPOST("view", 'alpha');
135 
136 $userid = GETPOSTINT('userid');
137 $begin = GETPOST('begin');
138 
139 // Load variable for pagination
140 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
141 $sortfield = GETPOST('sortfield', 'aZ09comma');
142 $sortorder = GETPOST('sortorder', 'aZ09comma');
143 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
144 if (!$sortorder) {
145  $sortorder = "ASC";
146 }
147 if (!$sortfield) {
148  $sortfield = "p.lastname";
149 }
150 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
151  // If $page is not defined, or '' or -1 or if we click on clear filters
152  $page = 0;
153 }
154 $offset = $limit * $page;
155 $pageprev = $page - 1;
156 $pagenext = $page + 1;
157 
158 
159 $title = (getDolGlobalString('SOCIETE_ADDRESSES_MANAGEMENT') ? $langs->trans("Contacts") : $langs->trans("ContactsAddresses"));
160 if ($type == "p") {
161  if (empty($contextpage) || $contextpage == 'contactlist') {
162  $contextpage = 'contactprospectlist';
163  }
164  $title .= ' ('.$langs->trans("ThirdPartyProspects").')';
165  $urlfiche = "card.php";
166 }
167 if ($type == "c") {
168  if (empty($contextpage) || $contextpage == 'contactlist') {
169  $contextpage = 'contactcustomerlist';
170  }
171  $title .= ' ('.$langs->trans("ThirdPartyCustomers").')';
172  $urlfiche = "card.php";
173 } elseif ($type == "f") {
174  if (empty($contextpage) || $contextpage == 'contactlist') {
175  $contextpage = 'contactsupplierlist';
176  }
177  $title .= ' ('.$langs->trans("ThirdPartySuppliers").')';
178  $urlfiche = "card.php";
179 } elseif ($type == "o") {
180  if (empty($contextpage) || $contextpage == 'contactlist') {
181  $contextpage = 'contactotherlist';
182  }
183  $title .= ' ('.$langs->trans("OthersNotLinkedToThirdParty").')';
184  $urlfiche = "";
185 }
186 
187 // Initialize technical object
188 $object = new Contact($db);
189 $extrafields = new ExtraFields($db);
190 $hookmanager->initHooks(array($contextpage));
191 
192 // fetch optionals attributes and labels
193 $extrafields->fetch_name_optionals_label($object->table_element);
194 
195 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
196 
197 // List of fields to search into when doing a "search in all"
198 $fieldstosearchall = array();
199 foreach ($object->fields as $key => $val) {
200  // don't allow search in private notes for external users when doing "search in all"
201  if (!empty($user->socid) && $key == "note_private") {
202  continue;
203  }
204 
205  if (empty($val['searchall'])) {
206  continue;
207  }
208 
209  $fieldstosearchall['p.'.$key] = $val['label'];
210 }
211 
212 // Add none object fields for "search in all"
213 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
214  $fieldstosearchall['s.nom'] = "ThirdParty";
215  $fieldstosearchall['s.name_alias'] = "AliasNames";
216 }
217 
218 $parameters = array('fieldstosearchall' => $fieldstosearchall);
219 $reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
220 if ($reshook > 0) {
221  $fieldstosearchall = empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall'];
222 } elseif ($reshook == 0) {
223  $fieldstosearchall = array_merge($fieldstosearchall, empty($hookmanager->resArray['fieldstosearchall']) ? array() : $hookmanager->resArray['fieldstosearchall']);
224 }
225 
226 // Definition of array of fields for columns
227 $arrayfields = array();
228 foreach ($object->fields as $key => $val) {
229  // If $val['visible']==0, then we never show the field
230  if (!empty($val['visible'])) {
231  $visible = (int) dol_eval($val['visible'], 1);
232  $arrayfields['p.'.$key] = array(
233  'label' => $val['label'],
234  'checked' => (($visible < 0) ? 0 : 1),
235  'enabled' => (abs($visible) != 3 && (int) dol_eval($val['enabled'], 1)),
236  'position' => $val['position'],
237  'help' => isset($val['help']) ? $val['help'] : ''
238  );
239  }
240 }
241 
242 // Add none object fields to fields for list
243 $arrayfields['country.code_iso'] = array('label' => "Country", 'position' => 66, 'checked' => 0);
244 if (!getDolGlobalString('SOCIETE_DISABLE_CONTACTS')) {
245  $arrayfields['s.nom'] = array('label' => "ThirdParty", 'position' => 113, 'checked' => 1);
246  $arrayfields['s.name_alias'] = array('label' => "AliasNameShort", 'position' => 114, 'checked' => 1);
247 }
248 
249 $arrayfields['unsubscribed'] = array(
250  'label' => 'No_Email',
251  'checked' => 0,
252  'enabled' => (isModEnabled('mailing')),
253  'position' => 111);
254 
255 if (isModEnabled('socialnetworks')) {
256  foreach ($socialnetworks as $key => $value) {
257  if ($value['active']) {
258  $arrayfields['p.'.$key] = array(
259  'label' => $value['label'],
260  'checked' => 0,
261  'position' => 300
262  );
263  }
264  }
265 }
266 
267 // Extra fields
268 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
269 
270 $object->fields = dol_sort_array($object->fields, 'position');
271 //$arrayfields['anotherfield'] = array('type'=>'integer', 'label'=>'AnotherField', 'checked'=>1, 'enabled'=>1, 'position'=>90, 'csslist'=>'right');
272 $arrayfields = dol_sort_array($arrayfields, 'position');
273 '@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
274 
275 
276 if (($id > 0 || !empty($ref)) && $action != 'add') {
277  $result = $object->fetch($id, $ref);
278  if ($result < 0) {
279  dol_print_error($db);
280  }
281 }
282 
283 $permissiontoread = $user->hasRight('societe', 'lire');
284 $permissiontodelete = $user->hasRight('societe', 'supprimer');
285 $permissiontoadd = $user->hasRight('societe', 'creer');
286 
287 if (!$permissiontoread) {
288  accessforbidden();
289 }
290 
291 
292 /*
293  * Actions
294  */
295 
296 if ($action == "change" && $user->hasRight('takepos', 'run')) { // Change customer for TakePOS
297  $idcustomer = GETPOSTINT('idcustomer');
298  $idcontact = GETPOSTINT('idcontact');
299 
300  // Check if draft invoice already exists, if not create it
301  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' AND entity IN (".getEntity('invoice').")";
302  $result = $db->query($sql);
303  $num_lines = $db->num_rows($result);
304  if ($num_lines == 0) {
305  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
306  $invoice = new Facture($db);
307  $constforthirdpartyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
308  $invoice->socid = getDolGlobalInt($constforthirdpartyid);
309  $invoice->date = dol_now();
310  $invoice->module_source = 'takepos';
311  $invoice->pos_source = $_SESSION["takeposterminal"];
312  $placeid = $invoice->create($user);
313  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
314  $db->query($sql);
315  }
316 
317  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".((int) $idcustomer)." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
318  $resql = $db->query($sql);
319 
320  // set contact on invoice
321  if (!isset($invoice)) {
322  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
323  $invoice = new Facture($db);
324  $invoice->fetch(null, "(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")");
325  $invoice->delete_linked_contact('external', 'BILLING');
326  }
327  $invoice->add_contact($idcontact, 'BILLING'); ?>
328  <script>
329  console.log("Reload page invoice.php with place=<?php print $place; ?>");
330  parent.$("#poslines").load("invoice.php?place=<?php print $place; ?>", function() {
331  //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
332  <?php if (!$resql) { ?>
333  alert('Error failed to update customer on draft invoice.');
334  <?php } ?>
335  parent.$("#idcustomer").val(<?php echo $idcustomer; ?>);
336  parent.$.colorbox.close(); /* Close the popup */
337  });
338  </script>
339  <?php
340  exit;
341 }
342 
343 if (GETPOST('cancel', 'alpha')) {
344  $action = 'list';
345  $massaction = '';
346 }
347 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
348  $massaction = '';
349 }
350 
351 $parameters = array('arrayfields' => &$arrayfields);
352 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
353 if ($reshook < 0) {
354  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
355 }
356 
357 if (empty($reshook)) {
358  // Selection of new fields
359  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
360 
361  // Purge search criteria
362  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
363  $search_all = "";
364  $search_id = '';
365  $search_firstlast_only = "";
366  $search_lastname = "";
367  $search_firstname = "";
368  $search_societe = "";
369  $search_societe_alias = "";
370  $search_town = "";
371  $search_address = "";
372  $search_zip = "";
373  $search_country = "";
374  $search_poste = "";
375  $search_phone = "";
376  $search_phone_perso = "";
377  $search_phone_pro = "";
378  $search_phone_mobile = "";
379  $search_fax = "";
380  $search_email = "";
381  $search_no_email = -1;
382  if (isModEnabled('socialnetworks')) {
383  foreach ($socialnetworks as $key => $value) {
384  if ($value['active']) {
385  $search_[$key] = "";
386  }
387  }
388  }
389  $search_priv = "";
390  $search_stcomm = '';
391  $search_level = '';
392  $search_status = -1;
393  $search_sale = '';
394  $search_categ = '';
395  $search_categ_thirdparty = '';
396  $search_categ_supplier = '';
397  $search_import_key = '';
398  $toselect = array();
399  $search_array_options = array();
400  $search_roles = array();
401  $search_birthday_start = '';
402  $search_birthday_end = '';
403  }
404 
405  // Mass actions
406  $objectclass = 'Contact';
407  $objectlabel = 'Contact';
408  $uploaddir = $conf->societe->dir_output;
409  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
410 
411  if ($action == 'setstcomm') {
412  $object = new Contact($db);
413  $result = $object->fetch(GETPOST('stcommcontactid'));
414  $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcommcontact');
415  $result = $object->update($object->id, $user);
416  if ($result < 0) {
417  setEventMessages($object->error, $object->errors, 'errors');
418  }
419 
420  $action = '';
421  }
422 }
423 
424 if ($search_priv < 0) {
425  $search_priv = '';
426 }
427 // the user has not right to see other third-party than their own
428 if (!$user->hasRight('societe', 'client', 'voir')) {
429  $search_sale = $user->id;
430 }
431 
432 
433 /*
434  * View
435  */
436 
437 $form = new Form($db);
438 $formother = new FormOther($db);
439 $formcompany = new FormCompany($db);
440 $contactstatic = new Contact($db);
441 
442 $now = dol_now();
443 
444 $title = $langs->trans("Contacts")." - ".$langs->trans("List");
445 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:M&oacute;dulo_Empresas';
446 $morejs = array();
447 $morecss = array();
448 
449 if (getDolGlobalString('THIRDPARTY_ENABLE_PROSPECTION_ON_ALTERNATIVE_ADRESSES')) {
450  $contactstatic->loadCacheOfProspStatus();
451 }
452 
453 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
454 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
455 
456 // Select every potentials, and note each potentials which fit in search parameters
457 $tab_level = array();
458 $sql = "SELECT code, label, sortorder";
459 $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectcontactlevel";
460 $sql .= " WHERE active > 0";
461 $sql .= " ORDER BY sortorder";
462 $resql = $db->query($sql);
463 if ($resql) {
464  while ($obj = $db->fetch_object($resql)) {
465  // Compute level text
466  $level = $langs->trans($obj->code);
467  if ($level == $obj->code) {
468  $level = $langs->trans($obj->label);
469  }
470  $tab_level[$obj->code] = $level;
471  }
472 } else {
473  dol_print_error($db);
474 }
475 
476 // Build and execute select
477 // --------------------------------------------------------------------
478 $sql = "SELECT s.rowid as socid, s.nom as name, s.name_alias as alias,";
479 $sql .= " p.rowid, p.lastname as lastname, p.statut, p.firstname, p.address, p.zip, p.town, p.poste, p.email, p.birthday,";
480 $sql .= " p.socialnetworks, p.photo,";
481 $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_modification,";
482 $sql .= " p.import_key, p.fk_stcommcontact as stcomm_id, p.fk_prospectlevel,";
483 $sql .= " st.libelle as stcomm, st.picto as stcomm_picto,";
484 $sql .= " co.label as country, co.code as country_code";
485 // Add fields from extrafields
486 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
487  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
488  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
489  }
490 }
491 if (isModEnabled('mailing')) {
492  $sql .= ", (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) as unsubscribed";
493 }
494 
495 // Add fields from hooks
496 $parameters = array();
497 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
498 $sql .= $hookmanager->resPrint;
499 $sql = preg_replace('/,\s*$/', '', $sql);
500 
501 $sqlfields = $sql; // $sql fields to remove for count total
502 
503 $sql .= " FROM ".MAIN_DB_PREFIX."socpeople as p";
504 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
505  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
506 }
507 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as co ON co.rowid = p.fk_pays";
508 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s ON s.rowid = p.fk_soc";
509 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_stcommcontact as st ON st.id = p.fk_stcommcontact";
510 
511 // Add fields from hooks - ListFrom
512 $parameters = array();
513 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
514 $sql .= $hookmanager->resPrint;
515 $sql .= ' WHERE p.entity IN ('.getEntity('contact').')';
516 if (!empty($userid)) { // propre au commercial
517  $sql .= " AND p.fk_user_creat=".((int) $userid);
518 }
519 if ($search_level) {
520  $sql .= natural_search("p.fk_prospectlevel", implode(',', $search_level), 3);
521 }
522 if ($search_stcomm != '' && $search_stcomm != -2) {
523  $sql .= natural_search("p.fk_stcommcontact", $search_stcomm, 2);
524 }
525 
526 // Filter to exclude not owned private contacts
527 if ($search_priv != '0' && $search_priv != '1') {
528  $sql .= " AND (p.priv='0' OR (p.priv='1' AND p.fk_user_creat=".((int) $user->id)."))";
529 } else {
530  if ($search_priv == '0') {
531  $sql .= " AND p.priv='0'";
532  }
533  if ($search_priv == '1') {
534  $sql .= " AND (p.priv='1' AND p.fk_user_creat=".((int) $user->id).")";
535  }
536 }
537 
538 // Search on sale representative
539 if (!empty($search_sale) && $search_sale != '-1') {
540  if ($search_sale == -2) {
541  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc)";
542  } elseif ($search_sale > 0) {
543  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".$db->prefix()."societe_commerciaux as sc WHERE sc.fk_soc = p.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
544  }
545 }
546 
547 // Search Contact Categories
548 $searchCategoryContactList = $search_categ ? array($search_categ) : array();
549 $searchCategoryContactOperator = 0;
550 // Search for tag/category ($searchCategoryContactList is an array of ID)
551 if (!empty($searchCategoryContactList)) {
552  $searchCategoryContactSqlList = array();
553  $listofcategoryid = '';
554  foreach ($searchCategoryContactList as $searchCategoryContact) {
555  if (intval($searchCategoryContact) == -2) {
556  $searchCategoryContactSqlList[] = "NOT EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople)";
557  } elseif (intval($searchCategoryContact) > 0) {
558  if ($searchCategoryContactOperator == 0) {
559  $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie = ".((int) $searchCategoryContact).")";
560  } else {
561  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryContact);
562  }
563  }
564  }
565  if ($listofcategoryid) {
566  $searchCategoryContactSqlList[] = " EXISTS (SELECT ck.fk_socpeople FROM ".MAIN_DB_PREFIX."categorie_contact as ck WHERE p.rowid = ck.fk_socpeople AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
567  }
568  if ($searchCategoryContactOperator == 1) {
569  if (!empty($searchCategoryContactSqlList)) {
570  $sql .= " AND (".implode(' OR ', $searchCategoryContactSqlList).")";
571  }
572  } else {
573  if (!empty($searchCategoryContactSqlList)) {
574  $sql .= " AND (".implode(' AND ', $searchCategoryContactSqlList).")";
575  }
576  }
577 }
578 
579 // Search Customer Categories
580 $searchCategoryCustomerList = $search_categ_thirdparty ? array($search_categ_thirdparty) : array();
581 $searchCategoryCustomerOperator = 0;
582 // Search for tag/category ($searchCategoryCustomerList is an array of ID)
583 if (!empty($searchCategoryCustomerList)) {
584  $searchCategoryCustomerSqlList = array();
585  $listofcategoryid = '';
586  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
587  if (intval($searchCategoryCustomer) == -2) {
588  $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
589  } elseif (intval($searchCategoryCustomer) > 0) {
590  if ($searchCategoryCustomerOperator == 0) {
591  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategoryCustomer).")";
592  } else {
593  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
594  }
595  }
596  }
597  if ($listofcategoryid) {
598  $searchCategoryCustomerSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
599  }
600  if ($searchCategoryCustomerOperator == 1) {
601  if (!empty($searchCategoryCustomerSqlList)) {
602  $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
603  }
604  } else {
605  if (!empty($searchCategoryCustomerSqlList)) {
606  $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
607  }
608  }
609 }
610 
611 // Search Supplier Categories
612 $searchCategorySupplierList = $search_categ_supplier ? array($search_categ_supplier) : array();
613 $searchCategorySupplierOperator = 0;
614 // Search for tag/category ($searchCategorySupplierList is an array of ID)
615 if (!empty($searchCategorySupplierList)) {
616  $searchCategorySupplierSqlList = array();
617  $listofcategoryid = '';
618  foreach ($searchCategorySupplierList as $searchCategorySupplier) {
619  if (intval($searchCategorySupplier) == -2) {
620  $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
621  } elseif (intval($searchCategorySupplier) > 0) {
622  if ($searchCategorySupplierOperator == 0) {
623  $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
624  } else {
625  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
626  }
627  }
628  }
629  if ($listofcategoryid) {
630  $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
631  }
632  if ($searchCategorySupplierOperator == 1) {
633  if (!empty($searchCategorySupplierSqlList)) {
634  $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
635  }
636  } else {
637  if (!empty($searchCategorySupplierSqlList)) {
638  $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
639  }
640  }
641 }
642 
643 if ($search_all) {
644  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
645 }
646 if (strlen($search_phone)) {
647  $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_phone);
648 }
649 if (strlen($search_cti)) {
650  $sql .= natural_search(array('p.phone', 'p.phone_perso', 'p.phone_mobile'), $search_cti);
651 }
652 if (strlen($search_firstlast_only)) {
653  $sql .= natural_search(array('p.lastname', 'p.firstname'), $search_firstlast_only);
654 }
655 
656 if ($search_id > 0) {
657  $sql .= natural_search('p.rowid', $search_id, 1);
658 }
659 if ($search_lastname) {
660  $sql .= natural_search('p.lastname', $search_lastname);
661 }
662 if ($search_firstname) {
663  $sql .= natural_search('p.firstname', $search_firstname);
664 }
665 if (empty($arrayfields['s.name_alias']['checked']) && $search_societe) {
666  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_societe);
667 } else {
668  if ($search_societe) {
669  $sql .= natural_search('s.nom', $search_societe);
670  }
671  if ($search_societe_alias) {
672  $sql .= natural_search('s.name_alias', $search_societe_alias);
673  }
674 }
675 if ($search_country) {
676  $sql .= " AND p.fk_pays IN (".$db->sanitize($search_country).')';
677 }
678 if (strlen($search_poste)) {
679  $sql .= natural_search('p.poste', $search_poste);
680 }
681 if (strlen($search_phone_perso)) {
682  $sql .= natural_search('p.phone_perso', $search_phone_perso);
683 }
684 if (strlen($search_phone_pro)) {
685  $sql .= natural_search('p.phone', $search_phone_pro);
686 }
687 if (strlen($search_phone_mobile)) {
688  $sql .= natural_search('p.phone_mobile', $search_phone_mobile);
689 }
690 if (strlen($search_fax)) {
691  $sql .= natural_search('p.fax', $search_fax);
692 }
693 if (isModEnabled('socialnetworks')) {
694  foreach ($socialnetworks as $key => $value) {
695  if ($value['active'] && strlen($search_[$key])) {
696  $searchkeyinjsonformat = preg_replace('/"$/', '', preg_replace('/^"/', '', json_encode($search_[$key])));
697  if (in_array($db->type, array('mysql', 'mysqli'))) {
698  $sql .= " AND p.socialnetworks REGEXP '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
699  } elseif ($db->type == 'pgsql') {
700  $sql .= " AND p.socialnetworks ~ '\"".$db->escape($db->escapeforlike($key))."\":\"[^\"]*".$db->escape($db->escapeforlike($searchkeyinjsonformat))."'";
701  } else {
702  // Works with all database but not reliable because search only for social network code starting with earched value
703  $sql .= " AND p.socialnetworks LIKE '%\"".$db->escape($db->escapeforlike($key))."\":\"".$db->escape($db->escapeforlike($searchkeyinjsonformat))."%'";
704  }
705  }
706  }
707 }
708 //print $sql;
709 
710 if (strlen($search_email)) {
711  $sql .= natural_search('p.email', $search_email);
712 }
713 if (strlen($search_address)) {
714  $sql .= natural_search("p.address", $search_address);
715 }
716 if (strlen($search_zip)) {
717  $sql .= natural_search("p.zip", $search_zip);
718 }
719 if (strlen($search_town)) {
720  $sql .= natural_search("p.town", $search_town);
721 }
722 if (count($search_roles) > 0) {
723  $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))."))";
724 }
725 if ($search_no_email != -1 && $search_no_email > 0) {
726  $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) > 0";
727 }
728 if ($search_no_email != -1 && $search_no_email == 0) {
729  $sql .= " AND (SELECT count(*) FROM ".MAIN_DB_PREFIX."mailing_unsubscribe WHERE email = p.email) = 0 AND p.email IS NOT NULL AND p.email <> ''";
730 }
731 if ($search_status != '' && $search_status >= 0) {
732  $sql .= " AND p.statut = ".((int) $search_status);
733 }
734 if ($search_import_key) {
735  $sql .= natural_search("p.import_key", $search_import_key);
736 }
737 if ($type == "o") { // filter on type
738  $sql .= " AND p.fk_soc IS NULL";
739 } elseif ($type == "f") { // filter on type
740  $sql .= " AND s.fournisseur = 1";
741 } elseif ($type == "c") { // filter on type
742  $sql .= " AND s.client IN (1, 3)";
743 } elseif ($type == "p") { // filter on type
744  $sql .= " AND s.client IN (2, 3)";
745 }
746 if (!empty($socid)) {
747  $sql .= " AND s.rowid = ".((int) $socid);
748 }
749 if ($search_birthday_start) {
750  $sql .= " AND p.birthday >= '".$db->idate($search_birthday_start)."'";
751 }
752 if ($search_birthday_end) {
753  $sql .= " AND p.birthday <= '".$db->idate($search_birthday_end)."'";
754 }
755 
756 // Add where from extra fields
757 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
758 
759 // Add where from hooks
760 $parameters = array();
761 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
762 $sql .= $hookmanager->resPrint;
763 //print $sql;
764 
765 // Add GroupBy from hooks
766 $parameters = array('fieldstosearchall' => $fieldstosearchall);
767 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
768 $sql .= $hookmanager->resPrint;
769 
770 // Count total nb of records
771 $nbtotalofrecords = '';
772 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
773  /* The fast and low memory method to get and count full list converts the sql into a sql count */
774  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
775  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
776  $resql = $db->query($sqlforcount);
777  if ($resql) {
778  $objforcount = $db->fetch_object($resql);
779  $nbtotalofrecords = $objforcount->nbtotalofrecords;
780  } else {
781  dol_print_error($db);
782  }
783 
784  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
785  $page = 0;
786  $offset = 0;
787  }
788  $db->free($resql);
789 }
790 
791 // Complete request and execute it with limit
792 if ($view == "recent") {
793  $sql .= $db->order("p.datec", "DESC");
794 } else {
795  $sql .= $db->order($sortfield, $sortorder);
796 }
797 if ($limit) {
798  $sql .= $db->plimit($limit + 1, $offset);
799 }
800 
801 $resql = $db->query($sql);
802 if (!$resql) {
803  dol_print_error($db);
804  exit;
805 }
806 
807 $num = $db->num_rows($resql);
808 
809 // Direct jump if only one record found
810 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && ($search_all != '' || $search_cti != '') && !$page) {
811  $obj = $db->fetch_object($resql);
812  $id = $obj->rowid;
813  header("Location: ".DOL_URL_ROOT.'/contact/card.php?id='.$id);
814  exit;
815 }
816 
817 
818 // Output page
819 // --------------------------------------------------------------------
820 
821 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
822 
823 $arrayofselected = is_array($toselect) ? $toselect : array();
824 
825 $param = '';
826 if (!empty($mode)) {
827  $param .= '&mode='.urlencode($mode);
828 }
829 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
830  $param .= '&contextpage='.urlencode($contextpage);
831 }
832 if ($limit > 0 && $limit != $conf->liste_limit) {
833  $param .= '&limit='.((int) $limit);
834 }
835 if ($optioncss != '') {
836  $param .= '&optioncss='.urlencode($optioncss);
837 }
838 $param .= '&begin='.urlencode((string) ($begin)).'&userid='.urlencode((string) ($userid)).'&contactname='.urlencode((string) ($search_all));
839 $param .= '&type='.urlencode($type).'&view='.urlencode($view);
840 if (!empty($search_sale) && $search_sale != '-1') {
841  $param .= '&search_sale='.urlencode($search_sale);
842 }
843 if (!empty($search_categ) && $search_categ != '-1') {
844  $param .= '&search_categ='.urlencode((string) ($search_categ));
845 }
846 if (!empty($search_categ_thirdparty) && $search_categ_thirdparty != '-1') {
847  $param .= '&search_categ_thirdparty='.urlencode((string) ($search_categ_thirdparty));
848 }
849 if (!empty($search_categ_supplier) && $search_categ_supplier != '-1') {
850  $param .= '&search_categ_supplier='.urlencode((string) ($search_categ_supplier));
851 }
852 if ($search_all != '') {
853  $param .= '&search_all='.urlencode($search_all);
854 }
855 if ($search_id > 0) {
856  $param .= "&search_id=".urlencode((string) ($search_id));
857 }
858 if ($search_lastname != '') {
859  $param .= '&search_lastname='.urlencode($search_lastname);
860 }
861 if ($search_firstname != '') {
862  $param .= '&search_firstname='.urlencode($search_firstname);
863 }
864 if ($search_societe != '') {
865  $param .= '&search_societe='.urlencode($search_societe);
866 }
867 if ($search_societe_alias != '') {
868  $param .= '&search_societe_alias='.urlencode($search_societe_alias);
869 }
870 if ($search_address != '') {
871  $param .= '&search_address='.urlencode($search_address);
872 }
873 if ($search_zip != '') {
874  $param .= '&search_zip='.urlencode($search_zip);
875 }
876 if ($search_town != '') {
877  $param .= '&search_town='.urlencode($search_town);
878 }
879 if ($search_country != '') {
880  $param .= "&search_country=".urlencode($search_country);
881 }
882 if ($search_poste != '') {
883  $param .= '&search_poste='.urlencode($search_poste);
884 }
885 if ($search_phone_pro != '') {
886  $param .= '&search_phone_pro='.urlencode($search_phone_pro);
887 }
888 if ($search_phone_perso != '') {
889  $param .= '&search_phone_perso='.urlencode($search_phone_perso);
890 }
891 if ($search_phone_mobile != '') {
892  $param .= '&search_phone_mobile='.urlencode($search_phone_mobile);
893 }
894 if ($search_fax != '') {
895  $param .= '&search_fax='.urlencode($search_fax);
896 }
897 if ($search_email != '') {
898  $param .= '&search_email='.urlencode($search_email);
899 }
900 if ($search_no_email != '') {
901  $param .= '&search_no_email='.urlencode((string) ($search_no_email));
902 }
903 if ($search_status != '') {
904  $param .= '&search_status='.urlencode((string) ($search_status));
905 }
906 if ($search_priv == '0' || $search_priv == '1') {
907  $param .= "&search_priv=".urlencode($search_priv);
908 }
909 if ($search_stcomm != '') {
910  $param .= '&search_stcomm='.urlencode((string) ($search_stcomm));
911 }
912 if (is_array($search_level) && count($search_level)) {
913  foreach ($search_level as $slevel) {
914  $param .= '&search_level[]='.urlencode($slevel);
915  }
916 }
917 if ($search_import_key != '') {
918  $param .= '&search_import_key='.urlencode($search_import_key);
919 }
920 if (count($search_roles) > 0) {
921  $param .= implode('&search_roles[]=', $search_roles);
922 }
923 if ($search_birthday_start) {
924  $param .= '&search_birthday_start='.urlencode(dol_print_date($search_birthday_start, '%d')).'&search_birthday_startmonth='.urlencode(dol_print_date($search_birthday_start, '%m')).'&search_birthday_startyear='.urlencode(dol_print_date($search_birthday_start, '%Y'));
925 }
926 if ($search_birthday_end) {
927  $param .= '&search_birthday_end='.urlencode(dol_print_date($search_birthday_end, '%d')).'&search_birthday_endmonth='.urlencode(dol_print_date($search_birthday_end, '%m')).'&search_birthday_endyear='.urlencode(dol_print_date($search_birthday_end, '%Y'));
928 }
929 // Add $param from extra fields
930 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
931 
932 // List of mass actions available
933 $arrayofmassactions = array(
934  'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
935 // 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
936 );
937 //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
938 if (!empty($permissiontodelete)) {
939  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
940 }
941 if (isModEnabled('category') && $user->hasRight('societe', 'creer')) {
942  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
943 }
944 if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete','preaffecttag'))) {
945  $arrayofmassactions = array();
946 }
947 
948 $massactionbutton = '';
949 if ($contextpage != 'poslist') {
950  $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
951 }
952 
953 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter">';
954 if ($optioncss != '') {
955  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
956 }
957 print '<input type="hidden" name="token" value="'.newToken().'">';
958 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
959 print '<input type="hidden" name="view" value="'.dol_escape_htmltag($view).'">';
960 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
961 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
962 //print '<input type="hidden" name="page" value="'.$page.'">';
963 print '<input type="hidden" name="type" value="'.$type.'">';
964 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
965 print '<input type="hidden" name="page_y" value="">';
966 print '<input type="hidden" name="mode" value="'.$mode.'">';
967 
968 
969 $newcardbutton = '';
970 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss' => 'reposition'));
971 $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss' => 'reposition'));
972 $newcardbutton .= dolGetButtonTitleSeparator();
973 if ($contextpage != 'poslist') {
974  $newcardbutton .= dolGetButtonTitle($langs->trans('NewContactAddress'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/contact/card.php?action=create', '', $permissiontoadd);
975 } elseif ($user->hasRight('societe', 'contact', 'creer')) {
976  $url = DOL_URL_ROOT . '/contact/card.php?action=create&type=t&contextpage=poslist&optioncss=print&backtopage=' . urlencode($_SERVER["PHP_SELF"] . '?token=' . newToken() . 'type=t&contextpage=poslist&nomassaction=1&optioncss=print&place='.$place);
977  $label = 'MenuNewCustomer';
978  $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url);
979 }
980 
981 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'address', 0, $newcardbutton, '', $limit, 0, 0, 1);
982 
983 $topicmail = "Information";
984 $modelmail = "contact";
985 $objecttmp = new Contact($db);
986 $trackid = 'ctc'.$object->id;
987 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
988 
989 if ($search_all) {
990  $setupstring = '';
991  foreach ($fieldstosearchall as $key => $val) {
992  $fieldstosearchall[$key] = $langs->trans($val);
993  $setupstring .= $key."=".$val.";";
994  }
995  print '<!-- Search done like if CONTACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
996  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
997 }
998 if ($search_firstlast_only) {
999  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_firstlast_only).$langs->trans("Lastname").", ".$langs->trans("Firstname").'</div>';
1000 }
1001 
1002 $moreforfilter = '';
1003 
1004 // If the user can view third-party other than their own
1005 if ($user->hasRight('societe', 'client', 'voir')) {
1006  $langs->load('commercial');
1007  $moreforfilter .= '<div class="divsearchfield">';
1008  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
1009  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250 widthcentpercentminusx', 1);
1010  $moreforfilter .= '</div>';
1011 }
1012 
1013 if (isModEnabled('category') && $user->hasRight('categorie', 'lire')) {
1014  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1015  $moreforfilter .= '<div class="divsearchfield">';
1016  $tmptitle = $langs->trans('ContactCategoriesShort');
1017  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1018  $moreforfilter .= $formother->select_categories(Categorie::TYPE_CONTACT, $search_categ, 'search_categ', 1, $tmptitle);
1019  $moreforfilter .= '</div>';
1020  if (empty($type) || $type == 'c' || $type == 'p') {
1021  $moreforfilter .= '<div class="divsearchfield">';
1022  $tmptitle = '';
1023  if ($type == 'c') {
1024  $tmptitle .= $langs->trans('CustomersCategoriesShort');
1025  } elseif ($type == 'p') {
1026  $tmptitle .= $langs->trans('ProspectsCategoriesShort');
1027  } else {
1028  $tmptitle .= $langs->trans('CustomersProspectsCategoriesShort');
1029  }
1030  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1031  $moreforfilter .= $formother->select_categories(Categorie::TYPE_CUSTOMER, $search_categ_thirdparty, 'search_categ_thirdparty', 1, $tmptitle);
1032  $moreforfilter .= '</div>';
1033  }
1034 
1035  if (isModEnabled("fournisseur") && (empty($type) || $type == 'f')) {
1036  $moreforfilter .= '<div class="divsearchfield">';
1037  $tmptitle = $langs->trans('SuppliersCategoriesShort');
1038  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
1039  $moreforfilter .= $formother->select_categories(Categorie::TYPE_SUPPLIER, $search_categ_supplier, 'search_categ_supplier', 1, $tmptitle);
1040  $moreforfilter .= '</div>';
1041  }
1042 }
1043 
1044 $moreforfilter .= '<div class="divsearchfield">';
1045 $moreforfilter .= $langs->trans('Roles').': ';
1046 $moreforfilter .= $formcompany->showRoles("search_roles", $objecttmp, 'edit', $search_roles);
1047 $moreforfilter .= '</div>';
1048 
1049 print '<div class="liste_titre liste_titre_bydiv centpercent">';
1050 print $moreforfilter;
1051 $parameters = array('type' => $type);
1052 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1053 print $hookmanager->resPrint;
1054 print '</div>';
1055 
1056 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1057 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
1058 $selectedfields .= ((count($arrayofmassactions) && $contextpage != 'poslist') ? $form->showCheckAddButtons('checkforselect', 1) : '');
1059 
1060 print '<div class="div-table-responsive">';
1061 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1062 
1063 // Fields title search
1064 // --------------------------------------------------------------------
1065 print '<tr class="liste_titre_filter">';
1066 // Action column
1067 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1068  print '<td class="liste_titre center maxwidthsearch actioncolumn">';
1069  $searchpicto = $form->showFilterButtons('left');
1070  print $searchpicto;
1071  print '</td>';
1072 }
1073 if (!empty($arrayfields['p.rowid']['checked'])) {
1074  print '<td class="liste_titre">';
1075  print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
1076  print '</td>';
1077 }
1078 if (!empty($arrayfields['p.lastname']['checked'])) {
1079  print '<td class="liste_titre">';
1080  print '<input class="flat" type="text" name="search_lastname" size="6" value="'.dol_escape_htmltag($search_lastname).'">';
1081  print '</td>';
1082 }
1083 if (!empty($arrayfields['p.firstname']['checked'])) {
1084  print '<td class="liste_titre">';
1085  print '<input class="flat" type="text" name="search_firstname" size="6" value="'.dol_escape_htmltag($search_firstname).'">';
1086  print '</td>';
1087 }
1088 if (!empty($arrayfields['p.poste']['checked'])) {
1089  print '<td class="liste_titre">';
1090  print '<input class="flat" type="text" name="search_poste" size="5" value="'.dol_escape_htmltag($search_poste).'">';
1091  print '</td>';
1092 }
1093 if (!empty($arrayfields['p.address']['checked'])) {
1094  print '<td class="liste_titre">';
1095  print '<input class="flat" type="text" name="search_address" size="6" value="'.dol_escape_htmltag($search_address).'">';
1096  print '</td>';
1097 }
1098 if (!empty($arrayfields['p.zip']['checked'])) {
1099  print '<td class="liste_titre">';
1100  print '<input class="flat" type="text" name="search_zip" size="3" value="'.dol_escape_htmltag($search_zip).'">';
1101  print '</td>';
1102 }
1103 if (!empty($arrayfields['p.town']['checked'])) {
1104  print '<td class="liste_titre">';
1105  print '<input class="flat" type="text" name="search_town" size="5" value="'.dol_escape_htmltag($search_town).'">';
1106  print '</td>';
1107 }
1108 
1109 /*
1110 // State
1111  if (!empty($arrayfields['state.nom']['checked']))
1112  {
1113  print '<td class="liste_titre">';
1114  print '<input class="flat searchstring" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1115  print '</td>';
1116  }
1117 
1118  // Region
1119  if (!empty($arrayfields['region.nom']['checked']))
1120  {
1121  print '<td class="liste_titre">';
1122  print '<input class="flat searchstring" size="4" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
1123  print '</td>';
1124  }
1125 */
1126 
1127 // Country
1128 if (!empty($arrayfields['country.code_iso']['checked'])) {
1129  print '<td class="liste_titre center">';
1130  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1131  print '</td>';
1132 }
1133 if (!empty($arrayfields['p.phone']['checked'])) {
1134  print '<td class="liste_titre">';
1135  print '<input class="flat" type="text" name="search_phone_pro" size="6" value="'.dol_escape_htmltag($search_phone_pro).'">';
1136  print '</td>';
1137 }
1138 if (!empty($arrayfields['p.phone_perso']['checked'])) {
1139  print '<td class="liste_titre">';
1140  print '<input class="flat" type="text" name="search_phone_perso" size="6" value="'.dol_escape_htmltag($search_phone_perso).'">';
1141  print '</td>';
1142 }
1143 if (!empty($arrayfields['p.phone_mobile']['checked'])) {
1144  print '<td class="liste_titre">';
1145  print '<input class="flat" type="text" name="search_phone_mobile" size="6" value="'.dol_escape_htmltag($search_phone_mobile).'">';
1146  print '</td>';
1147 }
1148 if (!empty($arrayfields['p.fax']['checked'])) {
1149  print '<td class="liste_titre">';
1150  print '<input class="flat" type="text" name="search_fax" size="6" value="'.dol_escape_htmltag($search_fax).'">';
1151  print '</td>';
1152 }
1153 if (!empty($arrayfields['p.email']['checked'])) {
1154  print '<td class="liste_titre">';
1155  print '<input class="flat" type="text" name="search_email" size="6" value="'.dol_escape_htmltag($search_email).'">';
1156  print '</td>';
1157 }
1158 if (!empty($arrayfields['unsubscribed']['checked'])) {
1159  print '<td class="liste_titre center">';
1160  print $form->selectarray('search_no_email', array('-1' => '', '0' => $langs->trans('No'), '1' => $langs->trans('Yes')), $search_no_email);
1161  print '</td>';
1162 }
1163 if (isModEnabled('socialnetworks')) {
1164  foreach ($socialnetworks as $key => $value) {
1165  if ($value['active']) {
1166  if (!empty($arrayfields['p.'.$key]['checked'])) {
1167  print '<td class="liste_titre">';
1168  print '<input class="flat" type="text" name="search_'.$key.'" size="6" value="'.dol_escape_htmltag($search_[$key]).'">';
1169  print '</td>';
1170  }
1171  }
1172  }
1173 }
1174 if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
1175  print '<td class="liste_titre">';
1176  print '<input class="flat" type="text" name="search_societe" size="8" value="'.dol_escape_htmltag($search_societe).'">';
1177  print '</td>';
1178 }
1179 // Alias of ThirdParty
1180 if (!empty($arrayfields['s.name_alias']['checked'])) {
1181  print '<td class="liste_titre" align="left">';
1182  print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
1183  print '</td>';
1184 }
1185 if (!empty($arrayfields['p.priv']['checked'])) {
1186  print '<td class="liste_titre center">';
1187  $selectarray = array('0' => $langs->trans("ContactPublic"), '1' => $langs->trans("ContactPrivate"));
1188  print $form->selectarray('search_priv', $selectarray, $search_priv, 1);
1189  print '</td>';
1190 }
1191 // Prospect level
1192 if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
1193  print '<td class="liste_titre center">';
1194  print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
1195  print '</td>';
1196 }
1197 // Prospect status
1198 if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
1199  print '<td class="liste_titre maxwidthonsmartphone center">';
1200  $arraystcomm = array();
1201  foreach ($contactstatic->cacheprospectstatus as $key => $val) {
1202  $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
1203  }
1204  print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', 'nowrap ');
1205  print '</td>';
1206 }
1207 if (!empty($arrayfields['p.birthday']['checked'])) {
1208  print '<td class="liste_titre center">';
1209  print '<div class="nowrap">';
1210  print $form->selectDate($search_birthday_start ? $search_birthday_start : -1, 'search_birthday_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1211  print '</div>';
1212  print '<div class="nowrap">';
1213  print $form->selectDate($search_birthday_end ? $search_birthday_end : -1, 'search_birthday_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1214  print '</div>';
1215  print '</td>';
1216 }
1217 
1218 // Extra fields
1219 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1220 
1221 // Fields from hook
1222 $parameters = array('arrayfields' => $arrayfields);
1223 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1224 print $hookmanager->resPrint;
1225 // Date creation
1226 if (!empty($arrayfields['p.datec']['checked'])) {
1227  print '<td class="liste_titre">';
1228  print '</td>';
1229 }
1230 // Date modification
1231 if (!empty($arrayfields['p.tms']['checked'])) {
1232  print '<td class="liste_titre">';
1233  print '</td>';
1234 }
1235 // Status
1236 if (!empty($arrayfields['p.statut']['checked'])) {
1237  print '<td class="liste_titre center parentonrightofpage">';
1238  print $form->selectarray('search_status', array('-1' => '', '0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), $search_status, 0, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage');
1239  print '</td>';
1240 }
1241 if (!empty($arrayfields['p.import_key']['checked'])) {
1242  print '<td class="liste_titre center">';
1243  print '<input class="flat searchstring" type="text" name="search_import_key" size="3" value="'.dol_escape_htmltag($search_import_key).'">';
1244  print '</td>';
1245 }
1246 // Action column
1247 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1248  print '<td class="liste_titre center maxwidthsearch">';
1249  $searchpicto = $form->showFilterButtons();
1250  print $searchpicto;
1251  print '</td>';
1252 }
1253 print '</tr>'."\n";
1254 
1255 $totalarray = array();
1256 $totalarray['nbfield'] = 0;
1257 
1258 // Fields title label
1259 // --------------------------------------------------------------------
1260 print '<tr class="liste_titre">';
1261 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1262  print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1263  $totalarray['nbfield']++;
1264 }
1265 if (!empty($arrayfields['p.rowid']['checked'])) {
1266  print_liste_field_titre($arrayfields['p.rowid']['label'], $_SERVER["PHP_SELF"], "p.rowid", "", $param, "", $sortfield, $sortorder);
1267  $totalarray['nbfield']++;
1268 }
1269 if (!empty($arrayfields['p.lastname']['checked'])) {
1270  print_liste_field_titre($arrayfields['p.lastname']['label'], $_SERVER["PHP_SELF"], "p.lastname", $begin, $param, '', $sortfield, $sortorder);
1271  $totalarray['nbfield']++;
1272 }
1273 if (!empty($arrayfields['p.firstname']['checked'])) {
1274  print_liste_field_titre($arrayfields['p.firstname']['label'], $_SERVER["PHP_SELF"], "p.firstname", $begin, $param, '', $sortfield, $sortorder);
1275  $totalarray['nbfield']++;
1276 }
1277 if (!empty($arrayfields['p.poste']['checked'])) {
1278  print_liste_field_titre($arrayfields['p.poste']['label'], $_SERVER["PHP_SELF"], "p.poste", $begin, $param, '', $sortfield, $sortorder);
1279  $totalarray['nbfield']++;
1280 }
1281 if (!empty($arrayfields['p.address']['checked'])) {
1282  print_liste_field_titre($arrayfields['p.address']['label'], $_SERVER["PHP_SELF"], "p.address", $begin, $param, '', $sortfield, $sortorder);
1283  $totalarray['nbfield']++;
1284 }
1285 if (!empty($arrayfields['p.zip']['checked'])) {
1286  print_liste_field_titre($arrayfields['p.zip']['label'], $_SERVER["PHP_SELF"], "p.zip", $begin, $param, '', $sortfield, $sortorder);
1287  $totalarray['nbfield']++;
1288 }
1289 if (!empty($arrayfields['p.town']['checked'])) {
1290  print_liste_field_titre($arrayfields['p.town']['label'], $_SERVER["PHP_SELF"], "p.town", $begin, $param, '', $sortfield, $sortorder);
1291  $totalarray['nbfield']++;
1292 }
1293 //if (!empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
1294 //if (!empty($arrayfields['region.nom']['checked'])) print_liste_field_titre($arrayfields['region.nom']['label'],$_SERVER["PHP_SELF"],"region.nom","",$param,'',$sortfield,$sortorder);
1295 if (!empty($arrayfields['country.code_iso']['checked'])) {
1296  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "co.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1297  $totalarray['nbfield']++;
1298 }
1299 if (!empty($arrayfields['p.phone']['checked'])) {
1300  print_liste_field_titre($arrayfields['p.phone']['label'], $_SERVER["PHP_SELF"], "p.phone", $begin, $param, '', $sortfield, $sortorder);
1301  $totalarray['nbfield']++;
1302 }
1303 if (!empty($arrayfields['p.phone_perso']['checked'])) {
1304  print_liste_field_titre($arrayfields['p.phone_perso']['label'], $_SERVER["PHP_SELF"], "p.phone_perso", $begin, $param, '', $sortfield, $sortorder);
1305  $totalarray['nbfield']++;
1306 }
1307 if (!empty($arrayfields['p.phone_mobile']['checked'])) {
1308  print_liste_field_titre($arrayfields['p.phone_mobile']['label'], $_SERVER["PHP_SELF"], "p.phone_mobile", $begin, $param, '', $sortfield, $sortorder);
1309  $totalarray['nbfield']++;
1310 }
1311 if (!empty($arrayfields['p.fax']['checked'])) {
1312  print_liste_field_titre($arrayfields['p.fax']['label'], $_SERVER["PHP_SELF"], "p.fax", $begin, $param, '', $sortfield, $sortorder);
1313  $totalarray['nbfield']++;
1314 }
1315 if (!empty($arrayfields['p.email']['checked'])) {
1316  print_liste_field_titre($arrayfields['p.email']['label'], $_SERVER["PHP_SELF"], "p.email", $begin, $param, '', $sortfield, $sortorder);
1317  $totalarray['nbfield']++;
1318 }
1319 if (!empty($arrayfields['unsubscribed']['checked'])) {
1320  print_liste_field_titre($arrayfields['unsubscribed']['label'], $_SERVER["PHP_SELF"], "unsubscribed", $begin, $param, '', $sortfield, $sortorder, 'center ');
1321  $totalarray['nbfield']++;
1322 }
1323 if (isModEnabled('socialnetworks')) {
1324  foreach ($socialnetworks as $key => $value) {
1325  if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
1326  print_liste_field_titre($arrayfields['p.'.$key]['label'], $_SERVER["PHP_SELF"], "p.".$key, $begin, $param, '', $sortfield, $sortorder);
1327  $totalarray['nbfield']++;
1328  }
1329  }
1330 }
1331 if (!empty($arrayfields['p.fk_soc']['checked'])) {
1332  print_liste_field_titre($arrayfields['p.fk_soc']['label'], $_SERVER["PHP_SELF"], "p.fk_soc", $begin, $param, '', $sortfield, $sortorder);
1333  $totalarray['nbfield']++;
1334 }
1335 if (!empty($arrayfields['s.nom']['checked'])) {
1336  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", $begin, $param, '', $sortfield, $sortorder);
1337  $totalarray['nbfield']++;
1338 }
1339 if (!empty($arrayfields['s.name_alias']['checked'])) {
1340  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", $begin, $param, '', $sortfield, $sortorder);
1341  $totalarray['nbfield']++;
1342 }
1343 if (!empty($arrayfields['p.priv']['checked'])) {
1344  print_liste_field_titre($arrayfields['p.priv']['label'], $_SERVER["PHP_SELF"], "p.priv", $begin, $param, '', $sortfield, $sortorder, 'center ');
1345  $totalarray['nbfield']++;
1346 }
1347 if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
1348  print_liste_field_titre($arrayfields['p.fk_prospectlevel']['label'], $_SERVER["PHP_SELF"], "p.fk_prospectlevel", "", $param, '', $sortfield, $sortorder, 'center ');
1349  $totalarray['nbfield']++;
1350 }
1351 if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
1352  print_liste_field_titre($arrayfields['p.fk_stcommcontact']['label'], $_SERVER["PHP_SELF"], "p.fk_stcommcontact", "", $param, '', $sortfield, $sortorder, 'center ');
1353  $totalarray['nbfield']++;
1354 }
1355 if (!empty($arrayfields['p.birthday']['checked'])) {
1356  print_liste_field_titre($arrayfields['p.birthday']['label'], $_SERVER["PHP_SELF"], "p.birthday", "", $param, '', $sortfield, $sortorder, 'center ');
1357  $totalarray['nbfield']++;
1358 }
1359 // Extra fields
1360 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1361 // Hook fields
1362 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1363 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1364 print $hookmanager->resPrint;
1365 if (!empty($arrayfields['p.datec']['checked'])) {
1366  print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1367  $totalarray['nbfield']++;
1368 }
1369 if (!empty($arrayfields['p.tms']['checked'])) {
1370  print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1371  $totalarray['nbfield']++;
1372 }
1373 if (!empty($arrayfields['p.statut']['checked'])) {
1374  print_liste_field_titre($arrayfields['p.statut']['label'], $_SERVER["PHP_SELF"], "p.statut", "", $param, '', $sortfield, $sortorder, 'center ');
1375  $totalarray['nbfield']++;
1376 }
1377 if (!empty($arrayfields['p.import_key']['checked'])) {
1378  print_liste_field_titre($arrayfields['p.import_key']['label'], $_SERVER["PHP_SELF"], "p.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1379  $totalarray['nbfield']++;
1380 }
1381 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1382  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1383  $totalarray['nbfield']++;
1384 }
1385 print "</tr>\n";
1386 
1387 
1388 // Loop on record
1389 // --------------------------------------------------------------------
1390 $i = 0;
1391 $savnbfield = $totalarray['nbfield'];
1392 $totalarray = array();
1393 $totalarray['nbfield'] = 0;
1394 $imaxinloop = ($limit ? min($num, $limit) : $num);
1395 while ($i < $imaxinloop) {
1396  $obj = $db->fetch_object($resql);
1397  if (empty($obj)) {
1398  break; // Should not happen
1399  }
1400 
1401  $arraysocialnetworks = (array) json_decode($obj->socialnetworks, true);
1402  $contactstatic->lastname = $obj->lastname;
1403  $contactstatic->firstname = '';
1404  $contactstatic->id = $obj->rowid;
1405  $contactstatic->statut = $obj->statut;
1406  $contactstatic->poste = $obj->poste;
1407  $contactstatic->email = $obj->email;
1408  $contactstatic->phone_pro = $obj->phone_pro;
1409  $contactstatic->phone_perso = $obj->phone_perso;
1410  $contactstatic->phone_mobile = $obj->phone_mobile;
1411  $contactstatic->address = $obj->address;
1412  $contactstatic->zip = $obj->zip;
1413  $contactstatic->town = $obj->town;
1414  $contactstatic->socialnetworks = $arraysocialnetworks;
1415  $contactstatic->country = $obj->country;
1416  $contactstatic->country_code = $obj->country_code;
1417  $contactstatic->photo = $obj->photo;
1418  $contactstatic->import_key = $obj->import_key;
1419  $contactstatic->photo = $obj->photo;
1420  $contactstatic->fk_prospectlevel = $obj->fk_prospectlevel;
1421 
1422  $object = $contactstatic;
1423 
1424  if ($mode == 'kanban') {
1425  if ($i == 0) {
1426  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1427  print '<div class="box-flex-container kanban">';
1428  }
1429  // Output Kanban
1430  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1431  $selected = 0;
1432  if (in_array($object->id, $arrayofselected)) {
1433  $selected = 1;
1434  }
1435  }
1436  if ($obj->socid > 0) {
1437  $contactstatic->fetch_thirdparty($obj->socid);
1438  }
1439  print $contactstatic->getKanbanView('', array('selected' => in_array($contactstatic->id, $arrayofselected)));
1440  if ($i == ($imaxinloop - 1)) {
1441  print '</div>';
1442  print '</td></tr>';
1443  }
1444  } else {
1445  // Show here line of result
1446  $j = 0;
1447  print '<tr data-rowid="'.$object->id.'" class="oddeven"';
1448  if ($contextpage == 'poslist') {
1449  print ' onclick="location.href=\'list.php?action=change&contextpage=poslist&idcustomer='.$obj->socid.'&idcontact='.$obj->rowid.'&place='.urlencode($place).'\'"';
1450  }
1451  print '>';
1452 
1453  // Action column
1454  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1455  print '<td class="nowrap center">';
1456  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1457  $selected = 0;
1458  if (in_array($obj->rowid, $arrayofselected)) {
1459  $selected = 1;
1460  }
1461  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1462  }
1463  print '</td>';
1464  if (!$i) {
1465  $totalarray['nbfield']++;
1466  }
1467  }
1468 
1469  // ID
1470  if (!empty($arrayfields['p.rowid']['checked'])) {
1471  print '<td class="tdoverflowmax50">';
1472  print dol_escape_htmltag($obj->rowid);
1473  print "</td>\n";
1474  if (!$i) {
1475  $totalarray['nbfield']++;
1476  }
1477  }
1478 
1479  // (Last) Name
1480  if (!empty($arrayfields['p.lastname']['checked'])) {
1481  print '<td class="middle tdoverflowmax150">';
1482  if ($contextpage == 'poslist') {
1483  print $contactstatic->lastname;
1484  } else {
1485  print $contactstatic->getNomUrl(1);
1486  }
1487  print '</td>';
1488  if (!$i) {
1489  $totalarray['nbfield']++;
1490  }
1491  }
1492 
1493  // Firstname
1494  if (!empty($arrayfields['p.firstname']['checked'])) {
1495  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($obj->firstname).'">'.dol_escape_htmltag($obj->firstname).'</td>';
1496  if (!$i) {
1497  $totalarray['nbfield']++;
1498  }
1499  }
1500 
1501  // Job position
1502  if (!empty($arrayfields['p.poste']['checked'])) {
1503  print '<td class="tdoverflowmax100">'.dol_escape_htmltag($obj->poste).'</td>';
1504  if (!$i) {
1505  $totalarray['nbfield']++;
1506  }
1507  }
1508 
1509  // Address
1510  if (!empty($arrayfields['p.address']['checked'])) {
1511  print '<td>'.dol_escape_htmltag($obj->address).'</td>';
1512  if (!$i) {
1513  $totalarray['nbfield']++;
1514  }
1515  }
1516 
1517  // Zip
1518  if (!empty($arrayfields['p.zip']['checked'])) {
1519  print '<td>'.dol_escape_htmltag($obj->zip).'</td>';
1520  if (!$i) {
1521  $totalarray['nbfield']++;
1522  }
1523  }
1524 
1525  // Town
1526  if (!empty($arrayfields['p.town']['checked'])) {
1527  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->town).'">'.dol_escape_htmltag($obj->town).'</td>';
1528  if (!$i) {
1529  $totalarray['nbfield']++;
1530  }
1531  }
1532 
1533  /*
1534  // State
1535  if (!empty($arrayfields['state.nom']['checked']))
1536  {
1537  print "<td>".$obj->state_name."</td>\n";
1538  if (! $i) $totalarray['nbfield']++;
1539  }
1540 
1541  // Region
1542  if (!empty($arrayfields['region.nom']['checked']))
1543  {
1544  print "<td>".$obj->region_name."</td>\n";
1545  if (! $i) $totalarray['nbfield']++;
1546  }*/
1547 
1548  // Country
1549  if (!empty($arrayfields['country.code_iso']['checked'])) {
1550  print '<td class="center">';
1551  $tmparray = getCountry($obj->fk_pays, 'all');
1552  print dol_escape_htmltag($tmparray['label']);
1553  print '</td>';
1554  if (!$i) {
1555  $totalarray['nbfield']++;
1556  }
1557  }
1558 
1559  // Phone pro
1560  if (!empty($arrayfields['p.phone']['checked'])) {
1561  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_pro, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
1562  if (!$i) {
1563  $totalarray['nbfield']++;
1564  }
1565  }
1566 
1567  // Phone perso
1568  if (!empty($arrayfields['p.phone_perso']['checked'])) {
1569  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_perso, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'phone').'</td>';
1570  if (!$i) {
1571  $totalarray['nbfield']++;
1572  }
1573  }
1574 
1575  // Phone mobile
1576  if (!empty($arrayfields['p.phone_mobile']['checked'])) {
1577  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->phone_mobile, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'mobile').'</td>';
1578  if (!$i) {
1579  $totalarray['nbfield']++;
1580  }
1581  }
1582 
1583  // Fax
1584  if (!empty($arrayfields['p.fax']['checked'])) {
1585  print '<td class="nowraponall tdoverflowmax150">'.dol_print_phone($obj->fax, $obj->country_code, $obj->rowid, $obj->socid, 'AC_TEL', ' ', 'fax').'</td>';
1586  if (!$i) {
1587  $totalarray['nbfield']++;
1588  }
1589  }
1590 
1591  // EMail
1592  if (!empty($arrayfields['p.email']['checked'])) {
1593  print '<td class="nowraponall tdoverflowmax300">';
1594  if ($contextpage == 'poslist') {
1595  print $obj->email;
1596  } else {
1597  print dol_print_email($obj->email, $obj->rowid, $obj->socid, 1, 18, 0, 1);
1598  }
1599  print '</td>';
1600  if (!$i) {
1601  $totalarray['nbfield']++;
1602  }
1603  }
1604 
1605  // No EMail Subscription
1606  if (!empty($arrayfields['unsubscribed']['checked'])) {
1607  print '<td class="center">';
1608  if (empty($obj->email)) {
1609  //print '<span class="opacitymedium">'.$langs->trans("NoEmail").'</span>';
1610  } else {
1611  print yn(($obj->unsubscribed > 0) ? 1 : 0);
1612  }
1613  print '</td>';
1614  if (!$i) {
1615  $totalarray['nbfield']++;
1616  }
1617  }
1618 
1619  // Social Networks
1620  if (isModEnabled('socialnetworks')) {
1621  foreach ($socialnetworks as $key => $value) {
1622  if ($value['active'] && !empty($arrayfields['p.'.$key]['checked'])) {
1623  print '<td class="tdoverflowmax100">'.(empty($arraysocialnetworks[$key]) ? '' : dol_print_socialnetworks($arraysocialnetworks[$key], $obj->rowid, $obj->socid, $key, $socialnetworks)).'</td>';
1624  if (!$i) {
1625  $totalarray['nbfield']++;
1626  }
1627  }
1628  }
1629  }
1630 
1631  // Company / Third Party
1632  if (!empty($arrayfields['p.fk_soc']['checked']) || !empty($arrayfields['s.nom']['checked'])) {
1633  print '<td class="tdoverflowmax200">';
1634  if ($obj->socid) {
1635  $objsoc = new Societe($db);
1636  $objsoc->fetch($obj->socid);
1637  $option_link = 'customer';
1638  if ($objsoc->client == 0 && $objsoc->fournisseur > 0) {
1639  $option_link = 'supplier';
1640  } elseif ($objsoc->client == 0 && $objsoc->fournisseur == 0) {
1641  $option_link = '';
1642  }
1643  if ($contextpage == 'poslist') {
1644  print $objsoc->name;
1645  } else {
1646  print $objsoc->getNomUrl(1, $option_link, 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1647  }
1648  } else {
1649  print '&nbsp;';
1650  }
1651  print '</td>';
1652  if (!$i) {
1653  $totalarray['nbfield']++;
1654  }
1655  }
1656 
1657  // Alias name
1658  if (!empty($arrayfields['s.name_alias']['checked'])) {
1659  print '<td class="tdoverflowmax100" title="'.dol_escape_htmltag($obj->alias).'">';
1660  print dol_escape_htmltag($obj->alias);
1661  print '</td>';
1662  if (!$i) {
1663  $totalarray['nbfield']++;
1664  }
1665  }
1666 
1667  // Private/Public
1668  if (!empty($arrayfields['p.priv']['checked'])) {
1669  print '<td class="center">'.$contactstatic->LibPubPriv($obj->priv).'</td>';
1670  if (!$i) {
1671  $totalarray['nbfield']++;
1672  }
1673  }
1674 
1675  // Prospect Level
1676  if (!empty($arrayfields['p.fk_prospectlevel']['checked'])) {
1677  print '<td class="center">';
1678  print $contactstatic->getLibProspLevel();
1679  print "</td>";
1680  if (!$i) {
1681  $totalarray['nbfield']++;
1682  }
1683  }
1684 
1685  // Prospect status
1686  if (!empty($arrayfields['p.fk_stcommcontact']['checked'])) {
1687  print '<td class="center nowrap"><div class="nowrap">';
1688  print '<div class="inline-block">'.$contactstatic->libProspCommStatut($obj->stcomm_id, 2, $contactstatic->cacheprospectstatus[$obj->stcomm_id]['label'], $obj->stcomm_picto);
1689  print '</div> - <div class="inline-block">';
1690  foreach ($contactstatic->cacheprospectstatus as $key => $val) {
1691  $titlealt = 'default';
1692  if (!empty($val['code']) && !in_array($val['code'], array('ST_NO', 'ST_NEVER', 'ST_TODO', 'ST_PEND', 'ST_DONE'))) {
1693  $titlealt = $val['label'];
1694  }
1695  if ($obj->stcomm_id != $val['id']) {
1696  print '<a class="pictosubstatus" href="'.$_SERVER["PHP_SELF"].'?stcommcontactid='.$obj->rowid.'&stcomm='.urlencode((string) ($val['code'])).'&action=setstcomm&token='.newToken().$param.($page ? '&page='.urlencode((string) ($page)) : '').'">'.img_action($titlealt, $val['code'], $val['picto']).'</a>';
1697  }
1698  }
1699  print '</div></div></td>';
1700  if (!$i) {
1701  $totalarray['nbfield']++;
1702  }
1703  }
1704 
1705  // Birthday
1706  if (!empty($arrayfields['p.birthday']['checked'])) {
1707  print '<td class="center nowraponall">';
1708  print dol_print_date($db->jdate($obj->birthday), 'day', 'tzuser');
1709  print '</td>';
1710  if (!$i) {
1711  $totalarray['nbfield']++;
1712  }
1713  }
1714 
1715  // Extra fields
1716  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1717 
1718  // Fields from hook
1719  $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1720  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1721  print $hookmanager->resPrint;
1722  // Date creation
1723  if (!empty($arrayfields['p.datec']['checked'])) {
1724  print '<td class="center nowraponall">';
1725  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1726  print '</td>';
1727  if (!$i) {
1728  $totalarray['nbfield']++;
1729  }
1730  }
1731 
1732  // Date modification
1733  if (!empty($arrayfields['p.tms']['checked'])) {
1734  print '<td class="center nowraponall">';
1735  print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1736  print '</td>';
1737  if (!$i) {
1738  $totalarray['nbfield']++;
1739  }
1740  }
1741 
1742  // Status
1743  if (!empty($arrayfields['p.statut']['checked'])) {
1744  print '<td class="center">'.$contactstatic->getLibStatut(5).'</td>';
1745  if (!$i) {
1746  $totalarray['nbfield']++;
1747  }
1748  }
1749 
1750  // Import key
1751  if (!empty($arrayfields['p.import_key']['checked'])) {
1752  print '<td class="tdoverflowmax100">';
1753  print dol_escape_htmltag($obj->import_key);
1754  print "</td>\n";
1755  if (!$i) {
1756  $totalarray['nbfield']++;
1757  }
1758  }
1759 
1760  // Action column
1761  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1762  print '<td class="nowrap center">';
1763  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1764  $selected = 0;
1765  if (in_array($obj->rowid, $arrayofselected)) {
1766  $selected = 1;
1767  }
1768  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1769  }
1770  print '</td>';
1771  if (!$i) {
1772  $totalarray['nbfield']++;
1773  }
1774  }
1775 
1776  print '</tr>'."\n";
1777  }
1778  $i++;
1779 }
1780 
1781 // Show total line
1782 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1783 
1784 // If no record found
1785 if ($num == 0) {
1786  $colspan = 1;
1787  foreach ($arrayfields as $key => $val) {
1788  if (!empty($val['checked'])) {
1789  $colspan++;
1790  }
1791  }
1792  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1793 }
1794 
1795 $db->free($resql);
1796 
1797 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1798 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1799 print $hookmanager->resPrint;
1800 
1801 print '</table>'."\n";
1802 print '</div>'."\n";
1803 
1804 print '</form>'."\n";
1805 
1806 // End of page
1807 llxFooter();
1808 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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:118
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
Class to manage contact/addresses.
Class to manage standard extra fields.
Class to manage invoices.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
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...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
newToken()
Return the value of token currently saved into session with name 'newtoken'.
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
getArrayOfSocialNetworks()
Get array of social network dictionary.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.
print *****$script_file(".$version.") pid code
1: frais de port 2: ecotaxe 3: option line (when qty = 0)