dolibarr  17.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 Alexandre Spangaro <aspangaro@open-dsi.fr>
12  *
13  * This program is free software; you can redistribute it and/or modify
14  * it under the terms of the GNU General Public License as published by
15  * the Free Software Foundation; either version 3 of the License, or
16  * (at your option) any later version.
17  *
18  * This program is distributed in the hope that it will be useful,
19  * but WITHOUT ANY WARRANTY; without even the implied warranty of
20  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21  * GNU General Public License for more details.
22  *
23  * You should have received a copy of the GNU General Public License
24  * along with this program. If not, see <https://www.gnu.org/licenses/>.
25  */
26 
33 // Load Dolibarr environment
34 require '../main.inc.php';
35 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
37 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
38 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
39 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
40 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
41 if (!empty($conf->categorie->enabled)) {
42  require_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
43 }
44 
45 // Load translation files required by the page
46 $langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
47 
48 $action = GETPOST('action', 'aZ09');
49 $massaction = GETPOST('massaction', 'alpha');
50 $show_files = GETPOST('show_files', 'int');
51 $confirm = GETPOST('confirm', 'alpha');
52 $toselect = GETPOST('toselect', 'array');
53 $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
54 
55 $search_name = GETPOST('search_name', 'alpha');
56 $search_email = GETPOST('search_email', 'alpha');
57 $search_town = GETPOST('search_town', 'alpha');
58 $search_zip = GETPOST('search_zip', 'alpha');
59 $search_state = GETPOST("search_state", 'alpha');
60 $search_country = GETPOST("search_country", 'int');
61 $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
62 $search_contract = GETPOST('search_contract', 'alpha');
63 $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
64 $search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
65 $sall = (GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
66 $search_status = GETPOST('search_status', 'alpha');
67 $socid = GETPOST('socid', 'int');
68 $search_user = GETPOST('search_user', 'int');
69 $search_sale = GETPOST('search_sale', 'int');
70 $search_product_category = GETPOST('search_product_category', 'int');
71 $search_dfmonth = GETPOST('search_dfmonth', 'int');
72 $search_dfyear = GETPOST('search_dfyear', 'int');
73 $search_op2df = GETPOST('search_op2df', 'alpha');
74 $search_date_startday = GETPOST('search_date_startday', 'int');
75 $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
76 $search_date_startyear = GETPOST('search_date_startyear', 'int');
77 $search_date_endday = GETPOST('search_date_endday', 'int');
78 $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
79 $search_date_endyear = GETPOST('search_date_endyear', 'int');
80 $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
81 $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
82 $searchCategoryCustomerOperator = 0;
83 if (GETPOSTISSET('formfilteraction')) {
84  $searchCategoryCustomerOperator = GETPOST('search_category_customer_operator', 'int');
85 } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
86  $searchCategoryCustomerOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
87 }
88 $searchCategoryCustomerList = GETPOST('search_category_customer_list', 'array');
89 
90 $optioncss = GETPOST('optioncss', 'alpha');
91 
92 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
93 $sortfield = GETPOST('sortfield', 'aZ09comma');
94 $sortorder = GETPOST('sortorder', 'aZ09comma');
95 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
96 if (empty($page) || $page == -1) {
97  $page = 0;
98 } // If $page is not defined, or '' or -1
99 $offset = $limit * $page;
100 $pageprev = $page - 1;
101 $pagenext = $page + 1;
102 if (!$sortfield) {
103  $sortfield = 'c.ref';
104 }
105 if (!$sortorder) {
106  $sortorder = 'DESC';
107 }
108 
109 // Security check
110 $id = GETPOST('id', 'int');
111 if ($user->socid) {
112  $socid = $user->socid;
113 }
114 $result = restrictedArea($user, 'contrat', $id);
115 
116 $diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id;
117 
118 $staticcontrat = new Contrat($db);
119 $staticcontratligne = new ContratLigne($db);
120 
121 if ($search_status == '') {
122  $search_status = 1;
123 }
124 
125 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
126 $object = new Contrat($db);
127 $hookmanager->initHooks(array('contractlist'));
128 $extrafields = new ExtraFields($db);
129 
130 // fetch optionals attributes and labels
131 $extrafields->fetch_name_optionals_label($object->table_element);
132 
133 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
134 // List of fields to search into when doing a "search in all"
135 $fieldstosearchall = array(
136  'c.ref'=>'Ref',
137  'c.ref_customer'=>'RefCustomer',
138  'c.ref_supplier'=>'RefSupplier',
139  's.nom'=>"ThirdParty",
140  'c.note_public'=>'NotePublic',
141 );
142 if (empty($user->socid)) {
143  $fieldstosearchall["c.note_private"] = "NotePrivate";
144 }
145 
146 $arrayfields = array(
147  'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10),
148  'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>12),
149  'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'position'=>14),
150  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>30),
151  's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0, 'position'=>30),
152  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0, 'position'=>31),
153  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>32),
154  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>33),
155  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>34),
156  'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>-1, 'position'=>80),
157  'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1, 'position'=>45),
158  'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
159  'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
160  'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
161  'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
162 );
163 // Extra fields
164 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
165 
166 $object->fields = dol_sort_array($object->fields, 'position');
167 $arrayfields = dol_sort_array($arrayfields, 'position');
168 
169 
170 /*
171  * Action
172  */
173 
174 if (GETPOST('cancel', 'alpha')) {
175  $action = 'list'; $massaction = '';
176 }
177 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
178  $massaction = '';
179 }
180 
181 $parameters = array('socid'=>$socid);
182 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
183 if ($reshook < 0) {
184  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
185 }
186 
187 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
188 
189 // Purge search criteria
190 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All test are required to be compatible with all browsers
191  $search_dfmonth = '';
192  $search_dfyear = '';
193  $search_op2df = '';
194  $search_name = "";
195  $search_email = "";
196  $search_town = '';
197  $search_zip = "";
198  $search_state = "";
199  $search_type = '';
200  $search_country = '';
201  $search_contract = "";
202  $search_ref_customer = "";
203  $search_ref_supplier = "";
204  $search_user = '';
205  $search_sale = '';
206  $search_product_category = '';
207  $search_date_startday = '';
208  $search_date_startmonth = '';
209  $search_date_startyear = '';
210  $search_date_endday = '';
211  $search_date_endmonth = '';
212  $search_date_endyear = '';
213  $search_date_start = '';
214  $search_date_end = '';
215  $sall = "";
216  $search_status = "";
217  $toselect = array();
218  $search_type_thirdparty = '';
219  $searchCategoryCustomerList = array();
220  $search_array_options = array();
221 }
222 
223 if (empty($reshook)) {
224  $objectclass = 'Contrat';
225  $objectlabel = 'Contracts';
226  $permissiontoread = $user->rights->contrat->lire;
227  $permissiontodelete = $user->rights->contrat->supprimer;
228  $uploaddir = $conf->contrat->dir_output;
229  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
230 }
231 
232 
233 /*
234  * View
235  */
236 
237 $now = dol_now();
238 $form = new Form($db);
239 $formfile = new FormFile($db);
240 $formother = new FormOther($db);
241 $socstatic = new Societe($db);
242 $formcompany = new FormCompany($db);
243 $contracttmp = new Contrat($db);
244 $title = "";
245 
246 $sql = 'SELECT';
247 $sql .= " c.rowid, c.ref, c.datec as date_creation, c.tms as date_update, c.date_contrat, c.statut, c.ref_customer, c.ref_supplier, c.note_private, c.note_public, c.entity,";
248 $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,';
249 $sql .= " typent.code as typent_code,";
250 $sql .= " state.code_departement as state_code, state.nom as state_name,";
251 $sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
252 $sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
253 $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,';
254 $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,';
255 $sql .= " SUM(".$db->ifsql("cd.statut=4 AND (cd.date_fin_validite IS NOT NULL AND cd.date_fin_validite < '".$db->idate($now - $conf->contrat->services->expires->warning_delay)."')", 1, 0).') as nb_late,';
256 $sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';
257 // Add fields from extrafields
258 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
259  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
260  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
261  }
262 }
263 // Add fields from hooks
264 $parameters = array();
265 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
266 $sql .= $hookmanager->resPrint;
267 $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
268 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
269 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
270 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
271 if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
272  $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
273 }
274 $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
275 if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
276  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";
277 }
278 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
279 if ($search_user > 0) {
280  $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
281  $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
282 }
283 $sql .= " WHERE c.fk_soc = s.rowid ";
284 $sql .= ' AND c.entity IN ('.getEntity('contract').')';
285 if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
286  $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
287 }
288 if ($socid) {
289  $sql .= " AND s.rowid = ".((int) $socid);
290 }
291 if (empty($user->rights->societe->client->voir) && !$socid) {
292  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
293 }
294 if ($search_date_start) {
295  $sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";
296 }
297 if ($search_date_end) {
298  $sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";
299 }
300 if ($search_name) {
301  $sql .= natural_search('s.nom', $search_name);
302 }
303 if ($search_email) {
304  $sql .= natural_search('s.email', $search_email);
305 }
306 if ($search_contract) {
307  $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
308 }
309 if (!empty($search_ref_customer)) {
310  $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
311 }
312 if (!empty($search_ref_supplier)) {
313  $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
314 }
315 if ($search_zip) {
316  $sql .= natural_search(array('s.zip'), $search_zip);
317 }
318 if ($search_town) {
319  $sql .= natural_search(array('s.town'), $search_town);
320 }
321 if ($search_country && $search_country != '-1') {
322  $sql .= " AND s.fk_pays IN (".$db->sanitize($search_country).')';
323 }
324 if ($search_sale > 0) {
325  $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
326 }
327 if ($sall) {
328  $sql .= natural_search(array_keys($fieldstosearchall), $sall);
329 }
330 if ($search_user > 0) {
331  $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);
332 }
333 // Search for tag/category ($searchCategoryProductList is an array of ID)
334 $searchCategoryProductOperator = -1;
335 $searchCategoryProductList = array($search_product_category);
336 if (!empty($searchCategoryProductList)) {
337  $searchCategoryProductSqlList = array();
338  $listofcategoryid = '';
339  foreach ($searchCategoryProductList as $searchCategoryProduct) {
340  if (intval($searchCategoryProduct) == -2) {
341  $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)";
342  } elseif (intval($searchCategoryProduct) > 0) {
343  if ($searchCategoryProductOperator == 0) {
344  $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).")";
345  } else {
346  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
347  }
348  }
349  }
350  if ($listofcategoryid) {
351  $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)."))";
352  }
353  if ($searchCategoryProductOperator == 1) {
354  if (!empty($searchCategoryProductSqlList)) {
355  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
356  }
357  } else {
358  if (!empty($searchCategoryProductSqlList)) {
359  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
360  }
361  }
362 }
363 $searchCategoryCustomerSqlList = array();
364 if ($searchCategoryCustomerOperator == 1) {
365  $existsCategoryCustomerList = array();
366  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
367  if (intval($searchCategoryCustomer) == -2) {
368  $sqlCategoryCustomerNotExists = " NOT EXISTS (";
369  $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
370  $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
371  $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
372  $sqlCategoryCustomerNotExists .= " )";
373  $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
374  } elseif (intval($searchCategoryCustomer) > 0) {
375  $existsCategoryCustomerList[] = $db->escape($searchCategoryCustomer);
376  }
377  }
378  if (!empty($existsCategoryCustomerList)) {
379  $sqlCategoryCustomerExists = " EXISTS (";
380  $sqlCategoryCustomerExists .= " SELECT cat_cus.fk_soc";
381  $sqlCategoryCustomerExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
382  $sqlCategoryCustomerExists .= " WHERE cat_cus.fk_soc = s.rowid";
383  $sqlCategoryCustomerExists .= " AND cat_cus.fk_categorie IN (".$db->sanitize(implode(',', $existsCategoryCustomerList)).")";
384  $sqlCategoryCustomerExists .= " )";
385  $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerExists;
386  }
387  if (!empty($searchCategoryCustomerSqlList)) {
388  $sql .= " AND (".implode(' OR ', $searchCategoryCustomerSqlList).")";
389  }
390 } else {
391  foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
392  if (intval($searchCategoryCustomer) == -2) {
393  $sqlCategoryCustomerNotExists = " NOT EXISTS (";
394  $sqlCategoryCustomerNotExists .= " SELECT cat_cus.fk_soc";
395  $sqlCategoryCustomerNotExists .= " FROM ".$db->prefix()."categorie_societe AS cat_cus";
396  $sqlCategoryCustomerNotExists .= " WHERE cat_cus.fk_soc = s.rowid";
397  $sqlCategoryCustomerNotExists .= " )";
398  $searchCategoryCustomerSqlList[] = $sqlCategoryCustomerNotExists;
399  } elseif (intval($searchCategoryCustomer) > 0) {
400  $searchCategoryCustomerSqlList[] = "s.rowid IN (SELECT fk_soc FROM ".$db->prefix()."categorie_societe WHERE fk_categorie = ".((int) $searchCategoryCustomer).")";
401  }
402  }
403  if (!empty($searchCategoryCustomerSqlList)) {
404  $sql .= " AND (".implode(' AND ', $searchCategoryCustomerSqlList).")";
405  }
406 }
407 // Add where from extra fields
408 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
409 // Add where from hooks
410 $parameters = array();
411 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
412 $sql .= $hookmanager->resPrint;
413 $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,";
414 $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,';
415 $sql .= " typent.code,";
416 $sql .= " state.code_departement, state.nom";
417 // Add fields from extrafields
418 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
419  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
420  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
421  }
422 }
423 // Add where from hooks
424 $parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
425 $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
426 $sql .= $hookmanager->resPrint;
427 // Add HAVING from hooks
428 $parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
429 $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
430 if (empty($reshook)) {
431  if ($search_dfyear > 0 && $search_op2df) {
432  if ($search_op2df == '<=') {
433  $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
434  } elseif ($search_op2df == '>=') {
435  $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
436  } else {
437  $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))."'";
438  }
439  }
440 }
441 $sql .= $hookmanager->resPrint;
442 
443 $nbtotalofrecords = '';
444 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
445  //$result = $db->query($sql);
446  //$nbtotalofrecords = $db->num_rows($result);
447 
448  if ($search_dfyear > 0 && $search_op2df) {
449  $resql = $db->query($sql, 0, 'auto', 1);
450  while ($db->fetch_object($resql)) {
451  if (empty($nbtotalofrecords)) {
452  $nbtotalofrecords = 1; // We can't make +1 because init value is ''
453  } else {
455  }
456  }
457  } else {
458  $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\‍(\‍),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
459  $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount);
460  $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
461 
462  $resql = $db->query($sqlforcount);
463  $objforcount = $db->fetch_object($resql);
464  $nbtotalofrecords = $objforcount->nbtotalofrecords;
465  }
466 
467  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
468  $page = 0;
469  $offset = 0;
470  }
471 }
472 
473 $sql .= $db->order($sortfield, $sortorder);
474 if ($limit) {
475  $sql .= $db->plimit($limit + 1, $offset);
476 }
477 
478 $resql = $db->query($sql);
479 if (!$resql) {
480  dol_print_error($db);
481  exit;
482 }
483 
484 $num = $db->num_rows($resql);
485 
486 // Direct jump if only one record found
487 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page) {
488  $obj = $db->fetch_object($resql);
489  $id = $obj->rowid;
490  header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
491  exit;
492 }
493 
494 
495 // Output page
496 // --------------------------------------------------------------------
497 
498 llxHeader('', $langs->trans("Contracts"));
499 
500 $i = 0;
501 
502 $arrayofselected = is_array($toselect) ? $toselect : array();
503 
504 if ($socid > 0) {
505  $soc = new Societe($db);
506  $soc->fetch($socid);
507  if (empty($search_name)) {
508  $search_name = $soc->name;
509  }
510 }
511 
512 $param = '';
513 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
514  $param .= '&contextpage='.urlencode($contextpage);
515 }
516 if ($limit > 0 && $limit != $conf->liste_limit) {
517  $param .= '&limit='.urlencode($limit);
518 }
519 if ($sall != '') {
520  $param .= '&sall='.urlencode($sall);
521 }
522 if ($search_contract != '') {
523  $param .= '&search_contract='.urlencode($search_contract);
524 }
525 if ($search_name != '') {
526  $param .= '&search_name='.urlencode($search_name);
527 }
528 if ($search_email != '') {
529  $param .= '&search_email='.urlencode($search_email);
530 }
531 if ($search_ref_customer != '') {
532  $param .= '&search_ref_customer='.urlencode($search_ref_customer);
533 }
534 if ($search_ref_supplier != '') {
535  $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
536 }
537 if ($search_op2df != '') {
538  $param .= '&search_op2df='.urlencode($search_op2df);
539 }
540 if ($search_date_startday > 0) {
541  $param .= '&search_date_startday='.urlencode($search_date_startday);
542 }
543 if ($search_date_startmonth > 0) {
544  $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
545 }
546 if ($search_date_startyear > 0) {
547  $param .= '&search_date_startyear='.urlencode($search_date_startyear);
548 }
549 if ($search_date_endday > 0) {
550  $param .= '&search_date_endday='.urlencode($search_date_endday);
551 }
552 if ($search_date_endmonth > 0) {
553  $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
554 }
555 if ($search_date_endyear > 0) {
556  $param .= '&search_date_endyear='.urlencode($search_date_endyear);
557 }
558 if ($search_dfyear > 0) {
559  $param .= '&search_dfyear='.urlencode($search_dfyear);
560 }
561 if ($search_dfmonth > 0) {
562  $param .= '&search_dfmonth='.urlencode($search_dfmonth);
563 }
564 if ($search_sale > 0) {
565  $param .= '&search_sale='.urlencode($search_sale);
566 }
567 if ($search_user > 0) {
568  $param .= '&search_user='.urlencode($search_user);
569 }
570 if ($search_type_thirdparty > 0) {
571  $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
572 }
573 if ($search_country != '') {
574  $param .= "&search_country=".urlencode($search_country);
575 }
576 if ($search_product_category > 0) {
577  $param .= '&search_product_category='.urlencode($search_product_category);
578 }
579 if ($show_files) {
580  $param .= '&show_files='.urlencode($show_files);
581 }
582 if ($optioncss != '') {
583  $param .= '&optioncss='.urlencode($optioncss);
584 }
585 foreach ($searchCategoryCustomerList as $searchCategoryCustomer) {
586  $param .= "&search_category_customer_list[]=".urlencode($searchCategoryCustomer);
587 }
588 // Add $param from extra fields
589 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
590 
591 // List of mass actions available
592 $arrayofmassactions = array(
593  'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
594  'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
595  'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
596 );
597 if ($user->rights->contrat->supprimer) {
598  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
599 }
600 if (in_array($massaction, array('presend', 'predelete'))) {
601  $arrayofmassactions = array();
602 }
603 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
604 
605 $url = DOL_URL_ROOT.'/contrat/card.php?action=create';
606 if (!empty($socid)) {
607  $url .= '&socid='.((int) $socid);
608 }
609 $newcardbutton = dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->rights->contrat->creer);
610 
611 print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
612 if ($optioncss != '') {
613  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
614 }
615 print '<input type="hidden" name="token" value="'.newToken().'">';
616 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
617 print '<input type="hidden" name="action" value="list">';
618 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
619 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
620 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
621 
622 print_barre_liste($langs->trans("Contracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
623 
624 $topicmail = "SendContractRef";
625 $modelmail = "contract";
626 $objecttmp = new Contrat($db);
627 $trackid = 'con'.$object->id;
628 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
629 
630 if ($sall) {
631  foreach ($fieldstosearchall as $key => $val) {
632  $fieldstosearchall[$key] = $langs->trans($val);
633  }
634  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
635 }
636 
637 $moreforfilter = '';
638 
639 // If the user can view prospects other than his'
640 if ($user->rights->user->user->lire) {
641  $langs->load("commercial");
642  $moreforfilter .= '<div class="divsearchfield">';
643  $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
644  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
645  $moreforfilter .= '</div>';
646 }
647 // If the user can view other users
648 if ($user->rights->user->user->lire) {
649  $moreforfilter .= '<div class="divsearchfield">';
650  $tmptitle = $langs->trans('LinkedToSpecificUsers');
651  $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
652  $moreforfilter .= '</div>';
653 }
654 // If the user can view categories of products
655 if (isModEnabled('categorie') && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
656  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
657  $moreforfilter .= '<div class="divsearchfield">';
658  $tmptitle = $langs->trans('IncludingProductWithTag');
659  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
660  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"').$form->selectarray('search_product_category', $cate_arbo, $search_product_category, $tmptitle, 0, 0, '', 0, 0, 0, 0, 'widthcentpercentminusx maxwidth300', 1);
661  $moreforfilter .= '</div>';
662 }
663 // Filter on customer categories
664 if (!empty($conf->global->MAIN_SEARCH_CATEGORY_CUSTOMER_ON_CONTRACT_LIST) && !empty($conf->categorie->enabled) && $user->rights->categorie->lire) {
665  $moreforfilter .= '<div class="divsearchfield">';
666  $tmptitle = $langs->transnoentities('CustomersProspectsCategoriesShort');
667  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
668  $categoriesArr = $form->select_all_categories(Categorie::TYPE_CUSTOMER, '', '', 64, 0, 1);
669  $categoriesArr[-2] = '- '.$langs->trans('NotCategorized').' -';
670  $moreforfilter .= Form::multiselectarray('search_category_customer_list', $categoriesArr, $searchCategoryCustomerList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
671  $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_customer_operator" name="search_category_customer_operator" value="1"'.($searchCategoryCustomerOperator == 1 ? ' checked="checked"' : '').'/>';
672  $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_cus'); // Tooltip on click
673  $moreforfilter .= '</div>';
674 }
675 
676 $parameters = array();
677 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
678 if (empty($reshook)) {
679  $moreforfilter .= $hookmanager->resPrint;
680 } else {
681  $moreforfilter = $hookmanager->resPrint;
682 }
683 
684 if (!empty($moreforfilter)) {
685  print '<div class="liste_titre liste_titre_bydiv centpercent">';
686  print $moreforfilter;
687  print '</div>';
688 }
689 
690 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
691 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
692 if ($massactionbutton) {
693  $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
694 }
695 
696 print '<div class="div-table-responsive">';
697 print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
698 
699 print '<tr class="liste_titre_filter">';
700 // Action column
701 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
702  print '<td class="liste_titre center">';
703  $searchpicto = $form->showFilterButtons('left');
704  print $searchpicto;
705  print '</td>';
706 }
707 if (!empty($arrayfields['c.ref']['checked'])) {
708  print '<td class="liste_titre">';
709  print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
710  print '</td>';
711 }
712 if (!empty($arrayfields['c.ref_customer']['checked'])) {
713  print '<td class="liste_titre">';
714  print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
715  print '</td>';
716 }
717 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
718  print '<td class="liste_titre">';
719  print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
720  print '</td>';
721 }
722 if (!empty($arrayfields['s.nom']['checked'])) {
723  print '<td class="liste_titre">';
724  print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
725  print '</td>';
726 }
727 if (!empty($arrayfields['s.email']['checked'])) {
728  print '<td class="liste_titre">';
729  print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
730  print '</td>';
731 }
732 // Town
733 if (!empty($arrayfields['s.town']['checked'])) {
734  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
735 }
736 // Zip
737 if (!empty($arrayfields['s.zip']['checked'])) {
738  print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
739 }
740 // State
741 if (!empty($arrayfields['state.nom']['checked'])) {
742  print '<td class="liste_titre">';
743  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
744  print '</td>';
745 }
746 // Country
747 if (!empty($arrayfields['country.code_iso']['checked'])) {
748  print '<td class="liste_titre center">';
749  print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
750  print '</td>';
751 }
752 // Company type
753 if (!empty($arrayfields['typent.code']['checked'])) {
754  print '<td class="liste_titre maxwidthonsmartphone center">';
755  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 1, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT) ? 'ASC' : $conf->global->SOCIETE_SORT_ON_TYPEENT), '', 1);
756  print '</td>';
757 }
758 if (!empty($arrayfields['sale_representative']['checked'])) {
759  print '<td class="liste_titre"></td>';
760 }
761 if (!empty($arrayfields['c.date_contrat']['checked'])) {
762  print '<td class="liste_titre center">';
763  print '<div class="nowrap">';
764  print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
765  print '</div>';
766  print '<div class="nowrap">';
767  print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
768  print '</div>';
769  print '</td>';
770 }
771 // Extra fields
772 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
773 
774 // Fields from hook
775 $parameters = array('arrayfields'=>$arrayfields);
776 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
777 print $hookmanager->resPrint;
778 // Date creation
779 if (!empty($arrayfields['c.datec']['checked'])) {
780  print '<td class="liste_titre">';
781  print '</td>';
782 }
783 // Date modification
784 if (!empty($arrayfields['c.tms']['checked'])) {
785  print '<td class="liste_titre">';
786  print '</td>';
787 }
788 // First end date
789 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
790  print '<td class="liste_titre nowraponall center">';
791  $arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');
792  print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
793  print '</br>';
794  print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
795  print ' ';
796  print $formother->selectyear($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
797  print '</td>';
798 }
799 // Status
800 if (!empty($arrayfields['status']['checked'])) {
801  print '<td class="liste_titre right" colspan="4"></td>';
802 }
803 
804 // Action column
805 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
806  print '<td class="liste_titre center">';
807  $searchpicto = $form->showFilterButtons();
808  print $searchpicto;
809  print '</td>';
810 }
811 print "</tr>\n";
812 
813 print '<tr class="liste_titre">';
814 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
815  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
816 }
817 if (!empty($arrayfields['c.ref']['checked'])) {
818  print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
819 }
820 if (!empty($arrayfields['c.ref_customer']['checked'])) {
821  print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
822 }
823 if (!empty($arrayfields['c.ref_supplier']['checked'])) {
824  print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
825 }
826 if (!empty($arrayfields['s.nom']['checked'])) {
827  print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
828 }
829 if (!empty($arrayfields['s.email']['checked'])) {
830  print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
831 }
832 if (!empty($arrayfields['s.town']['checked'])) {
833  print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
834 }
835 if (!empty($arrayfields['s.zip']['checked'])) {
836  print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
837 }
838 if (!empty($arrayfields['state.nom']['checked'])) {
839  print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
840 }
841 if (!empty($arrayfields['country.code_iso']['checked'])) {
842  print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
843 }
844 if (!empty($arrayfields['typent.code']['checked'])) {
845  print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
846 }
847 if (!empty($arrayfields['sale_representative']['checked'])) {
848  print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
849 }
850 if (!empty($arrayfields['c.date_contrat']['checked'])) {
851  print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
852 }
853 // Extra fields
854 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
855 // Hook fields
856 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
857 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
858 print $hookmanager->resPrint;
859 if (!empty($arrayfields['c.datec']['checked'])) {
860  print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
861 }
862 if (!empty($arrayfields['c.tms']['checked'])) {
863  print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
864 }
865 if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
866  print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
867 }
868 if (!empty($arrayfields['status']['checked'])) {
869  print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
870  print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
871  print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
872  print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
873 }
874 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
875  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
876 }
877 print "</tr>\n";
878 
879 $totalarray = array();
880 $totalarray['nbfield'] = 0;
881 $typenArray = array();
882 $cacheCountryIDCode = array();
883 
884 while ($i < min($num, $limit)) {
885  $obj = $db->fetch_object($resql);
886 
887  $contracttmp->ref = $obj->ref;
888  $contracttmp->id = $obj->rowid;
889  $contracttmp->ref_customer = $obj->ref_customer;
890  $contracttmp->ref_supplier = $obj->ref_supplier;
891 
892  if ($obj->socid > 0) {
893  $result = $socstatic->fetch($obj->socid);
894  }
895  /*$socstatic->id = $obj->socid;
896  $socstatic->name = $obj->name;
897  $socstatic->name_alias = $obj->name_alias;
898  $socstatic->email = $obj->email;
899  $socstatic->status = $obj->company_status;
900  $socstatic->logo = $obj->logo;
901  $socstatic->country_id = $obj->country_id;
902  $socstatic->country_code = '';
903  $socstatic->country = '';*/
904  if ($obj->country_id > 0) {
905  if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
906  $tmparray = getCountry($obj->country_id, 'all');
907  $cacheCountryIDCode[$obj->country_id] = array('code'=> empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
908  }
909  $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
910  $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
911  }
912 
913 
914  print '<tr class="oddeven">';
915  // Action column
916  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
917  print '<td class="nowrap center">';
918  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
919  $selected = 0;
920  if (in_array($obj->rowid, $arrayofselected)) {
921  $selected = 1;
922  }
923  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
924  }
925  print '</td>';
926  }
927  // Ref
928  if (!empty($arrayfields['c.ref']['checked'])) {
929  print '<td class="nowraponall">';
930  print $contracttmp->getNomUrl(1);
931  if ($obj->nb_late) {
932  print img_warning($langs->trans("Late"));
933  }
934  if (!empty($obj->note_private) || !empty($obj->note_public)) {
935  print ' <span class="note">';
936  print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
937  print '</span>';
938  }
939 
940  $filename = dol_sanitizeFileName($obj->ref);
941  $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
942  $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
943  print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
944  print '</td>';
945 
946  print '</td>';
947  }
948 
949  // Ref thirdparty
950  if (!empty($arrayfields['c.ref_customer']['checked'])) {
951  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
952  }
953  if (!empty($arrayfields['c.ref_supplier']['checked'])) {
954  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
955  }
956  if (!empty($arrayfields['s.nom']['checked'])) {
957  print '<td class="tdoverflowmax150">';
958  if ($obj->socid > 0) {
959  // TODO Use a cache for this string
960  print $socstatic->getNomUrl(1, '');
961  }
962  print '</td>';
963  }
964  // Email
965  if (!empty($arrayfields['s.email']['checked'])) {
966  print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 0, 0, 1, 1).'</td>';
967  }
968  // Town
969  if (!empty($arrayfields['s.town']['checked'])) {
970  print '<td class="nocellnopadd">';
971  print $obj->town;
972  print '</td>';
973  if (!$i) {
974  $totalarray['nbfield']++;
975  }
976  }
977  // Zip
978  if (!empty($arrayfields['s.zip']['checked'])) {
979  print '<td class="nocellnopadd">';
980  print $obj->zip;
981  print '</td>';
982  if (!$i) {
983  $totalarray['nbfield']++;
984  }
985  }
986  // State
987  if (!empty($arrayfields['state.nom']['checked'])) {
988  print "<td>".$obj->state_name."</td>\n";
989  if (!$i) {
990  $totalarray['nbfield']++;
991  }
992  }
993  // Country
994  if (!empty($arrayfields['country.code_iso']['checked'])) {
995  print '<td class="center tdoverflowmax100" title="'.dol_escape_htmltag($socstatic->country).'">';
996  print dol_escape_htmltag($socstatic->country);
997  print '</td>';
998  if (!$i) {
999  $totalarray['nbfield']++;
1000  }
1001  }
1002  // Type ent
1003  if (!empty($arrayfields['typent.code']['checked'])) {
1004  print '<td class="center">';
1005  if (count($typenArray) == 0) {
1006  $typenArray = $formcompany->typent_array(1);
1007  }
1008  print $typenArray[$obj->typent_code];
1009  print '</td>';
1010  if (!$i) {
1011  $totalarray['nbfield']++;
1012  }
1013  }
1014  if (!empty($arrayfields['sale_representative']['checked'])) {
1015  // Sales representatives
1016  print '<td>';
1017  if ($obj->socid > 0) {
1018  $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
1019  if ($listsalesrepresentatives < 0) {
1020  dol_print_error($db);
1021  }
1022  $nbofsalesrepresentative = count($listsalesrepresentatives);
1023  if ($nbofsalesrepresentative > 6) {
1024  // We print only number
1025  print $nbofsalesrepresentative;
1026  } elseif ($nbofsalesrepresentative > 0) {
1027  $userstatic = new User($db);
1028  $j = 0;
1029  foreach ($listsalesrepresentatives as $val) {
1030  $userstatic->id = $val['id'];
1031  $userstatic->lastname = $val['lastname'];
1032  $userstatic->firstname = $val['firstname'];
1033  $userstatic->email = $val['email'];
1034  $userstatic->statut = $val['statut'];
1035  $userstatic->entity = $val['entity'];
1036  $userstatic->photo = $val['photo'];
1037  $userstatic->login = $val['login'];
1038  $userstatic->phone = $val['phone'];
1039  $userstatic->job = $val['job'];
1040  $userstatic->gender = $val['gender'];
1041 
1042  //print '<div class="float">':
1043  print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
1044  $j++;
1045  if ($j < $nbofsalesrepresentative) {
1046  print ' ';
1047  }
1048  //print '</div>';
1049  }
1050  }
1051  //else print $langs->trans("NoSalesRepresentativeAffected");
1052  } else {
1053  print '&nbsp;';
1054  }
1055  print '</td>';
1056  }
1057  // Date
1058  if (!empty($arrayfields['c.date_contrat']['checked'])) {
1059  print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
1060  }
1061  // Extra fields
1062  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
1063  // Fields from hook
1064  $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
1065  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1066  print $hookmanager->resPrint;
1067  // Date creation
1068  if (!empty($arrayfields['c.datec']['checked'])) {
1069  print '<td class="center nowrap">';
1070  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
1071  print '</td>';
1072  if (!$i) {
1073  $totalarray['nbfield']++;
1074  }
1075  }
1076  // Date modification
1077  if (!empty($arrayfields['c.tms']['checked'])) {
1078  print '<td class="center nowrap">';
1079  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
1080  print '</td>';
1081  if (!$i) {
1082  $totalarray['nbfield']++;
1083  }
1084  }
1085  // Date lower end date
1086  if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
1087  print '<td class="center nowrapforall">';
1088  print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
1089  print '</td>';
1090  if (!$i) {
1091  $totalarray['nbfield']++;
1092  }
1093  }
1094  // Status
1095  if (!empty($arrayfields['status']['checked'])) {
1096  print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
1097  print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
1098  print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
1099  print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
1100  }
1101  // Action column
1102  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
1103  print '<td class="nowrap center">';
1104  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
1105  $selected = 0;
1106  if (in_array($obj->rowid, $arrayofselected)) {
1107  $selected = 1;
1108  }
1109  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
1110  }
1111  print '</td>';
1112  }
1113  if (!$i) {
1114  $totalarray['nbfield']++;
1115  }
1116 
1117  print "</tr>\n";
1118  $i++;
1119 }
1120 
1121 // If no record found
1122 if ($num == 0) {
1123  $colspan = 4; // Include the 4 columns of status
1124  foreach ($arrayfields as $key => $val) {
1125  if (!empty($val['checked'])) {
1126  $colspan++;
1127  }
1128  }
1129  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
1130 }
1131 
1132 $db->free($resql);
1133 
1134 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
1135 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
1136 print $hookmanager->resPrint;
1137 
1138 print '</table>';
1139 print '</div>';
1140 
1141 print '</form>';
1142 
1143 $hidegeneratedfilelistifempty = 1;
1144 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
1145  $hidegeneratedfilelistifempty = 0;
1146 }
1147 
1148 // Show list of available documents
1149 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
1150 $urlsource .= str_replace('&amp;', '&', $param);
1151 
1152 $filedir = $diroutputmassaction;
1153 $genallowed = $user->rights->contrat->lire;
1154 $delallowed = $user->rights->contrat->lire;
1155 
1156 print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
1157 
1158 
1159 llxFooter();
1160 $db->close();
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:56
llxFooter()
Empty footer.
Definition: wrapper.php:70
Class to manage contracts.
Class to manage lines of contracts.
Class to manage standard extra fields.
Class to build HTML component for third parties management Only common components are here.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
static multiselectarray($htmlname, $array, $selected=array(), $key_in_label=0, $value_as_key=0, $morecss='', $translate=0, $width=0, $moreattrib='', $elemtype='', $placeholder='', $addjscombo=-1)
Show a multiselect form from an array.
Classe 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.
Definition: user.class.php:47
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(isModEnabled('facture') &&!empty($user->rights->facture->lire)) if((isModEnabled('fournisseur') &&empty($conf->global->MAIN_USE_NEW_SUPPLIERMOD) && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') &&!empty($user->rights->don->lire)) if(isModEnabled('tax') &&!empty($user->rights->tax->charges->lire)) if(isModEnabled('facture') &&isModEnabled('commande') && $user->hasRight("commande", "lire") &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) $resql
Social contributions to pay.
Definition: index.php:745
if($cancel &&! $id) if($action=='add' &&! $cancel) if($action=='delete') if($id) $form
Actions.
Definition: card.php:143
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:575
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:594
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
img_warning($titlealt='default', $moreatt='', $morecss='pictowarning')
Show warning logo.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0)
Returns text escaped for inclusion in HTML alt or title tags, or into values of HTML input fields.
dol_string_nohtmltag($stringtoclean, $removelinefeed=1, $pagecodeto='UTF-8', $strip_tags=0, $removedoublespaces=1)
Clean a string from all HTML tags and entities.
dol_print_error($db='', $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='')
Set event messages in dol_events session object.
dol_print_date($time, $format='', $tzoutput='auto', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_print_email($email, $cid=0, $socid=0, $addlink=0, $max=64, $showinvalid=1, $withpicto=0)
Show EMail link formatted for HTML output.
dol_now($mode='auto')
Return date for now.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by second index function, which produces ascending (default) or descending output...
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="", $forcenowrapcolumntitle=0)
Show title line of an array.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
if(!function_exists('utf8_encode')) if(!function_exists('utf8_decode')) getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
isModEnabled($module)
Is Dolibarr module enabled.
$nbtotalofrecords
Count total nb of records.
Definition: list.php:329
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.