dolibarr 21.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-2020 Laurent Destailleur <eldy@users.sourceforge.net>
4 * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
5 * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6 * Copyright (C) 2014-2019 Juanjo Menent <jmenent@2byte.es>
7 * Copyright (C) 2015 Claudio Aschieri <c.aschieri@19.coop>
8 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
9 * Copyright (C) 2016-2018 Ferran Marcet <fmarcet@2byte.es>
10 * Copyright (C) 2019 Nicolas Zabouri <info@inovea-conseil.com>
11 * Copyright (C) 2021-2024 Alexandre Spangaro <alexandre@inovea-conseil.com>
12 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
13 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
14 * Copyright (C) 2024 Benjamin Falière <benjamin.faliere@altairis.fr>
15 *
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License as published by
18 * the Free Software Foundation; either version 3 of the License, or
19 * (at your option) any later version.
20 *
21 * This program is distributed in the hope that it will be useful,
22 * but WITHOUT ANY WARRANTY; without even the implied warranty of
23 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
24 * GNU General Public License for more details.
25 *
26 * You should have received a copy of the GNU General Public License
27 * along with this program. If not, see <https://www.gnu.org/licenses/>.
28 */
29
36// Load Dolibarr environment
37require '../main.inc.php';
38require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
39require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
40require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
41require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
42require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
43require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
44if (isModEnabled("category")) {
45 require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
46}
47
48// Load translation files required by the page
49$langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
50
51$action = GETPOST('action', 'aZ09');
52$massaction = GETPOST('massaction', 'alpha');
53$show_files = GETPOSTINT('show_files');
54$confirm = GETPOST('confirm', 'alpha');
55$toselect = GETPOST('toselect', 'array');
56$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
57$optioncss = GETPOST('optioncss', 'alpha');
58$mode = GETPOST('mode', 'alpha');
59
60$socid = GETPOSTINT('socid');
61
62$search_name = GETPOST('search_name', 'alpha');
63$search_email = GETPOST('search_email', 'alpha');
64$search_town = GETPOST('search_town', 'alpha');
65$search_zip = GETPOST('search_zip', 'alpha');
66$search_state = GETPOST("search_state", 'alpha');
67$search_country = GETPOST("search_country", 'aZ09');
68$search_type_thirdparty = GETPOST("search_type_thirdparty", 'intcomma');
69$search_contract = GETPOST('search_contract', 'alpha');
70$search_ref_customer = GETPOST('search_ref_customer', 'alpha');
71$search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
72$search_all = (GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
73$search_status = GETPOST('search_status', 'alpha');
74$search_signed_status = GETPOST('search_signed_status', 'alpha');
75$search_user = GETPOST('search_user', 'intcomma');
76$search_sale = GETPOST('search_sale', 'intcomma');
77$search_product_category = GETPOST('search_product_category', 'intcomma');
78$search_dfmonth = GETPOSTINT('search_dfmonth');
79$search_dfyear = GETPOSTINT('search_dfyear');
80$search_op2df = GETPOST('search_op2df', 'alpha');
81$search_date_startday = GETPOSTINT('search_date_startday');
82$search_date_startmonth = GETPOSTINT('search_date_startmonth');
83$search_date_startyear = GETPOSTINT('search_date_startyear');
84$search_date_endday = GETPOSTINT('search_date_endday');
85$search_date_endmonth = GETPOSTINT('search_date_endmonth');
86$search_date_endyear = GETPOSTINT('search_date_endyear');
87$search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
88$search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
89$searchCategoryCustomerOperator = 0;
90if (GETPOSTISSET('formfilteraction')) {
91 $searchCategoryCustomerOperator = GETPOSTINT('search_category_customer_operator');
92} elseif (getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT')) {
93 $searchCategoryCustomerOperator = getDolGlobalString('MAIN_SEARCH_CAT_OR_BY_DEFAULT');
94}
95$searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
96
97$search_date_creation_startmonth = GETPOSTINT('search_date_creation_startmonth');
98$search_date_creation_startyear = GETPOSTINT('search_date_creation_startyear');
99$search_date_creation_startday = GETPOSTINT('search_date_creation_startday');
100$search_date_creation_start = dol_mktime(0, 0, 0, $search_date_creation_startmonth, $search_date_creation_startday, $search_date_creation_startyear); // Use tzserver
101$search_date_creation_endmonth = GETPOSTINT('search_date_creation_endmonth');
102$search_date_creation_endyear = GETPOSTINT('search_date_creation_endyear');
103$search_date_creation_endday = GETPOSTINT('search_date_creation_endday');
104$search_date_creation_end = dol_mktime(23, 59, 59, $search_date_creation_endmonth, $search_date_creation_endday, $search_date_creation_endyear); // Use tzserver
105
106$search_date_modif_startmonth = GETPOSTINT('search_date_modif_startmonth');
107$search_date_modif_startyear = GETPOSTINT('search_date_modif_startyear');
108$search_date_modif_startday = GETPOSTINT('search_date_modif_startday');
109$search_date_modif_start = dol_mktime(0, 0, 0, $search_date_modif_startmonth, $search_date_modif_startday, $search_date_modif_startyear); // Use tzserver
110$search_date_modif_endmonth = GETPOSTINT('search_date_modif_endmonth');
111$search_date_modif_endyear = GETPOSTINT('search_date_modif_endyear');
112$search_date_modif_endday = GETPOSTINT('search_date_modif_endday');
113$search_date_modif_end = dol_mktime(23, 59, 59, $search_date_modif_endmonth, $search_date_modif_endday, $search_date_modif_endyear); // Use tzserver
114
115// Load variable for pagination
116$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
117$sortfield = GETPOST('sortfield', 'aZ09comma');
118$sortorder = GETPOST('sortorder', 'aZ09comma');
119$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
120if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
121 // If $page is not defined, or '' or -1 or if we click on clear filters
122 $page = 0;
123}
124$offset = $limit * $page;
125$pageprev = $page - 1;
126$pagenext = $page + 1;
127if (!$sortfield) {
128 $sortfield = 'c.ref';
129}
130if (!$sortorder) {
131 $sortorder = 'DESC';
132}
133
134// Security check
135$id = GETPOSTINT('id');
136if ($user->socid > 0) {
137 $socid = $user->socid;
138}
139
140$hookmanager->initHooks(array('contractlist'));
141
142$result = restrictedArea($user, 'contrat', $id);
143
144$diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id;
145
146$staticcontrat = new Contrat($db);
147$staticcontratligne = new ContratLigne($db);
148
149if ($search_status == '') {
150 $search_status = 1;
151}
152
153// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
154$object = new Contrat($db);
155$extrafields = new ExtraFields($db);
156
157// fetch optionals attributes and labels
158$extrafields->fetch_name_optionals_label($object->table_element);
159
160$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
161// List of fields to search into when doing a "search in all"
162$fieldstosearchall = array();
163foreach ($object->fields as $key => $val) {
164 if (!empty($val['searchall'])) {
165 $fieldstosearchall['c.'.$key] = $val['label'];
166 }
167}
168$fieldstosearchall["s.nom"] = "ThirdParty";
169if (empty($user->socid)) {
170 $fieldstosearchall["c.note_private"] = "NotePrivate";
171}
172$parameters = array('fieldstosearchall' => $fieldstosearchall);
173$reshook = $hookmanager->executeHooks('completeFieldsToSearchAll', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
174if ($reshook > 0) {
175 $fieldstosearchall = $hookmanager->resArray['fieldstosearchall'];
176} elseif ($reshook == 0) {
177 if (!empty($hookmanager->resArray['fieldstosearchall'])) {
178 $fieldstosearchall = array_merge($fieldstosearchall, $hookmanager->resArray['fieldstosearchall']);
179 }
180}
181
182$arrayfields = array(
183 'c.ref' => array('label' => $langs->trans("Ref"), 'checked' => 1, 'position' => 10),
184 'c.ref_customer' => array('label' => $langs->trans("RefCustomer"), 'checked' => 1, 'position' => 12),
185 'c.ref_supplier' => array('label' => $langs->trans("RefSupplier"), 'checked' => 1, 'position' => 14),
186 's.nom' => array('label' => $langs->trans("ThirdParty"), 'checked' => 1, 'position' => 30),
187 's.email' => array('label' => $langs->trans("ThirdPartyEmail"), 'checked' => 0, 'position' => 30),
188 's.town' => array('label' => $langs->trans("Town"), 'checked' => 0, 'position' => 31),
189 's.zip' => array('label' => $langs->trans("Zip"), 'checked' => 1, 'position' => 32),
190 'state.nom' => array('label' => $langs->trans("StateShort"), 'checked' => 0, 'position' => 33),
191 'country.code_iso' => array('label' => $langs->trans("Country"), 'checked' => 0, 'position' => 34),
192 'sale_representative' => array('label' => $langs->trans("SaleRepresentativesOfThirdParty"), 'checked' => -1, 'position' => 80),
193 'c.date_contrat' => array('label' => $langs->trans("DateContract"), 'checked' => 1, 'position' => 45),
194 'c.datec' => array('label' => $langs->trans("DateCreation"), 'checked' => 0, 'position' => 500),
195 'c.tms' => array('label' => $langs->trans("DateModificationShort"), 'checked' => 0, 'position' => 500),
196 'lower_planned_end_date' => array('label' => $langs->trans("LowerDateEndPlannedShort"), 'checked' => 1, 'position' => 900, 'help' => $langs->trans("LowerDateEndPlannedShort")),
197 'status' => array('label' => $langs->trans("Status"), 'checked' => 1, 'position' => 1000),
198 'c.signed_status' => array('label' => $langs->trans('SignedStatus'), 'checked' => 0, 'position' => 1001),
199);
200// Extra fields
201include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
202
203$object->fields = dol_sort_array($object->fields, 'position');
204$arrayfields = dol_sort_array($arrayfields, 'position');
205'@phan-var-force array<string,array{label:string,checked?:int<0,1>,position?:int,help?:string}> $arrayfields'; // dol_sort_array looses type for Phan
206
207if (!$user->hasRight('societe', 'client', 'voir')) {
208 $search_sale = $user->id;
209}
210
211$permissiontoread = $user->hasRight('contrat', 'lire');
212$permissiontoadd = $user->hasRight('contrat', 'creer');
213$permissiontodelete = $user->hasRight('contrat', 'supprimer');
214
215$result = restrictedArea($user, 'contrat', 0);
216
217
218
219/*
220 * Actions
221 */
222
223if (GETPOST('cancel', 'alpha')) {
224 $action = 'list';
225 $massaction = '';
226}
227if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
228 $massaction = '';
229}
230
231$parameters = array('socid' => $socid, 'arrayfields' => &$arrayfields);
232$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
233if ($reshook < 0) {
234 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
235}
236
237include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
238// Purge search criteria
239if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
240 $search_dfmonth = '';
241 $search_dfyear = '';
242 $search_op2df = '';
243 $search_name = "";
244 $search_email = "";
245 $search_town = '';
246 $search_zip = "";
247 $search_state = "";
248 $search_type = '';
249 $search_country = '';
250 $search_contract = "";
251 $search_ref_customer = "";
252 $search_ref_supplier = "";
253 $search_user = '';
254 $search_sale = '';
255 $search_product_category = '';
256 $search_date_startday = '';
257 $search_date_startmonth = '';
258 $search_date_startyear = '';
259 $search_date_endday = '';
260 $search_date_endmonth = '';
261 $search_date_endyear = '';
262 $search_date_start = '';
263 $search_date_end = '';
264 $search_all = "";
265 $search_date_creation_startmonth = "";
266 $search_date_creation_startyear = "";
267 $search_date_creation_startday = "";
268 $search_date_creation_start = "";
269 $search_date_creation_endmonth = "";
270 $search_date_creation_endyear = "";
271 $search_date_creation_endday = "";
272 $search_date_creation_end = "";
273 $search_date_modif_startmonth = "";
274 $search_date_modif_startyear = "";
275 $search_date_modif_startday = "";
276 $search_date_modif_start = "";
277 $search_date_modif_endmonth = "";
278 $search_date_modif_endyear = "";
279 $search_date_modif_endday = "";
280 $search_date_modif_end = "";
281 $search_status = "";
282 $search_signed_status = '';
283 $toselect = array();
284 $search_type_thirdparty = '';
285 $searchCategoryCustomerList = array();
286 $search_array_options = array();
287}
288
289if (empty($reshook)) {
290 $objectclass = 'Contrat';
291 $objectlabel = 'Contracts';
292 $uploaddir = $conf->contrat->dir_output;
293 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
294}
295
296
297/*
298 * View
299 */
300
301$form = new Form($db);
302$formfile = new FormFile($db);
303$formother = new FormOther($db);
304$socstatic = new Societe($db);
305$formcompany = new FormCompany($db);
306$contracttmp = new Contrat($db);
307
308$now = dol_now();
309
310$title = "";
311
312$sql = 'SELECT';
313$sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_modification, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity, c.signed_status,";
314$sql .= ' s.rowid as socid, s.nom as name, s.name_alias, s.email, s.town, s.zip, s.fk_pays as country_id, s.client, s.code_client, s.status as company_status, s.logo as company_logo,';
315$sql .= " typent.code as typent_code,";
316$sql .= " state.code_departement as state_code, state.nom as state_name,";
317// TODO Add a denormalized field "denormalized_lower_planned_end_date" so we can remove the HAVING and then,
318// remove completely the SUM and GROUP BY (faster). Status of each service can be read into the loop that build the list.
319$sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,"; // lowest expiration date among open service lines
320$sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
321$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NULL OR cd.date_fin_validite >= '".$db->idate($now)."')", 1, 0).') as nb_running,';
322$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now)."')", 1, 0).') as nb_expired,';
323$sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
324$sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';
325// Add fields from extrafields
326if (!empty($extrafields->attributes[$object->table_element]['label'])) {
327 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
328 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
329 }
330}
331// Add fields from hooks
332$parameters = array();
333$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
334$sql .= $hookmanager->resPrint;
335$sql = preg_replace('/,\s*$/', '', $sql);
336
337$sqlfields = $sql; // $sql fields to remove for count total
338
339$sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
340$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
341$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
342$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
343$sql .= ", ".MAIN_DB_PREFIX."contrat as c";
344if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
345 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";
346}
347$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
348if ($search_user > 0) {
349 $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
350 $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
351}
352$sql .= " WHERE c.fk_soc = s.rowid ";
353$sql .= ' AND c.entity IN ('.getEntity('contract').')';
354if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
355 $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
356}
357if ($socid > 0) {
358 $sql .= " AND s.rowid = ".((int) $socid);
359}
360if ($search_date_start) {
361 $sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";
362}
363if ($search_date_end) {
364 $sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";
365}
366if ($search_name) {
367 $sql .= natural_search('s.nom', $search_name);
368}
369if ($search_email) {
370 $sql .= natural_search('s.email', $search_email);
371}
372if ($search_contract) {
373 $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
374}
375if (!empty($search_ref_customer)) {
376 $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
377}
378if (!empty($search_ref_supplier)) {
379 $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
380}
381if ($search_zip) {
382 $sql .= natural_search(array('s.zip'), $search_zip);
383}
384if ($search_town) {
385 $sql .= natural_search(array('s.town'), $search_town);
386}
387if ($search_country && $search_country != '-1') {
388 $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
389}
390/*if ($search_sale > 0) {
391 $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
392}*/
393if ($search_all) {
394 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
395}
396if ($search_user > 0) {
397 $sql .= " AND ec.fk_c_type_contact = tc.rowid AND tc.element='contrat' AND tc.source='internal' AND ec.element_id = c.rowid AND ec.fk_socpeople = ".((int) $search_user);
398}
399// Search on sale representative
400if ($search_sale && $search_sale != '-1') {
401 if ($search_sale == -2) {
402 $sql .= " AND NOT EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc)";
403 } elseif ($search_sale > 0) {
404 $sql .= " AND EXISTS (SELECT sc.fk_soc FROM ".MAIN_DB_PREFIX."societe_commerciaux as sc WHERE sc.fk_soc = c.fk_soc AND sc.fk_user = ".((int) $search_sale).")";
405 }
406}
407// Search for tag/category ($searchCategoryProductList is an array of ID)
408$searchCategoryProductOperator = -1;
409$searchCategoryProductList = array($search_product_category);
410if (!empty($searchCategoryProductList)) {
411 $searchCategoryProductSqlList = array();
412 $listofcategoryid = '';
413 foreach ($searchCategoryProductList as $searchCategoryProduct) {
414 if (intval($searchCategoryProduct) == -2) {
415 $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product)";
416 } elseif (intval($searchCategoryProduct) > 0) {
417 if ($searchCategoryProductOperator == 0) {
418 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie = ".((int) $searchCategoryProduct).")";
419 } else {
420 $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
421 }
422 }
423 }
424 if ($listofcategoryid) {
425 $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck, ".MAIN_DB_PREFIX."contratdet as cd WHERE cd.fk_contrat = c.rowid AND cd.fk_product = ck.fk_product AND ck.fk_categorie IN (".$db->sanitize($listofcategoryid)."))";
426 }
427 if ($searchCategoryProductOperator == 1) {
428 if (!empty($searchCategoryProductSqlList)) {
429 $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
430 }
431 } else {
432 if (!empty($searchCategoryProductSqlList)) {
433 $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
434 }
435 }
436}
437$searchCategoryCustomerSqlList = array();
438if ($searchCategoryCustomerOperator == 1) {
439 $existsCategoryCustomerList = array();
440 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
441 if (intval($searchCategoryCustomer) == -2) {
442 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
443 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
444 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
445 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
446 $sqlCategoryCustomerNotExists .= " )";
447 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
448 } elseif (intval($searchCategoryCustomer) > 0) {
449 $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
450 }
451 }
452 if (!empty($existsCategoryCustomerList)) {
453 $sqlCategoryCustomerExists = " EXISTS (";
454 $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
455 $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
456 $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid";
457 $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
458 $sqlCategoryCustomerExists .= " )";
459 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
460 }
461 if (!empty($searchCategoryCustomerSqlList)) {
462 $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
463 }
464} else {
465 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
466 if (intval($searchCategoryCustomer) == -2) {
467 $sqlCategoryCustomerNotExists = " NOT EXISTS (";
468 $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
469 $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
470 $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
471 $sqlCategoryCustomerNotExists .= " )";
472 $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
473 } elseif (intval($searchCategoryCustomer) > 0) {
474 $searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
475 }
476 }
477 if (!empty($searchCategoryCustomerSqlList)) {
478 $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
479 }
480}
481
482if ($search_date_creation_start) {
483 $sql .= " AND c.datec >= '".$db->idate($search_date_creation_start)."'";
484}
485if ($search_date_creation_end) {
486 $sql .= " AND c.datec <= '".$db->idate($search_date_creation_end)."'";
487}
488
489if ($search_date_modif_start) {
490 $sql .= " AND c.tms >= '".$db->idate($search_date_modif_start)."'";
491}
492if ($search_date_modif_end) {
493 $sql .= " AND c.tms <= '".$db->idate($search_date_modif_end)."'";
494}
495if ($search_signed_status != '' && $search_signed_status >= 0) {
496 $sql .= ' AND c.signed_status = '.urlencode($search_signed_status);
497}
498
499// Add where from extra fields
500include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
501// Add where from hooks
502$parameters = array();
503$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
504$sql .= $hookmanager->resPrint;
505$sql .= " GROUP BY c.rowid, c.ref, c.datec, c.tms, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity, c.signed_status,";
506$sql .= ' s.rowid, s.nom, s.name_alias, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client, s.status, s.logo,';
507$sql .= " typent.code,";
508$sql .= " state.code_departement, state.nom";
509// Add fields from extrafields
510if (!empty($extrafields->attributes[$object->table_element]['label'])) {
511 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
512 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
513 }
514}
515// Add where from hooks
516$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df' => $search_op2df);
517$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
518$sql .= $hookmanager->resPrint;
519// Add HAVING from hooks
520$parameters = array('search_dfyear' => $search_dfyear, 'search_op2df' => $search_op2df);
521$reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
522if (empty($reshook)) {
523 if ($search_dfyear > 0 && $search_op2df) {
524 if ($search_op2df == '<=') {
525 $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
526 } elseif ($search_op2df == '>=') {
527 $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
528 } else {
529 $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."' AND MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
530 }
531 }
532}
533$sql .= $hookmanager->resPrint;
534
535// Count total nb of records
536$nbtotalofrecords = '';
537if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
538 //$result = $db->query($sql);
539 //$nbtotalofrecords = $db->num_rows($result);
540
541 if ($search_dfyear > 0 && $search_op2df) {
542 $resql = $db->query($sql, 0, 'auto', 1);
543 while ($db->fetch_object($resql)) {
544 if (empty($nbtotalofrecords)) {
545 $nbtotalofrecords = 1; // We can't make +1 because init value is ''
546 } else {
547 $nbtotalofrecords++;
548 }
549 }
550 } else {
551 /* The fast and low memory method to get and count full list converts the sql into a sql count */
552 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
553
554 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_country as country on (country.rowid = s.fk_pays)', '', $sqlforcount);
555 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_typent as typent on (typent.id = s.fk_typent)', '', $sqlforcount);
556 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'c_departements as state on (state.rowid = s.fk_departement)', '', $sqlforcount);
557 $sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat', '', $sqlforcount);
558 //$sqlforcount = str_replace('LEFT JOIN '.MAIN_DB_PREFIX.'contrat_extrafields as ef on (c.rowid = ef.fk_object)', '', $sqlforcount); // We my need this if there is filters on extrafields
559 $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
560
561 $resql = $db->query($sqlforcount);
562 if ($resql) {
563 $objforcount = $db->fetch_object($resql);
564 $nbtotalofrecords = $objforcount->nbtotalofrecords;
565 } else {
566 dol_print_error($db);
567 }
568 }
569
570 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
571 $page = 0;
572 $offset = 0;
573 }
574 $db->free($resql);
575}
576
577// Complete request and execute it with limit
578$sql .= $db->order($sortfield, $sortorder);
579if ($limit) {
580 $sql .= $db->plimit($limit + 1, $offset);
581}
582
583$resql = $db->query($sql);
584if (!$resql) {
585 dol_print_error($db);
586 exit;
587}
588
589$num = $db->num_rows($resql);
590
591// Direct jump if only one record found
592if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
593 $obj = $db->fetch_object($resql);
594 $id = $obj->rowid;
595 header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
596 exit;
597}
598
599
600// Output page
601// --------------------------------------------------------------------
602$title = $langs->trans("Contracts");
603$help_url = 'EN:Module_Contracts|FR:Module_Contrat|ES:Contratos_de_servicio';
604
605llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-contrat page-list bodyforlist');
606
607$i = 0;
608
609$arrayofselected = is_array($toselect) ? $toselect : array();
610
611if ($socid > 0) {
612 $soc = new Societe($db);
613 $soc->fetch($socid);
614 if (empty($search_name)) {
615 $search_name = $soc->name;
616 }
617}
618
619$param = '';
620if (!empty($mode)) {
621 $param .= '&mode='.urlencode($mode);
622}
623if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
624 $param .= '&contextpage='.urlencode($contextpage);
625}
626if ($limit > 0 && $limit != $conf->liste_limit) {
627 $param .= '&limit='.((int) $limit);
628}
629if ($search_all != '') {
630 $param .= '&search_all='.urlencode($search_all);
631}
632if ($search_contract != '') {
633 $param .= '&search_contract='.urlencode($search_contract);
634}
635if ($search_name != '') {
636 $param .= '&search_name='.urlencode($search_name);
637}
638if ($search_email != '') {
639 $param .= '&search_email='.urlencode($search_email);
640}
641if ($search_ref_customer != '') {
642 $param .= '&search_ref_customer='.urlencode($search_ref_customer);
643}
644if ($search_ref_supplier != '') {
645 $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
646}
647if ($search_op2df != '') {
648 $param .= '&search_op2df='.urlencode($search_op2df);
649}
650if ($search_date_creation_startmonth) {
651 $param .= '&search_date_creation_startmonth='.urlencode((string) ($search_date_creation_startmonth));
652}
653if ($search_date_creation_startyear) {
654 $param .= '&search_date_creation_startyear='.urlencode((string) ($search_date_creation_startyear));
655}
656if ($search_date_creation_startday) {
657 $param .= '&search_date_creation_startday='.urlencode((string) ($search_date_creation_startday));
658}
659if ($search_date_creation_start) {
660 $param .= '&search_date_creation_start='.urlencode($search_date_creation_start);
661}
662if ($search_date_creation_endmonth) {
663 $param .= '&search_date_creation_endmonth='.urlencode((string) ($search_date_creation_endmonth));
664}
665if ($search_date_creation_endyear) {
666 $param .= '&search_date_creation_endyear='.urlencode((string) ($search_date_creation_endyear));
667}
668if ($search_date_creation_endday) {
669 $param .= '&search_date_creation_endday='.urlencode((string) ($search_date_creation_endday));
670}
671if ($search_date_creation_end) {
672 $param .= '&search_date_creation_end='.urlencode($search_date_creation_end);
673}
674if ($search_date_modif_startmonth) {
675 $param .= '&search_date_modif_startmonth='.urlencode((string) ($search_date_modif_startmonth));
676}
677if ($search_date_modif_startyear) {
678 $param .= '&search_date_modif_startyear='.urlencode((string) ($search_date_modif_startyear));
679}
680if ($search_date_modif_startday) {
681 $param .= '&search_date_modif_startday='.urlencode((string) ($search_date_modif_startday));
682}
683if ($search_date_modif_start) {
684 $param .= '&search_date_modif_start='.urlencode($search_date_modif_start);
685}
686if ($search_date_modif_endmonth) {
687 $param .= '&search_date_modif_endmonth='.urlencode((string) ($search_date_modif_endmonth));
688}
689if ($search_date_modif_endyear) {
690 $param .= '&search_date_modif_endyear='.urlencode((string) ($search_date_modif_endyear));
691}
692if ($search_date_modif_endday) {
693 $param .= '&search_date_modif_endday='.urlencode((string) ($search_date_modif_endday));
694}
695if ($search_date_modif_end) {
696 $param .= '&search_date_modif_end=' . urlencode($search_date_modif_end);
697}
698if ($search_date_startday > 0) {
699 $param .= '&search_date_startday='.urlencode((string) ($search_date_startday));
700}
701if ($search_date_startmonth > 0) {
702 $param .= '&search_date_startmonth='.urlencode((string) ($search_date_startmonth));
703}
704if ($search_date_startyear > 0) {
705 $param .= '&search_date_startyear='.urlencode((string) ($search_date_startyear));
706}
707if ($search_date_endday > 0) {
708 $param .= '&search_date_endday='.urlencode((string) ($search_date_endday));
709}
710if ($search_date_endmonth > 0) {
711 $param .= '&search_date_endmonth='.urlencode((string) ($search_date_endmonth));
712}
713if ($search_date_endyear > 0) {
714 $param .= '&search_date_endyear='.urlencode((string) ($search_date_endyear));
715}
716if ($search_dfyear > 0) {
717 $param .= '&search_dfyear='.urlencode((string) ($search_dfyear));
718}
719if ($search_dfmonth > 0) {
720 $param .= '&search_dfmonth='.urlencode((string) ($search_dfmonth));
721}
722if ($search_signed_status != '' && $search_signed_status >= 0) {
723 $param .= '&search_signed_status='.urlencode($search_signed_status);
724}
725if ($search_sale > 0) {
726 $param .= '&search_sale='.urlencode($search_sale);
727}
728if ($search_user > 0) {
729 $param .= '&search_user='.urlencode((string) ($search_user));
730}
731if ($search_type_thirdparty > 0) {
732 $param .= '&search_type_thirdparty='.urlencode((string) ($search_type_thirdparty));
733}
734if ($search_country != '') {
735 $param .= "&search_country=".urlencode($search_country);
736}
737if ($search_product_category > 0) {
738 $param .= '&search_product_category='.urlencode((string) ($search_product_category));
739}
740if ($show_files) {
741 $param .= '&show_files='.urlencode((string) ($show_files));
742}
743if ($optioncss != '') {
744 $param .= '&optioncss='.urlencode($optioncss);
745}
746foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
747 $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
748}
749// Add $param from extra fields
750include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
751
752// List of mass actions available
753$arrayofmassactions = array(
754 'generate_doc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
755 'builddoc' => img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
756 'presend' => img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
757);
758if (!empty($permissiontodelete)) {
759 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
760}
761if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
762 $arrayofmassactions = array();
763}
764$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
765
766$url = DOL_URL_ROOT.'/contrat/card.php?action=create';
767if (!empty($socid)) {
768 $url .= '&socid='.((int) $socid);
769}
770$newcardbutton = '';
771$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'));
772$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'));
773$newcardbutton .= dolGetButtonTitleSeparator();
774$newcardbutton .= dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->hasRight('contrat', 'creer'));
775
776print '<form method="POST" id="searchFormList" action="'.$_SERVER['PHP_SELF'].'">'."\n";
777if ($optioncss != '') {
778 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
779}
780print '<input type="hidden" name="token" value="'.newToken().'">';
781print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
782print '<input type="hidden" name="action" value="list">';
783print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
784print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
785print '<input type="hidden" name="page" value="'.$page.'">';
786print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
787print '<input type="hidden" name="page_y" value="">';
788print '<input type="hidden" name="mode" value="'.$mode.'">';
789
790// @phan-suppress-next-line PhanPluginSuspiciousParamOrder
791print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
792
793$topicmail = "SendContractRef";
794$modelmail = "contract";
795$objecttmp = new Contrat($db);
796$trackid = 'con'.$object->id;
797include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
798
799if ($search_all) {
800 $setupstring = '';
801 foreach ($fieldstosearchall as $key => $val) {
802 $fieldstosearchall[$key] = $langs->trans($val);
803 $setupstring .= $key."=".$val.";";
804 }
805 print '<!-- Search done like if CONTRACT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
806 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
807}
808
809$moreforfilter = '';
810
811// If the user can view prospects other than his'
812if ($user->hasRight('user', 'user', 'lire')) {
813 $langs->load("commercial");
814 $moreforfilter .= '<div class="divsearchfield">';
815 $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
816 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
817 $moreforfilter .= '</div>';
818}
819// If the user can view other users
820if ($user->hasRight('user', 'user', 'lire')) {
821 $moreforfilter .= '<div class="divsearchfield">';
822 $tmptitle = $langs->trans('LinkedToSpecificUsers');
823 $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
824 $moreforfilter .= '</div>';
825}
826// If the user can view categories of products
827if (isModEnabled('category') && $user->hasRight('categorie', 'lire') && ($user->hasRight('produit', 'lire') || $user->hasRight('service', 'lire'))) {
828 include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
829 $moreforfilter .= '<div class="divsearchfield">';
830 $tmptitle = $langs->trans('IncludingProductWithTag');
831 $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', 'parent', 64, 0, 2);
832 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);
833 $moreforfilter .= '</div>';
834}
835// Filter on customer categories
836if (getDolGlobalString('MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST') && isModEnabled("category") && $user->hasRight('categorie', 'lire')) {
837 $moreforfilter .= '<div class="divsearchfield">';
838 $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
839 $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
840 $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 2);
841 $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
842 $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
843 $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
844 $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
845 $moreforfilter .= '</div>';
846}
847
848$parameters = array();
849$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
850if (empty($reshook)) {
851 $moreforfilter .= $hookmanager->resPrint;
852} else {
853 $moreforfilter = $hookmanager->resPrint;
854}
855
856if (!empty($moreforfilter)) {
857 print '<div class="liste_titre liste_titre_bydiv centpercent">';
858 print $moreforfilter;
859 print '</div>';
860}
861
862$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
863$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
864if ($massactionbutton) {
865 $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
866}
867
868print '<div class="div-table-responsive">';
869print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
870
871// Fields title search
872// --------------------------------------------------------------------
873print '<tr class="liste_titre_filter">';
874// Action column
875if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
876 print '<td class="liste_titre maxwidthsearch center">';
877 $searchpicto = $form->showFilterButtons('left');
878 print $searchpicto;
879 print '</td>';
880}
881if (!empty($arrayfields['c.ref']['checked'])) {
882 print '<td class="liste_titre">';
883 print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
884 print '</td>';
885}
886if (!empty($arrayfields['c.ref_customer']['checked'])) {
887 print '<td class="liste_titre">';
888 print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
889 print '</td>';
890}
891if (!empty($arrayfields['c.ref_supplier']['checked'])) {
892 print '<td class="liste_titre">';
893 print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
894 print '</td>';
895}
896if (!empty($arrayfields['s.nom']['checked'])) {
897 print '<td class="liste_titre">';
898 print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
899 print '</td>';
900}
901if (!empty($arrayfields['s.email']['checked'])) {
902 print '<td class="liste_titre">';
903 print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
904 print '</td>';
905}
906// Town
907if (!empty($arrayfields['s.town']['checked'])) {
908 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
909}
910// Zip
911if (!empty($arrayfields['s.zip']['checked'])) {
912 print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
913}
914// State
915if (!empty($arrayfields['state.nom']['checked'])) {
916 print '<td class="liste_titre">';
917 print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
918 print '</td>';
919}
920// Country
921if (!empty($arrayfields['country.code_iso']['checked'])) {
922 print '<td class="liste_titre center">';
923 print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
924 print '</td>';
925}
926// Company type
927if (!empty($arrayfields['typent.code']['checked'])) {
928 print '<td class="liste_titre maxwidthonsmartphone center">';
929 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), '', 1);
930 print '</td>';
931}
932if (!empty($arrayfields['sale_representative']['checked'])) {
933 print '<td class="liste_titre"></td>';
934}
935if (!empty($arrayfields['c.date_contrat']['checked'])) {
936 print '<td class="liste_titre center">';
937 print '<div class="nowrapfordate">';
938 print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
939 print '</div>';
940 print '<div class="nowrapfordate">';
941 print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
942 print '</div>';
943 print '</td>';
944}
945// Signed status
946if (!empty($arrayfields['c.signed_status']['checked'])) {
947 print '<td class="liste_titre center">';
948 $list_signed_status = $object->getSignedStatusLocalisedArray();
949 print $form->selectarray('search_signed_status', $list_signed_status, $search_signed_status, 1, 0, 0, '', 1, 0, 0, '', 'search_status');
950 print '</td>';
951}
952// Extra fields
953include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
954
955// Fields from hook
956$parameters = array('arrayfields' => $arrayfields);
957$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
958print $hookmanager->resPrint;
959// Creation date
960if (!empty($arrayfields['c.datec']['checked'])) {
961 print '<td class="liste_titre center nowraponall">';
962 print '<div class="nowrapfordate">';
963 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'));
964 print '</div>';
965 print '<div class="nowrapfordate">';
966 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'));
967 print '</div>';
968 print '</td>';
969}
970// Modification date
971if (!empty($arrayfields['c.tms']['checked'])) {
972 print '<td class="liste_titre center nowraponall">';
973 print '<div class="nowrapfordate">';
974 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'));
975 print '</div>';
976 print '<div class="nowrapfordate">';
977 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'));
978 print '</div>';
979 print '</td>';
980}
981// First end date
982if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
983 print '<td class="liste_titre nowraponall center">';
984 $arrayofoperators = array('0' => '', '=' => '=', '<=' => '<=', '>=' => '>=');
985 print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
986 print '</br>';
987 print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
988 print ' ';
989 print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
990 print '</td>';
991}
992// Status
993if (!empty($arrayfields['status']['checked'])) {
994 print '<td class="liste_titre right" colspan="4"></td>';
995}
996
997// Action column
998if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
999 print '<td class="liste_titre center">';
1000 $searchpicto = $form->showFilterButtons();
1001 print $searchpicto;
1002 print '</td>';
1003}
1004print '</tr>'."\n";
1005
1006$totalarray = array();
1007$totalarray['nbfield'] = 0;
1008
1009// Fields title label
1010// --------------------------------------------------------------------
1011print '<tr class="liste_titre">';
1012if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1013 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1014 $totalarray['nbfield']++; // For the column action
1015}
1016if (!empty($arrayfields['c.ref']['checked'])) {
1017 // False positive @phan-suppress-next-line PhanTypeInvalidDimOffset
1018 print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
1019 $totalarray['nbfield']++; // For the column action
1020}
1021if (!empty($arrayfields['c.ref_customer']['checked'])) {
1022 print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
1023 $totalarray['nbfield']++; // For the column action
1024}
1025if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1026 print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
1027 $totalarray['nbfield']++; // For the column action
1028}
1029if (!empty($arrayfields['s.nom']['checked'])) {
1030 print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
1031 $totalarray['nbfield']++; // For the column action
1032}
1033if (!empty($arrayfields['s.email']['checked'])) {
1034 print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
1035 $totalarray['nbfield']++; // For the column action
1036}
1037if (!empty($arrayfields['s.town']['checked'])) {
1038 print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
1039 $totalarray['nbfield']++; // For the column action
1040}
1041if (!empty($arrayfields['s.zip']['checked'])) {
1042 print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
1043 $totalarray['nbfield']++; // For the column action
1044}
1045if (!empty($arrayfields['state.nom']['checked'])) {
1046 print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
1047 $totalarray['nbfield']++; // For the column action
1048}
1049if (!empty($arrayfields['country.code_iso']['checked'])) {
1050 print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
1051 $totalarray['nbfield']++; // For the column action
1052}
1053if (!empty($arrayfields['typent.code']['checked'])) {
1054 print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
1055 $totalarray['nbfield']++; // For the column action
1056}
1057if (!empty($arrayfields['sale_representative']['checked'])) {
1058 print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
1059 $totalarray['nbfield']++; // For the column action
1060}
1061if (!empty($arrayfields['c.date_contrat']['checked'])) {
1062 print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
1063 $totalarray['nbfield']++; // For the column action
1064}
1065if (!empty($arrayfields['c.signed_status']['checked'])) {
1066 print_liste_field_titre($arrayfields['c.signed_status']['label'], $_SERVER["PHP_SELF"], "c.signed_status", "", $param, '', $sortfield, $sortorder, 'center ');
1067 $totalarray['nbfield']++;
1068}
1069// Extra fields
1070include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
1071// Hook fields
1072$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
1073$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1074print $hookmanager->resPrint;
1075if (!empty($arrayfields['c.datec']['checked'])) {
1076 print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1077 $totalarray['nbfield']++; // For the column action
1078}
1079if (!empty($arrayfields['c.tms']['checked'])) {
1080 print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
1081 $totalarray['nbfield']++; // For the column action
1082}
1083if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1084 print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
1085 $totalarray['nbfield']++; // For the column action
1086}
1087if (!empty($arrayfields['status']['checked'])) {
1088 print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1089 $totalarray['nbfield']++; // For the column action
1090 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1091 $totalarray['nbfield']++; // For the column action
1092 print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1093 $totalarray['nbfield']++; // For the column action
1094 print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
1095 $totalarray['nbfield']++; // For the column action
1096}
1097if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1098 print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
1099 $totalarray['nbfield']++; // For the column action
1100}
1101print "</tr>\n";
1102
1103// Loop on record
1104// --------------------------------------------------------------------
1105$i = 0;
1106$savnbfield = $totalarray['nbfield'];
1107$totalarray = array();
1108$totalarray['nbfield'] = 0;
1109$typenArray = array();
1110$cacheCountryIDCode = array();
1111$imaxinloop = ($limit ? min($num, $limit) : $num);
1112while ($i < $imaxinloop) {
1113 $obj = $db->fetch_object($resql);
1114 if (empty($obj)) {
1115 break; // Should not happen
1116 }
1117
1118 $contracttmp->ref = $obj->ref;
1119 $contracttmp->id = $obj->rowid;
1120 $contracttmp->ref_customer = $obj->ref_customer;
1121 $contracttmp->ref_supplier = $obj->ref_supplier;
1122
1123 $contracttmp->nbofserviceswait = $obj->nb_initial;
1124 $contracttmp->nbofservicesopened = $obj->nb_running;
1125 $contracttmp->nbofservicesexpired = $obj->nb_expired;
1126 $contracttmp->nbofservicesclosed = $obj->nb_closed;
1127 $contracttmp->signed_status = $obj->signed_status;
1128
1129 $socstatic->id = $obj->socid;
1130 $socstatic->name = $obj->name;
1131 $socstatic->name_alias = $obj->name_alias;
1132 $socstatic->email = $obj->email;
1133 $socstatic->status = $obj->company_status;
1134 $socstatic->logo = $obj->company_logo;
1135 $socstatic->country_id = $obj->country_id;
1136 $socstatic->country_code = '';
1137 $socstatic->country = '';
1138
1139 if ($obj->country_id > 0) {
1140 if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
1141 $tmparray = getCountry($obj->country_id, 'all');
1142 $cacheCountryIDCode[$obj->country_id] = array('code' => empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
1143 }
1144 $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
1145 $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
1146 }
1147
1148 if ($mode == 'kanban') {
1149 if ($i == 0) {
1150 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
1151 print '<div class="box-flex-container kanban">';
1152 }
1153 // Output Kanban
1154 $arraydata = array();
1155 $arraydata['thirdparty'] = $socstatic;
1156 $arraydata['selected'] = in_array($obj->rowid, $arrayofselected);
1157 $contracttmp->date_contrat = $obj->date_contrat;
1158 print $contracttmp->getKanbanView('', $arraydata);
1159 if ($i == ($imaxinloop - 1)) {
1160 print '</div>';
1161 print '</td></tr>';
1162 }
1163 } else {
1164 // Show here line of result
1165 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
1166 // Action column
1167 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1168 print '<td class="nowrap center">';
1169 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1170 $selected = 0;
1171 if (in_array($obj->rowid, $arrayofselected)) {
1172 $selected = 1;
1173 }
1174 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1175 }
1176 print '</td>';
1177 if (!$i) {
1178 $totalarray['nbfield']++;
1179 }
1180 }
1181 // Ref
1182 if (!empty($arrayfields['c.ref']['checked'])) {
1183 print '<td class="nowraponall">';
1184 print $contracttmp->getNomUrl(1);
1185 if ($obj->nb_late) {
1186 print img_warning($langs->trans("Late"));
1187 }
1188 if (!empty($obj->note_private) || !empty($obj->note_public)) {
1189 print ' <span class="note">';
1190 print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
1191 print '</span>';
1192 }
1193
1194 $filename = dol_sanitizeFileName($obj->ref);
1195 $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
1196 $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
1197 print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
1198 print '</td>';
1199
1200 print '</td>';
1201 if (!$i) {
1202 $totalarray['nbfield']++;
1203 }
1204 }
1205
1206 // Ref thirdparty
1207 if (!empty($arrayfields['c.ref_customer']['checked'])) {
1208 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
1209 if (!$i) {
1210 $totalarray['nbfield']++;
1211 }
1212 }
1213 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
1214 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
1215 }
1216 if (!empty($arrayfields['s.nom']['checked'])) {
1217 print '<td class="tdoverflowmax150">';
1218 if ($obj->socid > 0) {
1219 // TODO Use a cache for this string
1220 print $socstatic->getNomUrl(1, '');
1221 }
1222 print '</td>';
1223 }
1224 // Email
1225 if (!empty($arrayfields['s.email']['checked'])) {
1226 print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 1, 0, 1, 1).'</td>';
1227 }
1228 // Town
1229 if (!empty($arrayfields['s.town']['checked'])) {
1230 print '<td class="nocellnopadd">';
1231 print $obj->town;
1232 print '</td>';
1233 if (!$i) {
1234 $totalarray['nbfield']++;
1235 }
1236 }
1237 // Zip
1238 if (!empty($arrayfields['s.zip']['checked'])) {
1239 print '<td class="center nocellnopadd">';
1240 print $obj->zip;
1241 print '</td>';
1242 if (!$i) {
1243 $totalarray['nbfield']++;
1244 }
1245 }
1246 // State
1247 if (!empty($arrayfields['state.nom']['checked'])) {
1248 print "<td>".$obj->state_name."</td>\n";
1249 if (!$i) {
1250 $totalarray['nbfield']++;
1251 }
1252 }
1253 // Country
1254 if (!empty($arrayfields['country.code_iso']['checked'])) {
1255 print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($socstatic->country).'">';
1256 print dol_escape_htmltag($socstatic->country);
1257 print '</td>';
1258 if (!$i) {
1259 $totalarray['nbfield']++;
1260 }
1261 }
1262 // Type ent
1263 if (!empty($arrayfields['typent.code']['checked'])) {
1264 print '<td class="center">';
1265 if (count($typenArray) == 0) {
1266 $typenArray = $formcompany->typent_array(1);
1267 }
1268 print $typenArray[$obj->typent_code];
1269 print '</td>';
1270 if (!$i) {
1271 $totalarray['nbfield']++;
1272 }
1273 }
1274 if (!empty($arrayfields['sale_representative']['checked'])) {
1275 // Sales representatives
1276 print '<td>';
1277 if ($obj->socid > 0) {
1278 $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1279 if ($listsalesrepresentatives < 0) {
1280 dol_print_error($db);
1281 }
1282 $nbofsalesrepresentative = count($listsalesrepresentatives);
1283 if ($nbofsalesrepresentative > 6) {
1284 // We print only number
1285 print $nbofsalesrepresentative;
1286 } elseif ($nbofsalesrepresentative > 0) {
1287 $userstatic = new User($db);
1288 $j = 0;
1289 foreach ($listsalesrepresentatives as $val) {
1290 $userstatic->id = $val['id'];
1291 $userstatic->lastname = $val['lastname'];
1292 $userstatic->firstname = $val['firstname'];
1293 $userstatic->email = $val['email'];
1294 $userstatic->status = $val['statut'];
1295 $userstatic->entity = $val['entity'];
1296 $userstatic->photo = $val['photo'];
1297 $userstatic->login = $val['login'];
1298 $userstatic->phone = $val['phone'];
1299 $userstatic->job = $val['job'];
1300 $userstatic->gender = $val['gender'];
1301
1302 //print '<div class="float">':
1303 print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1304 $j++;
1305 if ($j < $nbofsalesrepresentative) {
1306 print ' ';
1307 }
1308 //print '</div>';
1309 }
1310 }
1311 //else print $langs->trans("NoSalesRepresentativeAffected");
1312 } else {
1313 print '&nbsp;';
1314 }
1315 print '</td>';
1316 }
1317 // Date
1318 if (!empty($arrayfields['c.date_contrat']['checked'])) {
1319 print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
1320 }
1321 // Signed Status
1322 if (!empty($arrayfields['c.signed_status']['checked'])) {
1323 print '<td class="center">'.$contracttmp->getLibSignedStatus(5).'</td>';
1324 if (!$i) {
1325 $totalarray['nbfield']++;
1326 }
1327 }
1328 // Extra fields
1329 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1330 // Fields from hook
1331 $parameters = array('arrayfields' => $arrayfields, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
1332 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1333 print $hookmanager->resPrint;
1334 // Date creation
1335 if (!empty($arrayfields['c.datec']['checked'])) {
1336 print '<td class="center nowrap">';
1337 print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1338 print '</td>';
1339 if (!$i) {
1340 $totalarray['nbfield']++;
1341 }
1342 }
1343 // Date modification
1344 if (!empty($arrayfields['c.tms']['checked'])) {
1345 print '<td class="center nowrap">';
1346 print dol_print_date($db->jdate($obj->date_modification), 'dayhour', 'tzuser');
1347 print '</td>';
1348 if (!$i) {
1349 $totalarray['nbfield']++;
1350 }
1351 }
1352 // Date lower end date
1353 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1354 print '<td class="center nowrapforall">';
1355 print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
1356 print '</td>';
1357 if (!$i) {
1358 $totalarray['nbfield']++;
1359 }
1360 }
1361 // Status
1362 if (!empty($arrayfields['status']['checked'])) {
1363 print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
1364 print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
1365 print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
1366 print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
1367 if (!$i) {
1368 $totalarray['nbfield']++;
1369 $totalarray['nbfield']++;
1370 $totalarray['nbfield']++;
1371 $totalarray['nbfield']++;
1372 }
1373 }
1374 // Action column
1375 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1376 print '<td class="nowrap center">';
1377 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1378 $selected = 0;
1379 if (in_array($obj->rowid, $arrayofselected)) {
1380 $selected = 1;
1381 }
1382 print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1383 }
1384 print '</td>';
1385 if (!$i) {
1386 $totalarray['nbfield']++;
1387 }
1388 }
1389
1390 print '</tr>'."\n";
1391 }
1392 $i++;
1393}
1394
1395// If no record found
1396if ($num == 0) {
1397 $colspan = 4; // Include the 4 columns of status
1398 foreach ($arrayfields as $key => $val) {
1399 if (!empty($val['checked'])) {
1400 $colspan++;
1401 }
1402 }
1403 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1404}
1405
1406$db->free($resql);
1407
1408$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
1409$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1410print $hookmanager->resPrint;
1411
1412print '</table>'."\n";
1413print '</div>'."\n";
1414
1415print '</form>'."\n";
1416
1417$hidegeneratedfilelistifempty = 1;
1418if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1419 $hidegeneratedfilelistifempty = 0;
1420}
1421
1422// Show list of available documents
1423$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1424$urlsource .= str_replace('&amp;', '&', $param);
1425
1426$filedir = $diroutputmassaction;
1427$genallowed = $permissiontoread;
1428$delallowed = $permissiontoadd;
1429
1430print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1431
1432
1433llxFooter();
1434$db->close();
$id
Definition account.php:39
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:58
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:70
Class to manage lines of contracts.
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Class permettant la generation de composants html autre Only common components are here.
Class to manage third parties objects (customers, suppliers, prospects...)
Class to manage Dolibarr users.
getCountry($searchkey, $withcode='', $dbtouse=null, $outputlangs=null, $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition date.lib.php:595
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition date.lib.php:614
llxFooter()
Footer empty.
Definition document.php:107
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...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
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_print_date($time, $format='', $tzoutput='auto', $outputlangs=null, $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
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.
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0, $morecss='paddingrightonly')
Show EMail link formatted for HTML output.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $mode=0)
Check permissions of a user to show a page and an object.