stocktransfer_list.php 32 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2021 Gauthier VERDOL <gauthier.verdol@atm-consulting.fr>
  4. * Copyright (C) ---Put here your own copyright and developer email---
  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 stocktransfer_list.php
  21. * \ingroup stocktransfer
  22. * \brief List page for stocktransfer
  23. */
  24. // Load Dolibarr environment
  25. require '../../../main.inc.php';
  26. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
  27. require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
  28. require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
  29. require_once DOL_DOCUMENT_ROOT.'/core/lib/functions.lib.php';
  30. require_once DOL_DOCUMENT_ROOT.'/product/stock/stocktransfer/class/stocktransfer.class.php';
  31. // Load translation files required by the page
  32. $langs->loadLangs(array("stocks", "other"));
  33. // Get parameters
  34. $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  35. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  36. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  37. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  38. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  39. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  40. $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'stocktransferlist'; // To manage different context of search
  41. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  42. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  43. $id = GETPOST('id', 'int');
  44. // Load variable for pagination
  45. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  46. $sortfield = GETPOST('sortfield', 'aZ09comma');
  47. $sortorder = GETPOST('sortorder', 'aZ09comma');
  48. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  49. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
  50. // If $page is not defined, or '' or -1 or if we click on clear filters
  51. $page = 0;
  52. }
  53. $offset = $limit * $page;
  54. $pageprev = $page - 1;
  55. $pagenext = $page + 1;
  56. // Initialize technical objects
  57. $object = new StockTransfer($db);
  58. $extrafields = new ExtraFields($db);
  59. $diroutputmassaction = getMultidirOutput($object).'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('stocktransferlist')); // Note that conf->hooks_modules contains array
  61. // Fetch optionals attributes and labels
  62. $extrafields->fetch_name_optionals_label($object->table_element);
  63. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  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 = trim(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. // List of fields to search into when doing a "search in all"
  86. $fieldstosearchall = array();
  87. foreach ($object->fields as $key => $val) {
  88. if (!empty($val['searchall'])) {
  89. $fieldstosearchall['t.'.$key] = $val['label'];
  90. }
  91. }
  92. // Definition of array of fields for columns
  93. $arrayfields = array();
  94. foreach ($object->fields as $key => $val) {
  95. // If $val['visible']==0, then we never show the field
  96. if (!empty($val['visible'])) {
  97. $visible = (int) dol_eval($val['visible'], 1);
  98. $arrayfields['t.'.$key] = array(
  99. 'label'=>$val['label'],
  100. 'checked'=>(($visible < 0) ? 0 : 1),
  101. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  102. 'position'=>$val['position'],
  103. 'help'=> isset($val['help']) ? $val['help'] : ''
  104. );
  105. }
  106. }
  107. // Extra fields
  108. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  109. $object->fields = dol_sort_array($object->fields, 'position');
  110. $arrayfields = dol_sort_array($arrayfields, 'position');
  111. $permissiontoread = $user->hasRight('stocktransfer', 'stocktransfer', 'read');
  112. $permissiontoadd = $user->hasRight('stocktransfer', 'stocktransfer', 'write');
  113. $permissiontodelete = $user->hasRight('stocktransfer', 'stocktransfer', 'delete');
  114. // Security check
  115. if (empty($conf->stocktransfer->enabled)) {
  116. accessforbidden('Module not enabled');
  117. }
  118. // Security check (enable the most restrictive one)
  119. if ($user->socid > 0) {
  120. accessforbidden();
  121. }
  122. //$result = restrictedArea($user, 'stocktransfer', $id, '');
  123. if (!$permissiontoread) {
  124. accessforbidden();
  125. }
  126. /*
  127. * Actions
  128. */
  129. if (GETPOST('cancel', 'alpha')) {
  130. $action = 'list';
  131. $massaction = '';
  132. }
  133. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  134. $massaction = '';
  135. }
  136. $parameters = array();
  137. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  138. if ($reshook < 0) {
  139. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  140. }
  141. if (empty($reshook)) {
  142. // Selection of new fields
  143. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  144. // Purge search criteria
  145. 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
  146. foreach ($object->fields as $key => $val) {
  147. $search[$key] = '';
  148. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  149. $search[$key.'_dtstart'] = '';
  150. $search[$key.'_dtend'] = '';
  151. }
  152. }
  153. $toselect = array();
  154. $search_array_options = array();
  155. }
  156. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  157. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  158. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  159. }
  160. // Mass actions
  161. $objectclass = 'StockTransfer';
  162. $objectlabel = 'StockTransfer';
  163. $uploaddir = $conf->stocktransfer->dir_output;
  164. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  165. }
  166. /*
  167. * View
  168. */
  169. $form = new Form($db);
  170. $now = dol_now();
  171. $title = $langs->trans('StockTransferList');
  172. //$help_url="EN:Module_StockTransfer|FR:Module_StockTransfer_FR|ES:Módulo_StockTransfer";
  173. $help_url = '';
  174. $morejs = array();
  175. $morecss = array();
  176. // Build and execute select
  177. // --------------------------------------------------------------------
  178. $sql = 'SELECT ';
  179. $sql .= $object->getFieldList('t');
  180. // Add fields from extrafields
  181. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  182. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  183. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  184. }
  185. }
  186. // Add fields from hooks
  187. $parameters = array();
  188. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  189. $sql .= $hookmanager->resPrint;
  190. $sql = preg_replace('/,\s*$/', '', $sql);
  191. $sqlfields = $sql; // $sql fields to remove for count total
  192. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  193. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  194. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  195. }
  196. // Add table from hooks
  197. $parameters = array();
  198. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  199. $sql .= $hookmanager->resPrint;
  200. if ($object->ismultientitymanaged == 1) {
  201. $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOST('search_current_entity', 'int') ? 0 : 1)).")";
  202. } else {
  203. $sql .= " WHERE 1 = 1";
  204. }
  205. foreach ($search as $key => $val) {
  206. if (array_key_exists($key, $object->fields)) {
  207. if ($key == 'status' && $search[$key] == -1) {
  208. continue;
  209. }
  210. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  211. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  212. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  213. $search[$key] = '';
  214. }
  215. $mode_search = 2;
  216. }
  217. if ($search[$key] != '') {
  218. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  219. }
  220. } else {
  221. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  222. $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
  223. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  224. if (preg_match('/_dtstart$/', $key)) {
  225. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  226. }
  227. if (preg_match('/_dtend$/', $key)) {
  228. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  229. }
  230. }
  231. }
  232. }
  233. }
  234. if ($search_all) {
  235. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  236. }
  237. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  238. // Add where from extra fields
  239. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  240. // Add where from hooks
  241. $parameters = array();
  242. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  243. $sql .= $hookmanager->resPrint;
  244. /* If a group by is required
  245. $sql.= " GROUP BY ";
  246. foreach($object->fields as $key => $val) {
  247. $sql .= "t.".$db->escape($key).", ";
  248. }
  249. // Add fields from extrafields
  250. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  251. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  252. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  253. }
  254. }
  255. // Add groupby from hooks
  256. $parameters=array();
  257. $reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  258. $sql.=$hookmanager->resPrint;
  259. $sql=preg_replace('/,\s*$/','', $sql);
  260. */
  261. // Count total nb of records
  262. $nbtotalofrecords = '';
  263. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  264. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  265. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  266. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  267. $resql = $db->query($sqlforcount);
  268. if ($resql) {
  269. $objforcount = $db->fetch_object($resql);
  270. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  271. } else {
  272. dol_print_error($db);
  273. }
  274. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
  275. $page = 0;
  276. $offset = 0;
  277. }
  278. $db->free($resql);
  279. }
  280. // Complete request and execute it with limit
  281. $sql .= $db->order($sortfield, $sortorder);
  282. if ($limit) {
  283. $sql .= $db->plimit($limit + 1, $offset);
  284. }
  285. $resql = $db->query($sql);
  286. if (!$resql) {
  287. dol_print_error($db);
  288. exit;
  289. }
  290. $num = $db->num_rows($resql);
  291. // Direct jump if only one record found
  292. if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  293. $obj = $db->fetch_object($resql);
  294. $id = $obj->rowid;
  295. header("Location: ".dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?id='.$id);
  296. exit;
  297. }
  298. // Output page
  299. // --------------------------------------------------------------------
  300. llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
  301. // Example : Adding jquery code
  302. // print '<script type="text/javascript">
  303. // jQuery(document).ready(function() {
  304. // function init_myfunc()
  305. // {
  306. // jQuery("#myid").removeAttr(\'disabled\');
  307. // jQuery("#myid").attr(\'disabled\',\'disabled\');
  308. // }
  309. // init_myfunc();
  310. // jQuery("#mybutton").click(function() {
  311. // init_myfunc();
  312. // });
  313. // });
  314. // </script>';
  315. $arrayofselected = is_array($toselect) ? $toselect : array();
  316. $param = '';
  317. if (!empty($mode)) {
  318. $param .= '&mode='.urlencode($mode);
  319. }
  320. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  321. $param .= '&contextpage='.urlencode($contextpage);
  322. }
  323. if ($limit > 0 && $limit != $conf->liste_limit) {
  324. $param .= '&limit='.((int) $limit);
  325. }
  326. if ($optioncss != '') {
  327. $param .= '&optioncss='.urlencode($optioncss);
  328. }
  329. foreach ($search as $key => $val) {
  330. if (is_array($search[$key])) {
  331. foreach ($search[$key] as $skey) {
  332. if ($skey != '') {
  333. $param .= '&search_'.$key.'[]='.urlencode($skey);
  334. }
  335. }
  336. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  337. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  338. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  339. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  340. } elseif ($search[$key] != '') {
  341. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  342. }
  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, $action); // 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'=>$langs->trans("Validate"),
  353. //'generate_doc'=>$langs->trans("ReGeneratePDF"),
  354. //'builddoc'=>$langs->trans("PDFMerge"),
  355. //'presend'=>$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="page_y" value="">';
  376. print '<input type="hidden" name="mode" value="'.$mode.'">';
  377. $newcardbutton = '';
  378. $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', dol_buildpath('/product/stock/stocktransfer/stocktransfer_card.php', 1).'?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
  379. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
  380. // Add code for pre mass action (confirmation or email presend form)
  381. $topicmail = "SendStockTransferRef";
  382. $modelmail = "stocktransfer";
  383. $objecttmp = new StockTransfer($db);
  384. $trackid = 'xxxx'.$object->id;
  385. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  386. if ($search_all) {
  387. $setupstring = '';
  388. foreach ($fieldstosearchall as $key => $val) {
  389. $fieldstosearchall[$key] = $langs->trans($val);
  390. $setupstring .= $key."=".$val.";";
  391. }
  392. print '<!-- Search done like if STOCKTRANSFER_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  393. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
  394. }
  395. $moreforfilter = '';
  396. /*$moreforfilter.='<div class="divsearchfield">';
  397. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  398. $moreforfilter.= '</div>';*/
  399. $parameters = array();
  400. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  401. if (empty($reshook)) {
  402. $moreforfilter .= $hookmanager->resPrint;
  403. } else {
  404. $moreforfilter = $hookmanager->resPrint;
  405. }
  406. if (!empty($moreforfilter)) {
  407. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  408. print $moreforfilter;
  409. $parameters = array();
  410. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  411. print $hookmanager->resPrint;
  412. print '</div>';
  413. }
  414. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  415. $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
  416. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  417. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  418. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  419. // Fields title search
  420. // --------------------------------------------------------------------
  421. print '<tr class="liste_titre_filter">';
  422. // Action column
  423. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  424. print '<td class="liste_titre center maxwidthsearch">';
  425. $searchpicto = $form->showFilterButtons('left');
  426. print $searchpicto;
  427. print '</td>';
  428. }
  429. foreach ($object->fields as $key => $val) {
  430. $searchkey = empty($search[$key]) ? '' : $search[$key];
  431. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  432. if ($key == 'status') {
  433. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  434. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  435. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  436. } elseif (in_array($val['type'], array('timestamp'))) {
  437. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  438. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  439. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  440. }
  441. if (!empty($arrayfields['t.'.$key]['checked'])) {
  442. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
  443. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  444. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
  445. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
  446. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
  447. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  448. print '<div class="nowrap">';
  449. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  450. print '</div>';
  451. print '<div class="nowrap">';
  452. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  453. print '</div>';
  454. } elseif ($key == 'lang') {
  455. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
  456. $formadmin = new FormAdmin($db);
  457. print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
  458. } else {
  459. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  460. }
  461. print '</td>';
  462. }
  463. }
  464. // Extra fields
  465. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  466. // Fields from hook
  467. $parameters = array('arrayfields'=>$arrayfields);
  468. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  469. print $hookmanager->resPrint;
  470. // Action column
  471. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  472. print '<td class="liste_titre center maxwidthsearch">';
  473. $searchpicto = $form->showFilterButtons();
  474. print $searchpicto;
  475. print '</td>';
  476. }
  477. print '</tr>'."\n";
  478. $totalarray = array();
  479. $totalarray['nbfield'] = 0;
  480. // Fields title label
  481. // --------------------------------------------------------------------
  482. print '<tr class="liste_titre">';
  483. // Action column
  484. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  485. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  486. $totalarray['nbfield']++;
  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')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && $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.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\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, $action); // Note that $action and $object may have been modified by hook
  510. print $hookmanager->resPrint;
  511. // Action column
  512. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  513. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  514. $totalarray['nbfield']++;
  515. }
  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 (!is_null($val) && 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 = array();
  531. $totalarray['nbfield'] = 0;
  532. $imaxinloop = ($limit ? min($num, $limit) : $num);
  533. while ($i < $imaxinloop) {
  534. $obj = $db->fetch_object($resql);
  535. if (empty($obj)) {
  536. break; // Should not happen
  537. }
  538. // Store properties in $object
  539. $object->setVarsFromFetchObj($obj);
  540. if ($mode == 'kanban') {
  541. if ($i == 0) {
  542. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  543. print '<div class="box-flex-container kanban">';
  544. }
  545. // Output Kanban
  546. $selected = -1;
  547. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  548. $selected = 0;
  549. if (in_array($object->id, $arrayofselected)) {
  550. $selected = 1;
  551. }
  552. }
  553. //print $object->getKanbanView('', array('thirdparty'=>$object->thirdparty, 'selected' => $selected));
  554. print $object->getKanbanView('', array('selected' => $selected));
  555. if ($i == ($imaxinloop - 1)) {
  556. print '</div>';
  557. print '</td></tr>';
  558. }
  559. } else {
  560. // Show line of result
  561. $j = 0;
  562. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  563. // Action column
  564. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  565. print '<td class="nowrap center">';
  566. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  567. $selected = 0;
  568. if (in_array($object->id, $arrayofselected)) {
  569. $selected = 1;
  570. }
  571. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  572. }
  573. print '</td>';
  574. if (!$i) {
  575. $totalarray['nbfield']++;
  576. }
  577. }
  578. foreach ($object->fields as $key => $val) {
  579. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  580. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  581. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  582. } elseif ($key == 'status') {
  583. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  584. }
  585. if (in_array($val['type'], array('timestamp'))) {
  586. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  587. } elseif ($key == 'ref') {
  588. $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
  589. }
  590. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
  591. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  592. }
  593. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  594. if (!empty($arrayfields['t.'.$key]['checked'])) {
  595. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  596. if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
  597. print ' title="'.dol_escape_htmltag($object->$key).'"';
  598. }
  599. print '>';
  600. if ($key == 'status') {
  601. print $object->getLibStatut(5);
  602. } elseif ($key == 'rowid') {
  603. print $object->showOutputField($val, $key, $object->id, '');
  604. } else {
  605. print $object->showOutputField($val, $key, $object->$key, '');
  606. }
  607. print '</td>';
  608. if (!$i) {
  609. $totalarray['nbfield']++;
  610. }
  611. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  612. if (!$i) {
  613. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  614. }
  615. if (!isset($totalarray['val'])) {
  616. $totalarray['val'] = array();
  617. }
  618. if (!isset($totalarray['val']['t.'.$key])) {
  619. $totalarray['val']['t.'.$key] = 0;
  620. }
  621. $totalarray['val']['t.'.$key] += $object->$key;
  622. }
  623. }
  624. }
  625. // Extra fields
  626. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  627. // Fields from hook
  628. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  629. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  630. print $hookmanager->resPrint;
  631. // Action column
  632. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  633. print '<td class="nowrap center">';
  634. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  635. $selected = 0;
  636. if (in_array($object->id, $arrayofselected)) {
  637. $selected = 1;
  638. }
  639. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  640. }
  641. print '</td>';
  642. if (!$i) {
  643. $totalarray['nbfield']++;
  644. }
  645. }
  646. print '</tr>'."\n";
  647. }
  648. $i++;
  649. }
  650. // Show total line
  651. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  652. // If no record found
  653. if ($num == 0) {
  654. $colspan = 1;
  655. foreach ($arrayfields as $key => $val) {
  656. if (!empty($val['checked'])) {
  657. $colspan++;
  658. }
  659. }
  660. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  661. }
  662. $db->free($resql);
  663. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  664. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  665. print $hookmanager->resPrint;
  666. print '</table>'."\n";
  667. print '</div>'."\n";
  668. print '</form>'."\n";
  669. if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  670. $hidegeneratedfilelistifempty = 1;
  671. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  672. $hidegeneratedfilelistifempty = 0;
  673. }
  674. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  675. $formfile = new FormFile($db);
  676. // Show list of available documents
  677. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  678. $urlsource .= str_replace('&amp;', '&', $param);
  679. $filedir = $diroutputmassaction;
  680. $genallowed = $permissiontoread;
  681. $delallowed = $permissiontoadd;
  682. print $formfile->showdocuments('massfilesarea_'.$object->module, '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  683. }
  684. // End of page
  685. llxFooter();
  686. $db->close();