cashcontrol_list.php 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  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. $mode = GETPOST('mode', 'alpha'); // for mode view result
  41. $id = GETPOST('id', 'int');
  42. // Load variable for pagination
  43. $limit = GETPOST('limit', 'int') ? GETPOST('limit', 'int') : $conf->liste_limit;
  44. $sortfield = GETPOST('sortfield', 'aZ09comma');
  45. $sortorder = GETPOST('sortorder', 'aZ09comma');
  46. $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
  47. if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
  48. // If $page is not defined, or '' or -1 or if we click on clear filters
  49. $page = 0;
  50. }
  51. $offset = $limit * $page;
  52. $pageprev = $page - 1;
  53. $pagenext = $page + 1;
  54. //if (! $sortfield) $sortfield="p.date_fin";
  55. //if (! $sortorder) $sortorder="DESC";
  56. // Initialize technical objects
  57. $object = new CashControl($db);
  58. $extrafields = new ExtraFields($db);
  59. //$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
  60. $hookmanager->initHooks(array('cashcontrol')); // 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 = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', '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 = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  112. $permissiontoadd = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  113. $permissiontodelete = (!empty($user->rights->cashdesk->run) || !empty($user->rights->takepos->run));
  114. // Security check
  115. if ($user->socid > 0) { // Protection if external user
  116. //$socid = $user->socid;
  117. accessforbidden();
  118. }
  119. if (!$user->hasRight('cashdesk', 'run') && !$user->hasRight('takepos', 'run')) {
  120. accessforbidden();
  121. }
  122. /*
  123. * Actions
  124. */
  125. if (GETPOST('cancel', 'alpha')) {
  126. $action = 'list';
  127. $massaction = '';
  128. }
  129. if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
  130. $massaction = '';
  131. }
  132. $parameters = array();
  133. $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
  134. if ($reshook < 0) {
  135. setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
  136. }
  137. if (empty($reshook)) {
  138. // Selection of new fields
  139. include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
  140. // Purge search criteria
  141. 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
  142. foreach ($object->fields as $key => $val) {
  143. $search[$key] = '';
  144. if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  145. $search[$key.'_dtstart'] = '';
  146. $search[$key.'_dtend'] = '';
  147. }
  148. }
  149. $toselect = array();
  150. $search_array_options = array();
  151. }
  152. if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
  153. || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
  154. $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
  155. }
  156. // Mass actions
  157. $objectclass = 'CashControl';
  158. $objectlabel = 'CashControl';
  159. $uploaddir = $conf->bank->dir_output;
  160. include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
  161. }
  162. /*
  163. * View
  164. */
  165. $form = new Form($db);
  166. $now = dol_now();
  167. //$help_url="EN:Module_pos_cash_fence|FR:Module_pos_cash_fence_FR|ES:Módulo_pos_cash_fence";
  168. $help_url = '';
  169. $title = $langs->trans('CashControl');
  170. $morejs = array();
  171. $morecss = array();
  172. // Build and execute select
  173. // --------------------------------------------------------------------
  174. $sql = 'SELECT ';
  175. $sql .= $object->getFieldList('t');
  176. // Add fields from extrafields
  177. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  178. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  179. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
  180. }
  181. }
  182. // Add fields from hooks
  183. $parameters = array();
  184. $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
  185. $sql .= $hookmanager->resPrint;
  186. $sql = preg_replace('/,\s*$/', '', $sql);
  187. $sqlfields = $sql; // $sql fields to remove for count total
  188. $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
  189. if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
  190. $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
  191. }
  192. // Add table from hooks
  193. $parameters = array();
  194. $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
  195. $sql .= $hookmanager->resPrint;
  196. if ($object->ismultientitymanaged == 1) {
  197. $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
  198. } else {
  199. $sql .= " WHERE 1 = 1";
  200. }
  201. foreach ($search as $key => $val) {
  202. if (array_key_exists($key, $object->fields)) {
  203. if ($key == 'status' && $search[$key] == -1) {
  204. continue;
  205. }
  206. $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
  207. if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
  208. if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
  209. $search[$key] = '';
  210. }
  211. $mode_search = 2;
  212. }
  213. if ($search[$key] != '') {
  214. $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
  215. }
  216. } else {
  217. if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
  218. $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
  219. if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
  220. if (preg_match('/_dtstart$/', $key)) {
  221. $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
  222. }
  223. if (preg_match('/_dtend$/', $key)) {
  224. $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
  225. }
  226. }
  227. }
  228. }
  229. }
  230. if ($search_all) {
  231. $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
  232. }
  233. //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
  234. // Add where from extra fields
  235. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
  236. // Add where from hooks
  237. $parameters = array();
  238. $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
  239. $sql .= $hookmanager->resPrint;
  240. /* If a group by is required
  241. $sql.= " GROUP BY ";
  242. foreach($object->fields as $key => $val) {
  243. $sql .= "t.".$db->escape($key).", ";
  244. }
  245. // Add fields from extrafields
  246. if (!empty($extrafields->attributes[$object->table_element]['label'])) {
  247. foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
  248. $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
  249. }
  250. }
  251. // Add where from hooks
  252. $parameters=array();
  253. $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
  254. $sql.=$hookmanager->resPrint;
  255. $sql=preg_replace('/,\s*$/','', $sql);
  256. */
  257. // Count total nb of records
  258. $nbtotalofrecords = '';
  259. if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
  260. /* The fast and low memory method to get and count full list converts the sql into a sql count */
  261. $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
  262. $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
  263. $resql = $db->query($sqlforcount);
  264. if ($resql) {
  265. $objforcount = $db->fetch_object($resql);
  266. $nbtotalofrecords = $objforcount->nbtotalofrecords;
  267. } else {
  268. dol_print_error($db);
  269. }
  270. if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
  271. $page = 0;
  272. $offset = 0;
  273. }
  274. $db->free($resql);
  275. }
  276. // Complete request and execute it with limit
  277. $sql .= $db->order($sortfield, $sortorder);
  278. if ($limit) {
  279. $sql .= $db->plimit($limit + 1, $offset);
  280. }
  281. $resql = $db->query($sql);
  282. if (!$resql) {
  283. dol_print_error($db);
  284. exit;
  285. }
  286. $num = $db->num_rows($resql);
  287. // Direct jump if only one record found
  288. if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
  289. $obj = $db->fetch_object($resql);
  290. $id = $obj->rowid;
  291. header("Location: ".DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$id);
  292. exit;
  293. }
  294. // Output page
  295. // --------------------------------------------------------------------
  296. llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
  297. $arrayofselected = is_array($toselect) ? $toselect : array();
  298. $param = '';
  299. if (!empty($mode)) {
  300. $param .= '&mode='.urlencode($mode);
  301. }
  302. if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
  303. $param .= '&contextpage='.urlencode($contextpage);
  304. }
  305. if ($limit > 0 && $limit != $conf->liste_limit) {
  306. $param .= '&limit='.((int) $limit);
  307. }
  308. foreach ($search as $key => $val) {
  309. if (is_array($search[$key])) {
  310. foreach ($search[$key] as $skey) {
  311. if ($skey != '') {
  312. $param .= '&search_'.$key.'[]='.urlencode($skey);
  313. }
  314. }
  315. } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
  316. $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
  317. $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
  318. $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
  319. } elseif ($search[$key] != '') {
  320. $param .= '&search_'.$key.'='.urlencode($search[$key]);
  321. }
  322. }
  323. if ($optioncss != '') {
  324. $param .= '&optioncss='.urlencode($optioncss);
  325. }
  326. // Add $param from extra fields
  327. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
  328. // Add $param from hooks
  329. $parameters = array();
  330. $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
  331. $param .= $hookmanager->resPrint;
  332. // List of mass actions available
  333. $arrayofmassactions = array();
  334. if (!empty($permissiontodelete)) {
  335. $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
  336. }
  337. $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
  338. print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
  339. if ($optioncss != '') {
  340. print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
  341. }
  342. print '<input type="hidden" name="token" value="'.newToken().'">';
  343. print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
  344. print '<input type="hidden" name="action" value="list">';
  345. print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
  346. print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
  347. print '<input type="hidden" name="page" value="'.$page.'">';
  348. print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
  349. print '<input type="hidden" name="mode" value="'.$mode.'">';
  350. $permforcashfence = 1;
  351. $newcardbutton = '';
  352. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewList'), '', 'fa fa-bars imgforviewmode', $_SERVER["PHP_SELF"].'?mode=common'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ((empty($mode) || $mode == 'common') ? 2 : 1), array('morecss'=>'reposition'));
  353. $newcardbutton .= dolGetButtonTitle($langs->trans('ViewKanban'), '', 'fa fa-th-list imgforviewmode', $_SERVER["PHP_SELF"].'?mode=kanban'.preg_replace('/(&|\?)*mode=[^&]+/', '', $param), '', ($mode == 'kanban' ? 2 : 1), array('morecss'=>'reposition'));
  354. $newcardbutton .= dolGetButtonTitleSeparator();
  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 BOOKCAL_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, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // 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. // Action column
  397. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  398. print '<td class="liste_titre maxwidthsearch">';
  399. $searchpicto = $form->showFilterButtons('left');
  400. print $searchpicto;
  401. print '</td>';
  402. }
  403. foreach ($object->fields as $key => $val) {
  404. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  405. if ($key == 'status') {
  406. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  407. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  408. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  409. } elseif (in_array($val['type'], array('timestamp'))) {
  410. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  411. } 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'])) {
  412. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  413. }
  414. if (!empty($arrayfields['t.'.$key]['checked'])) {
  415. print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
  416. if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
  417. 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);
  418. } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
  419. print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
  420. } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  421. print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
  422. } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
  423. print '<div class="nowrap">';
  424. print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
  425. print '</div>';
  426. print '<div class="nowrap">';
  427. print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
  428. print '</div>';
  429. }
  430. print '</td>';
  431. }
  432. }
  433. // Extra fields
  434. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
  435. // Fields from hook
  436. $parameters = array('arrayfields'=>$arrayfields);
  437. $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
  438. print $hookmanager->resPrint;
  439. // Action column
  440. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  441. print '<td class="liste_titre maxwidthsearch">';
  442. $searchpicto = $form->showFilterButtons();
  443. print $searchpicto;
  444. print '</td>';
  445. }
  446. print '</tr>'."\n";
  447. $totalarray = array();
  448. $totalarray['nbfield'] = 0;
  449. // Fields title label
  450. // --------------------------------------------------------------------
  451. print '<tr class="liste_titre">';
  452. // Action column
  453. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  454. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  455. $totalarray['nbfield']++;
  456. }
  457. foreach ($object->fields as $key => $val) {
  458. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  459. if ($key == 'status') {
  460. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  461. } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  462. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  463. } elseif (in_array($val['type'], array('timestamp'))) {
  464. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  465. } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
  466. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  467. }
  468. if (!empty($arrayfields['t.'.$key]['checked'])) {
  469. print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
  470. $totalarray['nbfield']++;
  471. }
  472. }
  473. // Extra fields
  474. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
  475. // Hook fields
  476. $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
  477. $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
  478. print $hookmanager->resPrint;
  479. // Action column
  480. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  481. print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
  482. $totalarray['nbfield']++;
  483. }
  484. print '</tr>'."\n";
  485. // Detect if we need a fetch on each output line
  486. $needToFetchEachLine = 0;
  487. if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
  488. foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
  489. if (!is_null($val) && preg_match('/\$object/', $val)) {
  490. $needToFetchEachLine++; // There is at least one compute field that use $object
  491. }
  492. }
  493. }
  494. // Loop on record
  495. // --------------------------------------------------------------------
  496. $i = 0;
  497. $savnbfield = $totalarray['nbfield'];
  498. $totalarray = array();
  499. $totalarray['nbfield'] = 0;
  500. while ($i < ($limit ? min($num, $limit) : $num)) {
  501. $obj = $db->fetch_object($resql);
  502. if (empty($obj)) {
  503. break; // Should not happen
  504. }
  505. // Store properties in $object
  506. $object->setVarsFromFetchObj($obj);
  507. // show kanban result
  508. if ($mode == 'kanban') {
  509. if ($i == 0) {
  510. print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
  511. print '<div class="box-flex-container kanban">';
  512. }
  513. $object->posmodule = $obj->posmodule;
  514. $object->cash = $obj->cash;
  515. $object->opening = $obj->opening;
  516. $object->year_close = $obj->year_close;
  517. $object->cheque = $obj->cheque;
  518. // Output Kanban
  519. $selected = -1;
  520. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  521. $selected = 0;
  522. if (in_array($object->id, $arrayofselected)) {
  523. $selected = 1;
  524. }
  525. }
  526. print $object->getKanbanView('', array('selected' => $selected));
  527. if ($i == (min($num, $limit) - 1)) {
  528. print '</div>';
  529. print '</td></tr>';
  530. }
  531. } else {
  532. // Show here line of result
  533. $j = 0;
  534. print '<tr data-rowid="'.$object->id.'" class="oddeven">';
  535. // Action column
  536. if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  537. print '<td class="nowrap center">';
  538. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  539. $selected = 0;
  540. if (in_array($object->id, $arrayofselected)) {
  541. $selected = 1;
  542. }
  543. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  544. }
  545. print '</td>';
  546. }
  547. foreach ($object->fields as $key => $val) {
  548. $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
  549. if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
  550. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  551. } elseif ($key == 'status') {
  552. $cssforfield .= ($cssforfield ? ' ' : '').'center';
  553. }
  554. if (in_array($val['type'], array('timestamp'))) {
  555. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  556. } elseif ($key == 'ref') {
  557. $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
  558. }
  559. if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
  560. $cssforfield .= ($cssforfield ? ' ' : '').'right';
  561. }
  562. //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
  563. if (!empty($arrayfields['t.'.$key]['checked'])) {
  564. print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
  565. if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
  566. print ' title="'.dol_escape_htmltag($object->$key).'"';
  567. }
  568. print '>';
  569. if ($key == 'status') {
  570. print $object->getLibStatut(5);
  571. } elseif ($key == 'rowid') {
  572. print $object->showOutputField($val, $key, $object->id, '');
  573. } else {
  574. print $object->showOutputField($val, $key, $object->$key, '');
  575. }
  576. print '</td>';
  577. if (!$i) {
  578. $totalarray['nbfield']++;
  579. }
  580. if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
  581. if (!$i) {
  582. $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
  583. }
  584. if (!isset($totalarray['val'])) {
  585. $totalarray['val'] = array();
  586. }
  587. if (!isset($totalarray['val']['t.'.$key])) {
  588. $totalarray['val']['t.'.$key] = 0;
  589. }
  590. $totalarray['val']['t.'.$key] += $object->$key;
  591. }
  592. }
  593. }
  594. // Extra fields
  595. include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
  596. // Fields from hook
  597. $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
  598. $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
  599. print $hookmanager->resPrint;
  600. // Action column
  601. if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
  602. print '<td class="nowrap center">';
  603. if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
  604. $selected = 0;
  605. if (in_array($object->id, $arrayofselected)) {
  606. $selected = 1;
  607. }
  608. print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
  609. }
  610. print '</td>';
  611. }
  612. if (!$i) {
  613. $totalarray['nbfield']++;
  614. }
  615. print '</tr>'."\n";
  616. }
  617. $i++;
  618. }
  619. // Show total line
  620. include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
  621. // If no record found
  622. if ($num == 0) {
  623. $colspan = 1;
  624. foreach ($arrayfields as $key => $val) {
  625. if (!empty($val['checked'])) {
  626. $colspan++;
  627. }
  628. }
  629. print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
  630. }
  631. $db->free($resql);
  632. $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
  633. $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
  634. print $hookmanager->resPrint;
  635. print '</table>'."\n";
  636. print '</div>'."\n";
  637. print '</form>'."\n";
  638. /*
  639. if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
  640. $hidegeneratedfilelistifempty = 1;
  641. if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
  642. $hidegeneratedfilelistifempty = 0;
  643. }
  644. require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
  645. $formfile = new FormFile($db);
  646. // Show list of available documents
  647. $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
  648. $urlsource .= str_replace('&amp;', '&', $param);
  649. $filedir = $diroutputmassaction;
  650. $genallowed = $permissiontoread;
  651. $delallowed = $permissiontoadd;
  652. print $formfile->showdocuments('massfilesarea_monmodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
  653. }
  654. */
  655. // End of page
  656. llxFooter();
  657. $db->close();