list.php 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943
  1. <?php
  2. /* Copyright (C) 2002-2003 Rodolphe Quiedeville <rodolphe@quiedeville.org>
  3. * Copyright (C) 2004-2014 Laurent Destailleur <eldy@users.sourceforge.net>
  4. * Copyright (C) 2005-2012 Regis Houssin <regis.houssin@inodbox.com>
  5. * Copyright (C) 2011-2012 Juanjo Menent <jmenent@2byte.es>
  6. * Copyright (C) 2013 Cédric Salvador <csalvador@gpcsolutions.fr>
  7. * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
  8. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  9. * Copyright (C) 2021 Frédéric France <frederic.france@netlogic.fr>
  10. * Copyright (C) 2022 Charlène Benke <charlene@patas-monkey.com>
  11. *
  12. * This program is free software; you can redistribute it and/or modify
  13. * it under the terms of the GNU General Public License as published by
  14. * the Free Software Foundation; either version 3 of the License, or
  15. * (at your option) any later version.
  16. *
  17. * This program is distributed in the hope that it will be useful,
  18. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  19. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  20. * GNU General Public License for more details.
  21. *
  22. * You should have received a copy of the GNU General Public License
  23. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  24. */
  25. /**
  26. * \file htdocs/fichinter/list.php
  27. * \brief List of all interventions
  28. * \ingroup ficheinter
  29. */
  30. // Load Dolibarr environment
  31. require '../main.inc.php';
  32. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  35. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  36. if (isModEnabled('project')) {
  37. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  38. }
  39. if (isModEnabled('contrat')) {
  40. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  41. }
  42. // Load translation files required by the page
  43. $langs->loadLangs(array('companies', 'bills', 'interventions'));
  44. if (isModEnabled('project')) {
  45. $langs->load("projects");
  46. }
  47. if (isModEnabled('contrat')) {
  48. $langs->load("contracts");
  49. }
  50. $action = GETPOST('action', 'aZ09');
  51. $massaction = GETPOST('massaction', 'alpha');
  52. $show_files = GETPOST('show_files', 'int');
  53. $confirm = GETPOST('confirm', 'alpha');
  54. $toselect = GETPOST('toselect', 'array');
  55. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'interventionlist';
  56. $search_ref = GETPOST('search_ref') ?GETPOST('search_ref', 'alpha') : GETPOST('search_inter', 'alpha');
  57. $search_ref_client = GETPOST('search_ref_client', 'alpha');
  58. $search_company = GETPOST('search_company', 'alpha');
  59. $search_desc = GETPOST('search_desc', 'alpha');
  60. $search_projet_ref = GETPOST('search_projet_ref', 'alpha');
  61. $search_contrat_ref = GETPOST('search_contrat_ref', 'alpha');
  62. $search_status = GETPOST('search_status', 'alpha');
  63. $search_all = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  64. $optioncss = GETPOST('optioncss', 'alpha');
  65. $socid = GETPOST('socid', 'int');
  66. $diroutputmassaction = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id;
  67. // Load variable for pagination
  68. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  69. $sortfield = GETPOST('sortfield', 'aZ09comma');
  70. $sortorder = GETPOST('sortorder', 'aZ09comma');
  71. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  72. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  73. // If $page is not defined, or '' or -1 or if we click on clear filters
  74. $page = 0;
  75. }
  76. $offset = $limit * $page;
  77. $pageprev = $page - 1;
  78. $pagenext = $page + 1;
  79. if (!$sortorder) {
  80. $sortorder = "DESC";
  81. }
  82. if (!$sortfield) {
  83. $sortfield = "f.ref";
  84. }
  85. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  86. $object = new Fichinter($db);
  87. $hookmanager->initHooks(array('interventionlist'));
  88. $extrafields = new ExtraFields($db);
  89. // Fetch optionals attributes and labels
  90. $extrafields->fetch_name_optionals_label($object->table_element);
  91. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  92. // List of fields to search into when doing a "search in all"
  93. $fieldstosearchall = array(
  94. 'f.ref'=>'Ref',
  95. 's.nom'=>"ThirdParty",
  96. 'f.description'=>'Description',
  97. 'f.note_public'=>'NotePublic',
  98. 'fd.description'=>'DescriptionOfLine',
  99. );
  100. if (empty($user->socid)) {
  101. $fieldstosearchall["f.note_private"] = "NotePrivate";
  102. }
  103. if (!empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  104. unset($fieldstosearchall['fd.description']);
  105. }
  106. // Definition of fields for list
  107. $arrayfields = array(
  108. 'f.ref'=>array('label'=>'Ref', 'checked'=>1),
  109. 'f.ref_client'=>array('label'=>'RefCustomer', 'checked'=>1),
  110. 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
  111. 'pr.ref'=>array('label'=>'Project', 'checked'=>1, 'enabled'=>(!isModEnabled('project') ? 0 : 1)),
  112. 'c.ref'=>array('label'=>'Contract', 'checked'=>1, 'enabled'=>(empty($conf->contrat->enabled) ? 0 : 1)),
  113. 'f.description'=>array('label'=>'Description', 'checked'=>1),
  114. 'f.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>500),
  115. 'f.tms'=>array('label'=>'DateModificationShort', 'checked'=>0, 'position'=>500),
  116. 'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PUBLIC_NOTES'))),
  117. 'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(!getDolGlobalInt('MAIN_LIST_HIDE_PRIVATE_NOTES'))),
  118. 'f.fk_statut'=>array('label'=>'Status', 'checked'=>1, 'position'=>1000),
  119. 'fd.description'=>array('label'=>"DescriptionOfLine", 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  120. 'fd.date'=>array('label'=>'DateOfLine', 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  121. 'fd.duree'=>array('label'=>'DurationOfLine', 'type'=> 'duration', 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0), //type duration is here because in database, column 'duree' is double
  122. );
  123. // Extra fields
  124. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  125. $object->fields = dol_sort_array($object->fields, 'position');
  126. $arrayfields = dol_sort_array($arrayfields, 'position');
  127. // Security check
  128. $id = GETPOST('id', 'int');
  129. if ($user->socid) {
  130. $socid = $user->socid;
  131. }
  132. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  133. $permissiontoread = $user->rights->ficheinter->lire;
  134. $permissiontodelete = $user->rights->ficheinter->supprimer;
  135. /*
  136. * Actions
  137. */
  138. if (GETPOST('cancel', 'alpha')) {
  139. $action = 'list';
  140. $massaction = '';
  141. }
  142. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  143. $massaction = '';
  144. }
  145. $parameters = array('socid'=>$socid);
  146. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  147. if ($reshook < 0) {
  148. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  149. }
  150. if (empty($reshook)) {
  151. // Selection of new fields
  152. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  153. // Purge search criteria
  154. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')) { // All tests are required to be compatible with all browsers
  155. $search_ref = "";
  156. $search_ref_client = "";
  157. $search_company = "";
  158. $search_projet_ref = "";
  159. $search_contrat_ref = "";
  160. $search_desc = "";
  161. $search_status = "";
  162. $toselect = array();
  163. $search_array_options = array();
  164. }
  165. // Mass actions
  166. $objectclass = 'Fichinter';
  167. $objectlabel = 'Interventions';
  168. $uploaddir = $conf->ficheinter->dir_output;
  169. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  170. }
  171. /*
  172. * View
  173. */
  174. $form = new Form($db);
  175. $formfile = new FormFile($db);
  176. $objectstatic = new Fichinter($db);
  177. $companystatic = new Societe($db);
  178. if (isModEnabled('project')) {
  179. $projetstatic = new Project($db);
  180. }
  181. if (isModEnabled('contrat')) {
  182. $contratstatic = new Contrat($db);
  183. }
  184. $now = dol_now();
  185. $help_url = '';
  186. $title = $langs->trans("Interventions");
  187. $morejs = array();
  188. $morecss = array();
  189. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  190. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  191. $atleastonefieldinlines = 0;
  192. foreach ($arrayfields as $tmpkey => $tmpval) {
  193. if (preg_match('/^fd\./', $tmpkey) && !empty($arrayfields[$tmpkey]['checked'])) {
  194. $atleastonefieldinlines++;
  195. break;
  196. }
  197. }
  198. $sql = "SELECT";
  199. $sql .= " f.ref, f.ref_client, f.rowid, f.fk_statut as status, f.description, f.datec as date_creation, f.tms as date_update, f.note_public, f.note_private,";
  200. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  201. $sql .= " fd.rowid as lineid, fd.description as descriptiondetail, fd.date as dp, fd.duree,";
  202. }
  203. $sql .= " s.nom as name, s.rowid as socid, s.client, s.fournisseur, s.email, s.status as thirdpartystatus";
  204. if (isModEnabled('project')) {
  205. $sql .= ", pr.rowid as projet_id, pr.ref as projet_ref, pr.title as projet_title";
  206. }
  207. if (isModEnabled('contrat')) {
  208. $sql .= ", c.rowid as contrat_id, c.ref as contrat_ref, c.ref_customer as contrat_ref_customer, c.ref_supplier as contrat_ref_supplier";
  209. }
  210. // Add fields from extrafields
  211. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  212. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  213. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  214. }
  215. }
  216. // Add fields from hooks
  217. $parameters = array();
  218. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  219. $sql .= $hookmanager->resPrint;
  220. $sqlfields = $sql; // $sql fields to remove for count total
  221. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  222. if (isModEnabled('project')) {
  223. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr on f.fk_projet = pr.rowid";
  224. }
  225. if (isModEnabled('contrat')) {
  226. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat as c on f.fk_contrat = c.rowid";
  227. }
  228. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  229. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  230. }
  231. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  232. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.rowid";
  233. }
  234. // Add table from hooks
  235. $parameters = array();
  236. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  237. $sql .= $hookmanager->resPrint;
  238. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  239. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  240. }
  241. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  242. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  243. $sql .= " AND f.fk_soc = s.rowid";
  244. if ($search_ref) {
  245. $sql .= natural_search('f.ref', $search_ref);
  246. }
  247. if ($search_ref_client) {
  248. $sql .= natural_search('f.ref_client', $search_ref_client);
  249. }
  250. if ($search_company) {
  251. $sql .= natural_search('s.nom', $search_company);
  252. }
  253. if ($search_projet_ref) {
  254. $sql .= natural_search('pr.ref', $search_projet_ref);
  255. }
  256. if ($search_contrat_ref) {
  257. $sql .= natural_search('c.ref', $search_contrat_ref);
  258. }
  259. if ($search_desc) {
  260. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  261. $sql .= natural_search(array('f.description', 'fd.description'), $search_desc);
  262. } else {
  263. $sql .= natural_search(array('f.description'), $search_desc);
  264. }
  265. }
  266. if ($search_status != '' && $search_status >= 0) {
  267. $sql .= ' AND f.fk_statut = '.urlencode($search_status);
  268. }
  269. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  270. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  271. }
  272. if ($socid) {
  273. $sql .= " AND s.rowid = ".((int) $socid);
  274. }
  275. if ($search_all) {
  276. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  277. }
  278. // Add where from extra fields
  279. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  280. // Add where from hooks
  281. $parameters = array();
  282. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  283. $sql .= $hookmanager->resPrint;
  284. // Add GroupBy from hooks
  285. $parameters = array('search_all' => $search_all, 'fieldstosearchall' => $fieldstosearchall);
  286. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  287. $sql .= $hookmanager->resPrint;
  288. // Count total nb of records
  289. $nbtotalofrecords = '';
  290. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  291. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  292. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  293. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  294. $resql = $db->query($sqlforcount);
  295. if ($resql) {
  296. $objforcount = $db->fetch_object($resql);
  297. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  298. } else {
  299. dol_print_error($db);
  300. }
  301. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  302. $page = 0;
  303. $offset = 0;
  304. }
  305. $db->free($resql);
  306. }
  307. // Complete request and execute it with limit
  308. $sql .= $db->order($sortfield, $sortorder);
  309. if ($limit) {
  310. $sql .= $db->plimit($limit + 1, $offset);
  311. }
  312. $resql = $db->query($sql);
  313. if (!$resql) {
  314. dol_print_error($db);
  315. exit;
  316. }
  317. $num = $db->num_rows($resql);
  318. // Direct jump if only one record found
  319. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  320. $obj = $db->fetch_object($resql);
  321. $id = $obj->rowid;
  322. header("Location: ".dol_buildpath('/mymodule/myobject_card.php', 1).'?id='.$id);
  323. exit;
  324. }
  325. // Output page
  326. // --------------------------------------------------------------------
  327. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  328. $arrayofselected = is_array($toselect) ? $toselect : array();
  329. if ($socid > 0) {
  330. $soc = new Societe($db);
  331. $soc->fetch($socid);
  332. if (empty($search_company)) {
  333. $search_company = $soc->name;
  334. }
  335. }
  336. $param = '';
  337. if (!empty($mode)) {
  338. $param .= '&mode='.urlencode($mode);
  339. }
  340. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  341. $param .= '&contextpage='.urlencode($contextpage);
  342. }
  343. if ($limit > 0 && $limit != $conf->liste_limit) {
  344. $param .= '&limit='.urlencode($limit);
  345. }
  346. if ($search_all) {
  347. $param .= "&search_all=".urlencode($search_all);
  348. }
  349. if ($socid) {
  350. $param .= "&socid=".urlencode($socid);
  351. }
  352. if ($search_ref) {
  353. $param .= "&search_ref=".urlencode($search_ref);
  354. }
  355. if ($search_ref_client) {
  356. $param .= "&search_ref_client=".urlencode($search_ref_client);
  357. }
  358. if ($search_company) {
  359. $param .= "&search_company=".urlencode($search_company);
  360. }
  361. if ($search_desc) {
  362. $param .= "&search_desc=".urlencode($search_desc);
  363. }
  364. if ($search_status != '' && $search_status > -1) {
  365. $param .= "&search_status=".urlencode($search_status);
  366. }
  367. if ($show_files) {
  368. $param .= '&show_files='.urlencode($show_files);
  369. }
  370. if ($optioncss != '') {
  371. $param .= '&optioncss='.urlencode($optioncss);
  372. }
  373. // Add $param from extra fields
  374. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  375. // Add $param from hooks
  376. $parameters = array();
  377. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  378. $param .= $hookmanager->resPrint;
  379. // List of mass actions available
  380. $arrayofmassactions = array(
  381. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  382. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  383. //'presend'=>$langs->trans("SendByMail"),
  384. );
  385. if (!empty($permissiontodelete)) {
  386. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  387. }
  388. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  389. $arrayofmassactions = array();
  390. }
  391. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  392. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  393. if ($optioncss != '') {
  394. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  395. }
  396. print '<input type="hidden" name="token" value="'.newToken().'">';
  397. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  398. print '<input type="hidden" name="action" value="list">';
  399. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  400. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  401. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  402. $newcardbutton = '';
  403. $url = DOL_URL_ROOT.'/fichinter/card.php?action=create';
  404. if (!empty($socid)) {
  405. $url .= '&socid='.$socid;
  406. }
  407. $newcardbutton = dolGetButtonTitle($langs->trans('NewIntervention'), '', 'fa fa-plus-circle', $url, '', $user->rights->ficheinter->creer);
  408. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  409. $topicmail = "Information";
  410. $modelmail = "intervention";
  411. $objecttmp = new Fichinter($db);
  412. $trackid = 'int'.$object->id;
  413. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  414. if ($search_all) {
  415. foreach ($fieldstosearchall as $key => $val) {
  416. $fieldstosearchall[$key] = $langs->trans($val);
  417. }
  418. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  419. }
  420. $moreforfilter = '';
  421. $parameters = array();
  422. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  423. if (empty($reshook)) {
  424. $moreforfilter .= $hookmanager->resPrint;
  425. } else {
  426. $moreforfilter = $hookmanager->resPrint;
  427. }
  428. if (!empty($moreforfilter)) {
  429. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  430. print $moreforfilter;
  431. print '</div>';
  432. }
  433. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  434. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
  435. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  436. print '<div class="div-table-responsive">';
  437. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  438. // Fields title search
  439. // --------------------------------------------------------------------
  440. print '<tr class="liste_titre_filter">';
  441. // Action column
  442. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  443. print '<td class="liste_titre maxwidthsearch">';
  444. $searchpicto = $form->showFilterButtons('left');
  445. print $searchpicto;
  446. print '</td>';
  447. }
  448. if (!empty($arrayfields['f.ref']['checked'])) {
  449. print '<td class="liste_titre">';
  450. print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="8">';
  451. print '</td>';
  452. }
  453. if (!empty($arrayfields['f.ref_client']['checked'])) {
  454. print '<td class="liste_titre">';
  455. print '<input type="text" class="flat" name="search_ref_client" value="'.$search_ref_client.'" size="8">';
  456. print '</td>';
  457. }
  458. if (!empty($arrayfields['s.nom']['checked'])) {
  459. print '<td class="liste_titre">';
  460. print '<input type="text" class="flat" name="search_company" value="'.$search_company.'" size="10">';
  461. print '</td>';
  462. }
  463. if (!empty($arrayfields['pr.ref']['checked'])) {
  464. print '<td class="liste_titre">';
  465. print '<input type="text" class="flat" name="search_projet_ref" value="'.$search_projet_ref.'" size="8">';
  466. print '</td>';
  467. }
  468. if (!empty($arrayfields['c.ref']['checked'])) {
  469. print '<td class="liste_titre">';
  470. print '<input type="text" class="flat" name="search_contrat_ref" value="'.$search_contrat_ref.'" size="8">';
  471. print '</td>';
  472. }
  473. if (!empty($arrayfields['f.description']['checked'])) {
  474. print '<td class="liste_titre">';
  475. print '<input type="text" class="flat" name="search_desc" value="'.$search_desc.'" size="12">';
  476. print '</td>';
  477. }
  478. // Extra fields
  479. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  480. // Fields from hook
  481. $parameters = array('arrayfields'=>$arrayfields);
  482. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  483. print $hookmanager->resPrint;
  484. if (!empty($arrayfields['f.datec']['checked'])) {
  485. // Date creation
  486. print '<td class="liste_titre">';
  487. print '</td>';
  488. }
  489. if (!empty($arrayfields['f.tms']['checked'])) {
  490. // Date modification
  491. print '<td class="liste_titre">';
  492. print '</td>';
  493. }
  494. if (!empty($arrayfields['f.note_public']['checked'])) {
  495. // Note public
  496. print '<td class="liste_titre">';
  497. print '</td>';
  498. }
  499. if (!empty($arrayfields['f.note_private']['checked'])) {
  500. // Note private
  501. print '<td class="liste_titre">';
  502. print '</td>';
  503. }
  504. // Status
  505. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  506. print '<td class="liste_titre right">';
  507. $tmp = $objectstatic->LibStatut(0); // To load $this->statuts_short
  508. $liststatus = $objectstatic->statuts_short;
  509. if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
  510. unset($liststatus[2]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
  511. }
  512. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 1, 0, 0, '', 'onrightofpage');
  513. print '</td>';
  514. }
  515. // Fields of detail line
  516. if (!empty($arrayfields['fd.description']['checked'])) {
  517. print '<td class="liste_titre">&nbsp;</td>';
  518. }
  519. if (!empty($arrayfields['fd.date']['checked'])) {
  520. print '<td class="liste_titre">&nbsp;</td>';
  521. }
  522. if (!empty($arrayfields['fd.duree']['checked'])) {
  523. print '<td class="liste_titre">&nbsp;</td>';
  524. }
  525. // Action column
  526. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  527. print '<td class="liste_titre maxwidthsearch">';
  528. $searchpicto = $form->showFilterButtons();
  529. print $searchpicto;
  530. print '</td>';
  531. }
  532. print '</tr>'."\n";
  533. $totalarray = array();
  534. $totalarray['nbfield'] = 0;
  535. // Fields title label
  536. // --------------------------------------------------------------------
  537. print '<tr class="liste_titre">';
  538. // Action column
  539. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  540. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  541. }
  542. if (!empty($arrayfields['f.ref']['checked'])) {
  543. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  544. }
  545. if (!empty($arrayfields['f.ref_client']['checked'])) {
  546. print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], "f.ref_client", "", $param, '', $sortfield, $sortorder);
  547. }
  548. if (!empty($arrayfields['s.nom']['checked'])) {
  549. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  550. }
  551. if (!empty($arrayfields['pr.ref']['checked'])) {
  552. print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], "pr.ref", "", $param, '', $sortfield, $sortorder);
  553. }
  554. if (!empty($arrayfields['c.ref']['checked'])) {
  555. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
  556. }
  557. if (!empty($arrayfields['f.description']['checked'])) {
  558. print_liste_field_titre($arrayfields['f.description']['label'], $_SERVER["PHP_SELF"], "f.description", "", $param, '', $sortfield, $sortorder);
  559. }
  560. // Extra fields
  561. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  562. // Hook fields
  563. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  564. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  565. print $hookmanager->resPrint;
  566. if (!empty($arrayfields['f.datec']['checked'])) {
  567. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  568. }
  569. if (!empty($arrayfields['f.tms']['checked'])) {
  570. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  571. }
  572. if (!empty($arrayfields['f.note_public']['checked'])) {
  573. print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  574. }
  575. if (!empty($arrayfields['f.note_private']['checked'])) {
  576. print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  577. }
  578. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  579. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  580. }
  581. if (!empty($arrayfields['fd.description']['checked'])) {
  582. print_liste_field_titre($arrayfields['fd.description']['label'], $_SERVER["PHP_SELF"], '');
  583. }
  584. if (!empty($arrayfields['fd.date']['checked'])) {
  585. print_liste_field_titre($arrayfields['fd.date']['label'], $_SERVER["PHP_SELF"], "fd.date", "", $param, '', $sortfield, $sortorder, 'center ');
  586. }
  587. if (!empty($arrayfields['fd.duree']['checked'])) {
  588. print_liste_field_titre($arrayfields['fd.duree']['label'], $_SERVER["PHP_SELF"], "fd.duree", "", $param, '', $sortfield, $sortorder, 'right ');
  589. }
  590. // Action column
  591. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  592. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  593. }
  594. print "</tr>\n";
  595. // Loop on record
  596. // --------------------------------------------------------------------
  597. $total = 0;
  598. $i = 0;
  599. $savnbfield = $totalarray['nbfield'];
  600. $totalarray = array();
  601. $totalarray['nbfield'] = 0;
  602. $totalarray['val'] = array();
  603. $totalarray['val']['fd.duree'] = 0;
  604. $imaxinloop = ($limit ? min($num, $limit) : $num);
  605. while ($i < $imaxinloop) {
  606. $obj = $db->fetch_object($resql);
  607. if (empty($obj)) {
  608. break; // Should not happen
  609. }
  610. // Store properties in $object
  611. //$object->setVarsFromFetchObj($obj);
  612. $objectstatic->id = $obj->rowid;
  613. $objectstatic->ref = $obj->ref;
  614. $objectstatic->ref_client = $obj->ref_client;
  615. $objectstatic->statut = $obj->status;
  616. $objectstatic->status = $obj->status;
  617. $companystatic->name = $obj->name;
  618. $companystatic->id = $obj->socid;
  619. $companystatic->client = $obj->client;
  620. $companystatic->fournisseur = $obj->fournisseur;
  621. $companystatic->email = $obj->email;
  622. $companystatic->status = $obj->thirdpartystatus;
  623. print '<tr class="oddeven">';
  624. // Action column
  625. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  626. print '<td class="nowrap center">';
  627. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  628. $selected = 0;
  629. if (in_array($obj->rowid, $arrayofselected)) {
  630. $selected = 1;
  631. }
  632. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  633. }
  634. print '</td>';
  635. }
  636. if (!empty($arrayfields['f.ref']['checked'])) {
  637. print "<td>";
  638. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  639. // Picto + Ref
  640. print '<td class="nobordernopadding nowraponall">';
  641. print $objectstatic->getNomUrl(1);
  642. print '</td>';
  643. // Warning
  644. $warnornote = '';
  645. //if ($obj->fk_statut == 1 && $db->jdate($obj->dfv) < ($now - $conf->fichinter->warning_delay)) $warnornote.=img_warning($langs->trans("Late"));
  646. if (!empty($obj->note_private)) {
  647. $warnornote .= ($warnornote ? ' ' : '');
  648. $warnornote .= '<span class="note">';
  649. $warnornote .= '<a href="note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
  650. $warnornote .= '</span>';
  651. }
  652. if ($warnornote) {
  653. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  654. print $warnornote;
  655. print '</td>';
  656. }
  657. // Other picto tool
  658. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  659. $filename = dol_sanitizeFileName($obj->ref);
  660. $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  661. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  662. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  663. print '</td></tr></table>';
  664. print "</td>\n";
  665. if (!$i) {
  666. $totalarray['nbfield']++;
  667. }
  668. }
  669. if (!empty($arrayfields['f.ref_client']['checked'])) {
  670. // Customer ref
  671. print '<td class="nowrap tdoverflowmax200">';
  672. print dol_escape_htmltag($obj->ref_client);
  673. print '</td>';
  674. if (!$i) {
  675. $totalarray['nbfield']++;
  676. }
  677. }
  678. if (!empty($arrayfields['s.nom']['checked'])) {
  679. print '<td>';
  680. print $companystatic->getNomUrl(1, '', 44);
  681. print '</td>';
  682. if (!$i) {
  683. $totalarray['nbfield']++;
  684. }
  685. }
  686. if (!empty($arrayfields['pr.ref']['checked'])) {
  687. print '<td>';
  688. $projetstatic->id = $obj->projet_id;
  689. $projetstatic->ref = $obj->projet_ref;
  690. $projetstatic->title = $obj->projet_title;
  691. if ($projetstatic->id > 0) {
  692. print $projetstatic->getNomUrl(1, '');
  693. }
  694. print '</td>';
  695. if (!$i) {
  696. $totalarray['nbfield']++;
  697. }
  698. }
  699. if (!empty($arrayfields['c.ref']['checked'])) {
  700. print '<td>';
  701. $contratstatic->id = $obj->contrat_id;
  702. $contratstatic->ref = $obj->contrat_ref;
  703. $contratstatic->ref_customer = $obj->contrat_ref_customer;
  704. $contratstatic->ref_supplier = $obj->contrat_ref_supplier;
  705. if ($contratstatic->id > 0) {
  706. print $contratstatic->getNomUrl(1, '');
  707. print '</td>';
  708. }
  709. if (!$i) {
  710. $totalarray['nbfield']++;
  711. }
  712. }
  713. if (!empty($arrayfields['f.description']['checked'])) {
  714. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->description, 1)), 48).'</td>';
  715. if (!$i) {
  716. $totalarray['nbfield']++;
  717. }
  718. }
  719. // Extra fields
  720. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  721. // Fields from hook
  722. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  723. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  724. print $hookmanager->resPrint;
  725. // Date creation
  726. if (!empty($arrayfields['f.datec']['checked'])) {
  727. print '<td class="center">';
  728. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  729. print '</td>';
  730. if (!$i) {
  731. $totalarray['nbfield']++;
  732. }
  733. }
  734. // Date modification
  735. if (!empty($arrayfields['f.tms']['checked'])) {
  736. print '<td class="center">';
  737. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  738. print '</td>';
  739. if (!$i) {
  740. $totalarray['nbfield']++;
  741. }
  742. }
  743. // Note public
  744. if (!empty($arrayfields['f.note_public']['checked'])) {
  745. print '<td class="center">';
  746. print dol_string_nohtmltag($obj->note_public);
  747. print '</td>';
  748. if (!$i) {
  749. $totalarray['nbfield']++;
  750. }
  751. }
  752. // Note private
  753. if (!empty($arrayfields['f.note_private']['checked'])) {
  754. print '<td class="center">';
  755. print dol_string_nohtmltag($obj->note_private);
  756. print '</td>';
  757. if (!$i) {
  758. $totalarray['nbfield']++;
  759. }
  760. }
  761. // Status
  762. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  763. print '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
  764. if (!$i) {
  765. $totalarray['nbfield']++;
  766. }
  767. }
  768. // Fields of detail of line
  769. if (!empty($arrayfields['fd.description']['checked'])) {
  770. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->descriptiondetail, 1)), 48).'</td>';
  771. if (!$i) {
  772. $totalarray['nbfield']++;
  773. }
  774. }
  775. if (!empty($arrayfields['fd.date']['checked'])) {
  776. print '<td class="center">'.dol_print_date($db->jdate($obj->dp), 'dayhour')."</td>\n";
  777. if (!$i) {
  778. $totalarray['nbfield']++;
  779. }
  780. }
  781. if (!empty($arrayfields['fd.duree']['checked'])) {
  782. print '<td class="right">'.convertSecondToTime($obj->duree, 'allhourmin').'</td>';
  783. if (!$i) {
  784. $totalarray['nbfield']++;
  785. }
  786. if (!$i) {
  787. $totalarray['type'][$totalarray['nbfield']] = 'duration';
  788. }
  789. if (!$i) {
  790. $totalarray['pos'][$totalarray['nbfield']] = 'fd.duree';
  791. }
  792. $totalarray['val']['fd.duree'] += $obj->duree;
  793. }
  794. // Action column
  795. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  796. print '<td class="nowrap center">';
  797. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  798. $selected = 0;
  799. if (in_array($obj->rowid, $arrayofselected)) {
  800. $selected = 1;
  801. }
  802. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  803. }
  804. print '</td>';
  805. }
  806. if (!$i) {
  807. $totalarray['nbfield']++;
  808. }
  809. print '</tr>'."\n";
  810. $total += $obj->duree;
  811. $i++;
  812. }
  813. // Show total line
  814. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  815. // If no record found
  816. if ($num == 0) {
  817. $colspan = 1;
  818. foreach ($arrayfields as $key => $val) {
  819. if (!empty($val['checked'])) {
  820. $colspan++;
  821. }
  822. }
  823. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  824. }
  825. $db->free($resql);
  826. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  827. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  828. print $hookmanager->resPrint;
  829. print '</table>'."\n";
  830. print '</div>'."\n";
  831. print '</form>'."\n";
  832. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  833. $hidegeneratedfilelistifempty = 1;
  834. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  835. $hidegeneratedfilelistifempty = 0;
  836. }
  837. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  838. $formfile = new FormFile($db);
  839. // Show list of available documents
  840. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  841. $urlsource .= str_replace('&amp;', '&', $param);
  842. $filedir = $diroutputmassaction;
  843. $genallowed = $user->rights->ficheinter->lire;
  844. $delallowed = $user->rights->ficheinter->creer;
  845. print $formfile->showdocuments('massfilesarea_interventions', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  846. }
  847. // End of page
  848. llxFooter();
  849. $db->close();