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