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