2011-06-22 16:24:20 +00:00
|
|
|
<?php
|
2026-08-11 14:38:26 +00:00
|
|
|
/* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
|
2011-06-22 16:24:20 +00:00
|
|
|
*
|
|
|
|
|
* 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
|
2013-01-16 14:36:08 +00:00
|
|
|
* the Free Software Foundation; either version 3 of the License, or
|
2011-06-22 16:24:20 +00:00
|
|
|
* (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/>.
|
2011-06-22 16:24:20 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
/**
|
2026-08-11 14:38:26 +00:00
|
|
|
* \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.
|
2011-06-22 16:24:20 +00:00
|
|
|
*/
|
|
|
|
|
|
2022-09-07 18:08:59 +00:00
|
|
|
// Load Dolibarr environment
|
2026-08-11 14:38:26 +00:00
|
|
|
require '../main.inc.php';
|
2012-08-22 21:11:24 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
|
2026-08-11 14:38:26 +00:00
|
|
|
require_once DOL_DOCUMENT_ROOT.'/core/lib/admin_extrafields.lib.php';
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2024-11-04 22:53:20 +00:00
|
|
|
/**
|
|
|
|
|
* @var Conf $conf
|
|
|
|
|
* @var DoliDB $db
|
|
|
|
|
* @var HookManager $hookmanager
|
|
|
|
|
* @var Translate $langs
|
|
|
|
|
* @var User $user
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-11 14:38:26 +00:00
|
|
|
if (!$user->admin) {
|
|
|
|
|
accessforbidden();
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-12 04:50:12 +00:00
|
|
|
// 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'));
|
|
|
|
|
|
2026-08-11 14:38:26 +00:00
|
|
|
$elementtype = GETPOST('elementtype', 'aZ09');
|
|
|
|
|
|
|
|
|
|
$extrafieldsadminmap = getExtrafieldsAdminMap();
|
|
|
|
|
if ($elementtype === '' || !array_key_exists($elementtype, $extrafieldsadminmap)) {
|
|
|
|
|
accessforbidden('Bad or missing value for parameter elementtype');
|
|
|
|
|
}
|
|
|
|
|
$pagedef = $extrafieldsadminmap[$elementtype];
|
|
|
|
|
|
2026-08-12 03:18:53 +00:00
|
|
|
// $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;
|
|
|
|
|
|
2026-08-11 18:28:59 +00:00
|
|
|
// 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'];
|
|
|
|
|
}
|
|
|
|
|
|
2026-08-11 14:38:26 +00:00
|
|
|
$langs->loadLangs($pagedef['langs']);
|
2011-06-22 16:24:20 +00:00
|
|
|
|
|
|
|
|
$extrafields = new ExtraFields($db);
|
|
|
|
|
$form = new Form($db);
|
|
|
|
|
|
|
|
|
|
// List of supported format
|
2024-05-03 00:39:35 +00:00
|
|
|
$type2label = ExtraFields::getListOfTypesLabels();
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2020-09-16 17:39:50 +00:00
|
|
|
$action = GETPOST('action', 'aZ09');
|
2020-04-10 08:59:32 +00:00
|
|
|
$attrname = GETPOST('attrname', 'alpha');
|
2011-06-22 16:24:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* Actions
|
|
|
|
|
*/
|
|
|
|
|
|
2013-09-23 11:22:28 +00:00
|
|
|
require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
|
2011-06-22 16:24:20 +00:00
|
|
|
|
|
|
|
|
|
|
|
|
|
/*
|
|
|
|
|
* View
|
|
|
|
|
*/
|
|
|
|
|
|
2026-08-12 03:18:53 +00:00
|
|
|
$title = $pagedef['title'] instanceof Closure ? $pagedef['title']() : $langs->trans($pagedef['title']);
|
|
|
|
|
$headlabel = $pagedef['headlabel'] instanceof Closure ? $pagedef['headlabel']() : $langs->trans($pagedef['headlabel']);
|
2026-08-11 14:59:51 +00:00
|
|
|
if (isset($pagedef['textobject'])) {
|
2026-08-12 03:18:53 +00:00
|
|
|
$textobject = $pagedef['textobject'] instanceof Closure ? $pagedef['textobject']() : $langs->transnoentitiesnoconv($pagedef['textobject']);
|
2026-08-11 14:59:51 +00:00
|
|
|
} else {
|
|
|
|
|
$textobject = $headlabel;
|
|
|
|
|
}
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2026-08-11 14:38:26 +00:00
|
|
|
$help_url = $pagedef['helpurl'];
|
2026-08-12 03:18:53 +00:00
|
|
|
llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-extrafields');
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2025-10-17 00:31:07 +00:00
|
|
|
$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>';
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2026-08-11 14:38:26 +00:00
|
|
|
print load_fiche_titre($title, $linkback, 'title_setup');
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2026-08-12 05:43:16 +00:00
|
|
|
dol_include_once($pagedef['headfile']);
|
2026-08-11 14:38:26 +00:00
|
|
|
$head = call_user_func($pagedef['headfunction']);
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2026-08-11 14:59:51 +00:00
|
|
|
print dol_get_fiche_head($head, $pagedef['tabid'], $headlabel, -1, $pagedef['headpicto']);
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2015-02-28 19:14:26 +00:00
|
|
|
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2020-10-27 17:19:31 +00:00
|
|
|
print dol_get_fiche_end();
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2012-09-22 18:27:06 +00:00
|
|
|
|
2021-03-20 09:00:24 +00:00
|
|
|
// Creation of an optional field
|
2021-02-26 20:17:52 +00:00
|
|
|
if ($action == 'create') {
|
2020-03-23 14:54:02 +00:00
|
|
|
print '<br><div id="newattrib"></div>';
|
|
|
|
|
print load_fiche_titre($langs->trans('NewAttribute'));
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2020-03-23 14:54:02 +00:00
|
|
|
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
|
2011-06-22 16:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2021-03-20 09:00:24 +00:00
|
|
|
// Edition of an optional field
|
2021-02-26 20:17:52 +00:00
|
|
|
if ($action == 'edit' && !empty($attrname)) {
|
2020-03-23 14:54:02 +00:00
|
|
|
print '<br><div id="editattrib"></div>';
|
|
|
|
|
print load_fiche_titre($langs->trans("FieldEdition", $attrname));
|
2011-06-22 16:24:20 +00:00
|
|
|
|
2020-03-23 14:54:02 +00:00
|
|
|
require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
|
2011-06-22 16:24:20 +00:00
|
|
|
}
|
|
|
|
|
|
2018-08-05 15:21:59 +00:00
|
|
|
// End of page
|
2011-08-27 14:24:16 +00:00
|
|
|
llxFooter();
|
2012-02-01 19:44:06 +00:00
|
|
|
$db->close();
|