productlot_list.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759
  1. <?php
  2. /* Copyright (C) 2007-2016 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018-2021 Ferran Marcet <fmarcet@2byte.es>
  4. * Copyright (C) 2019 Frédéric France <frederic.france@netlogic.fr>
  5. *
  6. * This program is free software; you can redistribute it and/or modify
  7. * it under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 3 of the License, or
  9. * (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  14. * GNU General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  18. */
  19. /**
  20. * \file product/stock/productlot_list.php
  21. * \ingroup stock
  22. * \brief This file is an example of a php page
  23. * Initialy built by build_class_from_table on 2016-05-17 12:22
  24. */
  25. // Load Dolibarr environment
  26. require '../../main.inc.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
  31. require_once DOL_DOCUMENT_ROOT.'/product/stock/class/productlot.class.php';
  32. // Load translation files required by the page
  33. $langs->loadLangs(array('stocks', 'productbatch', 'other', 'users'));
  34. // Get parameters
  35. $id = GETPOST('id', 'int');
  36. $action = GETPOST('action', 'aZ09');
  37. $massaction = GETPOST('massaction', 'alpha');
  38. $backtopage = GETPOST('backtopage', 'alpha');
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'productlotlist'; // To manage different context of search
  41. $optioncss = GETPOST('optioncss', 'alpha');
  42. $mode = GETPOST('mode', 'alpha');
  43. $search_entity = GETPOST('search_entity', 'int');
  44. $search_product = GETPOST('search_product', 'alpha');
  45. $search_batch = GETPOST('search_batch', 'alpha');
  46. $search_fk_user_creat = GETPOST('search_fk_user_creat', 'int');
  47. $search_fk_user_modif = GETPOST('search_fk_user_modif', 'int');
  48. $search_import_key = GETPOST('search_import_key', 'int');
  49. // Load variable for pagination
  50. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  51. $sortfield = GETPOST('sortfield', 'aZ09comma');
  52. $sortorder = GETPOST('sortorder', 'aZ09comma');
  53. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  54. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  55. // If $page is not defined, or '' or -1 or if we click on clear filters
  56. $page = 0;
  57. }
  58. $offset = $limit * $page;
  59. $pageprev = $page - 1;
  60. $pagenext = $page + 1;
  61. // Initialize technical object to manage hooks. Note that conf->hooks_modules contains array
  62. $object = new Productlot($db);
  63. $extrafields = new ExtraFields($db);
  64. $diroutputmassaction = $conf->productbatch->dir_output.'/temp/massgeneration/'.$user->id;
  65. $hookmanager->initHooks(array('product_lotlist'));
  66. // Fetch optionals attributes and labels
  67. $extrafields->fetch_name_optionals_label($object->table_element);
  68. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  69. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  70. // Default sort order (if not yet defined by previous GETPOST)
  71. if (!$sortfield) {
  72. $sortfield = "t.fk_product,t.batch"; // Set here default search field. By default 1st field in definition.
  73. }
  74. if (!$sortorder) {
  75. $sortorder = "ASC";
  76. }
  77. // Initialize array of search criterias
  78. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  79. $search = array();
  80. foreach ($object->fields as $key => $val) {
  81. if (GETPOST('search_'.$key, 'alpha') !== '') {
  82. $search[$key] = GETPOST('search_'.$key, 'alpha');
  83. }
  84. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  85. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  86. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  87. }
  88. }
  89. // List of fields to search into when doing a "search in all"
  90. $fieldstosearchall = array();
  91. foreach ($object->fields as $key => $val) {
  92. if (!empty($val['searchall'])) {
  93. $fieldstosearchall['t.'.$key] = $val['label'];
  94. }
  95. }
  96. // Definition of array of fields for columns
  97. $arrayfields = array();
  98. foreach ($object->fields as $key => $val) {
  99. // If $val['visible']==0, then we never show the field
  100. if (!empty($val['visible'])) {
  101. $visible = (int) dol_eval($val['visible'], 1);
  102. $arrayfields['t.'.$key] = array(
  103. 'label'=>$val['label'],
  104. 'checked'=>(($visible < 0) ? 0 : 1),
  105. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  106. 'position'=>$val['position'],
  107. 'help'=> isset($val['help']) ? $val['help'] : ''
  108. );
  109. }
  110. }
  111. // Extra fields
  112. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  113. $object->fields = dol_sort_array($object->fields, 'position');
  114. $arrayfields = dol_sort_array($arrayfields, 'position');
  115. $usercanread = $user->rights->produit->lire;
  116. $usercancreate = $user->rights->produit->creer;
  117. $usercandelete = $user->rights->produit->supprimer;
  118. $upload_dir = $conf->productbatch->multidir_output[$conf->entity];
  119. $permissiontoread = $usercanread;
  120. $permissiontoadd = $usercancreate;
  121. //$permissiontodelete = $usercandelete;
  122. // Security check
  123. if (empty($conf->productbatch->enabled)) {
  124. accessforbidden('Module not enabled');
  125. }
  126. $socid = 0;
  127. if ($user->socid > 0) { // Protection if external user
  128. //$socid = $user->socid;
  129. accessforbidden();
  130. }
  131. //$result = restrictedArea($user, 'productbatch');
  132. if (!$permissiontoread) {
  133. accessforbidden();
  134. }
  135. /*
  136. * Actions
  137. */
  138. if (GETPOST('cancel', 'alpha')) {
  139. $action = 'list';
  140. $massaction = '';
  141. }
  142. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  143. $massaction = '';
  144. }
  145. $parameters = array();
  146. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  147. if ($reshook < 0) {
  148. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  149. }
  150. if (empty($reshook)) {
  151. // Selection of new fields
  152. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  153. // Purge search criteria
  154. 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
  155. foreach ($object->fields as $key => $val) {
  156. $search[$key] = '';
  157. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  158. $search[$key.'_dtstart'] = '';
  159. $search[$key.'_dtend'] = '';
  160. }
  161. }
  162. $toselect = array();
  163. $search_array_options = array();
  164. }
  165. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  166. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  167. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  168. }
  169. // Mass actions
  170. $objectclass = 'ProductLot';
  171. $objectlabel = 'LotSerial';
  172. $uploaddir = $conf->productbatch->dir_output;
  173. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  174. }
  175. /*
  176. * View
  177. */
  178. $form = new Form($db);
  179. $now = dol_now();
  180. $help_url = 'EN:Module_Lot_/_Serial|FR:Module_Lot_/_Série';
  181. $title = $langs->trans('LotSerialList');
  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); // Note that $action and $object may have been modified by hook
  197. $sql .= $hookmanager->resPrint;
  198. $sql = preg_replace('/,\s*$/', '', $sql);
  199. $sqlfields = $sql;
  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); // 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. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  246. // Add where from extra fields
  247. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  248. // Add where from hooks
  249. $parameters = array();
  250. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  251. $sql .= $hookmanager->resPrint;
  252. /* If a group by is required
  253. $sql.= " GROUP BY ";
  254. foreach($object->fields as $key => $val) {
  255. $sql .= "t.".$db->escape($key).", ";
  256. }
  257. // Add fields from extrafields
  258. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  259. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  260. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  261. }
  262. }
  263. // Add where from hooks
  264. $parameters=array();
  265. $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  266. $sql.=$hookmanager->resPrint;
  267. $sql=preg_replace('/,\s*$/','', $sql);
  268. */
  269. // Count total nb of records
  270. $nbtotalofrecords = '';
  271. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  272. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  273. $resql = $db->query($sql);
  274. $nbtotalofrecords = $db->num_rows($resql);
  275. */
  276. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  277. /*$resql = $db->query($sql, 0, 'auto', 1);
  278. while ($db->fetch_object($resql)) {
  279. if (empty($nbtotalofrecords)) {
  280. $nbtotalofrecords = 1; // We can't make +1 because init value is ''
  281. } else {
  282. $nbtotalofrecords++;
  283. }
  284. }*/
  285. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  286. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  287. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  288. $resql = $db->query($sqlforcount);
  289. if ($resql) {
  290. $objforcount = $db->fetch_object($resql);
  291. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  292. } else {
  293. dol_print_error($db);
  294. }
  295. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  296. $page = 0;
  297. $offset = 0;
  298. }
  299. $db->free($resql);
  300. }
  301. // Complete request and execute it with limit
  302. $sql .= $db->order($sortfield, $sortorder);
  303. if ($limit) {
  304. $sql .= $db->plimit($limit + 1, $offset);
  305. }
  306. $resql = $db->query($sql);
  307. if (!$resql) {
  308. dol_print_error($db);
  309. exit;
  310. }
  311. $num = $db->num_rows($resql);
  312. $i = 0;
  313. // Direct jump if only one record found
  314. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  315. $obj = $db->fetch_object($resql);
  316. $id = $obj->rowid;
  317. header("Location: ".DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$id);
  318. exit;
  319. }
  320. // Output page
  321. // --------------------------------------------------------------------
  322. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  323. $arrayofselected = is_array($toselect) ? $toselect : array();
  324. $param = '';
  325. if (!empty($mode)) {
  326. $param .= '&mode='.urlencode($mode);
  327. }
  328. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  329. $param .= '&contextpage='.urlencode($contextpage);
  330. }
  331. if ($limit > 0 && $limit != $conf->liste_limit) {
  332. $param .= '&limit='.((int) $limit);
  333. }
  334. foreach ($search as $key => $val) {
  335. if (is_array($search[$key]) && count($search[$key])) {
  336. foreach ($search[$key] as $skey) {
  337. if ($skey != '') {
  338. $param .= '&search_'.$key.'[]='.urlencode($skey);
  339. }
  340. }
  341. } elseif ($search[$key] != '') {
  342. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  343. }
  344. }
  345. if ($optioncss != '') {
  346. $param .= '&optioncss='.urlencode($optioncss);
  347. }
  348. // Add $param from extra fields
  349. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  350. // Add $param from hooks
  351. $parameters = array();
  352. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  353. $param .= $hookmanager->resPrint;
  354. // List of mass actions available
  355. $arrayofmassactions = array(
  356. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  357. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  358. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  359. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  360. );
  361. if (!empty($permissiontodelete)) {
  362. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  363. }
  364. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  365. $arrayofmassactions = array();
  366. }
  367. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  368. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  369. if ($optioncss != '') {
  370. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  371. }
  372. print '<input type="hidden" name="token" value="'.newToken().'">';
  373. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  374. print '<input type="hidden" name="action" value="list">';
  375. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  376. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  377. print '<input type="hidden" name="page" value="'.$page.'">';
  378. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  379. print '<input type="hidden" name="mode" value="'.$mode.'">';
  380. $newcardbutton = '';
  381. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/productlot_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  382. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  383. // Add code for pre mass action (confirmation or email presend form)
  384. $topicmail = "Information";
  385. $modelmail = "productlot";
  386. $objecttmp = new Productlot($db);
  387. $trackid = 'lot'.$object->id;
  388. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  389. if ($search_all) {
  390. $setupstring = '';
  391. foreach ($fieldstosearchall as $key => $val) {
  392. $fieldstosearchall[$key] = $langs->trans($val);
  393. $setupstring .= $key."=".$val.";";
  394. }
  395. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  396. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  397. }
  398. // Filter on categories
  399. $moreforfilter = '';
  400. /*$moreforfilter.='<div class="divsearchfield">';
  401. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  402. $moreforfilter.= '</div>';*/
  403. $parameters = array();
  404. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  405. if (empty($reshook)) {
  406. $moreforfilter .= $hookmanager->resPrint;
  407. } else {
  408. $moreforfilter = $hookmanager->resPrint;
  409. }
  410. if (!empty($moreforfilter)) {
  411. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  412. print $moreforfilter;
  413. $parameters = array();
  414. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  415. print $hookmanager->resPrint;
  416. print '</div>';
  417. }
  418. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  419. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  420. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  421. print '<div class="div-table-responsive">';
  422. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  423. // Fields title search
  424. // --------------------------------------------------------------------
  425. print '<tr class="liste_titre_filter">';
  426. // Action column
  427. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  428. print '<td class="liste_titre maxwidthsearch">';
  429. $searchpicto = $form->showFilterButtons('left');
  430. print $searchpicto;
  431. print '</td>';
  432. }
  433. foreach ($object->fields as $key => $val) {
  434. $searchkey = empty($search[$key]) ? '' : $search[$key];
  435. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  436. if ($key == 'status') {
  437. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  438. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  439. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  440. } elseif (in_array($val['type'], array('timestamp'))) {
  441. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  442. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  443. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  444. }
  445. if (!empty($arrayfields['t.'.$key]['checked'])) {
  446. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  447. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  448. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  449. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  450. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  451. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  452. print '<div class="nowrap">';
  453. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  454. print '</div>';
  455. print '<div class="nowrap">';
  456. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  457. print '</div>';
  458. } elseif ($key == 'lang') {
  459. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  460. $formadmin = new FormAdmin($db);
  461. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  462. } else {
  463. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  464. }
  465. print '</td>';
  466. }
  467. }
  468. // Extra fields
  469. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  470. // Fields from hook
  471. $parameters = array('arrayfields'=>$arrayfields);
  472. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  473. print $hookmanager->resPrint;
  474. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  475. print '<td class="liste_titre"></td>';
  476. }*/
  477. // Action column
  478. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  479. print '<td class="liste_titre maxwidthsearch">';
  480. $searchpicto = $form->showFilterButtons();
  481. print $searchpicto;
  482. print '</td>';
  483. }
  484. print '</tr>'."\n";
  485. $totalarray = array();
  486. $totalarray['nbfield'] = 0;
  487. // Fields title label
  488. // --------------------------------------------------------------------
  489. print '<tr class="liste_titre">';
  490. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  491. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  492. }
  493. foreach ($object->fields as $key => $val) {
  494. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  495. if ($key == 'status') {
  496. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  497. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  498. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  499. } elseif (in_array($val['type'], array('timestamp'))) {
  500. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  501. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  502. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  503. }
  504. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  505. if (!empty($arrayfields['t.'.$key]['checked'])) {
  506. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  507. $totalarray['nbfield']++;
  508. }
  509. }
  510. // Extra fields
  511. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  512. // Hook fields
  513. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  514. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  515. print $hookmanager->resPrint;
  516. // Action column
  517. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  518. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  519. }
  520. $totalarray['nbfield']++;
  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 (!is_null($val) && 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. $savnbfield = $totalarray['nbfield'];
  535. $totalarray['nbfield'] = 0;
  536. $imaxinloop = ($limit ? min($num, $limit) : $num);
  537. while ($i < $imaxinloop) {
  538. $obj = $db->fetch_object($resql);
  539. if (empty($obj)) {
  540. break; // Should not happen
  541. }
  542. // Store properties in $object
  543. $object->setVarsFromFetchObj($obj);
  544. // Show here line of result
  545. $j = 0;
  546. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  547. // Action column
  548. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  549. print '<td class="nowrap center">';
  550. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  551. $selected = 0;
  552. if (in_array($object->id, $arrayofselected)) {
  553. $selected = 1;
  554. }
  555. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  556. }
  557. print '</td>';
  558. }
  559. foreach ($object->fields as $key => $val) {
  560. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  561. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  562. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  563. } elseif ($key == 'status') {
  564. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  565. }
  566. if (in_array($val['type'], array('timestamp'))) {
  567. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  568. } elseif ($key == 'ref' || $key == 'batch') {
  569. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  570. }
  571. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  572. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  573. }
  574. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  575. if (!empty($arrayfields['t.'.$key]['checked'])) {
  576. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  577. if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
  578. print ' title="'.dol_escape_htmltag($object->$key).'"';
  579. }
  580. print '>';
  581. if ($key == 'status') {
  582. print $object->getLibStatut(5);
  583. } elseif ($key == 'rowid') {
  584. print $object->showOutputField($val, $key, $object->id, '');
  585. } else {
  586. if ($key == 'batch') {
  587. print $object->getNomUrl(1);
  588. } else {
  589. print $object->showOutputField($val, $key, $object->$key, '');
  590. }
  591. }
  592. print '</td>';
  593. if (!$i) {
  594. $totalarray['nbfield']++;
  595. }
  596. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  597. if (!$i) {
  598. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  599. }
  600. if (!isset($totalarray['val'])) {
  601. $totalarray['val'] = array();
  602. }
  603. if (!isset($totalarray['val']['t.'.$key])) {
  604. $totalarray['val']['t.'.$key] = 0;
  605. }
  606. $totalarray['val']['t.'.$key] += $object->$key;
  607. }
  608. }
  609. }
  610. // Extra fields
  611. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  612. // Fields from hook
  613. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  614. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  615. print $hookmanager->resPrint;
  616. // Action column
  617. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  618. print '<td class="nowrap center">';
  619. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  620. $selected = 0;
  621. if (in_array($object->id, $arrayofselected)) {
  622. $selected = 1;
  623. }
  624. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  625. }
  626. print '</td>';
  627. }
  628. if (!$i) {
  629. $totalarray['nbfield']++;
  630. }
  631. print '</tr>'."\n";
  632. $i++;
  633. }
  634. // Show total line
  635. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  636. // If no record found
  637. if ($num == 0) {
  638. $colspan = 1;
  639. foreach ($arrayfields as $key => $val) {
  640. if (!empty($val['checked'])) {
  641. $colspan++;
  642. }
  643. }
  644. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  645. }
  646. $db->free($resql);
  647. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  648. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  649. print $hookmanager->resPrint;
  650. print '</table>'."\n";
  651. print '</div>'."\n";
  652. print '</form>'."\n";
  653. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  654. $hidegeneratedfilelistifempty = 1;
  655. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  656. $hidegeneratedfilelistifempty = 0;
  657. }
  658. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  659. $formfile = new FormFile($db);
  660. // Show list of available documents
  661. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  662. $urlsource .= str_replace('&amp;', '&', $param);
  663. $filedir = $diroutputmassaction;
  664. $genallowed = $permissiontoread;
  665. $delallowed = $permissiontoadd;
  666. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  667. }
  668. // End of page
  669. llxFooter();
  670. $db->close();