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