bom_list.php 30 KB

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