list.php 31 KB

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