1<?php
2/* Copyright (C) 2001-2007 Rodolphe Quiedeville		<rodolphe@quiedeville.org>
3 * Copyright (C) 2004-2016 Laurent Destailleur		<eldy@users.sourceforge.net>
4 * Copyright (C) 2004      Eric Seigne				<eric.seigne@ryxeo.com>
5 * Copyright (C) 2005      Marc Barilley / Ocebo	<marc@ocebo.com>
6 * Copyright (C) 2005-2013 Regis Houssin			<regis.houssin@inodbox.com>
7 * Copyright (C) 2006      Andre Cianfarani			<acianfa@free.fr>
8 * Copyright (C) 2010-2011 Juanjo Menent			<jmenent@2byte.es>
9 * Copyright (C) 2010-2011 Philippe Grand			<philippe.grand@atoo-net.com>
10 * Copyright (C) 2012      Christophe Battarel		<christophe.battarel@altairis.fr>
11 * Copyright (C) 2013      Cédric Salvador			<csalvador@gpcsolutions.fr>
12 * Copyright (C) 2015      Jean-François Ferry		<jfefe@aternatik.fr>
13 * Copyright (C) 2016-2021 Ferran Marcet			<fmarcet@2byte.es>
14 * Copyright (C) 2017-2018 Charlene Benke			<charlie@patas-monkey.com>
15 * Copyright (C) 2018	   Nicolas ZABOURI			<info@inovea-conseil.com>
16 * Copyright (C) 2019-2021 Alexandre Spangaro		<aspangaro@open-dsi.fr>
17 * Copyright (C) 2021	   Anthony Berton			<anthony.berton@bb2a.fr>
18 * Copyright (C) 2021      Frédéric France			<frederic.france@netlogic.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
34/**
35 *	\file       	htdocs/comm/propal/list.php
36 *	\ingroup    	propal
37 *	\brief      	Page of commercial proposals card and list
38 */
39
40require '../../main.inc.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
43require_once DOL_DOCUMENT_ROOT.'/core/class/html.formpropal.class.php';
44require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
45require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
46require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
47require_once DOL_DOCUMENT_ROOT.'/comm/propal/class/propal.class.php';
48require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
49
50// Load translation files required by the page
51$langs->loadLangs(array('companies', 'propal', 'compta', 'bills', 'orders', 'products', 'deliveries', 'categories'));
52if (!empty($conf->expedition->enabled)) {
53	$langs->loadLangs(array('sendings'));
54}
55
56$socid = GETPOST('socid', 'int');
57
58$action = GETPOST('action', 'aZ09');
59$massaction = GETPOST('massaction', 'alpha');
60$show_files = GETPOST('show_files', 'int');
61$confirm = GETPOST('confirm', 'alpha');
62$toselect = GETPOST('toselect', 'array');
63$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'proposallist';
64
65$search_user = GETPOST('search_user', 'int');
66$search_sale = GETPOST('search_sale', 'int');
67$search_ref = GETPOST('sf_ref') ?GETPOST('sf_ref', 'alpha') : GETPOST('search_ref', 'alpha');
68$search_refcustomer = GETPOST('search_refcustomer', 'alpha');
69
70$search_refproject = GETPOST('search_refproject', 'alpha');
71$search_project = GETPOST('search_project', 'alpha');
72
73$search_societe = GETPOST('search_societe', 'alpha');
74$search_societe_alias = GETPOST('search_societe_alias', 'alpha');
75$search_montant_ht = GETPOST('search_montant_ht', 'alpha');
76$search_montant_vat = GETPOST('search_montant_vat', 'alpha');
77$search_montant_ttc = GETPOST('search_montant_ttc', 'alpha');
78$search_warehouse = GETPOST('search_warehouse', 'alpha');
79$search_multicurrency_code = GETPOST('search_multicurrency_code', 'alpha');
80$search_multicurrency_tx = GETPOST('search_multicurrency_tx', 'alpha');
81$search_multicurrency_montant_ht = GETPOST('search_multicurrency_montant_ht', 'alpha');
82$search_multicurrency_montant_vat = GETPOST('search_multicurrency_montant_vat', 'alpha');
83$search_multicurrency_montant_ttc = GETPOST('search_multicurrency_montant_ttc', 'alpha');
84$search_login = GETPOST('search_login', 'alpha');
85$search_product_category = GETPOST('search_product_category', 'int');
86$search_town = GETPOST('search_town', 'alpha');
87$search_zip = GETPOST('search_zip', 'alpha');
88$search_state = GETPOST("search_state");
89$search_country = GETPOST("search_country", 'int');
90$search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
91$search_date_startday = GETPOST('search_date_startday', 'int');
92$search_date_startmonth = GETPOST('search_date_startmonth', 'int');
93$search_date_startyear = GETPOST('search_date_startyear', 'int');
94$search_date_endday = GETPOST('search_date_endday', 'int');
95$search_date_endmonth = GETPOST('search_date_endmonth', 'int');
96$search_date_endyear = GETPOST('search_date_endyear', 'int');
97$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear);	// Use tzserver
98$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
99$search_date_end_startday = GETPOST('search_date_end_startday', 'int');
100$search_date_end_startmonth = GETPOST('search_date_end_startmonth', 'int');
101$search_date_end_startyear = GETPOST('search_date_end_startyear', 'int');
102$search_date_end_endday = GETPOST('search_date_end_endday', 'int');
103$search_date_end_endmonth = GETPOST('search_date_end_endmonth', 'int');
104$search_date_end_endyear = GETPOST('search_date_end_endyear', 'int');
105$search_date_end_start = dol_mktime(0, 0, 0, $search_date_end_startmonth, $search_date_end_startday, $search_date_end_startyear);	// Use tzserver
106$search_date_end_end = dol_mktime(23, 59, 59, $search_date_end_endmonth, $search_date_end_endday, $search_date_end_endyear);
107$search_date_delivery_startday = GETPOST('search_date_delivery_startday', 'int');
108$search_date_delivery_startmonth = GETPOST('search_date_delivery_startmonth', 'int');
109$search_date_delivery_startyear = GETPOST('search_date_delivery_startyear', 'int');
110$search_date_delivery_endday = GETPOST('search_date_delivery_endday', 'int');
111$search_date_delivery_endmonth = GETPOST('search_date_delivery_endmonth', 'int');
112$search_date_delivery_endyear = GETPOST('search_date_delivery_endyear', 'int');
113$search_date_delivery_start = dol_mktime(0, 0, 0, $search_date_delivery_startmonth, $search_date_delivery_startday, $search_date_delivery_startyear);
114$search_date_delivery_end = dol_mktime(23, 59, 59, $search_date_delivery_endmonth, $search_date_delivery_endday, $search_date_delivery_endyear);
115$search_availability = GETPOST('search_availability', 'int');
116$search_categ_cus = GETPOST("search_categ_cus", 'int');
117$search_fk_cond_reglement = GETPOST("search_fk_cond_reglement", 'int');
118$search_fk_shipping_method = GETPOST("search_fk_shipping_method", 'int');
119$search_fk_input_reason = GETPOST("search_fk_input_reason", 'int');
120$search_fk_mode_reglement = GETPOST("search_fk_mode_reglement", 'int');
121$search_btn = GETPOST('button_search', 'alpha');
122$search_remove_btn = GETPOST('button_removefilter', 'alpha');
123
124$search_status = GETPOST('search_status', 'alpha');
125$optioncss = GETPOST('optioncss', 'alpha');
126$object_statut = GETPOST('search_statut', 'alpha');
127
128$sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
129$mesg = (GETPOST("msg") ? GETPOST("msg") : GETPOST("mesg"));
130
131
132$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
133$sortfield = GETPOST("sortfield", 'alpha');
134$sortorder = GETPOST("sortorder", 'alpha');
135$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
136if (empty($page) || $page == -1 || !empty($search_btn) || !empty($search_remove_btn) || (empty($toselect) && $massaction === '0')) {
137	$page = 0;
138}     // If $page is not defined, or '' or -1
139$offset = $limit * $page;
140$pageprev = $page - 1;
141$pagenext = $page + 1;
142if (!$sortfield) {
143	$sortfield = 'p.ref';
144}
145if (!$sortorder) {
146	$sortorder = 'DESC';
147}
148
149// Security check
150$module = 'propal';
151$dbtable = '';
152$objectid = '';
153if (!empty($user->socid)) {
154	$socid = $user->socid;
155}
156if (!empty($socid)) {
157	$objectid = $socid;
158	$module = 'societe';
159	$dbtable = '&societe';
160}
161$result = restrictedArea($user, $module, $objectid, $dbtable);
162
163$diroutputmassaction = $conf->propal->multidir_output[$conf->entity].'/temp/massgeneration/'.$user->id;
164
165// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
166$object = new Propal($db);
167$hookmanager->initHooks(array('propallist'));
168$extrafields = new ExtraFields($db);
169
170// fetch optionals attributes and labels
171$extrafields->fetch_name_optionals_label($object->table_element);
172
173$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
174
175// List of fields to search into when doing a "search in all"
176$fieldstosearchall = array(
177	'p.ref'=>'Ref',
178	'p.ref_client'=>'CustomerRef',
179	'pd.description'=>'Description',
180	's.nom'=>"ThirdParty",
181	's.name_alias'=>"AliasNameShort",
182	's.zip'=>"Zip",
183	's.town'=>"Town",
184	'p.note_public'=>'NotePublic',
185);
186if (empty($user->socid)) {
187	$fieldstosearchall["p.note_private"] = "NotePrivate";
188}
189
190
191$checkedtypetiers = 0;
192$arrayfields = array(
193	'p.ref'=>array('label'=>"Ref", 'checked'=>1),
194	'p.ref_client'=>array('label'=>"RefCustomer", 'checked'=>1),
195	'pr.ref'=>array('label'=>"ProjectRef", 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1)),
196	'pr.title'=>array('label'=>"ProjectLabel", 'checked'=>0, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1)),
197	's.nom'=>array('label'=>"ThirdParty", 'checked'=>1),
198	's.name_alias'=>array('label'=>"AliasNameShort", 'checked'=>-1),
199	's.town'=>array('label'=>"Town", 'checked'=>-1),
200	's.zip'=>array('label'=>"Zip", 'checked'=>1),
201	'state.nom'=>array('label'=>"StateShort", 'checked'=>0),
202	'country.code_iso'=>array('label'=>"Country", 'checked'=>0),
203	'typent.code'=>array('label'=>"ThirdPartyType", 'checked'=>$checkedtypetiers),
204	'p.date'=>array('label'=>"DatePropal", 'checked'=>1),
205	'p.fin_validite'=>array('label'=>"DateEnd", 'checked'=>1),
206	'p.date_livraison'=>array('label'=>"DeliveryDate", 'checked'=>0),
207	'ava.rowid'=>array('label'=>"AvailabilityPeriod", 'checked'=>0),
208	'p.fk_shipping_method'=>array('label'=>"SendingMethod", 'checked'=>0, 'enabled'=>!empty($conf->expedition->enabled)),
209	'p.fk_input_reason'=>array('label'=>"Origin", 'checked'=>0, 'enabled'=>1),
210	'p.fk_cond_reglement'=>array('label'=>"PaymentConditionsShort", 'checked'=>0),
211	'p.fk_mode_reglement'=>array('label'=>"PaymentMode", 'checked'=>0),
212	'p.total_ht'=>array('label'=>"AmountHT", 'checked'=>1),
213	'p.total_tva'=>array('label'=>"AmountVAT", 'checked'=>0),
214	'p.total_ttc'=>array('label'=>"AmountTTC", 'checked'=>0),
215	'p.total_ht_invoiced'=>array('label'=>"AmountInvoicedHT", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
216	'p.total_invoiced'=>array('label'=>"AmountInvoicedTTC", 'checked'=>0, 'enabled'=>!empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
217	'p.multicurrency_code'=>array('label'=>'Currency', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
218	'p.multicurrency_tx'=>array('label'=>'CurrencyRate', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
219	'p.multicurrency_total_ht'=>array('label'=>'MulticurrencyAmountHT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
220	'p.multicurrency_total_tva'=>array('label'=>'MulticurrencyAmountVAT', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
221	'p.multicurrency_total_ttc'=>array('label'=>'MulticurrencyAmountTTC', 'checked'=>0, 'enabled'=>(empty($conf->multicurrency->enabled) ? 0 : 1)),
222	'p.multicurrency_total_ht_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedHT', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
223	'p.multicurrency_total_invoiced'=>array('label'=>'MulticurrencyAmountInvoicedTTC', 'checked'=>0, 'enabled'=>!empty($conf->multicurrency->enabled) && !empty($conf->global->PROPOSAL_SHOW_INVOICED_AMOUNT)),
224	'u.login'=>array('label'=>"Author", 'checked'=>1, 'position'=>10),
225	'sale_representative'=>array('label'=>"SaleRepresentativesOfThirdParty", 'checked'=>-1),
226	'p.datec'=>array('label'=>"DateCreation", 'checked'=>0, 'position'=>500),
227	'p.tms'=>array('label'=>"DateModificationShort", 'checked'=>0, 'position'=>500),
228	'p.date_cloture'=>array('label'=>"DateClosing", 'checked'=>0, 'position'=>500),
229	'p.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
230	'p.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
231	'p.fk_statut'=>array('label'=>"Status", 'checked'=>1, 'position'=>1000),
232);
233
234// Extra fields
235include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
236
237$permissiontoread = $user->rights->propal->lire;
238$permissiontoadd = $user->rights->propal->creer;
239$permissiontodelete = $user->rights->propal->supprimer;
240if (!empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
241	$permissiontovalidate = $user->rights->propale->propal_advance->validate;
242	$permissiontoclose = $user->rights->propale->propal_advance->close;
243	$permissiontosendbymail = $user->rights->propale->propal_advance->send;
244} else {
245	$permissiontovalidate = $user->rights->propal->creer;
246	$permissiontoclose = $user->rights->propal->creer;
247	$permissiontosendbymail = $user->rights->propal->creer;
248}
249
250
251/*
252 * Actions
253 */
254
255if (GETPOST('cancel', 'alpha')) {
256	$action = 'list';
257	$massaction = '';
258}
259if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
260	$massaction = '';
261}
262
263$parameters = array('socid'=>$socid);
264$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
265if ($reshook < 0) {
266	setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
267}
268
269include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
270
271// Do we click on purge search criteria ?
272if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
273	$search_categ = '';
274	$search_user = '';
275	$search_sale = '';
276	$search_ref = '';
277	$search_refcustomer = '';
278	$search_refproject = '';
279	$search_project = '';
280	$search_societe = '';
281	$search_societe_alias = '';
282	$search_montant_ht = '';
283	$search_montant_vat = '';
284	$search_montant_ttc = '';
285	$search_warehouse = '';
286	$search_multicurrency_code = '';
287	$search_multicurrency_tx = '';
288	$search_multicurrency_montant_ht = '';
289	$search_multicurrency_montant_vat = '';
290	$search_multicurrency_montant_ttc = '';
291	$search_login = '';
292	$search_product_category = '';
293	$search_town = '';
294	$search_zip = "";
295	$search_state = "";
296	$search_type = '';
297	$search_country = '';
298	$search_type_thirdparty = '';
299	$search_date_startday = '';
300	$search_date_startmonth = '';
301	$search_date_startyear = '';
302	$search_date_endday = '';
303	$search_date_endmonth = '';
304	$search_date_endyear = '';
305	$search_date_start = '';
306	$search_date_end = '';
307	$search_date_end_startday = '';
308	$search_date_end_startmonth = '';
309	$search_date_end_startyear = '';
310	$search_date_end_endday = '';
311	$search_date_end_endmonth = '';
312	$search_date_end_endyear = '';
313	$search_date_end_start = '';
314	$search_date_end_end = '';
315	$search_date_delivery_startday = '';
316	$search_date_delivery_startmonth = '';
317	$search_date_delivery_startyear = '';
318	$search_date_delivery_endday = '';
319	$search_date_delivery_endmonth = '';
320	$search_date_delivery_endyear = '';
321	$search_date_delivery_start = '';
322	$search_date_delivery_end = '';
323	$search_availability = '';
324	$search_status = '';
325	$object_statut = '';
326	$toselect = '';
327	$search_array_options = array();
328	$search_categ_cus = 0;
329	$search_fk_cond_reglement = '';
330	$search_fk_shipping_method = '';
331	$search_fk_input_reason = '';
332	$search_fk_mode_reglement = '';
333}
334if ($object_statut != '') {
335	$search_status = $object_statut;
336}
337
338
339if (empty($reshook)) {
340	$objectclass = 'Propal';
341	$objectlabel = 'Proposals';
342	$uploaddir = $conf->propal->multidir_output[$conf->entity];
343	include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
344}
345
346if ($action == 'validate' && $permissiontovalidate) {
347	if (GETPOST('confirm') == 'yes') {
348		$tmpproposal = new Propal($db);
349		$db->begin();
350		$error = 0;
351		foreach ($toselect as $checked) {
352			if ($tmpproposal->fetch($checked)) {
353				if ($tmpproposal->statut == 0) {
354					if ($tmpproposal->valid($user)) {
355						setEventMessage($tmpproposal->ref." ".$langs->trans('PassedInOpenStatus'), 'mesgs');
356					} else {
357						setEventMessage($langs->trans('CantBeValidated'), 'errors');
358						$error++;
359					}
360				} else {
361					setEventMessage($tmpproposal->ref." ".$langs->trans('IsNotADraft'), 'errors');
362					$error++;
363				}
364			} else {
365				dol_print_error($db);
366				$error++;
367			}
368		}
369		if ($error) {
370			$db->rollback();
371		} else {
372			$db->commit();
373		}
374	}
375}
376
377if ($action == "sign" && $permissiontoclose) {
378	if (GETPOST('confirm') == 'yes') {
379		$tmpproposal = new Propal($db);
380		$db->begin();
381		$error = 0;
382		foreach ($toselect as $checked) {
383			if ($tmpproposal->fetch($checked)) {
384				if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED) {
385					$tmpproposal->statut = $tmpproposal::STATUS_SIGNED;;
386					if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_SIGNED)) {
387						setEventMessage($tmpproposal->ref." ".$langs->trans('Signed'), 'mesgs');
388					} else {
389						dol_print_error($db);
390						$error++;
391					}
392				} else {
393					setEventMessage($tmpproposal->ref." ".$langs->trans('CantBeSign'), 'errors');
394					$error++;
395				}
396			} else {
397				dol_print_error($db);
398				$error++;
399			}
400		}
401		if ($error) {
402			$db->rollback();
403		} else {
404			$db->commit();
405		}
406	}
407}
408if ($action == "nosign" && $permissiontoclose) {
409	if (GETPOST('confirm') == 'yes') {
410		$tmpproposal = new Propal($db);
411		$db->begin();
412		$error = 0;
413		foreach ($toselect as $checked) {
414			if ($tmpproposal->fetch($checked)) {
415				if ($tmpproposal->statut == $tmpproposal::STATUS_VALIDATED) {
416					$tmpproposal->statut = $tmpproposal::STATUS_NOTSIGNED;
417					if ($tmpproposal->closeProposal($user, $tmpproposal::STATUS_NOTSIGNED)) {
418						setEventMessage($tmpproposal->ref." ".$langs->trans('NoSigned'), 'mesgs');
419					} else {
420						dol_print_error($db);
421						$error++;
422					}
423				} else {
424					setEventMessage($tmpproposal->ref." ".$langs->trans('CantBeClosed'), 'errors');
425					$error++;
426				}
427			} else {
428				dol_print_error($db);
429				$error++;
430			}
431		}
432		if ($error) {
433			$db->rollback();
434		} else {
435			$db->commit();
436		}
437	}
438}
439
440// Closed records
441if (!$error && $massaction === 'setbilled' && $permissiontoclose) {
442	$db->begin();
443
444	$objecttmp = new $objectclass($db);
445	$nbok = 0;
446	foreach ($toselect as $toselectid) {
447		$result = $objecttmp->fetch($toselectid);
448		if ($result > 0) {
449			$result = $objecttmp->classifyBilled($user, 0);
450			if ($result <= 0) {
451				setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
452				$error++;
453				break;
454			} else {
455				$nbok++;
456			}
457		} else {
458			setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
459			$error++;
460			break;
461		}
462	}
463
464	if (!$error) {
465		if ($nbok > 1) {
466			setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
467		} else {
468			setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
469		}
470		$db->commit();
471	} else {
472		$db->rollback();
473	}
474}
475
476
477
478/*
479 * View
480 */
481
482$now = dol_now();
483
484$form = new Form($db);
485$formother = new FormOther($db);
486$formfile = new FormFile($db);
487$formpropal = new FormPropal($db);
488$companystatic = new Societe($db);
489$projectstatic = new Project($db);
490$formcompany = new FormCompany($db);
491
492$help_url = 'EN:Commercial_Proposals|FR:Proposition_commerciale|ES:Presupuestos';
493//llxHeader('',$langs->trans('Proposal'),$help_url);
494
495$sql = 'SELECT';
496if ($sall || $search_product_category > 0 || $search_user > 0) {
497	$sql = 'SELECT DISTINCT';
498}
499$sql .= ' s.rowid as socid, s.nom as name, s.name_alias as alias, s.email, s.phone, s.fax , s.address, s.town, s.zip, s.fk_pays, s.client, s.code_client, ';
500$sql .= " typent.code as typent_code,";
501$sql .= " ava.rowid as availability,";
502$sql .= " country.code as country_code,";
503$sql .= " state.code_departement as state_code, state.nom as state_name,";
504$sql .= ' p.rowid, p.entity as propal_entity, p.note_private, p.total_ht, p.total_tva, p.total_ttc, p.localtax1, p.localtax2, p.ref, p.ref_client, p.fk_statut as status, p.fk_user_author, p.datep as dp, p.fin_validite as dfv,p.date_livraison as ddelivery,';
505$sql .= ' p.fk_multicurrency, p.multicurrency_code, p.multicurrency_tx, p.multicurrency_total_ht, p.multicurrency_total_tva, p.multicurrency_total_ttc,';
506$sql .= ' p.datec as date_creation, p.tms as date_update, p.date_cloture as date_cloture,';
507$sql .= ' p.note_public, p.note_private,';
508$sql .= ' p.fk_cond_reglement,p.fk_mode_reglement,p.fk_shipping_method,p.fk_input_reason,';
509$sql .= " pr.rowid as project_id, pr.ref as project_ref, pr.title as project_label,";
510$sql .= ' u.login, u.lastname, u.firstname, u.email as user_email, u.statut as user_statut, u.entity as user_entity, u.photo, u.office_phone, u.office_fax, u.user_mobile, u.job, u.gender';
511if (!$user->rights->societe->client->voir && !$socid) {
512	$sql .= ", sc.fk_soc, sc.fk_user";
513}
514if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
515	$sql .= ", cc.fk_categorie, cc.fk_soc";
516}
517// Add fields from extrafields
518if (!empty($extrafields->attributes[$object->table_element]['label'])) {
519	foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
520		$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key.' as options_'.$key : '');
521	}
522}
523// Add fields from hooks
524$parameters = array();
525$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
526$sql .= $hookmanager->resPrint;
527$sql = preg_replace('/, $/', '', $sql);
528$sql .= ' FROM '.MAIN_DB_PREFIX.'societe as s';
529$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
530$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
531$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
532if (!empty($search_categ_cus) && $search_categ_cus != '-1') {
533	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX."categorie_societe as cc ON s.rowid = cc.fk_soc"; // We'll need this table joined to the select in order to filter by categ
534}
535$sql .= ', '.MAIN_DB_PREFIX.'propal as p';
536if (is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
537	$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (p.rowid = ef.fk_object)";
538}
539if ($sall || $search_product_category > 0) {
540	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'propaldet as pd ON p.rowid=pd.fk_propal';
541}
542if ($search_product_category > 0) {
543	$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=pd.fk_product';
544}
545$sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'user as u ON p.fk_user_author = u.rowid';
546$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr ON pr.rowid = p.fk_projet";
547$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_availability as ava on (ava.rowid = p.fk_availability)";
548// We'll need this table joined to the select in order to filter by sale
549if ($search_sale > 0 || (!$user->rights->societe->client->voir && !$socid)) {
550	$sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
551}
552if ($search_user > 0) {
553	$sql .= ", ".MAIN_DB_PREFIX."element_contact as c";
554	$sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
555}
556$sql .= ' WHERE p.fk_soc = s.rowid';
557$sql .= ' AND p.entity IN ('.getEntity('propal').')';
558if (!$user->rights->societe->client->voir && !$socid) { //restriction
559	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
560}
561
562if ($search_town) {
563	$sql .= natural_search('s.town', $search_town);
564}
565if ($search_zip) {
566	$sql .= natural_search("s.zip", $search_zip);
567}
568if ($search_state) {
569	$sql .= natural_search("state.nom", $search_state);
570}
571if ($search_country) {
572	$sql .= " AND s.fk_pays IN (".$db->sanitize($db->escape($search_country)).')';
573}
574if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
575	$sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
576}
577if ($search_ref) {
578	$sql .= natural_search('p.ref', $search_ref);
579}
580if ($search_refcustomer) {
581	$sql .= natural_search('p.ref_client', $search_refcustomer);
582}
583if ($search_refproject) {
584	$sql .= natural_search('pr.ref', $search_refproject);
585}
586if ($search_project) {
587	$sql .= natural_search('pr.title', $search_project);
588}
589if ($search_availability) {
590	$sql .= " AND p.fk_availability IN (".$db->sanitize($db->escape($search_availability)).')';
591}
592if ($search_societe) {
593	$sql .= natural_search('s.nom', $search_societe);
594}
595if ($search_societe_alias) {
596	$sql .= natural_search('s.name_alias', $search_societe_alias);
597}
598if ($search_login) {
599	$sql .= natural_search(array("u.login", "u.firstname", "u.lastname"), $search_login);
600}
601if ($search_montant_ht != '') {
602	$sql .= natural_search("p.total_ht", $search_montant_ht, 1);
603}
604if ($search_montant_vat != '') {
605	$sql .= natural_search("p.total_tva", $search_montant_vat, 1);
606}
607if ($search_montant_ttc != '') {
608	$sql .= natural_search("p.total_ttc", $search_montant_ttc, 1);
609}
610if ($search_warehouse != '' && $search_warehouse > 0) {
611	$sql .= natural_search("p.fk_warehouse", $search_warehouse, 1);
612}
613if ($search_multicurrency_code != '') {
614	$sql .= ' AND p.multicurrency_code = "'.$db->escape($search_multicurrency_code).'"';
615}
616if ($search_multicurrency_tx != '') {
617	$sql .= natural_search('p.multicurrency_tx', $search_multicurrency_tx, 1);
618}
619if ($search_multicurrency_montant_ht != '') {
620	$sql .= natural_search('p.multicurrency_total_ht', $search_multicurrency_montant_ht, 1);
621}
622if ($search_multicurrency_montant_vat != '') {
623	$sql .= natural_search('p.multicurrency_total_tva', $search_multicurrency_montant_vat, 1);
624}
625if ($search_multicurrency_montant_ttc != '') {
626	$sql .= natural_search('p.multicurrency_total_ttc', $search_multicurrency_montant_ttc, 1);
627}
628if ($sall) {
629	$sql .= natural_search(array_keys($fieldstosearchall), $sall);
630}
631
632if ($search_categ_cus > 0) {
633	$sql .= " AND cc.fk_categorie = ".((int) $search_categ_cus);
634}
635if ($search_categ_cus == -2) {
636	$sql .= " AND cc.fk_categorie IS NULL";
637}
638
639if ($search_fk_cond_reglement > 0) {
640	$sql .= " AND p.fk_cond_reglement = ".((int) $search_fk_cond_reglement);
641}
642if ($search_fk_shipping_method > 0) {
643	$sql .= " AND p.fk_shipping_method = ".((int) $search_fk_shipping_method);
644}
645if ($search_fk_input_reason > 0) {
646	$sql .= " AND p.fk_input_reason = ".((int) $search_fk_input_reason);
647}
648if ($search_fk_mode_reglement > 0) {
649	$sql .= " AND p.fk_mode_reglement = ".((int) $search_fk_mode_reglement);
650}
651
652if ($search_product_category > 0) {
653	$sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
654}
655if ($socid > 0) {
656	$sql .= ' AND s.rowid = '.((int) $socid);
657}
658if ($search_status != '' && $search_status != '-1') {
659	$sql .= ' AND p.fk_statut IN ('.$db->sanitize($search_status).')';
660}
661if ($search_date_start) {
662	$sql .= " AND p.datep >= '".$db->idate($search_date_start)."'";
663}
664if ($search_date_end) {
665	$sql .= " AND p.datep <= '".$db->idate($search_date_end)."'";
666}
667if ($search_date_end_start) {
668	$sql .= " AND p.fin_validite >= '".$db->idate($search_date_end_start)."'";
669}
670if ($search_date_end_end) {
671	$sql .= " AND p.fin_validite <= '".$db->idate($search_date_end_end)."'";
672}
673if ($search_date_delivery_start) {
674	$sql .= " AND p.date_livraison >= '".$db->idate($search_date_delivery_start)."'";
675}
676if ($search_date_delivery_end) {
677	$sql .= " AND p.date_livraison <= '".$db->idate($search_date_delivery_end)."'";
678}
679if ($search_sale > 0) {
680	$sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
681}
682if ($search_user > 0) {
683	$sql .= " AND c.fk_c_type_contact = tc.rowid AND tc.element='propal' AND tc.source='internal' AND c.element_id = p.rowid AND c.fk_socpeople = ".((int) $search_user);
684}
685// Add where from extra fields
686include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
687
688// Add where from hooks
689$parameters = array();
690$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
691$sql .= $hookmanager->resPrint;
692
693$sql .= $db->order($sortfield, $sortorder);
694$sql .= ', p.ref DESC';
695
696// Count total nb of records
697$nbtotalofrecords = '';
698if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
699	$result = $db->query($sql);
700	$nbtotalofrecords = $db->num_rows($result);
701
702	if (($page * $limit) > $nbtotalofrecords) {	// if total resultset is smaller then paging size (filtering), goto and load page 0
703		$page = 0;
704		$offset = 0;
705	}
706}
707
708$sql .= $db->plimit($limit + 1, $offset);
709
710$resql = $db->query($sql);
711
712if ($resql) {
713	$objectstatic = new Propal($db);
714	$userstatic = new User($db);
715
716	if ($socid > 0) {
717		$soc = new Societe($db);
718		$soc->fetch($socid);
719		$title = $langs->trans('ListOfProposals').' - '.$soc->name;
720		if (empty($search_societe)) {
721			$search_societe = $soc->name;
722		}
723	} else {
724		$title = $langs->trans('ListOfProposals');
725	}
726
727	$num = $db->num_rows($resql);
728
729	$arrayofselected = is_array($toselect) ? $toselect : array();
730
731	if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall) {
732		$obj = $db->fetch_object($resql);
733
734		$id = $obj->rowid;
735
736		header("Location: ".DOL_URL_ROOT.'/comm/propal/card.php?id='.$id);
737		exit;
738	}
739
740	llxHeader('', $langs->trans('Proposal'), $help_url);
741
742	$param = '&search_status='.urlencode($search_status);
743	if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
744		$param .= '&contextpage='.urlencode($contextpage);
745	}
746	if ($limit > 0 && $limit != $conf->liste_limit) {
747		$param .= '&limit='.urlencode($limit);
748	}
749	if ($sall) {
750		$param .= '&sall='.urlencode($sall);
751	}
752	if ($search_date_startday) {
753		$param .= '&search_date_startday='.urlencode($search_date_startday);
754	}
755	if ($search_date_startmonth) {
756		$param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
757	}
758	if ($search_date_startyear) {
759		$param .= '&search_date_startyear='.urlencode($search_date_startyear);
760	}
761	if ($search_date_endday) {
762		$param .= '&search_date_endday='.urlencode($search_date_endday);
763	}
764	if ($search_date_endmonth) {
765		$param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
766	}
767	if ($search_date_endyear) {
768		$param .= '&search_date_endyear='.urlencode($search_date_endyear);
769	}
770	if ($search_date_end_startday) {
771		$param .= '&search_date_end_startday='.urlencode($search_date_end_startday);
772	}
773	if ($search_date_end_startmonth) {
774		$param .= '&search_date_end_startmonth='.urlencode($search_date_end_startmonth);
775	}
776	if ($search_date_end_startyear) {
777		$param .= '&search_date_end_startyear='.urlencode($search_date_end_startyear);
778	}
779	if ($search_date_end_endday) {
780		$param .= '&search_date_end_endday='.urlencode($search_date_end_endday);
781	}
782	if ($search_date_end_endmonth) {
783		$param .= '&search_date_end_endmonth='.urlencode($search_date_end_endmonth);
784	}
785	if ($search_date_end_endyear) {
786		$param .= '&search_date_end_endyear='.urlencode($search_date_end_endyear);
787	}
788	if ($search_date_delivery_startday)	{
789		$param .= '&search_date_delivery_startday='.urlencode($search_date_delivery_startday);
790	}
791	if ($search_date_delivery_startmonth) {
792		$param .= '&search_date_delivery_startmonth='.urlencode($search_date_delivery_startmonth);
793	}
794	if ($search_date_delivery_startyear) {
795		$param .= '&search_date_delivery_startyear='.urlencode($search_date_delivery_startyear);
796	}
797	if ($search_date_delivery_endday) {
798		$param .= '&search_date_delivery_endday='.urlencode($search_date_delivery_endday);
799	}
800	if ($search_date_delivery_endmonth) {
801		$param .= '&search_date_delivery_endmonth='.urlencode($search_date_delivery_endmonth);
802	}
803	if ($search_date_delivery_endyear) {
804		$param .= '&search_date_delivery_endyear='.urlencode($search_date_delivery_endyear);
805	}
806	if ($search_ref) {
807		$param .= '&search_ref='.urlencode($search_ref);
808	}
809	if ($search_refcustomer) {
810		$param .= '&search_refcustomer='.urlencode($search_refcustomer);
811	}
812	if ($search_refproject) {
813		$param .= '&search_refproject='.urlencode($search_refproject);
814	}
815	if ($search_societe) {
816		$param .= '&search_societe='.urlencode($search_societe);
817	}
818	if ($search_societe_alias) {
819		$param .= '&search_societe_alias='.urlencode($search_societe_alias);
820	}
821	if ($search_user > 0) {
822		$param .= '&search_user='.urlencode($search_user);
823	}
824	if ($search_sale > 0) {
825		$param .= '&search_sale='.urlencode($search_sale);
826	}
827	if ($search_montant_ht) {
828		$param .= '&search_montant_ht='.urlencode($search_montant_ht);
829	}
830	if ($search_multicurrency_code != '') {
831		$param .= '&search_multicurrency_code='.urlencode($search_multicurrency_code);
832	}
833	if ($search_multicurrency_tx != '') {
834		$param .= '&search_multicurrency_tx='.urlencode($search_multicurrency_tx);
835	}
836	if ($search_multicurrency_montant_ht != '') {
837		$param .= '&search_multicurrency_montant_ht='.urlencode($search_multicurrency_montant_ht);
838	}
839	if ($search_multicurrency_montant_vat != '') {
840		$param .= '&search_multicurrency_montant_vat='.urlencode($search_multicurrency_montant_vat);
841	}
842	if ($search_multicurrency_montant_ttc != '') {
843		$param .= '&search_multicurrency_montant_ttc='.urlencode($search_multicurrency_montant_ttc);
844	}
845	if ($search_login) {
846		$param .= '&search_login='.urlencode($search_login);
847	}
848	if ($search_town) {
849		$param .= '&search_town='.urlencode($search_town);
850	}
851	if ($search_zip) {
852		$param .= '&search_zip='.urlencode($search_zip);
853	}
854	if ($socid > 0) {
855		$param .= '&socid='.urlencode($socid);
856	}
857	if ($optioncss != '') {
858		$param .= '&optioncss='.urlencode($optioncss);
859	}
860	if ($search_categ_cus > 0) {
861		$param .= '&search_categ_cus='.urlencode($search_categ_cus);
862	}
863	if ($search_product_category != '') {
864		$param .= '&search_product_category='.urlencode($search_product_category);
865	}
866	if ($search_fk_cond_reglement > 0) {
867		$param .= '&search_fk_cond_reglement='.urlencode($search_fk_cond_reglement);
868	}
869	if ($search_fk_shipping_method > 0) {
870		$param .= '&search_fk_shipping_method='.urlencode($search_fk_shipping_method);
871	}
872	if ($search_fk_input_reason > 0) {
873		$param .= '&search_fk_input_reason='.urlencode($search_fk_input_reason);
874	}
875	if ($search_fk_mode_reglement > 0) {
876		$param .= '&search_fk_mode_reglement='.urlencode($search_fk_mode_reglement);
877	}
878	if ($search_type_thirdparty > 0) {
879		$param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
880	}
881	if ($search_town) {
882		$param .= '&search_town='.urlencode($search_town);
883	}
884	if ($search_zip) {
885		$param .= '&search_zip='.urlencode($search_zip);
886	}
887	if ($search_state) {
888		$param .= '&search_state='.urlencode($search_state);
889	}
890	if ($search_town) {
891		$param .= '&search_town='.urlencode($search_town);
892	}
893	if ($search_country) {
894		$param .= '&search_country='.urlencode($search_country);
895	}
896
897	// Add $param from extra fields
898	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
899
900	// List of mass actions available
901	$arrayofmassactions = array(
902		'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
903		'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
904	);
905	if ($permissiontosendbymail) {
906		$arrayofmassactions['presend']=img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail");
907	}
908	if ($permissiontovalidate) {
909		$arrayofmassactions['prevalidate']=img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate");
910	}
911	if ($permissiontoclose) {
912		$arrayofmassactions['presign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("Sign");
913		$arrayofmassactions['nopresign']=img_picto('', 'propal', 'class="pictofixedwidth"').$langs->trans("NoSign");
914		$arrayofmassactions['setbilled'] =img_picto('', 'bill', 'class="pictofixedwidth"').$langs->trans("ClassifyBilled");
915	}
916	if ($permissiontodelete) {
917		$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
918	}
919
920	if (in_array($massaction, array('presend', 'predelete', 'closed'))) {
921		$arrayofmassactions = array();
922	}
923	$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
924
925	$url = DOL_URL_ROOT.'/comm/propal/card.php?action=create';
926	if (!empty($socid)) {
927		$url .= '&socid='.$socid;
928	}
929	$newcardbutton = dolGetButtonTitle($langs->trans('NewPropal'), '', 'fa fa-plus-circle', $url, '', $user->rights->propal->creer);
930
931	// Fields title search
932	print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">';
933	if ($optioncss != '') {
934		print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
935	}
936	print '<input type="hidden" name="token" value="'.newToken().'">';
937	print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
938	print '<input type="hidden" name="action" value="list">';
939	print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
940	print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
941	print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
942
943	print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'propal', 0, $newcardbutton, '', $limit, 0, 0, 1);
944
945	$topicmail = "SendPropalRef";
946	$modelmail = "propal_send";
947	$objecttmp = new Propal($db);
948	$trackid = 'pro'.$object->id;
949	include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
950
951	if ($massaction == 'prevalidate') {
952		print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassValidation"), $langs->trans("ConfirmMassValidationQuestion"), "validate", null, '', 0, 200, 500, 1);
953	}
954
955	if ($massaction == 'presign') {
956		print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassSignature"), $langs->trans("ConfirmMassSignatureQuestion"), "sign", null, '', 0, 200, 500, 1);
957	}
958
959	if ($massaction == 'nopresign') {
960		print $form->formconfirm($_SERVER["PHP_SELF"], $langs->trans("ConfirmMassNoSignature"), $langs->trans("ConfirmMassNoSignatureQuestion"), "nosign", null, '', 0, 200, 500, 1);
961	}
962
963	if ($sall) {
964		foreach ($fieldstosearchall as $key => $val) {
965			$fieldstosearchall[$key] = $langs->trans($val);
966		}
967		print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
968	}
969
970	$i = 0;
971
972	$moreforfilter = '';
973
974	// If the user can view prospects other than his'
975	if ($user->rights->societe->client->voir || $socid) {
976		$langs->load("commercial");
977		$moreforfilter .= '<div class="divsearchfield">';
978		$tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
979		$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'maxwidth250');
980		$moreforfilter .= '</div>';
981	}
982	// If the user can view prospects other than his'
983	if ($user->rights->societe->client->voir || $socid) {
984		$moreforfilter .= '<div class="divsearchfield">';
985		$tmptitle =  $langs->trans('LinkedToSpecificUsers');
986		$moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth250');
987		$moreforfilter .= '</div>';
988	}
989	// If the user can view products
990	if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
991		include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
992		$moreforfilter .= '<div class="divsearchfield">';
993		$tmptitle = $langs->trans('IncludingProductWithTag');
994		$cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
995		$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300' : 'maxwidth250'), 1);
996		$moreforfilter .= '</div>';
997	}
998	if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
999		require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
1000		$moreforfilter .= '<div class="divsearchfield">';
1001		$tmptitle = $langs->trans('CustomersProspectsCategoriesShort');
1002		$moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$formother->select_categories('customer', $search_categ_cus, 'search_categ_cus', 1, $tmptitle, (empty($conf->dol_optimize_smallscreen) ? 'maxwidth300' : 'maxwidth250'));
1003		$moreforfilter .= '</div>';
1004	}
1005	if (!empty($conf->stock->enabled) && !empty($conf->global->WAREHOUSE_ASK_WAREHOUSE_DURING_PROPAL)) {
1006		require_once DOL_DOCUMENT_ROOT.'/product/class/html.formproduct.class.php';
1007		$formproduct = new FormProduct($db);
1008		$moreforfilter .= '<div class="divsearchfield">';
1009		$tmptitle = $langs->trans('Warehouse');
1010		$moreforfilter .= img_picto($tmptitle, 'stock', 'class="pictofixedwidth"').$formproduct->selectWarehouses($search_warehouse, 'search_warehouse', '', $tmptitle, 0, 0, $tmptitle);
1011		$moreforfilter .= '</div>';
1012	}
1013	$parameters = array();
1014	$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
1015	if (empty($reshook)) {
1016		$moreforfilter .= $hookmanager->resPrint;
1017	} else {
1018		$moreforfilter = $hookmanager->resPrint;
1019	}
1020
1021	if (!empty($moreforfilter)) {
1022		print '<div class="liste_titre liste_titre_bydiv centpercent">';
1023		print $moreforfilter;
1024		print '</div>';
1025	}
1026
1027	$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
1028	$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
1029	$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
1030
1031	print '<div class="div-table-responsive">';
1032	print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
1033
1034	print '<tr class="liste_titre_filter">';
1035	if (!empty($arrayfields['p.ref']['checked'])) {
1036		print '<td class="liste_titre">';
1037		print '<input class="flat maxwidth50" type="text" name="search_ref" value="'.dol_escape_htmltag($search_ref).'">';
1038		print '</td>';
1039	}
1040	if (!empty($arrayfields['p.ref_client']['checked'])) {
1041		print '<td class="liste_titre">';
1042		print '<input class="flat maxwidth50" type="text" name="search_refcustomer" value="'.dol_escape_htmltag($search_refcustomer).'">';
1043		print '</td>';
1044	}
1045	if (!empty($arrayfields['pr.ref']['checked'])) {
1046		print '<td class="liste_titre">';
1047		print '<input class="flat maxwidth50" type="text" name="search_refproject" value="'.dol_escape_htmltag($search_refproject).'">';
1048		print '</td>';
1049	}
1050	if (!empty($arrayfields['pr.title']['checked'])) {
1051		print '<td class="liste_titre">';
1052		print '<input class="flat maxwidth50" type="text" name="search_project" value="'.dol_escape_htmltag($search_project).'">';
1053		print '</td>';
1054	}
1055	if (!empty($arrayfields['s.nom']['checked'])) {
1056		print '<td class="liste_titre" align="left">';
1057		print '<input class="flat maxwidth100" type="text" name="search_societe" value="'.dol_escape_htmltag($search_societe).'">';
1058		print '</td>';
1059	}
1060	if (!empty($arrayfields['s.name_alias']['checked'])) {
1061		print '<td class="liste_titre" align="left">';
1062		print '<input class="flat maxwidth100" type="text" name="search_societe_alias" value="'.dol_escape_htmltag($search_societe_alias).'">';
1063		print '</td>';
1064	}
1065	if (!empty($arrayfields['s.town']['checked'])) {
1066		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_town" value="'.$search_town.'"></td>';
1067	}
1068	if (!empty($arrayfields['s.zip']['checked'])) {
1069		print '<td class="liste_titre"><input class="flat maxwidth50" type="text" name="search_zip" value="'.$search_zip.'"></td>';
1070	}
1071	// State
1072	if (!empty($arrayfields['state.nom']['checked'])) {
1073		print '<td class="liste_titre">';
1074		print '<input class="flat maxwidth50" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
1075		print '</td>';
1076	}
1077	// Country
1078	if (!empty($arrayfields['country.code_iso']['checked'])) {
1079		print '<td class="liste_titre" align="center">';
1080		print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
1081		print '</td>';
1082	}
1083	// Company type
1084	if (!empty($arrayfields['typent.code']['checked'])) {
1085		print '<td class="liste_titre maxwidth100onsmartphone" align="center">';
1086		print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
1087		print ajax_combobox('search_type_thirdparty');
1088		print '</td>';
1089	}
1090	// Date
1091	if (!empty($arrayfields['p.date']['checked'])) {
1092		print '<td class="liste_titre center">';
1093		print '<div class="nowrap">';
1094		print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1095		print '</div>';
1096		print '<div class="nowrap">';
1097		print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1098		print '</div>';
1099		print '</td>';
1100	}
1101	// Date end
1102	if (!empty($arrayfields['p.fin_validite']['checked'])) {
1103		print '<td class="liste_titre center">';
1104		print '<div class="nowrap">';
1105		print $form->selectDate($search_date_end_start ? $search_date_end_start : -1, 'search_date_end_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1106		print '</div>';
1107		print '<div class="nowrap">';
1108		print $form->selectDate($search_date_end_end ? $search_date_end_end : -1, 'search_date_end_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
1109		print '</div>';
1110		print '</td>';
1111	}
1112	// Date delivery
1113	if (!empty($arrayfields['p.date_livraison']['checked'])) {
1114		print '<td class="liste_titre center">';
1115		print '<div class="nowrap">';
1116		print $form->selectDate($search_date_delivery_start ? $search_date_delivery_start : -1, 'search_date_delivery_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1117		print '</div>';
1118		print '<div class="nowrap">';
1119		print $form->selectDate($search_date_delivery_end ? $search_date_delivery_end : -1, 'search_date_delivery_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
1120		print '</div>';
1121		print '</td>';
1122	}
1123	// Availability
1124	if (!empty($arrayfields['ava.rowid']['checked'])) {
1125		print '<td class="liste_titre maxwidth100onsmartphone center">';
1126		$form->selectAvailabilityDelay($search_availability, 'search_availability', '', 1);
1127		print ajax_combobox('search_availability');
1128		print '</td>';
1129	}
1130	// Shipping Method
1131	if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1132		print '<td class="liste_titre">';
1133		$form->selectShippingMethod($search_fk_shipping_method, 'search_fk_shipping_method', '', 1, '', 1);
1134		print '</td>';
1135	}
1136	// Source - Input reason
1137	if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1138		print '<td class="liste_titre">';
1139		$form->selectInputReason($search_fk_input_reason, 'search_fk_input_reason', '', 1, 'maxwidth125', 1);
1140		print '</td>';
1141	}
1142	// Payment term
1143	if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1144		print '<td class="liste_titre">';
1145		$form->select_conditions_paiements($search_fk_cond_reglement, 'search_fk_cond_reglement', -1, 1, 1);
1146		print '</td>';
1147	}
1148	// Payment mode
1149	if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1150		print '<td class="liste_titre">';
1151		$form->select_types_paiements($search_fk_mode_reglement, 'search_fk_mode_reglement', '', 0, 1, 1, 0, -1);
1152		print '</td>';
1153	}
1154	if (!empty($arrayfields['p.total_ht']['checked'])) {
1155		// Amount
1156		print '<td class="liste_titre right">';
1157		print '<input class="flat" type="text" size="5" name="search_montant_ht" value="'.dol_escape_htmltag($search_montant_ht).'">';
1158		print '</td>';
1159	}
1160	if (!empty($arrayfields['p.total_tva']['checked'])) {
1161		// Amount
1162		print '<td class="liste_titre right">';
1163		print '<input class="flat" type="text" size="5" name="search_montant_vat" value="'.dol_escape_htmltag($search_montant_vat).'">';
1164		print '</td>';
1165	}
1166	if (!empty($arrayfields['p.total_ttc']['checked'])) {
1167		// Amount
1168		print '<td class="liste_titre right">';
1169		print '<input class="flat" type="text" size="5" name="search_montant_ttc" value="'.dol_escape_htmltag($search_montant_ttc).'">';
1170		print '</td>';
1171	}
1172	if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1173		// Amount invoiced
1174		print '<td class="liste_titre right">';
1175		print '</td>';
1176	}
1177	if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1178		// Amount invoiced
1179		print '<td class="liste_titre right">';
1180		print '</td>';
1181	}
1182	if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1183		// Currency
1184		print '<td class="liste_titre">';
1185		print $form->selectMultiCurrency($search_multicurrency_code, 'search_multicurrency_code', 1);
1186		print '</td>';
1187	}
1188	if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1189		// Currency rate
1190		print '<td class="liste_titre">';
1191		print '<input class="flat" type="text" size="4" name="search_multicurrency_tx" value="'.dol_escape_htmltag($search_multicurrency_tx).'">';
1192		print '</td>';
1193	}
1194	if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1195		// Amount
1196		print '<td class="liste_titre right">';
1197		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ht" value="'.dol_escape_htmltag($search_multicurrency_montant_ht).'">';
1198		print '</td>';
1199	}
1200	if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1201		// Amount
1202		print '<td class="liste_titre right">';
1203		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_vat" value="'.dol_escape_htmltag($search_multicurrency_montant_vat).'">';
1204		print '</td>';
1205	}
1206	if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1207		// Amount
1208		print '<td class="liste_titre right">';
1209		print '<input class="flat" type="text" size="4" name="search_multicurrency_montant_ttc" value="'.dol_escape_htmltag($search_multicurrency_montant_ttc).'">';
1210		print '</td>';
1211	}
1212	if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1213		// Amount invoiced
1214		print '<td class="liste_titre right">';
1215		print '</td>';
1216	}
1217	if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1218		// Amount invoiced
1219		print '<td class="liste_titre right">';
1220		print '</td>';
1221	}
1222	if (!empty($arrayfields['u.login']['checked'])) {
1223		// Author
1224		print '<td class="liste_titre" align="center">';
1225		print '<input class="flat" size="4" type="text" name="search_login" value="'.dol_escape_htmltag($search_login).'">';
1226		print '</td>';
1227	}
1228	if (!empty($arrayfields['sale_representative']['checked'])) {
1229		print '<td class="liste_titre"></td>';
1230	}
1231	// Extra fields
1232	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
1233
1234	// Fields from hook
1235	$parameters = array('arrayfields'=>$arrayfields);
1236	$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
1237	print $hookmanager->resPrint;
1238	// Date creation
1239	if (!empty($arrayfields['p.datec']['checked'])) {
1240		print '<td class="liste_titre">';
1241		print '</td>';
1242	}
1243	// Date modification
1244	if (!empty($arrayfields['p.tms']['checked'])) {
1245		print '<td class="liste_titre">';
1246		print '</td>';
1247	}
1248	// Date cloture
1249	if (!empty($arrayfields['p.date_cloture']['checked'])) {
1250		print '<td class="liste_titre">';
1251		print '</td>';
1252	}
1253	if (!empty($arrayfields['p.note_public']['checked'])) {
1254		// Note public
1255		print '<td class="liste_titre">';
1256		print '</td>';
1257	}
1258	if (!empty($arrayfields['p.note_private']['checked'])) {
1259		// Note private
1260		print '<td class="liste_titre">';
1261		print '</td>';
1262	}
1263	// Status
1264	if (!empty($arrayfields['p.fk_statut']['checked'])) {
1265		print '<td class="liste_titre maxwidthonsmartphone right">';
1266		$formpropal->selectProposalStatus($search_status, 1, 0, 1, 'customer', 'search_statut');
1267		print '</td>';
1268	}
1269	// Action column
1270	print '<td class="liste_titre" align="middle">';
1271	$searchpicto = $form->showFilterButtons();
1272	print $searchpicto;
1273	print '</td>';
1274
1275	print "</tr>\n";
1276
1277
1278	// Fields title
1279	print '<tr class="liste_titre">';
1280	if (!empty($arrayfields['p.ref']['checked'])) {
1281		print_liste_field_titre($arrayfields['p.ref']['label'], $_SERVER["PHP_SELF"], 'p.ref', '', $param, '', $sortfield, $sortorder);
1282	}
1283	if (!empty($arrayfields['p.ref_client']['checked'])) {
1284		print_liste_field_titre($arrayfields['p.ref_client']['label'], $_SERVER["PHP_SELF"], 'p.ref_client', '', $param, '', $sortfield, $sortorder);
1285	}
1286	if (!empty($arrayfields['pr.ref']['checked'])) {
1287		print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], 'pr.ref', '', $param, '', $sortfield, $sortorder);
1288	}
1289	if (!empty($arrayfields['pr.title']['checked'])) {
1290		print_liste_field_titre($arrayfields['pr.title']['label'], $_SERVER["PHP_SELF"], 'pr.title', '', $param, '', $sortfield, $sortorder);
1291	}
1292	if (!empty($arrayfields['s.nom']['checked'])) {
1293		print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], 's.nom', '', $param, '', $sortfield, $sortorder);
1294	}
1295	if (!empty($arrayfields['s.name_alias']['checked'])) {
1296		print_liste_field_titre($arrayfields['s.name_alias']['label'], $_SERVER["PHP_SELF"], 's.name_alias', '', $param, '', $sortfield, $sortorder);
1297	}
1298	if (!empty($arrayfields['s.town']['checked'])) {
1299		print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1300	}
1301	if (!empty($arrayfields['s.zip']['checked'])) {
1302		print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1303	}
1304	if (!empty($arrayfields['state.nom']['checked'])) {
1305		print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1306	}
1307	if (!empty($arrayfields['country.code_iso']['checked'])) {
1308		print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, 'align="center"', $sortfield, $sortorder);
1309	}
1310	if (!empty($arrayfields['typent.code']['checked'])) {
1311		print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, 'align="center"', $sortfield, $sortorder);
1312	}
1313	if (!empty($arrayfields['p.date']['checked'])) {
1314		print_liste_field_titre($arrayfields['p.date']['label'], $_SERVER["PHP_SELF"], 'p.datep', '', $param, 'align="center"', $sortfield, $sortorder);
1315	}
1316	if (!empty($arrayfields['p.fin_validite']['checked'])) {
1317		print_liste_field_titre($arrayfields['p.fin_validite']['label'], $_SERVER["PHP_SELF"], 'dfv', '', $param, 'align="center"', $sortfield, $sortorder);
1318	}
1319	if (!empty($arrayfields['p.date_livraison']['checked'])) {
1320		print_liste_field_titre($arrayfields['p.date_livraison']['label'], $_SERVER["PHP_SELF"], 'ddelivery', '', $param, 'align="center"', $sortfield, $sortorder);
1321	}
1322	if (!empty($arrayfields['ava.rowid']['checked'])) {
1323		print_liste_field_titre($arrayfields['ava.rowid']['label'], $_SERVER["PHP_SELF"], 'availability', '', $param, '', $sortfield, $sortorder);
1324	}
1325	if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1326		print_liste_field_titre($arrayfields['p.fk_shipping_method']['label'], $_SERVER["PHP_SELF"], "p.fk_shipping_method", "", $param, '', $sortfield, $sortorder);
1327	}
1328	if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1329		print_liste_field_titre($arrayfields['p.fk_input_reason']['label'], $_SERVER["PHP_SELF"], "p.fk_input_reason", "", $param, '', $sortfield, $sortorder);
1330	}
1331	if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1332		print_liste_field_titre($arrayfields['p.fk_cond_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_cond_reglement", "", $param, '', $sortfield, $sortorder);
1333	}
1334	if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1335		print_liste_field_titre($arrayfields['p.fk_mode_reglement']['label'], $_SERVER["PHP_SELF"], "p.fk_mode_reglement", "", $param, '', $sortfield, $sortorder);
1336	}
1337	if (!empty($arrayfields['p.total_ht']['checked'])) {
1338		print_liste_field_titre($arrayfields['p.total_ht']['label'], $_SERVER["PHP_SELF"], 'p.total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1339	}
1340	if (!empty($arrayfields['p.total_tva']['checked'])) {
1341		print_liste_field_titre($arrayfields['p.total_tva']['label'], $_SERVER["PHP_SELF"], 'p.total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1342	}
1343	if (!empty($arrayfields['p.total_ttc']['checked'])) {
1344		print_liste_field_titre($arrayfields['p.total_ttc']['label'], $_SERVER["PHP_SELF"], 'p.total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1345	}
1346	if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1347		print_liste_field_titre($arrayfields['p.total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1348	}
1349	if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1350		print_liste_field_titre($arrayfields['p.total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1351	}
1352	if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1353		print_liste_field_titre($arrayfields['p.multicurrency_code']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_code', '', $param, '', $sortfield, $sortorder);
1354	}
1355	if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1356		print_liste_field_titre($arrayfields['p.multicurrency_tx']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_tx', '', $param, '', $sortfield, $sortorder);
1357	}
1358	if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1359		print_liste_field_titre($arrayfields['p.multicurrency_total_ht']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ht', '', $param, 'class="right"', $sortfield, $sortorder);
1360	}
1361	if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1362		print_liste_field_titre($arrayfields['p.multicurrency_total_tva']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_tva', '', $param, 'class="right"', $sortfield, $sortorder);
1363	}
1364	if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1365		print_liste_field_titre($arrayfields['p.multicurrency_total_ttc']['label'], $_SERVER['PHP_SELF'], 'p.multicurrency_total_ttc', '', $param, 'class="right"', $sortfield, $sortorder);
1366	}
1367	if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1368		print_liste_field_titre($arrayfields['p.multicurrency_total_ht_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1369	}
1370	if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1371		print_liste_field_titre($arrayfields['p.multicurrency_total_invoiced']['label'], $_SERVER["PHP_SELF"], '', '', $param, 'class="right"', $sortfield, $sortorder);
1372	}
1373	if (!empty($arrayfields['u.login']['checked'])) {
1374		print_liste_field_titre($arrayfields['u.login']['label'], $_SERVER["PHP_SELF"], 'u.login', '', $param, 'align="center"', $sortfield, $sortorder);
1375	}
1376	if (!empty($arrayfields['sale_representative']['checked'])) {
1377		print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", "$param", '', $sortfield, $sortorder);
1378	}
1379	// Extra fields
1380	include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1381	// Hook fields
1382	$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
1383	$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
1384	print $hookmanager->resPrint;
1385	if (!empty($arrayfields['p.datec']['checked'])) {
1386		print_liste_field_titre($arrayfields['p.datec']['label'], $_SERVER["PHP_SELF"], "p.datec", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1387	}
1388	if (!empty($arrayfields['p.tms']['checked'])) {
1389		print_liste_field_titre($arrayfields['p.tms']['label'], $_SERVER["PHP_SELF"], "p.tms", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1390	}
1391	if (!empty($arrayfields['p.date_cloture']['checked'])) {
1392		print_liste_field_titre($arrayfields['p.date_cloture']['label'], $_SERVER["PHP_SELF"], "p.date_cloture", "", $param, 'align="center" class="nowrap"', $sortfield, $sortorder);
1393	}
1394	if (!empty($arrayfields['p.note_public']['checked'])) {
1395		print_liste_field_titre($arrayfields['p.note_public']['label'], $_SERVER["PHP_SELF"], "p.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1396	}
1397	if (!empty($arrayfields['p.note_private']['checked'])) {
1398		print_liste_field_titre($arrayfields['p.note_private']['label'], $_SERVER["PHP_SELF"], "p.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1399	}
1400	if (!empty($arrayfields['p.fk_statut']['checked'])) {
1401		print_liste_field_titre($arrayfields['p.fk_statut']['label'], $_SERVER["PHP_SELF"], "p.fk_statut", "", $param, 'class="right"', $sortfield, $sortorder);
1402	}
1403	print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', 'align="center"', $sortfield, $sortorder, 'maxwidthsearch ');
1404	print '</tr>'."\n";
1405
1406	$now = dol_now();
1407	$i = 0;
1408	$totalarray = array();
1409	$totalarray['nbfield'] = 0;
1410	$totalarray['val'] = array();
1411	$totalarray['val']['p.total_ht'] = 0;
1412	$totalarray['val']['p.total_tva'] = 0;
1413	$totalarray['val']['p.total_ttc'] = 0;
1414	$typenArray = null;
1415
1416	while ($i < min($num, $limit)) {
1417		$obj = $db->fetch_object($resql);
1418
1419		$objectstatic->id = $obj->rowid;
1420		$objectstatic->ref = $obj->ref;
1421		$objectstatic->ref_client = $obj->ref_client;
1422		$objectstatic->note_public = $obj->note_public;
1423		$objectstatic->note_private = $obj->note_private;
1424		$objectstatic->statut = $obj->status;
1425		$objectstatic->status = $obj->status;
1426
1427		$companystatic->id = $obj->socid;
1428		$companystatic->name = $obj->name;
1429		$companystatic->name_alias = $obj->alias;
1430		$companystatic->client = $obj->client;
1431		$companystatic->code_client = $obj->code_client;
1432		$companystatic->email = $obj->email;
1433		$companystatic->phone = $obj->phone;
1434		$companystatic->address = $obj->address;
1435		$companystatic->zip = $obj->zip;
1436		$companystatic->town = $obj->town;
1437		$companystatic->country_code = $obj->country_code;
1438
1439		$projectstatic->id = $obj->project_id;
1440		$projectstatic->ref = $obj->project_ref;
1441		$projectstatic->title = $obj->project_label;
1442
1443		$totalInvoicedHT = 0;
1444		$totalInvoicedTTC = 0;
1445		$multicurrency_totalInvoicedHT = 0;
1446		$multicurrency_totalInvoicedTTC = 0;
1447
1448		$TInvoiceData = $objectstatic->InvoiceArrayList($obj->rowid);
1449
1450		if (!empty($TInvoiceData)) {
1451			foreach ($TInvoiceData as $invoiceData) {
1452				$invoice = new Facture($db);
1453				$invoice->fetch($invoiceData->facid);
1454
1455				if (!empty($conf->global->FACTURE_DEPOSITS_ARE_JUST_PAYMENTS) && $invoice->type == Facture::TYPE_DEPOSIT) {
1456					continue;
1457				}
1458
1459				$totalInvoicedHT += $invoice->total_ht;
1460				$totalInvoicedTTC += $invoice->total_ttc;
1461				$multicurrency_totalInvoicedHT += $invoice->multicurrency_total_ht;
1462				$multicurrency_totalInvoicedTTC += $invoice->multicurrency_total_ttc;
1463			}
1464		}
1465
1466		print '<tr class="oddeven">';
1467
1468		if (!empty($arrayfields['p.ref']['checked'])) {
1469			print '<td class="nowraponall">';
1470
1471			print '<table class="nobordernopadding"><tr class="nocellnopadd">';
1472			// Picto + Ref
1473			print '<td class="nobordernopadding nowraponall">';
1474			print $objectstatic->getNomUrl(1, '', '', 0, 1, (isset($conf->global->PROPAL_LIST_SHOW_NOTES) ? $conf->global->PROPAL_LIST_SHOW_NOTES : 1));
1475			print '</td>';
1476			// Warning
1477			$warnornote = '';
1478			if ($obj->status == Propal::STATUS_VALIDATED && $db->jdate($obj->dfv) < ($now - $conf->propal->cloture->warning_delay)) {
1479				$warnornote .= img_warning($langs->trans("Late"));
1480			}
1481			if ($warnornote) {
1482				print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
1483				print $warnornote;
1484				print '</td>';
1485			}
1486			// Other picto tool
1487			print '<td width="16" class="nobordernopadding right">';
1488			$filename = dol_sanitizeFileName($obj->ref);
1489			$filedir = $conf->propal->multidir_output[$obj->propal_entity].'/'.dol_sanitizeFileName($obj->ref);
1490			$urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1491			print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
1492			print '</td></tr></table>';
1493
1494			print "</td>\n";
1495			if (!$i) {
1496				$totalarray['nbfield']++;
1497			}
1498		}
1499
1500		if (!empty($arrayfields['p.ref_client']['checked'])) {
1501			// Customer ref
1502			print '<td class="nowrap tdoverflowmax200">';
1503			print $obj->ref_client;
1504			print '</td>';
1505			if (!$i) {
1506				$totalarray['nbfield']++;
1507			}
1508		}
1509
1510		if (!empty($arrayfields['pr.ref']['checked'])) {
1511			// Project ref
1512			print '<td class="nowraponall">';
1513			if ($obj->project_id > 0) {
1514				print $projectstatic->getNomUrl(1);
1515			}
1516			print '</td>';
1517			if (!$i) {
1518				$totalarray['nbfield']++;
1519			}
1520		}
1521
1522		if (!empty($arrayfields['pr.title']['checked'])) {
1523			// Project label
1524			print '<td class="nowrap">';
1525			if ($obj->project_id > 0) {
1526				print $projectstatic->title;
1527			}
1528			print '</td>';
1529			if (!$i) {
1530				$totalarray['nbfield']++;
1531			}
1532		}
1533
1534		// Thirdparty
1535		if (!empty($arrayfields['s.nom']['checked'])) {
1536			print '<td class="tdoverflowmax200">';
1537			print $companystatic->getNomUrl(1, 'customer');
1538			print '</td>';
1539			if (!$i) {
1540				$totalarray['nbfield']++;
1541			}
1542		}
1543
1544		// Alias
1545		if (!empty($arrayfields['s.name_alias']['checked'])) {
1546			print '<td class="tdoverflowmax200">';
1547			print $obj->alias;
1548			print '</td>';
1549			if (!$i) {
1550				$totalarray['nbfield']++;
1551			}
1552		}
1553
1554		// Town
1555		if (!empty($arrayfields['s.town']['checked'])) {
1556			print '<td class="nocellnopadd">';
1557			print $obj->town;
1558			print '</td>';
1559			if (!$i) {
1560				$totalarray['nbfield']++;
1561			}
1562		}
1563		// Zip
1564		if (!empty($arrayfields['s.zip']['checked'])) {
1565			print '<td class="nocellnopadd">';
1566			print $obj->zip;
1567			print '</td>';
1568			if (!$i) {
1569				$totalarray['nbfield']++;
1570			}
1571		}
1572		// State
1573		if (!empty($arrayfields['state.nom']['checked'])) {
1574			print "<td>".$obj->state_name."</td>\n";
1575			if (!$i) {
1576				$totalarray['nbfield']++;
1577			}
1578		}
1579		// Country
1580		if (!empty($arrayfields['country.code_iso']['checked'])) {
1581			print '<td class="center">';
1582			$tmparray = getCountry($obj->fk_pays, 'all');
1583			print $tmparray['label'];
1584			print '</td>';
1585			if (!$i) {
1586				$totalarray['nbfield']++;
1587			}
1588		}
1589		// Type ent
1590		if (!empty($arrayfields['typent.code']['checked'])) {
1591			if (!is_array($typenArray) || empty($typenArray)) {
1592				$typenArray = $formcompany->typent_array(1);
1593			}
1594
1595			print '<td class="center">';
1596			print $typenArray[$obj->typent_code];
1597			print '</td>';
1598			if (!$i) {
1599				$totalarray['nbfield']++;
1600			}
1601		}
1602
1603		// Date proposal
1604		if (!empty($arrayfields['p.date']['checked'])) {
1605			print '<td class="center">';
1606			print dol_print_date($db->jdate($obj->dp), 'day');
1607			print "</td>\n";
1608			if (!$i) {
1609				$totalarray['nbfield']++;
1610			}
1611		}
1612
1613		// Date end validity
1614		if (!empty($arrayfields['p.fin_validite']['checked'])) {
1615			if ($obj->dfv) {
1616				print '<td class="center">'.dol_print_date($db->jdate($obj->dfv), 'day');
1617				print '</td>';
1618			} else {
1619				print '<td>&nbsp;</td>';
1620			}
1621			if (!$i) {
1622				$totalarray['nbfield']++;
1623			}
1624		}
1625		// Date delivery
1626		if (!empty($arrayfields['p.date_livraison']['checked'])) {
1627			if ($obj->ddelivery) {
1628				print '<td class="center">'.dol_print_date($db->jdate($obj->ddelivery), 'day');
1629				print '</td>';
1630			} else {
1631				print '<td>&nbsp;</td>';
1632			}
1633			if (!$i) {
1634				$totalarray['nbfield']++;
1635			}
1636		}
1637		// Availability
1638		if (!empty($arrayfields['ava.rowid']['checked'])) {
1639			print '<td class="center">';
1640			$form->form_availability('', $obj->availability, 'none', 1);
1641			print '</td>';
1642			if (!$i) {
1643				$totalarray['nbfield']++;
1644			}
1645		}
1646		// Shipping Method
1647		if (!empty($arrayfields['p.fk_shipping_method']['checked'])) {
1648			print '<td>';
1649			$form->formSelectShippingMethod('', $obj->fk_shipping_method, 'none', 1);
1650			print '</td>';
1651			if (!$i) {
1652				$totalarray['nbfield']++;
1653			}
1654		}
1655		// Source - input reason
1656		if (!empty($arrayfields['p.fk_input_reason']['checked'])) {
1657			print '<td class="tdoverflowmax125" title="'.dol_escape_htmltag($form->cache_demand_reason[$obj->fk_input_reason]['label']).'">';
1658			if ($obj->fk_input_reason > 0) {
1659				print $form->cache_demand_reason[$obj->fk_input_reason]['label'];
1660			}
1661			print '</td>';
1662			if (!$i) {
1663				$totalarray['nbfield']++;
1664			}
1665		}
1666		// Payment terms
1667		if (!empty($arrayfields['p.fk_cond_reglement']['checked'])) {
1668			print '<td>';
1669			$form->form_conditions_reglement($_SERVER['PHP_SELF'], $obj->fk_cond_reglement, 'none');
1670			print '</td>';
1671			if (!$i) {
1672				$totalarray['nbfield']++;
1673			}
1674		}
1675		// Payment mode
1676		if (!empty($arrayfields['p.fk_mode_reglement']['checked'])) {
1677			print '<td>';
1678			$form->form_modes_reglement($_SERVER['PHP_SELF'], $obj->fk_mode_reglement, 'none', '', -1);
1679			print '</td>';
1680			if (!$i) {
1681				$totalarray['nbfield']++;
1682			}
1683		}
1684		// Amount HT
1685		if (!empty($arrayfields['p.total_ht']['checked'])) {
1686			print '<td class="nowrap right"><span class="amount">'.price($obj->total_ht)."</span></td>\n";
1687			if (!$i) {
1688				$totalarray['nbfield']++;
1689			}
1690			if (!$i) {
1691				$totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht';
1692			}
1693			$totalarray['val']['p.total_ht'] += $obj->total_ht;
1694		}
1695		// Amount VAT
1696		if (!empty($arrayfields['p.total_tva']['checked'])) {
1697			print '<td class="nowrap right"><span class="amount">'.price($obj->total_tva)."</span></td>\n";
1698			if (!$i) {
1699				$totalarray['nbfield']++;
1700			}
1701			if (!$i) {
1702				$totalarray['pos'][$totalarray['nbfield']] = 'p.total_tva';
1703			}
1704			$totalarray['val']['p.total_tva'] += $obj->total_tva;
1705		}
1706		// Amount TTC
1707		if (!empty($arrayfields['p.total_ttc']['checked'])) {
1708			print '<td class="nowrap right"><span class="amount">'.price($obj->total_ttc)."</span></td>\n";
1709			if (!$i) {
1710				$totalarray['nbfield']++;
1711			}
1712			if (!$i) {
1713				$totalarray['pos'][$totalarray['nbfield']] = 'p.total_ttc';
1714			}
1715			$totalarray['val']['p.total_ttc'] += $obj->total_ttc;
1716		}
1717		// Amount invoiced HT
1718		if (!empty($arrayfields['p.total_ht_invoiced']['checked'])) {
1719			print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedHT)."</span></td>\n";
1720			if (!$i) {
1721				$totalarray['nbfield']++;
1722			}
1723			if (!$i) {
1724				$totalarray['pos'][$totalarray['nbfield']] = 'p.total_ht_invoiced';
1725			}
1726			$totalarray['val']['p.total_ht_invoiced'] += $totalInvoicedHT;
1727		}
1728		// Amount invoiced TTC
1729		if (!empty($arrayfields['p.total_invoiced']['checked'])) {
1730			print '<td class="nowrap right"><span class="amount">'.price($totalInvoicedTTC)."</span></td>\n";
1731			if (!$i) {
1732				$totalarray['nbfield']++;
1733			}
1734			if (!$i) {
1735				$totalarray['pos'][$totalarray['nbfield']] = 'p.total_invoiced';
1736			}
1737			$totalarray['val']['p.total_invoiced'] += $totalInvoicedTTC;
1738		}
1739		// Currency
1740		if (!empty($arrayfields['p.multicurrency_code']['checked'])) {
1741			print '<td class="nowrap">'.$obj->multicurrency_code.' - '.$langs->trans('Currency'.$obj->multicurrency_code)."</td>\n";
1742			if (!$i) {
1743				$totalarray['nbfield']++;
1744			}
1745		}
1746
1747		// Currency rate
1748		if (!empty($arrayfields['p.multicurrency_tx']['checked'])) {
1749			print '<td class="nowrap">';
1750			$form->form_multicurrency_rate($_SERVER['PHP_SELF'].'?id='.$obj->rowid, $obj->multicurrency_tx, 'none', $obj->multicurrency_code);
1751			print "</td>\n";
1752			if (!$i) {
1753				$totalarray['nbfield']++;
1754			}
1755		}
1756		// Amount HT
1757		if (!empty($arrayfields['p.multicurrency_total_ht']['checked'])) {
1758			print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ht)."</span></td>\n";
1759			if (!$i) {
1760				$totalarray['nbfield']++;
1761			}
1762		}
1763		// Amount VAT
1764		if (!empty($arrayfields['p.multicurrency_total_tva']['checked'])) {
1765			print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_tva)."</span></td>\n";
1766			if (!$i) {
1767				$totalarray['nbfield']++;
1768			}
1769		}
1770		// Amount TTC
1771		if (!empty($arrayfields['p.multicurrency_total_ttc']['checked'])) {
1772			print '<td class="right nowrap"><span class="amount">'.price($obj->multicurrency_total_ttc)."</span></td>\n";
1773			if (!$i) {
1774				$totalarray['nbfield']++;
1775			}
1776		}
1777		// Amount invoiced
1778		if (!empty($arrayfields['p.multicurrency_total_ht_invoiced']['checked'])) {
1779			print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedHT)."</span></td>\n";
1780			if (!$i) {
1781				$totalarray['nbfield']++;
1782			}
1783		}
1784		// Amount invoiced
1785		if (!empty($arrayfields['p.multicurrency_total_invoiced']['checked'])) {
1786			print '<td class="nowrap right"><span class="amount">'.price($multicurrency_totalInvoicedTTC)."</span></td>\n";
1787			if (!$i) {
1788				$totalarray['nbfield']++;
1789			}
1790		}
1791
1792		$userstatic->id = $obj->fk_user_author;
1793		$userstatic->login = $obj->login;
1794		$userstatic->lastname = $obj->lastname;
1795		$userstatic->firstname = $obj->firstname;
1796		$userstatic->email = $obj->user_email;
1797		$userstatic->statut = $obj->user_statut;
1798		$userstatic->entity = $obj->user_entity;
1799		$userstatic->photo = $obj->photo;
1800		$userstatic->office_phone = $obj->office_phone;
1801		$userstatic->office_fax = $obj->office_fax;
1802		$userstatic->user_mobile = $obj->user_mobile;
1803		$userstatic->job = $obj->job;
1804		$userstatic->gender = $obj->gender;
1805
1806		// Author
1807		if (!empty($arrayfields['u.login']['checked'])) {
1808			print '<td class="tdoverflowmax200">';
1809			if ($userstatic->id) {
1810				print $userstatic->getNomUrl(-1);
1811			}
1812			print "</td>\n";
1813			if (!$i) {
1814				$totalarray['nbfield']++;
1815			}
1816		}
1817
1818		if (!empty($arrayfields['sale_representative']['checked'])) {
1819			// Sales representatives
1820			print '<td class="tdoverflowmax200">';
1821			if ($obj->socid > 0) {
1822				$listsalesrepresentatives = $companystatic->getSalesRepresentatives($user);
1823				if ($listsalesrepresentatives < 0) {
1824					dol_print_error($db);
1825				}
1826				$nbofsalesrepresentative = count($listsalesrepresentatives);
1827				if ($nbofsalesrepresentative > 6) {
1828					// We print only number
1829					print $nbofsalesrepresentative;
1830				} elseif ($nbofsalesrepresentative > 0) {
1831					$userstatic = new User($db);
1832					$j = 0;
1833					foreach ($listsalesrepresentatives as $val) {
1834						$userstatic->id = $val['id'];
1835						$userstatic->lastname = $val['lastname'];
1836						$userstatic->firstname = $val['firstname'];
1837						$userstatic->email = $val['email'];
1838						$userstatic->statut = $val['statut'];
1839						$userstatic->entity = $val['entity'];
1840						$userstatic->photo = $val['photo'];
1841						$userstatic->login = $val['login'];
1842						$userstatic->office_phone = $val['office_phone'];
1843						$userstatic->office_fax = $val['office_fax'];
1844						$userstatic->user_mobile = $val['user_mobile'];
1845						$userstatic->job = $val['job'];
1846						$userstatic->gender = $val['gender'];
1847						//print '<div class="float">':
1848						print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1849						$j++;
1850						if ($j < $nbofsalesrepresentative) {
1851							print ' ';
1852						}
1853						//print '</div>';
1854					}
1855				}
1856				//else print $langs->trans("NoSalesRepresentativeAffected");
1857			} else {
1858				print '&nbsp;';
1859			}
1860			print '</td>';
1861			if (!$i) {
1862				$totalarray['nbfield']++;
1863			}
1864		}
1865
1866		// Extra fields
1867		include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1868		// Fields from hook
1869		$parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1870		$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
1871		print $hookmanager->resPrint;
1872		// Date creation
1873		if (!empty($arrayfields['p.datec']['checked'])) {
1874			print '<td align="center" class="nowrap">';
1875			print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1876			print '</td>';
1877			if (!$i) {
1878				$totalarray['nbfield']++;
1879			}
1880		}
1881		// Date modification
1882		if (!empty($arrayfields['p.tms']['checked'])) {
1883			print '<td align="center" class="nowrap">';
1884			print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1885			print '</td>';
1886			if (!$i) {
1887				$totalarray['nbfield']++;
1888			}
1889		}
1890		// Date cloture
1891		if (!empty($arrayfields['p.date_cloture']['checked'])) {
1892			print '<td align="center" class="nowrap">';
1893			print dol_print_date($db->jdate($obj->date_cloture), 'dayhour', 'tzuser');
1894			print '</td>';
1895			if (!$i) {
1896				$totalarray['nbfield']++;
1897			}
1898		}
1899		// Note public
1900		if (!empty($arrayfields['p.note_public']['checked'])) {
1901			print '<td class="center">';
1902			print dol_escape_htmltag($obj->note_public);
1903			print '</td>';
1904			if (!$i) {
1905				$totalarray['nbfield']++;
1906			}
1907		}
1908		// Note private
1909		if (!empty($arrayfields['p.note_private']['checked'])) {
1910			print '<td class="center">';
1911			print dol_escape_htmltag($obj->note_private);
1912			print '</td>';
1913			if (!$i) {
1914				$totalarray['nbfield']++;
1915			}
1916		}
1917		// Status
1918		if (!empty($arrayfields['p.fk_statut']['checked'])) {
1919			print '<td class="nowrap right">'.$objectstatic->getLibStatut(5).'</td>';
1920			if (!$i) {
1921				$totalarray['nbfield']++;
1922			}
1923		}
1924		// Action column
1925		print '<td class="nowrap" align="center">';
1926		if ($massactionbutton || $massaction) {   // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1927			$selected = 0;
1928			if (in_array($obj->rowid, $arrayofselected)) {
1929				$selected = 1;
1930			}
1931			print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1932		}
1933		print '</td>';
1934		if (!$i) {
1935			$totalarray['nbfield']++;
1936		}
1937
1938		print "</tr>\n";
1939
1940		$i++;
1941	}
1942
1943	// Show total line
1944	include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
1945
1946	$db->free($resql);
1947
1948	$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1949	$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
1950	print $hookmanager->resPrint;
1951
1952	print '</table>'."\n";
1953	print '</div>'."\n";
1954
1955	print '</form>'."\n";
1956
1957	$hidegeneratedfilelistifempty = 1;
1958	if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1959		$hidegeneratedfilelistifempty = 0;
1960	}
1961
1962	// Show list of available documents
1963	$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1964	$urlsource .= str_replace('&amp;', '&', $param);
1965
1966	$filedir = $diroutputmassaction;
1967	$genallowed = $user->rights->propal->lire;
1968	$delallowed = $user->rights->propal->creer;
1969
1970	print $formfile->showdocuments('massfilesarea_proposals', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1971} else {
1972	dol_print_error($db);
1973}
1974
1975// End of page
1976llxFooter();
1977$db->close();
1978