dolibarr  20.0.0-beta
cashcontrol_list.php
Go to the documentation of this file.
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 
25 // Load Dolibarr environment
26 require '../../main.inc.php';
27 require_once DOL_DOCUMENT_ROOT.'/compta/cashcontrol/class/cashcontrol.class.php';
28 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29 require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30 require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31 
32 // Load translation files required by the page
33 $langs->loadLangs(array("banks", "other"));
34 
35 $action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
36 $massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
37 $show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
38 $confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
39 $cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
40 $toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
41 $contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'cashcontrol'; // To manage different context of search
42 $backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
43 $optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
44 $mode = GETPOST('mode', 'alpha'); // for mode view result
45 $id = GETPOSTINT('id');
46 
47 // Load variable for pagination
48 $limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
49 $sortfield = GETPOST('sortfield', 'aZ09comma');
50 $sortorder = GETPOST('sortorder', 'aZ09comma');
51 $page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT("page");
52 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
53  // If $page is not defined, or '' or -1 or if we click on clear filters
54  $page = 0;
55 }
56 $offset = $limit * $page;
57 $pageprev = $page - 1;
58 $pagenext = $page + 1;
59 //if (! $sortfield) $sortfield="p.date_fin";
60 //if (! $sortorder) $sortorder="DESC";
61 
62 // Initialize technical objects
63 $object = new CashControl($db);
64 $extrafields = new ExtraFields($db);
65 //$diroutputmassaction = $conf->mymodule->dir_output.'/temp/massgeneration/'.$user->id;
66 $hookmanager->initHooks(array('cashcontrol')); // Note that conf->hooks_modules contains array
67 
68 // Fetch optionals attributes and labels
69 $extrafields->fetch_name_optionals_label($object->table_element);
70 //$extrafields->fetch_name_optionals_label($object->table_element_line);
71 
72 $search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
73 
74 // Default sort order (if not yet defined by previous GETPOST)
75 if (!$sortfield) {
76  reset($object->fields); // Reset is required to avoid key() to return null.
77  $sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
78 }
79 if (!$sortorder) {
80  $sortorder = "ASC";
81 }
82 
83 // Initialize array of search criteria
84 $search_all = GETPOST('search_all', 'alphanohtml') ? GETPOST('search_all', 'alphanohtml') : GETPOST('sall', 'alphanohtml');
85 $search = array();
86 foreach ($object->fields as $key => $val) {
87  if (GETPOST('search_'.$key, 'alpha') !== '') {
88  $search[$key] = GETPOST('search_'.$key, 'alpha');
89  }
90  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
91  $search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOSTINT('search_'.$key.'_dtstartmonth'), GETPOSTINT('search_'.$key.'_dtstartday'), GETPOSTINT('search_'.$key.'_dtstartyear'));
92  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOSTINT('search_'.$key.'_dtendmonth'), GETPOSTINT('search_'.$key.'_dtendday'), GETPOSTINT('search_'.$key.'_dtendyear'));
93  }
94 }
95 
96 // List of fields to search into when doing a "search in all"
97 $fieldstosearchall = array();
98 foreach ($object->fields as $key => $val) {
99  if (!empty($val['searchall'])) {
100  $fieldstosearchall['t.'.$key] = $val['label'];
101  }
102 }
103 
104 // Definition of array of fields for columns
105 $arrayfields = array();
106 foreach ($object->fields as $key => $val) {
107  // If $val['visible']==0, then we never show the field
108  if (!empty($val['visible'])) {
109  $visible = (int) dol_eval($val['visible'], 1);
110  $arrayfields['t.'.$key] = array(
111  'label'=>$val['label'],
112  'checked'=>(($visible < 0) ? 0 : 1),
113  'enabled'=>(abs($visible) != 3 && (int) dol_eval($val['enabled'], 1)),
114  'position'=>$val['position'],
115  'help'=> isset($val['help']) ? $val['help'] : ''
116  );
117  }
118 }
119 // Extra fields
120 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
121 
122 $object->fields = dol_sort_array($object->fields, 'position');
123 $arrayfields = dol_sort_array($arrayfields, 'position');
124 
125 $permissiontoread = ($user->hasRight('cashdesk', 'run') || $user->hasRight('takepos', 'run'));
126 $permissiontoadd = ($user->hasRight('cashdesk', 'run') || $user->hasRight('takepos', 'run'));
127 $permissiontodelete = ($user->hasRight('cashdesk', 'run') || $user->hasRight('takepos', 'run'));
128 
129 // Security check
130 if ($user->socid > 0) { // Protection if external user
131  //$socid = $user->socid;
132  accessforbidden();
133 }
134 if (!$user->hasRight('cashdesk', 'run') && !$user->hasRight('takepos', 'run')) {
135  accessforbidden();
136 }
137 
138 
139 /*
140  * Actions
141  */
142 
143 if (GETPOST('cancel', 'alpha')) {
144  $action = 'list';
145  $massaction = '';
146 }
147 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
148  $massaction = '';
149 }
150 
151 $parameters = array();
152 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
153 if ($reshook < 0) {
154  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
155 }
156 
157 if (empty($reshook)) {
158  // Selection of new fields
159  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
160 
161  // Purge search criteria
162  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
163  foreach ($object->fields as $key => $val) {
164  $search[$key] = '';
165  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
166  $search[$key.'_dtstart'] = '';
167  $search[$key.'_dtend'] = '';
168  }
169  }
170  $toselect = array();
171  $search_array_options = array();
172  }
173  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
174  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
175  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
176  }
177 
178  // Mass actions
179  $objectclass = 'CashControl';
180  $objectlabel = 'CashControl';
181  $uploaddir = $conf->bank->dir_output;
182  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
183 }
184 
185 
186 
187 /*
188  * View
189  */
190 
191 $form = new Form($db);
192 
193 $now = dol_now();
194 
195 //$help_url="EN:Module_pos_cash_fence|FR:Module_pos_cash_fence_FR|ES:Módulo_pos_cash_fence";
196 $help_url = '';
197 $title = $langs->trans('CashControl');
198 $morejs = array();
199 $morecss = array();
200 
201 // Build and execute select
202 // --------------------------------------------------------------------
203 $sql = 'SELECT ';
204 $sql .= $object->getFieldList('t');
205 // Add fields from extrafields
206 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
207  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
208  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
209  }
210 }
211 // Add fields from hooks
212 $parameters = array();
213 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
214 $sql .= $hookmanager->resPrint;
215 $sql = preg_replace('/,\s*$/', '', $sql);
216 
217 $sqlfields = $sql; // $sql fields to remove for count total
218 
219 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
220 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
221  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
222 }
223 // Add table from hooks
224 $parameters = array();
225 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
226 $sql .= $hookmanager->resPrint;
227 if ($object->ismultientitymanaged == 1) {
228  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
229 } else {
230  $sql .= " WHERE 1 = 1";
231 }
232 foreach ($search as $key => $val) {
233  if (array_key_exists($key, $object->fields)) {
234  if ($key == 'status' && $search[$key] == -1) {
235  continue;
236  }
237  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
238  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
239  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
240  $search[$key] = '';
241  }
242  $mode_search = 2;
243  }
244  if ($search[$key] != '') {
245  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
246  }
247  } else {
248  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
249  $columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
250  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
251  if (preg_match('/_dtstart$/', $key)) {
252  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
253  }
254  if (preg_match('/_dtend$/', $key)) {
255  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
256  }
257  }
258  }
259  }
260 }
261 if ($search_all) {
262  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
263 }
264 //$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
265 // Add where from extra fields
266 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
267 // Add where from hooks
268 $parameters = array();
269 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
270 $sql .= $hookmanager->resPrint;
271 
272 /* If a group by is required
273 $sql.= " GROUP BY ";
274 foreach($object->fields as $key => $val) {
275  $sql .= "t.".$db->escape($key).", ";
276 }
277 // Add fields from extrafields
278 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
279  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
280  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
281  }
282 }
283 // Add where from hooks
284 $parameters=array();
285 $reshook=$hookmanager->executeHooks('printFieldListGroupBy',$parameters, $object); // Note that $action and $object may have been modified by hook
286 $sql.=$hookmanager->resPrint;
287 $sql=preg_replace('/,\s*$/','', $sql);
288 */
289 
290 
291 // Count total nb of records
292 $nbtotalofrecords = '';
293 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
294  /* The fast and low memory method to get and count full list converts the sql into a sql count */
295  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
296  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
297  $resql = $db->query($sqlforcount);
298  if ($resql) {
299  $objforcount = $db->fetch_object($resql);
300  $nbtotalofrecords = $objforcount->nbtotalofrecords;
301  } else {
302  dol_print_error($db);
303  }
304 
305  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
306  $page = 0;
307  $offset = 0;
308  }
309  $db->free($resql);
310 }
311 
312 // Complete request and execute it with limit
313 $sql .= $db->order($sortfield, $sortorder);
314 if ($limit) {
315  $sql .= $db->plimit($limit + 1, $offset);
316 }
317 
318 $resql = $db->query($sql);
319 if (!$resql) {
320  dol_print_error($db);
321  exit;
322 }
323 
324 $num = $db->num_rows($resql);
325 
326 
327 // Direct jump if only one record found
328 if ($num == 1 && getDolGlobalString('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
329  $obj = $db->fetch_object($resql);
330  $id = $obj->rowid;
331  header("Location: ".DOL_URL_ROOT.'/compta/cashcontrol/cashcontrol_card.php?id='.$id);
332  exit;
333 }
334 
335 
336 // Output page
337 // --------------------------------------------------------------------
338 
339 llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'classforhorizontalscrolloftabs');
340 
341 $arrayofselected = is_array($toselect) ? $toselect : array();
342 
343 $param = '';
344 if (!empty($mode)) {
345  $param .= '&mode='.urlencode($mode);
346 }
347 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
348  $param .= '&contextpage='.urlencode($contextpage);
349 }
350 if ($limit > 0 && $limit != $conf->liste_limit) {
351  $param .= '&limit='.((int) $limit);
352 }
353 foreach ($search as $key => $val) {
354  if (is_array($search[$key])) {
355  foreach ($search[$key] as $skey) {
356  if ($skey != '') {
357  $param .= '&search_'.$key.'[]='.urlencode($skey);
358  }
359  }
360  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
361  $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
362  $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
363  $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
364  } elseif ($search[$key] != '') {
365  $param .= '&search_'.$key.'='.urlencode($search[$key]);
366  }
367 }
368 if ($optioncss != '') {
369  $param .= '&optioncss='.urlencode($optioncss);
370 }
371 // Add $param from extra fields
372 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
373 // Add $param from hooks
374 $parameters = array('param' => &$param);
375 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
376 $param .= $hookmanager->resPrint;
377 
378 // List of mass actions available
379 $arrayofmassactions = array();
380 if (!empty($permissiontodelete)) {
381  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
382 }
383 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
384 
385 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
386 if ($optioncss != '') {
387  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
388 }
389 print '<input type="hidden" name="token" value="'.newToken().'">';
390 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
391 print '<input type="hidden" name="action" value="list">';
392 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
393 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
394 print '<input type="hidden" name="page" value="'.$page.'">';
395 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
396 print '<input type="hidden" name="mode" value="'.$mode.'">';
397 
398 $permforcashfence = 1;
399 
400 $newcardbutton = '';
401 $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'));
402 $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'));
403 $newcardbutton .= dolGetButtonTitleSeparator();
404 $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);
405 
406 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'cash-register', 0, $newcardbutton, '', $limit, 0, 0, 1);
407 
408 // Add code for pre mass action (confirmation or email presend form)
409 $topicmail = "SendCashControlRef";
410 $modelmail = "cashcontrol";
411 $objecttmp = new CashControl($db);
412 $trackid = 'cashfence'.$object->id;
413 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
414 
415 if ($search_all) {
416  $setupstring = '';
417  foreach ($fieldstosearchall as $key => $val) {
418  $fieldstosearchall[$key] = $langs->trans($val);
419  $setupstring .= $key."=".$val.";";
420  }
421  print '<!-- Search done like if BOOKCAL_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
422  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
423 }
424 
425 $moreforfilter = '';
426 /*$moreforfilter.='<div class="divsearchfield">';
427  $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
428  $moreforfilter.= '</div>';*/
429 
430 $parameters = array();
431 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
432 if (empty($reshook)) {
433  $moreforfilter .= $hookmanager->resPrint;
434 } else {
435  $moreforfilter = $hookmanager->resPrint;
436 }
437 
438 if (!empty($moreforfilter)) {
439  print '<div class="liste_titre liste_titre_bydiv centpercent">';
440  print $moreforfilter;
441  print '</div>';
442 }
443 
444 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
445 $selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields
446 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
447 
448 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
449 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
450 
451 
452 // Fields title search
453 // --------------------------------------------------------------------
454 print '<tr class="liste_titre">';
455 // Action column
456 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
457  print '<td class="liste_titre maxwidthsearch">';
458  $searchpicto = $form->showFilterButtons('left');
459  print $searchpicto;
460  print '</td>';
461 }
462 foreach ($object->fields as $key => $val) {
463  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
464  if ($key == 'status') {
465  $cssforfield .= ($cssforfield ? ' ' : '').'center';
466  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
467  $cssforfield .= ($cssforfield ? ' ' : '').'center';
468  } elseif (in_array($val['type'], array('timestamp'))) {
469  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
470  } 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'])) {
471  $cssforfield .= ($cssforfield ? ' ' : '').'right';
472  }
473  if (!empty($arrayfields['t.'.$key]['checked'])) {
474  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
475  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
476  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);
477  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:')=== 0)) {
478  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
479  } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
480  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
481  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
482  print '<div class="nowrap">';
483  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
484  print '</div>';
485  print '<div class="nowrap">';
486  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
487  print '</div>';
488  }
489  print '</td>';
490  }
491 }
492 // Extra fields
493 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
494 
495 // Fields from hook
496 $parameters = array('arrayfields'=>$arrayfields);
497 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
498 print $hookmanager->resPrint;
499 // Action column
500 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
501  print '<td class="liste_titre maxwidthsearch">';
502  $searchpicto = $form->showFilterButtons();
503  print $searchpicto;
504  print '</td>';
505 }
506 print '</tr>'."\n";
507 
508 
509 $totalarray = array();
510 $totalarray['nbfield'] = 0;
511 
512 // Fields title label
513 // --------------------------------------------------------------------
514 print '<tr class="liste_titre">';
515 // Action column
516 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
517  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
518  $totalarray['nbfield']++;
519 }
520 foreach ($object->fields as $key => $val) {
521  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
522  if ($key == 'status') {
523  $cssforfield .= ($cssforfield ? ' ' : '').'center';
524  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
525  $cssforfield .= ($cssforfield ? ' ' : '').'center';
526  } elseif (in_array($val['type'], array('timestamp'))) {
527  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
528  } elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
529  $cssforfield .= ($cssforfield ? ' ' : '').'right';
530  }
531  if (!empty($arrayfields['t.'.$key]['checked'])) {
532  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
533  $totalarray['nbfield']++;
534  }
535 }
536 // Extra fields
537 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
538 // Hook fields
539 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
540 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
541 print $hookmanager->resPrint;
542 // Action column
543 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
544  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
545  $totalarray['nbfield']++;
546 }
547 print '</tr>'."\n";
548 
549 
550 // Detect if we need a fetch on each output line
551 $needToFetchEachLine = 0;
552 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
553  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
554  if (!is_null($val) && preg_match('/\$object/', $val)) {
555  $needToFetchEachLine++; // There is at least one compute field that use $object
556  }
557  }
558 }
559 
560 
561 // Loop on record
562 // --------------------------------------------------------------------
563 $i = 0;
564 $savnbfield = $totalarray['nbfield'];
565 $totalarray = array();
566 $totalarray['nbfield'] = 0;
567 while ($i < ($limit ? min($num, $limit) : $num)) {
568  $obj = $db->fetch_object($resql);
569  if (empty($obj)) {
570  break; // Should not happen
571  }
572 
573  // Store properties in $object
574  $object->setVarsFromFetchObj($obj);
575 
576  // show kanban result
577  if ($mode == 'kanban') {
578  if ($i == 0) {
579  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
580  print '<div class="box-flex-container kanban">';
581  }
582 
583  $object->posmodule = $obj->posmodule;
584  $object->cash = $obj->cash;
585  $object->opening = $obj->opening;
586  $object->year_close = $obj->year_close;
587  $object->cheque = $obj->cheque;
588 
589  // Output Kanban
590  $selected = -1;
591  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
592  $selected = 0;
593  if (in_array($object->id, $arrayofselected)) {
594  $selected = 1;
595  }
596  }
597  print $object->getKanbanView('', array('selected' => $selected));
598  if ($i == (min($num, $limit) - 1)) {
599  print '</div>';
600  print '</td></tr>';
601  }
602  } else {
603  // Show here line of result
604  $j = 0;
605  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
606 
607  // Action column
608  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
609  print '<td class="nowrap center">';
610  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
611  $selected = 0;
612  if (in_array($object->id, $arrayofselected)) {
613  $selected = 1;
614  }
615  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
616  }
617  print '</td>';
618  }
619 
620  foreach ($object->fields as $key => $val) {
621  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
622  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
623  $cssforfield .= ($cssforfield ? ' ' : '').'center';
624  } elseif ($key == 'status') {
625  $cssforfield .= ($cssforfield ? ' ' : '').'center';
626  }
627 
628  if (in_array($val['type'], array('timestamp'))) {
629  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
630  } elseif ($key == 'ref') {
631  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
632  }
633 
634  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
635  $cssforfield .= ($cssforfield ? ' ' : '').'right';
636  }
637  //if (in_array($key, array('fk_soc', 'fk_user', 'fk_warehouse'))) $cssforfield = 'tdoverflowmax100';
638 
639  if (!empty($arrayfields['t.'.$key]['checked'])) {
640  print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
641  if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
642  print ' title="'.dol_escape_htmltag($object->$key).'"';
643  }
644  print '>';
645  if ($key == 'status') {
646  print $object->getLibStatut(5);
647  } elseif ($key == 'rowid') {
648  print $object->showOutputField($val, $key, $object->id, '');
649  } else {
650  print $object->showOutputField($val, $key, $object->$key, '');
651  }
652  print '</td>';
653  if (!$i) {
654  $totalarray['nbfield']++;
655  }
656  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
657  if (!$i) {
658  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
659  }
660  if (!isset($totalarray['val'])) {
661  $totalarray['val'] = array();
662  }
663  if (!isset($totalarray['val']['t.'.$key])) {
664  $totalarray['val']['t.'.$key] = 0;
665  }
666  $totalarray['val']['t.'.$key] += $object->$key;
667  }
668  }
669  }
670  // Extra fields
671  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
672  // Fields from hook
673  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
674  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
675  print $hookmanager->resPrint;
676  // Action column
677  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
678  print '<td class="nowrap center">';
679  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
680  $selected = 0;
681  if (in_array($object->id, $arrayofselected)) {
682  $selected = 1;
683  }
684  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
685  }
686  print '</td>';
687  }
688  if (!$i) {
689  $totalarray['nbfield']++;
690  }
691 
692  print '</tr>'."\n";
693  }
694  $i++;
695 }
696 
697 // Show total line
698 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
699 
700 
701 // If no record found
702 if ($num == 0) {
703  $colspan = 1;
704  foreach ($arrayfields as $key => $val) {
705  if (!empty($val['checked'])) {
706  $colspan++;
707  }
708  }
709  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
710 }
711 
712 $db->free($resql);
713 
714 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
715 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
716 print $hookmanager->resPrint;
717 
718 print '</table>'."\n";
719 print '</div>'."\n";
720 
721 print '</form>'."\n";
722 
723 /*
724 if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
725  $hidegeneratedfilelistifempty = 1;
726  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
727  $hidegeneratedfilelistifempty = 0;
728  }
729 
730  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
731  $formfile = new FormFile($db);
732 
733  // Show list of available documents
734  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
735  $urlsource .= str_replace('&amp;', '&', $param);
736 
737  $filedir = $diroutputmassaction;
738  $genallowed = $permissiontoread;
739  $delallowed = $permissiontoadd;
740 
741  print $formfile->showdocuments('massfilesarea_monmodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
742 }
743 */
744 
745 // End of page
746 llxFooter();
747 $db->close();
if($user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition: card.php:58
if(!defined('NOREQUIRESOC')) if(!defined('NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined('NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined('NOREQUIREAJAX')) llxHeader()
Empty header.
Definition: wrapper.php:55
llxFooter()
Empty footer.
Definition: wrapper.php:69
Class to manage cash fence.
Class to manage standard extra fields.
Class to manage generation of HTML components Only common components must be here.
if(isModEnabled('invoice') && $user->hasRight('facture', 'lire')) if((isModEnabled('fournisseur') &&!getDolGlobalString('MAIN_USE_NEW_SUPPLIERMOD') && $user->hasRight("fournisseur", "facture", "lire"))||(isModEnabled('supplier_invoice') && $user->hasRight("supplier_invoice", "lire"))) if(isModEnabled('don') && $user->hasRight('don', 'lire')) if(isModEnabled('tax') && $user->hasRight('tax', 'charges', 'lire')) if(isModEnabled('invoice') &&isModEnabled('order') && $user->hasRight("commande", "lire") &&!getDolGlobalString('WORKFLOW_DISABLE_CREATE_INVOICE_FROM_ORDER')) $sql
Social contributions to pay.
Definition: index.php:745
dol_mktime($hour, $minute, $second, $month, $day, $year, $gm='auto', $check=1)
Return a timestamp date built from detailed information (by default a local PHP server timestamp) Rep...
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
dolGetButtonTitle($label, $helpText='', $iconClass='fa fa-file', $url='', $id='', $status=1, $params=array())
Function dolGetButtonTitle : this kind of buttons are used in title in list.
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0)
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
dol_sort_array(&$array, $index, $order='asc', $natsort=0, $case_sensitive=0, $keepindex=0)
Advanced sort array by the value of a given key, which produces ascending (default) or descending out...
getTitleFieldOfList($name, $thead=0, $file="", $field="", $begin="", $moreparam="", $moreattrib="", $sortfield="", $sortorder="", $prefix="", $disablesortlink=0, $tooltip='', $forcenowrapcolumntitle=0)
Get title line of an array.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $hideselectlimit=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_print_error($db=null, $error='', $errors=null)
Displays error message system with all the information to facilitate the diagnosis and the escalation...
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Returns text escaped for inclusion in HTML alt or title or value tags, or into values of HTML input f...
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.