list.php 42 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020
  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. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formother.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  36. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  37. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  38. // Load translation files required by the page
  39. $langs->loadLangs(array('contracts', 'products', 'companies', 'compta'));
  40. $action = GETPOST('action', 'aZ09');
  41. $massaction = GETPOST('massaction', 'alpha');
  42. $show_files = GETPOST('show_files', 'int');
  43. $confirm = GETPOST('confirm', 'alpha');
  44. $toselect = GETPOST('toselect', 'array');
  45. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'contractlist'; // To manage different context of search
  46. $search_name = GETPOST('search_name', 'alpha');
  47. $search_email = GETPOST('search_email', 'alpha');
  48. $search_town = GETPOST('search_town', 'alpha');
  49. $search_zip = GETPOST('search_zip', 'alpha');
  50. $search_state = GETPOST("search_state", 'alpha');
  51. $search_country = GETPOST("search_country", 'int');
  52. $search_type_thirdparty = GETPOST("search_type_thirdparty", 'int');
  53. $search_contract = GETPOST('search_contract', 'alpha');
  54. $search_ref_customer = GETPOST('search_ref_customer', 'alpha');
  55. $search_ref_supplier = GETPOST('search_ref_supplier', 'alpha');
  56. $sall = (GETPOST('search_all', 'alphanohtml') != '') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  57. $search_status = GETPOST('search_status', 'alpha');
  58. $socid = GETPOST('socid', 'int');
  59. $search_user = GETPOST('search_user', 'int');
  60. $search_sale = GETPOST('search_sale', 'int');
  61. $search_product_category = GETPOST('search_product_category', 'int');
  62. $search_dfmonth = GETPOST('search_dfmonth', 'int');
  63. $search_dfyear = GETPOST('search_dfyear', 'int');
  64. $search_op2df = GETPOST('search_op2df', 'alpha');
  65. $search_date_startday = GETPOST('search_date_startday', 'int');
  66. $search_date_startmonth = GETPOST('search_date_startmonth', 'int');
  67. $search_date_startyear = GETPOST('search_date_startyear', 'int');
  68. $search_date_endday = GETPOST('search_date_endday', 'int');
  69. $search_date_endmonth = GETPOST('search_date_endmonth', 'int');
  70. $search_date_endyear = GETPOST('search_date_endyear', 'int');
  71. $search_date_start = dol_mktime(0, 0, 0, $search_date_startmonth, $search_date_startday, $search_date_startyear); // Use tzserver
  72. $search_date_end = dol_mktime(23, 59, 59, $search_date_endmonth, $search_date_endday, $search_date_endyear);
  73. $optioncss = GETPOST('optioncss', 'alpha');
  74. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  75. $sortfield = GETPOST('sortfield', 'aZ09comma');
  76. $sortorder = GETPOST('sortorder', 'aZ09comma');
  77. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  78. if (empty($page) || $page == -1) {
  79. $page = 0;
  80. } // If $page is not defined, or '' or -1
  81. $offset = $limit * $page;
  82. $pageprev = $page - 1;
  83. $pagenext = $page + 1;
  84. if (!$sortfield) {
  85. $sortfield = 'c.ref';
  86. }
  87. if (!$sortorder) {
  88. $sortorder = 'DESC';
  89. }
  90. // Security check
  91. $id = GETPOST('id', 'int');
  92. if ($user->socid) {
  93. $socid = $user->socid;
  94. }
  95. $result = restrictedArea($user, 'contrat', $id);
  96. $diroutputmassaction = $conf->contrat->dir_output.'/temp/massgeneration/'.$user->id;
  97. $staticcontrat = new Contrat($db);
  98. $staticcontratligne = new ContratLigne($db);
  99. if ($search_status == '') {
  100. $search_status = 1;
  101. }
  102. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  103. $object = new Contrat($db);
  104. $hookmanager->initHooks(array('contractlist'));
  105. $extrafields = new ExtraFields($db);
  106. // fetch optionals attributes and labels
  107. $extrafields->fetch_name_optionals_label($object->table_element);
  108. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  109. // List of fields to search into when doing a "search in all"
  110. $fieldstosearchall = array(
  111. 'c.ref'=>'Ref',
  112. 'c.ref_customer'=>'RefCustomer',
  113. 'c.ref_supplier'=>'RefSupplier',
  114. 's.nom'=>"ThirdParty",
  115. 'c.note_public'=>'NotePublic',
  116. );
  117. if (empty($user->socid)) {
  118. $fieldstosearchall["c.note_private"] = "NotePrivate";
  119. }
  120. $arrayfields = array(
  121. 'c.ref'=>array('label'=>$langs->trans("Ref"), 'checked'=>1, 'position'=>10),
  122. 'c.ref_customer'=>array('label'=>$langs->trans("RefCustomer"), 'checked'=>1, 'position'=>12),
  123. 'c.ref_supplier'=>array('label'=>$langs->trans("RefSupplier"), 'checked'=>1, 'position'=>14),
  124. 's.nom'=>array('label'=>$langs->trans("ThirdParty"), 'checked'=>1, 'position'=>30),
  125. 's.email'=>array('label'=>$langs->trans("ThirdPartyEmail"), 'checked'=>0, 'position'=>30),
  126. 's.town'=>array('label'=>$langs->trans("Town"), 'checked'=>0, 'position'=>31),
  127. 's.zip'=>array('label'=>$langs->trans("Zip"), 'checked'=>1, 'position'=>32),
  128. 'state.nom'=>array('label'=>$langs->trans("StateShort"), 'checked'=>0, 'position'=>33),
  129. 'country.code_iso'=>array('label'=>$langs->trans("Country"), 'checked'=>0, 'position'=>34),
  130. 'sale_representative'=>array('label'=>$langs->trans("SaleRepresentativesOfThirdParty"), 'checked'=>-1, 'position'=>80),
  131. 'c.date_contrat'=>array('label'=>$langs->trans("DateContract"), 'checked'=>1, 'position'=>45),
  132. 'c.datec'=>array('label'=>$langs->trans("DateCreation"), 'checked'=>0, 'position'=>500),
  133. 'c.tms'=>array('label'=>$langs->trans("DateModificationShort"), 'checked'=>0, 'position'=>500),
  134. 'lower_planned_end_date'=>array('label'=>$langs->trans("LowerDateEndPlannedShort"), 'checked'=>1, 'position'=>900, 'help'=>$langs->trans("LowerDateEndPlannedShort")),
  135. 'status'=>array('label'=>$langs->trans("Status"), 'checked'=>1, 'position'=>1000),
  136. );
  137. // Extra fields
  138. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  139. $object->fields = dol_sort_array($object->fields, 'position');
  140. $arrayfields = dol_sort_array($arrayfields, 'position');
  141. /*
  142. * Action
  143. */
  144. if (GETPOST('cancel', 'alpha')) {
  145. $action = 'list'; $massaction = '';
  146. }
  147. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  148. $massaction = '';
  149. }
  150. $parameters = array('socid'=>$socid);
  151. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  152. if ($reshook < 0) {
  153. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  154. }
  155. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  156. // Purge search criteria
  157. 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
  158. $search_dfmonth = '';
  159. $search_dfyear = '';
  160. $search_op2df = '';
  161. $search_name = "";
  162. $search_email = "";
  163. $search_town = '';
  164. $search_zip = "";
  165. $search_state = "";
  166. $search_type = '';
  167. $search_country = '';
  168. $search_contract = "";
  169. $search_ref_customer = "";
  170. $search_ref_supplier = "";
  171. $search_user = '';
  172. $search_sale = '';
  173. $search_product_category = '';
  174. $search_date_startday = '';
  175. $search_date_startmonth = '';
  176. $search_date_startyear = '';
  177. $search_date_endday = '';
  178. $search_date_endmonth = '';
  179. $search_date_endyear = '';
  180. $search_date_start = '';
  181. $search_date_end = '';
  182. $sall = "";
  183. $search_status = "";
  184. $toselect = array();
  185. $search_type_thirdparty = '';
  186. $search_array_options = array();
  187. }
  188. if (empty($reshook)) {
  189. $objectclass = 'Contrat';
  190. $objectlabel = 'Contracts';
  191. $permissiontoread = $user->rights->contrat->lire;
  192. $permissiontodelete = $user->rights->contrat->supprimer;
  193. $uploaddir = $conf->contrat->dir_output;
  194. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  195. }
  196. /*
  197. * View
  198. */
  199. $now = dol_now();
  200. $form = new Form($db);
  201. $formfile = new FormFile($db);
  202. $formother = new FormOther($db);
  203. $socstatic = new Societe($db);
  204. $formcompany = new FormCompany($db);
  205. $contracttmp = new Contrat($db);
  206. $title = "";
  207. $sql = 'SELECT';
  208. $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,";
  209. $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,';
  210. $sql .= " typent.code as typent_code,";
  211. $sql .= " state.code_departement as state_code, state.nom as state_name,";
  212. $sql .= " MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") as lower_planned_end_date,";
  213. $sql .= " SUM(".$db->ifsql("cd.statut=0", 1, 0).') as nb_initial,';
  214. $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,';
  215. $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,';
  216. $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,';
  217. $sql .= " SUM(".$db->ifsql("cd.statut=5", 1, 0).') as nb_closed';
  218. // Add fields from extrafields
  219. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  220. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  221. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  222. }
  223. }
  224. // Add fields from hooks
  225. $parameters = array();
  226. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  227. $sql .= $hookmanager->resPrint;
  228. $sql .= " FROM ".MAIN_DB_PREFIX."societe as s";
  229. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_country as country on (country.rowid = s.fk_pays)";
  230. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_typent as typent on (typent.id = s.fk_typent)";
  231. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."c_departements as state on (state.rowid = s.fk_departement)";
  232. if ($search_sale > 0 || (empty($user->rights->societe->client->voir) && !$socid)) {
  233. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  234. }
  235. $sql .= ", ".MAIN_DB_PREFIX."contrat as c";
  236. if (!empty($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  237. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (c.rowid = ef.fk_object)";
  238. }
  239. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contratdet as cd ON c.rowid = cd.fk_contrat";
  240. if ($search_product_category > 0) {
  241. $sql .= ' LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product';
  242. }
  243. if ($search_user > 0) {
  244. $sql .= ", ".MAIN_DB_PREFIX."element_contact as ec";
  245. $sql .= ", ".MAIN_DB_PREFIX."c_type_contact as tc";
  246. }
  247. $sql .= " WHERE c.fk_soc = s.rowid ";
  248. $sql .= ' AND c.entity IN ('.getEntity('contract').')';
  249. if ($search_type_thirdparty != '' && $search_type_thirdparty > 0) {
  250. $sql .= " AND s.fk_typent IN (".$db->sanitize($db->escape($search_type_thirdparty)).')';
  251. }
  252. if ($search_product_category > 0) {
  253. $sql .= " AND cp.fk_categorie = ".((int) $search_product_category);
  254. }
  255. if ($socid) {
  256. $sql .= " AND s.rowid = ".((int) $socid);
  257. }
  258. if (empty($user->rights->societe->client->voir) && !$socid) {
  259. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  260. }
  261. if ($search_date_start) {
  262. $sql .= " AND c.date_contrat >= '".$db->idate($search_date_start)."'";
  263. }
  264. if ($search_date_end) {
  265. $sql .= " AND c.date_contrat <= '".$db->idate($search_date_end)."'";
  266. }
  267. if ($search_name) {
  268. $sql .= natural_search('s.nom', $search_name);
  269. }
  270. if ($search_email) {
  271. $sql .= natural_search('s.email', $search_email);
  272. }
  273. if ($search_contract) {
  274. $sql .= natural_search(array('c.rowid', 'c.ref'), $search_contract);
  275. }
  276. if (!empty($search_ref_customer)) {
  277. $sql .= natural_search(array('c.ref_customer'), $search_ref_customer);
  278. }
  279. if (!empty($search_ref_supplier)) {
  280. $sql .= natural_search(array('c.ref_supplier'), $search_ref_supplier);
  281. }
  282. if ($search_zip) {
  283. $sql .= natural_search(array('s.zip'), $search_zip);
  284. }
  285. if ($search_town) {
  286. $sql .= natural_search(array('s.town'), $search_town);
  287. }
  288. if ($search_sale > 0) {
  289. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $search_sale);
  290. }
  291. if ($sall) {
  292. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  293. }
  294. if ($search_user > 0) {
  295. $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);
  296. }
  297. // Add where from extra fields
  298. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  299. // Add where from hooks
  300. $parameters = array();
  301. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  302. $sql .= $hookmanager->resPrint;
  303. $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,";
  304. $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,';
  305. $sql .= " typent.code,";
  306. $sql .= " state.code_departement, state.nom";
  307. // Add fields from extrafields
  308. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  309. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  310. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key : '');
  311. }
  312. }
  313. // Add where from hooks
  314. $parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
  315. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  316. $sql .= $hookmanager->resPrint;
  317. // Add HAVING from hooks
  318. $parameters = array('search_dfyear' => $search_dfyear, 'search_op2df'=>$search_op2df);
  319. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  320. if (empty($reshook)) {
  321. if ($search_dfyear > 0 && $search_op2df) {
  322. if ($search_op2df == '<=') {
  323. $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") <= '".$db->idate(dol_get_last_day($search_dfyear, $search_dfmonth, false))."'";
  324. } elseif ($search_op2df == '>=') {
  325. $sql .= " HAVING MIN(".$db->ifsql("cd.statut=4", "cd.date_fin_validite", "null").") >= '".$db->idate(dol_get_first_day($search_dfyear, $search_dfmonth, false))."'";
  326. } else {
  327. $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))."'";
  328. }
  329. }
  330. }
  331. $sql .= $hookmanager->resPrint;
  332. $nbtotalofrecords = '';
  333. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  334. //$result = $db->query($sql);
  335. //$nbtotalofrecords = $db->num_rows($result);
  336. if ($search_dfyear > 0 && $search_op2df) {
  337. $resql = $db->query($sql, 0, 'auto', 1);
  338. while ($db->fetch_object($resql)) {
  339. if (empty($nbtotalofrecords)) {
  340. $nbtotalofrecords = 1; // We can't make +1 because init value is ''
  341. } else {
  342. $nbtotalofrecords++;
  343. }
  344. }
  345. } else {
  346. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  347. $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'contratdet as cd ON c.rowid = cd.fk_contrat/', '', $sqlforcount);
  348. $sqlforcount = preg_replace('/LEFT JOIN '.MAIN_DB_PREFIX.'categorie_product as cp ON cp.fk_product=cd.fk_product/', '', $sqlforcount);
  349. $sqlforcount = preg_replace('/AND cp.fk_categorie = '.((int) $search_product_category).'/', '', $sqlforcount);
  350. $sqlforcount = preg_replace('/GROUP BY.*$/', '', $sqlforcount);
  351. $resql = $db->query($sqlforcount);
  352. $objforcount = $db->fetch_object($resql);
  353. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  354. }
  355. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  356. $page = 0;
  357. $offset = 0;
  358. }
  359. }
  360. $sql .= $db->order($sortfield, $sortorder);
  361. if ($limit) {
  362. $sql .= $db->plimit($limit + 1, $offset);
  363. }
  364. $resql = $db->query($sql);
  365. if (!$resql) {
  366. dol_print_error($db);
  367. exit;
  368. }
  369. $num = $db->num_rows($resql);
  370. // Direct jump if only one record found
  371. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $sall && !$page) {
  372. $obj = $db->fetch_object($resql);
  373. $id = $obj->rowid;
  374. header("Location: ".DOL_URL_ROOT.'/contrat/card.php?id='.$id);
  375. exit;
  376. }
  377. // Output page
  378. // --------------------------------------------------------------------
  379. llxHeader('', $langs->trans("Contracts"));
  380. $i = 0;
  381. $arrayofselected = is_array($toselect) ? $toselect : array();
  382. if ($socid > 0) {
  383. $soc = new Societe($db);
  384. $soc->fetch($socid);
  385. if (empty($search_name)) {
  386. $search_name = $soc->name;
  387. }
  388. }
  389. $param = '';
  390. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  391. $param .= '&contextpage='.urlencode($contextpage);
  392. }
  393. if ($limit > 0 && $limit != $conf->liste_limit) {
  394. $param .= '&limit='.urlencode($limit);
  395. }
  396. if ($sall != '') {
  397. $param .= '&sall='.urlencode($sall);
  398. }
  399. if ($search_contract != '') {
  400. $param .= '&search_contract='.urlencode($search_contract);
  401. }
  402. if ($search_name != '') {
  403. $param .= '&search_name='.urlencode($search_name);
  404. }
  405. if ($search_email != '') {
  406. $param .= '&search_email='.urlencode($search_email);
  407. }
  408. if ($search_ref_customer != '') {
  409. $param .= '&search_ref_customer='.urlencode($search_ref_customer);
  410. }
  411. if ($search_ref_supplier != '') {
  412. $param .= '&search_ref_supplier='.urlencode($search_ref_supplier);
  413. }
  414. if ($search_op2df != '') {
  415. $param .= '&search_op2df='.urlencode($search_op2df);
  416. }
  417. if ($search_date_startday > 0) {
  418. $param .= '&search_date_startday='.urlencode($search_date_startday);
  419. }
  420. if ($search_date_startmonth > 0) {
  421. $param .= '&search_date_startmonth='.urlencode($search_date_startmonth);
  422. }
  423. if ($search_date_startyear > 0) {
  424. $param .= '&search_date_startyear='.urlencode($search_date_startyear);
  425. }
  426. if ($search_date_endday > 0) {
  427. $param .= '&search_date_endday='.urlencode($search_date_endday);
  428. }
  429. if ($search_date_endmonth > 0) {
  430. $param .= '&search_date_endmonth='.urlencode($search_date_endmonth);
  431. }
  432. if ($search_date_endyear > 0) {
  433. $param .= '&search_date_endyear='.urlencode($search_date_endyear);
  434. }
  435. if ($search_dfyear > 0) {
  436. $param .= '&search_dfyear='.urlencode($search_dfyear);
  437. }
  438. if ($search_dfmonth > 0) {
  439. $param .= '&search_dfmonth='.urlencode($search_dfmonth);
  440. }
  441. if ($search_sale > 0) {
  442. $param .= '&search_sale='.urlencode($search_sale);
  443. }
  444. if ($search_user > 0) {
  445. $param .= '&search_user='.urlencode($search_user);
  446. }
  447. if ($search_type_thirdparty > 0) {
  448. $param .= '&search_type_thirdparty='.urlencode($search_type_thirdparty);
  449. }
  450. if ($search_product_category > 0) {
  451. $param .= '&search_product_category='.urlencode($search_product_category);
  452. }
  453. if ($show_files) {
  454. $param .= '&show_files='.urlencode($show_files);
  455. }
  456. if ($optioncss != '') {
  457. $param .= '&optioncss='.urlencode($optioncss);
  458. }
  459. // Add $param from extra fields
  460. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  461. // List of mass actions available
  462. $arrayofmassactions = array(
  463. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  464. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  465. 'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  466. );
  467. if ($user->rights->contrat->supprimer) {
  468. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  469. }
  470. if (in_array($massaction, array('presend', 'predelete'))) {
  471. $arrayofmassactions = array();
  472. }
  473. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  474. $url = DOL_URL_ROOT.'/contrat/card.php?action=create';
  475. if (!empty($socid)) {
  476. $url .= '&socid='.((int) $socid);
  477. }
  478. $newcardbutton = dolGetButtonTitle($langs->trans('NewContractSubscription'), '', 'fa fa-plus-circle', $url, '', $user->rights->contrat->creer);
  479. print '<form method="POST" action="'.$_SERVER['PHP_SELF'].'">';
  480. if ($optioncss != '') {
  481. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  482. }
  483. print '<input type="hidden" name="token" value="'.newToken().'">';
  484. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  485. print '<input type="hidden" name="action" value="list">';
  486. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  487. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  488. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  489. print_barre_liste($langs->trans("ListOfContracts"), $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'contract', 0, $newcardbutton, '', $limit, 0, 0, 1);
  490. $topicmail = "SendContractRef";
  491. $modelmail = "contract";
  492. $objecttmp = new Contrat($db);
  493. $trackid = 'con'.$object->id;
  494. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  495. if ($sall) {
  496. foreach ($fieldstosearchall as $key => $val) {
  497. $fieldstosearchall[$key] = $langs->trans($val);
  498. }
  499. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  500. }
  501. $moreforfilter = '';
  502. // If the user can view prospects other than his'
  503. if ($user->rights->user->user->lire) {
  504. $langs->load("commercial");
  505. $moreforfilter .= '<div class="divsearchfield">';
  506. $tmptitle = $langs->trans('ThirdPartiesOfSaleRepresentative');
  507. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$formother->select_salesrepresentatives($search_sale, 'search_sale', $user, 0, $tmptitle, 'widthcentpercentminusx maxwidth300');
  508. $moreforfilter .= '</div>';
  509. }
  510. // If the user can view other users
  511. if ($user->rights->user->user->lire) {
  512. $moreforfilter .= '<div class="divsearchfield">';
  513. $tmptitle = $langs->trans('LinkedToSpecificUsers');
  514. $moreforfilter .= img_picto($tmptitle, 'user', 'class="pictofixedwidth"').$form->select_dolusers($search_user, 'search_user', $tmptitle, '', 0, '', '', 0, 0, 0, '', 0, '', 'widthcentpercentminusx maxwidth300');
  515. $moreforfilter .= '</div>';
  516. }
  517. // If the user can view categories of products
  518. if (!empty($conf->categorie->enabled) && $user->rights->categorie->lire && ($user->rights->produit->lire || $user->rights->service->lire)) {
  519. include_once DOL_DOCUMENT_ROOT.'/categories/class/categorie.class.php';
  520. $moreforfilter .= '<div class="divsearchfield">';
  521. $tmptitle = $langs->trans('IncludingProductWithTag');
  522. $cate_arbo = $form->select_all_categories(Categorie::TYPE_PRODUCT, null, 'parent', null, null, 1);
  523. $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);
  524. $moreforfilter .= '</div>';
  525. }
  526. $parameters = array();
  527. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  528. if (empty($reshook)) {
  529. $moreforfilter .= $hookmanager->resPrint;
  530. } else {
  531. $moreforfilter = $hookmanager->resPrint;
  532. }
  533. if (!empty($moreforfilter)) {
  534. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  535. print $moreforfilter;
  536. print '</div>';
  537. }
  538. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  539. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  540. if ($massactionbutton) {
  541. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  542. }
  543. print '<div class="div-table-responsive">';
  544. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  545. print '<tr class="liste_titre_filter">';
  546. if (!empty($arrayfields['c.ref']['checked'])) {
  547. print '<td class="liste_titre">';
  548. print '<input type="text" class="flat" size="3" name="search_contract" value="'.dol_escape_htmltag($search_contract).'">';
  549. print '</td>';
  550. }
  551. if (!empty($arrayfields['c.ref_customer']['checked'])) {
  552. print '<td class="liste_titre">';
  553. print '<input type="text" class="flat" size="6" name="search_ref_customer" value="'.dol_escape_htmltag($search_ref_customer).'">';
  554. print '</td>';
  555. }
  556. if (!empty($arrayfields['c.ref_supplier']['checked'])) {
  557. print '<td class="liste_titre">';
  558. print '<input type="text" class="flat" size="6" name="search_ref_supplier" value="'.dol_escape_htmltag($search_ref_supplier).'">';
  559. print '</td>';
  560. }
  561. if (!empty($arrayfields['s.nom']['checked'])) {
  562. print '<td class="liste_titre">';
  563. print '<input type="text" class="flat" size="8" name="search_name" value="'.dol_escape_htmltag($search_name).'">';
  564. print '</td>';
  565. }
  566. if (!empty($arrayfields['s.email']['checked'])) {
  567. print '<td class="liste_titre">';
  568. print '<input type="text" class="flat" size="6" name="search_email" value="'.dol_escape_htmltag($search_email).'">';
  569. print '</td>';
  570. }
  571. // Town
  572. if (!empty($arrayfields['s.town']['checked'])) {
  573. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_town" value="'.dol_escape_htmltag($search_town).'"></td>';
  574. }
  575. // Zip
  576. if (!empty($arrayfields['s.zip']['checked'])) {
  577. print '<td class="liste_titre"><input class="flat" type="text" size="6" name="search_zip" value="'.dol_escape_htmltag($search_zip).'"></td>';
  578. }
  579. // State
  580. if (!empty($arrayfields['state.nom']['checked'])) {
  581. print '<td class="liste_titre">';
  582. print '<input class="flat" size="4" type="text" name="search_state" value="'.dol_escape_htmltag($search_state).'">';
  583. print '</td>';
  584. }
  585. // Country
  586. if (!empty($arrayfields['country.code_iso']['checked'])) {
  587. print '<td class="liste_titre center">';
  588. print $form->select_country($search_country, 'search_country', '', 0, 'minwidth100imp maxwidth100');
  589. print '</td>';
  590. }
  591. // Company type
  592. if (!empty($arrayfields['typent.code']['checked'])) {
  593. print '<td class="liste_titre maxwidthonsmartphone center">';
  594. 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);
  595. print '</td>';
  596. }
  597. if (!empty($arrayfields['sale_representative']['checked'])) {
  598. print '<td class="liste_titre"></td>';
  599. }
  600. if (!empty($arrayfields['c.date_contrat']['checked'])) {
  601. print '<td class="liste_titre center">';
  602. print '<div class="nowrap">';
  603. print $form->selectDate($search_date_start ? $search_date_start : -1, 'search_date_start', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  604. print '</div>';
  605. print '<div class="nowrap">';
  606. print $form->selectDate($search_date_end ? $search_date_end : -1, 'search_date_end', 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  607. print '</div>';
  608. print '</td>';
  609. }
  610. // Extra fields
  611. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  612. // Fields from hook
  613. $parameters = array('arrayfields'=>$arrayfields);
  614. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  615. print $hookmanager->resPrint;
  616. // Date creation
  617. if (!empty($arrayfields['c.datec']['checked'])) {
  618. print '<td class="liste_titre">';
  619. print '</td>';
  620. }
  621. // Date modification
  622. if (!empty($arrayfields['c.tms']['checked'])) {
  623. print '<td class="liste_titre">';
  624. print '</td>';
  625. }
  626. // First end date
  627. if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
  628. print '<td class="liste_titre nowraponall center">';
  629. $arrayofoperators = array('0'=>'', '='=>'=', '<='=>'<=', '>='=>'>=');
  630. print $form->selectarray('search_op2df', $arrayofoperators, $search_op2df, 0, 0, 0, '', 0, 0, 0, '', 'maxwidth50imp');
  631. print '</br>';
  632. print $formother->select_month($search_dfmonth, 'search_dfmonth', 1, 0);
  633. print ' ';
  634. $formother->select_year($search_dfyear, 'search_dfyear', 1, 20, 5, 0, 0, '');
  635. print '</td>';
  636. }
  637. // Status
  638. if (!empty($arrayfields['status']['checked'])) {
  639. print '<td class="liste_titre right" colspan="4"></td>';
  640. }
  641. print '<td class="liste_titre center">';
  642. $searchpicto = $form->showFilterButtons();
  643. print $searchpicto;
  644. print '</td>';
  645. print "</tr>\n";
  646. print '<tr class="liste_titre">';
  647. if (!empty($arrayfields['c.ref']['checked'])) {
  648. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
  649. }
  650. if (!empty($arrayfields['c.ref_customer']['checked'])) {
  651. print_liste_field_titre($arrayfields['c.ref_customer']['label'], $_SERVER["PHP_SELF"], "c.ref_customer", "", $param, '', $sortfield, $sortorder);
  652. }
  653. if (!empty($arrayfields['c.ref_supplier']['checked'])) {
  654. print_liste_field_titre($arrayfields['c.ref_supplier']['label'], $_SERVER["PHP_SELF"], "c.ref_supplier", "", $param, '', $sortfield, $sortorder);
  655. }
  656. if (!empty($arrayfields['s.nom']['checked'])) {
  657. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  658. }
  659. if (!empty($arrayfields['s.email']['checked'])) {
  660. print_liste_field_titre($arrayfields['s.email']['label'], $_SERVER["PHP_SELF"], "s.email", "", $param, '', $sortfield, $sortorder);
  661. }
  662. if (!empty($arrayfields['s.town']['checked'])) {
  663. print_liste_field_titre($arrayfields['s.town']['label'], $_SERVER["PHP_SELF"], 's.town', '', $param, '', $sortfield, $sortorder);
  664. }
  665. if (!empty($arrayfields['s.zip']['checked'])) {
  666. print_liste_field_titre($arrayfields['s.zip']['label'], $_SERVER["PHP_SELF"], 's.zip', '', $param, '', $sortfield, $sortorder);
  667. }
  668. if (!empty($arrayfields['state.nom']['checked'])) {
  669. print_liste_field_titre($arrayfields['state.nom']['label'], $_SERVER["PHP_SELF"], "state.nom", "", $param, '', $sortfield, $sortorder);
  670. }
  671. if (!empty($arrayfields['country.code_iso']['checked'])) {
  672. print_liste_field_titre($arrayfields['country.code_iso']['label'], $_SERVER["PHP_SELF"], "country.code_iso", "", $param, '', $sortfield, $sortorder, 'center ');
  673. }
  674. if (!empty($arrayfields['typent.code']['checked'])) {
  675. print_liste_field_titre($arrayfields['typent.code']['label'], $_SERVER["PHP_SELF"], "typent.code", "", $param, '', $sortfield, $sortorder, 'center ');
  676. }
  677. if (!empty($arrayfields['sale_representative']['checked'])) {
  678. print_liste_field_titre($arrayfields['sale_representative']['label'], $_SERVER["PHP_SELF"], "", "", $param, '', $sortfield, $sortorder);
  679. }
  680. if (!empty($arrayfields['c.date_contrat']['checked'])) {
  681. print_liste_field_titre($arrayfields['c.date_contrat']['label'], $_SERVER["PHP_SELF"], "c.date_contrat", "", $param, '', $sortfield, $sortorder, 'center ');
  682. }
  683. // Extra fields
  684. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  685. // Hook fields
  686. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  687. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  688. print $hookmanager->resPrint;
  689. if (!empty($arrayfields['c.datec']['checked'])) {
  690. print_liste_field_titre($arrayfields['c.datec']['label'], $_SERVER["PHP_SELF"], "c.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  691. }
  692. if (!empty($arrayfields['c.tms']['checked'])) {
  693. print_liste_field_titre($arrayfields['c.tms']['label'], $_SERVER["PHP_SELF"], "c.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  694. }
  695. if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
  696. print_liste_field_titre($arrayfields['lower_planned_end_date']['label'], $_SERVER["PHP_SELF"], "lower_planned_end_date", "", $param, '', $sortfield, $sortorder, 'center ');
  697. }
  698. if (!empty($arrayfields['status']['checked'])) {
  699. print_liste_field_titre($staticcontratligne->LibStatut(0, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
  700. print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 0, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
  701. print_liste_field_titre($staticcontratligne->LibStatut(4, 3, 1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
  702. print_liste_field_titre($staticcontratligne->LibStatut(5, 3, -1, 'class="nochangebackground"'), '', '', '', '', 'width="16"');
  703. }
  704. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  705. print "</tr>\n";
  706. $totalarray = array();
  707. $totalarray['nbfield'] = 0;
  708. $typenArray = array();
  709. $cacheCountryIDCode = array();
  710. while ($i < min($num, $limit)) {
  711. $obj = $db->fetch_object($resql);
  712. $contracttmp->ref = $obj->ref;
  713. $contracttmp->id = $obj->rowid;
  714. $contracttmp->ref_customer = $obj->ref_customer;
  715. $contracttmp->ref_supplier = $obj->ref_supplier;
  716. if ($obj->socid > 0) {
  717. $result = $socstatic->fetch($obj->socid);
  718. }
  719. /*$socstatic->id = $obj->socid;
  720. $socstatic->name = $obj->name;
  721. $socstatic->name_alias = $obj->name_alias;
  722. $socstatic->email = $obj->email;
  723. $socstatic->status = $obj->company_status;
  724. $socstatic->logo = $obj->logo;
  725. $socstatic->country_id = $obj->country_id;
  726. $socstatic->country_code = '';
  727. $socstatic->country = '';*/
  728. if ($obj->country_id > 0) {
  729. if (!isset($cacheCountryIDCode[$obj->country_id]['code'])) {
  730. $tmparray = getCountry($obj->country_id, 'all');
  731. $cacheCountryIDCode[$obj->country_id] = array('code'=> empty($tmparray['code']) ? '' : $tmparray['code'], 'label' => empty($tmparray['label']) ? '' : $tmparray['label']);
  732. }
  733. $socstatic->country_code = $cacheCountryIDCode[$obj->country_id]['code'];
  734. $socstatic->country = $cacheCountryIDCode[$obj->country_id]['label'];
  735. }
  736. print '<tr class="oddeven">';
  737. // Ref
  738. if (!empty($arrayfields['c.ref']['checked'])) {
  739. print '<td class="nowraponall">';
  740. print $contracttmp->getNomUrl(1);
  741. if ($obj->nb_late) {
  742. print img_warning($langs->trans("Late"));
  743. }
  744. if (!empty($obj->note_private) || !empty($obj->note_public)) {
  745. print ' <span class="note">';
  746. print '<a href="'.DOL_URL_ROOT.'/contrat/note.php?id='.$obj->rowid.'&save_lastsearch_values=1">'.img_picto($langs->trans("ViewPrivateNote"), 'note').'</a>';
  747. print '</span>';
  748. }
  749. $filename = dol_sanitizeFileName($obj->ref);
  750. $filedir = $conf->contrat->multidir_output[$obj->entity].'/'.dol_sanitizeFileName($obj->ref);
  751. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  752. print $formfile->getDocumentsLink($contracttmp->element, $filename, $filedir);
  753. print '</td>';
  754. print '</td>';
  755. }
  756. // Ref thirdparty
  757. if (!empty($arrayfields['c.ref_customer']['checked'])) {
  758. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag(dol_string_nohtmltag($contracttmp->getFormatedCustomerRef($obj->ref_customer))).'">'.$contracttmp->getFormatedCustomerRef($obj->ref_customer).'</td>';
  759. }
  760. if (!empty($arrayfields['c.ref_supplier']['checked'])) {
  761. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->ref_supplier).'">'.dol_escape_htmltag($obj->ref_supplier).'</td>';
  762. }
  763. if (!empty($arrayfields['s.nom']['checked'])) {
  764. print '<td class="tdoverflowmax150">';
  765. if ($obj->socid > 0) {
  766. // TODO Use a cache for this string
  767. print $socstatic->getNomUrl(1, '');
  768. }
  769. print '</td>';
  770. }
  771. // Email
  772. if (!empty($arrayfields['s.email']['checked'])) {
  773. print '<td class="tdoverflowmax200" title="'.dol_escape_htmltag($obj->email).'">'.dol_print_email($obj->email, 0, $obj->socid, 0, 0, 1, 1).'</td>';
  774. }
  775. // Town
  776. if (!empty($arrayfields['s.town']['checked'])) {
  777. print '<td class="nocellnopadd">';
  778. print $obj->town;
  779. print '</td>';
  780. if (!$i) {
  781. $totalarray['nbfield']++;
  782. }
  783. }
  784. // Zip
  785. if (!empty($arrayfields['s.zip']['checked'])) {
  786. print '<td class="nocellnopadd">';
  787. print $obj->zip;
  788. print '</td>';
  789. if (!$i) {
  790. $totalarray['nbfield']++;
  791. }
  792. }
  793. // State
  794. if (!empty($arrayfields['state.nom']['checked'])) {
  795. print "<td>".$obj->state_name."</td>\n";
  796. if (!$i) {
  797. $totalarray['nbfield']++;
  798. }
  799. }
  800. // Country
  801. if (!empty($arrayfields['country.code_iso']['checked'])) {
  802. print '<td class="center">';
  803. print $socstatic->country;
  804. print '</td>';
  805. if (!$i) {
  806. $totalarray['nbfield']++;
  807. }
  808. }
  809. // Type ent
  810. if (!empty($arrayfields['typent.code']['checked'])) {
  811. print '<td class="center">';
  812. if (count($typenArray) == 0) {
  813. $typenArray = $formcompany->typent_array(1);
  814. }
  815. print $typenArray[$obj->typent_code];
  816. print '</td>';
  817. if (!$i) {
  818. $totalarray['nbfield']++;
  819. }
  820. }
  821. if (!empty($arrayfields['sale_representative']['checked'])) {
  822. // Sales representatives
  823. print '<td>';
  824. if ($obj->socid > 0) {
  825. $listsalesrepresentatives = $socstatic->getSalesRepresentatives($user);
  826. if ($listsalesrepresentatives < 0) {
  827. dol_print_error($db);
  828. }
  829. $nbofsalesrepresentative = count($listsalesrepresentatives);
  830. if ($nbofsalesrepresentative > 6) {
  831. // We print only number
  832. print $nbofsalesrepresentative;
  833. } elseif ($nbofsalesrepresentative > 0) {
  834. $userstatic = new User($db);
  835. $j = 0;
  836. foreach ($listsalesrepresentatives as $val) {
  837. $userstatic->id = $val['id'];
  838. $userstatic->lastname = $val['lastname'];
  839. $userstatic->firstname = $val['firstname'];
  840. $userstatic->email = $val['email'];
  841. $userstatic->statut = $val['statut'];
  842. $userstatic->entity = $val['entity'];
  843. $userstatic->photo = $val['photo'];
  844. $userstatic->login = $val['login'];
  845. $userstatic->phone = $val['phone'];
  846. $userstatic->job = $val['job'];
  847. $userstatic->gender = $val['gender'];
  848. //print '<div class="float">':
  849. print ($nbofsalesrepresentative < 2) ? $userstatic->getNomUrl(-1, '', 0, 0, 12) : $userstatic->getNomUrl(-2);
  850. $j++;
  851. if ($j < $nbofsalesrepresentative) {
  852. print ' ';
  853. }
  854. //print '</div>';
  855. }
  856. }
  857. //else print $langs->trans("NoSalesRepresentativeAffected");
  858. } else {
  859. print '&nbsp;';
  860. }
  861. print '</td>';
  862. }
  863. // Date
  864. if (!empty($arrayfields['c.date_contrat']['checked'])) {
  865. print '<td class="center">'.dol_print_date($db->jdate($obj->date_contrat), 'day', 'tzserver').'</td>';
  866. }
  867. // Extra fields
  868. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  869. // Fields from hook
  870. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  871. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  872. print $hookmanager->resPrint;
  873. // Date creation
  874. if (!empty($arrayfields['c.datec']['checked'])) {
  875. print '<td class="center nowrap">';
  876. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  877. print '</td>';
  878. if (!$i) {
  879. $totalarray['nbfield']++;
  880. }
  881. }
  882. // Date modification
  883. if (!empty($arrayfields['c.tms']['checked'])) {
  884. print '<td class="center nowrap">';
  885. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  886. print '</td>';
  887. if (!$i) {
  888. $totalarray['nbfield']++;
  889. }
  890. }
  891. // Date lower end date
  892. if (!empty($arrayfields['lower_planned_end_date']['checked'])) {
  893. print '<td class="center nowrapforall">';
  894. print dol_print_date($db->jdate($obj->lower_planned_end_date), 'day', 'tzuser');
  895. print '</td>';
  896. if (!$i) {
  897. $totalarray['nbfield']++;
  898. }
  899. }
  900. // Status
  901. if (!empty($arrayfields['status']['checked'])) {
  902. print '<td class="center">'.($obj->nb_initial > 0 ? $obj->nb_initial : '').'</td>';
  903. print '<td class="center">'.($obj->nb_running > 0 ? $obj->nb_running : '').'</td>';
  904. print '<td class="center">'.($obj->nb_expired > 0 ? $obj->nb_expired : '').'</td>';
  905. print '<td class="center">'.($obj->nb_closed > 0 ? $obj->nb_closed : '').'</td>';
  906. }
  907. // Action column
  908. print '<td class="nowrap center">';
  909. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  910. $selected = 0;
  911. if (in_array($obj->rowid, $arrayofselected)) {
  912. $selected = 1;
  913. }
  914. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  915. }
  916. print '</td>';
  917. if (!$i) {
  918. $totalarray['nbfield']++;
  919. }
  920. print "</tr>\n";
  921. $i++;
  922. }
  923. $db->free($resql);
  924. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  925. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  926. print $hookmanager->resPrint;
  927. print '</table>';
  928. print '</div>';
  929. print '</form>';
  930. $hidegeneratedfilelistifempty = 1;
  931. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  932. $hidegeneratedfilelistifempty = 0;
  933. }
  934. // Show list of available documents
  935. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  936. $urlsource .= str_replace('&amp;', '&', $param);
  937. $filedir = $diroutputmassaction;
  938. $genallowed = $user->rights->contrat->lire;
  939. $delallowed = $user->rights->contrat->lire;
  940. print $formfile->showdocuments('massfilesarea_contract', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  941. llxFooter();
  942. $db->close();