dolibarr 25.0.0-alpha
extrafields.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2026 Frédéric France <frederic.france@free.fr>
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; either version 3 of the License, or
7 * (at your option) any later version.
8 *
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <https://www.gnu.org/licenses/>.
16 */
17
27// Load Dolibarr environment
28require '../main.inc.php';
36require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
37require_once DOL_DOCUMENT_ROOT.'/core/lib/admin_extrafields.lib.php';
38
39if (!$user->admin) {
41}
42
43// Load modules that declared the 'extrafieldsadmin' or 'globaladmin' hook context, so their
44// 'getExtrafieldsAdminMap' hook (fired inside getExtrafieldsAdminMap() below) can contribute
45// additional whitelist entries — see the docblock on getExtrafieldsAdminMap() for the shape.
46$hookmanager->initHooks(array('extrafieldsadmin', 'globaladmin'));
47
48$elementtype = GETPOST('elementtype', 'aZ09');
49
50$extrafieldsadminmap = getExtrafieldsAdminMap();
51if ($elementtype === '' || !array_key_exists($elementtype, $extrafieldsadminmap)) {
52 accessforbidden('Bad or missing value for parameter elementtype');
53}
54$pagedef = $extrafieldsadminmap[$elementtype];
55
56// $pagekey is the whitelisted map key from the request, before any override below — it must
57// be used for every self-referencing URL/redirect/hidden-field so navigation and post-save
58// redirects return to the SAME registry entry the user started on (see $elementtype override
59// just below, which can make $elementtype diverge from $pagekey for one registry entry).
60$pagekey = $elementtype;
61
62// A registry entry may present a different, developer-authored real elementtype than its
63// own map key (e.g. two entries with two different tab-bar presentations both operating on
64// the same underlying table). The whitelist check above already gated on the untrusted
65// $elementtype from GETPOST(); this override can only ever come from a hardcoded registry
66// value, never from user input, so it cannot be used to smuggle an unvalidated elementtype
67// into core/actions_extrafields.inc.php / the ExtraFields class below.
68if (isset($pagedef['elementtype'])) {
69 $elementtype = $pagedef['elementtype'];
70}
71
72$langs->loadLangs($pagedef['langs']);
73
74$extrafields = new ExtraFields($db);
75$form = new Form($db);
76
77// List of supported format
79
80$action = GETPOST('action', 'aZ09');
81$attrname = GETPOST('attrname', 'alpha');
82
83
84/*
85 * Actions
86 */
87
88require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
89
90
91/*
92 * View
93 */
94
95$title = $pagedef['title'] instanceof Closure ? $pagedef['title']() : $langs->trans($pagedef['title']);
96$headlabel = $pagedef['headlabel'] instanceof Closure ? $pagedef['headlabel']() : $langs->trans($pagedef['headlabel']);
97if (isset($pagedef['textobject'])) {
98 $textobject = $pagedef['textobject'] instanceof Closure ? $pagedef['textobject']() : $langs->transnoentitiesnoconv($pagedef['textobject']);
99} else {
100 $textobject = $headlabel;
101}
102
103$help_url = $pagedef['helpurl'];
104llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-admin page-extrafields');
105
106$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>';
107
108print load_fiche_titre($title, $linkback, 'title_setup');
109
110dol_include_once($pagedef['headfile']);
111$head = call_user_func($pagedef['headfunction']);
112
113print dol_get_fiche_head($head, $pagedef['tabid'], $headlabel, -1, $pagedef['headpicto']);
114
115require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
116
117print dol_get_fiche_end();
118
119
120// Creation of an optional field
121if ($action == 'create') {
122 print '<br><div id="newattrib"></div>';
123 print load_fiche_titre($langs->trans('NewAttribute'));
124
125 require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
126}
127
128// Edition of an optional field
129if ($action == 'edit' && !empty($attrname)) {
130 print '<br><div id="editattrib"></div>';
131 print load_fiche_titre($langs->trans("FieldEdition", $attrname));
132
133 require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
134}
135
136// End of page
137llxFooter();
138$db->close();
getExtrafieldsAdminMap()
Return the whitelist of elementtype values accepted by htdocs/admin/extrafields.php,...
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 to manage standard extra fields.
static getListOfTypesLabels()
Return array with all possible types and labels of extrafields.
Class to manage generation of HTML components Only common components must be here.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $db
API class for accounts.
if(!function_exists( 'dol_getprefix')) dol_include_once($relpath, $classname='')
Make an include_once using default root and alternate root if it fails.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0, $nodefault=0)
Return value of a param into GET or POST supervariable.
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)
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0, $morecssdiv='')
Show tabs of a record.
Definition html.lib.php:519
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:717
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='', $morecssonpicto='widthpictotitle')
Load a title with picto.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.