list.php 28 KB

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