dolibarr/htdocs/admin/extrafields.php

140 lines
5 KiB
PHP
Raw Permalink Normal View History

<?php
/* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
*
* 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 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
* \file htdocs/admin/extrafields.php
* \ingroup core
* \brief Single, secured admin page to create/edit/delete the
* extrafields of any registered object type. The set of
* accepted object types is a closed whitelist see
* core/lib/admin_extrafields.lib.php.
*/
2022-09-07 18:08:59 +00:00
// Load Dolibarr environment
require '../main.inc.php';
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin_extrafields.lib.php';
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 22:53:20 +00:00
/**
* @var Conf $conf
* @var DoliDB $db
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
if (!$user->admin) {
accessforbidden();
}
// Load modules that declared the 'extrafieldsadmin' or 'globaladmin' hook context, so their
// 'getExtrafieldsAdminMap' hook (fired inside getExtrafieldsAdminMap() below) can contribute
// additional whitelist entries — see the docblock on getExtrafieldsAdminMap() for the shape.
$hookmanager->initHooks(array('extrafieldsadmin', 'globaladmin'));
$elementtype = GETPOST('elementtype', 'aZ09');
$extrafieldsadminmap = getExtrafieldsAdminMap();
if ($elementtype === '' || !array_key_exists($elementtype, $extrafieldsadminmap)) {
accessforbidden('Bad or missing value for parameter elementtype');
}
$pagedef = $extrafieldsadminmap[$elementtype];
// $pagekey is the whitelisted map key from the request, before any override below — it must
// be used for every self-referencing URL/redirect/hidden-field so navigation and post-save
// redirects return to the SAME registry entry the user started on (see $elementtype override
// just below, which can make $elementtype diverge from $pagekey for one registry entry).
$pagekey = $elementtype;
// A registry entry may present a different, developer-authored real elementtype than its
// own map key (e.g. two entries with two different tab-bar presentations both operating on
// the same underlying table). The whitelist check above already gated on the untrusted
// $elementtype from GETPOST(); this override can only ever come from a hardcoded registry
// value, never from user input, so it cannot be used to smuggle an unvalidated elementtype
// into core/actions_extrafields.inc.php / the ExtraFields class below.
if (isset($pagedef['elementtype'])) {
$elementtype = $pagedef['elementtype'];
}
$langs->loadLangs($pagedef['langs']);
$extrafields = new ExtraFields($db);
$form = new Form($db);
// List of supported format
$type2label = ExtraFields::getListOfTypesLabels();
2020-09-16 17:39:50 +00:00
$action = GETPOST('action', 'aZ09');
$attrname = GETPOST('attrname', 'alpha');
/*
* Actions
*/
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
/*
* View
*/
$title = $pagedef['title'] instanceof Closure ? $pagedef['title']() : $langs->trans($pagedef['title']);
$headlabel = $pagedef['headlabel'] instanceof Closure ? $pagedef['headlabel']() : $langs->trans($pagedef['headlabel']);
if (isset($pagedef['textobject'])) {
$textobject = $pagedef['textobject'] instanceof Closure ? $pagedef['textobject']() : $langs->transnoentitiesnoconv($pagedef['textobject']);
} else {
$textobject = $headlabel;
}
$help_url = $pagedef['helpurl'];
llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-extrafields');
$linkback = '<a href="'.dolBuildUrl(DOL_URL_ROOT.'/admin/modules.php', ['restore_lastsearch_values' => 1]).'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
print load_fiche_titre($title, $linkback, 'title_setup');
dol_include_once($pagedef['headfile']);
$head = call_user_func($pagedef['headfunction']);
print dol_get_fiche_head($head, $pagedef['tabid'], $headlabel, -1, $pagedef['headpicto']);
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
2020-10-27 17:19:31 +00:00
print dol_get_fiche_end();
// Creation of an optional field
2021-02-26 20:17:52 +00:00
if ($action == 'create') {
print '<br><div id="newattrib"></div>';
print load_fiche_titre($langs->trans('NewAttribute'));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
}
// Edition of an optional field
2021-02-26 20:17:52 +00:00
if ($action == 'edit' && !empty($attrname)) {
print '<br><div id="editattrib"></div>';
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
}
2018-08-05 15:21:59 +00:00
// End of page
llxFooter();
2012-02-01 19:44:06 +00:00
$db->close();