dolibarr  19.0.0-dev
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') : str_replace('_', '', basename(dirname(__FILE__)).basename(__FILE__, '.php')); // 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 $mode = GETPOST('mode', 'aZ'); // The output mode ('list', 'kanban', 'hierarchy', 'calendar', ...)
47 
48 $id = GETPOST('id', 'int');
49 
50 // Load variable for pagination
51 $limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
52 $sortfield = GETPOST('sortfield', 'aZ09comma');
53 $sortorder = GETPOST('sortorder', 'aZ09comma');
54 $page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
55 if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
56  // If $page is not defined, or '' or -1 or if we click on clear filters
57  $page = 0;
58 }
59 $offset = $limit * $page;
60 $pageprev = $page - 1;
61 $pagenext = $page + 1;
62 
63 // Initialize technical objects
64 $object = new Inventory($db);
65 $extrafields = new ExtraFields($db);
66 // no inventory docs yet
67 // $diroutputmassaction = $conf->inventory->dir_output.'/temp/massgeneration/'.$user->id;
68 $diroutputmassaction = null;
69 $hookmanager->initHooks(array('inventorylist')); // Note that conf->hooks_modules contains array
70 // Fetch optionals attributes and labels
71 $extrafields->fetch_name_optionals_label($object->table_element);
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 criterias
84 $search_all = GETPOST('search_all', '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, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
92  $search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
93  }
94 }
95 $searchCategoryProductOperator = 0;
96 if (GETPOSTISSET('formfilteraction')) {
97  $searchCategoryProductOperator = GETPOST('search_category_product_operator', 'int');
98 } elseif (!empty($conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT)) {
99  $searchCategoryProductOperator = $conf->global->MAIN_SEARCH_CAT_OR_BY_DEFAULT;
100 }
101 $searchCategoryProductList = GETPOST('search_category_product_list', 'array');
102 
103 // List of fields to search into when doing a "search in all"
104 $fieldstosearchall = array();
105 foreach ($object->fields as $key => $val) {
106  if (!empty($val['searchall'])) {
107  $fieldstosearchall['t.'.$key] = $val['label'];
108  }
109 }
110 
111 // Definition of array of fields for columns
112 $arrayfields = array();
113 foreach ($object->fields as $key => $val) {
114  // If $val['visible']==0, then we never show the field
115  if (!empty($val['visible'])) {
116  $visible = (int) dol_eval($val['visible'], 1);
117  $arrayfields['t.'.$key] = array(
118  'label'=>$val['label'],
119  'checked'=>(($visible < 0) ? 0 : 1),
120  'enabled'=>(abs($visible) != 3 && dol_eval($val['enabled'], 1)),
121  'position'=>$val['position'],
122  'help'=> isset($val['help']) ? $val['help'] : ''
123  );
124  }
125 }
126 // Extra fields
127 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
128 
129 $object->fields = dol_sort_array($object->fields, 'position');
130 $arrayfields = dol_sort_array($arrayfields, 'position');
131 
132 $permissiontoread = $user->rights->stock->lire;
133 $permissiontoadd = $user->rights->stock->creer;
134 $permissiontodelete = $user->rights->stock->supprimer;
135 
136 // Security check
137 $socid = 0;
138 if ($user->socid > 0) { // Protection if external user
139  //$socid = $user->socid;
140  accessforbidden();
141 }
142 if (empty($conf->global->MAIN_USE_ADVANCED_PERMS)) {
143  $result = restrictedArea($user, 'stock');
144 } else {
145  $result = restrictedArea($user, 'stock', 0, '', 'inventory_advance');
146 }
147 
148 
149 /*
150  * Actions
151  */
152 
153 if (GETPOST('cancel', 'alpha')) {
154  $action = 'list';
155  $massaction = '';
156 }
157 if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
158  $massaction = '';
159 }
160 
161 $parameters = array();
162 $reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
163 if ($reshook < 0) {
164  setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
165 }
166 
167 if (empty($reshook)) {
168  // Selection of new fields
169  include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
170 
171  // Purge search criteria
172  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
173  foreach ($object->fields as $key => $val) {
174  $search[$key] = '';
175  if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
176  $search[$key.'_dtstart'] = '';
177  $search[$key.'_dtend'] = '';
178  }
179  }
180  $searchCategoryProductList = array();
181  $toselect = array();
182  $search_array_options = array();
183  }
184  if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
185  || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
186  $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
187  }
188 
189  // Mass actions
190  $objectclass = 'Inventory';
191  $objectlabel = 'Inventory';
192  $uploaddir = $conf->stock->dir_output;
193  include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
194 }
195 
196 
197 
198 /*
199  * View
200  */
201 
202 $form = new Form($db);
203 
204 $now = dol_now();
205 
206 $title = $langs->trans('Inventories');
207 //$help_url="EN:Module_Inventory|FR:Module_Inventory_FR|ES:Módulo_Inventory";
208 $help_url = '';
209 $morejs = array();
210 $morecss = array();
211 
212 
213 // Build and execute select
214 // --------------------------------------------------------------------
215 $sql = 'SELECT ';
216 $sql .= $object->getFieldList('t');
217 // Add fields from extrafields
218 if (!empty($extrafields->attributes[$object->table_element]['label'])) {
219  foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
220  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
221  }
222 }
223 // Add fields from hooks
224 $parameters = array();
225 $reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
226 $sql .= $hookmanager->resPrint;
227 $sql = preg_replace('/,\s*$/', '', $sql);
228 
229 $sqlfields = $sql; // $sql fields to remove for count total
230 
231 $sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
232 if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
233  $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
234 }
235 // Add table from hooks
236 $parameters = array();
237 $reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
238 $sql .= $hookmanager->resPrint;
239 if ($object->ismultientitymanaged == 1) {
240  $sql .= " WHERE t.entity IN (".getEntity($object->element).")";
241 } else {
242  $sql .= " WHERE 1 = 1";
243 }
244 foreach ($search as $key => $val) {
245  if (array_key_exists($key, $object->fields)) {
246  if ($key == 'status' && $search[$key] == -1) {
247  continue;
248  }
249  $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
250  if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
251  if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
252  $search[$key] = '';
253  }
254  $mode_search = 2;
255  }
256  if ($search[$key] != '') {
257  $sql .= natural_search("t.".$db->escape($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
258  }
259  } else {
260  if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
261  $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
262  if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
263  if (preg_match('/_dtstart$/', $key)) {
264  $sql .= " AND t.".$db->escape($columnName)." >= '".$db->idate($search[$key])."'";
265  }
266  if (preg_match('/_dtend$/', $key)) {
267  $sql .= " AND t.".$db->escape($columnName)." <= '".$db->idate($search[$key])."'";
268  }
269  }
270  }
271  }
272 }
273 
274 if ($search_all) {
275  $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
276 }
277 // Search for tag/category ($searchCategoryProductList is an array of ID)
278 if (!empty($searchCategoryProductList)) {
279  $searchCategoryProductSqlList = array();
280  $listofcategoryid = '';
281  foreach ($searchCategoryProductList as $searchCategoryProduct) {
282  if (intval($searchCategoryProduct) == -2) {
283  $searchCategoryProductSqlList[] = "NOT EXISTS (SELECT ck.fk_product FROM ".MAIN_DB_PREFIX."categorie_product as ck WHERE p.rowid = ck.fk_product)";
284  } elseif (intval($searchCategoryProduct) > 0) {
285  if ($searchCategoryProductOperator == 0) {
286  $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).")";
287  } else {
288  $listofcategoryid .= ($listofcategoryid ? ', ' : '') .((int) $searchCategoryProduct);
289  }
290  }
291  }
292  if ($listofcategoryid) {
293  $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)."))";
294  }
295  if ($searchCategoryProductOperator == 1) {
296  if (!empty($searchCategoryProductSqlList)) {
297  $sql .= " AND (".implode(' OR ', $searchCategoryProductSqlList).")";
298  }
299  } else {
300  if (!empty($searchCategoryProductSqlList)) {
301  $sql .= " AND (".implode(' AND ', $searchCategoryProductSqlList).")";
302  }
303  }
304 }
305 // Add where from extra fields
306 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
307 // Add where from hooks
308 $parameters = array();
309 $reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
310 $sql .= $hookmanager->resPrint;
311 
312 /* If a group by is required
313 $sql.= " GROUP BY ";
314 foreach($object->fields as $key => $val) {
315  $sql .= "t.".$db->escape($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) {
320  $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
321  }
322 }
323 // Add where from hooks
324 $parameters=array();
325 $reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
326 $sql.=$hookmanager->resPrint;
327 $sql=preg_replace('/,\s*$/','', $sql);
328 */
329 
330 // Count total nb of records
331 $nbtotalofrecords = '';
332 if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
333  /* The fast and low memory method to get and count full list converts the sql into a sql count */
334  $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
335  $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
336  $resql = $db->query($sqlforcount);
337  if ($resql) {
338  $objforcount = $db->fetch_object($resql);
339  $nbtotalofrecords = $objforcount->nbtotalofrecords;
340  } else {
341  dol_print_error($db);
342  }
343 
344  if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller then paging size (filtering), goto and load page 0
345  $page = 0;
346  $offset = 0;
347  }
348  $db->free($resql);
349 }
350 
351 // Complete request and execute it with limit
352 $sql .= $db->order($sortfield, $sortorder);
353 if ($limit) {
354  $sql .= $db->plimit($limit + 1, $offset);
355 }
356 
357 $resql = $db->query($sql);
358 if (!$resql) {
359  dol_print_error($db);
360  exit;
361 }
362 
363 $num = $db->num_rows($resql);
364 
365 // Direct jump if only one record found
366 if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
367  $obj = $db->fetch_object($resql);
368  $id = $obj->rowid;
369  header("Location: ".DOL_URL_ROOT.'/inventory/card.php?id='.$id);
370  exit;
371 }
372 
373 
374 // Output page
375 // --------------------------------------------------------------------
376 
377 llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'bodyforlist'); // Can use also classforhorizontalscrolloftabs instead of bodyforlist for no horizontal scroll
378 
379 $arrayofselected = is_array($toselect) ? $toselect : array();
380 
381 $param = '';
382 if (!empty($mode)) {
383  $param .= '&mode='.urlencode($mode);
384 }
385 if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
386  $param .= '&contextpage='.urlencode($contextpage);
387 }
388 if ($limit > 0 && $limit != $conf->liste_limit) {
389  $param .= '&limit='.((int) $limit);
390 }
391 foreach ($search as $key => $val) {
392  if (is_array($search[$key])) {
393  foreach ($search[$key] as $skey) {
394  if ($skey != '') {
395  $param .= '&search_'.$key.'[]='.urlencode($skey);
396  }
397  }
398  } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
399  $param .= '&search_'.$key.'month='.((int) GETPOST('search_'.$key.'month', 'int'));
400  $param .= '&search_'.$key.'day='.((int) GETPOST('search_'.$key.'day', 'int'));
401  $param .= '&search_'.$key.'year='.((int) GETPOST('search_'.$key.'year', 'int'));
402  } elseif ($search[$key] != '') {
403  $param .= '&search_'.$key.'='.urlencode($search[$key]);
404  }
405 }
406 if ($optioncss != '') {
407  $param .= '&optioncss='.urlencode($optioncss);
408 }
409 foreach ($searchCategoryProductList as $searchCategoryProduct) {
410  $param .= "&search_category_product_list[]=".urlencode($searchCategoryProduct);
411 }
412 // Add $param from extra fields
413 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
414 // Add $param from hooks
415 $parameters = array();
416 $reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
417 $param .= $hookmanager->resPrint;
418 
419 // List of mass actions available
420 $arrayofmassactions = array(
421  //'validate'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Validate"),
422  //'generate_doc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("ReGeneratePDF"),
423  //'builddoc'=>img_picto('', 'pdf', 'class="pictofixedwidth"').$langs->trans("PDFMerge"),
424  //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
425 );
426 if (!empty($permissiontodelete)) {
427  $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
428 }
429 if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
430  $arrayofmassactions = array();
431 }
432 $massactionbutton = $form->selectMassAction('', $arrayofmassactions);
433 
434 print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
435 if ($optioncss != '') {
436  print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
437 }
438 print '<input type="hidden" name="token" value="'.newToken().'">';
439 print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
440 print '<input type="hidden" name="action" value="list">';
441 print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
442 print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
443 print '<input type="hidden" name="page" value="'.$page.'">';
444 print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
445 print '<input type="hidden" name="page_y" value="">';
446 print '<input type="hidden" name="mode" value="'.$mode.'">';
447 
448 $newcardbutton = '';
449 $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'));
450 $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'));
451 $newcardbutton .= dolGetButtonTitleSeparator();
452 $newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/product/inventory/card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $permissiontoadd);
453 
454 print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, $object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
455 
456 // Add code for pre mass action (confirmation or email presend form)
457 $topicmail = "Information";
458 $modelmail = "inventory";
459 $objecttmp = new Inventory($db);
460 $trackid = 'stockinv'.$object->id;
461 include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
462 
463 if ($search_all) {
464  $setupstring = '';
465  foreach ($fieldstosearchall as $key => $val) {
466  $fieldstosearchall[$key] = $langs->trans($val);
467  $setupstring .= $key."=".$val.";";
468  }
469  print '<!-- Search done like if MYOBJECT_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
470  print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>'."\n";
471 }
472 
473 $moreforfilter = '';
474 /*$moreforfilter.='<div class="divsearchfield">';
475 $moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
476 $moreforfilter.= '</div>';*/
477 
478 // Filter on categories
479 if (!empty($conf->global->MAIN_SEARCH_CATEGORY_PRODUCT_ON_LISTS) && isModEnabled('categorie') && $user->hasRight('categorie', 'lire')) {
480  $moreforfilter .= '<div class="divsearchfield">';
481  $tmptitle = $langs->transnoentities('ProductsCategoriesShort');
482  $moreforfilter .= img_picto($tmptitle, 'category', 'class="pictofixedwidth"');
483  $categoriesProductArr = $form->select_all_categories(Categorie::TYPE_PRODUCT, '', '', 64, 0, 1);
484  $categoriesProductArr[-2] = '- '.$langs->trans('NotCategorized').' -';
485  $moreforfilter .= Form::multiselectarray('search_category_product_list', $categoriesProductArr, $searchCategoryProductList, 0, 0, 'minwidth300', 0, 0, '', 'category', $tmptitle);
486  $moreforfilter .= ' <input type="checkbox" class="valignmiddle" id="search_category_product_operator" name="search_category_product_operator" value="1"'.($searchCategoryProductOperator == 1 ? ' checked="checked"' : '').'/>';
487  $moreforfilter .= $form->textwithpicto('', $langs->trans('UseOrOperatorForCategories') . ' : ' . $tmptitle, 1, 'help', '', 0, 2, 'tooltip_cat_pro'); // Tooltip on click
488  $moreforfilter .= '</div>';
489 }
490 
491 $parameters = array();
492 $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
493 if (empty($reshook)) {
494  $moreforfilter .= $hookmanager->resPrint;
495 } else {
496  $moreforfilter = $hookmanager->resPrint;
497 }
498 
499 if (!empty($moreforfilter)) {
500  print '<div class="liste_titre liste_titre_bydiv centpercent">';
501  print $moreforfilter;
502  $parameters = array();
503  $reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
504  print $hookmanager->resPrint;
505  print '</div>';
506 }
507 
508 $varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
509 $selectedfields = ($mode != 'kanban' ? $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN', '')) : ''); // This also change content of $arrayfields
510 $selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
511 
512 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you dont need reserved height for your table
513 print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
514 
515 
516 // Fields title search
517 // --------------------------------------------------------------------
518 print '<tr class="liste_titre_filter">';
519 // Action column
520 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
521  print '<td class="liste_titre center maxwidthsearch">';
522  $searchpicto = $form->showFilterButtons('left');
523  print $searchpicto;
524  print '</td>';
525 }
526 foreach ($object->fields as $key => $val) {
527  $searchkey = empty($search[$key]) ? '' : $search[$key];
528  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
529  if ($key == 'status') {
530  $cssforfield .= ($cssforfield ? ' ' : '').'center';
531  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
532  $cssforfield .= ($cssforfield ? ' ' : '').'center';
533  } elseif (in_array($val['type'], array('timestamp'))) {
534  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
535  } 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'])) {
536  $cssforfield .= ($cssforfield ? ' ' : '').'right';
537  }
538  if (!empty($arrayfields['t.'.$key]['checked'])) {
539  print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
540  if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
541  print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
542  } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
543  print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
544  } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
545  print '<div class="nowrap">';
546  print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
547  print '</div>';
548  print '<div class="nowrap">';
549  print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
550  print '</div>';
551  } elseif ($key == 'lang') {
552  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
553  $formadmin = new FormAdmin($db);
554  print $formadmin->select_language($search[$key], 'search_lang', 0, null, 1, 0, 0, 'minwidth150 maxwidth200', 2);
555  } else {
556  print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
557  }
558  print '</td>';
559  }
560 }
561 // Extra fields
562 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
563 
564 // Fields from hook
565 $parameters = array('arrayfields'=>$arrayfields);
566 $reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
567 print $hookmanager->resPrint;
568 // Action column
569 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
570  print '<td class="liste_titre center maxwidthsearch">';
571  $searchpicto = $form->showFilterButtons();
572  print $searchpicto;
573  print '</td>';
574 }
575 print '</tr>'."\n";
576 
577 $totalarray = array();
578 $totalarray['nbfield'] = 0;
579 
580 // Fields title label
581 // --------------------------------------------------------------------
582 print '<tr class="liste_titre">';
583 // Action column
584 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
585  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
586  $totalarray['nbfield']++;
587 }
588 foreach ($object->fields as $key => $val) {
589  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
590  if ($key == 'status') {
591  $cssforfield .= ($cssforfield ? ' ' : '').'center';
592  } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
593  $cssforfield .= ($cssforfield ? ' ' : '').'center';
594  } elseif (in_array($val['type'], array('timestamp'))) {
595  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
596  } 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'])) {
597  $cssforfield .= ($cssforfield ? ' ' : '').'right';
598  }
599  $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
600  if (!empty($arrayfields['t.'.$key]['checked'])) {
601  print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
602  $totalarray['nbfield']++;
603  }
604 }
605 // Extra fields
606 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
607 // Hook fields
608 $parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder, 'totalarray'=>&$totalarray);
609 $reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
610 print $hookmanager->resPrint;
611 // Action column
612 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
613  print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
614  $totalarray['nbfield']++;
615 }
616 print '</tr>'."\n";
617 
618 
619 // Detect if we need a fetch on each output line
620 $needToFetchEachLine = 0;
621 if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
622  foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
623  if (!is_null($val) && preg_match('/\$object/', $val)) {
624  $needToFetchEachLine++; // There is at least one compute field that use $object
625  }
626  }
627 }
628 
629 // Loop on record
630 // --------------------------------------------------------------------
631 $i = 0;
632 $savnbfield = $totalarray['nbfield'];
633 $totalarray = array();
634 $totalarray['nbfield'] = 0;
635 $imaxinloop = ($limit ? min($num, $limit) : $num);
636 while ($i < $imaxinloop) {
637  $obj = $db->fetch_object($resql);
638  if (empty($obj)) {
639  break; // Should not happen
640  }
641 
642  // Store properties in $object
643  $object->setVarsFromFetchObj($obj);
644 
645  if ($mode == 'kanban') {
646  if ($i == 0) {
647  print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
648  print '<div class="box-flex-container kanban">';
649  }
650  // Output Kanban
651  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
652  $selected = 0;
653  if (in_array($object->id, $arrayofselected)) {
654  $selected = 1;
655  }
656  }
657  print $object->getKanbanView('', array('selected' => in_array($object->id, $arrayofselected)));
658  if ($i == ($imaxinloop - 1)) {
659  print '</div>';
660  print '</td></tr>';
661  }
662  } else {
663  // Show here line of result
664  $j = 0;
665  print '<tr data-rowid="'.$object->id.'" class="oddeven">';
666  // Action column
667  if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
668  print '<td class="nowrap center">';
669  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
670  $selected = 0;
671  if (in_array($object->id, $arrayofselected)) {
672  $selected = 1;
673  }
674  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
675  }
676  print '</td>';
677  if (!$i) {
678  $totalarray['nbfield']++;
679  }
680  }
681  foreach ($object->fields as $key => $val) {
682  $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
683  if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
684  $cssforfield .= ($cssforfield ? ' ' : '').'center';
685  } elseif ($key == 'status') {
686  $cssforfield .= ($cssforfield ? ' ' : '').'center';
687  }
688 
689  if (in_array($val['type'], array('timestamp'))) {
690  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
691  } elseif ($key == 'ref') {
692  $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
693  }
694 
695  if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
696  $cssforfield .= ($cssforfield ? ' ' : '').'right';
697  }
698 
699  if (!empty($arrayfields['t.'.$key]['checked'])) {
700  print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
701  if (preg_match('/tdoverflow/', $cssforfield) && !is_numeric($object->$key)) {
702  print ' title="'.dol_escape_htmltag($object->$key).'"';
703  }
704  print '>';
705  if ($key == 'status') {
706  print $object->getLibStatut(5);
707  } elseif ($key == 'rowid') {
708  print $object->showOutputField($val, $key, $object->id, '');
709  } else {
710  print $object->showOutputField($val, $key, $object->$key, '');
711  }
712  print '</td>';
713  if (!$i) {
714  $totalarray['nbfield']++;
715  }
716  if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
717  if (!$i) {
718  $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
719  }
720  if (!isset($totalarray['val'])) {
721  $totalarray['val'] = array();
722  }
723  if (!isset($totalarray['val']['t.'.$key])) {
724  $totalarray['val']['t.'.$key] = 0;
725  }
726  $totalarray['val']['t.'.$key] += $object->$key;
727  }
728  }
729  }
730  // Extra fields
731  include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
732  // Fields from hook
733  $parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
734  $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
735  print $hookmanager->resPrint;
736  // Action column
737  if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
738  print '<td class="nowrap center">';
739  if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
740  $selected = 0;
741  if (in_array($object->id, $arrayofselected)) {
742  $selected = 1;
743  }
744  print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
745  }
746  print '</td>';
747  if (!$i) {
748  $totalarray['nbfield']++;
749  }
750  }
751 
752  print '</tr>'."\n";
753  }
754 
755  $i++;
756 }
757 
758 // Show total line
759 include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
760 
761 
762 // If no record found
763 if ($num == 0) {
764  $colspan = 1;
765  foreach ($arrayfields as $key => $val) {
766  if (!empty($val['checked'])) {
767  $colspan++;
768  }
769  }
770  print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
771 }
772 
773 
774 $db->free($resql);
775 
776 $parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
777 $reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
778 print $hookmanager->resPrint;
779 
780 print '</table>'."\n";
781 print '</div>'."\n";
782 
783 print '</form>'."\n";
784 // no inventory docs yet
785 /*
786 if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
787  $hidegeneratedfilelistifempty = 1;
788  if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
789  $hidegeneratedfilelistifempty = 0;
790  }
791 
792  require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
793  $formfile = new FormFile($db);
794 
795  // Show list of available documents
796  $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
797  $urlsource .= str_replace('&amp;', '&', $param);
798 
799  $filedir = $diroutputmassaction;
800  $genallowed = $permissiontoread;
801  $delallowed = $permissiontoadd;
802 
803  print $formfile->showdocuments('massfilesarea_mymodule', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
804 }
805 */
806 // End of page
807 llxFooter();
808 $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 generate html code for admin pages.
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') && $user->hasRight('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') && $user->hasRight('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)) $sql
Social contributions to pay.
Definition: index.php:746
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_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...
dol_now($mode='auto')
Return date for now.
getDolGlobalInt($key, $default=0)
Return dolibarr global constant int value.
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.
dolGetButtonTitleSeparator($moreClass="")
Add space between dolGetButtonTitle.
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.
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.
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.
isModEnabled($module)
Is Dolibarr module enabled.
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...
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.