dolibarr  20.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) 2004-2019 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2019 Regis Houssin <regis.houssin@inodbox.com>
5  * Copyright (C) 2012 Marcos García <marcosgdf@gmail.com>
6  * Copyright (C) 2013-2015 Raphaël Doursenaud <rdoursenaud@gpcsolutions.fr>
7  * Copyright (C) 2015 Florian Henry <florian.henry@open-concept.pro>
8  * Copyright (C) 2016-2024 Josep Lluis Amador <joseplluis@lliuretic.cat>
9  * Copyright (C) 2016 Ferran Marcet <fmarcet@2byte.es>
10  * Copyright (C) 2017 Rui Strecht <rui.strecht@aliartalentos.com>
11  * Copyright (C) 2017 Juanjo Menent <jmenent@2byte.es>
12  * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
13  * Copyright (C) 2020 Open-Dsi <support@open-dsi.fr>
14  * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
15  * Copyright (C) 2022 Anthony Berton <anthony.berton@bb2a.fr>
16  * Copyright (C) 2023 William Mead <william.mead@manchenumerique.fr>
17  * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
18  * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
19  *
20  * This program is free software; you can redistribute it and/or modify
21  * it under the terms of the GNU General Public License as published by
22  * the Free Software Foundation; either version 3 of the License, or
23  * (at your option) any later version.
24  *
25  * This program is distributed in the hope that it will be useful,
26  * but WITHOUT ANY WARRANTY; without even the implied warranty of
27  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
28  * GNU General Public License for more details.
29  *
30  * You should have received a copy of the GNU General Public License
31  * along with this program. If not, see <https://www.gnu.org/licenses/>.
32  */
33 
41 // Load Dolibarr environment
42 require_once '../main.inc.php';
43 include_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
44 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
45 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
46 require_once DOL_DOCUMENT_ROOT.'/core/lib/functions2.lib.php';
47 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
48 require_once DOL_DOCUMENT_ROOT.'/societe/class/client.class.php';
49 if (isModEnabled('category')) {
50  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
51  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcategory.class.php';
52 }
53 
54 // Load translation files required by the page
55 $langs->loadLangs(array("companies", "commercial", "customers", "suppliers", "bills", "compta", "categories", "cashdesk"));
56 
57 
58 // Get parameters
59 $action = GETPOST('action', 'aZ09');
60 $massaction = GETPOST('massaction', 'alpha');
61 $show_files = GETPOSTINT('show_files');
62 $confirm = GETPOST('confirm', 'alpha');
63 $toselect = GETPOST('toselect', 'array');
64 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'thirdpartylist';
65 $optioncss = GETPOST('optioncss', 'alpha');
66 if ($contextpage == 'poslist') {
67  $optioncss = 'print';
68 }
69 $mode = GETPOST("mode", 'alpha');
70 
71 // search fields
72 $search_all = trim(GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
73 $search_cti = preg_replace('/^0+/', '', preg_replace('/[^0-9]/', '', GETPOST('search_cti', 'alphanohtml'))); // Phone number without any special chars
74 
75 $search_id = GETPOST("search_id", 'int');
76 $search_nom = trim(GETPOST("search_nom", 'restricthtml'));
77 $search_alias = trim(GETPOST("search_alias", 'restricthtml'));
78 $search_nom_only = trim(GETPOST("search_nom_only", 'restricthtml'));
79 $search_barcode = trim(GETPOST("search_barcode", 'alpha'));
80 $search_customer_code = trim(GETPOST('search_customer_code', 'alpha'));
81 $search_supplier_code = trim(GETPOST('search_supplier_code', 'alpha'));
82 $search_account_customer_code = trim(GETPOST('search_account_customer_code', 'alpha'));
83 $search_account_supplier_code = trim(GETPOST('search_account_supplier_code', 'alpha'));
84 $search_address = trim(GETPOST('search_address', 'alpha'));
85 $search_zip = trim(GETPOST("search_zip", 'alpha'));
86 $search_town = trim(GETPOST("search_town", 'alpha'));
87 $search_state = trim(GETPOST("search_state", 'alpha'));
88 $search_region = trim(GETPOST("search_region", 'alpha'));
89 $search_email = trim(GETPOST('search_email', 'alpha'));
90 $search_phone = trim(GETPOST('search_phone', 'alpha'));
91 $search_phone_mobile = trim(GETPOST('search_phone_mobile', 'alpha'));
92 $search_fax = trim(GETPOST('search_fax', 'alpha'));
93 $search_url = trim(GETPOST('search_url', 'alpha'));
94 $search_idprof1 = trim(GETPOST('search_idprof1', 'alpha'));
95 $search_idprof2 = trim(GETPOST('search_idprof2', 'alpha'));
96 $search_idprof3 = trim(GETPOST('search_idprof3', 'alpha'));
97 $search_idprof4 = trim(GETPOST('search_idprof4', 'alpha'));
98 $search_idprof5 = trim(GETPOST('search_idprof5', 'alpha'));
99 $search_idprof6 = trim(GETPOST('search_idprof6', 'alpha'));
100 $search_vat = trim(GETPOST('search_vat', 'alpha'));
101 $search_sale = GETPOSTINT("search_sale");
102 $search_categ_cus = GETPOSTINT("search_categ_cus");
103 $search_categ_sup = GETPOSTINT("search_categ_sup");
104 $searchCategoryCustomerOperator = 0;
105 $searchCategorySupplierOperator = 0;
106 if (GETPOSTISSET('formfilteraction')) {
107  $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator');
108  $searchCategorySupplierOperator = GETPOST('search_category_supplier_operator');
109 } elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
110  $searchCategoryCustomerOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
111  $searchCategorySupplierOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
112 }
113 $searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
114 if (!empty($search_categ_cus) && empty($searchCategoryCustomerList)) {
115  $searchCategoryCustomerList = array($search_categ_cus);
116 }
117 $searchCategorySupplierList = GETPOST('search_category_supplier_list', 'array');
118 if (!empty($search_categ_sup) && empty($searchCategorySupplierList)) {
119  $searchCategorySupplierList = array($search_categ_sup);
120 }
121 $search_country = GETPOST("search_country", 'aZ09');
122 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
123 $search_price_level = GETPOST('search_price_level', 'int');
124 $search_staff = GETPOST("search_staff", 'int');
125 $search_status = GETPOST("search_status", 'intcomma');
126 $search_type = GETPOST('search_type', 'alpha');
127 $search_level = GETPOST("search_level", "array:alpha");
128 $search_stcomm = GETPOST('search_stcomm', "array:int");
129 $search_import_key = trim(GETPOST("search_import_key", "alpha"));
130 $search_parent_name = trim(GETPOST('search_parent_name', 'alpha'));
131 
132 $search_date_creation_startmonth = GETPOSTINT('search_date_creation_startmonth');
133 $search_date_creation_startyear = GETPOSTINT('search_date_creation_startyear');
134 $search_date_creation_startday = GETPOSTINT('search_date_creation_startday');
135 $search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); // Use tzserver
136 $search_date_creation_endmonth = GETPOSTINT('search_date_creation_endmonth');
137 $search_date_creation_endyear = GETPOSTINT('search_date_creation_endyear');
138 $search_date_creation_endday = GETPOSTINT('search_date_creation_endday');
139 $search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); // Use tzserver
140 
141 $search_date_modif_startmonth = GETPOSTINT('search_date_modif_startmonth');
142 $search_date_modif_startyear = GETPOSTINT('search_date_modif_startyear');
143 $search_date_modif_startday = GETPOSTINT('search_date_modif_startday');
144 $search_date_modif_start = dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear); // Use tzserver
145 $search_date_modif_endmonth = GETPOSTINT('search_date_modif_endmonth');
146 $search_date_modif_endyear = GETPOSTINT('search_date_modif_endyear');
147 $search_date_modif_endday = GETPOSTINT('search_date_modif_endday');
148 $search_date_modif_end = dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear); // Use tzserver
149 
150 $type = GETPOST('type', 'alpha');
151 $place = GETPOST('place', 'aZ09') ? GETPOST('place', 'aZ09') : '0'; // $place is string id of table for Bar or Restaurant
152 
153 $diroutputmassaction = $conf->societe->dir_output.'/temp/massgeneration/'.$user->id;
154 
155 // Load variable for pagination
156 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
157 $sortfield = GETPOST('sortfield', 'aZ09comma');
158 $sortorder = GETPOST('sortorder', 'aZ09comma');
159 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
160 if (!$sortorder) {
161  $sortorder = "ASC";
162 }
163 if (!$sortfield) {
164  $sortfield = "s.nom";
165 }
166 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
167  // If $page is not defined, or '' or -1 or if we click on clear filters
168  $page = 0;
169 }
170 $offset = $limit * $page;
171 $pageprev = $page - 1;
172 $pagenext = $page + 1;
173 
174 if ($type == 'c') {
175  if (empty($contextpage) || $contextpage == 'thirdpartylist') {
176  $contextpage = 'customerlist';
177  }
178  if ($search_type == '') {
179  $search_type = '1,3';
180  }
181 }
182 if ($type == 'p') {
183  if (empty($contextpage) || $contextpage == 'thirdpartylist') {
184  $contextpage = 'prospectlist';
185  }
186  if ($search_type == '') {
187  $search_type = '2,3';
188  }
189 }
190 if ($type == 't') {
191  if (empty($contextpage) || $contextpage == 'poslist') {
192  $contextpage = 'poslist';
193  }
194  if ($search_type == '') {
195  $search_type = '1,2,3';
196  }
197 }
198 if ($type == 'f') {
199  if (empty($contextpage) || $contextpage == 'thirdpartylist') {
200  $contextpage = 'supplierlist';
201  }
202  if ($search_type == '') {
203  $search_type = '4';
204  }
205 }
206 // Initialize technical objects to manage hooks of page. Note that conf->hooks_modules contains array of hook context
207 $object = new Societe($db);
208 $extrafields = new ExtraFields($db);
209 $hookmanager->initHooks(array($contextpage));
210 
211 // Fetch optionals attributes and labels
212 $extrafields->fetch_name_optionals_label($object->table_element);
213 
214 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
215 
216 // List of fields to search into when doing a "search in all"
217 $fieldstosearchall = array(
218  's.nom' => "ThirdPartyName",
219  's.name_alias' => "AliasNameShort",
220  's.code_client' => "CustomerCode",
221  's.code_fournisseur' => "SupplierCode",
222  's.code_compta' => "CustomerAccountancyCodeShort",
223  's.code_compta_fournisseur' => "SupplierAccountancyCodeShort",
224  's.zip' => "Zip",
225  's.town' => "Town",
226  's.email' => "EMail",
227  's.url' => "URL",
228  's.tva_intra' => "VATIntra",
229  's.siren' => "ProfId1",
230  's.siret' => "ProfId2",
231  's.ape' => "ProfId3",
232  's.phone' => "Phone",
233  's.phone_mobile' => "PhoneMobile",
234  's.fax' => "Fax",
235 );
236 if (($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') {
237  $fieldstosearchall['s.idprof4'] = 'ProfId4';
238 }
239 if (($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') {
240  $fieldstosearchall['s.idprof5'] = 'ProfId5';
241 }
242 if (($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') {
243  $fieldstosearchall['s.idprof6'] = 'ProfId6';
244 }
245 if (isModEnabled('barcode')) {
246  $fieldstosearchall['s.barcode'] = 'Gencod';
247 }
248 // Personalized search criteria. Example: $conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS = 's.nom=ThirdPartyName;s.name_alias=AliasNameShort;s.code_client=CustomerCode'
249 if (getDolGlobalString('THIRDPARTY_QUICKSEARCH_ON_FIELDS')) {
250  $fieldstosearchall = dolExplodeIntoArray($conf->global->THIRDPARTY_QUICKSEARCH_ON_FIELDS);
251 }
252 
253 
254 // Define list of fields to show into list
255 $checkedcustomercode = (in_array($contextpage, array('thirdpartylist', 'customerlist', 'prospectlist', 'poslist')) ? 1 : 0);
256 $checkedsuppliercode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
257 $checkedcustomeraccountcode = (in_array($contextpage, array('customerlist')) ? 1 : 0);
258 $checkedsupplieraccountcode = (in_array($contextpage, array('supplierlist')) ? 1 : 0);
259 $checkedtypetiers = 1;
260 $checkedprofid1 = 0;
261 $checkedprofid2 = 0;
262 $checkedprofid3 = 0;
263 $checkedprofid4 = 0;
264 $checkedprofid5 = 0;
265 $checkedprofid6 = 0;
266 //$checkedprofid4=((($tmp = $langs->transnoentities("ProfId4".$mysoc->country_code)) && $tmp != "ProfId4".$mysoc->country_code && $tmp != '-') ? 1 : 0);
267 //$checkedprofid5=((($tmp = $langs->transnoentities("ProfId5".$mysoc->country_code)) && $tmp != "ProfId5".$mysoc->country_code && $tmp != '-') ? 1 : 0);
268 //$checkedprofid6=((($tmp = $langs->transnoentities("ProfId6".$mysoc->country_code)) && $tmp != "ProfId6".$mysoc->country_code && $tmp != '-') ? 1 : 0);
269 $checkprospectlevel = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
270 $checkstcomm = (in_array($contextpage, array('prospectlist')) ? 1 : 0);
271 $arrayfields = array(
272  's.rowid' => array('label' => "TechnicalID", 'position' => 1, 'checked' => -1, 'enabled' => 1),
273  's.nom' => array('label' => "ThirdPartyName", 'position' => 2, 'checked' => 1),
274  's.name_alias' => array('label' => "AliasNameShort", 'position' => 3, 'checked' => 1),
275  's.barcode' => array('label' => "Gencod", 'position' => 5, 'checked' => 1, 'enabled' => (isModEnabled('barcode'))),
276  's.code_client' => array('label' => "CustomerCodeShort", 'position' => 10, 'checked' => $checkedcustomercode),
277  's.code_fournisseur' => array('label' => "SupplierCodeShort", 'position' => 11, 'checked' => $checkedsuppliercode, 'enabled' => (isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
278  's.code_compta' => array('label' => "CustomerAccountancyCodeShort", 'position' => 13, 'checked' => $checkedcustomeraccountcode),
279  's.code_compta_fournisseur' => array('label' => "SupplierAccountancyCodeShort", 'position' => 14, 'checked' => $checkedsupplieraccountcode, 'enabled' => (isModEnabled("supplier_order") || isModEnabled("supplier_invoice"))),
280  's.address' => array('label' => "Address", 'position' => 19, 'checked' => 0),
281  's.zip' => array('label' => "Zip", 'position' => 20, 'checked' => 1),
282  's.town' => array('label' => "Town", 'position' => 21, 'checked' => 0),
283  'state.nom' => array('label' => "State", 'position' => 22, 'checked' => 0),
284  'region.nom' => array('label' => "Region", 'position' => 23, 'checked' => 0),
285  'country.code_iso' => array('label' => "Country", 'position' => 24, 'checked' => 0),
286  's.email' => array('label' => "Email", 'position' => 25, 'checked' => 0),
287  's.url' => array('label' => "Url", 'position' => 26, 'checked' => 0),
288  's.phone' => array('label' => "Phone", 'position' => 27, 'checked' => 1),
289  's.fax' => array('label' => "Fax", 'position' => 28, 'checked' => 0),
290  'typent.code' => array('label' => "ThirdPartyType", 'position' => 29, 'checked' => $checkedtypetiers),
291  'staff.code' => array('label' => "Workforce", 'position' => 31, 'checked' => 0),
292  's.phone_mobile' => array('label' => "PhoneMobile", 'position' => 32, 'checked' => 0),
293  's.siren' => array('label' => "ProfId1Short", 'position' => 40, 'checked' => $checkedprofid1),
294  's.siret' => array('label' => "ProfId2Short", 'position' => 41, 'checked' => $checkedprofid2),
295  's.ape' => array('label' => "ProfId3Short", 'position' => 42, 'checked' => $checkedprofid3),
296  's.idprof4' => array('label' => "ProfId4Short", 'position' => 43, 'checked' => $checkedprofid4),
297  's.idprof5' => array('label' => "ProfId5Short", 'position' => 44, 'checked' => $checkedprofid5),
298  's.idprof6' => array('label' => "ProfId6Short", 'position' => 45, 'checked' => $checkedprofid6),
299  's.tva_intra' => array('label' => "VATIntraShort", 'position' => 50, 'checked' => 0),
300  'customerorsupplier' => array('label' => 'NatureOfThirdParty', 'position' => 61, 'checked' => 1),
301  's.fk_prospectlevel' => array('label' => "ProspectLevel", 'position' => 62, 'checked' => $checkprospectlevel),
302  's.fk_stcomm' => array('label' => "StatusProsp", 'position' => 63, 'checked' => $checkstcomm),
303  's2.nom' => array('label' => 'ParentCompany', 'position' => 64, 'checked' => 0),
304  's.datec' => array('label' => "DateCreation", 'checked' => 0, 'position' => 500),
305  's.tms' => array('label' => "DateModificationShort", 'checked' => 0, 'position' => 500),
306  's.status' => array('label' => "Status", 'checked' => 1, 'position' => 1000),
307  's.import_key' => array('label' => "ImportId", 'checked' => 0, 'position' => 1100),
308 );
309 if (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES')) {
310  $arrayfields['s.price_level'] = array('label' => "PriceLevel", 'position' => 30, 'checked' => 0);
311 }
312 
313 // Add non object fields to fields for list
314 $arrayfields['sales.representative'] = array('label' => $langs->trans("SalesRepresentatives"), 'checked' => 1, 'position' => 12);
315 
316 // Extra fields
317 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
318 
319 $object->fields = dol_sort_array($object->fields, 'position');
320 $arrayfields = dol_sort_array($arrayfields, 'position');
321 '@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
322 
323 // Security check
324 $socid = GETPOSTINT('socid');
325 if ($user->socid) {
326  $socid = $user->socid;
327 }
328 $result = restrictedArea($user, 'societe', $socid, '');
329 
330 
331 
332 /*
333  * Actions
334  */
335 
336 if ($action == "change" && $user->hasRight('takepos', 'run')) { // Change customer for TakePOS
337  $idcustomer = GETPOSTINT('idcustomer');
338 
339  // Check if draft invoice already exists, if not create it
340  $sql = "SELECT rowid FROM ".MAIN_DB_PREFIX."facture where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' AND entity IN (".getEntity('invoice').")";
341  $result = $db->query($sql);
342  $num_lines = $db->num_rows($result);
343  if ($num_lines == 0) {
344  require_once DOL_DOCUMENT_ROOT.'/compta/facture/class/facture.class.php';
345  $invoice = new Facture($db);
346  $constforthirdpartyid = 'CASHDESK_ID_THIRDPARTY'.$_SESSION["takeposterminal"];
347  $invoice->socid = getDolGlobalInt($constforthirdpartyid);
348  $invoice->date = dol_now();
349  $invoice->module_source = 'takepos';
350  $invoice->pos_source = $_SESSION["takeposterminal"];
351  $placeid = $invoice->create($user);
352  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")' where rowid = ".((int) $placeid);
353  $db->query($sql);
354  }
355 
356  $sql = "UPDATE ".MAIN_DB_PREFIX."facture set fk_soc=".((int) $idcustomer)." where ref='(PROV-POS".$_SESSION["takeposterminal"]."-".$place.")'";
357  $resql = $db->query($sql); ?>
358  <script>
359  console.log("Reload page invoice.php with place=<?php print $place; ?>");
360  parent.$("#poslines").load("invoice.php?place=<?php print $place; ?>", function() {
361  //parent.$("#poslines").scrollTop(parent.$("#poslines")[0].scrollHeight);
362  <?php if (!$resql) { ?>
363  alert('Error failed to update customer on draft invoice.');
364  <?php } ?>
365  parent.$.colorbox.close(); /* Close the popup */
366  });
367  </script>
368  <?php
369  exit;
370 }
371 
372 if (GETPOST('cancel', 'alpha')) {
373  $action = 'list';
374  $massaction = '';
375 }
376 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
377  $massaction = '';
378 }
379 
380 $parameters = array('arrayfields' => &$arrayfields);
381 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
382 if ($reshook < 0) {
383  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
384 }
385 
386 if (empty($reshook)) {
387  // Selection of new fields
388  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
389 
390  // Purge search criteria
391  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
392  $search_id = '';
393  $search_nom = '';
394  $search_alias = '';
395  $search_categ_cus = 0;
396  $search_categ_sup = 0;
397  $searchCategoryCustomerOperator = 0;
398  $searchCategorySupplierOperator = 0;
399  $searchCategoryCustomerList = array();
400  $searchCategorySupplierList = array();
401  $search_sale = '';
402  $search_barcode = "";
403  $search_customer_code = '';
404  $search_supplier_code = '';
405  $search_account_customer_code = '';
406  $search_account_supplier_code = '';
407  $search_address = '';
408  $search_zip = "";
409  $search_town = "";
410  $search_state = "";
411  $search_region = "";
412  $search_country = '';
413  $search_email = '';
414  $search_phone = '';
415  $search_phone_mobile = '';
416  $search_fax = '';
417  $search_url = '';
418  $search_idprof1 = '';
419  $search_idprof2 = '';
420  $search_idprof3 = '';
421  $search_idprof4 = '';
422  $search_idprof5 = '';
423  $search_idprof6 = '';
424  $search_vat = '';
425  $search_type = '';
426  $search_price_level = '';
427  $search_type_thirdparty = '';
428  $search_staff = '';
429  $search_date_creation_startmonth = "";
430  $search_date_creation_startyear = "";
431  $search_date_creation_startday = "";
432  $search_date_creation_start = "";
433  $search_date_creation_endmonth = "";
434  $search_date_creation_endyear = "";
435  $search_date_creation_endday = "";
436  $search_date_creation_end = "";
437  $search_date_modif_startmonth = "";
438  $search_date_modif_startyear = "";
439  $search_date_modif_startday = "";
440  $search_date_modif_start = "";
441  $search_date_modif_endmonth = "";
442  $search_date_modif_endyear = "";
443  $search_date_modif_endday = "";
444  $search_date_modif_end = "";
445  $search_status = -1;
446  $search_stcomm = '';
447  $search_level = '';
448  $search_parent_name = '';
449  $search_import_key = '';
450 
451  $search_all = '';
452  $toselect = array();
453  $search_array_options = array();
454  }
455 
456  // Mass actions
457  $objectclass = 'Societe';
458  $objectlabel = 'ThirdParty';
459  $permissiontoread = $user->hasRight('societe', 'lire');
460  $permissiontodelete = $user->hasRight('societe', 'supprimer');
461  $permissiontoadd = $user->hasRight("societe", "creer");
462  $uploaddir = $conf->societe->dir_output;
463  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
464 
465  if ($action == 'setstcomm') {
466  $object = new Client($db);
467  $result = $object->fetch(GETPOST('stcommsocid'));
468  $object->stcomm_id = dol_getIdFromCode($db, GETPOST('stcomm', 'alpha'), 'c_stcomm');
469  $result = $object->update($object->id, $user);
470  if ($result < 0) {
471  setEventMessages($object->error, $object->errors, 'errors');
472  }
473 
474  $action = '';
475  }
476 }
477 
478 if ($search_status == '' && empty($search_all)) {
479  $search_status = 1; // display active thirdparty only by default
480 }
481 
482 
483 
484 /*
485  * View
486  */
487 
488 /*
489  REM: Rules on permissions to see thirdparties
490  Internal or External user + No permission to see customers => See nothing
491  Internal user socid=0 + Permission to see ALL customers => See all thirdparties
492  Internal user socid=0 + No permission to see ALL customers => See only thirdparties linked to user that are sale representative
493  External user socid=x + Permission to see ALL customers => Can see only himself
494  External user socid=x + No permission to see ALL customers => Can see only himself
495  */
496 
497 $form = new Form($db);
498 $formother = new FormOther($db);
499 $companystatic = new Societe($db);
500 $companyparent = new Societe($db);
501 $formcompany = new FormCompany($db);
502 $prospectstatic = new Client($db);
503 $prospectstatic->client = 2;
504 $prospectstatic->loadCacheOfProspStatus();
505 
506 $now = dol_now();
507 
508 $title = $langs->trans("ThirdParties");
509 if ($type == 'c' && (empty($search_type) || ($search_type == '1,3'))) {
510  $title = $langs->trans("Customers");
511 }
512 if ($type == 'p' && (empty($search_type) || ($search_type == '2,3'))) {
513  $title = $langs->trans("Prospects");
514 }
515 if ($type == 'f' && (empty($search_type) || ($search_type == '4'))) {
516  $title = $langs->trans("Suppliers");
517 }
518 $help_url = 'EN:Module_Third_Parties|FR:Module_Tiers|ES:Empresas';
519 
520 
521 // Select every potentials, and note each potentials which fit in search parameters
522 $tab_level = array();
523 $sql = "SELECT code, label, sortorder";
524 $sql .= " FROM ".MAIN_DB_PREFIX."c_prospectlevel";
525 $sql .= " WHERE active > 0";
526 $sql .= " ORDER BY sortorder";
527 $resql = $db->query($sql);
528 if ($resql) {
529  while ($obj = $db->fetch_object($resql)) {
530  // Compute level text
531  $level = $langs->trans($obj->code);
532  if ($level == $obj->code) {
533  $level = $langs->trans($obj->label);
534  }
535  $tab_level[$obj->code] = $level;
536  }
537 } else {
538  dol_print_error($db);
539 }
540 
541 // Build and execute select
542 // --------------------------------------------------------------------
543 $sql = "SELECT s.rowid, s.nom as name, s.name_alias, s.barcode, s.address, s.town, s.zip, s.datec, s.code_client, s.code_fournisseur, s.logo,";
544 $sql .= " s.entity,";
545 $sql .= " st.libelle as stcomm, st.picto as stcomm_picto, s.fk_stcomm as stcomm_id, s.fk_prospectlevel, s.prefix_comm, s.client, s.fournisseur, s.canvas, s.status as status,";
546 $sql .= " s.email, s.phone, s.phone_mobile, s.fax, s.url, s.siren as idprof1, s.siret as idprof2, s.ape as idprof3, s.idprof4 as idprof4, s.idprof5 as idprof5, s.idprof6 as idprof6, s.tva_intra, s.fk_pays,";
547 $sql .= " s.tms as date_modification, s.datec as date_creation, s.import_key,";
548 $sql .= " s.code_compta, s.code_compta_fournisseur, s.parent as fk_parent,s.price_level,";
549 $sql .= " s2.nom as name2,";
550 $sql .= " typent.code as typent_code,";
551 $sql .= " staff.code as staff_code,";
552 $sql .= " country.code as country_code, country.label as country_label,";
553 $sql .= " state.code_departement as state_code, state.nom as state_name,";
554 $sql .= " region.code_region as region_code, region.nom as region_name";
555 // Add fields from extrafields
556 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
557  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
558  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
559  }
560 }
561 // Add fields from hooks
562 $parameters = array();
563 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
564 $sql .= $hookmanager->resPrint;
565 $sql = preg_replace('/,\s*$/', '', $sql);
566 //$sql .= ", COUNT(rc.rowid) as anotherfield";
567 
568 $sqlfields = $sql; // $sql fields to remove for count total
569 
570 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
571 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."societe as s2 ON s.parent = s2.rowid";
572 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
573  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (s.rowid = ef.fk_object)";
574 }
575 
576 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
577 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
578 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_effectif as staff on (staff.id = s.fk_effectif)";
579 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
580 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_regions as region on (region.code_region = state.fk_region)";
581 $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."c_stcomm as st ON s.fk_stcomm = st.id";
582 // Add table from hooks
583 $parameters = array();
584 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
585 $sql .= $hookmanager->resPrint;
586 $sql .= " WHERE s.entity IN (".getEntity('societe').")";
587 if (!$user->hasRight('fournisseur', 'lire')) {
588  $sql .= " AND (s.fournisseur <> 1 OR s.client <> 0)"; // client=0, fournisseur=0 must be visible
589 }
590 // Search on sale representative
591 if ($search_sale && $search_sale != '-1') {
592  if ($search_sale == -2) {
593  $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid)";
594  } elseif ($search_sale > 0) {
595  $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = s.rowid AND sc.fk_user = ".((int) $search_sale).")";
596  }
597 }
598 
599 // Search for tag/category ($searchCategoryCustomerList is an array of ID)
600 if (!empty($searchCategoryCustomerList)) {
601  $searchCategoryCustomerSqlList = array();
602  $listofcategoryid = '';
603  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
604  if (intval($searchCategoryCustomer) == -2) {
605  $searchCategoryCustomerSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_societe as ck WHERE s.rowid = ck.fk_soc)";
606  } elseif (intval($searchCategoryCustomer) > 0) {
607  if ($searchCategoryCustomerOperator == 0) {
608  $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).")";
609  } else {
610  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryCustomer);
611  }
612  }
613  }
614  if ($listofcategoryid) {
615  $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)."))";
616  }
617  if ($searchCategoryCustomerOperator == 1) {
618  if (!empty($searchCategoryCustomerSqlList)) {
619  $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
620  }
621  } else {
622  if (!empty($searchCategoryCustomerSqlList)) {
623  $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
624  }
625  }
626 }
627 
628 // Search for tag/category ($searchCategorySupplierList is an array of ID)
629 if (!empty($searchCategorySupplierList)) {
630  $searchCategorySupplierSqlList = array();
631  $listofcategoryid = '';
632  foreach ($searchCategorySupplierList as $searchCategorySupplier) {
633  if (intval($searchCategorySupplier) == -2) {
634  $searchCategorySupplierSqlList[] = "NOT EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc)";
635  } elseif (intval($searchCategorySupplier) > 0) {
636  if ($searchCategorySupplierOperator == 0) {
637  $searchCategorySupplierSqlList[] = " EXISTS (SELECT ck.fk_soc FROM ".MAIN_DB_PREFIX."categorie_fournisseur as ck WHERE s.rowid = ck.fk_soc AND ck.fk_categorie = ".((int) $searchCategorySupplier).")";
638  } else {
639  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategorySupplier);
640  }
641  }
642  }
643  if ($listofcategoryid) {
644  $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)."))";
645  }
646  if ($searchCategorySupplierOperator == 1) {
647  if (!empty($searchCategorySupplierSqlList)) {
648  $sql .= " AND (".implode(' OR ', $searchCategorySupplierSqlList).")";
649  }
650  } else {
651  if (!empty($searchCategorySupplierSqlList)) {
652  $sql .= " AND (".implode(' AND ', $searchCategorySupplierSqlList).")";
653  }
654  }
655 }
656 if ($search_all) {
657  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
658 }
659 if (strlen($search_cti)) {
660  $sql .= natural_search('s.phone', $search_cti);
661 }
662 if ($search_id > 0) {
663  $sql .= natural_search("s.rowid", $search_id, 1);
664 }
665 if (empty($arrayfields['s.name_alias']['checked']) && $search_nom) {
666  $sql .= natural_search(array("s.nom", "s.name_alias"), $search_nom);
667 } else {
668  if ($search_nom) {
669  $sql .= natural_search("s.nom", $search_nom);
670  }
671 
672  if ($search_alias) {
673  $sql .= natural_search("s.name_alias", $search_alias);
674  }
675 }
676 if ($search_nom_only) {
677  $sql .= natural_search("s.nom", $search_nom_only);
678 }
679 if ($search_customer_code) {
680  $sql .= natural_search("s.code_client", $search_customer_code);
681 }
682 if ($search_supplier_code) {
683  $sql .= natural_search("s.code_fournisseur", $search_supplier_code);
684 }
685 if ($search_account_customer_code) {
686  $sql .= natural_search("s.code_compta", $search_account_customer_code);
687 }
688 if ($search_account_supplier_code) {
689  $sql .= natural_search("s.code_compta_fournisseur", $search_account_supplier_code);
690 }
691 if ($search_address) {
692  $sql .= natural_search('s.address', $search_address);
693 }
694 if (strlen($search_zip)) {
695  $sql .= natural_search("s.zip", $search_zip);
696 }
697 if ($search_town) {
698  $sql .= natural_search("s.town", $search_town);
699 }
700 if ($search_state) {
701  $sql .= natural_search("state.nom", $search_state);
702 }
703 if ($search_region) {
704  $sql .= natural_search("region.nom", $search_region);
705 }
706 if ($search_country && $search_country != '-1') {
707  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
708 }
709 if ($search_email) {
710  $sql .= natural_search("s.email", $search_email);
711 }
712 if (strlen($search_phone)) {
713  $sql .= natural_search("s.phone", $search_phone);
714 }
715 if (strlen($search_phone_mobile)) {
716  $sql .= natural_search("s.phone_mobile", $search_phone_mobile);
717 }
718 if (strlen($search_fax)) {
719  $sql .= natural_search("s.fax", $search_fax);
720 }
721 if ($search_url) {
722  $sql .= natural_search("s.url", $search_url);
723 }
724 if (strlen($search_idprof1)) {
725  $sql .= natural_search("s.siren", $search_idprof1);
726 }
727 if (strlen($search_idprof2)) {
728  $sql .= natural_search("s.siret", $search_idprof2);
729 }
730 if (strlen($search_idprof3)) {
731  $sql .= natural_search("s.ape", $search_idprof3);
732 }
733 if (strlen($search_idprof4)) {
734  $sql .= natural_search("s.idprof4", $search_idprof4);
735 }
736 if (strlen($search_idprof5)) {
737  $sql .= natural_search("s.idprof5", $search_idprof5);
738 }
739 if (strlen($search_idprof6)) {
740  $sql .= natural_search("s.idprof6", $search_idprof6);
741 }
742 if (strlen($search_vat)) {
743  $sql .= natural_search("s.tva_intra", $search_vat);
744 }
745 // Filter on type of thirdparty
746 if ($search_type > 0 && in_array($search_type, array('1,3', '1,2,3', '2,3'))) {
747  $sql .= " AND s.client IN (".$db->sanitize($search_type).")";
748 }
749 if ($search_type > 0 && in_array($search_type, array('4'))) {
750  $sql .= " AND s.fournisseur = 1";
751 }
752 if ($search_type == '0') {
753  $sql .= " AND s.client = 0 AND s.fournisseur = 0";
754 }
755 if ($search_status != '' && $search_status >= 0) {
756  $sql .= natural_search("s.status", $search_status, 2);
757 }
758 if (isModEnabled('barcode') && $search_barcode) {
759  $sql .= natural_search("s.barcode", $search_barcode);
760 }
761 if ($search_price_level && $search_price_level != '-1') {
762  $sql .= natural_search("s.price_level", $search_price_level, 2);
763 }
764 if ($search_type_thirdparty && $search_type_thirdparty > 0) {
765  $sql .= natural_search("s.fk_typent", $search_type_thirdparty, 2);
766 }
767 if (!empty($search_staff) && $search_staff != '-1') {
768  $sql .= natural_search("s.fk_effectif", $search_staff, 2);
769 }
770 if ($search_parent_name) {
771  $sql .= natural_search("s2.nom", $search_parent_name);
772 }
773 if ($search_level) {
774  $sql .= natural_search("s.fk_prospectlevel", implode(',', $search_level), 3);
775 }
776 if ($search_stcomm) {
777  $sql .= natural_search("s.fk_stcomm", implode(',', $search_stcomm), 2);
778 }
779 if ($search_import_key) {
780  $sql .= natural_search("s.import_key", $search_import_key);
781 }
782 if ($search_date_creation_start) {
783  $sql .= " AND s.datec >= '".$db->idate($search_date_creation_start)."'";
784 }
785 if ($search_date_creation_end) {
786  $sql .= " AND s.datec <= '".$db->idate($search_date_creation_end)."'";
787 }
788 
789 if ($search_date_modif_start) {
790  $sql .= " AND s.tms >= '".$db->idate($search_date_modif_start)."'";
791 }
792 if ($search_date_modif_end) {
793  $sql .= " AND s.tms <= '".$db->idate($search_date_modif_end)."'";
794 }
795 
796 // Add where from extra fields
797 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
798 // Add where from hooks
799 $parameters = array('socid' => $socid);
800 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
801 if (empty($reshook)) {
802  if ($socid) {
803  $sql .= " AND s.rowid = ".((int) $socid);
804  }
805 }
806 $sql .= $hookmanager->resPrint;
807 
808 // Add GroupBy from hooks
809 $parameters = array('fieldstosearchall' => $fieldstosearchall);
810 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
811 $sql .= $hookmanager->resPrint;
812 
813 // Count total nb of records
814 $nbtotalofrecords = '';
815 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
816  /* The fast and low memory method to get and count full list converts the sql into a sql count */
817  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
818  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
819  $resql = $db->query($sqlforcount);
820  if ($resql) {
821  $objforcount = $db->fetch_object($resql);
822  $nbtotalofrecords = $objforcount->nbtotalofrecords;
823  } else {
824  dol_print_error($db);
825  }
826 
827  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
828  $page = 0;
829  $offset = 0;
830  }
831  $db->free($resql);
832 }
833 
834 // Complete request and execute it with limit
835 $sql .= $db->order($sortfield, $sortorder);
836 if ($limit) {
837  $sql .= $db->plimit($limit + 1, $offset);
838 }
839 
840 $resql = $db->query($sql);
841 if (!$resql) {
842  dol_print_error($db);
843  exit;
844 }
845 
846 $num = $db->num_rows($resql);
847 
848 
849 // Direct jump if only one record found
850 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && ($search_all != '' || $search_cti != '') && $action != 'list') {
851  $obj = $db->fetch_object($resql);
852  $id = $obj->rowid;
853  if (getDolGlobalString('SOCIETE_ON_SEARCH_AND_LIST_GO_ON_CUSTOMER_OR_SUPPLIER_CARD')) {
854  if ($obj->client > 0) {
855  header("Location: ".DOL_URL_ROOT.'/comm/card.php?socid='.$id);
856  exit;
857  }
858  if ($obj->fournisseur > 0) {
859  header("Location: ".DOL_URL_ROOT.'/fourn/card.php?socid='.$id);
860  exit;
861  }
862  }
863 
864  header("Location: ".DOL_URL_ROOT.'/societe/card.php?socid='.$id);
865  exit;
866 }
867 
868 // Output page
869 // --------------------------------------------------------------------
870 
871 $paramsCat = '';
872 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
873  $paramsCat .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
874 }
875 foreach ($searchCategorySupplierList as $searchCategorySupplier) {
876  $paramsCat .= "&search_category_supplier_list[]=".urlencode($searchCategorySupplier);
877 }
878 
879 llxHeader('', $title, $help_url, '', 0, 0, array(), array(), $paramsCat);
880 
881 
882 $arrayofselected = is_array($toselect) ? $toselect : array();
883 
884 $param = '';
885 if (!empty($mode)) {
886  $param .= '&mode='.urlencode($mode);
887 }
888 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
889  $param .= '&contextpage='.urlencode($contextpage);
890 }
891 if ($limit > 0 && $limit != $conf->liste_limit) {
892  $param .= '&limit='.((int) $limit);
893 }
894 if ($optioncss != '') {
895  $param .= '&optioncss='.urlencode($optioncss);
896 }
897 if ($search_all != '') {
898  $param = "&search_all=".urlencode($search_all);
899 }
900 if ($search_categ_cus > 0) {
901  $param .= '&search_categ_cus='.urlencode((string) ($search_categ_cus));
902 }
903 if ($search_categ_sup > 0) {
904  $param .= '&search_categ_sup='.urlencode((string) ($search_categ_sup));
905 }
906 if ($searchCategoryCustomerOperator == 1) {
907  $param .= "&search_category_customer_operator=".urlencode((string) ($searchCategoryCustomerOperator));
908 }
909 if ($searchCategorySupplierOperator == 1) {
910  $param .= "&search_category_supplier_operator=".urlencode((string) ($searchCategorySupplierOperator));
911 }
912 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
913  $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
914 }
915 foreach ($searchCategorySupplierList as $searchCategorySupplier) {
916  $param .= "&search_category_supplier_list[]=".urlencode($searchCategorySupplier);
917 }
918 if ($search_sale > 0) {
919  $param .= '&search_sale='.((int) $search_sale);
920 }
921 if ($search_id > 0) {
922  $param .= "&search_id=".((int) $search_id);
923 }
924 if ($search_nom != '') {
925  $param .= "&search_nom=".urlencode($search_nom);
926 }
927 if ($search_alias != '') {
928  $param .= "&search_alias=".urlencode($search_alias);
929 }
930 if ($search_address != '') {
931  $param .= '&search_address='.urlencode($search_address);
932 }
933 if ($search_zip != '') {
934  $param .= "&search_zip=".urlencode($search_zip);
935 }
936 if ($search_town != '') {
937  $param .= "&search_town=".urlencode($search_town);
938 }
939 if ($search_phone != '') {
940  $param .= "&search_phone=".urlencode($search_phone);
941 }
942 if ($search_phone_mobile != '') {
943  $param .= "&search_phone_mobile=".urlencode($search_phone_mobile);
944 }
945 if ($search_fax != '') {
946  $param .= "&search_fax=".urlencode($search_fax);
947 }
948 if ($search_email != '') {
949  $param .= "&search_email=".urlencode($search_email);
950 }
951 if ($search_url != '') {
952  $param .= "&search_url=".urlencode($search_url);
953 }
954 if ($search_state != '') {
955  $param .= "&search_state=".urlencode($search_state);
956 }
957 if ($search_region != '') {
958  $param .= "&search_region=".urlencode($search_region);
959 }
960 if ($search_country != '') {
961  $param .= "&search_country=".urlencode($search_country);
962 }
963 if ($search_customer_code != '') {
964  $param .= "&search_customer_code=".urlencode($search_customer_code);
965 }
966 if ($search_supplier_code != '') {
967  $param .= "&search_supplier_code=".urlencode($search_supplier_code);
968 }
969 if ($search_account_customer_code != '') {
970  $param .= "&search_account_customer_code=".urlencode($search_account_customer_code);
971 }
972 if ($search_account_supplier_code != '') {
973  $param .= "&search_account_supplier_code=".urlencode($search_account_supplier_code);
974 }
975 if ($search_barcode != '') {
976  $param .= "&search_barcode=".urlencode($search_barcode);
977 }
978 if ($search_idprof1 != '') {
979  $param .= '&search_idprof1='.urlencode($search_idprof1);
980 }
981 if ($search_idprof2 != '') {
982  $param .= '&search_idprof2='.urlencode($search_idprof2);
983 }
984 if ($search_idprof3 != '') {
985  $param .= '&search_idprof3='.urlencode($search_idprof3);
986 }
987 if ($search_idprof4 != '') {
988  $param .= '&search_idprof4='.urlencode($search_idprof4);
989 }
990 if ($search_idprof5 != '') {
991  $param .= '&search_idprof5='.urlencode($search_idprof5);
992 }
993 if ($search_idprof6 != '') {
994  $param .= '&search_idprof6='.urlencode($search_idprof6);
995 }
996 if ($search_vat != '') {
997  $param .= '&search_vat='.urlencode($search_vat);
998 }
999 if ($search_price_level != '') {
1000  $param .= '&search_price_level='.urlencode($search_price_level);
1001 }
1002 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
1003  $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
1004 }
1005 if ($search_type != '') {
1006  $param .= '&search_type='.urlencode($search_type);
1007 }
1008 if ($search_status != '') {
1009  $param .= '&search_status='.urlencode((string) ($search_status));
1010 }
1011 if (is_array($search_level) && count($search_level)) {
1012  foreach ($search_level as $slevel) {
1013  $param .= '&search_level[]='.urlencode($slevel);
1014  }
1015 }
1016 if (is_array($search_stcomm) && count($search_stcomm)) {
1017  foreach ($search_stcomm as $slevel) {
1018  $param .= '&search_stcomm[]='.urlencode($slevel);
1019  }
1020 }
1021 if ($search_parent_name != '') {
1022  $param .= '&search_parent_name='.urlencode($search_parent_name);
1023 }
1024 if ($search_import_key != '') {
1025  $param .= '&search_import_key='.urlencode($search_import_key);
1026 }
1027 if ($type != '') {
1028  $param .= '&type='.urlencode($type);
1029 }
1030 if ($search_date_creation_startmonth) {
1031  $param .= '&search_date_creation_startmonth='.urlencode((string) ($search_date_creation_startmonth));
1032 }
1033 if ($search_date_creation_startyear) {
1034  $param .= '&search_date_creation_startyear='.urlencode((string) ($search_date_creation_startyear));
1035 }
1036 if ($search_date_creation_startday) {
1037  $param .= '&search_date_creation_startday='.urlencode((string) ($search_date_creation_startday));
1038 }
1039 if ($search_date_creation_start) {
1040  $param .= '&search_date_creation_start='.urlencode($search_date_creation_start);
1041 }
1042 if ($search_date_creation_endmonth) {
1043  $param .= '&search_date_creation_endmonth='.urlencode((string) ($search_date_creation_endmonth));
1044 }
1045 if ($search_date_creation_endyear) {
1046  $param .= '&search_date_creation_endyear='.urlencode((string) ($search_date_creation_endyear));
1047 }
1048 if ($search_date_creation_endday) {
1049  $param .= '&search_date_creation_endday='.urlencode((string) ($search_date_creation_endday));
1050 }
1051 if ($search_date_creation_end) {
1052  $param .= '&search_date_creation_end='.urlencode($search_date_creation_end);
1053 }
1054 if ($search_date_modif_startmonth) {
1055  $param .= '&search_date_modif_startmonth='.urlencode((string) ($search_date_modif_startmonth));
1056 }
1057 if ($search_date_modif_startyear) {
1058  $param .= '&search_date_modif_startyear='.urlencode((string) ($search_date_modif_startyear));
1059 }
1060 if ($search_date_modif_startday) {
1061  $param .= '&search_date_modif_startday='.urlencode((string) ($search_date_modif_startday));
1062 }
1063 if ($search_date_modif_start) {
1064  $param .= '&search_date_modif_start='.urlencode($search_date_modif_start);
1065 }
1066 if ($search_date_modif_endmonth) {
1067  $param .= '&search_date_modif_endmonth='.urlencode((string) ($search_date_modif_endmonth));
1068 }
1069 if ($search_date_modif_endyear) {
1070  $param .= '&search_date_modif_endyear='.urlencode((string) ($search_date_modif_endyear));
1071 }
1072 if ($search_date_modif_endday) {
1073  $param .= '&search_date_modif_endday='.urlencode((string) ($search_date_modif_endday));
1074 }
1075 if ($search_date_modif_end) {
1076  $param .= '&search_date_modif_end=' . urlencode($search_date_modif_end);
1077 }
1078 
1079 // Add $param from extra fields
1080 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
1081 // Add $param from hooks
1082 $parameters = array();
1083 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1084 $param .= $hookmanager->resPrint;
1085 
1086 // Show delete result message
1087 if (GETPOST('delsoc')) {
1088  setEventMessages($langs->trans("CompanyDeleted", GETPOST('delsoc')), null, 'mesgs');
1089 }
1090 
1091 // List of mass actions available
1092 $arrayofmassactions = array(
1093  'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
1094  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
1095 );
1096 //if($user->rights->societe->creer) $arrayofmassactions['createbills']=$langs->trans("CreateInvoiceForThisCustomer");
1097 if (isModEnabled('category') && $user->hasRight("societe", "creer")) {
1098  $arrayofmassactions['preaffecttag'] = img_picto('', 'category', 'class="pictofixedwidth"').$langs->trans("AffectTag");
1099 }
1100 if ($user->hasRight("societe", "creer")) {
1101  $arrayofmassactions['preenable'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SetToStatus", $object->LibStatut($object::STATUS_INACTIVITY));
1102 }
1103 if ($user->hasRight("societe", "creer")) {
1104  $arrayofmassactions['predisable'] = img_picto('', 'stop-circle', 'class="pictofixedwidth"').$langs->trans("SetToStatus", $object->LibStatut($object::STATUS_CEASED));
1105 }
1106 if ($user->hasRight("societe", "creer")) {
1107  $arrayofmassactions['presetcommercial'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("AllocateCommercial");
1108  $arrayofmassactions['unsetcommercial'] = img_picto('', 'user', 'class="pictofixedwidth"').$langs->trans("UnallocateCommercial");
1109 }
1110 
1111 if ($user->hasRight('societe', 'supprimer')) {
1112  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
1113 }
1114 if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete', 'preaffecttag', 'preenable', 'preclose'))) {
1115  $arrayofmassactions = array();
1116 }
1117 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
1118 
1119 $typefilter = '';
1120 $label = 'MenuNewThirdParty';
1121 
1122 if (!empty($type)) {
1123  $typefilter = '&amp;type='.$type;
1124  if ($type == 'p') {
1125  $label = 'MenuNewProspect';
1126  }
1127  if ($type == 'c') {
1128  $label = 'MenuNewCustomer';
1129  }
1130  if ($type == 'f') {
1131  $label = 'NewSupplier';
1132  }
1133 }
1134 
1135 if ($contextpage == 'poslist' && $type == 't' && (getDolGlobalString('PRODUIT_MULTIPRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES') || getDolGlobalString('PRODUIT_CUSTOMER_PRICES_BY_QTY_MULTIPRICES'))) {
1136  print get_htmloutput_mesg(img_warning('default').' '.$langs->trans("BecarefullChangeThirdpartyBeforeAddProductToInvoice"), '', 'warning', 1);
1137 }
1138 
1139 // Show the new button only when this page is not opend from the Extended POS (pop-up window)
1140 // but allow it too, when a user has the rights to create a new customer
1141 if ($contextpage != 'poslist') {
1142  $url = DOL_URL_ROOT.'/societe/card.php?action=create'.$typefilter;
1143  if (!empty($socid)) {
1144  $url .= '&socid='.$socid;
1145  }
1146  $newcardbutton = '';
1147  $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'));
1148  $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'));
1149  $newcardbutton .= dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url, '', $user->hasRight('societe', 'creer'));
1150 } elseif ($user->hasRight('societe', 'creer')) {
1151  $url = DOL_URL_ROOT.'/societe/card.php?action=create&type=t&contextpage=poslist&optioncss=print&backtopage='.urlencode($_SERVER["PHP_SELF"].'?type=t&contextpage=poslist&nomassaction=1&optioncss=print&place='.$place);
1152  $label = 'MenuNewCustomer';
1153  $newcardbutton = dolGetButtonTitle($langs->trans($label), '', 'fa fa-plus-circle', $url);
1154 }
1155 
1156 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" name="formfilter" autocomplete="off">'."\n";
1157 if ($optioncss != '') {
1158  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
1159 }
1160 print '<input type="hidden" name="token" value="'.newToken().'">';
1161 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
1162 print '<input type="hidden" name="action" value="list">';
1163 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
1164 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
1165 //print '<input type="hidden" name="page" value="'.$page.'">';
1166 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
1167 if (!empty($place)) {
1168  print '<input type="hidden" name="place" value="'.$place.'">';
1169 }
1170 print '<input type="hidden" name="page_y" value="">';
1171 print '<input type="hidden" name="mode" value="'.$mode.'">';
1172 if (empty($arrayfields['customerorsupplier']['checked'])) {
1173  print '<input type="hidden" name="type" value="'.$type.'">';
1174 }
1175 if (!empty($place)) {
1176  print '<input type="hidden" name="place" value="'.$place.'">';
1177 }
1178 
1179 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'building', 0, $newcardbutton, '', $limit, 0, 0, 1);
1180 
1181 $langs->load("other");
1182 $textprofid = array();
1183 foreach (array(1, 2, 3, 4, 5, 6) as $key) {
1184  $label = $langs->transnoentities("ProfId".$key.$mysoc->country_code);
1185  $textprofid[$key] = '';
1186  if ($label != "ProfId".$key.$mysoc->country_code) { // Get only text between ()
1187  if (preg_match('/\‍((.*)\‍)/i', $label, $reg)) {
1188  $label = $reg[1];
1189  }
1190  // @phan-suppress-next-line PhanPluginSuspiciousParamPosition
1191  $textprofid[$key] = $langs->trans("ProfIdShortDesc", $key, $mysoc->country_code, $label);
1192  }
1193 }
1194 
1195 // Add code for pre mass action (confirmation or email presend form)
1196 $topicmail = "Information";
1197 $modelmail = "thirdparty";
1198 $objecttmp = new Societe($db);
1199 $trackid = 'thi'.$object->id;
1200 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
1201 
1202 /*
1203 if (!empty($search_categ_cus) || !empty($search_categ_sup)) {
1204  print "<div id='ways'>";
1205  $c = new Categorie($db);
1206  $ways = $c->print_all_ways(' &gt; ', 'societe/list.php');
1207  print " &gt; ".$ways[0]."<br>\n";
1208  print "</div><br>";
1209 }
1210 */
1211 
1212 if ($search_all) {
1213  $setupstring = '';
1214  foreach ($fieldstosearchall as $key => $val) {
1215  $fieldstosearchall[$key] = $langs->trans($val);
1216  $setupstring .= $key."=".$val.";";
1217  }
1218  print '<!-- Search done like if SOCIETE_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
1219  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>';
1220 }
1221 
1222 // Filter on categories
1223 $moreforfilter = '';
1224 if (empty($type) || $type == 'c' || $type == 'p') {
1225  if (isModEnabled('category') && $user->hasRight('categorie', 'read')) {
1226  $formcategory = new FormCategory($db);
1227  $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_CUSTOMER, $searchCategoryCustomerList, 'minwidth300', $searchCategoryCustomerOperator ? $searchCategoryCustomerOperator : 0);
1228  }
1229 }
1230 
1231 if (empty($type) || $type == 'f') {
1232  if (isModEnabled("fournisseur") && isModEnabled('category') && $user->hasRight('categorie', 'read')) {
1233  $formcategory = new FormCategory($db);
1234  $moreforfilter .= $formcategory->getFilterBox(Categorie::TYPE_SUPPLIER, $searchCategorySupplierList, 'minwidth300', $searchCategorySupplierOperator ? $searchCategorySupplierOperator : 0);
1235  }
1236 }
1237 
1238 // If the user can view prospects other than his'
1239 if ($user->hasRight("societe", "client", "voir") || $socid) {
1240  $moreforfilter .= '<div class="divsearchfield">';
1241  $tmptitle = $langs->trans('SalesRepresentatives');
1242  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"');
1243  $moreforfilter .= $formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $langs->trans('SalesRepresentatives'), ($conf->dol_optimize_smallscreen ? 'maxwidth200' : 'maxwidth300'), 1);
1244  $moreforfilter .= '</div>';
1245 }
1246 if (!empty($moreforfilter)) {
1247  print '<div class="liste_titre liste_titre_bydiv centpercent">';
1248  print $moreforfilter;
1249  $parameters = array('type' => $type);
1250  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1251  print $hookmanager->resPrint;
1252  print '</div>';
1253 }
1254 
1255 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1256 $htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
1257 $selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
1258 $selectedfields .= ((count($arrayofmassactions) && $contextpage != 'poslist') ? $form->showCheckAddButtons('checkforselect', 1) : '');
1259 
1260 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
1261 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1262 
1263 // Fields title search
1264 // --------------------------------------------------------------------
1265 print '<tr class="liste_titre_filter">';
1266 // Action column
1267 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1268  print '<td class="liste_titre maxwidthsearch center actioncolumn">';
1269  $searchpicto = $form->showFilterButtons('left');
1270  print $searchpicto;
1271  print '</td>';
1272 }
1273 if (!empty($arrayfields['s.rowid']['checked'])) {
1274  print '<td class="liste_titre" data-key="id">';
1275  print '<input class="flat searchstring" type="text" name="search_id" size="1" value="'.dol_escape_htmltag($search_id).'">';
1276  print '</td>';
1277 }
1278 if (!empty($arrayfields['s.nom']['checked'])) {
1279  print '<td class="liste_titre" data-key="ref">';
1280  if (!empty($search_nom_only) && empty($search_nom)) {
1281  $search_nom = $search_nom_only;
1282  }
1283  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_nom" value="'.dol_escape_htmltag($search_nom).'">';
1284  print '</td>';
1285 }
1286 if (!empty($arrayfields['s.name_alias']['checked'])) {
1287  print '<td class="liste_titre">';
1288  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_alias" value="'.dol_escape_htmltag($search_alias).'">';
1289  print '</td>';
1290 }
1291 // Barcode
1292 if (!empty($arrayfields['s.barcode']['checked'])) {
1293  print '<td class="liste_titre">';
1294  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_barcode" value="'.dol_escape_htmltag($search_barcode).'">';
1295  print '</td>';
1296 }
1297 // Customer code
1298 if (!empty($arrayfields['s.code_client']['checked'])) {
1299  print '<td class="liste_titre">';
1300  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_customer_code" value="'.dol_escape_htmltag($search_customer_code).'">';
1301  print '</td>';
1302 }
1303 // Supplier code
1304 if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
1305  print '<td class="liste_titre">';
1306  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_supplier_code" value="'.dol_escape_htmltag($search_supplier_code).'">';
1307  print '</td>';
1308 }
1309 // Account Customer code
1310 if (!empty($arrayfields['s.code_compta']['checked'])) {
1311  print '<td class="liste_titre">';
1312  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_account_customer_code" value="'.dol_escape_htmltag($search_account_customer_code).'">';
1313  print '</td>';
1314 }
1315 // Account Supplier code
1316 if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
1317  print '<td class="liste_titre">';
1318  print '<input class="flat maxwidth75imp" type="text" name="search_account_supplier_code" value="'.dol_escape_htmltag($search_account_supplier_code).'">';
1319  print '</td>';
1320 }
1321 // Address
1322 if (!empty($arrayfields['s.address']['checked'])) {
1323  print '<td class="liste_titre">';
1324  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_address" value="'.dol_escape_htmltag($search_address).'">';
1325  print '</td>';
1326 }
1327 // Sales representatives
1328 if (!empty($arrayfields['sales.representative']['checked'])) {
1329  print '<td class="liste_titre">';
1330  print '</td>';
1331 }
1332 // Zip
1333 if (!empty($arrayfields['s.zip']['checked'])) {
1334  print '<td class="liste_titre">';
1335  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_zip" value="'.dol_escape_htmltag($search_zip).'">';
1336  print '</td>';
1337 }
1338 // Town
1339 if (!empty($arrayfields['s.town']['checked'])) {
1340  print '<td class="liste_titre">';
1341  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_town" value="'.dol_escape_htmltag($search_town).'">';
1342  print '</td>';
1343 }
1344 // State
1345 if (!empty($arrayfields['state.nom']['checked'])) {
1346  print '<td class="liste_titre">';
1347  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1348  print '</td>';
1349 }
1350 // Region
1351 if (!empty($arrayfields['region.nom']['checked'])) {
1352  print '<td class="liste_titre">';
1353  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_region" value="'.dol_escape_htmltag($search_region).'">';
1354  print '</td>';
1355 }
1356 // Country
1357 if (!empty($arrayfields['country.code_iso']['checked'])) {
1358  print '<td class="liste_titre center">';
1359  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1360  print '</td>';
1361 }
1362 // Company type
1363 if (!empty($arrayfields['typent.code']['checked'])) {
1364  print '<td class="liste_titre maxwidthonsmartphone center">';
1365  // We use showempty=0 here because there is already an unknown value into dictionary.
1366  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (!getDolGlobalString('SOCIETE_SORT_ON_TYPEENT') ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), 'minwidth50 maxwidth125', 1);
1367  print '</td>';
1368 }
1369 // Multiprice level
1370 if (!empty($arrayfields['s.price_level']['checked'])) {
1371  print '<td class="liste_titre">';
1372  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_price_level" value="'.dol_escape_htmltag($search_price_level).'">';
1373  print '</td>';
1374 }
1375 // Staff
1376 if (!empty($arrayfields['staff.code']['checked'])) {
1377  print '<td class="liste_titre maxwidthonsmartphone center">';
1378  print $form->selectarray("search_staff", $formcompany->effectif_array(0), $search_staff, 0, 0, 0, '', 0, 0, 0, 'ASC', 'maxwidth100', 1);
1379  print '</td>';
1380 }
1381 if (!empty($arrayfields['s.email']['checked'])) {
1382  // Email
1383  print '<td class="liste_titre">';
1384  print '<input class="flat searchemail maxwidth50imp" type="text" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
1385  print '</td>';
1386 }
1387 if (!empty($arrayfields['s.phone']['checked'])) {
1388  // Phone
1389  print '<td class="liste_titre">';
1390  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_phone" value="'.dol_escape_htmltag($search_phone).'">';
1391  print '</td>';
1392 }
1393 if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1394  // PhoneMobile
1395  print '<td class="liste_titre">';
1396  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_phone_mobile" value="'.dol_escape_htmltag($search_phone_mobile).'">';
1397  print '</td>';
1398 }
1399 if (!empty($arrayfields['s.fax']['checked'])) {
1400  // Fax
1401  print '<td class="liste_titre">';
1402  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_fax" value="'.dol_escape_htmltag($search_fax).'">';
1403  print '</td>';
1404 }
1405 if (!empty($arrayfields['s.url']['checked'])) {
1406  // Url
1407  print '<td class="liste_titre">';
1408  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_url" value="'.dol_escape_htmltag($search_url).'">';
1409  print '</td>';
1410 }
1411 if (!empty($arrayfields['s.siren']['checked'])) {
1412  // IdProf1
1413  print '<td class="liste_titre">';
1414  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof1" value="'.dol_escape_htmltag($search_idprof1).'">';
1415  print '</td>';
1416 }
1417 if (!empty($arrayfields['s.siret']['checked'])) {
1418  // IdProf2
1419  print '<td class="liste_titre">';
1420  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof2" value="'.dol_escape_htmltag($search_idprof2).'">';
1421  print '</td>';
1422 }
1423 if (!empty($arrayfields['s.ape']['checked'])) {
1424  // IdProf3
1425  print '<td class="liste_titre">';
1426  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof3" value="'.dol_escape_htmltag($search_idprof3).'">';
1427  print '</td>';
1428 }
1429 if (!empty($arrayfields['s.idprof4']['checked'])) {
1430  // IdProf4
1431  print '<td class="liste_titre">';
1432  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof4" value="'.dol_escape_htmltag($search_idprof4).'">';
1433  print '</td>';
1434 }
1435 if (!empty($arrayfields['s.idprof5']['checked'])) {
1436  // IdProf5
1437  print '<td class="liste_titre">';
1438  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof5" value="'.dol_escape_htmltag($search_idprof5).'">';
1439  print '</td>';
1440 }
1441 if (!empty($arrayfields['s.idprof6']['checked'])) {
1442  // IdProf6
1443  print '<td class="liste_titre">';
1444  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_idprof6" value="'.dol_escape_htmltag($search_idprof6).'">';
1445  print '</td>';
1446 }
1447 if (!empty($arrayfields['s.tva_intra']['checked'])) {
1448  // Vat number
1449  print '<td class="liste_titre">';
1450  print '<input class="flat searchstring maxwidth50imp" type="text" name="search_vat" value="'.dol_escape_htmltag($search_vat).'">';
1451  print '</td>';
1452 }
1453 
1454 // Nature (customer/prospect/supplier)
1455 if (!empty($arrayfields['customerorsupplier']['checked'])) {
1456  print '<td class="liste_titre maxwidthonsmartphone center">';
1457  if ($type != '') {
1458  print '<input type="hidden" name="type" value="'.$type.'">';
1459  }
1460  print $formcompany->selectProspectCustomerType($search_type, 'search_type', 'search_type', 'list');
1461  print '</td>';
1462 }
1463 // Prospect level
1464 if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
1465  print '<td class="liste_titre center">';
1466  print $form->multiselectarray('search_level', $tab_level, $search_level, 0, 0, 'width75', 0, 0, '', '', '', 2);
1467  print '</td>';
1468 }
1469 // Prospect status
1470 if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
1471  print '<td class="liste_titre maxwidthonsmartphone center">';
1472  $arraystcomm = array();
1473  foreach ($prospectstatic->cacheprospectstatus as $key => $val) {
1474  $arraystcomm[$val['id']] = ($langs->trans("StatusProspect".$val['id']) != "StatusProspect".$val['id'] ? $langs->trans("StatusProspect".$val['id']) : $val['label']);
1475  }
1476  //print $form->selectarray('search_stcomm', $arraystcomm, $search_stcomm, -2, 0, 0, '', 0, 0, 0, '', '', 1);
1477  print $form->multiselectarray('search_stcomm', $arraystcomm, $search_stcomm, 0, 0, 'width100', 0, 0, '', '', '', 2);
1478  print '</td>';
1479 }
1480 if (!empty($arrayfields['s2.nom']['checked'])) {
1481  print '<td class="liste_titre center">';
1482  print '<input class="flat searchstring maxwidth75imp" type="text" name="search_parent_name" value="'.dol_escape_htmltag($search_parent_name).'">';
1483  print '</td>';
1484 }
1485 // Extra fields
1486 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1487 
1488 // Fields from hook
1489 $parameters = array('arrayfields' => $arrayfields);
1490 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1491 print $hookmanager->resPrint;
1492 // Creation date
1493 if (!empty($arrayfields['s.datec']['checked'])) {
1494  print '<td class="liste_titre center nowraponall">';
1495  print '<div class="nowrapfordate">';
1496  print $form->selectDate($search_date_creation_start ? $search_date_creation_start : -1, 'search_date_creation_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1497  print '</div>';
1498  print '<div class="nowrapfordate">';
1499  print $form->selectDate($search_date_creation_end ? $search_date_creation_end : -1, 'search_date_creation_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1500  print '</div>';
1501  print '</td>';
1502 }
1503 // Modification date
1504 if (!empty($arrayfields['s.tms']['checked'])) {
1505  print '<td class="liste_titre center nowraponall">';
1506  print '<div class="nowrapfordate">';
1507  print $form->selectDate($search_date_modif_start ? $search_date_modif_start : -1, 'search_date_modif_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1508  print '</div>';
1509  print '<div class="nowrapfordate">';
1510  print $form->selectDate($search_date_modif_end ? $search_date_modif_end : -1, 'search_date_modif_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1511  print '</div>';
1512  print '</td>';
1513 }
1514 // Status
1515 if (!empty($arrayfields['s.status']['checked'])) {
1516  print '<td class="liste_titre center minwidth75imp parentonrightofpage">';
1517  print $form->selectarray('search_status', array('0' => $langs->trans('ActivityCeased'), '1' => $langs->trans('InActivity')), $search_status, 1, 0, 0, '', 0, 0, 0, '', 'search_status width100 onrightofpage', 1);
1518  print '</td>';
1519 }
1520 if (!empty($arrayfields['s.import_key']['checked'])) {
1521  print '<td class="liste_titre center">';
1522  print '<input class="flat searchstring maxwidth50" type="text" name="search_import_key" value="'.dol_escape_htmltag($search_import_key).'">';
1523  print '</td>';
1524 }
1525 // Action column
1526 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1527  print '<td class="liste_titre center maxwidthsearch actioncolumn">';
1528  $searchpicto = $form->showFilterButtons();
1529  print $searchpicto;
1530  print '</td>';
1531 }
1532 
1533 print '</tr>'."\n";
1534 
1535 $totalarray = array();
1536 $totalarray['nbfield'] = 0;
1537 
1538 // Fields title label
1539 // --------------------------------------------------------------------
1540 print '<tr class="liste_titre">';
1541 // Action column
1542 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1543  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1544  $totalarray['nbfield']++;
1545 }
1546 if (!empty($arrayfields['s.rowid']['checked'])) {
1547  print_liste_field_titre($arrayfields['s.rowid']['label'], $_SERVER["PHP_SELF"], "s.rowid", "", $param, ' data-key="id"', $sortfield, $sortorder, '');
1548  $totalarray['nbfield']++;
1549 }
1550 if (!empty($arrayfields['s.nom']['checked'])) {
1551  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, ' data-key="ref"', $sortfield, $sortorder, ' ');
1552  $totalarray['nbfield']++;
1553 }
1554 if (!empty($arrayfields['s.name_alias']['checked'])) {
1555  print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], "s.name_alias", "", $param, "", $sortfield, $sortorder);
1556  $totalarray['nbfield']++;
1557 }
1558 if (!empty($arrayfields['s.barcode']['checked'])) {
1559  print_liste_field_titre($arrayfields['s.barcode']['label'], $_SERVER["PHP_SELF"], "s.barcode", $param, '', '', $sortfield, $sortorder);
1560  $totalarray['nbfield']++;
1561 }
1562 if (!empty($arrayfields['s.code_client']['checked'])) {
1563  print_liste_field_titre($arrayfields['s.code_client']['label'], $_SERVER["PHP_SELF"], "s.code_client", "", $param, '', $sortfield, $sortorder);
1564  $totalarray['nbfield']++;
1565 }
1566 if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
1567  print_liste_field_titre($arrayfields['s.code_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_fournisseur", "", $param, '', $sortfield, $sortorder);
1568  $totalarray['nbfield']++;
1569 }
1570 if (!empty($arrayfields['s.code_compta']['checked'])) {
1571  print_liste_field_titre($arrayfields['s.code_compta']['label'], $_SERVER["PHP_SELF"], "s.code_compta", "", $param, '', $sortfield, $sortorder);
1572  $totalarray['nbfield']++;
1573 }
1574 if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
1575  print_liste_field_titre($arrayfields['s.code_compta_fournisseur']['label'], $_SERVER["PHP_SELF"], "s.code_compta_fournisseur", "", $param, '', $sortfield, $sortorder);
1576  $totalarray['nbfield']++;
1577 }
1578 if (!empty($arrayfields['s.address']['checked'])) {
1579  print_liste_field_titre($arrayfields['s.address']['label'], $_SERVER['PHP_SELF'], 's.address', '', $param, '', $sortfield, $sortorder);
1580  $totalarray['nbfield']++;
1581 }
1582 if (!empty($arrayfields['sales.representative']['checked'])) {
1583  print_liste_field_titre($arrayfields['sales.representative']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder);
1584  $totalarray['nbfield']++;
1585 }
1586 if (!empty($arrayfields['s.zip']['checked'])) {
1587  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], "s.zip", "", $param, '', $sortfield, $sortorder);
1588  $totalarray['nbfield']++;
1589 }
1590 if (!empty($arrayfields['s.town']['checked'])) {
1591  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], "s.town", "", $param, '', $sortfield, $sortorder);
1592  $totalarray['nbfield']++;
1593 }
1594 if (!empty($arrayfields['state.nom']['checked'])) {
1595  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1596  $totalarray['nbfield']++;
1597 }
1598 if (!empty($arrayfields['region.nom']['checked'])) {
1599  print_liste_field_titre($arrayfields['region.nom']['label'], $_SERVER["PHP_SELF"], "region.nom", "", $param, '', $sortfield, $sortorder);
1600  $totalarray['nbfield']++;
1601 }
1602 if (!empty($arrayfields['country.code_iso']['checked'])) {
1603  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1604  $totalarray['nbfield']++;
1605 }
1606 if (!empty($arrayfields['typent.code']['checked'])) {
1607  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, "", $sortfield, $sortorder, 'center ');
1608  $totalarray['nbfield']++;
1609 }
1610 if (!empty($arrayfields['staff.code']['checked'])) {
1611  print_liste_field_titre($arrayfields['staff.code']['label'], $_SERVER["PHP_SELF"], "staff.code", "", $param, '', $sortfield, $sortorder, 'center ');
1612  $totalarray['nbfield']++;
1613 }
1614 if (!empty($arrayfields['s.price_level']['checked'])) {
1615  print_liste_field_titre($arrayfields['s.price_level']['label'], $_SERVER["PHP_SELF"], "s.price_level", "", $param, '', $sortfield, $sortorder);
1616  $totalarray['nbfield']++;
1617 }
1618 if (!empty($arrayfields['s.email']['checked'])) {
1619  print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
1620  $totalarray['nbfield']++;
1621 }
1622 if (!empty($arrayfields['s.phone']['checked'])) {
1623  print_liste_field_titre($arrayfields['s.phone']['label'], $_SERVER["PHP_SELF"], "s.phone", "", $param, '', $sortfield, $sortorder);
1624  $totalarray['nbfield']++;
1625 }
1626 if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1627  print_liste_field_titre($arrayfields['s.phone_mobile']['label'], $_SERVER["PHP_SELF"], "s.phone_mobile", "", $param, '', $sortfield, $sortorder);
1628  $totalarray['nbfield']++;
1629 }
1630 if (!empty($arrayfields['s.fax']['checked'])) {
1631  print_liste_field_titre($arrayfields['s.fax']['label'], $_SERVER["PHP_SELF"], "s.fax", "", $param, '', $sortfield, $sortorder);
1632  $totalarray['nbfield']++;
1633 }
1634 if (!empty($arrayfields['s.url']['checked'])) {
1635  print_liste_field_titre($arrayfields['s.url']['label'], $_SERVER["PHP_SELF"], "s.url", "", $param, '', $sortfield, $sortorder);
1636  $totalarray['nbfield']++;
1637 }
1638 if (!empty($arrayfields['s.siren']['checked'])) {
1639  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId1Short"), $textprofid[1], 1, 0), $_SERVER["PHP_SELF"], "s.siren", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1640  $totalarray['nbfield']++;
1641 }
1642 if (!empty($arrayfields['s.siret']['checked'])) {
1643  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId2Short"), $textprofid[2], 1, 0), $_SERVER["PHP_SELF"], "s.siret", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1644  $totalarray['nbfield']++;
1645 }
1646 if (!empty($arrayfields['s.ape']['checked'])) {
1647  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId3Short"), $textprofid[3], 1, 0), $_SERVER["PHP_SELF"], "s.ape", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1648  $totalarray['nbfield']++;
1649 }
1650 if (!empty($arrayfields['s.idprof4']['checked'])) {
1651  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId4Short"), $textprofid[4], 1, 0), $_SERVER["PHP_SELF"], "s.idprof4", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1652  $totalarray['nbfield']++;
1653 }
1654 if (!empty($arrayfields['s.idprof5']['checked'])) {
1655  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId5Short"), $textprofid[5], 1, 0), $_SERVER["PHP_SELF"], "s.idprof5", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1656  $totalarray['nbfield']++;
1657 }
1658 if (!empty($arrayfields['s.idprof6']['checked'])) {
1659  print_liste_field_titre($form->textwithpicto($langs->trans("ProfId6Short"), $textprofid[6], 1, 0), $_SERVER["PHP_SELF"], "s.idprof6", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1660  $totalarray['nbfield']++;
1661 }
1662 if (!empty($arrayfields['s.tva_intra']['checked'])) {
1663  print_liste_field_titre($arrayfields['s.tva_intra']['label'], $_SERVER["PHP_SELF"], "s.tva_intra", "", $param, '', $sortfield, $sortorder, 'nowrap ');
1664  $totalarray['nbfield']++;
1665 }
1666 if (!empty($arrayfields['customerorsupplier']['checked'])) {
1667  print_liste_field_titre($arrayfields['customerorsupplier']['label'], $_SERVER['PHP_SELF'], '', '', $param, '', $sortfield, $sortorder, 'center '); // type of customer
1668  $totalarray['nbfield']++;
1669 }
1670 if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
1671  print_liste_field_titre($arrayfields['s.fk_prospectlevel']['label'], $_SERVER["PHP_SELF"], "s.fk_prospectlevel", "", $param, '', $sortfield, $sortorder, 'center ');
1672  $totalarray['nbfield']++;
1673 }
1674 if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
1675  print_liste_field_titre($arrayfields['s.fk_stcomm']['label'], $_SERVER["PHP_SELF"], "s.fk_stcomm", "", $param, '', $sortfield, $sortorder, 'center ');
1676  $totalarray['nbfield']++;
1677 }
1678 if (!empty($arrayfields['s2.nom']['checked'])) {
1679  print_liste_field_titre($arrayfields['s2.nom']['label'], $_SERVER["PHP_SELF"], "s2.nom", "", $param, '', $sortfield, $sortorder, 'center ');
1680  $totalarray['nbfield']++;
1681 }
1682 // Extra fields
1683 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1684 // Hook fields
1685 $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
1686 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1687 print $hookmanager->resPrint;
1688 if (!empty($arrayfields['s.datec']['checked'])) {
1689  print_liste_field_titre($arrayfields['s.datec']['label'], $_SERVER["PHP_SELF"], "s.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1690  $totalarray['nbfield']++; // For the column action
1691 }
1692 if (!empty($arrayfields['s.tms']['checked'])) {
1693  print_liste_field_titre($arrayfields['s.tms']['label'], $_SERVER["PHP_SELF"], "s.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1694  $totalarray['nbfield']++; // For the column action
1695 }
1696 if (!empty($arrayfields['s.status']['checked'])) {
1697  print_liste_field_titre($arrayfields['s.status']['label'], $_SERVER["PHP_SELF"], "s.status", "", $param, '', $sortfield, $sortorder, 'center ');
1698  $totalarray['nbfield']++; // For the column action
1699 }
1700 if (!empty($arrayfields['s.import_key']['checked'])) {
1701  print_liste_field_titre($arrayfields['s.import_key']['label'], $_SERVER["PHP_SELF"], "s.import_key", "", $param, '', $sortfield, $sortorder, 'center ');
1702  $totalarray['nbfield']++; // For the column action
1703 }
1704 // Action column
1705 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1706  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
1707  $totalarray['nbfield']++;
1708 }
1709 print '</tr>'."\n";
1710 
1711 
1712 // Loop on record
1713 // --------------------------------------------------------------------
1714 $i = 0;
1715 $savnbfield = $totalarray['nbfield'];
1716 $totalarray = array();
1717 $totalarray['nbfield'] = 0;
1718 $imaxinloop = ($limit ? min($num, $limit) : $num);
1719 while ($i < $imaxinloop) {
1720  $obj = $db->fetch_object($resql);
1721  if (empty($obj)) {
1722  break; // Should not happen
1723  }
1724 
1725  $parameters = array('staticdata' => $obj);
1726  // Note that $action and $object may have been modified by hook
1727  // do companystatic fetch in hook if wanted or anything else
1728  $reshook = $hookmanager->executeHooks('loadStaticObject', $parameters, $companystatic, $action);
1729  if (empty($reshook)) {
1730  $companystatic->id = $obj->rowid;
1731  $companystatic->name = $obj->name;
1732  $companystatic->name_alias = $obj->name_alias;
1733  $companystatic->logo = $obj->logo;
1734  $companystatic->barcode = $obj->barcode;
1735  $companystatic->canvas = $obj->canvas;
1736  $companystatic->client = $obj->client;
1737  $companystatic->status = $obj->status;
1738  $companystatic->email = $obj->email;
1739  $companystatic->address = $obj->address;
1740  $companystatic->zip = $obj->zip;
1741  $companystatic->town = $obj->town;
1742  $companystatic->fournisseur = $obj->fournisseur;
1743  $companystatic->code_client = $obj->code_client;
1744  $companystatic->code_fournisseur = $obj->code_fournisseur;
1745  $companystatic->tva_intra = $obj->tva_intra;
1746  $companystatic->country_code = $obj->country_code;
1747 
1748  $companystatic->code_compta_client = $obj->code_compta;
1749  $companystatic->code_compta_fournisseur = $obj->code_compta_fournisseur;
1750 
1751  $companystatic->fk_prospectlevel = $obj->fk_prospectlevel;
1752  $companystatic->parent = $obj->fk_parent;
1753  $companystatic->entity = $obj->entity;
1754 
1755  $object = $companystatic;
1756  }
1757 
1758  if ($mode == 'kanban') {
1759  if ($i == 0) {
1760  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1761  print '<div class="box-flex-container kanban">';
1762  }
1763  // Output Kanban
1764  print $companystatic->getKanbanView('', array('selected' => in_array($obj->rowid, $arrayofselected)));
1765  if ($i == ($imaxinloop - 1)) {
1766  print '</div>';
1767  print '</td></tr>';
1768  }
1769  } else {
1770  // Show line of result
1771  $j = 0;
1772  print '<tr data-rowid="'.$companystatic->id.'" class="oddeven"';
1773  if ($contextpage == 'poslist') {
1774  print ' onclick="location.href=\'list.php?action=change&contextpage=poslist&idcustomer='.$obj->rowid.'&place='.urlencode($place).'\'"';
1775  }
1776  print '>';
1777 
1778  // Action column (Show the massaction button only when this page is not opend from the Extended POS)
1779  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1780  print '<td class="nowrap center actioncolumn">';
1781  if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1782  $selected = 0;
1783  if (in_array($obj->rowid, $arrayofselected)) {
1784  $selected = 1;
1785  }
1786  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1787  }
1788  print '</td>';
1789  if (!$i) {
1790  $totalarray['nbfield']++;
1791  }
1792  }
1793  if (!empty($arrayfields['s.rowid']['checked'])) {
1794  print '<td class="tdoverflowmax50" data-key="id">';
1795  print dol_escape_htmltag($obj->rowid);
1796  print "</td>\n";
1797  if (!$i) {
1798  $totalarray['nbfield']++;
1799  }
1800  }
1801  if (!empty($arrayfields['s.nom']['checked'])) {
1802  print '<td'.(getDolGlobalString('MAIN_SOCIETE_SHOW_COMPLETE_NAME') ? '' : ' class="tdoverflowmax200"').' data-key="ref">';
1803  if ($contextpage == 'poslist') {
1804  print dol_escape_htmltag($companystatic->name);
1805  } else {
1806  print $companystatic->getNomUrl(1, '', 100, 0, 1, empty($arrayfields['s.name_alias']['checked']) ? 0 : 1);
1807  }
1808  print "</td>\n";
1809  if (!$i) {
1810  $totalarray['nbfield']++;
1811  }
1812  }
1813  if (!empty($arrayfields['s.name_alias']['checked'])) {
1814  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->name_alias).'">';
1815  print dol_escape_htmltag($companystatic->name_alias);
1816  print "</td>\n";
1817  if (!$i) {
1818  $totalarray['nbfield']++;
1819  }
1820  }
1821  // Barcode
1822  if (!empty($arrayfields['s.barcode']['checked'])) {
1823  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->barcode).'">'.dol_escape_htmltag($companystatic->barcode).'</td>';
1824  if (!$i) {
1825  $totalarray['nbfield']++;
1826  }
1827  }
1828  // Customer code
1829  if (!empty($arrayfields['s.code_client']['checked'])) {
1830  print '<td class="nowraponall">'.dol_escape_htmltag($companystatic->code_client).'</td>';
1831  if (!$i) {
1832  $totalarray['nbfield']++;
1833  }
1834  }
1835  // Supplier code
1836  if (!empty($arrayfields['s.code_fournisseur']['checked'])) {
1837  print '<td class="nowraponall">'.dol_escape_htmltag($companystatic->code_fournisseur).'</td>';
1838  if (!$i) {
1839  $totalarray['nbfield']++;
1840  }
1841  }
1842  // Account customer code
1843  if (!empty($arrayfields['s.code_compta']['checked'])) {
1844  print '<td>'.dol_escape_htmltag($companystatic->code_compta_client).'</td>';
1845  if (!$i) {
1846  $totalarray['nbfield']++;
1847  }
1848  }
1849  // Account supplier code
1850  if (!empty($arrayfields['s.code_compta_fournisseur']['checked'])) {
1851  print '<td>'.dol_escape_htmltag($companystatic->code_compta_fournisseur).'</td>';
1852  if (!$i) {
1853  $totalarray['nbfield']++;
1854  }
1855  }
1856  // Address
1857  if (!empty($arrayfields['s.address']['checked'])) {
1858  print '<td class="tdoverflowmax250" title="'.dol_escape_htmltag($companystatic->address).'">'.dol_escape_htmltag($companystatic->address).'</td>';
1859  if (!$i) {
1860  $totalarray['nbfield']++;
1861  }
1862  }
1863  // Sales Representative
1864  if (!empty($arrayfields['sales.representative']['checked'])) {
1865  print '<td class="nowraponall tdoverflowmax200">';
1866  $listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
1867  $nbofsalesrepresentative = count($listsalesrepresentatives);
1868  if ($nbofsalesrepresentative > 6) {
1869  // We print only number
1870  print $nbofsalesrepresentative;
1871  } elseif ($nbofsalesrepresentative > 0) {
1872  $userstatic = new User($db);
1873  $j = 0;
1874  foreach ($listsalesrepresentatives as $val) {
1875  $userstatic->id = $val['id'];
1876  $userstatic->lastname = $val['lastname'];
1877  $userstatic->firstname = $val['firstname'];
1878  $userstatic->email = $val['email'];
1879  $userstatic->entity = $val['entity'];
1880  $userstatic->photo = $val['photo'];
1881  $userstatic->login = $val['login'];
1882  $userstatic->office_phone = $val['office_phone'];
1883  $userstatic->office_fax = $val['office_fax'];
1884  $userstatic->user_mobile = $val['user_mobile'];
1885  $userstatic->job = $val['job'];
1886  $userstatic->gender = $val['gender'];
1887  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1888  $j++;
1889  if ($j < $nbofsalesrepresentative) {
1890  print ' ';
1891  }
1892  }
1893  } else {
1894  print '&nbsp;';
1895  }
1896  print '</td>';
1897  if (!$i) {
1898  $totalarray['nbfield']++;
1899  }
1900  }
1901  // Zip
1902  if (!empty($arrayfields['s.zip']['checked'])) {
1903  print "<td>".dol_escape_htmltag($companystatic->zip)."</td>\n";
1904  if (!$i) {
1905  $totalarray['nbfield']++;
1906  }
1907  }
1908  // Town
1909  if (!empty($arrayfields['s.town']['checked'])) {
1910  print '<td class="tdoverflowmax150" title="'.dol_escape_htmltag($companystatic->town).'">'.dol_escape_htmltag($companystatic->town)."</td>\n";
1911  if (!$i) {
1912  $totalarray['nbfield']++;
1913  }
1914  }
1915  // State
1916  if (!empty($arrayfields['state.nom']['checked'])) {
1917  print "<td>".dol_escape_htmltag($obj->state_name)."</td>\n";
1918  if (!$i) {
1919  $totalarray['nbfield']++;
1920  }
1921  }
1922  // Region
1923  if (!empty($arrayfields['region.nom']['checked'])) {
1924  print "<td>".dol_escape_htmltag($obj->region_name)."</td>\n";
1925  if (!$i) {
1926  $totalarray['nbfield']++;
1927  }
1928  }
1929  // Country
1930  if (!empty($arrayfields['country.code_iso']['checked'])) {
1931  print '<td class="center tdoverflowmax100">';
1932  $labelcountry = ($companystatic->country_code && ($langs->trans("Country".$companystatic->country_code) != "Country".$companystatic->country_code)) ? $langs->trans("Country".$companystatic->country_code) : $obj->country_label;
1933  print $labelcountry;
1934  print '</td>';
1935  if (!$i) {
1936  $totalarray['nbfield']++;
1937  }
1938  }
1939  // Type ent
1940  if (!empty($arrayfields['typent.code']['checked'])) {
1941  if (!isset($typenArray) || !is_array($typenArray) || count($typenArray) == 0) {
1942  $typenArray = $formcompany->typent_array(1);
1943  }
1944  $labeltypeofcompany = empty($typenArray[$obj->typent_code]) ? '' : $typenArray[$obj->typent_code];
1945 
1946  print '<td class="center tdoverflowmax125" title="'.dol_escape_htmltag($labeltypeofcompany).'">';
1947  print dol_escape_htmltag($labeltypeofcompany);
1948  print '</td>';
1949  if (!$i) {
1950  $totalarray['nbfield']++;
1951  }
1952  }
1953  // Multiprice level
1954  if (!empty($arrayfields['s.price_level']['checked'])) {
1955  print '<td class="center">'.$obj->price_level."</td>\n";
1956  if (!$i) {
1957  $totalarray['nbfield']++;
1958  }
1959  }
1960  // Staff
1961  if (!empty($arrayfields['staff.code']['checked'])) {
1962  print '<td class="center">';
1963  if (!empty($obj->staff_code)) {
1964  if (empty($conf->cache['staffArray'])) {
1965  $conf->cache['staffArray'] = $formcompany->effectif_array(1);
1966  }
1967  print $conf->cache['staffArray'][$obj->staff_code];
1968  }
1969  print '</td>';
1970  if (!$i) {
1971  $totalarray['nbfield']++;
1972  }
1973  }
1974  if (!empty($arrayfields['s.email']['checked'])) {
1975  print '<td class="tdoverflowmax150">'.dol_print_email($obj->email, $obj->rowid, $obj->rowid, 1, 0, 0, 1)."</td>\n";
1976  if (!$i) {
1977  $totalarray['nbfield']++;
1978  }
1979  }
1980  if (!empty($arrayfields['s.phone']['checked'])) {
1981  print '<td class="nowraponall">'.dol_print_phone($obj->phone, $companystatic->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone')."</td>\n";
1982  if (!$i) {
1983  $totalarray['nbfield']++;
1984  }
1985  }
1986  if (!empty($arrayfields['s.phone_mobile']['checked'])) {
1987  print '<td class="nowraponall">'.dol_print_phone($obj->phone_mobile, $companystatic->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'phone_mobile')."</td>\n";
1988  if (!$i) {
1989  $totalarray['nbfield']++;
1990  }
1991  }
1992  if (!empty($arrayfields['s.fax']['checked'])) {
1993  print '<td class="nowraponall">'.dol_print_phone($obj->fax, $companystatic->country_code, 0, $obj->rowid, 'AC_TEL', ' ', 'fax')."</td>\n";
1994  if (!$i) {
1995  $totalarray['nbfield']++;
1996  }
1997  }
1998  if (!empty($arrayfields['s.url']['checked'])) {
1999  print "<td>".dol_print_url($obj->url, '', '', 1)."</td>\n";
2000  if (!$i) {
2001  $totalarray['nbfield']++;
2002  }
2003  }
2004  if (!empty($arrayfields['s.siren']['checked'])) {
2005  print "<td>".$obj->idprof1."</td>\n";
2006  if (!$i) {
2007  $totalarray['nbfield']++;
2008  }
2009  }
2010  if (!empty($arrayfields['s.siret']['checked'])) {
2011  print "<td>".$obj->idprof2."</td>\n";
2012  if (!$i) {
2013  $totalarray['nbfield']++;
2014  }
2015  }
2016  if (!empty($arrayfields['s.ape']['checked'])) {
2017  print "<td>".$obj->idprof3."</td>\n";
2018  if (!$i) {
2019  $totalarray['nbfield']++;
2020  }
2021  }
2022  if (!empty($arrayfields['s.idprof4']['checked'])) {
2023  print "<td>".$obj->idprof4."</td>\n";
2024  if (!$i) {
2025  $totalarray['nbfield']++;
2026  }
2027  }
2028  if (!empty($arrayfields['s.idprof5']['checked'])) {
2029  print "<td>".$obj->idprof5."</td>\n";
2030  if (!$i) {
2031  $totalarray['nbfield']++;
2032  }
2033  }
2034  if (!empty($arrayfields['s.idprof6']['checked'])) {
2035  print "<td>".$obj->idprof6."</td>\n";
2036  if (!$i) {
2037  $totalarray['nbfield']++;
2038  }
2039  }
2040  // VAT
2041  if (!empty($arrayfields['s.tva_intra']['checked'])) {
2042  print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($companystatic->tva_intra).'">';
2043  if ($companystatic->tva_intra && !isValidVATID($companystatic)) {
2044  print img_warning("BadVATNumber", '', 'pictofixedwidth');
2045  }
2046  print $companystatic->tva_intra;
2047  print "</td>\n";
2048  if (!$i) {
2049  $totalarray['nbfield']++;
2050  }
2051  }
2052  // Nature
2053  if (!empty($arrayfields['customerorsupplier']['checked'])) {
2054  print '<td class="center">';
2055  print $companystatic->getTypeUrl(1);
2056  print '</td>';
2057  if (!$i) {
2058  $totalarray['nbfield']++;
2059  }
2060  }
2061  // Prospect level
2062  if (!empty($arrayfields['s.fk_prospectlevel']['checked'])) {
2063  print '<td class="center nowraponall">';
2064  print $companystatic->getLibProspLevel();
2065  print "</td>";
2066  if (!$i) {
2067  $totalarray['nbfield']++;
2068  }
2069  }
2070  // Prospect status
2071  if (!empty($arrayfields['s.fk_stcomm']['checked'])) {
2072  print '<td class="center nowraponall">';
2073 
2074  $prospectid = $obj->rowid;
2075  $statusprospect = $obj->stcomm_id;
2076 
2077  $formcompany->selectProspectStatus('status_prospect', $prospectstatic, $statusprospect, $prospectid);
2078 
2079  print '</td>';
2080  if (!$i) {
2081  $totalarray['nbfield']++;
2082  }
2083  }
2084  // Parent company
2085  if (!empty($arrayfields['s2.nom']['checked'])) {
2086  print '<td class="center tdoverflowmax100">';
2087  if ($companystatic->parent > 0) {
2088  $companyparent->fetch($companystatic->parent);
2089  print $companyparent->getNomUrl(1);
2090  }
2091  print "</td>";
2092  if (!$i) {
2093  $totalarray['nbfield']++;
2094  }
2095  }
2096  // Extra fields
2097  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
2098  // Fields from hook
2099  $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
2100  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2101  print $hookmanager->resPrint;
2102  // Date creation
2103  if (!empty($arrayfields['s.datec']['checked'])) {
2104  print '<td class="center nowraponall">';
2105  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
2106  print '</td>';
2107  if (!$i) {
2108  $totalarray['nbfield']++;
2109  }
2110  }
2111  // Date modification
2112  if (!empty($arrayfields['s.tms']['checked'])) {
2113  print '<td class="center nowraponall">';
2114  print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
2115  print '</td>';
2116  if (!$i) {
2117  $totalarray['nbfield']++;
2118  }
2119  }
2120  // Status
2121  if (!empty($arrayfields['s.status']['checked'])) {
2122  print '<td class="center nowraponall">'.$companystatic->getLibStatut(5).'</td>';
2123  if (!$i) {
2124  $totalarray['nbfield']++;
2125  }
2126  }
2127  // Import key
2128  if (!empty($arrayfields['s.import_key']['checked'])) {
2129  print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($obj->import_key).'">';
2130  print dol_escape_htmltag($obj->import_key);
2131  print "</td>\n";
2132  if (!$i) {
2133  $totalarray['nbfield']++;
2134  }
2135  }
2136  // Action column (Show the massaction button only when this page is not opend from the Extended POS)
2137  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
2138  print '<td class="nowrap center actioncolumn">';
2139  if (($massactionbutton || $massaction) && $contextpage != 'poslist') { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
2140  $selected = 0;
2141  if (in_array($obj->rowid, $arrayofselected)) {
2142  $selected = 1;
2143  }
2144  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
2145  }
2146  print '</td>';
2147  if (!$i) {
2148  $totalarray['nbfield']++;
2149  }
2150  }
2151 
2152  print '</tr>'."\n";
2153  }
2154  $i++;
2155 }
2156 
2157 // Show total line
2158 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2159 
2160 // If no record found
2161 if ($num == 0) {
2162  $colspan = 1;
2163  foreach ($arrayfields as $key => $val) {
2164  if (!empty($val['checked'])) {
2165  $colspan++;
2166  }
2167  }
2168  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
2169 }
2170 
2171 $db->free($resql);
2172 
2173 $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
2174 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
2175 print $hookmanager->resPrint;
2176 
2177 print '</table>'."\n";
2178 print '</div>'."\n";
2179 
2180 // Line that calls the select_status function by passing it js as the 5th parameter in order to activate the js script
2181 $formcompany->selectProspectStatus('status_prospect', $prospectstatic, null, null, "js");
2182 
2183 print '</form>'."\n";
2184 
2185 // End of page
2186 llxFooter();
2187 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
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
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
$object ref
Definition: info.php:79
Class to manage customers or prospects.
Class to manage standard extra fields.
Class to manage invoices.
Class to manage forms for categories.
Class to build HTML component for third parties management Only common components are here.
Class to manage generation of HTML components Only common components must be here.
Class permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:744
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
dolExplodeIntoArray($string, $delimiter=';', $kv='=')
Split a string with 2 keys into key array.
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_getIdFromCode($db, $key, $tablename, $fieldkey='code', $fieldid='id', $entityfilter=0, $filters='')
Return an id or code from a code or id.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
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.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
get_htmloutput_mesg($mesgstring='', $mesgarray=[], $style='ok', $keepembedded=0)
Get formatted messages to output (Used to show messages on html output).
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
getEntity($element, $shared=1, $currentobject=null)
Get list of entity id to use.
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.