bom_list.php 28 KB

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