dolibarr 22.0.5
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 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';
28require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
29require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
30require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
31require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
32require_once DOL_DOCUMENT_ROOT.'/product/class/product.class.php';
33
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'); // 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$extrafields = new ExtraFields($db);
77$diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
78$hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array
79
80// Fetch optionals attributes and labels
81$extrafields->fetch_name_optionals_label($object->table_element);
82
83$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
84
85// Default sort order (if not yet defined by previous GETPOST)
86if (!$sortfield) {
87 $sortfield = "t.ref"; // Set here default search field. By default 1st field in definition.
88}
89if (!$sortorder) {
90 $sortorder = "ASC";
91}
92
93// Initialize array of search criteria
94$search_all = trim(GETPOST('search_all', 'alphanohtml'));
95$search = array();
96foreach ($object->fields as $key => $val) {
97 if (GETPOST('search_'.$key, 'alpha') !== '') {
98 $search[$key] = GETPOST('search_'.$key, 'alpha');
99 }
100 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
101 $search[$key.'_dtstart'] = GETPOSTDATE('search_'.$key);
102 $search[$key.'_dtend'] = GETPOSTDATE('search_'.$key, 'end');
103 }
104}
105
106// List of fields to search into when doing a "search in all"
107$fieldstosearchall = array();
108foreach ($object->fields as $key => $val) {
109 if (!empty($val['searchall'])) {
110 $fieldstosearchall['t.'.$key] = $val['label'];
111 }
112}
113
114// Definition of array of fields for columns
115$arrayfields = array();
116foreach ($object->fields as $key => $val) {
117 // If $val['visible']==0, then we never show the field
118 if (!empty($val['visible'])) {
119 $visible = (int) dol_eval((string) $val['visible'], 1);
120 $arrayfields['t.'.$key] = array(
121 'label' => $val['label'],
122 'checked' => (($visible < 0) ? 0 : 1),
123 'enabled' => (abs($visible) != 3 && (bool) dol_eval((string) $val['enabled'], 1)),
124 'position' => $val['position'],
125 'help' => isset($val['help']) ? $val['help'] : ''
126 );
127 }
128}
129// Extra fields
130include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
131
132$object->fields = dol_sort_array($object->fields, 'position');
133$arrayfields = dol_sort_array($arrayfields, 'position');
134
135$permissiontoread = $user->hasRight('bom', 'read');
136$permissiontoadd = $user->hasRight('bom', 'write');
137$permissiontodelete = $user->hasRight('bom', 'delete');
138
139// Security check
140if ($user->socid > 0) {
142}
143$result = restrictedArea($user, 'bom');
144
145
146/*
147 * Actions
148 */
149$error = 0;
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 ($key == 'status') {
174 $search[$key] = -1;
175 }
176 if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
177 $search[$key.'_dtstart'] = '';
178 $search[$key.'_dtend'] = '';
179 }
180 }
181 $search_all = '';
182 $toselect = array();
183 $search_array_options = array();
184 }
185 if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
186 || GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
187 $massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
188 }
189
190 // Mass actions
191 $objectclass = 'BOM';
192 $objectlabel = 'BillOfMaterials';
193 $uploaddir = $conf->bom->dir_output;
194 include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
195
196
197 // Validate records
198 if ($massaction == 'disable' && $permissiontoadd) {
199 $objecttmp = new $objectclass($db);
200
201 if (!$error) {
202 $db->begin();
203
204 $nbok = 0;
205 foreach ($toselect as $toselectid) {
206 $result = $objecttmp->fetch($toselectid);
207 if ($result > 0) {
208 if ($objecttmp->status != $objecttmp::STATUS_VALIDATED) {
209 $langs->load("errors");
210 setEventMessages($langs->trans("ErrorObjectMustHaveStatusActiveToBeDisabled", $objecttmp->ref), null, 'errors');
211 $error++;
212 break;
213 }
214
215 // Can be 'cancel()' or 'close()'
216 $result = $objecttmp->cancel($user);
217 if ($result < 0) {
218 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
219 $error++;
220 break;
221 } else {
222 $nbok++;
223 }
224 } else {
225 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
226 $error++;
227 break;
228 }
229 }
230
231 if (!$error) {
232 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
233 $db->commit();
234 } else {
235 $db->rollback();
236 }
237 //var_dump($listofobjectthirdparties);exit;
238 }
239 }
240
241 // Validate records
242 if (!$error && $massaction == 'enable' && $permissiontoadd) {
243 $objecttmp = new $objectclass($db);
244
245 if (!$error) {
246 $db->begin();
247
248 $nbok = 0;
249 foreach ($toselect as $toselectid) {
250 $result = $objecttmp->fetch($toselectid);
251 if ($result > 0) {
252 if ($objecttmp->status != $objecttmp::STATUS_DRAFT && $objecttmp->status != $objecttmp::STATUS_CANCELED) {
253 $langs->load("errors");
254 setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated", $objecttmp->ref), null, 'errors');
255 $error++;
256 break;
257 }
258
259 // Can be 'cancel()' or 'close()'
260 $result = $objecttmp->validate($user);
261 if ($result < 0) {
262 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
263 $error++;
264 break;
265 } else {
266 $nbok++;
267 }
268 } else {
269 setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
270 $error++;
271 break;
272 }
273 }
274
275 if (!$error) {
276 setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
277 $db->commit();
278 } else {
279 $db->rollback();
280 }
281 }
282 }
283}
284
285
286/*
287 * View
288 */
289
290$form = new Form($db);
291
292$now = dol_now();
293
294$title = $langs->trans('ListOfBOMs');
295$help_url = 'EN:Module_BOM';
296$morejs = array();
297$morecss = array();
298
299
300// Build and execute select
301// --------------------------------------------------------------------
302$sql = 'SELECT ';
303$sql .= $object->getFieldList('t');
304// Add fields from extrafields
305if (!empty($extrafields->attributes[$object->table_element]['label'])) {
306 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
307 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key : '');
308 }
309}
310// Add fields from hooks
311$parameters = array();
312$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
313$sql .= $hookmanager->resPrint;
314$sql = preg_replace('/,\s*$/', '', $sql);
315
316$sqlfields = $sql; // $sql fields to remove for count total
317
318$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
319if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
320 $sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
321}
322$sql .= " LEFT JOIN ".MAIN_DB_PREFIX."product as p ON t.fk_product = p.rowid";
323// Add table from hooks
324$parameters = array();
325$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
326$sql .= $hookmanager->resPrint;
327if ($object->ismultientitymanaged == 1) {
328 $sql .= " WHERE t.entity IN (".getEntity($object->element, (GETPOSTINT('search_current_entity') ? 0 : 1)).")";
329} else {
330 $sql .= " WHERE 1 = 1";
331}
332foreach ($search as $key => $val) {
333 if (array_key_exists($key, $object->fields)) {
334 if ($key == 'status' && $search[$key] == -1) {
335 continue;
336 }
337 $mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
338 if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
339 if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
340 $search[$key] = '';
341 }
342 $mode_search = 2;
343 }
344 if ($search[$key] != '') {
345 $sql .= natural_search("t.".$db->sanitize($key), $search[$key], (($key == 'status') ? 2 : $mode_search));
346 }
347 } else {
348 if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
349 $columnName = preg_replace('/(_dtstart|_dtend)$/', '', $key);
350 if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
351 if (preg_match('/_dtstart$/', $key)) {
352 $sql .= " AND t.".$db->sanitize($columnName)." >= '".$db->idate($search[$key])."'";
353 }
354 if (preg_match('/_dtend$/', $key)) {
355 $sql .= " AND t.".$db->sanitize($columnName)." <= '".$db->idate($search[$key])."'";
356 }
357 }
358 }
359 }
360}
361
362if ($search_all) {
363 $sql .= natural_search(array_keys($fieldstosearchall), $search_all);
364}
365//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
366// Add where from extra fields
367include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
368// Add where from hooks
369$parameters = array();
370$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
371$sql .= $hookmanager->resPrint;
372
373/* If a group by is required
374$sql.= " GROUP BY ";
375foreach($object->fields as $key => $val) {
376 $sql .= "t.".$db->sanitize($key).", ";
377}
378// Add fields from extrafields
379if (!empty($extrafields->attributes[$object->table_element]['label'])) {
380 foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
381 $sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
382 }
383}
384// Add groupby from hooks
385$parameters=array();
386$reshook = $hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
387$sql.=$hookmanager->resPrint;
388$sql=preg_replace('/,\s*$/','', $sql);
389*/
390
391// Count total nb of records
392$nbtotalofrecords = '';
393if (!getDolGlobalInt('MAIN_DISABLE_FULL_SCANLIST')) {
394 /* The fast and low memory method to get and count full list converts the sql into a sql count */
395 $sqlforcount = preg_replace('/^'.preg_quote($sqlfields, '/').'/', 'SELECT COUNT(*) as nbtotalofrecords', $sql);
396 $sqlforcount = preg_replace('/GROUP BY .*$/', '', $sqlforcount);
397 $resql = $db->query($sqlforcount);
398 if ($resql) {
399 $objforcount = $db->fetch_object($resql);
400 $nbtotalofrecords = $objforcount->nbtotalofrecords;
401 } else {
402 dol_print_error($db);
403 }
404
405 if (($page * $limit) > $nbtotalofrecords) { // if total resultset is smaller than the paging size (filtering), goto and load page 0
406 $page = 0;
407 $offset = 0;
408 }
409 $db->free($resql);
410}
411
412// Complete request and execute it with limit
413$sql .= $db->order($sortfield, $sortorder);
414if ($limit) {
415 $sql .= $db->plimit($limit + 1, $offset);
416}
417
418$resql = $db->query($sql);
419if (!$resql) {
420 dol_print_error($db);
421 exit;
422}
423
424$num = $db->num_rows($resql);
425
426// Direct jump if only one record found
427if ($num == 1 && getDolGlobalInt('MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE') && $search_all && !$page) {
428 $obj = $db->fetch_object($resql);
429 $id = $obj->rowid;
430 header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.((int) $id));
431 exit;
432}
433
434
435// Output page
436// --------------------------------------------------------------------
437
438llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', 'mod-bom page-list bodyforlist');
439
440$arrayofselected = is_array($toselect) ? $toselect : array();
441
442$param = '';
443if (!empty($mode)) {
444 $param .= '&mode='.urlencode($mode);
445}
446if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
447 $param .= '&contextpage='.urlencode($contextpage);
448}
449if ($limit > 0 && $limit != $conf->liste_limit) {
450 $param .= '&limit='.((int) $limit);
451}
452if ($optioncss != '') {
453 $param .= '&optioncss='.urlencode($optioncss);
454}
455foreach ($search as $key => $val) {
456 if (is_array($search[$key])) {
457 foreach ($search[$key] as $skey) {
458 if ($skey != '') {
459 $param .= '&search_'.$key.'[]='.urlencode($skey);
460 }
461 }
462 } elseif (preg_match('/(_dtstart|_dtend)$/', $key) && !empty($val)) {
463 $param .= '&search_'.$key.'month='.(GETPOSTINT('search_'.$key.'month'));
464 $param .= '&search_'.$key.'day='.(GETPOSTINT('search_'.$key.'day'));
465 $param .= '&search_'.$key.'year='.(GETPOSTINT('search_'.$key.'year'));
466 } elseif ($search[$key] != '') {
467 $param .= '&search_'.$key.'='.urlencode($search[$key]);
468 }
469}
470// Add $param from extra fields
471include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
472// Add $param from hooks
473$parameters = array('param' => &$param);
474$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
475$param .= $hookmanager->resPrint;
476
477// List of mass actions available
478$arrayofmassactions = array(
479 //'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
480 'enable' => img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Enable"),
481 'disable' => img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Disable"),
482);
483if (!empty($permissiontodelete)) {
484 $arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
485}
486if (GETPOSTINT('nomassaction') || in_array($massaction, array('presend', 'predelete'))) {
487 $arrayofmassactions = array();
488}
489$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
490
491print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
492if ($optioncss != '') {
493 print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
494}
495print '<input type="hidden" name="token" value="'.newToken().'">';
496print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
497print '<input type="hidden" name="action" value="list">';
498print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
499print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
500print '<input type="hidden" name="page" value="'.$page.'">';
501print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
502print '<input type="hidden" name="page_y" value="">';
503print '<input type="hidden" name="mode" value="'.$mode.'">';
504
505$newcardbutton = '';
506$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'));
507$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'));
508$newcardbutton .= dolGetButtonTitleSeparator();
509$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'));
510
511print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
512
513// Add code for pre mass action (confirmation or email presend form)
514$topicmail = "SendBillOfMaterialsRef";
515$modelmail = "bom";
516$objecttmp = new BOM($db);
517$trackid = 'bom'.$object->id;
518include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
519
520if ($search_all) {
521 $setupstring = '';
522 foreach ($fieldstosearchall as $key => $val) {
523 $fieldstosearchall[$key] = $langs->trans($val);
524 $setupstring .= $key."=".$val.";";
525 }
526 print '<!-- Search done like if BOM_QUICKSEARCH_ON_FIELDS = '.$setupstring.' -->'."\n";
527 print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).implode(', ', $fieldstosearchall).'</div>'."\n";
528}
529
530$moreforfilter = '';
531/*$moreforfilter.='<div class="divsearchfield">';
532$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
533$moreforfilter.= '</div>';*/
534
535$parameters = array();
536$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
537if (empty($reshook)) {
538 $moreforfilter .= $hookmanager->resPrint;
539} else {
540 $moreforfilter = $hookmanager->resPrint;
541}
542
543if (!empty($moreforfilter)) {
544 print '<div class="liste_titre liste_titre_bydiv centpercent">';
545 print $moreforfilter;
546 print '</div>';
547}
548
549$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
550$htmlofselectarray = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage, getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')); // This also change content of $arrayfields with user setup
551$selectedfields = ($mode != 'kanban' ? $htmlofselectarray : '');
552$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
553
554print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
555print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
556
557
558// Fields title search
559// --------------------------------------------------------------------
560print '<tr class="liste_titre_filter">';
561
562// Action column
563if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
564 print '<td class="liste_titre center maxwidthsearch">';
565 $searchpicto = $form->showFilterButtons('left');
566 print $searchpicto;
567 print '</td>';
568}
569
570foreach ($object->fields as $key => $val) {
571 $searchkey = empty($search[$key]) ? '' : $search[$key];
572 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
573 if ($key == 'status') {
574 $cssforfield .= ($cssforfield ? ' ' : '').'center';
575 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
576 $cssforfield .= ($cssforfield ? ' ' : '').'center';
577 } elseif (in_array($val['type'], array('timestamp'))) {
578 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
579 } 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'])) {
580 $cssforfield .= ($cssforfield ? ' ' : '').'right';
581 }
582 if (!empty($arrayfields['t.'.$key]['checked'])) {
583 print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').($key == 'status' ? ' parentonrightofpage' : '').'">';
584 if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
585 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);
586 } elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
587 print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', $cssforfield.' maxwidth250', 1);
588 } elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
589 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
590 } elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
591 print '<div class="nowrap">';
592 print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
593 print '</div>';
594 print '<div class="nowrap">';
595 print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
596 print '</div>';
597 } elseif ($key == 'lang') {
598 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formadmin.class.php';
599 $formadmin = new FormAdmin($db);
600 print $formadmin->select_language($search[$key], 'search_lang', 0, array(), 1, 0, 0, 'minwidth100imp maxwidth125', 2);
601 } else {
602 print '<input type="text" class="flat maxwidth'.($val['type'] == 'integer' ? '50' : '75').'" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
603 }
604 print '</td>';
605 }
606}
607// Extra fields
608include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
609
610// Fields from hook
611$parameters = array('arrayfields' => $arrayfields);
612$reshook = $hookmanager->executeHooks('printFieldListOption', $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 '<td class="liste_titre center maxwidthsearch">';
617 $searchpicto = $form->showFilterButtons();
618 print $searchpicto;
619 print '</td>';
620}
621print '</tr>'."\n";
622
623$totalarray = array();
624$totalarray['nbfield'] = 0;
625
626// Fields title label
627// --------------------------------------------------------------------
628print '<tr class="liste_titre">';
629// Action column
630if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
631 print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
632 $totalarray['nbfield']++;
633}
634foreach ($object->fields as $key => $val) {
635 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
636 if ($key == 'status') {
637 $cssforfield .= ($cssforfield ? ' ' : '').'center';
638 } elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
639 $cssforfield .= ($cssforfield ? ' ' : '').'center';
640 } elseif (in_array($val['type'], array('timestamp'))) {
641 $cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
642 } 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'])) {
643 $cssforfield .= ($cssforfield ? ' ' : '').'right';
644 }
645 $cssforfield = preg_replace('/small\s*/', '', $cssforfield); // the 'small' css must not be used for the title label
646 if (!empty($arrayfields['t.'.$key]['checked'])) {
647 if ($key == "fk_product") {
648 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";
649 } else {
650 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";
651 }
652 $totalarray['nbfield']++;
653 }
654}
655// Extra fields
656include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
657// Hook fields
658$parameters = array('arrayfields' => $arrayfields, 'param' => $param, 'sortfield' => $sortfield, 'sortorder' => $sortorder, 'totalarray' => &$totalarray);
659$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
660print $hookmanager->resPrint;
661// Action column
662if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
663 print getTitleFieldOfList(($mode != 'kanban' ? $selectedfields : ''), 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
664 $totalarray['nbfield']++;
665}
666print '</tr>'."\n";
667
668
669// Detect if we need a fetch on each output line
670$needToFetchEachLine = 0;
671if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
672 foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
673 if (!is_null($val) && preg_match('/\$object/', $val)) {
674 $needToFetchEachLine++; // There is at least one compute field that use $object
675 }
676 }
677}
678
679
680// Loop on record
681// --------------------------------------------------------------------
682$i = 0;
683$savnbfield = $totalarray['nbfield'];
684$totalarray = array();
685$totalarray['nbfield'] = 0;
686$imaxinloop = ($limit ? min($num, $limit) : $num);
687while ($i < $imaxinloop) {
688 $obj = $db->fetch_object($resql);
689 if (empty($obj)) {
690 break; // Should not happen
691 }
692
693 // Store properties in $object
694 $object->setVarsFromFetchObj($obj);
695
696 // mode view kanban
697 if ($mode == 'kanban') {
698 if ($i == 0) {
699 print '<tr class="trkanban"><td colspan="'.$savnbfield.'">';
700 print '<div class="box-flex-container kanban">';
701 }
702
703 // TODO Use a cache for product
704 if (!empty($obj->fk_product)) {
705 $prod = new Product($db);
706 $prod->fetch($obj->fk_product);
707 } else {
708 $prod = null;
709 }
710
711 // Output Kanban
712 $selected = -1;
713 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
714 $selected = 0;
715 if (in_array($object->id, $arrayofselected)) {
716 $selected = 1;
717 }
718 }
719 print $object->getKanbanView('', array('prod' => $prod, 'selected' => $selected));
720 if ($i == ($imaxinloop - 1)) {
721 print '</div>';
722 print '</td></tr>';
723 }
724 } else {
725 // Show line of result
726 $j = 0;
727 print '<tr data-rowid="'.$object->id.'" class="oddeven">';
728 // Action column
729 if (getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
730 print '<td class="nowrap center">';
731 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
732 $selected = 0;
733 if (in_array($object->id, $arrayofselected)) {
734 $selected = 1;
735 }
736 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
737 }
738 print '</td>';
739 if (!$i) {
740 $totalarray['nbfield']++;
741 }
742 }
743 // Fields
744 foreach ($object->fields as $key => $val) {
745 $cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
746 if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
747 $cssforfield .= ($cssforfield ? ' ' : '').'center';
748 } elseif ($key == 'status') {
749 $cssforfield .= ($cssforfield ? ' ' : '').'center';
750 }
751
752 if ($key == 'ref') {
753 $cssforfield .= ($cssforfield ? ' ' : '').'nowraponall';
754 }
755
756 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'])) {
757 $cssforfield .= ($cssforfield ? ' ' : '').'right';
758 }
759
760 if (!empty($arrayfields['t.'.$key]['checked'])) {
761 print '<td'.($cssforfield ? ' class="'.$cssforfield.(preg_match('/tdoverflow/', $cssforfield) ? ' classfortooltip' : '').'"' : '');
762 if (preg_match('/tdoverflow/', $cssforfield) && !in_array($val['type'], array('ip', 'url')) && !is_numeric($object->$key)) {
763 print ' title="'.dolPrintHTMLForAttribute((string) $object->$key).'"';
764 }
765 print '>';
766 if ($key == 'status') {
767 print $object->getLibStatut(5);
768 } elseif ($key == 'rowid') {
769 print $object->showOutputField($val, $key, (string) $object->id, '');
770 } else {
771 if ($val['type'] == 'html') {
772 print '<div class="small lineheightsmall twolinesmax-normallineheight">';
773 }
774 print $object->showOutputField($val, $key, (string) $object->$key, '');
775 if ($val['type'] == 'html') {
776 print '</div>';
777 }
778 }
779 print '</td>';
780 if (!$i) {
781 $totalarray['nbfield']++;
782 }
783 if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
784 if (!$i) {
785 $totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
786 }
787 if (!isset($totalarray['val'])) {
788 $totalarray['val'] = array();
789 }
790 if (!isset($totalarray['val']['t.'.$key])) {
791 $totalarray['val']['t.'.$key] = 0;
792 }
793 $totalarray['val']['t.'.$key] += $object->$key;
794 }
795 }
796 }
797 // Extra fields
798 include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
799 // Fields from hook
800 $parameters = array('arrayfields' => $arrayfields, 'object' => $object, 'obj' => $obj, 'i' => $i, 'totalarray' => &$totalarray);
801 $reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
802 print $hookmanager->resPrint;
803 // Action column
804 if (!getDolGlobalString('MAIN_CHECKBOX_LEFT_COLUMN')) {
805 print '<td class="nowrap center">';
806 if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
807 $selected = 0;
808 if (in_array($object->id, $arrayofselected)) {
809 $selected = 1;
810 }
811 print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
812 }
813 print '</td>';
814 if (!$i) {
815 $totalarray['nbfield']++;
816 }
817 }
818
819 print '</tr>'."\n";
820 }
821
822 $i++;
823}
824
825// Show total line
826include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
827
828
829// If no record found
830if ($num == 0) {
831 $colspan = 1;
832 foreach ($arrayfields as $key => $val) {
833 if (!empty($val['checked'])) {
834 $colspan++;
835 }
836 }
837 print '<tr><td colspan="'.$colspan.'"><span class="opacitymedium">'.$langs->trans("NoRecordFound").'</span></td></tr>';
838}
839
840
841$db->free($resql);
842
843$parameters = array('arrayfields' => $arrayfields, 'sql' => $sql);
844$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object, $action); // Note that $action and $object may have been modified by hook
845print $hookmanager->resPrint;
846
847print '</table>'."\n";
848print '</div>'."\n";
849
850print '</form>'."\n";
851
852
853if (in_array('builddoc', array_keys($arrayofmassactions)) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
854 $hidegeneratedfilelistifempty = 1;
855 if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
856 $hidegeneratedfilelistifempty = 0;
857 }
858
859 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
860 $formfile = new FormFile($db);
861
862 // Show list of available documents
863 $urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
864 $urlsource .= str_replace('&amp;', '&', $param);
865
866 $filedir = $diroutputmassaction;
867 $genallowed = $permissiontoread;
868 $delallowed = $permissiontoadd;
869
870 print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
871}
872
873// End of page
874llxFooter();
875$db->close();
$id
Support class for third parties, contacts, members, users or resources.
Definition account.php:48
if( $user->socid > 0) if(! $user->hasRight('accounting', 'chartofaccount')) $object
Definition card.php:67
$totalarray
Definition export.php:1206
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
Class for BOM.
Definition bom.class.php:42
Class to manage standard extra fields.
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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
GETPOSTDATE($prefix, $hourTime='', $gm='auto', $saverestore='')
Helper function that combines values of a dolibarr DatePicker (such as Form\selectDate) for year,...
print_barre_liste($title, $page, $file, $options='', $sortfield='', $sortorder='', $morehtmlcenter='', $num=-1, $totalnboflines='', $picto='generic', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limit=-1, $selectlimitsuffix=0, $hidenavigation=0, $pagenavastextinput=0, $morehtmlrightbeforearrow='')
Print a title with navigation controls for pagination.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2, $allowothertags=array())
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.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
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 a 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...
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
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.