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