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