dolibarr  7.0.0-beta
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-2017 Laurent Destailleur <eldy@users.sourceforge.net>
4  * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
5  * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
6  * Copyright (C) 2014 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 Ferran Marcet <fmarcet@2byte.es>
10  *
11  * This program is free software; you can redistribute it and/or modify
12  * it under the terms of the GNU General Public License as published by
13  * the Free Software Foundation; either version 3 of the License, or
14  * (at your option) any later version.
15  *
16  * This program is distributed in the hope that it will be useful,
17  * but WITHOUT ANY WARRANTY; without even the implied warranty of
18  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19  * GNU General Public License for more details.
20  *
21  * You should have received a copy of the GNU General Public License
22  * along with this program. If not, see <http://www.gnu.org/licenses/>.
23  */
24 
31 require ("../main.inc.php");
32 require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
33 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
34 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
35 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
36 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
37 
38 $langs->load("contracts");
39 $langs->load("products");
40 $langs->load("companies");
41 $langs->load("compta");
42 
43 $action=GETPOST('action','alpha');
44 $massaction=GETPOST('massaction','alpha');
45 $show_files=GETPOST('show_files','int');
46 $confirm=GETPOST('confirm','alpha');
47 $toselect = GETPOST('toselect', 'array');
48 
49 $search_name=GETPOST('search_name');
50 $search_email=GETPOST('search_email');
51 $search_town=GETPOST('search_town','alpha');
52 $search_zip=GETPOST('search_zip','alpha');
53 $search_state=trim(GETPOST("search_state"));
54 $search_country=GETPOST("search_country",'int');
55 $search_type_thirdparty=GETPOST("search_type_thirdparty",'int');
56 $search_contract=GETPOST('search_contract');
57 $search_ref_customer=GETPOST('search_ref_customer','alpha');
58 $search_ref_supplier=GETPOST('search_ref_supplier','alpha');
59 $sall=trim((GETPOST('search_all', 'alphanohtml')!='')?GETPOST('search_all', 'alphanohtml'):GETPOST('sall', 'alphanohtml'));
60 $search_status=GETPOST('search_status');
61 $socid=GETPOST('socid');
62 $search_user=GETPOST('search_user','int');
63 $search_sale=GETPOST('search_sale','int');
64 $search_product_category=GETPOST('search_product_category','int');
65 $search_dfmonth=GETPOST('search_dfmonth','int');
66 $search_dfyear=GETPOST('search_dfyear','int');
67 $search_op2df=GETPOST('search_op2df','alpha');
68 $day=GETPOST("day","int");
69 $year=GETPOST("year","int");
70 $month=GETPOST("month","int");
71 
72 $optioncss = GETPOST('optioncss','alpha');
73 
74 $limit = GETPOST('limit','int')?GETPOST('limit','int'):$conf->liste_limit;
75 $sortfield = GETPOST("sortfield",'alpha');
76 $sortorder = GETPOST("sortorder",'alpha');
77 $page = GETPOST("page",'int');
78 if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
79 $offset = $limit * $page;
80 $pageprev = $page - 1;
81 $pagenext = $page + 1;
82 if (! $sortfield) $sortfield='c.ref';
83 if (! $sortorder) $sortorder='DESC';
84 
85 // Security check
86 $id=GETPOST('id','int');
87 if ($user->societe_id) $socid=$user->societe_id;
88 $result = restrictedArea($user, 'contrat', $id);
89 
90 $diroutputmassaction=$conf->contrat->dir_output . '/temp/massgeneration/'.$user->id;
91 
92 $staticcontrat=new Contrat($db);
93 $staticcontratligne=new ContratLigne($db);
94 
95 if ($search_status == '') $search_status=1;
96 
97 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
98 $contextpage='contractlist';
99 
100 // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
101 $hookmanager->initHooks(array($contextpage));
102 $extrafields = new ExtraFields($db);
103 
104 // fetch optionals attributes and labels
105 $extralabels = $extrafields->fetch_name_optionals_label('contrat');
106 $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
107 // List of fields to search into when doing a "search in all"
108 $fieldstosearchall = array(
109  'c.ref'=>'Ref',
110  'c.ref_customer'=>'RefCustomer',
111  'c.ref_supplier'=>'RefSupplier',
112  's.nom'=>"ThirdParty",
113  'cd.description'=>'Description',
114  'c.note_public'=>'NotePublic',
115 );
116 if (empty($user->socid)) $fieldstosearchall["c.note_private"]="NotePrivate";
117 
118 $arrayfields=array(
119  'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1),
120  'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1),
121  'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1),
122  's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1),
123  's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0),
124  's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0),
125  's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>0),
126  'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0),
127  'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0),
128  'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>1),
129  'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1),
130  'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
131  'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
132  'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
133  'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
134 );
135 // Extra fields
136 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
137 {
138  foreach($extrafields->attribute_label as $key => $val)
139  {
140  if (! empty($extrafields->attribute_list[$key])) $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>(($extrafields->attribute_list[$key]<0)?0:1), 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>(abs($extrafields->attribute_list[$key])!=3 && $extrafields->attribute_perms[$key]));
141  }
142 }
143 
144 
145 /*
146  * Action
147  */
148 
149 if (GETPOST('cancel','alpha')) { $action='list'; $massaction=''; }
150 if (! GETPOST('confirmmassaction','alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') { $massaction=''; }
151 
152 $parameters=array('socid'=>$socid);
153 $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
154 if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
155 
156 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
157 
158 // Purge search criteria
159 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
160 {
161  $day='';
162  $month='';
163  $year='';
164  $search_dfmonth='';
165  $search_dfyear='';
166  $search_op2df='';
167  $search_name="";
168  $search_email="";
169  $search_town='';
170  $search_zip="";
171  $search_state="";
172  $search_type='';
173  $search_country='';
174  $search_contract="";
175  $search_ref_customer="";
176  $search_ref_supplier="";
177  $search_user='';
178  $search_sale='';
179  $search_product_category='';
180  $sall="";
181  $search_status="";
182  $toselect='';
183  $search_array_options=array();
184 }
185 
186 if (empty($reshook))
187 {
188  $objectclass='Contrat';
189  $objectlabel='Contracts';
190  $permtoread = $user->rights->contrat->lire;
191  $permtodelete = $user->rights->contrat->supprimer;
192  $uploaddir = $conf->contrat->dir_output;
193  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
194 }
195 
196 
197 /*
198  * View
199  */
200 
201 $now=dol_now();
202 $form = new Form($db);
203 $formfile = new FormFile($db);
204 $formother = new FormOther($db);
205 $socstatic = new Societe($db);
206 $contracttmp = new Contrat($db);
207 
208 llxHeader('', $langs->trans("Contracts"));
209 
210 $sql = 'SELECT';
211 $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,";
212 $sql.= ' s.rowid as socid, s.nom as name, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
213 $sql.= " typent.code as typent_code,";
214 $sql.= " state.code_departement as state_code, state.nom as state_name,";
215 $sql.= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
216 $sql.= ' SUM('.$db->ifsql("cd.statut=0",1,0).') as nb_initial,';
217 $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,';
218 $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,';
219 $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,';
220 $sql.= ' SUM('.$db->ifsql("cd.statut=5",1,0).') as nb_closed';
221 // Add fields from extrafields
222 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
223 // Add fields from hooks
224 $parameters=array();
225 $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
226 $sql.=$hookmanager->resPrint;
227 $sql.= " FROM ".MAIN_DB_PREFIX."societe as s";
228 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
229 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
230 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
231 if ($search_sale > 0 || (! $user->rights->societe->client->voir && ! $socid)) $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
232 $sql.= ", ".MAIN_DB_PREFIX."contrat as c";
233 if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contrat_extrafields as ef on (c.rowid = ef.fk_object)";
234 $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
235 if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
236 if ($search_user > 0)
237 {
238  $sql.=", ".MAIN_DB_PREFIX."element_contact as ec";
239  $sql.=", ".MAIN_DB_PREFIX."c_type_contact as tc";
240 }
241 $sql.= " WHERE c.fk_soc = s.rowid ";
242 $sql.= ' AND c.entity IN ('.getEntity('contract').')';
243 if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
244 if ($socid) $sql.= " AND s.rowid = ".$db->escape($socid);
245 if (!$user->rights->societe->client->voir && !$socid) $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
246 if ($month > 0)
247 {
248  if ($year > 0 && empty($day))
249  $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,$month,false))."' AND '".$db->idate(dol_get_last_day($year,$month,false))."'";
250  else if ($year > 0 && ! empty($day))
251  $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_mktime(0, 0, 0, $month, $day, $year))."' AND '".$db->idate(dol_mktime(23, 59, 59, $month, $day, $year))."'";
252  else
253  $sql.= " AND date_format(c.date_contrat, '%m') = '".$month."'";
254 }
255 else if ($year > 0)
256 {
257  $sql.= " AND c.date_contrat BETWEEN '".$db->idate(dol_get_first_day($year,1,false))."' AND '".$db->idate(dol_get_last_day($year,12,false))."'";
258 }
259 if ($search_name) $sql .= natural_search('s.nom', $search_name);
260 if ($search_email) $sql .= natural_search('s.email', $search_name);
261 if ($search_contract) $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
262 if (!empty($search_ref_customer)) $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
263 if (!empty($search_ref_supplier)) $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
264 if ($search_sale > 0)
265 {
266  $sql.= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$search_sale;
267 }
268 if ($sall) $sql .= natural_search(array_keys($fieldstosearchall), $sall);
269 if ($search_user > 0) $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 = ".$search_user;
270 // Add where from extra fields
271 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
272 // Add where from hooks
273 $parameters=array();
274 $reshook=$hookmanager->executeHooks('printFieldListWhere',$parameters); // Note that $action and $object may have been modified by hook
275 $sql.=$hookmanager->resPrint;
276 $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,";
277 $sql.= ' s.rowid, s.nom, s.email, s.town, s.zip, s.fk_pays, s.client, s.code_client,';
278 $sql.= " typent.code,";
279 $sql.= " state.code_departement, state.nom";
280 // Add fields from extrafields
281 foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key : '');
282 // Add where from hooks
283 $parameters=array();
284 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters); // Note that $action and $object may have been modified by hook
285 $sql.=$hookmanager->resPrint;
286 if ($search_dfyear > 0 && $search_op2df)
287 {
288  if ($search_op2df == '<=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear,$search_dfmonth,false))."'";
289  elseif ($search_op2df == '>=') $sql.= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear,$search_dfmonth,false))."'";
290  else $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))."'";
291 }
292 $sql.= $db->order($sortfield,$sortorder);
293 //print $sql;
294 
295 $totalnboflines=0;
296 $result=$db->query($sql);
297 if ($result)
298 {
299  $totalnboflines = $db->num_rows($result);
300 }
301 
302 $nbtotalofrecords = '';
303 if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
304 {
305  $result = $db->query($sql);
306  $nbtotalofrecords = $db->num_rows($result);
307 }
308 
309 $sql.= $db->plimit($limit + 1, $offset);
310 
311 $resql=$db->query($sql);
312 if ($resql)
313 {
314  $num = $db->num_rows($resql);
315  $i = 0;
316 
317  $arrayofselected=is_array($toselect)?$toselect:array();
318 
319  if ($socid > 0)
320  {
321  $soc = new Societe($db);
322  $soc->fetch($socid);
323  if (empty($search_name)) $search_name = $soc->name;
324  }
325 
326  $param='';
327  if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.urlencode($contextpage);
328  if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
329  if ($sall != '') $param.='&sall='.urlencode($sall);
330  if ($search_contract != '') $param.='&search_contract='.urlencode($search_contract);
331  if ($search_name != '') $param.='&search_name='.urlencode($search_name);
332  if ($search_email != '') $param.='&search_email='.urlencode($search_email);
333  if ($search_ref_customer != '') $param.='&search_ref_customer='.urlencode($search_ref_customer);
334  if ($search_ref_supplier != '') $param.='&search_ref_supplier='.urlencode($search_ref_supplier);
335  if ($search_op2df != '') $param.='&search_op2df='.urlencode($search_op2df);
336  if ($search_dfyear != '') $param.='&search_dfyear='.urlencode($search_dfyear);
337  if ($search_dfmonth != '') $param.='&search_dfmonth='.urlencode($search_dfmonth);
338  if ($search_sale != '') $param.='&search_sale=' .urlencode($search_sale);
339  if ($search_user != '') $param.='&search_user=' .urlencode($search_user);
340  if ($search_product_category != '') $param.='&search_product_category=' .urlencode($search_product_category);
341  if ($show_files) $param.='&show_files=' .urlencode($show_files);
342  if ($optioncss != '') $param.='&optioncss='.urlencode($optioncss);
343  // Add $param from extra fields
344  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
345 
346  // List of mass actions available
347  $arrayofmassactions = array(
348  'presend'=>$langs->trans("SendByMail"),
349  'builddoc'=>$langs->trans("PDFMerge"),
350  );
351  if ($user->rights->contrat->supprimer) $arrayofmassactions['predelete']=$langs->trans("Delete");
352  if (in_array($massaction, array('presend','predelete'))) $arrayofmassactions=array();
353  $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
354 
355  print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
356  if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
357  print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
358  print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
359  print '<input type="hidden" name="action" value="list">';
360  print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
361  print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
362  print '<input type="hidden" name="page" value="'.$page.'">';
363 
364  print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $totalnboflines, 'title_commercial.png', 0, '', '', $limit);
365 
366  $topicmail="SendContractRef";
367  $modelmail="contract";
368  $objecttmp=new Contrat($db);
369  $trackid='con'.$object->id;
370  include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
371 
372  if ($sall)
373  {
374  foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
375  print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
376  }
377 
378  $moreforfilter='';
379 
380  // If the user can view prospects other than his'
381  if ($user->rights->societe->client->voir || $socid)
382  {
383  $langs->load("commercial");
384  $moreforfilter.='<div class="divsearchfield">';
385  $moreforfilter.=$langs->trans('ThirdPartiesOfSaleRepresentative'). ': ';
386  $moreforfilter.=$formother->select_salesrepresentatives($search_sale,'search_sale',$user,0,1,'maxwidth200');
387  $moreforfilter.='</div>';
388  }
389  // If the user can view other users
390  if ($user->rights->user->user->lire)
391  {
392  $moreforfilter.='<div class="divsearchfield">';
393  $moreforfilter.=$langs->trans('LinkedToSpecificUsers'). ': ';
394  $moreforfilter.=$form->select_dolusers($search_user, 'search_user', 1, '', 0, '', '', 0, 0, 0, '', 0, '', 'maxwidth200');
395  $moreforfilter.='</div>';
396  }
397  // If the user can view categories of products
398  if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
399  {
400  include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
401  $moreforfilter.='<div class="divsearchfield">';
402  $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
403  $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
404  $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, 'maxwidth300', 1);
405  $moreforfilter.='</div>';
406  }
407 
408  $parameters=array();
409  $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
410  if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
411  else $moreforfilter = $hookmanager->resPrint;
412 
413  if (! empty($moreforfilter))
414  {
415  print '<div class="liste_titre liste_titre_bydiv centpercent">';
416  print $moreforfilter;
417  print '</div>';
418  }
419 
420  $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
421  $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
422  if ($massactionbutton) $selectedfields.=$form->showCheckAddButtons('checkforselect', 1);
423 
424  print '<div class="div-table-responsive">';
425  print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
426 
427  print '<tr class="liste_titre_filter">';
428  if (! empty($arrayfields['c.ref']['checked']))
429  {
430  print '<td class="liste_titre">';
431  print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
432  print '</td>';
433  }
434  if (! empty($arrayfields['c.ref_customer']['checked']))
435  {
436  print '<td class="liste_titre">';
437  print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
438  print '</td>';
439  }
440  if (! empty($arrayfields['c.ref_supplier']['checked']))
441  {
442  print '<td class="liste_titre">';
443  print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
444  print '</td>';
445  }
446  if (! empty($arrayfields['s.nom']['checked']))
447  {
448  print '<td class="liste_titre">';
449  print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
450  print '</td>';
451  }
452  if (! empty($arrayfields['s.email']['checked']))
453  {
454  print '<td class="liste_titre">';
455  print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
456  print '</td>';
457  }
458  // Town
459  if (! empty($arrayfields['s.town']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.$search_town.'"></td>';
460  // Zip
461  if (! empty($arrayfields['s.zip']['checked'])) print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.$search_zip.'"></td>';
462  // State
463  if (! empty($arrayfields['state.nom']['checked']))
464  {
465  print '<td class="liste_titre">';
466  print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
467  print '</td>';
468  }
469  // Country
470  if (! empty($arrayfields['country.code_iso']['checked']))
471  {
472  print '<td class="liste_titre" align="center">';
473  print $form->select_country($search_country,'search_country','',0,'maxwidth100');
474  print '</td>';
475  }
476  // Company type
477  if (! empty($arrayfields['typent.code']['checked']))
478  {
479  print '<td class="liste_titre maxwidthonsmartphone" align="center">';
480  print $form->selectarray("search_type_thirdparty", $formcompany->typent_array(0), $search_type_thirdparty, 0, 0, 0, '', 0, 0, 0, (empty($conf->global->SOCIETE_SORT_ON_TYPEENT)?'ASC':$conf->global->SOCIETE_SORT_ON_TYPEENT));
481  print '</td>';
482  }
483  if (! empty($arrayfields['sale_representative']['checked']))
484  {
485  print '<td class="liste_titre"></td>';
486  }
487  if (! empty($arrayfields['c.date_contrat']['checked']))
488  {
489  // Date contract
490  print '<td class="liste_titre center">';
491  //print $langs->trans('Month').': ';
492  if (! empty($conf->global->MAIN_LIST_FILTER_ON_DAY)) print '<input class="flat" type="text" size="1" maxlength="2" name="day" value="'.$day.'">';
493  print '<input class="flat" type="text" size="1" maxlength="2" name="month" value="'.$month.'">';
494  //print '&nbsp;'.$langs->trans('Year').': ';
495  $syear = $year;
496  $formother->select_year($syear,'year',1, 20, 5);
497  print '</td>';
498  }
499  // Extra fields
500  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
501 
502  // Fields from hook
503  $parameters=array('arrayfields'=>$arrayfields);
504  $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
505  print $hookmanager->resPrint;
506  // Date creation
507  if (! empty($arrayfields['c.datec']['checked']))
508  {
509  print '<td class="liste_titre">';
510  print '</td>';
511  }
512  // Date modification
513  if (! empty($arrayfields['c.tms']['checked']))
514  {
515  print '<td class="liste_titre">';
516  print '</td>';
517  }
518  // First end date
519  if (! empty($arrayfields['lower_planned_end_date']['checked']))
520  {
521  print '<td class="liste_titre" align="center">';
522  $arrayofoperators=array('0'=>'','='=>'=','<='=>'<=','>='=>'>=');
523  print $form->selectarray('search_op2df',$arrayofoperators,$search_op2df,0);
524  print '</br>';
525  print $formother->select_month($search_dfmonth, 'search_dfmonth', 1);
526  print ' ';
527  $formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5);
528  print '</td>';
529  }
530  // Status
531  if (! empty($arrayfields['status']['checked']))
532  {
533  print '<td class="liste_titre" colspan="4" align="right"></td>';
534  }
535  print '<td class="liste_titre" align="middle">';
536  $searchpicto=$form->showFilterButtons();
537  print $searchpicto;
538  print '</td>';
539  print "</tr>\n";
540 
541  print '<tr class="liste_titre">';
542  if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref","","$param",'',$sortfield,$sortorder);
543  if (! empty($arrayfields['c.ref_customer']['checked'])) print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer","","$param",'',$sortfield,$sortorder);
544  if (! empty($arrayfields['c.ref_supplier']['checked'])) print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier","","$param",'',$sortfield,$sortorder);
545  if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom","","$param",'',$sortfield,$sortorder);
546  if (! empty($arrayfields['s.email']['checked'])) print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email","","$param",'',$sortfield,$sortorder);
547  if (! empty($arrayfields['s.town']['checked'])) print_liste_field_titre($arrayfields['s.town']['label'],$_SERVER["PHP_SELF"],'s.town','',$param,'',$sortfield,$sortorder);
548  if (! empty($arrayfields['s.zip']['checked'])) print_liste_field_titre($arrayfields['s.zip']['label'],$_SERVER["PHP_SELF"],'s.zip','',$param,'',$sortfield,$sortorder);
549  if (! empty($arrayfields['state.nom']['checked'])) print_liste_field_titre($arrayfields['state.nom']['label'],$_SERVER["PHP_SELF"],"state.nom","",$param,'',$sortfield,$sortorder);
550  if (! empty($arrayfields['country.code_iso']['checked'])) print_liste_field_titre($arrayfields['country.code_iso']['label'],$_SERVER["PHP_SELF"],"country.code_iso","",$param,'align="center"',$sortfield,$sortorder);
551  if (! empty($arrayfields['typent.code']['checked'])) print_liste_field_titre($arrayfields['typent.code']['label'],$_SERVER["PHP_SELF"],"typent.code","",$param,'align="center"',$sortfield,$sortorder);
552  if (! empty($arrayfields['sale_representative']['checked'])) print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "","","$param",'',$sortfield,$sortorder);
553  if (! empty($arrayfields['c.date_contrat']['checked'])) print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat","","$param",'align="center"',$sortfield,$sortorder);
554  // Extra fields
555  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
556  // Hook fields
557  $parameters=array('arrayfields'=>$arrayfields);
558  $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
559  print $hookmanager->resPrint;
560  if (! empty($arrayfields['c.datec']['checked'])) print_liste_field_titre($arrayfields['c.datec']['label'],$_SERVER["PHP_SELF"],"c.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
561  if (! empty($arrayfields['c.tms']['checked'])) print_liste_field_titre($arrayfields['c.tms']['label'],$_SERVER["PHP_SELF"],"c.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
562  if (! empty($arrayfields['lower_planned_end_date']['checked'])) print_liste_field_titre($arrayfields['lower_planned_end_date']['label'],$_SERVER["PHP_SELF"],"lower_planned_end_date","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
563  if (! empty($arrayfields['status']['checked']))
564  {
565  print_liste_field_titre($staticcontratligne->LibStatut(0,3), '', '', '', '', 'width="16"');
566  print_liste_field_titre($staticcontratligne->LibStatut(4,3,0), '', '', '', '', 'width="16"');
567  print_liste_field_titre($staticcontratligne->LibStatut(4,3,1), '', '', '', '', 'width="16"');
568  print_liste_field_titre($staticcontratligne->LibStatut(5,3), '', '', '', '', 'width="16"');
569  }
570  print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
571  print "</tr>\n";
572 
573  while ($i < min($num,$limit))
574  {
575  $obj = $db->fetch_object($resql);
576 
577  $contracttmp->ref=$obj->ref;
578  $contracttmp->id=$obj->rowid;
579  $contracttmp->ref_customer=$obj->ref_customer;
580  $contracttmp->ref_supplier=$obj->ref_supplier;
581 
582  if ($obj->socid > 0)
583  {
584  $result=$socstatic->fetch($obj->socid);
585  }
586 
587  print '<tr class="oddeven">';
588  if (! empty($arrayfields['c.ref']['checked']))
589  {
590  print '<td class="nowrap">';
591  print $contracttmp->getNomUrl(1);
592  if ($obj->nb_late) print img_warning($langs->trans("Late"));
593  if (!empty($obj->note_private) || !empty($obj->note_public))
594  {
595  print ' <span class="note">';
596  print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"),'object_generic').'</a>';
597  print '</span>';
598  }
599 
600  $filename=dol_sanitizeFileName($obj->ref);
601  $filedir=$conf->contrat->dir_output . '/' . dol_sanitizeFileName($obj->ref);
602  $urlsource=$_SERVER['PHP_SELF'].'?id='.$obj->rowid;
603  print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
604  print '</td>';
605 
606  print '</td>';
607  }
608  if (! empty($arrayfields['c.ref_customer']['checked']))
609  {
610  print '<td>'.$obj->ref_customer.'</td>';
611  }
612  if (! empty($arrayfields['c.ref_supplier']['checked']))
613  {
614  print '<td>'.$obj->ref_supplier.'</td>';
615  }
616  if (! empty($arrayfields['s.nom']['checked']))
617  {
618  print '<td>';
619  //print '<a href="../comm/card.php?socid='.$obj->socid.'">'.img_object($langs->trans("ShowCompany"),"company").' '.$obj->name.'</a>';
620  if ($obj->socid > 0)
621  {
622  print $socstatic->getNomUrl(1, '');
623  }
624  print '</td>';
625  }
626  if (! empty($arrayfields['s.email']['checked']))
627  {
628  print '<td>'.$obj->email.'</td>';
629  }
630  // Town
631  if (! empty($arrayfields['s.town']['checked']))
632  {
633  print '<td class="nocellnopadd">';
634  print $obj->town;
635  print '</td>';
636  if (! $i) $totalarray['nbfield']++;
637  }
638  // Zip
639  if (! empty($arrayfields['s.zip']['checked']))
640  {
641  print '<td class="nocellnopadd">';
642  print $obj->zip;
643  print '</td>';
644  if (! $i) $totalarray['nbfield']++;
645  }
646  // State
647  if (! empty($arrayfields['state.nom']['checked']))
648  {
649  print "<td>".$obj->state_name."</td>\n";
650  if (! $i) $totalarray['nbfield']++;
651  }
652  // Country
653  if (! empty($arrayfields['country.code_iso']['checked']))
654  {
655  print '<td align="center">';
656  $tmparray=getCountry($obj->fk_pays,'all');
657  print $tmparray['label'];
658  print '</td>';
659  if (! $i) $totalarray['nbfield']++;
660  }
661  // Type ent
662  if (! empty($arrayfields['typent.code']['checked']))
663  {
664  print '<td align="center">';
665  if (count($typenArray)==0) $typenArray = $formcompany->typent_array(1);
666  print $typenArray[$obj->typent_code];
667  print '</td>';
668  if (! $i) $totalarray['nbfield']++;
669  }
670  if (! empty($arrayfields['sale_representative']['checked']))
671  {
672  // Sales representatives
673  print '<td>';
674  if ($obj->socid > 0)
675  {
676  $listsalesrepresentatives=$socstatic->getSalesRepresentatives($user);
677  if ($listsalesrepresentatives < 0) dol_print_error($db);
678  $nbofsalesrepresentative=count($listsalesrepresentatives);
679  if ($nbofsalesrepresentative > 3) // We print only number
680  {
681  print '<a href="'.DOL_URL_ROOT.'/societe/commerciaux.php?socid='.$socstatic->id.'">';
682  print $nbofsalesrepresentative;
683  print '</a>';
684  }
685  else if ($nbofsalesrepresentative > 0)
686  {
687  $userstatic=new User($db);
688  $j=0;
689  foreach($listsalesrepresentatives as $val)
690  {
691  $userstatic->id=$val['id'];
692  $userstatic->lastname=$val['lastname'];
693  $userstatic->firstname=$val['firstname'];
694  $userstatic->email=$val['email'];
695  $userstatic->statut=$val['statut'];
696  $userstatic->entity=$val['entity'];
697  $userstatic->photo=$val['photo'];
698 
699  //print '<div class="float">':
700  print $userstatic->getNomUrl(-2);
701  $j++;
702  if ($j < $nbofsalesrepresentative) print ' ';
703  //print '</div>';
704  }
705  }
706  //else print $langs->trans("NoSalesRepresentativeAffected");
707  }
708  else
709  {
710  print '&nbsp';
711  }
712  print '</td>';
713  }
714  // Date
715  if (! empty($arrayfields['c.date_contrat']['checked']))
716  {
717  print '<td align="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzuser').'</td>';
718  }
719  // Extra fields
720  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
721  // Fields from hook
722  $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
723  $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
724  print $hookmanager->resPrint;
725  // Date creation
726  if (! empty($arrayfields['c.datec']['checked']))
727  {
728  print '<td align="center" class="nowrap">';
729  print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
730  print '</td>';
731  if (! $i) $totalarray['nbfield']++;
732  }
733  // Date modification
734  if (! empty($arrayfields['c.tms']['checked']))
735  {
736  print '<td align="center" class="nowrap">';
737  print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
738  print '</td>';
739  if (! $i) $totalarray['nbfield']++;
740  }
741  // Date lower end date
742  if (! empty($arrayfields['lower_planned_end_date']['checked']))
743  {
744  print '<td align="center" class="nowrap">';
745  print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
746  print '</td>';
747  if (! $i) $totalarray['nbfield']++;
748  }
749  // Status
750  if (! empty($arrayfields['status']['checked']))
751  {
752  print '<td align="center">'.($obj->nb_initial>0?$obj->nb_initial:'').'</td>';
753  print '<td align="center">'.($obj->nb_running>0?$obj->nb_running:'').'</td>';
754  print '<td align="center">'.($obj->nb_expired>0?$obj->nb_expired:'').'</td>';
755  print '<td align="center">'.($obj->nb_closed>0 ?$obj->nb_closed:'').'</td>';
756  }
757  // Action column
758  print '<td class="nowrap" align="center">';
759  if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
760  {
761  $selected=0;
762  if (in_array($obj->rowid, $arrayofselected)) $selected=1;
763  print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
764  }
765  print '</td>';
766  if (! $i) $totalarray['nbfield']++;
767 
768  print "</tr>\n";
769  $i++;
770  }
771  $db->free($resql);
772 
773  print '</table>';
774  print '</div>';
775 
776  print '</form>';
777 
778  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files)
779  {
780  /*
781  * Show list of available documents
782  */
783  $urlsource=$_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
784  $urlsource.=str_replace('&amp;','&',$param);
785 
786  $filedir=$diroutputmassaction;
787  $genallowed=$user->rights->contrat->lire;
788  $delallowed=$user->rights->contrat->lire;
789 
790  print $formfile->showdocuments('massfilesarea_contract','',$filedir,$urlsource,0,$delallowed,'',1,1,0,48,1,$param,$title,'');
791  }
792  else
793  {
794  print '<br><a name="show_files"></a><a href="'.$_SERVER["PHP_SELF"].'?show_files=1'.$param.'#show_files">'.$langs->trans("ShowTempMassFilesArea").'</a>';
795  }
796 }
797 else
798 {
799  dol_print_error($db);
800 }
801 
802 
803 llxFooter();
804 $db->close();
llxFooter()
Empty footer.
Definition: wrapper.php:58
img_picto($titlealt, $picto, $moreatt= '', $pictoisfullpath=false, $srconly=0, $notitle=0, $alt='', $morecss='')
Show picto whatever it's its name (generic function)
setEventMessages($mesg, $mesgs, $style='mesgs')
Set event messages in dol_events session object.
if(!GETPOST('transkey')&&!GETPOST('transphrase')) else
View.
Definition: notice.php:43
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm=false, $check=1)
Return a timestamp date built from detailed informations (by default a local PHP server timestamp) Re...
dol_sanitizeFileName($str, $newstr='_', $unaccent=1)
Clean a string to use it as a file name.
if(GETPOST('cancel','alpha')) if(!GETPOST('confirmmassaction','alpha')&&$massaction!= 'presend'&&$massaction!= 'confirm_presend')
Draft customers invoices.
Definition: list.php:147
Class to manage Dolibarr users.
Definition: user.class.php:39
Class to manage contracts.
dol_get_first_day($year, $month=1, $gm=false)
Return GMT time for first day of a month or year.
Definition: date.lib.php:445
dol_print_error($db='', $error='', $errors=null)
Affiche message erreur system avec toutes les informations pour faciliter le diagnostic et la remonte...
Classe permettant la gestion des lignes de contrats.
getCountry($searchkey, $withcode='', $dbtouse=0, $outputlangs='', $entconv=1, $searchlabel='')
Return country label, code or id from an id, code or label.
if(empty($reshook)) $form
View.
Definition: perms.php:103
GETPOST($paramname, $check='none', $method=0, $filter=NULL, $options=NULL, $noreplace=0)
Return value of a param into GET or POST supervariable.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
print_barre_liste($titre, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='title_generic.png', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0)
Print a title with navigation controls for pagination.
Class to manage third parties objects (customers, suppliers, prospects...)
img_warning($titlealt= 'default', $moreatt= '')
Show warning logo.
if($_POST["cancel"]==$langs->trans("Cancel")&&!$id) if($action== 'setdatev'&&$user->rights->tax->charges->creer) if($action== 'add'&&$_POST["cancel"]<> $langs->trans("Cancel")) if($action== 'delete') $title
Actions.
Definition: card.php:183
Classe permettant la generation de composants html autre Only common components are here...
llxHeader()
Empty header.
Definition: wrapper.php:46
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='gmt')
Return date for now.
Class to offer components to list and upload files.
dol_print_date($time, $format='', $tzoutput='tzserver', $outputlangs='', $encodetooutput=false)
Output date in a string format according to outputlangs (or langs if not defined).
dol_get_last_day($year, $month=12, $gm=false)
Return GMT time for last day of a month or year.
Definition: date.lib.php:459
print
Draft customers invoices.
Definition: index.php:91
if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) if(!empty($conf->don->enabled)&&$user->rights->societe->lire) if(!empty($conf->tax->enabled)&&$user->rights->tax->charges->lire) if(!empty($conf->facture->enabled)&&!empty($conf->commande->enabled)&&$user->rights->commande->lire &&empty($conf->global->WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER)) if(!empty($conf->facture->enabled)&&$user->rights->facture->lire) if(!empty($conf->fournisseur->enabled)&&$user->rights->fournisseur->facture->lire) $resql
Social contributions to pay.
Definition: index.php:1013
print_liste_field_titre($name, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $tooltip="")
Show title line of an array.
restrictedArea($user, $features, $objectid=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $objcanvas=null)
Check permissions of a user to show a page and an object.