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