list.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Alexandre Spangaro <aspangaro@open-dsi.fr>
  4. * Copyright (C) 2018 Ferran Marcet <fmarcet@2byte.es>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file htdocs/asset/list.php
  21. * \ingroup asset
  22. * \brief List page for asset
  23. */
  24. // Load Dolibarr environment
  25. require '../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/asset/class/asset.class.php';
  30. // Load translation files required by the page
  31. $langs->loadLangs(array("assets", "other"));
  32. // Get parameters
  33. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  34. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  35. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  36. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  37. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  38. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  39. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'assetlist'; // To manage different context of search
  40. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  41. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  42. $mode = GETPOST('mode', 'alpha'); // mode view (kanban or common)
  43. $id = GETPOST('id', 'int');
  44. // Load variable for pagination
  45. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  46. $sortfield = GETPOST('sortfield', 'aZ09comma');
  47. $sortorder = GETPOST('sortorder', 'aZ09comma');
  48. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  49. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  50. $page = 0;
  51. } // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  52. $offset = $limit * $page;
  53. $pageprev = $page - 1;
  54. $pagenext = $page + 1;
  55. // Initialize technical objects
  56. $object = new Asset($db);
  57. $extrafields = new ExtraFields($db);
  58. $diroutputmassaction = $conf->asset->dir_output.'/temp/massgeneration/'.$user->id;
  59. $hookmanager->initHooks(array('assetlist')); // Note that conf->hooks_modules contains array
  60. // Fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  63. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  64. // Default sort order (if not yet defined by previous GETPOST)
  65. if (!$sortfield) {
  66. reset($object->fields); // Reset is required to avoid key() to return null.
  67. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "ASC";
  71. }
  72. // Initialize array of search criterias
  73. $search_all = GETPOST('search_all', 'alphanohtml');
  74. $search = array();
  75. foreach ($object->fields as $key => $val) {
  76. if (GETPOST('search_'.$key, 'alpha') !== '') {
  77. $search[$key] = GETPOST('search_'.$key, 'alpha');
  78. }
  79. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  80. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  81. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  82. }
  83. }
  84. // List of fields to search into when doing a "search in all"
  85. $fieldstosearchall = array();
  86. foreach ($object->fields as $key => $val) {
  87. if (!empty($val['searchall'])) {
  88. $fieldstosearchall['t.'.$key] = $val['label'];
  89. }
  90. }
  91. // Definition of array of fields for columns
  92. $arrayfields = array();
  93. foreach ($object->fields as $key => $val) {
  94. // If $val['visible']==0, then we never show the field
  95. if (!empty($val['visible'])) {
  96. $visible = (int) dol_eval($val['visible'], 1);
  97. $arrayfields['t.'.$key] = array(
  98. 'label'=>$val['label'],
  99. 'checked'=>(($visible < 0) ? 0 : 1),
  100. 'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1)),
  101. 'position'=>$val['position'],
  102. 'help'=> isset($val['help']) ? $val['help'] : ''
  103. );
  104. }
  105. }
  106. // Extra fields
  107. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  108. $object->fields = dol_sort_array($object->fields, 'position');
  109. $arrayfields = dol_sort_array($arrayfields, 'position');
  110. $permissiontoread = $user->hasRight('asset', 'read');
  111. $permissiontoadd = $user->hasRight('asset', 'write');
  112. $permissiontodelete = $user->hasRight('asset', 'delete');
  113. // Security check
  114. if (!isModEnabled('asset')) {
  115. accessforbidden('Module not enabled');
  116. }
  117. // Security check (enable the most restrictive one)
  118. if ($user->socid > 0) {
  119. accessforbidden();
  120. }
  121. $socid = 0; if ($user->socid > 0) {
  122. $socid = $user->socid;
  123. }
  124. $isdraft = (($object->status == $object::STATUS_DRAFT) ? 1 : 0);
  125. restrictedArea($user, $object->element, $object->id, $object->table_element, '', 'fk_soc', 'rowid', $isdraft);
  126. if (!isModEnabled('asset')) {
  127. accessforbidden();
  128. }
  129. if (!$permissiontoread) {
  130. accessforbidden();
  131. }
  132. /*
  133. * Actions
  134. */
  135. if (GETPOST('cancel', 'alpha')) {
  136. $action = 'list';
  137. $massaction = '';
  138. }
  139. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  140. $massaction = '';
  141. }
  142. $parameters = array();
  143. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  144. if ($reshook < 0) {
  145. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  146. }
  147. if (empty($reshook)) {
  148. // Selection of new fields
  149. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  150. // Purge search criteria
  151. 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
  152. foreach ($object->fields as $key => $val) {
  153. $search[$key] = '';
  154. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  155. $search[$key.'_dtstart'] = '';
  156. $search[$key.'_dtend'] = '';
  157. }
  158. }
  159. $toselect = array();
  160. $search_array_options = array();
  161. }
  162. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  163. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  164. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  165. }
  166. // Mass actions
  167. $objectclass = 'Asset';
  168. $objectlabel = 'Asset';
  169. $uploaddir = $conf->asset->dir_output;
  170. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  171. }
  172. /*
  173. * View
  174. */
  175. $form = new Form($db);
  176. $now = dol_now();
  177. $help_url = '';
  178. $title = $langs->trans('ListOf', $langs->transnoentitiesnoconv("Assets"));
  179. $morejs = array();
  180. $morecss = array();
  181. // Build and execute select
  182. // --------------------------------------------------------------------
  183. $sql = 'SELECT ';
  184. $sql .= $object->getFieldList('t');
  185. // Add fields from extrafields
  186. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  187. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  188. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  189. }
  190. }
  191. // Add fields from hooks
  192. $parameters = array();
  193. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  194. $sql .= $hookmanager->resPrint;
  195. $sql = preg_replace('/,\s*$/', '', $sql);
  196. $sqlfields = $sql; // $sql fields to remove for count total
  197. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  198. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  199. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  200. }
  201. // Add table from hooks
  202. $parameters = array();
  203. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  204. $sql .= $hookmanager->resPrint;
  205. if ($object->ismultientitymanaged == 1) {
  206. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  207. } else {
  208. $sql .= " WHERE 1 = 1";
  209. }
  210. foreach ($search as $key => $val) {
  211. if (array_key_exists($key, $object->fields)) {
  212. if ($key == 'status' && $search[$key] == -1) {
  213. continue;
  214. }
  215. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  216. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  217. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  218. $search[$key] = '';
  219. }
  220. $mode_search = 2;
  221. }
  222. if ($search[$key] != '') {
  223. $sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
  224. }
  225. } else {
  226. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  227. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  228. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  229. if (preg_match('/_dtstart$/', $key)) {
  230. $sql .= " AND t.".$columnName." >= '".$db->idate($search[$key])."'";
  231. }
  232. if (preg_match('/_dtend$/', $key)) {
  233. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  234. }
  235. }
  236. }
  237. }
  238. }
  239. if ($search_all) {
  240. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  241. }
  242. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  243. // Add where from extra fields
  244. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  245. // Add where from hooks
  246. $parameters = array();
  247. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  248. $sql .= $hookmanager->resPrint;
  249. /* If a group by is required
  250. $sql .= " GROUP BY ";
  251. foreach($object->fields as $key => $val) {
  252. $sql .= "t.".$key.", ";
  253. }
  254. // Add fields from extrafields
  255. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  256. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  257. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  258. }
  259. }
  260. // Add where from hooks
  261. $parameters = array();
  262. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  263. $sql .= $hookmanager->resPrint;
  264. $sql = preg_replace('/,\s*$/', '', $sql);
  265. */
  266. // Add HAVING from hooks
  267. /*
  268. $parameters = array();
  269. $reshook = $hookmanager->executeHooks('printFieldListHaving', $parameters, $object); // Note that $action and $object may have been modified by hook
  270. $sql .= !empty($hookmanager->resPrint) ? (" HAVING 1=1 " . $hookmanager->resPrint) : "";
  271. */
  272. // Count total nb of records
  273. $nbtotalofrecords = '';
  274. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  275. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  276. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  277. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  278. $resql = $db->query($sqlforcount);
  279. if ($resql) {
  280. $objforcount = $db->fetch_object($resql);
  281. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  282. } else {
  283. dol_print_error($db);
  284. }
  285. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  286. $page = 0;
  287. $offset = 0;
  288. }
  289. $db->free($resql);
  290. }
  291. // Complete request and execute it with limit
  292. $sql .= $db->order($sortfield, $sortorder);
  293. if ($limit) {
  294. $sql .= $db->plimit($limit + 1, $offset);
  295. }
  296. $resql = $db->query($sql);
  297. if (!$resql) {
  298. dol_print_error($db);
  299. exit;
  300. }
  301. $num = $db->num_rows($resql);
  302. // Direct jump if only one record found
  303. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  304. $obj = $db->fetch_object($resql);
  305. $id = $obj->rowid;
  306. header("Location: ".DOL_URL_ROOT.'/asset/card.php?id='.$id);
  307. exit;
  308. }
  309. // Output page
  310. // --------------------------------------------------------------------
  311. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
  312. $arrayofselected = is_array($toselect) ? $toselect : array();
  313. $param = '';
  314. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  315. $param .= '&contextpage='.urlencode($contextpage);
  316. }
  317. if ($limit > 0 && $limit != $conf->liste_limit) {
  318. $param .= '&limit='.((int) $limit);
  319. }
  320. foreach ($search as $key => $val) {
  321. if (is_array($search[$key]) && count($search[$key])) {
  322. foreach ($search[$key] as $skey) {
  323. if ($skey != '') {
  324. $param .= '&search_'.$key.'[]='.urlencode($skey);
  325. }
  326. }
  327. } elseif ($search[$key] != '') {
  328. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  329. }
  330. }
  331. if ($optioncss != '') {
  332. $param .= '&optioncss='.urlencode($optioncss);
  333. }
  334. // Add $param from extra fields
  335. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  336. // Add $param from hooks
  337. $parameters = array();
  338. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  339. $param .= $hookmanager->resPrint;
  340. // List of mass actions available
  341. $arrayofmassactions = array(
  342. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  343. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  344. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  345. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  346. );
  347. if ($permissiontodelete) {
  348. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  349. }
  350. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  351. $arrayofmassactions = array();
  352. }
  353. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  354. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  355. if ($optioncss != '') {
  356. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  357. }
  358. print '<input type="hidden" name="token" value="'.newToken().'">';
  359. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  360. print '<input type="hidden" name="action" value="list">';
  361. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  362. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  363. print '<input type="hidden" name="page" value="'.$page.'">';
  364. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  365. $newcardbutton = '';
  366. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/asset/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  367. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  368. // Add code for pre mass action (confirmation or email presend form)
  369. $topicmail = "SendAssetRef";
  370. $modelmail = "asset";
  371. $objecttmp = new Asset($db);
  372. $trackid = 'asset'.$object->id;
  373. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  374. if ($search_all) {
  375. foreach ($fieldstosearchall as $key => $val) {
  376. $fieldstosearchall[$key] = $langs->trans($val);
  377. }
  378. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  379. }
  380. $moreforfilter = '';
  381. /*$moreforfilter.='<div class="divsearchfield">';
  382. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  383. $moreforfilter.= '</div>';*/
  384. $parameters = array();
  385. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // 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. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  397. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  398. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  399. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  400. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  401. // Fields title search
  402. // --------------------------------------------------------------------
  403. print '<tr class="liste_titre">';
  404. foreach ($object->fields as $key => $val) {
  405. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  406. if ($key == 'status') {
  407. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  408. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  409. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  410. } elseif (in_array($val['type'], array('timestamp'))) {
  411. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  412. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  413. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  414. }
  415. if (!empty($arrayfields['t.'.$key]['checked'])) {
  416. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  417. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  418. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  419. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  420. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  421. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  422. print '<div class="nowrap">';
  423. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  424. print '</div>';
  425. print '<div class="nowrap">';
  426. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  427. print '</div>';
  428. } elseif ($key == 'lang') {
  429. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  430. $formadmin = new FormAdmin($db);
  431. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  432. } else {
  433. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  434. }
  435. print '</td>';
  436. }
  437. }
  438. // Extra fields
  439. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  440. // Fields from hook
  441. $parameters = array('arrayfields'=>$arrayfields);
  442. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  443. print $hookmanager->resPrint;
  444. // Action column
  445. print '<td class="liste_titre maxwidthsearch">';
  446. $searchpicto = $form->showFilterButtons();
  447. print $searchpicto;
  448. print '</td>';
  449. print '</tr>'."\n";
  450. // Fields title label
  451. // --------------------------------------------------------------------
  452. print '<tr class="liste_titre">';
  453. foreach ($object->fields as $key => $val) {
  454. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  455. if ($key == 'status') {
  456. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  457. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  458. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  459. } elseif (in_array($val['type'], array('timestamp'))) {
  460. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  461. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  462. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  463. }
  464. if (!empty($arrayfields['t.'.$key]['checked'])) {
  465. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  466. }
  467. }
  468. // Extra fields
  469. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  470. // Hook fields
  471. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  472. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  473. print $hookmanager->resPrint;
  474. // Action column
  475. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  476. print '</tr>'."\n";
  477. // Detect if we need a fetch on each output line
  478. $needToFetchEachLine = 0;
  479. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  480. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  481. if (!is_null($val) && preg_match('/\$object/', $val)) {
  482. $needToFetchEachLine++; // There is at least one compute field that use $object
  483. }
  484. }
  485. }
  486. // Loop on record
  487. // --------------------------------------------------------------------
  488. $i = 0;
  489. $totalarray = array();
  490. $totalarray['nbfield'] = 0;
  491. while ($i < ($limit ? min($num, $limit) : $num)) {
  492. $obj = $db->fetch_object($resql);
  493. if (empty($obj)) {
  494. break; // Should not happen
  495. }
  496. // Store properties in $object
  497. $object->setVarsFromFetchObj($obj);
  498. // Show here line of result
  499. print '<tr class="oddeven">';
  500. foreach ($object->fields as $key => $val) {
  501. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  502. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  503. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  504. } elseif ($key == 'status') {
  505. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  506. }
  507. if (in_array($val['type'], array('timestamp'))) {
  508. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  509. } elseif ($key == 'ref') {
  510. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  511. }
  512. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  513. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  514. }
  515. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  516. if (!empty($arrayfields['t.'.$key]['checked'])) {
  517. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
  518. if ($key == 'status') {
  519. print $object->getLibStatut(5);
  520. } elseif ($key == 'rowid') {
  521. print $object->showOutputField($val, $key, $object->id, '');
  522. } else {
  523. print $object->showOutputField($val, $key, $object->$key, '');
  524. }
  525. print '</td>';
  526. if (!$i) {
  527. $totalarray['nbfield']++;
  528. }
  529. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  530. if (!$i) {
  531. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  532. }
  533. if (!isset($totalarray['val'])) {
  534. $totalarray['val'] = array();
  535. }
  536. if (!isset($totalarray['val']['t.'.$key])) {
  537. $totalarray['val']['t.'.$key] = 0;
  538. }
  539. $totalarray['val']['t.'.$key] += $object->$key;
  540. }
  541. }
  542. }
  543. // Extra fields
  544. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  545. // Fields from hook
  546. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  547. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  548. print $hookmanager->resPrint;
  549. // Action column
  550. print '<td class="nowrap center">';
  551. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  552. $selected = 0;
  553. if (in_array($object->id, $arrayofselected)) {
  554. $selected = 1;
  555. }
  556. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  557. }
  558. print '</td>';
  559. if (!$i) {
  560. $totalarray['nbfield']++;
  561. }
  562. print '</tr>'."\n";
  563. $i++;
  564. }
  565. // Show total line
  566. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  567. // If no record found
  568. if ($num == 0) {
  569. $colspan = 1;
  570. foreach ($arrayfields as $key => $val) {
  571. if (!empty($val['checked'])) {
  572. $colspan++;
  573. }
  574. }
  575. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  576. }
  577. $db->free($resql);
  578. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  579. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  580. print $hookmanager->resPrint;
  581. print '</table>'."\n";
  582. print '</div>'."\n";
  583. print '</form>'."\n";
  584. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  585. $hidegeneratedfilelistifempty = 1;
  586. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  587. $hidegeneratedfilelistifempty = 0;
  588. }
  589. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  590. $formfile = new FormFile($db);
  591. // Show list of available documents
  592. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  593. $urlsource .= str_replace('&amp;', '&', $param);
  594. $filedir = $diroutputmassaction;
  595. $genallowed = $permissiontoread;
  596. $delallowed = $permissiontoadd;
  597. print $formfile->showdocuments('massfilesarea_asset', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  598. }
  599. // End of page
  600. llxFooter();
  601. $db->close();