rollerstorageindex.php 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781
  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/custom/rollerstorage/rollerstorageindex.php
  19. * \ingroup inventory
  20. * \brief List page for inventory
  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 . '/product/inventory/class/inventory.class.php';
  28. require_once DOL_DOCUMENT_ROOT . '/custom/rollerstorage/class/statuses.class.php';
  29. if (isModEnabled('categorie')) {
  30. require_once DOL_DOCUMENT_ROOT . '/categories/class/categorie.class.php';
  31. }
  32. // Load translation files required by the page
  33. $langs->loadLangs(array("stocks", "other"));
  34. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  35. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  36. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  37. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  38. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'inventorylist'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. $id = GETPOST('id', 'int');
  44. $idmenu = GETPOST('idmenu', 'int');
  45. $backurlforlist = '/custom/rollerstorage/rollerstorageindex.php?idmenu=' . $idmenu . '&leftmenu=';
  46. // Load variable for pagination
  47. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  48. $sortfield = GETPOST('sortfield', 'aZ09comma');
  49. $sortorder = GETPOST('sortorder', 'aZ09comma');
  50. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  51. if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  52. // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
  53. $page = 0;
  54. }
  55. $offset = $limit * $page;
  56. $pageprev = $page - 1;
  57. $pagenext = $page + 1;
  58. // Initialize technical objects
  59. $object = new Inventory($db);
  60. $extrafields = new ExtraFields($db);
  61. $stasusesObj = new Statuses($db);
  62. function getLibStatus($object)
  63. {
  64. global $stasusesObj;
  65. global $db;
  66. $allapotok = $stasusesObj->getStatusIds($db);
  67. return '<span class="badge badge-status' . $object->status . ' badge-status" title="' . $allapotok[$object->status] . '">' . $allapotok[$object->status] . '</span>';
  68. }
  69. // no inventory docs yet
  70. // $diroutputmassaction = $conf->inventory->dir_output.'/temp/massgeneration/'.$user->id;
  71. $diroutputmassaction = null;
  72. $hookmanager->initHooks(array('inventorylist')); // Note that conf->hooks_modules contains array
  73. // Fetch optionals attributes and labels
  74. $extrafields->fetch_name_optionals_label($object->table_element);
  75. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  76. // Default sort order (if not yet defined by previous GETPOST)
  77. if (!$sortfield) {
  78. reset($object->fields); // Reset is required to avoid key() to return null.
  79. $sortfield = "t." . key($object->fields); // Set here default search field. By default 1st field in definition.
  80. }
  81. if (!$sortorder) {
  82. $sortorder = "ASC";
  83. }
  84. // Initialize array of search criterias
  85. $search_all = GETPOST('search_all', 'alphanohtml');
  86. $search = array();
  87. foreach ($object->fields as $key => $val) {
  88. if (GETPOST('search_' . $key, 'alpha') !== '') {
  89. $search[$key] = GETPOST('search_' . $key, 'alpha');
  90. }
  91. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  92. $search[$key . '_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_' . $key . '_dtstartmonth', 'int'), GETPOST('search_' . $key . '_dtstartday', 'int'), GETPOST('search_' . $key . '_dtstartyear', 'int'));
  93. $search[$key . '_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_' . $key . '_dtendmonth', 'int'), GETPOST('search_' . $key . '_dtendday', 'int'), GETPOST('search_' . $key . '_dtendyear', 'int'));
  94. }
  95. }
  96. $searchCategoryProductOperator = 0;
  97. if (GETPOSTISSET('formfilteraction')) {
  98. $searchCategoryProductOperator = GETPOST('search_category_product_operator', 'int');
  99. } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
  100. $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
  101. }
  102. $searchCategoryProductList = GETPOST('search_category_product_list', 'array');
  103. // List of fields to search into when doing a "search in all"
  104. $fieldstosearchall = array();
  105. foreach ($object->fields as $key => $val) {
  106. if (!empty($val['searchall'])) {
  107. $fieldstosearchall['t.' . $key] = $val['label'];
  108. }
  109. }
  110. // Definition of array of fields for columns
  111. $arrayfields = array();
  112. foreach ($object->fields as $key => $val) {
  113. // If $val['visible']==0, then we never show the field
  114. if (!empty($val['visible'])) {
  115. $visible = (int) dol_eval($val['visible'], 1, 1, '1');
  116. $arrayfields['t.' . $key] = array(
  117. 'label' => $val['label'],
  118. 'checked' => (($visible < 0) ? 0 : 1),
  119. 'enabled' => ($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
  120. 'position' => $val['position'],
  121. 'help' => isset($val['help']) ? $val['help'] : ''
  122. );
  123. }
  124. }
  125. // Extra fields
  126. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_array_fields.tpl.php';
  127. $object->fields = dol_sort_array($object->fields, 'position');
  128. $arrayfields = dol_sort_array($arrayfields, 'position');
  129. //$permissiontoread = $user->rights->stock->lire;
  130. //$permissiontoadd = $user->rights->stock->creer;
  131. //$permissiontodelete = $user->rights->stock->supprimer;
  132. $permissiontoread = $user->rights->rollerstorage->rollerhistory->readall;
  133. $permissiontoadd = $user->rights->rollerstorage->rollerhistory->write;
  134. $permissiontodelete = $user->rights->rollerstorage->rollerhistory->delete;
  135. if(!$permissiontoread){
  136. $permissions = get_object_vars($user->rights->rollerstorage->rollerhistory);
  137. ksort($permissions);
  138. foreach($permissions as $key => $value){
  139. $inventoryAndMenu = explode('_', $key);
  140. if($inventoryAndMenu[1]){
  141. header("Location: " . DOL_URL_ROOT .'/custom/rollerstorage/rollerstorageinventoryindex.php?inventory_id=' . $inventoryAndMenu[1]);
  142. break;
  143. }
  144. }
  145. }
  146. // Security check
  147. $socid = 0;
  148. if ($user->socid > 0) { // Protection if external user
  149. //$socid = $user->socid;
  150. accessforbidden();
  151. }
  152. if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
  153. $result = restrictedArea($user, 'stock');
  154. } else {
  155. $result = restrictedArea($user, 'stock', 0, '', 'inventory_advance');
  156. }
  157. /*
  158. * Actions
  159. */
  160. if (GETPOST('cancel', 'alpha')) {
  161. $action = 'list';
  162. $massaction = '';
  163. }
  164. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  165. $massaction = '';
  166. }
  167. $parameters = array();
  168. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  169. if ($reshook < 0) {
  170. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  171. }
  172. if (empty($reshook)) {
  173. // Selection of new fields
  174. include DOL_DOCUMENT_ROOT . '/core/actions_changeselectedfields.inc.php';
  175. // Purge search criteria
  176. 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
  177. foreach ($object->fields as $key => $val) {
  178. $search[$key] = '';
  179. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  180. $search[$key . '_dtstart'] = '';
  181. $search[$key . '_dtend'] = '';
  182. }
  183. }
  184. $searchCategoryProductList = array();
  185. $toselect = array();
  186. $search_array_options = array();
  187. }
  188. if (
  189. GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  190. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')
  191. ) {
  192. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  193. }
  194. // Mass actions
  195. $objectclass = 'Inventory';
  196. $objectlabel = 'Inventory';
  197. $uploaddir = $conf->stock->dir_output;
  198. include DOL_DOCUMENT_ROOT . '/core/actions_massactions.inc.php';
  199. }
  200. /*
  201. * View
  202. */
  203. $form = new Form($db);
  204. $now = dol_now();
  205. //$help_url="EN:Module_Inventory|FR:Module_Inventory_FR|ES:Módulo_Inventory";
  206. $help_url = '';
  207. $title = $langs->trans('ListOfInventories');
  208. $morejs = array();
  209. $morecss = array();
  210. /*
  211. Kell a statuszok atirasahoz, mert az llx_inventoryban a status rowid-helyett status_id-et tartalmaz
  212. */
  213. $statusesForSQL = array_flip($stasusesObj->getStatusidsAndRowids());
  214. //____________________________________________________________________
  215. // Build and execute select
  216. // --------------------------------------------------------------------
  217. $sql = 'SELECT ent.*, ';
  218. $sql .= $object->getFieldList('t');
  219. // Add fields from extrafields
  220. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  221. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  222. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef." . $key . " as options_" . $key : '');
  223. }
  224. }
  225. // Add fields from hooks
  226. $parameters = array();
  227. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  228. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  229. $sql = preg_replace('/,\s*$/', '', $sql);
  230. $sqlfields = $sql; // $sql fields to remove for count total
  231. $sql .= " FROM " . MAIN_DB_PREFIX . $object->table_element . " as t";
  232. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  233. $sql .= " LEFT JOIN " . MAIN_DB_PREFIX . $object->table_element . "_extrafields as ef on (t.rowid = ef.fk_object)";
  234. }
  235. //print $sql;exit;
  236. $sql .= " INNER JOIN " . MAIN_DB_PREFIX . "entrepot AS ent ON t.fk_warehouse = ent.rowid ";
  237. // Add table from hooks
  238. $parameters = array();
  239. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  240. $sql .= $hookmanager->resPrint;
  241. if ($object->ismultientitymanaged == 1) {
  242. $sql .= " WHERE t.entity IN (" . getEntity($object->element) . ")";
  243. } else {
  244. $sql .= " WHERE 1 = 1";
  245. }
  246. foreach ($search as $key => $val) {
  247. if (array_key_exists($key, $object->fields)) {
  248. if ($key == 'status' && $search[$key] == -1) {
  249. continue;
  250. }
  251. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  252. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  253. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  254. $search[$key] = '';
  255. }
  256. $mode_search = 2;
  257. }
  258. if ($search[$key] != '') {
  259. $akey = 't.' . $key;
  260. if($key == 'status'){
  261. $search[$key] = $statusesForSQL[$val];
  262. }
  263. $sql .= natural_search($akey, $search[$key], (($key == 'status') ? 2 : $mode_search));
  264. }
  265. } else {
  266. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  267. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  268. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  269. if (preg_match('/_dtstart$/', $key)) {
  270. $sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
  271. }
  272. if (preg_match('/_dtend$/', $key)) {
  273. $sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
  274. }
  275. }
  276. }
  277. }
  278. }
  279. if ($search_all) {
  280. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  281. }
  282. // Search for tag/category ($searchCategoryProductList is an array of ID)
  283. if (!empty($searchCategoryProductList)) {
  284. $searchCategoryProductSqlList = array();
  285. $listofcategoryid = '';
  286. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  287. if (intval($searchCategoryProduct) == -2) {
  288. $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM " . MAIN_DB_PREFIX . "categorie_product as ck WHERE p.rowid = ck.fk_product)";
  289. } elseif (intval($searchCategoryProduct) > 0) {
  290. if ($searchCategoryProductOperator == 0) {
  291. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM " . MAIN_DB_PREFIX . "categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie = " . ((int) $searchCategoryProduct) . ")";
  292. } else {
  293. $listofcategoryid .= ($listofcategoryid ? ', ' : '') . ((int) $searchCategoryProduct);
  294. }
  295. }
  296. }
  297. if ($listofcategoryid) {
  298. $searchCategoryProductSqlList[] = " EXISTS (SELECT ck.fk_product FROM " . MAIN_DB_PREFIX . "categorie_product as ck WHERE p.rowid = ck.fk_product AND ck.fk_categorie IN (" . $db->sanitize($listofcategoryid) . "))";
  299. }
  300. if ($searchCategoryProductOperator == 1) {
  301. if (!empty($searchCategoryProductSqlList)) {
  302. $sql .= " AND (" . implode(' OR ', $searchCategoryProductSqlList) . ")";
  303. }
  304. } else {
  305. if (!empty($searchCategoryProductSqlList)) {
  306. $sql .= " AND (" . implode(' AND ', $searchCategoryProductSqlList) . ")";
  307. }
  308. }
  309. }
  310. // Add where from extra fields
  311. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_sql.tpl.php';
  312. // Add where from hooks
  313. $parameters = array();
  314. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  315. $sql .= $hookmanager->resPrint;
  316. /* If a group by is required
  317. $sql.= " GROUP BY ";
  318. foreach($object->fields as $key => $val)
  319. {
  320. $sql .= "t.".$key.", ";
  321. }
  322. // Add fields from extrafields
  323. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  324. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) $sql.=($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  325. }
  326. // Add where from hooks
  327. $parameters=array();
  328. $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  329. $sql.=$hookmanager->resPrint;
  330. $sql=preg_replace('/,\s*$/','', $sql);
  331. */
  332. /// Count total nb of records
  333. $nbtotalofrecords = '';
  334. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  335. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  336. $sqlforcount = preg_replace('/^' . preg_quote($sqlfields, '/') . '/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  337. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  338. $resql = $db->query($sqlforcount);
  339. if ($resql) {
  340. $objforcount = $db->fetch_object($resql);
  341. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  342. } else {
  343. dol_print_error($db);
  344. }
  345. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  346. $page = 0;
  347. $offset = 0;
  348. }
  349. $db->free($resql);
  350. }
  351. // Complete request and execute it with limit
  352. $sql .= $db->order($sortfield, $sortorder);
  353. if ($limit) {
  354. $sql .= $db->plimit($limit + 1, $offset);
  355. }
  356. $resql = $db->query($sql);
  357. if (!$resql) {
  358. dol_print_error($db);
  359. exit;
  360. }
  361. $num = $db->num_rows($resql);
  362. // Direct jump if only one record found
  363. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  364. $obj = $db->fetch_object($resql);
  365. $id = $obj->rowid;
  366. header("Location: " . DOL_URL_ROOT . '/custom/rollerstorage/card.php?id=' . $id);
  367. exit;
  368. }
  369. // Output page
  370. // --------------------------------------------------------------------
  371. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'classforhorizontalscrolloftabs');
  372. $arrayofselected = is_array($toselect) ? $toselect : array();
  373. $param = '';
  374. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  375. $param .= '&contextpage=' . urlencode($contextpage);
  376. }
  377. if ($limit > 0 && $limit != $conf->liste_limit) {
  378. $param .= '&limit=' . urlencode($limit);
  379. }
  380. foreach ($search as $key => $val) {
  381. if (is_array($search[$key]) && count($search[$key])) {
  382. foreach ($search[$key] as $skey) {
  383. $param .= '&search_' . $key . '[]=' . urlencode($skey);
  384. }
  385. } else {
  386. $param .= '&search_' . $key . '=' . urlencode($search[$key]);
  387. }
  388. }
  389. if ($optioncss != '') {
  390. $param .= '&optioncss=' . urlencode($optioncss);
  391. }
  392. foreach ($searchCategoryProductList as $searchCategoryProduct) {
  393. $param .= "&search_category_product_list[]=" . urlencode($searchCategoryProduct);
  394. }
  395. // Add $param from extra fields
  396. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_param.tpl.php';
  397. // Add $param from hooks
  398. $parameters = array();
  399. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  400. $param .= $hookmanager->resPrint;
  401. // List of mass actions available
  402. $arrayofmassactions = array(
  403. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  404. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  405. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  406. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  407. );
  408. if ($permissiontodelete) {
  409. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"') . $langs->trans("Delete");
  410. }
  411. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  412. $arrayofmassactions = array();
  413. }
  414. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  415. if ($permissiontoread) {
  416. print '<form method="POST" id="searchFormList" action="' . $_SERVER["PHP_SELF"] . '">' . "\n";
  417. if ($optioncss != '') {
  418. print '<input type="hidden" name="optioncss" value="' . $optioncss . '">';
  419. }
  420. print '<input type="hidden" name="token" value="' . newToken() . '">';
  421. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  422. print '<input type="hidden" name="action" value="list">';
  423. print '<input type="hidden" name="sortfield" value="' . $sortfield . '">';
  424. print '<input type="hidden" name="sortorder" value="' . $sortorder . '">';
  425. print '<input type="hidden" name="page" value="' . $page . '">';
  426. print '<input type="hidden" name="contextpage" value="' . $contextpage . '">';
  427. //$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/inventory/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  428. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT . '/custom/rollerstorage/card.php?action=create&backtopage=' . urlencode($_SERVER['PHP_SELF']) . '?inventory_id=' . $inventory_id . '&idmenu=' . $idmenu . '&leftmenu=', '', $permissiontoadd);
  429. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  430. // Add code for pre mass action (confirmation or email presend form)
  431. $topicmail = "Information";
  432. $modelmail = "inventory";
  433. $objecttmp = new Inventory($db);
  434. $trackid = 'stockinv' . $object->id;
  435. include DOL_DOCUMENT_ROOT . '/core/tpl/massactions_pre.tpl.php';
  436. if ($search_all) {
  437. foreach ($fieldstosearchall as $key => $val) {
  438. $fieldstosearchall[$key] = $langs->trans($val);
  439. }
  440. print '<div class="divsearchfieldfilter">' . $langs->trans("FilterOnInto", $search_all) . join(', ', $fieldstosearchall) . '</div>';
  441. }
  442. $moreforfilter = '';
  443. /*$moreforfilter.='<div class="divsearchfield">';
  444. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  445. $moreforfilter.= '</div>';*/
  446. // Filter on categories
  447. if (!empty($conf->global->MAIN_SEARCH_CATEGORY_PRODUCT_ON_LISTS) && isModEnabled('categorie') && $user->rights->categorie->lire) {
  448. $moreforfilter .= '<div class="divsearchfield">';
  449. $tmptitle = $langs->transnoentities('ProductsCategoriesShort');
  450. $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
  451. $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1);
  452. $categoriesProductArr[-2] = '- ' . $langs->trans('NotCategorized') . ' -';
  453. $moreforfilter .= Form::multiselectarray('search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
  454. $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_product_operator" name="search_category_product_operator" value="1"' . ($searchCategoryProductOperator == 1 ? ' checked="checked"' : '') . '/>';
  455. $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_pro'); // Tooltip on click
  456. $moreforfilter .= '</div>';
  457. }
  458. $parameters = array();
  459. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  460. if (empty($reshook)) {
  461. $moreforfilter .= $hookmanager->resPrint;
  462. } else {
  463. $moreforfilter = $hookmanager->resPrint;
  464. }
  465. if (!empty($moreforfilter)) {
  466. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  467. print $moreforfilter;
  468. print '</div>';
  469. }
  470. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  471. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  472. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  473. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  474. print '<table class="tagtable nobottomiftotal liste' . ($moreforfilter ? " listwithfilterbefore" : "") . '">' . "\n";
  475. // Fields title search
  476. // --------------------------------------------------------------------
  477. print '<tr class="liste_titre">';
  478. // Action column
  479. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  480. print '<td class="liste_titre maxwidthsearch">';
  481. $searchpicto = $form->showFilterButtons('left');
  482. print $searchpicto;
  483. print '</td>';
  484. }
  485. foreach ($object->fields as $key => $val) {
  486. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  487. if ($key == 'status') {
  488. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  489. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  490. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  491. } elseif (in_array($val['type'], array('timestamp'))) {
  492. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  493. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  494. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  495. }
  496. if (!empty($arrayfields['t.' . $key]['checked'])) {
  497. print '<td class="liste_titre' . ($cssforfield ? ' ' . $cssforfield : '') . '">';
  498. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  499. print $form->selectarray('search_' . $key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  500. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  501. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  502. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  503. print '<input type="text" class="flat maxwidth75" name="search_' . $key . '" value="' . dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '') . '">';
  504. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  505. print '<div class="nowrap">';
  506. print $form->selectDate($search[$key . '_dtstart'] ? $search[$key . '_dtstart'] : '', "search_" . $key . "_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  507. print '</div>';
  508. print '<div class="nowrap">';
  509. print $form->selectDate($search[$key . '_dtend'] ? $search[$key . '_dtend'] : '', "search_" . $key . "_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  510. print '</div>';
  511. }
  512. print '</td>';
  513. }
  514. }
  515. // Extra fields
  516. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_input.tpl.php';
  517. // Fields from hook
  518. $parameters = array('arrayfields' => $arrayfields);
  519. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  520. print $hookmanager->resPrint;
  521. // Action column
  522. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  523. print '<td class="liste_titre maxwidthsearch">';
  524. $searchpicto = $form->showFilterButtons();
  525. print $searchpicto;
  526. print '</td>';
  527. }
  528. print '</tr>' . "\n";
  529. // Fields title label
  530. // --------------------------------------------------------------------
  531. print '<tr class="liste_titre">';
  532. // Action column
  533. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  534. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  535. }
  536. foreach ($object->fields as $key => $val) {
  537. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  538. if ($key == 'status') {
  539. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  540. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  541. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  542. } elseif (in_array($val['type'], array('timestamp'))) {
  543. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  544. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  545. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  546. }
  547. if (!empty($arrayfields['t.' . $key]['checked'])) {
  548. print getTitleFieldOfList($arrayfields['t.' . $key]['label'], 0, $_SERVER['PHP_SELF'], 't.' . $key, '', $param, ($cssforfield ? 'class="' . $cssforfield . '"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield . ' ' : '')) . "\n";
  549. }
  550. }
  551. // Extra fields
  552. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_search_title.tpl.php';
  553. // Hook fields
  554. $parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder);
  555. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  556. print $hookmanager->resPrint;
  557. // Action column
  558. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  559. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ') . "\n";
  560. }
  561. print '</tr>' . "\n";
  562. // Detect if we need a fetch on each output line
  563. $needToFetchEachLine = 0;
  564. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  565. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  566. if (preg_match('/\$object/', $val)) {
  567. $needToFetchEachLine++; // There is at least one compute field that use $object
  568. }
  569. }
  570. }
  571. // Loop on record
  572. // --------------------------------------------------------------------
  573. $i = 0;
  574. $totalarray = array();
  575. $totalarray['nbfield'] = 0;
  576. while ($i < ($limit ? min($num, $limit) : $num)) {
  577. $obj = $db->fetch_object($resql);
  578. if (empty($obj)) {
  579. break; // Should not happen
  580. }
  581. // Store properties in $object
  582. $object->setVarsFromFetchObj($obj);
  583. // Show here line of result
  584. print '<tr class="oddeven">';
  585. // Action column
  586. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  587. print '<td class="nowrap center">';
  588. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  589. $selected = 0;
  590. if (in_array($object->id, $arrayofselected)) {
  591. $selected = 1;
  592. }
  593. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  594. }
  595. print '</td>';
  596. }
  597. foreach ($object->fields as $key => $val) {
  598. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  599. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  600. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  601. } elseif ($key == 'status') {
  602. $cssforfield .= ($cssforfield ? ' ' : '') . 'center';
  603. }
  604. if (in_array($val['type'], array('timestamp'))) {
  605. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  606. } elseif ($key == 'ref') {
  607. $cssforfield .= ($cssforfield ? ' ' : '') . 'nowrap';
  608. }
  609. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  610. $cssforfield .= ($cssforfield ? ' ' : '') . 'right';
  611. }
  612. if (!empty($arrayfields['t.' . $key]['checked'])) {
  613. print '<td' . ($cssforfield ? ' class="' . $cssforfield . '"' : '') . '>';
  614. $typeData = explode(':', $val['type']);
  615. if ($key == 'status') {
  616. print getLibStatus($object);
  617. //print $object->getLibStatut(5);
  618. } elseif ($key == 'rowid') {
  619. print $object->showOutputField($val, $key, $object->id, '');
  620. } elseif ($key == 'ref') {
  621. print '<span class="fas fa-boxes paddingright classfortooltip" style=" color: #a69944;"></span><a href="' . DOL_URL_ROOT . '/custom/rollerstorage/card.php?id=' . $object->id . '&backtopage=' . $backurlforlist . '">' . $object->$key . '</a>';
  622. } elseif (isset($typeData[1]) && $typeData[1] == 'Entrepot') {
  623. print '<div title="<span class=&quot;fas fa-box-open em080&quot; style=&quot; color: #a69944;&quot; cursor: pointer;></span> <u class=&quot;paddingrightonly&quot;>Raktár</u><br><b>Ref.:</b> ' . $obj->address . '<br>
  624. <b>A hely rövid neve:</b> ' . $obj->lieu . '" class="classfortooltip"><span class="fas fa-box-open em080 paddingright classfortooltip" style=" color: #a69944;"></span>
  625. ' . $obj->lieu . '</div>';
  626. } else {
  627. print $object->showOutputField($val, $key, $object->$key, '');
  628. }
  629. print '</td>';
  630. if (!$i) {
  631. $totalarray['nbfield']++;
  632. }
  633. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  634. if (!$i) {
  635. $totalarray['pos'][$totalarray['nbfield']] = 't.' . $key;
  636. }
  637. if (!isset($totalarray['val'])) {
  638. $totalarray['val'] = array();
  639. }
  640. if (!isset($totalarray['val']['t.' . $key])) {
  641. $totalarray['val']['t.' . $key] = 0;
  642. }
  643. $totalarray['val']['t.' . $key] += $object->$key;
  644. }
  645. }
  646. }
  647. // Extra fields
  648. include DOL_DOCUMENT_ROOT . '/core/tpl/extrafields_list_print_fields.tpl.php';
  649. // Fields from hook
  650. $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
  651. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  652. print $hookmanager->resPrint;
  653. // Action column
  654. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  655. print '<td class="nowrap center">';
  656. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  657. $selected = 0;
  658. if (in_array($object->id, $arrayofselected)) {
  659. $selected = 1;
  660. }
  661. print '<input id="cb' . $object->id . '" class="flat checkforselect" type="checkbox" name="toselect[]" value="' . $object->id . '"' . ($selected ? ' checked="checked"' : '') . '>';
  662. }
  663. print '</td>';
  664. }
  665. if (!$i) {
  666. $totalarray['nbfield']++;
  667. }
  668. print '</tr>' . "\n";
  669. $i++;
  670. }
  671. // Show total line
  672. include DOL_DOCUMENT_ROOT . '/core/tpl/list_print_total.tpl.php';
  673. // If no record found
  674. if ($num == 0) {
  675. $colspan = 1;
  676. foreach ($arrayfields as $key => $val) {
  677. if (!empty($val['checked'])) {
  678. $colspan++;
  679. }
  680. }
  681. print '<tr><td colspan="' . $colspan . '" class="opacitymedium">' . $langs->trans("NoRecordFound") . '</td></tr>';
  682. }
  683. $db->free($resql);
  684. $parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
  685. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
  686. print $hookmanager->resPrint;
  687. print '</table>' . "\n";
  688. print '</div>' . "\n";
  689. print '</form>' . "\n";
  690. } else {
  691. print '<div class="error">Hozzáférés megtagadva.<br>Egy letiltott modul oldalához, területéhez vagy szolgáltatásához próbál hozzáférni, vagy anélkül, hogy hitelesített munkamenetben lenne, vagy amely nem engedélyezett a felhasználó számára.</div>';
  692. }
  693. // End of page
  694. llxFooter();
  695. $db->close();