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