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