list.php 60 KB

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