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