list.php 28 KB

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