dolibarr 25.0.0-alpha
bom_list.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2024-2025 MDW <mdeweerd@users.noreply.github.com>
4 * Copyright (C) 2024-2026 Frédéric France <frederic.france@free.fr>
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
38require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
39require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
40require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
41
42// Load translation files required by the page
43$langs->loadLangs(array('mrp', 'other'));
44
45// Get parameters
46$action = GETPOST('action', 'aZ09') ? GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
47$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
48$show_files = GETPOSTINT('show_files'); // Show files area generated by bulk actions ?
49$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
50$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
51$toselect = GETPOST('toselect', 'array:int'); // Array of ids of elements selected into a list
52$contextpage = GETPOST('contextpage', 'aZ') ? GETPOST('contextpage', 'aZ') : 'bomlist'; // To manage different context of search
53$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
54$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
55$mode = GETPOST('mode', 'aZ'); // mode view (kanban or common)
56
57$id = GETPOSTINT('id');
58
59// Load variable for pagination
60$limit = GETPOSTINT('limit') ? GETPOSTINT('limit') : $conf->liste_limit;
61$sortfield = GETPOST('sortfield', 'aZ09comma');
62$sortorder = GETPOST('sortorder', 'aZ09comma');
63$page = GETPOSTISSET('pageplusone') ? (GETPOSTINT('pageplusone') - 1) : GETPOSTINT('page');
64if (empty($page) || $page < 0 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha')) {
65 // If $page is not defined, or '' or -1 or if we click on clear filters
66 $page = 0;
67}
68$offset = $limit * $page;
69$pageprev = $page - 1;
70$pagenext = $page + 1;
71//if (! $sortfield) $sortfield="p.date_fin";
72//if (! $sortorder) $sortorder="DESC";
73
74// Initialize a technical objects
75$object = new BOM($db);
76$diroutputmassaction = getMultidirOutput($object, '', 0, 'temp') . 'massgeneration/'.$user->id;
77$hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array
78
79// Fetch optionals attributes and labels
80$extrafields->fetch_name_optionals_label($object->table_element);
81
82$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
83
84// Default sort order (if not yet defined by previous GETPOST)
85if (!$sortfield) {
86 $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
87}
88if (!$sortorder) {
89 $sortorder = "ASC";
90}
91
92// Initialize array of search criteria
93$search_all = trim(GETPOST('search_all', 'alphanohtml'));
94$search = array();
95foreach ($object->fields as $key => $val) {
96 if (GETPOST('search_'.$key, 'alpha') !== '') {
97 $search[$key] = GETPOST('search_'.$key, 'alpha');
98 }
99 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
100 $search[$key.'_dtstart'] = GETPOSTDATE('search_'.$key);
101 $search[$key.'_dtend'] = GETPOSTDATE('search_'.$key, 'end');
102 }
103}
104
105// List of fields to search into when doing a "search in all"
106$fieldstosearchall = array();
107foreach ($object->fields as $key => $val) {
108 if (!empty($val['searchall'])) {
109 $fieldstosearchall['t.'.$key] = $val['label'];
110 }
111}
112
113// Definition of array of fields for columns
114$arrayfields = array();
115foreach ($object->fields as $key => $val) {
116 // If $val['visible']==0, then we never show the field
117 if (!empty($val['visible'])) {
118 $visible = (int) dol_eval((string) $val['visible'], 1);
119 $arrayfields['t.'.$key] = array(
120 'label' => $val['label'],
121 'checked' => (($visible < 0) ? 0 : 1),
122 'enabled' => (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
123 'position' => $val['position'],
124 'help' => isset($val['help']) ? $val['help'] : ''
125 );
126 }
127}
128// Extra fields
129include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
130// Add hook to complete $arrayfield
131$parameters = array('arrayfields' => &$arrayfields);
132$reshook = $hookmanager->executeHooks('completeArrayFields', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
133
134$object->fields = dol_sort_array($object->fields, 'position');
135$arrayfields = dol_sort_array($arrayfields, 'position');
136
137$permissiontoread = $user->hasRight('bom', 'read');
138$permissiontoadd = $user->hasRight('bom', 'write');
139$permissiontodelete = $user->hasRight('bom', 'delete');
140
141// Security check
142if ($user->socid > 0) {
144}
145$result = restrictedArea($user, 'bom');
146
147$uploaddir = getMultidirOutput($object);
148
149
150/*
151 * Actions
152 */
153
154$error = 0;
155
156if (GETPOST('cancel', 'alpha')) {
157 $action = 'list';
158 $massaction = '';
159}
160if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
161 $massaction = '';
162}
163
164$parameters = array();
165$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
166if ($reshook < 0) {
167 setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
168}
169
170if (empty($reshook)) {
171 // Selection of new fields
172 include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
173
174 // Purge search criteria
175 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
176 foreach ($object->fields as $key => $val) {
177 $search[$key] = '';
178 if ($key == 'status') {
179 $search[$key] = -1;
180 }
181 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
182 $search[$key.'_dtstart'] = '';
183 $search[$key.'_dtend'] = '';
184 }
185 }
186 $search_all = '';
187 $toselect = array();
188 $search_array_options = array();
189 }
190 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
191 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
192 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
193 }
194
195 // Mass actions
196 $objectclass = 'BOM';
197 $objectlabel = 'BillOfMaterials';
198
199 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
200
201
202 // Validate records
203 if ($massaction == 'disable' && $permissiontoadd) {
204 $objecttmp = new $objectclass($db);
205
206 if (!$error) {
207 $db->begin();
208
209 $nbok = 0;
210 foreach ($toselect as $toselectid) {
211 $result = $objecttmp->fetch($toselectid);
212 if ($result > 0) {
213 if ($objecttmp->status != $objecttmp::STATUS_VALIDATED) {
214 $langs->load("errors");
215 setEventMessages($langs->trans("ErrorObjectMustHaveStatusActiveToBeDisabled", $objecttmp->ref), null, 'errors');
216 $error++;
217 break;
218 }
219
220 // Can be 'cancel()' or 'close()'
221 $result = $objecttmp->cancel($user);
222 if ($result < 0) {
223 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
224 $error++;
225 break;
226 } else {
227 $nbok++;
228 }
229 } else {
230 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
231 $error++;
232 break;
233 }
234 }
235
236 if (!$error) {
237 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
238 $db->commit();
239 } else {
240 $db->rollback();
241 }
242 //var_dump($listofobjectthirdparties);exit;
243 }
244 }
245
246 // Validate records
247 if (!$error && $massaction == 'enable' && $permissiontoadd) {
248 $objecttmp = new $objectclass($db);
249
250 if (!$error) {
251 $db->begin();
252
253 $nbok = 0;
254 foreach ($toselect as $toselectid) {
255 $result = $objecttmp->fetch($toselectid);
256 if ($result > 0) {
257 if ($objecttmp->status != $objecttmp::STATUS_DRAFT && $objecttmp->status != $objecttmp::STATUS_CANCELED) {
258 $langs->load("errors");
259 setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated", $objecttmp->ref), null, 'errors');
260 $error++;
261 break;
262 }
263
264 // Can be 'cancel()' or 'close()'
265 $result = $objecttmp->validate($user);
266 if ($result < 0) {
267 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
268 $error++;
269 break;
270 } else {
271 $nbok++;
272 }
273 } else {
274 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
275 $error++;
276 break;
277 }
278 }
279
280 if (!$error) {
281 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
282 $db->commit();
283 } else {
284 $db->rollback();
285 }
286 }
287 }
288}
289
290
291/*
292 * View
293 */
294
295$form = new Form($db);
296
297$now = dol_now();
298
299$title = $langs->trans('ListOfBOMs');
300$help_url = 'EN:Module_BOM';
301$morejs = array();
302$morecss = array();
303
304$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
305$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, $conf->main_checkbox_left_column); // This also change content of $arrayfields with user setup
306
307
308// Build and execute select
309// --------------------------------------------------------------------
310$sql = 'SELECT ';
311$sql .= $object->getFieldList('t');
312// Add fields from extrafields
313if (!empty($extrafields->attributes[$object->table_element]['label'])) {
314 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
315 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
316 }
317}
318// Add fields from hooks
319$parameters = array();
320$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
321$sql .= $hookmanager->resPrint;
322$sql = preg_replace('/,\s*$/', '', $sql);
323
324$sqlfields = $sql; // $sql fields to remove for count total
325
326$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
327if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
328 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
329}
330$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON t.fk_product = p.rowid";
331// Add table from hooks
332$parameters = array();
333$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
334$sql .= $hookmanager->resPrint;
335if ($object->ismultientitymanaged == 1) {
336 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
337} else {
338 $sql .= " WHERE 1 = 1";
339}
340foreach ($search as $key => $val) {
341 if (array_key_exists($key, $object->fields)) {
342 if ($key == 'status' && $search[$key] == -1) {
343 continue;
344 }
345 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
346 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
347 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
348 $search[$key] = '';
349 }
350 $mode_search = 2;
351 }
352 if ($search[$key] != '') {
353 if ($key == 'ref' && empty($arrayfields['t.label']['checked'])) {
354 // Label is shown into the ref column, so search on both
355 $sql .= natural_search(array('t.ref', 't.label'), $search[$key]);
356 } else {
357 $sql .= natural_search("t.".$db->sanitize($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
358 }
359 }
360 } else {
361 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
362 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
363 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
364 if (preg_match('/_dtstart$/', $key)) {
365 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
366 }
367 if (preg_match('/_dtend$/', $key)) {
368 $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
369 }
370 }
371 }
372 }
373}
374
375if ($search_all) {
376 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
377}
378//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
379// Add where from extra fields
380include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
381// Add where from hooks
382$parameters = array();
383$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
384$sql .= $hookmanager->resPrint;
385
386/* If a group by is required
387$sql.= " GROUP BY ";
388foreach($object->fields as $key => $val) {
389 $sql .= "t.".$db->sanitize($key).", ";
390}
391// Add fields from extrafields
392if (!empty($extrafields->attributes[$object->table_element]['label'])) {
393 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
394 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
395 }
396}
397// Add groupby from hooks
398$parameters=array();
399$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
400$sql.=$hookmanager->resPrint;
401$sql=preg_replace('/,\s*$/','', $sql);
402*/
403
404// Count total nb of records
405$nbtotalofrecords = '';
406if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
407 /* The fast and low memory method to get and count full list converts the sql into a sql count */
408 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
409 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
410 $resql = $db->query($sqlforcount);
411 if ($resql) {
412 $objforcount = $db->fetch_object($resql);
413 $nbtotalofrecords = $objforcount->nbtotalofrecords;
414 } else {
415 dol_print_error($db);
416 }
417
418 if (($page * $limit) > (int) $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
419 $page = 0;
420 $offset = 0;
421 }
422 $db->free($resql);
423}
424
425// Complete request and execute it with limit
426$sql .= $db->order($sortfield, $sortorder);
427if ($limit) {
428 $sql .= $db->plimit($limit + 1, $offset);
429}
430
431$resql = $db->query($sql);
432if (!$resql) {
433 dol_print_error($db);
434 exit;
435}
436
437$num = $db->num_rows($resql);
438
439// Direct jump if only one record found
440if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
441 $obj = $db->fetch_object($resql);
442 $id = $obj->rowid;
443 header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.((int) $id));
444 exit;
445}
446
447
448// Output page
449// --------------------------------------------------------------------
450
451llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-bom page-list bodyforlist');
452
453$arrayofselected = is_array($toselect) ? $toselect : array();
454
455$param = '';
456if (!empty($mode)) {
457 $param .= '&mode='.urlencode($mode);
458}
459if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
460 $param .= '&contextpage='.urlencode($contextpage);
461}
462if ($limit > 0 && $limit != $conf->liste_limit) {
463 $param .= '&limit='.((int) $limit);
464}
465if ($optioncss != '') {
466 $param .= '&optioncss='.urlencode($optioncss);
467}
468foreach ($search as $key => $val) {
469 if (is_array($search[$key])) {
470 foreach ($search[$key] as $skey) {
471 if ($skey != '') {
472 $param .= '&search_'.$key.'[]='.urlencode($skey);
473 }
474 }
475 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
476 $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
477 $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
478 $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
479 } elseif ($search[$key] != '') {
480 $param .= '&search_'.$key.'='.urlencode($search[$key]);
481 }
482}
483// Add $param from extra fields
484include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
485// Add $param from hooks
486$parameters = array('param' => &$param);
487$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
488$param .= $hookmanager->resPrint;
489
490// List of mass actions available
491$arrayofmassactions = array(
492 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
493 'enable' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Enable"),
494 'disable' => img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Disable"),
495);
496if (!empty($permissiontodelete)) {
497 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
498}
499if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
500 $arrayofmassactions = array();
501}
502$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
503
504print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'" spellcheck="false">'."\n";
505if ($optioncss != '') {
506 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
507}
508print '<input type="hidden" name="token" value="'.newToken().'">';
509print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
510print '<input type="hidden" name="action" value="list">';
511print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
512print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
513print '<input type="hidden" name="page" value="'.$page.'">';
514print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
515print '<input type="hidden" name="page_y" value="">';
516print '<input type="hidden" name="mode" value="'.$mode.'">';
517
518$newcardbutton = '';
519$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'));
520$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'));
521$newcardbutton .= dolGetButtonTitleSeparator();
522$newcardbutton .= dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bom/bom_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->hasRight('bom', 'write'));
523
524print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
525
526// Add code for pre mass action (confirmation or email presend form)
527$topicmail = "SendBillOfMaterialsRef";
528$modelmail = "bom";
529$objecttmp = new BOM($db);
530$trackid = 'bom'.$object->id;
531include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
532
533if ($search_all) {
534 $setupstring = '';
535 foreach ($fieldstosearchall as $key => $val) {
536 $fieldstosearchall[$key] = $langs->trans($val);
537 $setupstring .= $key."=".$val.";";
538 }
539 print '<!-- Search done like if BOM_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
540 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
541}
542
543$moreforfilter = '';
544/*$moreforfilter.='<div class="divsearchfield">';
545$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
546$moreforfilter.= '</div>';*/
547
548$parameters = array();
549$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
550if (empty($reshook)) {
551 $moreforfilter .= $hookmanager->resPrint;
552} else {
553 $moreforfilter = $hookmanager->resPrint;
554}
555
556if (!empty($moreforfilter)) {
557 print '<div class="liste_titre liste_titre_bydiv centpercent">';
558 print $moreforfilter;
559 print '</div>';
560}
561
562$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
563$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
564
565print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
566print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
567
568
569// Fields title search
570// --------------------------------------------------------------------
571print '<tr class="liste_titre_filter">';
572
573// Action column
574if ($conf->main_checkbox_left_column) {
575 print '<td class="liste_titre center maxwidthsearch">';
576 $searchpicto = $form->showFilterButtons('left');
577 print $searchpicto;
578 print '</td>';
579}
580
581foreach ($object->fields as $key => $val) {
582 $searchkey = empty($search[$key]) ? '' : $search[$key];
583 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
584 if ($key == 'status') {
585 $cssforfield .= ($cssforfield ? ' ' : '').'center';
586 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
587 $cssforfield .= ($cssforfield ? ' ' : '').'center';
588 } elseif (in_array($val['type'], array('timestamp'))) {
589 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
590 } 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'])) {
591 $cssforfield .= ($cssforfield ? ' ' : '').'right';
592 }
593 if (!empty($arrayfields['t.'.$key]['checked'])) {
594 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
595 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
596 print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), 1, 0, 0, '', 1, 0, 0, '', 'maxwidth100'.($key == 'status' ? ' search_status width100 onrightofpage' : ''), 1);
597 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
598 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
599 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
600 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
601 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
602 print '<div class="nowrap">';
603 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
604 print '</div>';
605 print '<div class="nowrap">';
606 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
607 print '</div>';
608 } elseif ($key == 'lang') {
609 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
610 $formadmin = new FormAdmin($db);
611 print $formadmin->select_language($search[$key], 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
612 } else {
613 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
614 }
615 print '</td>';
616 }
617}
618// Extra fields
619include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
620
621// Fields from hook
622$parameters = array('arrayfields' => $arrayfields);
623$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
624print $hookmanager->resPrint;
625// Action column
626if (!$conf->main_checkbox_left_column) {
627 print '<td class="liste_titre center maxwidthsearch">';
628 $searchpicto = $form->showFilterButtons();
629 print $searchpicto;
630 print '</td>';
631}
632print '</tr>'."\n";
633
634$totalarray = array();
635$totalarray['nbfield'] = 0;
636
637// Fields title label
638// --------------------------------------------------------------------
639print '<tr class="liste_titre">';
640// Action column
641if ($conf->main_checkbox_left_column) {
642 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
643 $totalarray['nbfield']++;
644}
645foreach ($object->fields as $key => $val) {
646 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
647 if ($key == 'status') {
648 $cssforfield .= ($cssforfield ? ' ' : '').'center';
649 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
650 $cssforfield .= ($cssforfield ? ' ' : '').'center';
651 } elseif (in_array($val['type'], array('timestamp'))) {
652 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
653 } 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'])) {
654 $cssforfield .= ($cssforfield ? ' ' : '').'right';
655 }
656 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
657 if (!empty($arrayfields['t.'.$key]['checked'])) {
658 if ($key == "fk_product") {
659 print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 'p.ref', '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''), 0, (empty($val['helplist']) ? '' : $val['helplist']))."\n";
660 } else {
661 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";
662 }
663 $totalarray['nbfield']++;
664 }
665}
666// Extra fields
667include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
668// Hook fields
669$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
670$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
671print $hookmanager->resPrint;
672// Action column
673if (!$conf->main_checkbox_left_column) {
674 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
675 $totalarray['nbfield']++;
676}
677print '</tr>'."\n";
678
679
680// Detect if we need a fetch on each output line
681$needToFetchEachLine = 0;
682if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
683 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
684 if (!is_null($val) && preg_match('/\$object/', $val)) {
685 $needToFetchEachLine++; // There is at least one compute field that use $object
686 }
687 }
688}
689
690
691// Loop on record
692// --------------------------------------------------------------------
693$i = 0;
694$savnbfield = $totalarray['nbfield'];
695$totalarray = array();
696$totalarray['nbfield'] = 0;
697$imaxinloop = ($limit ? min($num, $limit) : $num);
698while ($i < $imaxinloop) {
699 $obj = $db->fetch_object($resql);
700 if (empty($obj)) {
701 break; // Should not happen
702 }
703
704 // Store properties in $object
705 $object->setVarsFromFetchObj($obj);
706
707 // mode view kanban
708 if ($mode == 'kanban') {
709 if ($i == 0) {
710 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
711 print '<div class="box-flex-container kanban">';
712 }
713
714 // TODO Use a cache for product
715 if (!empty($obj->fk_product)) {
716 $prod = new Product($db);
717 $prod->fetch($obj->fk_product);
718 } else {
719 $prod = null;
720 }
721
722 // Output Kanban
723 $selected = -1;
724 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
725 $selected = 0;
726 if (in_array($object->id, $arrayofselected)) {
727 $selected = 1;
728 }
729 }
730 print $object->getKanbanView('', array('prod' => $prod, 'selected' => $selected));
731 if ($i == ($imaxinloop - 1)) {
732 print '</div>';
733 print '</td></tr>';
734 }
735 } else {
736 // Show line of result
737 $j = 0;
738 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
739 // Action column
740 if ($conf->main_checkbox_left_column) {
741 print '<td class="nowrap center">';
742 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
743 $selected = 0;
744 if (in_array($object->id, $arrayofselected)) {
745 $selected = 1;
746 }
747 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
748 }
749 print '</td>';
750 if (!$i) {
751 $totalarray['nbfield']++;
752 }
753 }
754 // Fields
755 foreach ($object->fields as $key => $val) {
756 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
757 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
758 $cssforfield .= ($cssforfield ? ' ' : '').'center';
759 } elseif ($key == 'status') {
760 $cssforfield .= ($cssforfield ? ' ' : '').'center';
761 }
762
763 if ($key == 'ref') {
764 $cssforfield .= ($cssforfield ? ' ' : '').(empty($arrayfields['t.label']['checked']) ? 'tdlineheightsmall' : 'nowraponall');
765 }
766
767 if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('id', 'rowid', 'ref', 'status')) && empty($val['arrayofkeyval'])) {
768 $cssforfield .= ($cssforfield ? ' ' : '').'right';
769 }
770
771 if (!empty($arrayfields['t.'.$key]['checked'])) {
772 print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
773 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
774 print ' title="'.dolPrintHTMLForAttribute((string) $object->$key).'"';
775 }
776 print '>';
777 if ($key == 'status') {
778 print $object->getLibStatut(5);
779 } elseif ($key == 'rowid') {
780 print $object->showOutputField($val, $key, (string) $object->id, '');
781 } elseif ($key == 'ref' && empty($arrayfields['t.label']['checked'])) {
782 // Show label under the ref when label column is not enabled
783 print '<div class="tdoverflowmax150 inline-block lineheightsmall">';
784 print $object->showOutputField($val, $key, (string) $object->$key, '');
785 if (!empty($object->label)) {
786 print '<br><span class="spantitle">'.dolPrintHTML($object->label).'</span>';
787 }
788 print '</div>';
789 } elseif ($key == 'label') {
790 print '<span class="spantitle">'.$object->showOutputField($val, $key, (string) $object->$key, '').'</span>';
791 } else {
792 if ($val['type'] == 'html') {
793 print '<div class="small lineheightsmall twolinesmax-normallineheight">';
794 }
795 print $object->showOutputField($val, $key, (string) $object->$key, '');
796 if ($val['type'] == 'html') {
797 print '</div>';
798 }
799 }
800 print '</td>';
801 if (!$i) {
802 $totalarray['nbfield']++;
803 }
804 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
805 if (!$i) {
806 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
807 }
808 if (!isset($totalarray['val'])) {
809 $totalarray['val'] = array();
810 }
811 if (!isset($totalarray['val']['t.'.$key])) {
812 $totalarray['val']['t.'.$key] = 0;
813 }
814 $totalarray['val']['t.'.$key] += $object->$key;
815 }
816 }
817 }
818 // Extra fields
819 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
820 // Fields from hook
821 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
822 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
823 print $hookmanager->resPrint;
824 // Action column
825 if (!$conf->main_checkbox_left_column) {
826 print '<td class="nowrap center">';
827 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
828 $selected = 0;
829 if (in_array($object->id, $arrayofselected)) {
830 $selected = 1;
831 }
832 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
833 }
834 print '</td>';
835 if (!$i) {
836 $totalarray['nbfield']++;
837 }
838 }
839
840 print '</tr>'."\n";
841 }
842
843 $i++;
844}
845
846// Show total line
847include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
848
849
850// If no record found
851if ($num == 0) {
852 $colspan = 1;
853 foreach ($arrayfields as $key => $val) {
854 if (!empty($val['checked'])) {
855 $colspan++;
856 }
857 }
858 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
859}
860
861
862$db->free($resql);
863
864$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
865$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
866print $hookmanager->resPrint;
867
868print '</table>'."\n";
869print '</div>'."\n";
870
871print '</form>'."\n";
872
873
874if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
875 $hidegeneratedfilelistifempty = 1;
876 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
877 $hidegeneratedfilelistifempty = 0;
878 }
879
880 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
881 $formfile = new FormFile($db);
882
883 // Show list of available documents
884 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
885 $urlsource .= str_replace('&amp;', '&', $param);
886
887 $filedir = $diroutputmassaction;
888 $genallowed = $permissiontoread;
889 $delallowed = $permissiontoadd;
890
891 print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
892}
893
894// End of page
895llxFooter();
896$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:47
if(! $sortfield) if(! $sortorder) $object
Definition account.php:100
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:91
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader($head='', $title='', $help_url='', $target='', $disablejs=0, $disablehead=0, $arrayofjs='', $arrayofcss='', $morequerystring='', $morecssonbody='', $replacemainareaby='', $disablenofollow=0, $disablenoindex=0)
Empty header.
Definition wrapper.php:73
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class for BOM.
Definition bom.class.php:42
Class to generate html code for admin pages.
Class to offer components to list and upload files.
Class to manage generation of HTML components Only common components must be here.
Class to manage products or services.
dol_now($mode='gmt')
Return date for now.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
dol_eval($s, $returnvalue=1, $hideerrors=1, $onlysimplestring='1')
Replace eval function to add more security.
natural_search($fields, $value, $mode=0, $nofirstand=0, $sqltoadd='')
Generate natural SQL search string for a criteria (this criteria can be tested on one or several fiel...
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...
getMultidirOutput($object, $module='', $forobject=0, $mode='output')
Return the full path of the directory where a module (or an object of a module) stores its files.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
GETPOSTINT($paramname, $method=0, $nodefault=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
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.
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.
dol_escape_htmltag($stringtoescape, $keepb=0, $keepn=0, $noescapetags='', $escapeonlyhtmltags=0, $cleanalsojavascript=0)
Definition html.lib.php:183
restrictedArea(User $user, $features, $object=0, $tableandshare='', $feature2='', $dbt_keyfield='fk_soc', $dbt_select='rowid', $isdraft=0, $nodie=0, $mode='')
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.