services.php 29 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680
  1. <?php
  2. /* Copyright (C) 2001-2004 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@capnetworks.com>
  5. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  6. *
  7. * This program is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published by
  9. * the Free Software Foundation; either version 3 of the License, or
  10. * (at your option) any later version.
  11. *
  12. * This program is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  15. * GNU General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  19. */
  20. /**
  21. * \file htdocs/contrat/services.php
  22. * \ingroup contrat
  23. * \brief Page to list services in contracts
  24. */
  25. require ("../main.inc.php");
  26. require_once (DOL_DOCUMENT_ROOT."/contrat/class/contrat.class.php");
  27. require_once (DOL_DOCUMENT_ROOT."/product/class/product.class.php");
  28. require_once (DOL_DOCUMENT_ROOT."/societe/class/societe.class.php");
  29. $langs->load("products");
  30. $langs->load("contracts");
  31. $langs->load("companies");
  32. $limit = GETPOST("limit")?GETPOST("limit","int"):$conf->liste_limit;
  33. $sortfield = GETPOST("sortfield",'alpha');
  34. $sortorder = GETPOST("sortorder",'alpha');
  35. $page = GETPOST("page",'int');
  36. if (empty($page) || $page == -1) { $page = 0; } // If $page is not defined, or '' or -1
  37. $offset = $limit * $page;
  38. $pageprev = $page - 1;
  39. $pagenext = $page + 1;
  40. if (! $sortfield) $sortfield="c.rowid";
  41. if (! $sortorder) $sortorder="ASC";
  42. $mode = GETPOST("mode");
  43. $filter=GETPOST("filter");
  44. $search_name=GETPOST("search_name");
  45. $search_contract=GETPOST("search_contract");
  46. $search_service=GETPOST("search_service");
  47. $search_status=GETPOST("search_status","alpha");
  48. $statut=GETPOST('statut')?GETPOST('statut'):1;
  49. $search_product_category=GETPOST('search_product_category','int');
  50. $socid=GETPOST('socid','int');
  51. $opouvertureprevuemonth=GETPOST('opouvertureprevuemonth');
  52. $opouvertureprevueday=GETPOST('opouvertureprevueday');
  53. $opouvertureprevueyear=GETPOST('opouvertureprevueyear');
  54. $filter_opouvertureprevue=GETPOST('filter_opouvertureprevue');
  55. $op1month=GETPOST('op1month');
  56. $op1day=GETPOST('op1day');
  57. $op1year=GETPOST('op1year');
  58. $filter_op1=GETPOST('filter_op1');
  59. $op2month=GETPOST('op2month');
  60. $op2day=GETPOST('op2day');
  61. $op2year=GETPOST('op2year');
  62. $filter_op2=GETPOST('filter_op2');
  63. $opcloturemonth=GETPOST('opcloturemonth');
  64. $opclotureday=GETPOST('opclotureday');
  65. $opclotureyear=GETPOST('opclotureyear');
  66. $filter_opcloture=GETPOST('filter_opcloture');
  67. // Initialize context for list
  68. $contextpage=GETPOST('contextpage','aZ')?GETPOST('contextpage','aZ'):'servicelist'.$mode;
  69. // Initialize technical object to manage hooks of thirdparties. Note that conf->hooks_modules contains array array
  70. $hookmanager->initHooks(array($contextpage));
  71. $extrafields = new ExtraFields($db);
  72. // fetch optionals attributes and labels
  73. $extralabels = $extrafields->fetch_name_optionals_label('contratdet');
  74. $search_array_options=$extrafields->getOptionalsFromPost($extralabels,'','search_');
  75. // Security check
  76. $contratid = GETPOST('id','int');
  77. if (! empty($user->societe_id)) $socid=$user->societe_id;
  78. $result = restrictedArea($user, 'contrat',$contratid);
  79. if ($search_status != '')
  80. {
  81. $tmp=explode('&', $search_status);
  82. $mode=$tmp[0];
  83. if (empty($tmp[1])) $filter='';
  84. else
  85. {
  86. if ($tmp[1] == 'filter=notexpired') $filter='notexpired';
  87. if ($tmp[1] == 'filter=expired') $filter='expired';
  88. }
  89. }
  90. else
  91. {
  92. $search_status = $mode;
  93. if ($filter == 'expired') $search_status.='&filter=expired';
  94. if ($filter == 'notexpired') $search_status.='&filter=notexpired';
  95. }
  96. $staticcontrat=new Contrat($db);
  97. $staticcontratligne=new ContratLigne($db);
  98. $companystatic=new Societe($db);
  99. $arrayfields=array(
  100. 'c.ref'=>array('label'=>$langs->trans("Contract"), 'checked'=>1, 'position'=>80),
  101. 'p.description'=>array('label'=>$langs->trans("Service"), 'checked'=>1, 'position'=>80),
  102. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>100),
  103. 'cd.date_ouverture_prevue'=>array('label'=>$langs->trans("DateStartPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode == "0")),
  104. 'cd.date_ouverture'=>array('label'=>$langs->trans("DateStartRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode > 0)),
  105. 'cd.date_fin_validite'=>array('label'=>$langs->trans("DateEndPlannedShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode < 5)),
  106. 'cd.date_cloture'=>array('label'=>$langs->trans("DateEndRealShort"), 'checked'=>(($mode == "" || $mode == -1) || $mode >= 5)),
  107. 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1),
  108. //'cd.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  109. 'cd.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500)
  110. );
  111. // Extra fields
  112. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  113. {
  114. foreach($extrafields->attribute_label as $key => $val)
  115. {
  116. $arrayfields["ef.".$key]=array('label'=>$extrafields->attribute_label[$key], 'checked'=>$extrafields->attribute_list[$key], 'position'=>$extrafields->attribute_pos[$key], 'enabled'=>$extrafields->attribute_perms[$key]);
  117. }
  118. }
  119. /*
  120. * Actions
  121. */
  122. if (GETPOST('cancel')) { $action='list'; $massaction=''; }
  123. if (! GETPOST('confirmmassaction') && $massaction != 'presend' && $massaction != 'confirm_presend' && $massaction != 'confirm_createbills') { $massaction=''; }
  124. $parameters=array('socid'=>$socid);
  125. $reshook=$hookmanager->executeHooks('doActions',$parameters,$object,$action); // Note that $action and $object may have been modified by some hooks
  126. if ($reshook < 0) setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  127. if (empty($reshook))
  128. {
  129. // Selection of new fields
  130. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  131. if (GETPOST("button_removefilter_x") || GETPOST("button_removefilter.x") || GETPOST("button_removefilter")) // All test are required to be compatible with all browsers
  132. {
  133. $search_name="";
  134. $search_contract="";
  135. $search_service="";
  136. $search_status=-1;
  137. $opouvertureprevuemonth="";
  138. $opouvertureprevueday="";
  139. $opouvertureprevueyear="";
  140. $filter_opouvertureprevue="";
  141. $op1month="";
  142. $op1day="";
  143. $op1year="";
  144. $filter_op1="";
  145. $op2month="";
  146. $op2day="";
  147. $op2year="";
  148. $filter_op2="";
  149. $opcloturemonth="";
  150. $opclotureday="";
  151. $opclotureyear="";
  152. $filter_opcloture="";
  153. $mode='';
  154. $filter='';
  155. }
  156. }
  157. /*
  158. * View
  159. */
  160. $now=dol_now();
  161. $form=new Form($db);
  162. $sql = "SELECT c.rowid as cid, c.ref, c.statut as cstatut,";
  163. $sql.= " s.rowid as socid, s.nom as name,";
  164. $sql.= " cd.rowid, cd.description, cd.statut,";
  165. $sql.= " p.rowid as pid, p.ref as pref, p.label as label, p.fk_product_type as ptype, p.entity as pentity,";
  166. if (!$user->rights->societe->client->voir && !$socid) $sql .= " sc.fk_soc, sc.fk_user,";
  167. $sql.= " cd.date_ouverture_prevue,";
  168. $sql.= " cd.date_ouverture,";
  169. $sql.= " cd.date_fin_validite,";
  170. $sql.= " cd.date_cloture,";
  171. //$sql.= " cd.date_c as date_creation,";
  172. $sql.= " cd.tms as date_update";
  173. // Add fields from extrafields
  174. foreach ($extrafields->attribute_label as $key => $val) $sql.=($extrafields->attribute_type[$key] != 'separate' ? ",ef.".$key.' as options_'.$key : '');
  175. // Add fields from hooks
  176. $parameters=array();
  177. $reshook=$hookmanager->executeHooks('printFieldListSelect',$parameters); // Note that $action and $object may have been modified by hook
  178. $sql.=$hookmanager->resPrint;
  179. $sql.= " FROM ".MAIN_DB_PREFIX."contrat as c,";
  180. $sql.= " ".MAIN_DB_PREFIX."societe as s,";
  181. if (!$user->rights->societe->client->voir && !$socid) $sql .= " ".MAIN_DB_PREFIX."societe_commerciaux as sc,";
  182. $sql.= " ".MAIN_DB_PREFIX."contratdet as cd";
  183. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label)) $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet_extrafields as ef on (cd.rowid = ef.fk_object)";
  184. $sql.= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON cd.fk_product = p.rowid";
  185. if ($search_product_category > 0) $sql.= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
  186. $sql.= " WHERE c.entity = ".$conf->entity;
  187. $sql.= " AND c.rowid = cd.fk_contrat";
  188. if ($search_product_category > 0) $sql.=" AND cp.fk_categorie = ".$search_product_category;
  189. $sql.= " AND c.fk_soc = s.rowid";
  190. if (!$user->rights->societe->client->voir && !$socid) $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = " .$user->id;
  191. if ($mode == "0") $sql.= " AND cd.statut = 0";
  192. if ($mode == "4") $sql.= " AND cd.statut = 4";
  193. if ($mode == "5") $sql.= " AND cd.statut = 5";
  194. if ($filter == "expired") $sql.= " AND cd.date_fin_validite < '".$db->idate($now)."'";
  195. if ($filter == "notexpired") $sql.= " AND cd.date_fin_validite >= '".$db->idate($now)."'";
  196. if ($search_name) $sql.= " AND s.nom LIKE '%".$db->escape($search_name)."%'";
  197. if ($search_contract) $sql.= " AND c.rowid = '".$db->escape($search_contract)."'";
  198. if ($search_service) $sql.= " AND (p.ref LIKE '%".$db->escape($search_service)."%' OR p.description LIKE '%".$db->escape($search_service)."%' OR cd.description LIKE '%".$db->escape($search_service)."%')";
  199. if ($socid > 0) $sql.= " AND s.rowid = ".$socid;
  200. $filter_dateouvertureprevue=dol_mktime(0,0,0,$opouvertureprevuemonth,$opouvertureprevueday,$opouvertureprevueyear);
  201. $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year);
  202. $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year);
  203. $filter_datecloture=dol_mktime(0,0,0,$opcloturemonth,$opclotureday,$opclotureyear);
  204. if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1 && $filter_dateouvertureprevue != '') $sql.= " AND cd.date_ouverture_prevue ".$filter_opouvertureprevue." '".$db->idate($filter_dateouvertureprevue)."'";
  205. if (! empty($filter_op1) && $filter_op1 != -1 && $filter_date1 != '') $sql.= " AND cd.date_ouverture ".$filter_op1." '".$db->idate($filter_date1)."'";
  206. if (! empty($filter_op2) && $filter_op2 != -1 && $filter_date2 != '') $sql.= " AND cd.date_fin_validite ".$filter_op2." '".$db->idate($filter_date2)."'";
  207. if (! empty($filter_opcloture) && $filter_opcloture != -1 && $filter_datecloture != '') $sql.= " AND cd.date_cloture ".$filter_opcloture." '".$db->idate($filter_datecloture)."'";
  208. $sql .= $db->order($sortfield,$sortorder);
  209. $nbtotalofrecords = '';
  210. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST))
  211. {
  212. $result = $db->query($sql);
  213. $nbtotalofrecords = $db->num_rows($result);
  214. }
  215. $sql .= $db->plimit($limit + 1, $offset);
  216. //print $sql;
  217. dol_syslog("contrat/services.php", LOG_DEBUG);
  218. $resql=$db->query($sql);
  219. if (! $resql)
  220. {
  221. dol_print_error($db);
  222. exit;
  223. }
  224. $num = $db->num_rows($resql);
  225. /*
  226. if ($num == 1 && ! empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all)
  227. {
  228. $obj = $db->fetch_object($resql);
  229. $id = $obj->id;
  230. header("Location: ".DOL_URL_ROOT.'/projet/tasks/task.php?id='.$id.'&withprojet=1');
  231. exit;
  232. }*/
  233. llxHeader(null, $langs->trans("Services"));
  234. $param='';
  235. if (! empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) $param.='&contextpage='.$contextpage;
  236. if ($limit > 0 && $limit != $conf->liste_limit) $param.='&limit='.$limit;
  237. if ($search_contract) $param.='&amp;search_contract='.urlencode($search_contract);
  238. if ($search_name) $param.='&amp;search_name='.urlencode($search_name);
  239. if ($search_service) $param.='&amp;search_service='.urlencode($search_service);
  240. if ($mode) $param.='&amp;mode='.urlencode($mode);
  241. if ($filter) $param.='&amp;filter='.urlencode($filter);
  242. if (! empty($filter_opouvertureprevue) && $filter_opouvertureprevue != -1) $param.='&amp;filter_opouvertureprevue='.urlencode($filter_opouvertureprevue);
  243. if (! empty($filter_op1) && $filter_op1 != -1) $param.='&amp;filter_op1='.urlencode($filter_op1);
  244. if (! empty($filter_op2) && $filter_op2 != -1) $param.='&amp;filter_op2='.urlencode($filter_op2);
  245. if (! empty($filter_opcloture) && $filter_opcloture != -1) $param.='&amp;filter_opcloture='.urlencode($filter_opcloture);
  246. if ($filter_dateouvertureprevue != '') $param.='&amp;opouvertureprevueday='.$opouvertureprevueday.'&amp;opouvertureprevuemonth='.$opouvertureprevuemonth.'&amp;opouvertureprevueyear='.$opouvertureprevueyear;
  247. if ($filter_date1 != '') $param.='&amp;op1day='.$op1day.'&amp;op1month='.$op1month.'&amp;op1year='.$op1year;
  248. if ($filter_date2 != '') $param.='&amp;op2day='.$op2day.'&amp;op2month='.$op2month.'&amp;op2year='.$op2year;
  249. if ($filter_datecloture != '') $param.='&amp;opclotureday='.$op2day.'&amp;opcloturemonth='.$op2month.'&amp;opclotureyear='.$op2year;
  250. if ($optioncss != '') $param.='&optioncss='.$optioncss;
  251. // Add $param from extra fields
  252. foreach ($search_array_options as $key => $val)
  253. {
  254. $crit=$val;
  255. $tmpkey=preg_replace('/search_options_/','',$key);
  256. if ($val != '') $param.='&search_options_'.$tmpkey.'='.urlencode($val);
  257. }
  258. // List of mass actions available
  259. $arrayofmassactions = array(
  260. //'presend'=>$langs->trans("SendByMail"),
  261. //'builddoc'=>$langs->trans("PDFMerge"),
  262. );
  263. //if ($user->rights->contrat->supprimer) $arrayofmassactions['delete']=$langs->trans("Delete");
  264. //if ($massaction == 'presend') $arrayofmassactions=array();
  265. $massactionbutton=$form->selectMassAction('', $arrayofmassactions);
  266. print '<form method="POST" action="'. $_SERVER["PHP_SELF"] .'">';
  267. if ($optioncss != '') print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  268. print '<input type="hidden" name="token" value="'.$_SESSION['newtoken'].'">';
  269. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  270. print '<input type="hidden" name="action" value="list">';
  271. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  272. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  273. print '<input type="hidden" name="page" value="'.$page.'">';
  274. $title=$langs->trans("ListOfServices");
  275. if ($mode == "0") $title=$langs->trans("ListOfInactiveServices"); // Must use == "0"
  276. if ($mode == "4" && $filter != "expired") $title=$langs->trans("ListOfRunningServices");
  277. if ($mode == "4" && $filter == "expired") $title=$langs->trans("ListOfExpiredServices");
  278. if ($mode == "5") $title=$langs->trans("ListOfClosedServices");
  279. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'title_commercial.png', 0, '', '', $limit);
  280. if ($sall)
  281. {
  282. foreach($fieldstosearchall as $key => $val) $fieldstosearchall[$key]=$langs->trans($val);
  283. print $langs->trans("FilterOnInto", $sall) . join(', ',$fieldstosearchall);
  284. }
  285. $morefilter = '';
  286. // If the user can view categories of products
  287. if ($conf->categorie->enabled && ($user->rights->produit->lire || $user->rights->service->lire))
  288. {
  289. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  290. $moreforfilter.='<div class="divsearchfield">';
  291. $moreforfilter.=$langs->trans('IncludingProductWithTag'). ': ';
  292. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  293. $moreforfilter.=$form->selectarray('search_product_category', $cate_arbo, $search_product_category, 1, 0, 0, '', 0, 0, 0, 0, '', 1);
  294. $moreforfilter.='</div>';
  295. }
  296. $parameters=array();
  297. $reshook=$hookmanager->executeHooks('printFieldPreListTitle',$parameters); // Note that $action and $object may have been modified by hook
  298. if (empty($reshook)) $moreforfilter .= $hookmanager->resPrint;
  299. else $moreforfilter = $hookmanager->resPrint;
  300. if (! empty($moreforfilter))
  301. {
  302. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  303. print $moreforfilter;
  304. print '</div>';
  305. }
  306. $varpage=empty($contextpage)?$_SERVER["PHP_SELF"]:$contextpage;
  307. $selectedfields=$form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  308. print '<div class="div-table-responsive">';
  309. print '<table class="tagtable liste'.($moreforfilter?" listwithfilterbefore":"").'">'."\n";
  310. print '<tr class="liste_titre">';
  311. if (! empty($arrayfields['c.ref']['checked'])) print_liste_field_titre($arrayfields['c.ref']['label'],$_SERVER["PHP_SELF"],"c.ref","",$param,"",$sortfield,$sortorder);
  312. if (! empty($arrayfields['p.description']['checked'])) print_liste_field_titre($arrayfields['p.description']['label'],$_SERVER["PHP_SELF"],"p.description","",$param,"",$sortfield,$sortorder);
  313. if (! empty($arrayfields['s.nom']['checked'])) print_liste_field_titre($arrayfields['s.nom']['label'],$_SERVER["PHP_SELF"],"s.nom","",$param,"",$sortfield,$sortorder);
  314. if (! empty($arrayfields['cd.date_ouverture_prevue']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture_prevue']['label'],$_SERVER["PHP_SELF"],"cd.date_ouverture_prevue","",$param,'align="center"',$sortfield,$sortorder);
  315. if (! empty($arrayfields['cd.date_ouverture']['checked'])) print_liste_field_titre($arrayfields['cd.date_ouverture']['label'],$_SERVER["PHP_SELF"],"cd.date_ouverture","",$param,'align="center"',$sortfield,$sortorder);
  316. if (! empty($arrayfields['cd.date_fin_validite']['checked'])) print_liste_field_titre($arrayfields['cd.date_fin_validite']['label'],$_SERVER["PHP_SELF"],"cd.date_fin_validite","",$param,'align="center"',$sortfield,$sortorder);
  317. if (! empty($arrayfields['cd.date_cloture']['checked'])) print_liste_field_titre($arrayfields['cd.date_cloture']['label'],$_SERVER["PHP_SELF"],"cd.date_cloture","",$param,'align="center"',$sortfield,$sortorder);
  318. // Extra fields
  319. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  320. {
  321. foreach($extrafields->attribute_label as $key => $val)
  322. {
  323. if (! empty($arrayfields["ef.".$key]['checked']))
  324. {
  325. $align=$extrafields->getAlignFlag($key);
  326. print_liste_field_titre($langs->trans($extralabels[$key]),$_SERVER["PHP_SELF"],"ef.".$key,"",$param,($align?'align="'.$align.'"':''),$sortfield,$sortorder);
  327. }
  328. }
  329. }
  330. // Hook fields
  331. $parameters=array('arrayfields'=>$arrayfields);
  332. $reshook=$hookmanager->executeHooks('printFieldListTitle',$parameters); // Note that $action and $object may have been modified by hook
  333. print $hookmanager->resPrint;
  334. if (! empty($arrayfields['cd.datec']['checked'])) print_liste_field_titre($arrayfields['cd.datec']['label'],$_SERVER["PHP_SELF"],"cd.datec","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  335. if (! empty($arrayfields['cd.tms']['checked'])) print_liste_field_titre($arrayfields['cd.tms']['label'],$_SERVER["PHP_SELF"],"cd.tms","",$param,'align="center" class="nowrap"',$sortfield,$sortorder);
  336. if (! empty($arrayfields['status']['checked'])) print_liste_field_titre($arrayfields['status']['label'],$_SERVER["PHP_SELF"],"cd.statut,c.statut","",$param,'align="right"',$sortfield,$sortorder);
  337. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"],"",'','','align="center"',$sortfield,$sortorder,'maxwidthsearch ');
  338. print "</tr>\n";
  339. print '<tr class="liste_titre">';
  340. if (! empty($arrayfields['c.ref']['checked']))
  341. {
  342. print '<td class="liste_titre">';
  343. print '<input type="hidden" name="filter" value="'.$filter.'">';
  344. print '<input type="hidden" name="mode" value="'.$mode.'">';
  345. print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  346. print '</td>';
  347. }
  348. // Service label
  349. if (! empty($arrayfields['p.description']['checked']))
  350. {
  351. print '<td class="liste_titre">';
  352. print '<input type="text" class="flat maxwidth100" name="search_service" value="'.dol_escape_htmltag($search_service).'">';
  353. print '</td>';
  354. }
  355. // Third party
  356. if (! empty($arrayfields['s.nom']['checked']))
  357. {
  358. print '<td class="liste_titre">';
  359. print '<input type="text" class="flat maxwidth100" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
  360. print '</td>';
  361. }
  362. if (! empty($arrayfields['cd.date_ouverture_prevue']['checked']))
  363. {
  364. print '<td class="liste_titre" align="center">';
  365. $arrayofoperators=array('<'=>'<','>'=>'>');
  366. print $form->selectarray('filter_opouvertureprevue',$arrayofoperators,$filter_opouvertureprevue,1);
  367. print ' ';
  368. $filter_dateouvertureprevue=dol_mktime(0,0,0,$opouvertureprevuemonth,$opouvertureprevueday,$opouvertureprevueyear);
  369. print $form->select_date($filter_dateouvertureprevue,'opouvertureprevue',0,0,1,'',1,0,1);
  370. print '</td>';
  371. }
  372. if (! empty($arrayfields['cd.date_ouverture']['checked']))
  373. {
  374. print '<td class="liste_titre" align="center">';
  375. $arrayofoperators=array('<'=>'<','>'=>'>');
  376. print $form->selectarray('filter_op1',$arrayofoperators,$filter_op1,1);
  377. print ' ';
  378. $filter_date1=dol_mktime(0,0,0,$op1month,$op1day,$op1year);
  379. print $form->select_date($filter_date1,'op1',0,0,1,'',1,0,1);
  380. print '</td>';
  381. }
  382. if (! empty($arrayfields['cd.date_fin_validite']['checked']))
  383. {
  384. print '<td class="liste_titre" align="center">';
  385. $arrayofoperators=array('<'=>'<','>'=>'>');
  386. print $form->selectarray('filter_op2',$arrayofoperators,$filter_op2,1);
  387. print ' ';
  388. $filter_date2=dol_mktime(0,0,0,$op2month,$op2day,$op2year);
  389. print $form->select_date($filter_date2,'op2',0,0,1,'',1,0,1);
  390. print '</td>';
  391. }
  392. if (! empty($arrayfields['cd.date_cloture']['checked']))
  393. {
  394. print '<td class="liste_titre" align="center">';
  395. $arrayofoperators=array('<'=>'<','>'=>'>');
  396. print $form->selectarray('filter_opcloture',$arrayofoperators,$filter_opcloture,1);
  397. print ' ';
  398. $filter_date_cloture=dol_mktime(0,0,0,$opcloturemonth,$opclotureday,$opclotureyear);
  399. print $form->select_date($filter_date_cloture,'opcloture',0,0,1,'',1,0,1);
  400. print '</td>';
  401. }
  402. // Extra fields
  403. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  404. {
  405. foreach($extrafields->attribute_label as $key => $val)
  406. {
  407. if (! empty($arrayfields["ef.".$key]['checked']))
  408. {
  409. $align=$extrafields->getAlignFlag($key);
  410. $typeofextrafield=$extrafields->attribute_type[$key];
  411. print '<td class="liste_titre'.($align?' '.$align:'').'">';
  412. if (in_array($typeofextrafield, array('varchar', 'int', 'double', 'select')))
  413. {
  414. $crit=$val;
  415. $tmpkey=preg_replace('/search_options_/','',$key);
  416. $searchclass='';
  417. if (in_array($typeofextrafield, array('varchar', 'select'))) $searchclass='searchstring';
  418. if (in_array($typeofextrafield, array('int', 'double'))) $searchclass='searchnum';
  419. print '<input class="flat'.($searchclass?' '.$searchclass:'').'" size="4" type="text" name="search_options_'.$tmpkey.'" value="'.dol_escape_htmltag($search_array_options['search_options_'.$tmpkey]).'">';
  420. }
  421. print '</td>';
  422. }
  423. }
  424. }
  425. // Fields from hook
  426. $parameters=array('arrayfields'=>$arrayfields);
  427. $reshook=$hookmanager->executeHooks('printFieldListOption',$parameters); // Note that $action and $object may have been modified by hook
  428. print $hookmanager->resPrint;
  429. if (! empty($arrayfields['cd.datec']['checked']))
  430. {
  431. // Date creation
  432. print '<td class="liste_titre">';
  433. print '</td>';
  434. }
  435. if (! empty($arrayfields['cd.tms']['checked']))
  436. {
  437. // Date modification
  438. print '<td class="liste_titre">';
  439. print '</td>';
  440. }
  441. if (! empty($arrayfields['status']['checked']))
  442. {
  443. // Status
  444. print '<td class="liste_titre" align="right">';
  445. $arrayofstatus=array(
  446. '0'=>$langs->trans("ServiceStatusInitial"),
  447. '4'=>$langs->trans("ServiceStatusRunning"),
  448. '4&filter=notexpired'=>$langs->trans("ServiceStatusNotLate"),
  449. '4&filter=expired'=>$langs->trans("ServiceStatusLate"),
  450. '5'=>$langs->trans("ServiceStatusClosed")
  451. );
  452. print $form->selectarray('search_status', $arrayofstatus, (strstr($search_status, ',')?-1:$search_status), 1, 0, '', 0, 0, 0, '', 'maxwidth100onsmartphone');
  453. print '</td>';
  454. }
  455. // Action column
  456. print '<td class="liste_titre" align="right">';
  457. $searchpicto=$form->showFilterAndCheckAddButtons(0);
  458. print $searchpicto;
  459. print '</td>';
  460. print "</tr>\n";
  461. $contractstatic=new Contrat($db);
  462. $productstatic=new Product($db);
  463. $var=True; $i=0;
  464. while ($i < min($num,$limit))
  465. {
  466. $obj = $db->fetch_object($resql);
  467. $contractstatic->id=$obj->cid;
  468. $contractstatic->ref=$obj->ref?$obj->ref:$obj->cid;
  469. print '<tr class="oddeven">';
  470. // Ref
  471. if (! empty($arrayfields['c.ref']['checked']))
  472. {
  473. print '<td>';
  474. print $contractstatic->getNomUrl(1,16);
  475. print '</td>';
  476. }
  477. // Service
  478. if (! empty($arrayfields['p.description']['checked']))
  479. {
  480. print '<td>';
  481. if ($obj->pid)
  482. {
  483. $productstatic->id=$obj->pid;
  484. $productstatic->type=$obj->ptype;
  485. $productstatic->ref=$obj->pref;
  486. $productstatic->entity=$obj->pentity;
  487. print $productstatic->getNomUrl(1,'',24);
  488. print $obj->label?' - '.dol_trunc($obj->label,16):'';
  489. if (! empty($obj->description) && ! empty($conf->global->PRODUCT_DESC_IN_LIST)) print '<br>'.dol_nl2br($obj->description);
  490. }
  491. else
  492. {
  493. if ($obj->type == 0) print img_object($obj->description,'product').' '.dol_trunc($obj->description,24);
  494. if ($obj->type == 1) print img_object($obj->description,'service').' '.dol_trunc($obj->description,24);
  495. }
  496. print '</td>';
  497. }
  498. // Third party
  499. if (! empty($arrayfields['s.nom']['checked']))
  500. {
  501. print '<td>';
  502. $companystatic->id=$obj->socid;
  503. $companystatic->name=$obj->name;
  504. $companystatic->client=1;
  505. print $companystatic->getNomUrl(1,'customer',28);
  506. print '</td>';
  507. }
  508. // Start date
  509. if (! empty($arrayfields['cd.date_ouverture_prevue']['checked']))
  510. {
  511. print '<td align="center">';
  512. print ($obj->date_ouverture_prevue?dol_print_date($db->jdate($obj->date_ouverture_prevue)):'&nbsp;');
  513. if ($db->jdate($obj->date_ouverture_prevue) && ($db->jdate($obj->date_ouverture_prevue) < ($now - $conf->contrat->services->inactifs->warning_delay)) && $obj->statut == 0)
  514. print ' '.img_picto($langs->trans("Late"),"warning");
  515. else print '&nbsp;&nbsp;&nbsp;&nbsp;';
  516. print '</td>';
  517. }
  518. if (! empty($arrayfields['cd.date_ouverture']['checked']))
  519. {
  520. print '<td align="center">'.($obj->date_ouverture?dol_print_date($db->jdate($obj->date_ouverture)):'&nbsp;').'</td>';
  521. }
  522. // End date
  523. if (! empty($arrayfields['cd.date_fin_validite']['checked']))
  524. {
  525. print '<td align="center">'.($obj->date_fin_validite?dol_print_date($db->jdate($obj->date_fin_validite)):'&nbsp;');
  526. if ($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < ($now - $conf->contrat->services->expires->warning_delay) && $obj->statut < 5)
  527. {
  528. $warning_delay=$conf->contrat->services->expires->warning_delay / 3600 / 24;
  529. $textlate = $langs->trans("Late").' = '.$langs->trans("DateReference").' > '.$langs->trans("DateToday").' '.(ceil($warning_delay) >= 0 ? '+' : '').ceil($warning_delay).' '.$langs->trans("days");
  530. print img_warning($textlate);
  531. }
  532. else print '&nbsp;&nbsp;&nbsp;&nbsp;';
  533. print '</td>';
  534. }
  535. if (! empty($arrayfields['cd.date_cloture']['checked']))
  536. {
  537. print '<td align="center">'.dol_print_date($db->jdate($obj->date_cloture)).'</td>';
  538. }
  539. // Extra fields
  540. if (is_array($extrafields->attribute_label) && count($extrafields->attribute_label))
  541. {
  542. foreach($extrafields->attribute_label as $key => $val)
  543. {
  544. if (! empty($arrayfields["ef.".$key]['checked']))
  545. {
  546. print '<td';
  547. $align=$extrafields->getAlignFlag($key);
  548. if ($align) print ' align="'.$align.'"';
  549. print '>';
  550. $tmpkey='options_'.$key;
  551. print $extrafields->showOutputField($key, $obj->$tmpkey, '', 1);
  552. print '</td>';
  553. if (! $i) $totalarray['nbfield']++;
  554. }
  555. }
  556. }
  557. // Fields from hook
  558. $parameters=array('arrayfields'=>$arrayfields, 'obj'=>$obj);
  559. $reshook=$hookmanager->executeHooks('printFieldListValue',$parameters); // Note that $action and $object may have been modified by hook
  560. print $hookmanager->resPrint;
  561. // Date creation
  562. if (! empty($arrayfields['cd.datec']['checked']))
  563. {
  564. print '<td align="center">';
  565. print dol_print_date($db->jdate($obj->date_creation), 'dayhour');
  566. print '</td>';
  567. if (! $i) $totalarray['nbfield']++;
  568. }
  569. // Date modification
  570. if (! empty($arrayfields['cd.tms']['checked']))
  571. {
  572. print '<td align="center">';
  573. print dol_print_date($db->jdate($obj->date_update), 'dayhour');
  574. print '</td>';
  575. if (! $i) $totalarray['nbfield']++;
  576. }
  577. // Status
  578. if (! empty($arrayfields['status']['checked']))
  579. {
  580. print '<td align="right">';
  581. if ($obj->cstatut == 0) // If contract is draft, we say line is also draft
  582. {
  583. print $contractstatic->LibStatut(0,5,($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now));
  584. }
  585. else
  586. {
  587. print $staticcontratligne->LibStatut($obj->statut,5,($obj->date_fin_validite && $db->jdate($obj->date_fin_validite) < $now)?1:0);
  588. }
  589. print '</td>';
  590. }
  591. // Action column
  592. print '<td class="nowrap" align="center">';
  593. if ($massactionbutton || $massaction) // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  594. {
  595. $selected=0;
  596. if (in_array($obj->rowid, $arrayofselected)) $selected=1;
  597. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected?' checked="checked"':'').'>';
  598. }
  599. print '</td>';
  600. if (! $i) $totalarray['nbfield']++;
  601. print "</tr>\n";
  602. $i++;
  603. }
  604. $db->free($resql);
  605. $parameters=array('sql' => $sql);
  606. $reshook=$hookmanager->executeHooks('printFieldListFooter',$parameters); // Note that $action and $object may have been modified by hook
  607. print $hookmanager->resPrint;
  608. print '</table>';
  609. print '</div>';
  610. print '</form>';
  611. llxFooter();
  612. $db->close();