bom_list.php 34 KB

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