productlot_list.php 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751
  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) accessforbidden();
  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. $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 = 'ProductLot';
  169. $objectlabel = 'LotSerial';
  170. $uploaddir = $conf->productbatch->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_Lot_/_Serial|FR:Module_Lot_/_Série';
  179. $title = $langs->trans('LotSerialList');
  180. $morejs = array();
  181. $morecss = array();
  182. // Build and execute select
  183. // --------------------------------------------------------------------
  184. $sql = 'SELECT ';
  185. $sql .= $object->getFieldList('t');
  186. // Add fields from extrafields
  187. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  188. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  189. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  190. }
  191. }
  192. // Add fields from hooks
  193. $parameters = array();
  194. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  195. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  196. $sql = preg_replace('/,\s*$/', '', $sql);
  197. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  198. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  199. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  200. }
  201. // Add table from hooks
  202. $parameters = array();
  203. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  204. $sql .= $hookmanager->resPrint;
  205. if ($object->ismultientitymanaged == 1) {
  206. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  207. } else {
  208. $sql .= " WHERE 1 = 1";
  209. }
  210. foreach ($search as $key => $val) {
  211. if (array_key_exists($key, $object->fields)) {
  212. if ($key == 'status' && $search[$key] == -1) {
  213. continue;
  214. }
  215. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  216. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  217. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  218. $search[$key] = '';
  219. }
  220. $mode_search = 2;
  221. }
  222. if ($search[$key] != '') {
  223. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  224. }
  225. } else {
  226. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  227. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  228. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  229. if (preg_match('/_dtstart$/', $key)) {
  230. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  231. }
  232. if (preg_match('/_dtend$/', $key)) {
  233. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  234. }
  235. }
  236. }
  237. }
  238. }
  239. if ($search_all) {
  240. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  241. }
  242. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  243. // Add where from extra fields
  244. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  245. // Add where from hooks
  246. $parameters = array();
  247. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  248. $sql .= $hookmanager->resPrint;
  249. /* If a group by is required
  250. $sql.= " GROUP BY ";
  251. foreach($object->fields as $key => $val) {
  252. $sql .= "t.".$db->escape($key).", ";
  253. }
  254. // Add fields from extrafields
  255. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  256. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  257. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  258. }
  259. }
  260. // Add where from hooks
  261. $parameters=array();
  262. $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
  263. $sql.=$hookmanager->resPrint;
  264. $sql=preg_replace('/,\s*$/','', $sql);
  265. */
  266. // Count total nb of records
  267. $nbtotalofrecords = '';
  268. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  269. /* This old and fast method to get and count full list returns all record so use a high amount of memory.
  270. $resql = $db->query($sql);
  271. $nbtotalofrecords = $db->num_rows($resql);
  272. */
  273. /* The slow method does not consume memory on mysql (not tested on pgsql) */
  274. /*$resql = $db->query($sql, 0, 'auto', 1);
  275. while ($db->fetch_object($resql)) {
  276. if (empty($nbtotalofrecords)) {
  277. $nbtotalofrecords = 1; // We can't make +1 because init value is ''
  278. } else {
  279. $nbtotalofrecords++;
  280. }
  281. }*/
  282. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  283. $sqlforcount = preg_replace('/^SELECT[a-zA-Z0-9\._\s\(\),=<>\:\-\']+\sFROM/Ui', 'SELECT COUNT(*) as nbtotalofrecords FROM', $sql);
  284. $resql = $db->query($sqlforcount);
  285. if ($resql) {
  286. $objforcount = $db->fetch_object($resql);
  287. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  288. } else {
  289. dol_print_error($db);
  290. }
  291. if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
  292. $page = 0;
  293. $offset = 0;
  294. }
  295. $db->free($resql);
  296. }
  297. // Complete request and execute it with limit
  298. $sql .= $db->order($sortfield, $sortorder);
  299. if ($limit) {
  300. $sql .= $db->plimit($limit + 1, $offset);
  301. }
  302. $resql = $db->query($sql);
  303. if (!$resql) {
  304. dol_print_error($db);
  305. exit;
  306. }
  307. $num = $db->num_rows($resql);
  308. $i = 0;
  309. // Direct jump if only one record found
  310. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  311. $obj = $db->fetch_object($resql);
  312. $id = $obj->rowid;
  313. header("Location: ".DOL_URL_ROOT.'/product/stock/productlot_card.php?id='.$id);
  314. exit;
  315. }
  316. // Output page
  317. // --------------------------------------------------------------------
  318. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist');
  319. $arrayofselected = is_array($toselect) ? $toselect : array();
  320. $param = '';
  321. if (!empty($mode)) {
  322. $param .= '&mode='.urlencode($mode);
  323. }
  324. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  325. $param .= '&contextpage='.urlencode($contextpage);
  326. }
  327. if ($limit > 0 && $limit != $conf->liste_limit) {
  328. $param .= '&limit='.urlencode($limit);
  329. }
  330. foreach ($search as $key => $val) {
  331. if (is_array($search[$key]) && count($search[$key])) {
  332. foreach ($search[$key] as $skey) {
  333. if ($skey != '') {
  334. $param .= '&search_'.$key.'[]='.urlencode($skey);
  335. }
  336. }
  337. } elseif ($search[$key] != '') {
  338. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  339. }
  340. }
  341. if ($optioncss != '') {
  342. $param .= '&optioncss='.urlencode($optioncss);
  343. }
  344. // Add $param from extra fields
  345. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  346. // Add $param from hooks
  347. $parameters = array();
  348. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  349. $param .= $hookmanager->resPrint;
  350. // List of mass actions available
  351. $arrayofmassactions = array(
  352. //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
  353. //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
  354. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  355. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  356. );
  357. if (!empty($permissiontodelete)) {
  358. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  359. }
  360. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  361. $arrayofmassactions = array();
  362. }
  363. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  364. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  365. if ($optioncss != '') {
  366. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  367. }
  368. print '<input type="hidden" name="token" value="'.newToken().'">';
  369. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  370. print '<input type="hidden" name="action" value="list">';
  371. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  372. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  373. print '<input type="hidden" name="page" value="'.$page.'">';
  374. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  375. print '<input type="hidden" name="mode" value="'.$mode.'">';
  376. $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);
  377. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  378. // Add code for pre mass action (confirmation or email presend form)
  379. $topicmail = "Information";
  380. $modelmail = "productlot";
  381. $objecttmp = new Productlot($db);
  382. $trackid = 'lot'.$object->id;
  383. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  384. if ($search_all) {
  385. $setupstring = '';
  386. foreach ($fieldstosearchall as $key => $val) {
  387. $fieldstosearchall[$key] = $langs->trans($val);
  388. $setupstring .= $key."=".$val.";";
  389. }
  390. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  391. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  392. }
  393. // Filter on categories
  394. $moreforfilter = '';
  395. /*$moreforfilter.='<div class="divsearchfield">';
  396. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  397. $moreforfilter.= '</div>';*/
  398. $parameters = array();
  399. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  400. if (empty($reshook)) {
  401. $moreforfilter .= $hookmanager->resPrint;
  402. } else {
  403. $moreforfilter = $hookmanager->resPrint;
  404. }
  405. if (!empty($moreforfilter)) {
  406. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  407. print $moreforfilter;
  408. $parameters = array();
  409. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters); // Note that $action and $object may have been modified by hook
  410. print $hookmanager->resPrint;
  411. print '</div>';
  412. }
  413. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  414. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')); // This also change content of $arrayfields
  415. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  416. print '<div class="div-table-responsive">';
  417. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  418. // Fields title search
  419. // --------------------------------------------------------------------
  420. print '<tr class="liste_titre_filter">';
  421. // Action column
  422. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  423. print '<td class="liste_titre maxwidthsearch">';
  424. $searchpicto = $form->showFilterButtons('left');
  425. print $searchpicto;
  426. print '</td>';
  427. }
  428. foreach ($object->fields as $key => $val) {
  429. $searchkey = empty($search[$key]) ? '' : $search[$key];
  430. $cssforfield = (empty($val['css']) ? '' : $val['css']);
  431. if ($key == 'status') {
  432. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  433. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  434. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  435. } elseif (in_array($val['type'], array('timestamp'))) {
  436. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  437. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  438. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  439. }
  440. if (!empty($arrayfields['t.'.$key]['checked'])) {
  441. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  442. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  443. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
  444. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  445. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  446. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  447. print '<div class="nowrap">';
  448. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  449. print '</div>';
  450. print '<div class="nowrap">';
  451. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  452. print '</div>';
  453. } elseif ($key == 'lang') {
  454. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  455. $formadmin = new FormAdmin($db);
  456. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  457. } else {
  458. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  459. }
  460. print '</td>';
  461. }
  462. }
  463. // Extra fields
  464. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  465. // Fields from hook
  466. $parameters = array('arrayfields'=>$arrayfields);
  467. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  468. print $hookmanager->resPrint;
  469. /*if (!empty($arrayfields['anotherfield']['checked'])) {
  470. print '<td class="liste_titre"></td>';
  471. }*/
  472. // Action column
  473. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  474. print '<td class="liste_titre maxwidthsearch">';
  475. $searchpicto = $form->showFilterButtons();
  476. print $searchpicto;
  477. print '</td>';
  478. }
  479. print '</tr>'."\n";
  480. $totalarray = array();
  481. $totalarray['nbfield'] = 0;
  482. // Fields title label
  483. // --------------------------------------------------------------------
  484. print '<tr class="liste_titre">';
  485. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  486. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  487. }
  488. foreach ($object->fields as $key => $val) {
  489. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  490. if ($key == 'status') {
  491. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  492. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  493. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  494. } elseif (in_array($val['type'], array('timestamp'))) {
  495. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  496. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  497. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  498. }
  499. $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
  500. if (!empty($arrayfields['t.'.$key]['checked'])) {
  501. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  502. $totalarray['nbfield']++;
  503. }
  504. }
  505. // Extra fields
  506. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  507. // Hook fields
  508. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  509. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  510. print $hookmanager->resPrint;
  511. // Action column
  512. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  513. print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  514. }
  515. $totalarray['nbfield']++;
  516. print '</tr>'."\n";
  517. // Detect if we need a fetch on each output line
  518. $needToFetchEachLine = 0;
  519. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  520. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  521. if (preg_match('/\$object/', $val)) {
  522. $needToFetchEachLine++; // There is at least one compute field that use $object
  523. }
  524. }
  525. }
  526. // Loop on record
  527. // --------------------------------------------------------------------
  528. $i = 0;
  529. $savnbfield = $totalarray['nbfield'];
  530. $totalarray['nbfield'] = 0;
  531. $imaxinloop = ($limit ? min($num, $limit) : $num);
  532. while ($i < $imaxinloop) {
  533. $obj = $db->fetch_object($resql);
  534. if (empty($obj)) {
  535. break; // Should not happen
  536. }
  537. // Store properties in $object
  538. $object->setVarsFromFetchObj($obj);
  539. // Show here line of result
  540. $j = 0;
  541. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  542. // Action column
  543. if (!empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  544. print '<td class="nowrap center">';
  545. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  546. $selected = 0;
  547. if (in_array($object->id, $arrayofselected)) {
  548. $selected = 1;
  549. }
  550. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  551. }
  552. print '</td>';
  553. }
  554. foreach ($object->fields as $key => $val) {
  555. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  556. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  557. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  558. } elseif ($key == 'status') {
  559. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  560. }
  561. if (in_array($val['type'], array('timestamp'))) {
  562. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  563. } elseif ($key == 'ref' || $key == 'batch') {
  564. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  565. }
  566. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  567. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  568. }
  569. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  570. if (!empty($arrayfields['t.'.$key]['checked'])) {
  571. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
  572. if (preg_match('/tdoverflow/', $cssforfield)) {
  573. print ' title="'.dol_escape_htmltag($object->$key).'"';
  574. }
  575. print '>';
  576. if ($key == 'status') {
  577. print $object->getLibStatut(5);
  578. } elseif ($key == 'rowid') {
  579. print $object->showOutputField($val, $key, $object->id, '');
  580. } else {
  581. if ($key == 'batch') {
  582. print $object->getNomUrl(1);
  583. } else {
  584. print $object->showOutputField($val, $key, $object->$key, '');
  585. }
  586. }
  587. print '</td>';
  588. if (!$i) {
  589. $totalarray['nbfield']++;
  590. }
  591. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  592. if (!$i) {
  593. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  594. }
  595. if (!isset($totalarray['val'])) {
  596. $totalarray['val'] = array();
  597. }
  598. if (!isset($totalarray['val']['t.'.$key])) {
  599. $totalarray['val']['t.'.$key] = 0;
  600. }
  601. $totalarray['val']['t.'.$key] += $object->$key;
  602. }
  603. }
  604. }
  605. // Extra fields
  606. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  607. // Fields from hook
  608. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  609. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  610. print $hookmanager->resPrint;
  611. // Action column
  612. if (empty($conf->global->MAIN_CHECKBOX_LEFT_COLUMN)) {
  613. print '<td class="nowrap center">';
  614. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  615. $selected = 0;
  616. if (in_array($object->id, $arrayofselected)) {
  617. $selected = 1;
  618. }
  619. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  620. }
  621. print '</td>';
  622. }
  623. if (!$i) {
  624. $totalarray['nbfield']++;
  625. }
  626. print '</tr>'."\n";
  627. $i++;
  628. }
  629. // Show total line
  630. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  631. // If no record found
  632. if ($num == 0) {
  633. $colspan = 1;
  634. foreach ($arrayfields as $key => $val) {
  635. if (!empty($val['checked'])) {
  636. $colspan++;
  637. }
  638. }
  639. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  640. }
  641. $db->free($resql);
  642. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  643. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  644. print $hookmanager->resPrint;
  645. print '</table>'."\n";
  646. print '</div>'."\n";
  647. print '</form>'."\n";
  648. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  649. $hidegeneratedfilelistifempty = 1;
  650. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  651. $hidegeneratedfilelistifempty = 0;
  652. }
  653. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  654. $formfile = new FormFile($db);
  655. // Show list of available documents
  656. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  657. $urlsource .= str_replace('&amp;', '&', $param);
  658. $filedir = $diroutputmassaction;
  659. $genallowed = $permissiontoread;
  660. $delallowed = $permissiontoadd;
  661. print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  662. }
  663. // End of page
  664. llxFooter();
  665. $db->close();