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