list.php 54 KB

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