bom_list.php 33 KB

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