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