list.php 35 KB

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