dolibarr/htdocs/bom/bom_list.php

748 lines
28 KiB
PHP
Raw Normal View History

2019-02-26 19:27:04 +01:00
<?php
/* Copyright (C) 2007-2017 Laurent Destailleur <eldy@users.sourceforge.net>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 3 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
2019-09-23 21:55:30 +02:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
2019-02-26 19:27:04 +01:00
*/
/**
2019-03-06 18:25:02 +01:00
* \file htdocs/bom/bom_list.php
2019-02-26 19:27:04 +01:00
* \ingroup bom
* \brief List page for bom
*/
2019-10-16 03:17:53 +02:00
2019-02-26 19:27:04 +01:00
// Load Dolibarr environment
2019-03-06 18:25:02 +01:00
require '../main.inc.php';
2019-02-26 19:27:04 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formcompany.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/date.lib.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/company.lib.php';
2019-03-06 18:25:02 +01:00
require_once DOL_DOCUMENT_ROOT.'/bom/class/bom.class.php';
2019-02-26 19:27:04 +01:00
// Load translation files required by the page
2019-03-04 12:46:07 +01:00
$langs->loadLangs(array("mrp", "other"));
2019-02-26 19:27:04 +01:00
$action = GETPOST('action', 'aZ09') ?GETPOST('action', 'aZ09') : 'view'; // The action 'add', 'create', 'edit', 'update', 'view', ...
$massaction = GETPOST('massaction', 'alpha'); // The bulk action (combo box choice into lists)
$show_files = GETPOST('show_files', 'int'); // Show files area generated by bulk actions ?
$confirm = GETPOST('confirm', 'alpha'); // Result of a confirmation
$cancel = GETPOST('cancel', 'alpha'); // We click on a Cancel button
$toselect = GETPOST('toselect', 'array'); // Array of ids of elements selected into a list
$contextpage = GETPOST('contextpage', 'aZ') ?GETPOST('contextpage', 'aZ') : 'bomlist'; // To manage different context of search
$backtopage = GETPOST('backtopage', 'alpha'); // Go back to a dedicated page
$optioncss = GETPOST('optioncss', 'aZ'); // Option for the css output (always '' except when 'print')
$id = GETPOST('id', 'int');
2019-02-26 19:27:04 +01:00
// Load variable for pagination
$limit = GETPOST('limit', 'int') ?GETPOST('limit', 'int') : $conf->liste_limit;
2020-09-18 17:13:01 +02:00
$sortfield = GETPOST('sortfield', 'aZ09comma');
2020-09-17 14:31:25 +02:00
$sortorder = GETPOST('sortorder', 'aZ09comma');
$page = GETPOSTISSET('pageplusone') ? (GETPOST('pageplusone') - 1) : GETPOST("page", 'int');
2021-02-23 17:51:46 +01:00
if (empty($page) || $page == -1 || GETPOST('button_search', 'alpha') || GETPOST('button_removefilter', 'alpha') || (empty($toselect) && $massaction === '0')) {
$page = 0;
} // If $page is not defined, or '' or -1 or if we click on clear filters or if we select empty mass action
2019-02-26 19:27:04 +01:00
$offset = $limit * $page;
$pageprev = $page - 1;
$pagenext = $page + 1;
//if (! $sortfield) $sortfield="p.date_fin";
//if (! $sortorder) $sortorder="DESC";
// Initialize technical objects
2019-03-06 19:00:12 +01:00
$object = new BOM($db);
2019-02-26 19:27:04 +01:00
$extrafields = new ExtraFields($db);
$diroutputmassaction = $conf->bom->dir_output.'/temp/massgeneration/'.$user->id;
$hookmanager->initHooks(array('bomlist')); // Note that conf->hooks_modules contains array
2019-09-28 10:55:09 +02:00
2019-02-26 19:27:04 +01:00
// Fetch optionals attributes and labels
$extrafields->fetch_name_optionals_label($object->table_element);
2019-09-28 10:55:09 +02:00
2019-02-26 21:48:21 +01:00
$search_array_options = $extrafields->getOptionalsFromPost($object->table_element, '', 'search_');
2019-02-26 19:27:04 +01:00
// Default sort order (if not yet defined by previous GETPOST)
2021-02-23 17:51:46 +01:00
if (!$sortfield) {
$sortfield = "t.".key($object->fields); // Set here default search field. By default 1st field in definition.
}
if (!$sortorder) {
$sortorder = "ASC";
}
2019-02-26 19:27:04 +01:00
// Initialize array of search criterias
$search_all = GETPOST("search_all", 'alpha');
$search = array();
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
if (GETPOST('search_'.$key, 'alpha') !== '') {
$search[$key] = GETPOST('search_'.$key, 'alpha');
}
2021-07-04 20:08:34 +02:00
if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
$search[$key.'_dtstart'] = dol_mktime(0, 0, 0, GETPOST('search_'.$key.'_dtstartmonth', 'int'), GETPOST('search_'.$key.'_dtstartday', 'int'), GETPOST('search_'.$key.'_dtstartyear', 'int'));
$search[$key.'_dtend'] = dol_mktime(23, 59, 59, GETPOST('search_'.$key.'_dtendmonth', 'int'), GETPOST('search_'.$key.'_dtendday', 'int'), GETPOST('search_'.$key.'_dtendyear', 'int'));
}
2019-02-26 19:27:04 +01:00
}
// List of fields to search into when doing a "search in all"
$fieldstosearchall = array();
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
2021-06-14 01:55:58 +02:00
if (!empty($val['searchall'])) {
2021-02-23 17:51:46 +01:00
$fieldstosearchall['t.'.$key] = $val['label'];
}
2019-02-26 19:27:04 +01:00
}
2021-06-24 09:54:30 +02:00
// Definition of array of fields for columns
$arrayfields = array();
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
2019-02-26 19:27:04 +01:00
// If $val['visible']==0, then we never show the field
2021-02-23 17:51:46 +01:00
if (!empty($val['visible'])) {
2021-06-24 09:54:30 +02:00
$visible = (int) dol_eval($val['visible'], 1);
$arrayfields['t.'.$key] = array(
'label'=>$val['label'],
'checked'=>(($visible < 0) ? 0 : 1),
'enabled'=>($visible != 3 && dol_eval($val['enabled'], 1, 1, '1')),
2021-06-24 09:54:30 +02:00
'position'=>$val['position'],
'help'=> isset($val['help']) ? $val['help'] : ''
2021-06-24 09:54:30 +02:00
);
2021-02-23 17:51:46 +01:00
}
2019-02-26 19:27:04 +01:00
}
// Extra fields
2021-06-24 09:54:30 +02:00
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_array_fields.tpl.php';
2019-02-26 19:27:04 +01:00
$object->fields = dol_sort_array($object->fields, 'position');
$arrayfields = dol_sort_array($arrayfields, 'position');
2019-11-04 15:45:50 +01:00
$permissiontoread = $user->rights->bom->read;
$permissiontoadd = $user->rights->bom->write;
$permissiontodelete = $user->rights->bom->delete;
2019-02-26 19:27:04 +01:00
2021-03-19 14:25:59 +01:00
// Security check
if ($user->socid > 0) {
// Protection if external user
accessforbidden();
}
$result = restrictedArea($user, 'bom');
2019-02-26 19:27:04 +01:00
/*
* Actions
*/
2021-02-23 17:51:46 +01:00
if (GETPOST('cancel', 'alpha')) {
2021-07-04 20:08:34 +02:00
$action = 'list';
$massaction = '';
2021-02-23 17:51:46 +01:00
}
if (!GETPOST('confirmmassaction', 'alpha') && $massaction != 'presend' && $massaction != 'confirm_presend') {
$massaction = '';
}
2019-02-26 19:27:04 +01:00
$parameters = array();
$reshook = $hookmanager->executeHooks('doActions', $parameters, $object, $action); // Note that $action and $object may have been modified by some hooks
2021-02-23 17:51:46 +01:00
if ($reshook < 0) {
setEventMessages($hookmanager->error, $hookmanager->errors, 'errors');
}
2019-02-26 19:27:04 +01:00
2021-02-23 17:51:46 +01:00
if (empty($reshook)) {
2019-02-26 19:27:04 +01:00
// Selection of new fields
include DOL_DOCUMENT_ROOT.'/core/actions_changeselectedfields.inc.php';
// Purge search criteria
2021-02-23 17:51:46 +01:00
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
foreach ($object->fields as $key => $val) {
$search[$key] = '';
2021-07-04 20:08:34 +02:00
if (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
$search[$key.'_dtstart'] = '';
$search[$key.'_dtend'] = '';
}
2019-02-26 19:27:04 +01:00
}
2021-06-24 09:54:30 +02:00
$toselect = array();
$search_array_options = array();
2019-02-26 19:27:04 +01:00
}
2019-02-26 21:48:21 +01:00
if (GETPOST('button_removefilter_x', 'alpha') || GETPOST('button_removefilter.x', 'alpha') || GETPOST('button_removefilter', 'alpha')
2021-02-23 17:51:46 +01:00
|| GETPOST('button_search_x', 'alpha') || GETPOST('button_search.x', 'alpha') || GETPOST('button_search', 'alpha')) {
$massaction = ''; // Protection to avoid mass action if we force a new search during a mass action confirmation
2019-02-26 19:27:04 +01:00
}
// Mass actions
$objectclass = 'BOM';
$objectlabel = 'BillOfMaterials';
$permissiontoread = $user->rights->bom->read;
$permissiontodelete = $user->rights->bom->delete;
2019-02-26 19:27:04 +01:00
$uploaddir = $conf->bom->dir_output;
include DOL_DOCUMENT_ROOT.'/core/actions_massactions.inc.php';
2019-11-04 15:45:50 +01:00
// Validate records
2021-02-23 17:51:46 +01:00
if (!$error && $massaction == 'disable' && $permissiontoadd) {
$objecttmp = new $objectclass($db);
2019-11-04 15:45:50 +01:00
2021-02-23 17:51:46 +01:00
if (!$error) {
2019-11-04 15:45:50 +01:00
$db->begin();
$nbok = 0;
2021-02-23 17:51:46 +01:00
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
2021-02-23 17:51:46 +01:00
if ($result > 0) {
if ($objecttmp->status != $objecttmp::STATUS_VALIDATED) {
2019-11-04 15:45:50 +01:00
$langs->load("errors");
2019-11-05 18:06:33 +01:00
setEventMessages($langs->trans("ErrorObjectMustHaveStatusActiveToBeDisabled", $objecttmp->ref), null, 'errors');
2019-11-04 15:45:50 +01:00
$error++;
break;
}
// Can be 'cancel()' or 'close()'
$result = $objecttmp->cancel($user);
2021-02-23 17:51:46 +01:00
if ($result < 0) {
2019-11-04 15:45:50 +01:00
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
2021-02-23 17:51:46 +01:00
} else {
$nbok++;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-04 15:45:50 +01:00
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
2021-02-23 17:51:46 +01:00
if (!$error) {
if ($nbok > 1) {
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
} else {
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
}
2019-11-04 15:45:50 +01:00
$db->commit();
2020-05-21 15:05:19 +02:00
} else {
2019-11-04 15:45:50 +01:00
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
}
2019-11-05 18:06:33 +01:00
// Validate records
2021-02-23 17:51:46 +01:00
if (!$error && $massaction == 'enable' && $permissiontoadd) {
$objecttmp = new $objectclass($db);
2019-11-05 18:06:33 +01:00
2021-02-23 17:51:46 +01:00
if (!$error) {
2019-11-05 18:06:33 +01:00
$db->begin();
$nbok = 0;
2021-02-23 17:51:46 +01:00
foreach ($toselect as $toselectid) {
$result = $objecttmp->fetch($toselectid);
2021-02-23 17:51:46 +01:00
if ($result > 0) {
if ($objecttmp->status != $objecttmp::STATUS_DRAFT && $objecttmp->status != $objecttmp::STATUS_CANCELED) {
2019-11-05 18:06:33 +01:00
$langs->load("errors");
setEventMessages($langs->trans("ErrorObjectMustHaveStatusDraftOrDisabledToBeActivated", $objecttmp->ref), null, 'errors');
$error++;
break;
}
// Can be 'cancel()' or 'close()'
$result = $objecttmp->validate($user);
2021-02-23 17:51:46 +01:00
if ($result < 0) {
2019-11-05 18:06:33 +01:00
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
2021-02-23 17:51:46 +01:00
} else {
$nbok++;
}
2020-05-21 15:05:19 +02:00
} else {
2019-11-05 18:06:33 +01:00
setEventMessages($objecttmp->error, $objecttmp->errors, 'errors');
$error++;
break;
}
}
2021-02-23 17:51:46 +01:00
if (!$error) {
if ($nbok > 1) {
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
} else {
setEventMessages($langs->trans("RecordsModified", $nbok), null, 'mesgs');
}
2019-11-05 18:06:33 +01:00
$db->commit();
2020-05-21 15:05:19 +02:00
} else {
2019-11-05 18:06:33 +01:00
$db->rollback();
}
//var_dump($listofobjectthirdparties);exit;
}
}
2019-11-04 15:45:50 +01:00
}
2019-02-26 19:27:04 +01:00
/*
* View
*/
$form = new Form($db);
2019-02-26 19:27:04 +01:00
$now = dol_now();
2019-02-26 19:27:04 +01:00
$help_url = 'EN:Module_BOM';
2019-03-04 12:46:07 +01:00
$title = $langs->trans('ListOfBOMs');
2021-07-04 20:08:34 +02:00
$morejs = array();
$morecss = array();
2019-02-26 19:27:04 +01:00
// Build and execute select
// --------------------------------------------------------------------
$sql = 'SELECT ';
2021-07-04 20:08:34 +02:00
$sql .= $object->getFieldList('t');
2019-02-26 19:27:04 +01:00
// Add fields from extrafields
if (!empty($extrafields->attributes[$object->table_element]['label'])) {
2021-02-23 17:51:46 +01:00
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
2021-08-27 22:42:04 +02:00
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? ", ef.".$key." as options_".$key.' ' : '');
2021-02-23 17:51:46 +01:00
}
2019-10-16 03:17:53 +02:00
}
2019-02-26 19:27:04 +01:00
// Add fields from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSelect', $parameters, $object); // Note that $action and $object may have been modified by hook
2020-01-09 22:14:39 +01:00
$sql .= preg_replace('/^,/', '', $hookmanager->resPrint);
$sql = preg_replace('/,\s*$/', '', $sql);
$sql .= " FROM ".MAIN_DB_PREFIX.$object->table_element." as t";
2021-07-04 20:08:34 +02:00
if (isset($extrafields->attributes[$object->table_element]['label']) && is_array($extrafields->attributes[$object->table_element]['label']) && count($extrafields->attributes[$object->table_element]['label'])) {
2021-02-23 17:51:46 +01:00
$sql .= " LEFT JOIN ".MAIN_DB_PREFIX.$object->table_element."_extrafields as ef on (t.rowid = ef.fk_object)";
}
2021-07-04 20:08:34 +02:00
// Add table from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListFrom', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
2021-02-23 17:51:46 +01:00
if ($object->ismultientitymanaged == 1) {
$sql .= " WHERE t.entity IN (".getEntity($object->element).")";
} else {
$sql .= " WHERE 1 = 1";
}
foreach ($search as $key => $val) {
2021-07-04 20:08:34 +02:00
if (array_key_exists($key, $object->fields)) {
if ($key == 'status' && $search[$key] == -1) {
2021-07-06 19:02:03 +02:00
continue;
2021-02-23 17:51:46 +01:00
}
2021-07-04 20:08:34 +02:00
$mode_search = (($object->isInt($object->fields[$key]) || $object->isFloat($object->fields[$key])) ? 1 : 0);
if ((strpos($object->fields[$key]['type'], 'integer:') === 0) || (strpos($object->fields[$key]['type'], 'sellist:') === 0) || !empty($object->fields[$key]['arrayofkeyval'])) {
if ($search[$key] == '-1' || ($search[$key] === '0' && (empty($object->fields[$key]['arrayofkeyval']) || !array_key_exists('0', $object->fields[$key]['arrayofkeyval'])))) {
2021-07-04 20:08:34 +02:00
$search[$key] = '';
}
$mode_search = 2;
}
if ($search[$key] != '') {
$sql .= natural_search($key, $search[$key], (($key == 'status') ? 2 : $mode_search));
}
} else {
if (preg_match('/(_dtstart|_dtend)$/', $key) && $search[$key] != '') {
$columnName=preg_replace('/(_dtstart|_dtend)$/', '', $key);
if (preg_match('/^(date|timestamp|datetime)/', $object->fields[$columnName]['type'])) {
if (preg_match('/_dtstart$/', $key)) {
$sql .= " AND t." . $columnName . " >= '" . $db->idate($search[$key]) . "'";
}
if (preg_match('/_dtend$/', $key)) {
$sql .= " AND t." . $columnName . " <= '" . $db->idate($search[$key]) . "'";
}
}
}
2021-02-23 17:51:46 +01:00
}
2019-02-26 19:27:04 +01:00
}
2020-10-16 13:30:20 +02:00
2021-02-23 17:51:46 +01:00
if ($search_all) {
$sql .= natural_search(array_keys($fieldstosearchall), $search_all);
}
2021-07-04 20:08:34 +02:00
//$sql.= dolSqlDateFilter("t.field", $search_xxxday, $search_xxxmonth, $search_xxxyear);
2019-02-26 19:27:04 +01:00
// Add where from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_sql.tpl.php';
// Add where from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListWhere', $parameters, $object); // Note that $action and $object may have been modified by hook
$sql .= $hookmanager->resPrint;
2019-02-26 19:27:04 +01:00
/* If a group by is required
2021-07-04 20:08:34 +02:00
$sql.= " GROUP BY ";
2019-02-26 19:27:04 +01:00
foreach($object->fields as $key => $val)
{
2021-08-27 22:42:04 +02:00
$sql .= "t.".$key.", ";
2019-02-26 19:27:04 +01:00
}
// Add fields from extrafields
if (! empty($extrafields->attributes[$object->table_element]['label'])) {
2021-06-24 09:54:30 +02:00
foreach ($extrafields->attributes[$object->table_element]['label'] as $key => $val) {
$sql .= ($extrafields->attributes[$object->table_element]['type'][$key] != 'separate' ? "ef.".$key.', ' : '');
}
2019-10-16 03:17:53 +02:00
}
2019-02-26 19:27:04 +01:00
// Add where from hooks
$parameters=array();
2021-07-04 20:08:34 +02:00
$reshook=$hookmanager->executeHooks('printFieldListGroupBy', $parameters, $object); // Note that $action and $object may have been modified by hook
2019-02-26 19:27:04 +01:00
$sql.=$hookmanager->resPrint;
2020-01-09 22:14:39 +01:00
$sql=preg_replace('/,\s*$/','', $sql);
2019-02-26 19:27:04 +01:00
*/
$sql .= $db->order($sortfield, $sortorder);
2019-02-26 19:27:04 +01:00
// Count total nb of records
$nbtotalofrecords = '';
2021-02-23 17:51:46 +01:00
if (empty($conf->global->MAIN_DISABLE_FULL_SCANLIST)) {
2019-02-26 19:27:04 +01:00
$resql = $db->query($sql);
$nbtotalofrecords = $db->num_rows($resql);
2021-02-23 17:51:46 +01:00
if (($page * $limit) > $nbtotalofrecords) { // if total of record found is smaller than page * limit, goto and load page 0
2019-02-26 19:27:04 +01:00
$page = 0;
$offset = 0;
}
}
// if total of record found is smaller than limit, no need to do paging and to restart another select with limits set.
2021-02-23 17:51:46 +01:00
if (is_numeric($nbtotalofrecords) && ($limit > $nbtotalofrecords || empty($limit))) {
2019-02-26 19:27:04 +01:00
$num = $nbtotalofrecords;
2020-05-21 15:05:19 +02:00
} else {
2021-02-23 17:51:46 +01:00
if ($limit) {
$sql .= $db->plimit($limit + 1, $offset);
}
2019-02-26 19:27:04 +01:00
$resql = $db->query($sql);
2021-02-23 17:51:46 +01:00
if (!$resql) {
2019-02-26 19:27:04 +01:00
dol_print_error($db);
exit;
}
$num = $db->num_rows($resql);
}
// Direct jump if only one record found
2021-02-23 17:51:46 +01:00
if ($num == 1 && !empty($conf->global->MAIN_SEARCH_DIRECT_OPEN_IF_ONLY_ONE) && $search_all && !$page) {
2019-02-26 19:27:04 +01:00
$obj = $db->fetch_object($resql);
$id = $obj->rowid;
2019-10-16 03:17:53 +02:00
header("Location: ".DOL_URL_ROOT.'/bom/bom_card.php?id='.$id);
2019-02-26 19:27:04 +01:00
exit;
}
// Output page
// --------------------------------------------------------------------
2021-07-04 20:08:34 +02:00
llxHeader('', $title, $help_url, '', 0, 0, $morejs, $morecss, '', '');
2019-02-26 19:27:04 +01:00
$arrayofselected = is_array($toselect) ? $toselect : array();
2019-02-26 19:27:04 +01:00
$param = '';
2021-02-23 17:51:46 +01:00
if (!empty($contextpage) && $contextpage != $_SERVER["PHP_SELF"]) {
$param .= '&contextpage='.urlencode($contextpage);
}
if ($limit > 0 && $limit != $conf->liste_limit) {
$param .= '&limit='.urlencode($limit);
}
foreach ($search as $key => $val) {
if (is_array($search[$key]) && count($search[$key])) {
foreach ($search[$key] as $skey) {
$param .= '&search_'.$key.'[]='.urlencode($skey);
}
} else {
$param .= '&search_'.$key.'='.urlencode($search[$key]);
}
}
if ($optioncss != '') {
$param .= '&optioncss='.urlencode($optioncss);
2019-02-26 19:27:04 +01:00
}
// Add $param from extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_param.tpl.php';
2021-07-04 20:08:34 +02:00
// Add $param from hooks
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldListSearchParam', $parameters, $object); // Note that $action and $object may have been modified by hook
$param .= $hookmanager->resPrint;
2019-02-26 19:27:04 +01:00
// List of mass actions available
$arrayofmassactions = array(
2021-04-14 14:45:55 +02:00
//'presend'=>img_picto('', 'email', 'class="pictofixedwidth"').$langs->trans("SendByMail"),
2021-04-14 12:28:01 +02:00
'enable'=>img_picto('', 'check', 'class="pictofixedwidth"').$langs->trans("Enable"),
'disable'=>img_picto('', 'close_title', 'class="pictofixedwidth"').$langs->trans("Disable"),
2019-02-26 19:27:04 +01:00
);
2021-02-23 17:51:46 +01:00
if ($permissiontodelete) {
2021-04-14 12:28:01 +02:00
$arrayofmassactions['predelete'] = img_picto('', 'delete', 'class="pictofixedwidth"').$langs->trans("Delete");
2021-02-23 17:51:46 +01:00
}
if (GETPOST('nomassaction', 'int') || in_array($massaction, array('presend', 'predelete'))) {
$arrayofmassactions = array();
}
$massactionbutton = $form->selectMassAction('', $arrayofmassactions);
2019-02-26 19:27:04 +01:00
2021-07-04 20:08:34 +02:00
print '<form method="POST" id="searchFormList" action="'.$_SERVER["PHP_SELF"].'">'."\n";
2021-02-23 17:51:46 +01:00
if ($optioncss != '') {
print '<input type="hidden" name="optioncss" value="'.$optioncss.'">';
}
print '<input type="hidden" name="token" value="'.newToken().'">';
2019-02-26 19:27:04 +01:00
print '<input type="hidden" name="formfilteraction" id="formfilteraction" value="list">';
print '<input type="hidden" name="action" value="list">';
print '<input type="hidden" name="sortfield" value="'.$sortfield.'">';
print '<input type="hidden" name="sortorder" value="'.$sortorder.'">';
2021-07-04 20:08:34 +02:00
print '<input type="hidden" name="page" value="'.$page.'">';
2019-02-26 19:27:04 +01:00
print '<input type="hidden" name="contextpage" value="'.$contextpage.'">';
2019-10-16 03:17:53 +02:00
$newcardbutton = dolGetButtonTitle($langs->trans('New'), '', 'fa fa-plus-circle', DOL_URL_ROOT.'/bom/bom_card.php?action=create&backtopage='.urlencode($_SERVER['PHP_SELF']), '', $user->rights->bom->write);
2019-02-26 19:27:04 +01:00
2021-07-04 20:08:34 +02:00
print_barre_liste($title, $page, $_SERVER["PHP_SELF"], $param, $sortfield, $sortorder, $massactionbutton, $num, $nbtotalofrecords, 'object_'.$object->picto, 0, $newcardbutton, '', $limit, 0, 0, 1);
2019-02-26 19:27:04 +01:00
// Add code for pre mass action (confirmation or email presend form)
$topicmail = "SendBillOfMaterialsRef";
$modelmail = "bom";
$objecttmp = new BOM($db);
2020-11-08 14:39:20 +01:00
$trackid = 'bom'.$object->id;
2019-02-26 19:27:04 +01:00
include DOL_DOCUMENT_ROOT.'/core/tpl/massactions_pre.tpl.php';
2021-02-23 17:51:46 +01:00
if ($search_all) {
foreach ($fieldstosearchall as $key => $val) {
$fieldstosearchall[$key] = $langs->trans($val);
}
print '<div class="divsearchfieldfilter">'.$langs->trans("FilterOnInto", $search_all).join(', ', $fieldstosearchall).'</div>';
2019-02-26 19:27:04 +01:00
}
$moreforfilter = '';
/*$moreforfilter.='<div class="divsearchfield">';
$moreforfilter.= $langs->trans('MyFilter') . ': <input type="text" name="search_myfield" value="'.dol_escape_htmltag($search_myfield).'">';
$moreforfilter.= '</div>';*/
$parameters = array();
$reshook = $hookmanager->executeHooks('printFieldPreListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
2021-02-23 17:51:46 +01:00
if (empty($reshook)) {
$moreforfilter .= $hookmanager->resPrint;
} else {
$moreforfilter = $hookmanager->resPrint;
}
2019-02-26 19:27:04 +01:00
2021-02-23 17:51:46 +01:00
if (!empty($moreforfilter)) {
2019-02-26 19:27:04 +01:00
print '<div class="liste_titre liste_titre_bydiv centpercent">';
print $moreforfilter;
print '</div>';
}
$varpage = empty($contextpage) ? $_SERVER["PHP_SELF"] : $contextpage;
$selectedfields = $form->multiSelectArrayWithCheckbox('selectedfields', $arrayfields, $varpage); // This also change content of $arrayfields
$selectedfields .= (count($arrayofmassactions) ? $form->showCheckAddButtons('checkforselect', 1) : '');
2019-02-26 19:27:04 +01:00
2020-12-03 10:13:13 +01:00
print '<div class="div-table-responsive">';
2020-03-27 11:15:38 +01:00
print '<table class="tagtable nobottomiftotal liste'.($moreforfilter ? " listwithfilterbefore" : "").'">'."\n";
2019-02-26 19:27:04 +01:00
// Fields title search
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
2021-05-06 21:11:39 +02:00
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
2021-02-23 17:51:46 +01:00
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
2021-05-06 21:11:39 +02:00
} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
2021-02-23 17:51:46 +01:00
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
if (!empty($arrayfields['t.'.$key]['checked'])) {
print '<td class="liste_titre'.($cssforfield ? ' '.$cssforfield : '').'">';
2021-02-23 17:51:46 +01:00
if (!empty($val['arrayofkeyval']) && is_array($val['arrayofkeyval'])) {
2021-07-04 20:08:34 +02:00
print $form->selectarray('search_'.$key, $val['arrayofkeyval'], (isset($search[$key]) ? $search[$key] : ''), $val['notnull'], 0, 0, '', 1, 0, 0, '', 'maxwidth100', 1);
2021-06-24 09:54:30 +02:00
} elseif ((strpos($val['type'], 'integer:') === 0) || (strpos($val['type'], 'sellist:') === 0)) {
2021-07-04 20:08:34 +02:00
print $object->showInputField($val, $key, (isset($search[$key]) ? $search[$key] : ''), '', '', 'search_', 'maxwidth125', 1);
} elseif (!preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
print '<input type="text" class="flat maxwidth75" name="search_'.$key.'" value="'.dol_escape_htmltag(isset($search[$key]) ? $search[$key] : '').'">';
} elseif (preg_match('/^(date|timestamp|datetime)/', $val['type'])) {
print '<div class="nowrap">';
print $form->selectDate($search[$key.'_dtstart'] ? $search[$key.'_dtstart'] : '', "search_".$key."_dtstart", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('From'));
print '</div>';
print '<div class="nowrap">';
print $form->selectDate($search[$key.'_dtend'] ? $search[$key.'_dtend'] : '', "search_".$key."_dtend", 0, 0, 1, '', 1, 0, 0, '', '', '', '', 1, '', $langs->trans('to'));
print '</div>';
2021-02-23 17:51:46 +01:00
}
2019-05-22 19:21:55 +02:00
print '</td>';
}
2019-02-26 19:27:04 +01:00
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_input.tpl.php';
// Fields from hook
$parameters = array('arrayfields'=>$arrayfields);
$reshook = $hookmanager->executeHooks('printFieldListOption', $parameters, $object); // Note that $action and $object may have been modified by hook
2019-02-26 19:27:04 +01:00
print $hookmanager->resPrint;
// Action column
2019-05-19 13:51:47 +02:00
print '<td class="liste_titre maxwidthsearch">';
$searchpicto = $form->showFilterButtons();
2019-02-26 19:27:04 +01:00
print $searchpicto;
print '</td>';
print '</tr>'."\n";
// Fields title label
// --------------------------------------------------------------------
print '<tr class="liste_titre">';
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
2021-02-23 17:51:46 +01:00
if ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
2021-05-06 21:11:39 +02:00
} elseif (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && $val['label'] != 'TechnicalID' && empty($val['arrayofkeyval'])) {
2021-02-23 17:51:46 +01:00
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
if (!empty($arrayfields['t.'.$key]['checked'])) {
print getTitleFieldOfList($arrayfields['t.'.$key]['label'], 0, $_SERVER['PHP_SELF'], 't.'.$key, '', $param, ($cssforfield ? 'class="'.$cssforfield.'"' : ''), $sortfield, $sortorder, ($cssforfield ? $cssforfield.' ' : ''))."\n";
2019-02-26 19:27:04 +01:00
}
}
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_search_title.tpl.php';
// Hook fields
$parameters = array('arrayfields'=>$arrayfields, 'param'=>$param, 'sortfield'=>$sortfield, 'sortorder'=>$sortorder);
$reshook = $hookmanager->executeHooks('printFieldListTitle', $parameters, $object); // Note that $action and $object may have been modified by hook
2019-02-26 19:27:04 +01:00
print $hookmanager->resPrint;
// Action column
2019-10-16 03:17:53 +02:00
print getTitleFieldOfList($selectedfields, 0, $_SERVER["PHP_SELF"], '', '', '', '', $sortfield, $sortorder, 'center maxwidthsearch ')."\n";
2019-02-26 19:27:04 +01:00
print '</tr>'."\n";
// Detect if we need a fetch on each output line
$needToFetchEachLine = 0;
2021-07-04 20:08:34 +02:00
if (isset($extrafields->attributes[$object->table_element]['computed']) && is_array($extrafields->attributes[$object->table_element]['computed']) && count($extrafields->attributes[$object->table_element]['computed']) > 0) {
2021-02-23 17:51:46 +01:00
foreach ($extrafields->attributes[$object->table_element]['computed'] as $key => $val) {
if (preg_match('/\$object/', $val)) {
$needToFetchEachLine++; // There is at least one compute field that use $object
}
2019-02-26 19:27:04 +01:00
}
}
// Loop on record
// --------------------------------------------------------------------
$i = 0;
$totalarray = array();
2021-07-04 20:08:34 +02:00
$totalarray['nbfield'] = 0;
2021-02-23 17:51:46 +01:00
while ($i < ($limit ? min($num, $limit) : $num)) {
2019-02-26 19:27:04 +01:00
$obj = $db->fetch_object($resql);
2021-02-23 17:51:46 +01:00
if (empty($obj)) {
break; // Should not happen
}
2019-02-26 19:27:04 +01:00
// Store properties in $object
2020-01-09 22:14:39 +01:00
$object->setVarsFromFetchObj($obj);
2019-02-26 19:27:04 +01:00
// Show here line of result
print '<tr class="oddeven">';
2021-02-23 17:51:46 +01:00
foreach ($object->fields as $key => $val) {
$cssforfield = (empty($val['csslist']) ? (empty($val['css']) ? '' : $val['css']) : $val['csslist']);
2021-02-23 17:51:46 +01:00
if (in_array($val['type'], array('date', 'datetime', 'timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
} elseif ($key == 'status') {
$cssforfield .= ($cssforfield ? ' ' : '').'center';
}
2021-02-23 17:51:46 +01:00
if (in_array($val['type'], array('timestamp'))) {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
} elseif ($key == 'ref') {
$cssforfield .= ($cssforfield ? ' ' : '').'nowrap';
}
2021-07-04 20:08:34 +02:00
if (in_array($val['type'], array('double(24,8)', 'double(6,3)', 'integer', 'real', 'price')) && !in_array($key, array('rowid', 'status')) && empty($val['arrayofkeyval'])) {
2021-02-23 17:51:46 +01:00
$cssforfield .= ($cssforfield ? ' ' : '').'right';
}
2021-02-23 17:51:46 +01:00
if (!empty($arrayfields['t.'.$key]['checked'])) {
2019-05-22 19:21:55 +02:00
print '<td'.($cssforfield ? ' class="'.$cssforfield.'"' : '').'>';
2021-02-23 17:51:46 +01:00
if ($key == 'status') {
print $object->getLibStatut(5);
2021-07-04 20:08:34 +02:00
} elseif ($key == 'rowid') {
print $object->showOutputField($val, $key, $object->id, '');
2021-02-23 17:51:46 +01:00
} else {
print $object->showOutputField($val, $key, $object->$key, '');
}
2019-02-26 19:27:04 +01:00
print '</td>';
2021-02-23 17:51:46 +01:00
if (!$i) {
$totalarray['nbfield']++;
}
2021-10-19 16:26:43 +02:00
if (!empty($val['isameasure']) && $val['isameasure'] == 1) {
2021-02-23 17:51:46 +01:00
if (!$i) {
$totalarray['pos'][$totalarray['nbfield']] = 't.'.$key;
}
2021-06-14 01:55:58 +02:00
if (!isset($totalarray['val'])) {
$totalarray['val'] = array();
}
if (!isset($totalarray['val']['t.'.$key])) {
$totalarray['val']['t.'.$key] = 0;
}
2020-01-09 22:14:39 +01:00
$totalarray['val']['t.'.$key] += $object->$key;
2019-02-26 19:27:04 +01:00
}
}
}
2019-02-26 19:27:04 +01:00
// Extra fields
include DOL_DOCUMENT_ROOT.'/core/tpl/extrafields_list_print_fields.tpl.php';
// Fields from hook
2020-01-09 22:14:39 +01:00
$parameters = array('arrayfields'=>$arrayfields, 'object'=>$object, 'obj'=>$obj, 'i'=>$i, 'totalarray'=>&$totalarray);
$reshook = $hookmanager->executeHooks('printFieldListValue', $parameters, $object); // Note that $action and $object may have been modified by hook
2019-02-26 19:27:04 +01:00
print $hookmanager->resPrint;
// Action column
2019-10-16 03:17:53 +02:00
print '<td class="nowrap center">';
2021-02-23 17:51:46 +01:00
if ($massactionbutton || $massaction) { // If we are in select mode (massactionbutton defined) or if we have already selected and sent an action ($massaction) defined
$selected = 0;
2021-02-23 17:51:46 +01:00
if (in_array($object->id, $arrayofselected)) {
$selected = 1;
}
2020-01-09 22:14:39 +01:00
print '<input id="cb'.$object->id.'" class="flat checkforselect" type="checkbox" name="toselect[]" value="'.$object->id.'"'.($selected ? ' checked="checked"' : '').'>';
2019-02-26 19:27:04 +01:00
}
print '</td>';
2021-02-23 17:51:46 +01:00
if (!$i) {
$totalarray['nbfield']++;
}
2019-02-26 19:27:04 +01:00
2020-01-09 22:14:39 +01:00
print '</tr>'."\n";
2019-02-26 19:27:04 +01:00
$i++;
}
// Show total line
2019-11-05 12:47:38 +01:00
include DOL_DOCUMENT_ROOT.'/core/tpl/list_print_total.tpl.php';
2019-02-26 19:27:04 +01:00
// If no record found
2021-02-23 17:51:46 +01:00
if ($num == 0) {
$colspan = 1;
2021-02-23 17:51:46 +01:00
foreach ($arrayfields as $key => $val) {
if (!empty($val['checked'])) {
$colspan++;
}
}
2019-02-26 19:27:04 +01:00
print '<tr><td colspan="'.$colspan.'" class="opacitymedium">'.$langs->trans("NoRecordFound").'</td></tr>';
}
$db->free($resql);
$parameters = array('arrayfields'=>$arrayfields, 'sql'=>$sql);
$reshook = $hookmanager->executeHooks('printFieldListFooter', $parameters, $object); // Note that $action and $object may have been modified by hook
2019-02-26 19:27:04 +01:00
print $hookmanager->resPrint;
print '</table>'."\n";
print '</div>'."\n";
print '</form>'."\n";
2021-02-23 17:51:46 +01:00
if (in_array('builddoc', $arrayofmassactions) && ($nbtotalofrecords === '' || $nbtotalofrecords)) {
$hidegeneratedfilelistifempty = 1;
2021-02-23 17:51:46 +01:00
if ($massaction == 'builddoc' || $action == 'remove_file' || $show_files) {
$hidegeneratedfilelistifempty = 0;
}
2019-02-26 19:27:04 +01:00
require_once DOL_DOCUMENT_ROOT.'/core/class/html.formfile.class.php';
$formfile = new FormFile($db);
// Show list of available documents
$urlsource = $_SERVER['PHP_SELF'].'?sortfield='.$sortfield.'&sortorder='.$sortorder;
$urlsource .= str_replace('&amp;', '&', $param);
2019-02-26 19:27:04 +01:00
$filedir = $diroutputmassaction;
2020-01-09 22:14:39 +01:00
$genallowed = $permissiontoread;
$delallowed = $permissiontoadd;
2019-02-26 19:27:04 +01:00
2019-02-26 21:48:21 +01:00
print $formfile->showdocuments('massfilesarea_bom', '', $filedir, $urlsource, 0, $delallowed, '', 1, 1, 0, 48, 1, $param, $title, '', '', '', null, $hidegeneratedfilelistifempty);
2019-02-26 19:27:04 +01:00
}
// End of page
llxFooter();
$db->close();