cashcontrol_list.php 28 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683
  1. <?php
  2. /* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) ---Put here your own copyright and developer email---
  4. *
  5. * This program is free software; you can redistribute it and/or modify
  6. * it under the terms of the GNU General Public License as published by
  7. * the Free Software Foundation; either version 3 of the License, or
  8. * (at your option) any later version.
  9. *
  10. * This program is distributed in the hope that it will be useful,
  11. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. * GNU General Public License for more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  17. */
  18. /**
  19. * \file htdocs/compta/cashcontrol/cashcontrol_list.php
  20. * \ingroup cashdesk|takepos
  21. * \brief List page for cashcontrol
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.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. // Load translation files required by the page
  30. $langs->loadLangs(array("banks", "other"));
  31. $action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
  32. $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
  33. $show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
  34. $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
  35. $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
  36. $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
  37. $contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'cashcontrol'; // To manage different context of search
  38. $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
  39. $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
  40. $id = GETPOST('id', 'int');
  41. // Load variable for pagination
  42. $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
  43. $sortfield = GETPOST('sortfield', 'aZ09comma');
  44. $sortorder = GETPOST('sortorder', 'aZ09comma');
  45. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  46. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  47. // If $page is not defined, or '' or -1 or if we click on clear filters
  48. $page = 0;
  49. }
  50. $offset = $limit * $page;
  51. $pageprev = $page - 1;
  52. $pagenext = $page + 1;
  53. //if (! $sortfield) $sortfield="p.date_fin";
  54. //if (! $sortorder) $sortorder="DESC";
  55. // Initialize technical objects
  56. $object = new CashControl($db);
  57. $extrafields = new ExtraFields($db);
  58. //$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  59. $hookmanager->initHooks(array('cashcontrol')); // Note that conf->hooks_modules contains array
  60. // Fetch optionals attributes and labels
  61. $extrafields->fetch_name_optionals_label($object->table_element);
  62. //$extrafields->fetch_name_optionals_label($object->table_element_line);
  63. $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
  64. // Default sort order (if not yet defined by previous GETPOST)
  65. if (!$sortfield) {
  66. reset($object->fields); // Reset is required to avoid key() to return null.
  67. $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
  68. }
  69. if (!$sortorder) {
  70. $sortorder = "ASC";
  71. }
  72. // Initialize array of search criterias
  73. $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
  74. $search = array();
  75. foreach ($object->fields as $key => $val) {
  76. if (GETPOST('search_'.$key, 'alpha') !== '') {
  77. $search[$key] = GETPOST('search_'.$key, 'alpha');
  78. }
  79. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  80. $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
  81. $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
  82. }
  83. }
  84. // List of fields to search into when doing a "search in all"
  85. $fieldstosearchall = array();
  86. foreach ($object->fields as $key => $val) {
  87. if (!empty($val['searchall'])) {
  88. $fieldstosearchall['t.'.$key] = $val['label'];
  89. }
  90. }
  91. // Definition of array of fields for columns
  92. $arrayfields = array();
  93. foreach ($object->fields as $key => $val) {
  94. // If $val['visible']==0, then we never show the field
  95. if (!empty($val['visible'])) {
  96. $visible = (int) dol_eval($val['visible'], 1);
  97. $arrayfields['t.'.$key] = array(
  98. 'label'=>$val['label'],
  99. 'checked'=>(($visible < 0) ? 0 : 1),
  100. 'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
  101. 'position'=>$val['position'],
  102. 'help'=> isset($val['help']) ? $val['help'] : ''
  103. );
  104. }
  105. }
  106. // Extra fields
  107. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
  108. $object->fields = dol_sort_array($object->fields, 'position');
  109. $arrayfields = dol_sort_array($arrayfields, 'position');
  110. $permissiontoread = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  111. $permissiontoadd = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  112. $permissiontodelete = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  113. // Security check
  114. if ($user->socid > 0) { // Protection if external user
  115. //$socid = $user->socid;
  116. accessforbidden();
  117. }
  118. if (empty($user->rights->cashdesk->run) && empty($user->rights->takepos->run)) {
  119. accessforbidden();
  120. }
  121. /*
  122. * Actions
  123. */
  124. if (GETPOST('cancel', 'alpha')) {
  125. $action = 'list';
  126. $massaction = '';
  127. }
  128. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  129. $massaction = '';
  130. }
  131. $parameters = array();
  132. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  133. if ($reshook < 0) {
  134. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  135. }
  136. if (empty($reshook)) {
  137. // Selection of new fields
  138. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  139. // Purge search criteria
  140. 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
  141. foreach ($object->fields as $key => $val) {
  142. $search[$key] = '';
  143. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  144. $search[$key.'_dtstart'] = '';
  145. $search[$key.'_dtend'] = '';
  146. }
  147. }
  148. $toselect = array();
  149. $search_array_options = array();
  150. }
  151. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  152. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  153. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  154. }
  155. // Mass actions
  156. $objectclass = 'CashControl';
  157. $objectlabel = 'CashControl';
  158. //$uploaddir = '';
  159. //include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  160. }
  161. /*
  162. * View
  163. */
  164. $form = new Form($db);
  165. $now = dol_now();
  166. //$help_url="EN:Module_pos_cash_fence|FR:Module_pos_cash_fence_FR|ES:Módulo_pos_cash_fence";
  167. $help_url = '';
  168. $title = $langs->trans('CashControl');
  169. $morejs = array();
  170. $morecss = array();
  171. // Build and execute select
  172. // --------------------------------------------------------------------
  173. $sql = 'SELECT ';
  174. $sql .= $object->getFieldList('t');
  175. // Add fields from extrafields
  176. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  177. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  178. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  179. }
  180. }
  181. // Add fields from hooks
  182. $parameters = array();
  183. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  184. $sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
  185. $sql = preg_replace('/,\s*$/', '', $sql);
  186. $sqlfields = $sql; // $sql fields to remove for count total
  187. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  188. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  189. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  190. }
  191. // Add table from hooks
  192. $parameters = array();
  193. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  194. $sql .= $hookmanager->resPrint;
  195. if ($object->ismultientitymanaged == 1) {
  196. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  197. } else {
  198. $sql .= " WHERE 1 = 1";
  199. }
  200. foreach ($search as $key => $val) {
  201. if (array_key_exists($key, $object->fields)) {
  202. if ($key == 'status' && $search[$key] == -1) {
  203. continue;
  204. }
  205. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  206. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  207. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  208. $search[$key] = '';
  209. }
  210. $mode_search = 2;
  211. }
  212. if ($search[$key] != '') {
  213. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  214. }
  215. } else {
  216. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  217. $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
  218. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  219. if (preg_match('/_dtstart$/', $key)) {
  220. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  221. }
  222. if (preg_match('/_dtend$/', $key)) {
  223. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  224. }
  225. }
  226. }
  227. }
  228. }
  229. if ($search_all) {
  230. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  231. }
  232. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  233. // Add where from extra fields
  234. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  235. // Add where from hooks
  236. $parameters = array();
  237. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  238. $sql .= $hookmanager->resPrint;
  239. /* If a group by is required
  240. $sql.= " GROUP BY ";
  241. foreach($object->fields as $key => $val) {
  242. $sql .= "t.".$db->escape($key).", ";
  243. }
  244. // Add fields from extrafields
  245. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  246. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  247. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  248. }
  249. }
  250. // Add where from hooks
  251. $parameters=array();
  252. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
  253. $sql.=$hookmanager->resPrint;
  254. $sql=preg_replace('/,\s*$/','', $sql);
  255. */
  256. // Count total nb of records
  257. $nbtotalofrecords = '';
  258. if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
  259. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  260. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  261. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  262. $resql = $db->query($sqlforcount);
  263. if ($resql) {
  264. $objforcount = $db->fetch_object($resql);
  265. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  266. } else {
  267. dol_print_error($db);
  268. }
  269. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  270. $page = 0;
  271. $offset = 0;
  272. }
  273. $db->free($resql);
  274. }
  275. // Complete request and execute it with limit
  276. $sql .= $db->order($sortfield, $sortorder);
  277. if ($limit) {
  278. $sql .= $db->plimit($limit + 1, $offset);
  279. }
  280. $resql = $db->query($sql);
  281. if (!$resql) {
  282. dol_print_error($db);
  283. exit;
  284. }
  285. $num = $db->num_rows($resql);
  286. // Direct jump if only one record found
  287. if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
  288. $obj = $db->fetch_object($resql);
  289. $id = $obj->rowid;
  290. header("Location: ".DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$id);
  291. exit;
  292. }
  293. // Output page
  294. // --------------------------------------------------------------------
  295. llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
  296. $arrayofselected = is_array($toselect) ? $toselect : array();
  297. $param = '';
  298. if (!empty($mode)) {
  299. $param .= '&mode='.urlencode($mode);
  300. }
  301. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  302. $param .= '&contextpage='.urlencode($contextpage);
  303. }
  304. if ($limit > 0 && $limit != $conf->liste_limit) {
  305. $param .= '&limit='.urlencode($limit);
  306. }
  307. foreach ($search as $key => $val) {
  308. if (is_array($search[$key])) {
  309. foreach ($search[$key] as $skey) {
  310. if ($skey != '') {
  311. $param .= '&search_'.$key.'[]='.urlencode($skey);
  312. }
  313. }
  314. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  315. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  316. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  317. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  318. } elseif ($search[$key] != '') {
  319. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  320. }
  321. }
  322. if ($optioncss != '') {
  323. $param .= '&optioncss='.urlencode($optioncss);
  324. }
  325. // Add $param from extra fields
  326. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  327. // Add $param from hooks
  328. $parameters = array();
  329. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  330. $param .= $hookmanager->resPrint;
  331. // List of mass actions available
  332. $arrayofmassactions = array(
  333. //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
  334. //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
  335. );
  336. //if ($permissiontodelete) {
  337. // $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  338. //}
  339. if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
  340. $arrayofmassactions = array();
  341. }
  342. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  343. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  344. if ($optioncss != '') {
  345. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  346. }
  347. print '<input type="hidden" name="token" value="'.newToken().'">';
  348. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  349. print '<input type="hidden" name="action" value="list">';
  350. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  351. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  352. print '<input type="hidden" name="page" value="'.$page.'">';
  353. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  354. $permforcashfence = 1;
  355. $newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permforcashfence);
  356. print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'cash-register', 0, $newcardbutton, '', $limit, 0, 0, 1);
  357. // Add code for pre mass action (confirmation or email presend form)
  358. $topicmail = "SendCashControlRef";
  359. $modelmail = "cashcontrol";
  360. $objecttmp = new CashControl($db);
  361. $trackid = 'cashfence'.$object->id;
  362. include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
  363. if ($search_all) {
  364. $setupstring = '';
  365. foreach ($fieldstosearchall as $key => $val) {
  366. $fieldstosearchall[$key] = $langs->trans($val);
  367. $setupstring .= $key."=".$val.";";
  368. }
  369. print '<!-- Search done like if PRODUCT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
  370. print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
  371. }
  372. $moreforfilter = '';
  373. /*$moreforfilter.='<div class="divsearchfield">';
  374. $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
  375. $moreforfilter.= '</div>';*/
  376. $parameters = array();
  377. $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  378. if (empty($reshook)) {
  379. $moreforfilter .= $hookmanager->resPrint;
  380. } else {
  381. $moreforfilter = $hookmanager->resPrint;
  382. }
  383. if (!empty($moreforfilter)) {
  384. print '<div class="liste_titre liste_titre_bydiv centpercent">';
  385. print $moreforfilter;
  386. print '</div>';
  387. }
  388. $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
  389. $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
  390. $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
  391. print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
  392. print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
  393. // Fields title search
  394. // --------------------------------------------------------------------
  395. print '<tr class="liste_titre">';
  396. foreach ($object->fields as $key => $val) {
  397. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  398. if ($key == 'status') {
  399. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  400. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  401. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  402. } elseif (in_array($val['type'], array('timestamp'))) {
  403. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  404. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $key != 'rowid' && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  405. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  406. }
  407. if (!empty($arrayfields['t.'.$key]['checked'])) {
  408. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  409. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  410. print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status onrightofpage' : ''), 1);
  411. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
  412. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  413. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  414. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  415. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  416. print '<div class="nowrap">';
  417. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  418. print '</div>';
  419. print '<div class="nowrap">';
  420. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  421. print '</div>';
  422. }
  423. print '</td>';
  424. }
  425. }
  426. // Extra fields
  427. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  428. // Fields from hook
  429. $parameters = array('arrayfields'=>$arrayfields);
  430. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  431. print $hookmanager->resPrint;
  432. // Action column
  433. print '<td class="liste_titre maxwidthsearch">';
  434. $searchpicto = $form->showFilterButtons();
  435. print $searchpicto;
  436. print '</td>';
  437. print '</tr>'."\n";
  438. // Fields title label
  439. // --------------------------------------------------------------------
  440. print '<tr class="liste_titre">';
  441. foreach ($object->fields as $key => $val) {
  442. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  443. if ($key == 'status') {
  444. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  445. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  446. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  447. } elseif (in_array($val['type'], array('timestamp'))) {
  448. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  449. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  450. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  451. }
  452. if (!empty($arrayfields['t.'.$key]['checked'])) {
  453. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  454. }
  455. }
  456. // Extra fields
  457. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  458. // Hook fields
  459. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
  460. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  461. print $hookmanager->resPrint;
  462. // Action column
  463. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  464. print '</tr>'."\n";
  465. // Detect if we need a fetch on each output line
  466. $needToFetchEachLine = 0;
  467. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  468. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  469. if (preg_match('/\$object/', $val)) {
  470. $needToFetchEachLine++; // There is at least one compute field that use $object
  471. }
  472. }
  473. }
  474. // Loop on record
  475. // --------------------------------------------------------------------
  476. $i = 0;
  477. $totalarray = array();
  478. $totalarray['nbfield'] = 0;
  479. while ($i < ($limit ? min($num, $limit) : $num)) {
  480. $obj = $db->fetch_object($resql);
  481. if (empty($obj)) {
  482. break; // Should not happen
  483. }
  484. // Store properties in $object
  485. $object->setVarsFromFetchObj($obj);
  486. // Show here line of result
  487. $j = 0;
  488. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  489. foreach ($object->fields as $key => $val) {
  490. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  491. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  492. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  493. } elseif ($key == 'status') {
  494. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  495. }
  496. if (in_array($val['type'], array('timestamp'))) {
  497. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  498. } elseif ($key == 'ref') {
  499. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  500. }
  501. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  502. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  503. }
  504. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  505. if (!empty($arrayfields['t.'.$key]['checked'])) {
  506. print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '');
  507. if (preg_match('/tdoverflow/', $cssforfield)) {
  508. print ' title="'.dol_escape_htmltag($object->$key).'"';
  509. }
  510. print '>';
  511. if ($key == 'status') {
  512. print $object->getLibStatut(5);
  513. } elseif ($key == 'rowid') {
  514. print $object->showOutputField($val, $key, $object->id, '');
  515. } else {
  516. print $object->showOutputField($val, $key, $object->$key, '');
  517. }
  518. print '</td>';
  519. if (!$i) {
  520. $totalarray['nbfield']++;
  521. }
  522. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  523. if (!$i) {
  524. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  525. }
  526. if (!isset($totalarray['val'])) {
  527. $totalarray['val'] = array();
  528. }
  529. if (!isset($totalarray['val']['t.'.$key])) {
  530. $totalarray['val']['t.'.$key] = 0;
  531. }
  532. $totalarray['val']['t.'.$key] += $object->$key;
  533. }
  534. }
  535. }
  536. // Extra fields
  537. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  538. // Fields from hook
  539. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  540. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  541. print $hookmanager->resPrint;
  542. // Action column
  543. print '<td class="nowrap center">';
  544. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  545. $selected = 0;
  546. if (in_array($object->id, $arrayofselected)) {
  547. $selected = 1;
  548. }
  549. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  550. }
  551. print '</td>';
  552. if (!$i) {
  553. $totalarray['nbfield']++;
  554. }
  555. print '</tr>'."\n";
  556. $i++;
  557. }
  558. // Show total line
  559. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  560. // If no record found
  561. if ($num == 0) {
  562. $colspan = 1;
  563. foreach ($arrayfields as $key => $val) {
  564. if (!empty($val['checked'])) {
  565. $colspan++;
  566. }
  567. }
  568. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  569. }
  570. $db->free($resql);
  571. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  572. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  573. print $hookmanager->resPrint;
  574. print '</table>'."\n";
  575. print '</div>'."\n";
  576. print '</form>'."\n";
  577. /*
  578. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  579. $hidegeneratedfilelistifempty = 1;
  580. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  581. $hidegeneratedfilelistifempty = 0;
  582. }
  583. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  584. $formfile = new FormFile($db);
  585. // Show list of available documents
  586. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  587. $urlsource .= str_replace('&amp;', '&', $param);
  588. $filedir = $diroutputmassaction;
  589. $genallowed = $permissiontoread;
  590. $delallowed = $permissiontoadd;
  591. print $formfile->showdocuments('massfilesarea_monmodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  592. }
  593. */
  594. // End of page
  595. llxFooter();
  596. $db->close();