list.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829
  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. require '../main.inc.php';
  31. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  32. require_once DOL_DOCUMENT_ROOT.'/contact/class/contact.class.php';
  33. require_once DOL_DOCUMENT_ROOT.'/fichinter/class/fichinter.class.php';
  34. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  35. if (!empty($conf->projet->enabled)) {
  36. require_once DOL_DOCUMENT_ROOT.'/projet/class/project.class.php';
  37. }
  38. if (!empty($conf->contrat->enabled)) {
  39. require_once DOL_DOCUMENT_ROOT.'/contrat/class/contrat.class.php';
  40. }
  41. // Load translation files required by the page
  42. $langs->loadLangs(array('companies', 'bills', 'interventions'));
  43. if (!empty($conf->projet->enabled)) {
  44. $langs->load("projects");
  45. }
  46. if (!empty($conf->contrat->enabled)) {
  47. $langs->load("contracts");
  48. }
  49. $action = GETPOST('action', 'aZ09');
  50. $massaction = GETPOST('massaction', 'alpha');
  51. $show_files = GETPOST('show_files', 'int');
  52. $confirm = GETPOST('confirm', 'alpha');
  53. $toselect = GETPOST('toselect', 'array');
  54. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'interventionlist';
  55. $search_ref = GETPOST('search_ref') ?GETPOST('search_ref', 'alpha') : GETPOST('search_inter', 'alpha');
  56. $search_ref_client = GETPOST('search_ref_client', 'alpha');
  57. $search_company = GETPOST('search_company', 'alpha');
  58. $search_desc = GETPOST('search_desc', 'alpha');
  59. $search_projet_ref = GETPOST('search_projet_ref', 'alpha');
  60. $search_contrat_ref = GETPOST('search_contrat_ref', 'alpha');
  61. $search_status = GETPOST('search_status', 'alpha');
  62. $sall = trim((GETPOST('search_all', 'alphanohtml') != '') ?GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml'));
  63. $optioncss = GETPOST('optioncss', 'alpha');
  64. $socid = GETPOST('socid', 'int');
  65. // Security check
  66. $id = GETPOST('id', 'int');
  67. if ($user->socid) {
  68. $socid = $user->socid;
  69. }
  70. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  71. $diroutputmassaction = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id;
  72. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  73. $sortfield = GETPOST('sortfield', 'aZ09comma');
  74. $sortorder = GETPOST('sortorder', 'aZ09comma');
  75. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  76. if (empty($page) || $page == -1) {
  77. $page = 0;
  78. } // If $page is not defined, or '' or -1
  79. $offset = $limit * $page;
  80. $pageprev = $page - 1;
  81. $pagenext = $page + 1;
  82. if (!$sortorder) {
  83. $sortorder = "DESC";
  84. }
  85. if (!$sortfield) {
  86. $sortfield = "f.ref";
  87. }
  88. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  89. $object = new Fichinter($db);
  90. $hookmanager->initHooks(array('interventionlist'));
  91. $extrafields = new ExtraFields($db);
  92. // fetch optionals attributes and labels
  93. $extrafields->fetch_name_optionals_label($object->table_element);
  94. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  95. // List of fields to search into when doing a "search in all"
  96. $fieldstosearchall = array(
  97. 'f.ref'=>'Ref',
  98. 's.nom'=>"ThirdParty",
  99. 'f.description'=>'Description',
  100. 'f.note_public'=>'NotePublic',
  101. 'fd.description'=>'DescriptionOfLine',
  102. );
  103. if (empty($user->socid)) {
  104. $fieldstosearchall["f.note_private"] = "NotePrivate";
  105. }
  106. if (!empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  107. unset($fieldstosearchall['fd.description']);
  108. }
  109. // Definition of fields for list
  110. $arrayfields = array(
  111. 'f.ref'=>array('label'=>'Ref', 'checked'=>1),
  112. 'f.ref_client'=>array('label'=>'RefCustomer', 'checked'=>1),
  113. 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
  114. 'pr.ref'=>array('label'=>'Project', 'checked'=>1, 'enabled'=>(empty($conf->projet->enabled) ? 0 : 1)),
  115. 'c.ref'=>array('label'=>'Contract', 'checked'=>1, 'enabled'=>(empty($conf->contrat->enabled) ? 0 : 1)),
  116. 'f.description'=>array('label'=>'Description', 'checked'=>1),
  117. 'f.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>500),
  118. 'f.tms'=>array('label'=>'DateModificationShort', 'checked'=>0, 'position'=>500),
  119. 'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
  120. 'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
  121. 'f.fk_statut'=>array('label'=>'Status', 'checked'=>1, 'position'=>1000),
  122. 'fd.description'=>array('label'=>"DescriptionOfLine", 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  123. 'fd.date'=>array('label'=>'DateOfLine', 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  124. 'fd.duree'=>array('label'=>'DurationOfLine', 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  125. );
  126. // Extra fields
  127. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  128. $object->fields = dol_sort_array($object->fields, 'position');
  129. $arrayfields = dol_sort_array($arrayfields, 'position');
  130. /*
  131. * Actions
  132. */
  133. if (GETPOST('cancel', 'alpha')) {
  134. $action = 'list'; $massaction = '';
  135. }
  136. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  137. $massaction = '';
  138. }
  139. $parameters = array('socid'=>$socid);
  140. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  141. if ($reshook < 0) {
  142. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  143. }
  144. if (empty($reshook)) {
  145. // Selection of new fields
  146. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  147. // Purge search criteria
  148. 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
  149. $search_ref = "";
  150. $search_ref_client = "";
  151. $search_company = "";
  152. $search_projet_ref = "";
  153. $search_contrat_ref = "";
  154. $search_desc = "";
  155. $search_status = "";
  156. $toselect = array();
  157. $search_array_options = array();
  158. }
  159. // Mass actions
  160. $objectclass = 'Fichinter';
  161. $objectlabel = 'Interventions';
  162. $permissiontoread = $user->rights->ficheinter->lire;
  163. $permissiontodelete = $user->rights->ficheinter->supprimer;
  164. $uploaddir = $conf->ficheinter->dir_output;
  165. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  166. }
  167. /*
  168. * View
  169. */
  170. $now = dol_now();
  171. $form = new Form($db);
  172. $formfile = new FormFile($db);
  173. $objectstatic = new Fichinter($db);
  174. $companystatic = new Societe($db);
  175. if (!empty($conf->projet->enabled)) {
  176. $projetstatic = new Project($db);
  177. }
  178. if (!empty($conf->contrat->enabled)) {
  179. $contratstatic = new Contrat($db);
  180. }
  181. $title = $langs->trans("ListOfInterventions");
  182. llxHeader('', $title);
  183. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  184. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  185. $atleastonefieldinlines = 0;
  186. foreach ($arrayfields as $tmpkey => $tmpval) {
  187. if (preg_match('/^fd\./', $tmpkey) && !empty($arrayfields[$tmpkey]['checked'])) {
  188. $atleastonefieldinlines++;
  189. break;
  190. }
  191. }
  192. $sql = "SELECT";
  193. $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,";
  194. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  195. $sql .= " fd.rowid as lineid, fd.description as descriptiondetail, fd.date as dp, fd.duree,";
  196. }
  197. $sql .= " s.nom as name, s.rowid as socid, s.client, s.fournisseur, s.email, s.status as thirdpartystatus";
  198. if (!empty($conf->projet->enabled)) {
  199. $sql .= ", pr.rowid as projet_id, pr.ref as projet_ref, pr.title as projet_title";
  200. }
  201. if (!empty($conf->contrat->enabled)) {
  202. $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";
  203. }
  204. // Add fields from extrafields
  205. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  206. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  207. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  208. }
  209. }
  210. // Add fields from hooks
  211. $parameters = array();
  212. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  213. $sql .= $hookmanager->resPrint;
  214. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  215. if (!empty($conf->projet->enabled)) {
  216. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr on f.fk_projet = pr.rowid";
  217. }
  218. if (!empty($conf->contrat->enabled)) {
  219. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat as c on f.fk_contrat = c.rowid";
  220. }
  221. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  222. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  223. }
  224. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  225. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.rowid";
  226. }
  227. // Add table from hooks
  228. $parameters = array();
  229. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  230. $sql .= $hookmanager->resPrint;
  231. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  232. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  233. }
  234. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  235. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  236. $sql .= " AND f.fk_soc = s.rowid";
  237. if ($search_ref) {
  238. $sql .= natural_search('f.ref', $search_ref);
  239. }
  240. if ($search_ref_client) {
  241. $sql .= natural_search('f.ref_client', $search_ref_client);
  242. }
  243. if ($search_company) {
  244. $sql .= natural_search('s.nom', $search_company);
  245. }
  246. if ($search_projet_ref) {
  247. $sql .= natural_search('pr.ref', $search_projet_ref);
  248. }
  249. if ($search_contrat_ref) {
  250. $sql .= natural_search('c.ref', $search_contrat_ref);
  251. }
  252. if ($search_desc) {
  253. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  254. $sql .= natural_search(array('f.description', 'fd.description'), $search_desc);
  255. } else {
  256. $sql .= natural_search(array('f.description'), $search_desc);
  257. }
  258. }
  259. if ($search_status != '' && $search_status >= 0) {
  260. $sql .= ' AND f.fk_statut = '.urlencode($search_status);
  261. }
  262. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  263. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  264. }
  265. if ($socid) {
  266. $sql .= " AND s.rowid = ".((int) $socid);
  267. }
  268. if ($sall) {
  269. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  270. }
  271. // Add where from extra fields
  272. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  273. // Add where from hooks
  274. $parameters = array();
  275. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters); // Note that $action and $object may have been modified by hook
  276. $sql .= $hookmanager->resPrint;
  277. // Add GroupBy from hooks
  278. $parameters = array('all' => $all, 'fieldstosearchall' => $fieldstosearchall);
  279. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  280. $sql .= $hookmanager->resPrint;
  281. $sql .= $db->order($sortfield, $sortorder);
  282. // Count total nb of records
  283. $nbtotalofrecords = '';
  284. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  285. $result = $db->query($sql);
  286. $nbtotalofrecords = $db->num_rows($result);
  287. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  288. $page = 0;
  289. $offset = 0;
  290. }
  291. }
  292. $sql .= $db->plimit($limit + 1, $offset);
  293. //print $sql;
  294. $resql = $db->query($sql);
  295. if ($resql) {
  296. $num = $db->num_rows($resql);
  297. $arrayofselected = is_array($toselect) ? $toselect : array();
  298. if ($socid > 0) {
  299. $soc = new Societe($db);
  300. $soc->fetch($socid);
  301. if (empty($search_company)) {
  302. $search_company = $soc->name;
  303. }
  304. }
  305. $param = '';
  306. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  307. $param .= '&contextpage='.urlencode($contextpage);
  308. }
  309. if ($limit > 0 && $limit != $conf->liste_limit) {
  310. $param .= '&limit='.urlencode($limit);
  311. }
  312. if ($sall) {
  313. $param .= "&sall=".urlencode($sall);
  314. }
  315. if ($socid) {
  316. $param .= "&socid=".urlencode($socid);
  317. }
  318. if ($search_ref) {
  319. $param .= "&search_ref=".urlencode($search_ref);
  320. }
  321. if ($search_ref_client) {
  322. $param .= "&search_ref_client=".urlencode($search_ref_client);
  323. }
  324. if ($search_company) {
  325. $param .= "&search_company=".urlencode($search_company);
  326. }
  327. if ($search_desc) {
  328. $param .= "&search_desc=".urlencode($search_desc);
  329. }
  330. if ($search_status != '' && $search_status > -1) {
  331. $param .= "&search_status=".urlencode($search_status);
  332. }
  333. if ($show_files) {
  334. $param .= '&show_files='.urlencode($show_files);
  335. }
  336. if ($optioncss != '') {
  337. $param .= '&optioncss='.urlencode($optioncss);
  338. }
  339. // Add $param from extra fields
  340. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  341. // List of mass actions available
  342. $arrayofmassactions = array(
  343. 'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  344. 'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  345. //'presend'=>$langs->trans("SendByMail"),
  346. );
  347. if ($user->rights->ficheinter->supprimer) {
  348. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  349. }
  350. if (in_array($massaction, array('presend', 'predelete'))) {
  351. $arrayofmassactions = array();
  352. }
  353. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  354. $newcardbutton = '';
  355. $url = DOL_URL_ROOT.'/fichinter/card.php?action=create';
  356. if (!empty($socid)) {
  357. $url .= '&socid='.$socid;
  358. }
  359. $newcardbutton = dolGetButtonTitle($langs->trans('NewIntervention'), '', 'fa fa-plus-circle', $url, '', $user->rights->ficheinter->creer);
  360. // Lines of title fields
  361. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  362. if ($optioncss != '') {
  363. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  364. }
  365. print '<input type="hidden" name="token" value="'.newToken().'">';
  366. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  367. print '<input type="hidden" name="action" value="list">';
  368. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  369. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  370. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  371. print_barre_liste($title, $page, $_SERVER['PHP_SELF'], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'commercial', 0, $newcardbutton, '', $limit, 0, 0, 1);
  372. $topicmail = "Information";
  373. $modelmail = "intervention";
  374. $objecttmp = new Fichinter($db);
  375. $trackid = 'int'.$object->id;
  376. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  377. if ($sall) {
  378. foreach ($fieldstosearchall as $key => $val) {
  379. $fieldstosearchall[$key] = $langs->trans($val);
  380. }
  381. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).join(', ', $fieldstosearchall).'</div>';
  382. }
  383. $moreforfilter = '';
  384. $parameters = array();
  385. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  386. if (empty($reshook)) {
  387. $moreforfilter .= $hookmanager->resPrint;
  388. } else {
  389. $moreforfilter = $hookmanager->resPrint;
  390. }
  391. if (!empty($moreforfilter)) {
  392. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  393. print $moreforfilter;
  394. print '</div>';
  395. }
  396. if ($massactionbutton) {
  397. $selectedfields .= $form->showCheckAddButtons('checkforselect', 1);
  398. }
  399. print '<div class="div-table-responsive">';
  400. print '<table class="tagtable liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  401. print '<tr class="liste_titre_filter">';
  402. if (!empty($arrayfields['f.ref']['checked'])) {
  403. print '<td class="liste_titre">';
  404. print '<input type="text" class="flat" name="search_ref" value="'.$search_ref.'" size="8">';
  405. print '</td>';
  406. }
  407. if (!empty($arrayfields['f.ref_client']['checked'])) {
  408. print '<td class="liste_titre">';
  409. print '<input type="text" class="flat" name="search_ref_client" value="'.$search_ref_client.'" size="8">';
  410. print '</td>';
  411. }
  412. if (!empty($arrayfields['s.nom']['checked'])) {
  413. print '<td class="liste_titre">';
  414. print '<input type="text" class="flat" name="search_company" value="'.$search_company.'" size="10">';
  415. print '</td>';
  416. }
  417. if (!empty($arrayfields['pr.ref']['checked'])) {
  418. print '<td class="liste_titre">';
  419. print '<input type="text" class="flat" name="search_projet_ref" value="'.$search_projet_ref.'" size="8">';
  420. print '</td>';
  421. }
  422. if (!empty($arrayfields['c.ref']['checked'])) {
  423. print '<td class="liste_titre">';
  424. print '<input type="text" class="flat" name="search_contrat_ref" value="'.$search_contrat_ref.'" size="8">';
  425. print '</td>';
  426. }
  427. if (!empty($arrayfields['f.description']['checked'])) {
  428. print '<td class="liste_titre">';
  429. print '<input type="text" class="flat" name="search_desc" value="'.$search_desc.'" size="12">';
  430. print '</td>';
  431. }
  432. // Extra fields
  433. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  434. // Fields from hook
  435. $parameters = array('arrayfields'=>$arrayfields);
  436. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters); // Note that $action and $object may have been modified by hook
  437. print $hookmanager->resPrint;
  438. if (!empty($arrayfields['f.datec']['checked'])) {
  439. // Date creation
  440. print '<td class="liste_titre">';
  441. print '</td>';
  442. }
  443. if (!empty($arrayfields['f.tms']['checked'])) {
  444. // Date modification
  445. print '<td class="liste_titre">';
  446. print '</td>';
  447. }
  448. if (!empty($arrayfields['f.note_public']['checked'])) {
  449. // Note public
  450. print '<td class="liste_titre">';
  451. print '</td>';
  452. }
  453. if (!empty($arrayfields['f.note_private']['checked'])) {
  454. // Note private
  455. print '<td class="liste_titre">';
  456. print '</td>';
  457. }
  458. // Status
  459. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  460. print '<td class="liste_titre right">';
  461. $tmp = $objectstatic->LibStatut(0); // To load $this->statuts_short
  462. $liststatus = $objectstatic->statuts_short;
  463. if (empty($conf->global->FICHINTER_CLASSIFY_BILLED)) {
  464. unset($liststatus[2]); // Option deprecated. In a future, billed must be managed with a dedicated field to 0 or 1
  465. }
  466. print $form->selectarray('search_status', $liststatus, $search_status, 1, 0, 0, '', 1);
  467. print '</td>';
  468. }
  469. // Fields of detail line
  470. if (!empty($arrayfields['fd.description']['checked'])) {
  471. print '<td class="liste_titre">&nbsp;</td>';
  472. }
  473. if (!empty($arrayfields['fd.date']['checked'])) {
  474. print '<td class="liste_titre">&nbsp;</td>';
  475. }
  476. if (!empty($arrayfields['fd.duree']['checked'])) {
  477. print '<td class="liste_titre">&nbsp;</td>';
  478. }
  479. print '<td class="liste_titre maxwidthsearch">';
  480. $searchpicto = $form->showFilterButtons();
  481. print $searchpicto;
  482. print '</td>';
  483. print "</tr>\n";
  484. print '<tr class="liste_titre">';
  485. if (!empty($arrayfields['f.ref']['checked'])) {
  486. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  487. }
  488. if (!empty($arrayfields['f.ref_client']['checked'])) {
  489. print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], "f.ref_client", "", $param, '', $sortfield, $sortorder);
  490. }
  491. if (!empty($arrayfields['s.nom']['checked'])) {
  492. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  493. }
  494. if (!empty($arrayfields['pr.ref']['checked'])) {
  495. print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], "pr.ref", "", $param, '', $sortfield, $sortorder);
  496. }
  497. if (!empty($arrayfields['c.ref']['checked'])) {
  498. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
  499. }
  500. if (!empty($arrayfields['f.description']['checked'])) {
  501. print_liste_field_titre($arrayfields['f.description']['label'], $_SERVER["PHP_SELF"], "f.description", "", $param, '', $sortfield, $sortorder);
  502. }
  503. // Extra fields
  504. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  505. // Hook fields
  506. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  507. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  508. print $hookmanager->resPrint;
  509. if (!empty($arrayfields['f.datec']['checked'])) {
  510. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  511. }
  512. if (!empty($arrayfields['f.tms']['checked'])) {
  513. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  514. }
  515. if (!empty($arrayfields['f.note_public']['checked'])) {
  516. print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  517. }
  518. if (!empty($arrayfields['f.note_private']['checked'])) {
  519. print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  520. }
  521. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  522. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  523. }
  524. if (!empty($arrayfields['fd.description']['checked'])) {
  525. print_liste_field_titre($arrayfields['fd.description']['label'], $_SERVER["PHP_SELF"], '');
  526. }
  527. if (!empty($arrayfields['fd.date']['checked'])) {
  528. print_liste_field_titre($arrayfields['fd.date']['label'], $_SERVER["PHP_SELF"], "fd.date", "", $param, '', $sortfield, $sortorder, 'center ');
  529. }
  530. if (!empty($arrayfields['fd.duree']['checked'])) {
  531. print_liste_field_titre($arrayfields['fd.duree']['label'], $_SERVER["PHP_SELF"], "fd.duree", "", $param, '', $sortfield, $sortorder, 'right ');
  532. }
  533. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  534. print "</tr>\n";
  535. $total = 0;
  536. $i = 0;
  537. $totalarray = array();
  538. $totalarray['nbfield'] = 0;
  539. $totalarray['val'] = array();
  540. $totalarray['val']['fd.duree'] = 0;
  541. while ($i < min($num, $limit)) {
  542. $obj = $db->fetch_object($resql);
  543. $objectstatic->id = $obj->rowid;
  544. $objectstatic->ref = $obj->ref;
  545. $objectstatic->ref_client = $obj->ref_client;
  546. $objectstatic->statut = $obj->status;
  547. $objectstatic->status = $obj->status;
  548. $companystatic->name = $obj->name;
  549. $companystatic->id = $obj->socid;
  550. $companystatic->client = $obj->client;
  551. $companystatic->fournisseur = $obj->fournisseur;
  552. $companystatic->email = $obj->email;
  553. $companystatic->status = $obj->thirdpartystatus;
  554. print '<tr class="oddeven">';
  555. if (!empty($arrayfields['f.ref']['checked'])) {
  556. print "<td>";
  557. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  558. // Picto + Ref
  559. print '<td class="nobordernopadding nowrap">';
  560. print $objectstatic->getNomUrl(1);
  561. print '</td>';
  562. // Warning
  563. $warnornote = '';
  564. //if ($obj->fk_statut == 1 && $db->jdate($obj->dfv) < ($now - $conf->fichinter->warning_delay)) $warnornote.=img_warning($langs->trans("Late"));
  565. if (!empty($obj->note_private)) {
  566. $warnornote .= ($warnornote ? ' ' : '');
  567. $warnornote .= '<span class="note">';
  568. $warnornote .= '<a href="note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
  569. $warnornote .= '</span>';
  570. }
  571. if ($warnornote) {
  572. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  573. print $warnornote;
  574. print '</td>';
  575. }
  576. // Other picto tool
  577. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  578. $filename = dol_sanitizeFileName($obj->ref);
  579. $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  580. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  581. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  582. print '</td></tr></table>';
  583. print "</td>\n";
  584. if (!$i) {
  585. $totalarray['nbfield']++;
  586. }
  587. }
  588. if (!empty($arrayfields['f.ref_client']['checked'])) {
  589. // Customer ref
  590. print '<td class="nowrap tdoverflowmax200">';
  591. print $obj->ref_client;
  592. print '</td>';
  593. if (!$i) {
  594. $totalarray['nbfield']++;
  595. }
  596. }
  597. if (!empty($arrayfields['s.nom']['checked'])) {
  598. print '<td>';
  599. print $companystatic->getNomUrl(1, '', 44);
  600. print '</td>';
  601. if (!$i) {
  602. $totalarray['nbfield']++;
  603. }
  604. }
  605. if (!empty($arrayfields['pr.ref']['checked'])) {
  606. print '<td>';
  607. $projetstatic->id = $obj->projet_id;
  608. $projetstatic->ref = $obj->projet_ref;
  609. $projetstatic->title = $obj->projet_title;
  610. if ($projetstatic->id > 0) {
  611. print $projetstatic->getNomUrl(1, '');
  612. }
  613. print '</td>';
  614. if (!$i) {
  615. $totalarray['nbfield']++;
  616. }
  617. }
  618. if (!empty($arrayfields['c.ref']['checked'])) {
  619. print '<td>';
  620. $contratstatic->id = $obj->contrat_id;
  621. $contratstatic->ref = $obj->contrat_ref;
  622. $contratstatic->ref_customer = $obj->contrat_ref_customer;
  623. $contratstatic->ref_supplier = $obj->contrat_ref_supplier;
  624. if ($contratstatic->id > 0) {
  625. print $contratstatic->getNomUrl(1, '');
  626. print '</td>';
  627. }
  628. if (!$i) {
  629. $totalarray['nbfield']++;
  630. }
  631. }
  632. if (!empty($arrayfields['f.description']['checked'])) {
  633. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->description, 1)), 48).'</td>';
  634. if (!$i) {
  635. $totalarray['nbfield']++;
  636. }
  637. }
  638. // Extra fields
  639. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  640. // Fields from hook
  641. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  642. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  643. print $hookmanager->resPrint;
  644. // Date creation
  645. if (!empty($arrayfields['f.datec']['checked'])) {
  646. print '<td class="center">';
  647. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  648. print '</td>';
  649. if (!$i) {
  650. $totalarray['nbfield']++;
  651. }
  652. }
  653. // Date modification
  654. if (!empty($arrayfields['f.tms']['checked'])) {
  655. print '<td class="center">';
  656. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  657. print '</td>';
  658. if (!$i) {
  659. $totalarray['nbfield']++;
  660. }
  661. }
  662. // Note public
  663. if (!empty($arrayfields['f.note_public']['checked'])) {
  664. print '<td class="center">';
  665. print dol_escape_htmltag($obj->note_public);
  666. print '</td>';
  667. if (!$i) {
  668. $totalarray['nbfield']++;
  669. }
  670. }
  671. // Note private
  672. if (!empty($arrayfields['f.note_private']['checked'])) {
  673. print '<td class="center">';
  674. print dol_escape_htmltag($obj->note_private);
  675. print '</td>';
  676. if (!$i) {
  677. $totalarray['nbfield']++;
  678. }
  679. }
  680. // Status
  681. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  682. print '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
  683. if (!$i) {
  684. $totalarray['nbfield']++;
  685. }
  686. }
  687. // Fields of detail of line
  688. if (!empty($arrayfields['fd.description']['checked'])) {
  689. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->descriptiondetail, 1)), 48).'</td>';
  690. if (!$i) {
  691. $totalarray['nbfield']++;
  692. }
  693. }
  694. if (!empty($arrayfields['fd.date']['checked'])) {
  695. print '<td class="center">'.dol_print_date($db->jdate($obj->dp), 'dayhour')."</td>\n";
  696. if (!$i) {
  697. $totalarray['nbfield']++;
  698. }
  699. }
  700. if (!empty($arrayfields['fd.duree']['checked'])) {
  701. print '<td class="right">'.convertSecondToTime($obj->duree, 'allhourmin').'</td>';
  702. if (!$i) {
  703. $totalarray['nbfield']++;
  704. }
  705. if (!$i) {
  706. $totalarray['type'][$totalarray['nbfield']] = 'duration';
  707. $totalarray['pos'][$totalarray['nbfield']] = 'fd.duree';
  708. }
  709. $totalarray['val']['fd.duree'] += $obj->duree;
  710. }
  711. // Action column
  712. print '<td class="nowrap center">';
  713. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  714. $selected = 0;
  715. if (in_array($obj->rowid, $arrayofselected)) {
  716. $selected = 1;
  717. }
  718. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  719. }
  720. print '</td>';
  721. if (!$i) {
  722. $totalarray['nbfield']++;
  723. }
  724. print "</tr>\n";
  725. $total += $obj->duree;
  726. $i++;
  727. }
  728. // Show total line
  729. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  730. $db->free($resql);
  731. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  732. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters); // Note that $action and $object may have been modified by hook
  733. print $hookmanager->resPrint;
  734. print '</table>'."\n";
  735. print '</div>';
  736. print "</form>\n";
  737. $hidegeneratedfilelistifempty = 1;
  738. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  739. $hidegeneratedfilelistifempty = 0;
  740. }
  741. // Show list of available documents
  742. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  743. $urlsource .= str_replace('&amp;', '&', $param);
  744. $filedir = $diroutputmassaction;
  745. $genallowed = $user->rights->ficheinter->lire;
  746. $delallowed = $user->rights->ficheinter->creer;
  747. print $formfile->showdocuments('massfilesarea_interventions', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  748. } else {
  749. dol_print_error($db);
  750. }
  751. llxFooter();
  752. $db->close();