list.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922
  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->project->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->project->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. $diroutputmassaction = $conf->ficheinter->dir_output.'/temp/massgeneration/'.$user->id;
  66. // Load variable for pagination
  67. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  68. $sortfield = GETPOST('sortfield', 'aZ09comma');
  69. $sortorder = GETPOST('sortorder', 'aZ09comma');
  70. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  71. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  72. // If $page is not defined, or '' or -1 or if we click on clear filters
  73. $page = 0;
  74. }
  75. $offset = $limit * $page;
  76. $pageprev = $page - 1;
  77. $pagenext = $page + 1;
  78. if (!$sortorder) {
  79. $sortorder = "DESC";
  80. }
  81. if (!$sortfield) {
  82. $sortfield = "f.ref";
  83. }
  84. // Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
  85. $object = new Fichinter($db);
  86. $hookmanager->initHooks(array('interventionlist'));
  87. $extrafields = new ExtraFields($db);
  88. // Fetch optionals attributes and labels
  89. $extrafields->fetch_name_optionals_label($object->table_element);
  90. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  91. // List of fields to search into when doing a "search in all"
  92. $fieldstosearchall = array(
  93. 'f.ref'=>'Ref',
  94. 's.nom'=>"ThirdParty",
  95. 'f.description'=>'Description',
  96. 'f.note_public'=>'NotePublic',
  97. 'fd.description'=>'DescriptionOfLine',
  98. );
  99. if (empty($user->socid)) {
  100. $fieldstosearchall["f.note_private"] = "NotePrivate";
  101. }
  102. if (!empty($conf->global->FICHINTER_DISABLE_DETAILS)) {
  103. unset($fieldstosearchall['fd.description']);
  104. }
  105. // Definition of fields for list
  106. $arrayfields = array(
  107. 'f.ref'=>array('label'=>'Ref', 'checked'=>1),
  108. 'f.ref_client'=>array('label'=>'RefCustomer', 'checked'=>1),
  109. 's.nom'=>array('label'=>'ThirdParty', 'checked'=>1),
  110. 'pr.ref'=>array('label'=>'Project', 'checked'=>1, 'enabled'=>(empty($conf->project->enabled) ? 0 : 1)),
  111. 'c.ref'=>array('label'=>'Contract', 'checked'=>1, 'enabled'=>(empty($conf->contrat->enabled) ? 0 : 1)),
  112. 'f.description'=>array('label'=>'Description', 'checked'=>1),
  113. 'f.datec'=>array('label'=>'DateCreation', 'checked'=>0, 'position'=>500),
  114. 'f.tms'=>array('label'=>'DateModificationShort', 'checked'=>0, 'position'=>500),
  115. 'f.note_public'=>array('label'=>'NotePublic', 'checked'=>0, 'position'=>510, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PUBLIC_NOTES))),
  116. 'f.note_private'=>array('label'=>'NotePrivate', 'checked'=>0, 'position'=>511, 'enabled'=>(empty($conf->global->MAIN_LIST_ALLOW_PRIVATE_NOTES))),
  117. 'f.fk_statut'=>array('label'=>'Status', 'checked'=>1, 'position'=>1000),
  118. 'fd.description'=>array('label'=>"DescriptionOfLine", 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  119. 'fd.date'=>array('label'=>'DateOfLine', 'checked'=>1, 'enabled'=>empty($conf->global->FICHINTER_DISABLE_DETAILS) ? 1 : 0),
  120. '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
  121. );
  122. // Extra fields
  123. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  124. $object->fields = dol_sort_array($object->fields, 'position');
  125. $arrayfields = dol_sort_array($arrayfields, 'position');
  126. // Security check
  127. $id = GETPOST('id', 'int');
  128. if ($user->socid) {
  129. $socid = $user->socid;
  130. }
  131. $result = restrictedArea($user, 'ficheinter', $id, 'fichinter');
  132. $permissiontoread = $user->rights->ficheinter->lire;
  133. $permissiontodelete = $user->rights->ficheinter->supprimer;
  134. /*
  135. * Actions
  136. */
  137. if (GETPOST('cancel', 'alpha')) {
  138. $action = 'list';
  139. $massaction = '';
  140. }
  141. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  142. $massaction = '';
  143. }
  144. $parameters = array('socid'=>$socid);
  145. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  146. if ($reshook < 0) {
  147. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  148. }
  149. if (empty($reshook)) {
  150. // Selection of new fields
  151. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  152. // Purge search criteria
  153. 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
  154. $search_ref = "";
  155. $search_ref_client = "";
  156. $search_company = "";
  157. $search_projet_ref = "";
  158. $search_contrat_ref = "";
  159. $search_desc = "";
  160. $search_status = "";
  161. $toselect = array();
  162. $search_array_options = array();
  163. }
  164. // Mass actions
  165. $objectclass = 'Fichinter';
  166. $objectlabel = 'Interventions';
  167. $uploaddir = $conf->ficheinter->dir_output;
  168. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  169. }
  170. /*
  171. * View
  172. */
  173. $form = new Form($db);
  174. $formfile = new FormFile($db);
  175. $objectstatic = new Fichinter($db);
  176. $companystatic = new Societe($db);
  177. if (!empty($conf->project->enabled)) {
  178. $projetstatic = new Project($db);
  179. }
  180. if (!empty($conf->contrat->enabled)) {
  181. $contratstatic = new Contrat($db);
  182. }
  183. $now = dol_now();
  184. $help_url = '';
  185. $title = $langs->trans("ListOfInterventions");
  186. $morejs = array();
  187. $morecss = array();
  188. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  189. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  190. $atleastonefieldinlines = 0;
  191. foreach ($arrayfields as $tmpkey => $tmpval) {
  192. if (preg_match('/^fd\./', $tmpkey) && !empty($arrayfields[$tmpkey]['checked'])) {
  193. $atleastonefieldinlines++;
  194. break;
  195. }
  196. }
  197. $sql = "SELECT";
  198. $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,";
  199. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  200. $sql .= " fd.rowid as lineid, fd.description as descriptiondetail, fd.date as dp, fd.duree,";
  201. }
  202. $sql .= " s.nom as name, s.rowid as socid, s.client, s.fournisseur, s.email, s.status as thirdpartystatus";
  203. if (!empty($conf->project->enabled)) {
  204. $sql .= ", pr.rowid as projet_id, pr.ref as projet_ref, pr.title as projet_title";
  205. }
  206. if (!empty($conf->contrat->enabled)) {
  207. $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";
  208. }
  209. // Add fields from extrafields
  210. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  211. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  212. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  213. }
  214. }
  215. // Add fields from hooks
  216. $parameters = array();
  217. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters); // Note that $action and $object may have been modified by hook
  218. $sql .= $hookmanager->resPrint;
  219. $sql .= " FROM ".MAIN_DB_PREFIX."fichinter as f";
  220. if (!empty($conf->project->enabled)) {
  221. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."projet as pr on f.fk_projet = pr.rowid";
  222. }
  223. if (!empty($conf->contrat->enabled)) {
  224. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."contrat as c on f.fk_contrat = c.rowid";
  225. }
  226. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  227. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (f.rowid = ef.fk_object)";
  228. }
  229. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  230. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX."fichinterdet as fd ON fd.fk_fichinter = f.rowid";
  231. }
  232. // Add table from hooks
  233. $parameters = array();
  234. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  235. $sql .= $hookmanager->resPrint;
  236. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  237. $sql .= ", ".MAIN_DB_PREFIX."societe_commerciaux as sc";
  238. }
  239. $sql .= ", ".MAIN_DB_PREFIX."societe as s";
  240. $sql .= " WHERE f.entity IN (".getEntity('intervention').")";
  241. $sql .= " AND f.fk_soc = s.rowid";
  242. if ($search_ref) {
  243. $sql .= natural_search('f.ref', $search_ref);
  244. }
  245. if ($search_ref_client) {
  246. $sql .= natural_search('f.ref_client', $search_ref_client);
  247. }
  248. if ($search_company) {
  249. $sql .= natural_search('s.nom', $search_company);
  250. }
  251. if ($search_projet_ref) {
  252. $sql .= natural_search('pr.ref', $search_projet_ref);
  253. }
  254. if ($search_contrat_ref) {
  255. $sql .= natural_search('c.ref', $search_contrat_ref);
  256. }
  257. if ($search_desc) {
  258. if (empty($conf->global->FICHINTER_DISABLE_DETAILS) && $atleastonefieldinlines) {
  259. $sql .= natural_search(array('f.description', 'fd.description'), $search_desc);
  260. } else {
  261. $sql .= natural_search(array('f.description'), $search_desc);
  262. }
  263. }
  264. if ($search_status != '' && $search_status >= 0) {
  265. $sql .= ' AND f.fk_statut = '.urlencode($search_status);
  266. }
  267. if (empty($user->rights->societe->client->voir) && empty($socid)) {
  268. $sql .= " AND s.rowid = sc.fk_soc AND sc.fk_user = ".((int) $user->id);
  269. }
  270. if ($socid) {
  271. $sql .= " AND s.rowid = ".((int) $socid);
  272. }
  273. if ($sall) {
  274. $sql .= natural_search(array_keys($fieldstosearchall), $sall);
  275. }
  276. // Add where from extra fields
  277. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  278. // Add where from hooks
  279. $parameters = array();
  280. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  281. $sql .= $hookmanager->resPrint;
  282. // Add GroupBy from hooks
  283. $parameters = array('search_all' => $sall, 'fieldstosearchall' => $fieldstosearchall);
  284. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  285. $sql .= $hookmanager->resPrint;
  286. // Count total nb of records
  287. $nbtotalofrecords = '';
  288. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  289. /* This old and fast method to get and count full list returns all record so use a high amount of memory. */
  290. $resql = $db->query($sql);
  291. $nbtotalofrecords = $db->num_rows($resql);
  292. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  293. /*$sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  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 of record found is smaller than page * limit, 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 ($sall) {
  347. $param .= "&sall=".urlencode($sall);
  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 ($sall) {
  415. foreach ($fieldstosearchall as $key => $val) {
  416. $fieldstosearchall[$key] = $langs->trans($val);
  417. }
  418. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $sall).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 (!empty($conf->global->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);
  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 (empty($conf->global->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. if (!empty($arrayfields['f.ref']['checked'])) {
  539. print_liste_field_titre($arrayfields['f.ref']['label'], $_SERVER["PHP_SELF"], "f.ref", "", $param, '', $sortfield, $sortorder);
  540. }
  541. if (!empty($arrayfields['f.ref_client']['checked'])) {
  542. print_liste_field_titre($arrayfields['f.ref_client']['label'], $_SERVER["PHP_SELF"], "f.ref_client", "", $param, '', $sortfield, $sortorder);
  543. }
  544. if (!empty($arrayfields['s.nom']['checked'])) {
  545. print_liste_field_titre($arrayfields['s.nom']['label'], $_SERVER["PHP_SELF"], "s.nom", "", $param, '', $sortfield, $sortorder);
  546. }
  547. if (!empty($arrayfields['pr.ref']['checked'])) {
  548. print_liste_field_titre($arrayfields['pr.ref']['label'], $_SERVER["PHP_SELF"], "pr.ref", "", $param, '', $sortfield, $sortorder);
  549. }
  550. if (!empty($arrayfields['c.ref']['checked'])) {
  551. print_liste_field_titre($arrayfields['c.ref']['label'], $_SERVER["PHP_SELF"], "c.ref", "", $param, '', $sortfield, $sortorder);
  552. }
  553. if (!empty($arrayfields['f.description']['checked'])) {
  554. print_liste_field_titre($arrayfields['f.description']['label'], $_SERVER["PHP_SELF"], "f.description", "", $param, '', $sortfield, $sortorder);
  555. }
  556. // Extra fields
  557. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  558. // Hook fields
  559. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  560. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters); // Note that $action and $object may have been modified by hook
  561. print $hookmanager->resPrint;
  562. if (!empty($arrayfields['f.datec']['checked'])) {
  563. print_liste_field_titre($arrayfields['f.datec']['label'], $_SERVER["PHP_SELF"], "f.datec", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  564. }
  565. if (!empty($arrayfields['f.tms']['checked'])) {
  566. print_liste_field_titre($arrayfields['f.tms']['label'], $_SERVER["PHP_SELF"], "f.tms", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  567. }
  568. if (!empty($arrayfields['f.note_public']['checked'])) {
  569. print_liste_field_titre($arrayfields['f.note_public']['label'], $_SERVER["PHP_SELF"], "f.note_public", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  570. }
  571. if (!empty($arrayfields['f.note_private']['checked'])) {
  572. print_liste_field_titre($arrayfields['f.note_private']['label'], $_SERVER["PHP_SELF"], "f.note_private", "", $param, '', $sortfield, $sortorder, 'center nowrap ');
  573. }
  574. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  575. print_liste_field_titre($arrayfields['f.fk_statut']['label'], $_SERVER["PHP_SELF"], "f.fk_statut", "", $param, '', $sortfield, $sortorder, 'right ');
  576. }
  577. if (!empty($arrayfields['fd.description']['checked'])) {
  578. print_liste_field_titre($arrayfields['fd.description']['label'], $_SERVER["PHP_SELF"], '');
  579. }
  580. if (!empty($arrayfields['fd.date']['checked'])) {
  581. print_liste_field_titre($arrayfields['fd.date']['label'], $_SERVER["PHP_SELF"], "fd.date", "", $param, '', $sortfield, $sortorder, 'center ');
  582. }
  583. if (!empty($arrayfields['fd.duree']['checked'])) {
  584. print_liste_field_titre($arrayfields['fd.duree']['label'], $_SERVER["PHP_SELF"], "fd.duree", "", $param, '', $sortfield, $sortorder, 'right ');
  585. }
  586. print_liste_field_titre($selectedfields, $_SERVER["PHP_SELF"], "", '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ');
  587. print "</tr>\n";
  588. // Loop on record
  589. // --------------------------------------------------------------------
  590. $total = 0;
  591. $i = 0;
  592. $savnbfield = $totalarray['nbfield'];
  593. $totalarray = array();
  594. $totalarray['nbfield'] = 0;
  595. $totalarray['val'] = array();
  596. $totalarray['val']['fd.duree'] = 0;
  597. $imaxinloop = ($limit ? min($num, $limit) : $num);
  598. while ($i < $imaxinloop) {
  599. $obj = $db->fetch_object($resql);
  600. if (empty($obj)) {
  601. break; // Should not happen
  602. }
  603. // Store properties in $object
  604. //$object->setVarsFromFetchObj($obj);
  605. $objectstatic->id = $obj->rowid;
  606. $objectstatic->ref = $obj->ref;
  607. $objectstatic->ref_client = $obj->ref_client;
  608. $objectstatic->statut = $obj->status;
  609. $objectstatic->status = $obj->status;
  610. $companystatic->name = $obj->name;
  611. $companystatic->id = $obj->socid;
  612. $companystatic->client = $obj->client;
  613. $companystatic->fournisseur = $obj->fournisseur;
  614. $companystatic->email = $obj->email;
  615. $companystatic->status = $obj->thirdpartystatus;
  616. print '<tr class="oddeven">';
  617. if (!empty($arrayfields['f.ref']['checked'])) {
  618. print "<td>";
  619. print '<table class="nobordernopadding"><tr class="nocellnopadd">';
  620. // Picto + Ref
  621. print '<td class="nobordernopadding nowraponall">';
  622. print $objectstatic->getNomUrl(1);
  623. print '</td>';
  624. // Warning
  625. $warnornote = '';
  626. //if ($obj->fk_statut == 1 && $db->jdate($obj->dfv) < ($now - $conf->fichinter->warning_delay)) $warnornote.=img_warning($langs->trans("Late"));
  627. if (!empty($obj->note_private)) {
  628. $warnornote .= ($warnornote ? ' ' : '');
  629. $warnornote .= '<span class="note">';
  630. $warnornote .= '<a href="note.php?id='.$obj->rowid.'">'.img_picto($langs->trans("ViewPrivateNote"), 'object_generic').'</a>';
  631. $warnornote .= '</span>';
  632. }
  633. if ($warnornote) {
  634. print '<td style="min-width: 20px" class="nobordernopadding nowrap">';
  635. print $warnornote;
  636. print '</td>';
  637. }
  638. // Other picto tool
  639. print '<td width="16" class="right nobordernopadding hideonsmartphone">';
  640. $filename = dol_sanitizeFileName($obj->ref);
  641. $filedir = $conf->ficheinter->dir_output.'/'.dol_sanitizeFileName($obj->ref);
  642. $urlsource = $_SERVER['PHP_SELF'].'?id='.$obj->rowid;
  643. print $formfile->getDocumentsLink($objectstatic->element, $filename, $filedir);
  644. print '</td></tr></table>';
  645. print "</td>\n";
  646. if (!$i) {
  647. $totalarray['nbfield']++;
  648. }
  649. }
  650. if (!empty($arrayfields['f.ref_client']['checked'])) {
  651. // Customer ref
  652. print '<td class="nowrap tdoverflowmax200">';
  653. print dol_escape_htmltag($obj->ref_client);
  654. print '</td>';
  655. if (!$i) {
  656. $totalarray['nbfield']++;
  657. }
  658. }
  659. if (!empty($arrayfields['s.nom']['checked'])) {
  660. print '<td>';
  661. print $companystatic->getNomUrl(1, '', 44);
  662. print '</td>';
  663. if (!$i) {
  664. $totalarray['nbfield']++;
  665. }
  666. }
  667. if (!empty($arrayfields['pr.ref']['checked'])) {
  668. print '<td>';
  669. $projetstatic->id = $obj->projet_id;
  670. $projetstatic->ref = $obj->projet_ref;
  671. $projetstatic->title = $obj->projet_title;
  672. if ($projetstatic->id > 0) {
  673. print $projetstatic->getNomUrl(1, '');
  674. }
  675. print '</td>';
  676. if (!$i) {
  677. $totalarray['nbfield']++;
  678. }
  679. }
  680. if (!empty($arrayfields['c.ref']['checked'])) {
  681. print '<td>';
  682. $contratstatic->id = $obj->contrat_id;
  683. $contratstatic->ref = $obj->contrat_ref;
  684. $contratstatic->ref_customer = $obj->contrat_ref_customer;
  685. $contratstatic->ref_supplier = $obj->contrat_ref_supplier;
  686. if ($contratstatic->id > 0) {
  687. print $contratstatic->getNomUrl(1, '');
  688. print '</td>';
  689. }
  690. if (!$i) {
  691. $totalarray['nbfield']++;
  692. }
  693. }
  694. if (!empty($arrayfields['f.description']['checked'])) {
  695. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->description, 1)), 48).'</td>';
  696. if (!$i) {
  697. $totalarray['nbfield']++;
  698. }
  699. }
  700. // Extra fields
  701. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  702. // Fields from hook
  703. $parameters = array('arrayfields'=>$arrayfields, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  704. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters); // Note that $action and $object may have been modified by hook
  705. print $hookmanager->resPrint;
  706. // Date creation
  707. if (!empty($arrayfields['f.datec']['checked'])) {
  708. print '<td class="center">';
  709. print dol_print_date($db->jdate($obj->date_creation), 'dayhour', 'tzuser');
  710. print '</td>';
  711. if (!$i) {
  712. $totalarray['nbfield']++;
  713. }
  714. }
  715. // Date modification
  716. if (!empty($arrayfields['f.tms']['checked'])) {
  717. print '<td class="center">';
  718. print dol_print_date($db->jdate($obj->date_update), 'dayhour', 'tzuser');
  719. print '</td>';
  720. if (!$i) {
  721. $totalarray['nbfield']++;
  722. }
  723. }
  724. // Note public
  725. if (!empty($arrayfields['f.note_public']['checked'])) {
  726. print '<td class="center">';
  727. print dol_string_nohtmltag($obj->note_public);
  728. print '</td>';
  729. if (!$i) {
  730. $totalarray['nbfield']++;
  731. }
  732. }
  733. // Note private
  734. if (!empty($arrayfields['f.note_private']['checked'])) {
  735. print '<td class="center">';
  736. print dol_string_nohtmltag($obj->note_private);
  737. print '</td>';
  738. if (!$i) {
  739. $totalarray['nbfield']++;
  740. }
  741. }
  742. // Status
  743. if (!empty($arrayfields['f.fk_statut']['checked'])) {
  744. print '<td class="right">'.$objectstatic->getLibStatut(5).'</td>';
  745. if (!$i) {
  746. $totalarray['nbfield']++;
  747. }
  748. }
  749. // Fields of detail of line
  750. if (!empty($arrayfields['fd.description']['checked'])) {
  751. print '<td>'.dol_trunc(dolGetFirstLineOfText(dol_string_nohtmltag($obj->descriptiondetail, 1)), 48).'</td>';
  752. if (!$i) {
  753. $totalarray['nbfield']++;
  754. }
  755. }
  756. if (!empty($arrayfields['fd.date']['checked'])) {
  757. print '<td class="center">'.dol_print_date($db->jdate($obj->dp), 'dayhour')."</td>\n";
  758. if (!$i) {
  759. $totalarray['nbfield']++;
  760. }
  761. }
  762. if (!empty($arrayfields['fd.duree']['checked'])) {
  763. print '<td class="right">'.convertSecondToTime($obj->duree, 'allhourmin').'</td>';
  764. if (!$i) {
  765. $totalarray['nbfield']++;
  766. }
  767. if (!$i) {
  768. $totalarray['type'][$totalarray['nbfield']] = 'duration';
  769. }
  770. if (!$i) {
  771. $totalarray['pos'][$totalarray['nbfield']] = 'fd.duree';
  772. }
  773. $totalarray['val']['fd.duree'] += $obj->duree;
  774. }
  775. // Action column
  776. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  777. print '<td class="nowrap center">';
  778. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  779. $selected = 0;
  780. if (in_array($obj->rowid, $arrayofselected)) {
  781. $selected = 1;
  782. }
  783. print '<input id="cb'.$obj->rowid.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$obj->rowid.'"'.($selected ? ' checked="checked"' : '').'>';
  784. }
  785. print '</td>';
  786. }
  787. if (!$i) {
  788. $totalarray['nbfield']++;
  789. }
  790. print '</tr>'."\n";
  791. $total += $obj->duree;
  792. $i++;
  793. }
  794. // Show total line
  795. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  796. // If no record found
  797. if ($num == 0) {
  798. $colspan = 1;
  799. foreach ($arrayfields as $key => $val) {
  800. if (!empty($val['checked'])) {
  801. $colspan++;
  802. }
  803. }
  804. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  805. }
  806. $db->free($resql);
  807. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  808. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  809. print $hookmanager->resPrint;
  810. print '</table>'."\n";
  811. print '</div>'."\n";
  812. print '</form>'."\n";
  813. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  814. $hidegeneratedfilelistifempty = 1;
  815. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  816. $hidegeneratedfilelistifempty = 0;
  817. }
  818. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  819. $formfile = new FormFile($db);
  820. // Show list of available documents
  821. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  822. $urlsource .= str_replace('&amp;', '&', $param);
  823. $filedir = $diroutputmassaction;
  824. $genallowed = $user->rights->ficheinter->lire;
  825. $delallowed = $user->rights->ficheinter->creer;
  826. print $formfile->showdocuments('massfilesarea_interventions', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  827. }
  828. // End of page
  829. llxFooter();
  830. $db->close();