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