dolibarr 21.0.0-beta
myobject_extrafields.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2001-2002 Rodolphe Quiedeville <rodolphe@quiedeville.org>
3 * Copyright (C) 2003 Jean-Louis Bergamo <jlb@j1b.org>
4 * Copyright (C) 2004-2011 Laurent Destailleur <eldy@users.sourceforge.net>
5 * Copyright (C) 2012 Regis Houssin <regis.houssin@inodbox.com>
6 * Copyright (C) 2014 Florian Henry <florian.henry@open-concept.pro>
7 * Copyright (C) 2015 Jean-François Ferry <jfefe@aternatik.fr>
8 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
9 *
10 * This program is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU General Public License as published by
12 * the Free Software Foundation; either version 3 of the License, or
13 * (at your option) any later version.
14 *
15 * This program is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU General Public License for more details.
19 *
20 * You should have received a copy of the GNU General Public License
21 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 */
23
30// Load Dolibarr environment
31$res = 0;
32// Try main.inc.php into web root known defined into CONTEXT_DOCUMENT_ROOT (not always defined)
33if (!$res && !empty($_SERVER["CONTEXT_DOCUMENT_ROOT"])) {
34 $res = @include $_SERVER["CONTEXT_DOCUMENT_ROOT"]."/main.inc.php";
35}
36// Try main.inc.php into web root detected using web root calculated from SCRIPT_FILENAME
37$tmp = empty($_SERVER['SCRIPT_FILENAME']) ? '' : $_SERVER['SCRIPT_FILENAME'];
38$tmp2 = realpath(__FILE__);
39$i = strlen($tmp) - 1;
40$j = strlen($tmp2) - 1;
41while ($i > 0 && $j > 0 && isset($tmp[$i]) && isset($tmp2[$j]) && $tmp[$i] == $tmp2[$j]) {
42 $i--;
43 $j--;
44}
45if (!$res && $i > 0 && file_exists(substr($tmp, 0, ($i + 1))."/main.inc.php")) {
46 $res = @include substr($tmp, 0, ($i + 1))."/main.inc.php";
47}
48if (!$res && $i > 0 && file_exists(dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php")) {
49 $res = @include dirname(substr($tmp, 0, ($i + 1)))."/main.inc.php";
50}
51// Try main.inc.php using relative path
52if (!$res && file_exists("../../main.inc.php")) {
53 $res = @include "../../main.inc.php";
54}
55if (!$res && file_exists("../../../main.inc.php")) {
56 $res = @include "../../../main.inc.php";
57}
58if (!$res) {
59 die("Include of main fails");
60}
61
62require_once DOL_DOCUMENT_ROOT.'/core/class/extrafields.class.php';
63require_once '../lib/mymodule.lib.php';
64
73// Load translation files required by the page
74$langs->loadLangs(array('mymodule@mymodule', 'admin'));
75
76$extrafields = new ExtraFields($db);
77$form = new Form($db);
78
79// List of supported format
81
82$action = GETPOST('action', 'aZ09');
83$attrname = GETPOST('attrname', 'alpha');
84$elementtype = 'mymodule_myobject'; //Must be the $table_element of the class that manage extrafield
85
86if (!$user->admin) {
88}
89
90
91/*
92 * Actions
93 */
94
95require DOL_DOCUMENT_ROOT.'/core/actions_extrafields.inc.php';
96
97
98
99/*
100 * View
101 */
102
103$textobject = $langs->transnoentitiesnoconv("MyObject");
104
105$help_url = '';
106$page_name = "MyModuleSetup";
107
108llxHeader('', $langs->trans("MyModuleSetup"), $help_url, '', 0, 0, '', '', '', 'mod-mymodule page-admin_extrafields');
109
110
111$linkback = '<a href="'.DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1">'.$langs->trans("BackToModuleList").'</a>';
112print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
113
114
116
117print dol_get_fiche_head($head, 'myobject_extrafields', $langs->trans($page_name), -1, 'mymodule@mymodule');
118
119require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_view.tpl.php';
120
121print dol_get_fiche_end();
122
123
124// Buttons
125if ((float) DOL_VERSION < 17) { // On v17+, the "New Attribute" button is included into tpl. @phpstan-ignore-line
126 if ($action != 'create' && $action != 'edit') {
127 print '<div class="tabsAction">';
128 print '<a class="butAction reposition" href="'.$_SERVER["PHP_SELF"].'?action=create">'.$langs->trans("NewAttribute").'</a>';
129 print "</div>";
130 }
131}
132
133
134/*
135 * Creation of an optional field
136 */
137if ($action == 'create') {
138 print '<br><div id="newattrib"></div>';
139 print load_fiche_titre($langs->trans('NewAttribute'));
140
141 require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_add.tpl.php';
142}
143
144/*
145 * Edition of an optional field
146 */
147if ($action == 'edit' && !empty($attrname)) {
148 print "<br>";
149 print load_fiche_titre($langs->trans("FieldEdition", $attrname));
150
151 require DOL_DOCUMENT_ROOT.'/core/tpl/admin_extrafields_edit.tpl.php';
152}
153
154// End of page
155llxFooter();
156$db->close();
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:71
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
dol_get_fiche_head($links=array(), $active='', $title='', $notab=0, $picto='', $pictoisfullpath=0, $morehtmlright='', $morecss='', $limittoshow=0, $moretabssuffix='', $dragdropfile=0)
Show tabs of a record.
dol_get_fiche_end($notab=0)
Return tab footer of a card.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
mymoduleAdminPrepareHead()
Prepare admin pages header.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.