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