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