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