cashcontrol_list.php 27 KB

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