bom_list.php 34 KB

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