dolibarr 20.0.0
setup.php
Go to the documentation of this file.
1<?php
2/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
3 * Copyright (C) 2022 Alice Adminson <aadminson@example.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 * Copyright (C) 2024 Frédéric France <frederic.france@free.fr>
6 *
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
19 */
20
27// Load Dolibarr environment
28require '../../main.inc.php';
29
30global $langs, $user;
31
32// Libraries
33require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
34require_once '../lib/bookcal.lib.php';
35//require_once "../class/myclass.class.php";
36
37// Translations
38$langs->loadLangs(array("admin", "agenda"));
39
40// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
41$hookmanager->initHooks(array('bookcalsetup', 'globalsetup'));
42
43// Access control
44if (!$user->admin) {
46}
47
48// Parameters
49$action = GETPOST('action', 'aZ09');
50$backtopage = GETPOST('backtopage', 'alpha');
51$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
52
53$value = GETPOST('value', 'alpha');
54$label = GETPOST('label', 'alpha');
55$scandir = GETPOST('scan_dir', 'alpha');
56$type = 'myobject';
57
58
59$error = 0;
60$setupnotempty = 0;
61
62// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
63$useFormSetup = 1;
64
65if (!class_exists('FormSetup')) {
66 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
67}
68
69$formSetup = new FormSetup($db);
70
71
72// Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC
73$item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC');
74$item->defaultFieldValue = 'MyBigCompany public interface for Bookcal';
75
76$setupnotempty = + count($formSetup->items);
77
78
79$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
80
81
82/*
83 * Actions
84 */
85
86// For retrocompatibility Dolibarr < 15.0
87if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) {
88 $formSetup->saveConfFromPost();
89}
90
91include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
92
93if ($action == 'updateMask') {
94 $maskconst = GETPOST('maskconst', 'aZ09');
95 $maskvalue = GETPOST('maskvalue', 'alpha');
96
97 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
98 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
99 if (!($res > 0)) {
100 $error++;
101 }
102 }
103
104 if (!$error) {
105 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
106 } else {
107 setEventMessages($langs->trans("Error"), null, 'errors');
108 }
109} elseif ($action == 'setmod') {
110 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
111 $tmpobjectkey = GETPOST('object', 'aZ09');
112 if (!empty($tmpobjectkey)) {
113 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey)."_ADDON";
114 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
115 }
116} elseif ($action == 'set') {
117 // Activate a model
118 $ret = addDocumentModel($value, $type, $label, $scandir);
119} elseif ($action == 'del') {
120 $ret = delDocumentModel($value, $type);
121 if ($ret > 0) {
122 $tmpobjectkey = GETPOST('object', 'aZ09');
123 if (!empty($tmpobjectkey)) {
124 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
125 if (getDolGlobalString($constforval) == "$value") {
126 dolibarr_del_const($db, $constforval, $conf->entity);
127 }
128 }
129 }
130} elseif ($action == 'setdoc') {
131 // Set or unset default model
132 $tmpobjectkey = GETPOST('object', 'aZ09');
133 if (!empty($tmpobjectkey)) {
134 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
135 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
136 // The constant that was read before the new set
137 // We therefore requires a variable to have a coherent view
138 $conf->global->$constforval = $value;
139 }
140
141 // We disable/enable the document template (into llx_document_model table)
142 $ret = delDocumentModel($value, $type);
143 if ($ret > 0) {
144 $ret = addDocumentModel($value, $type, $label, $scandir);
145 }
146 }
147} elseif ($action == 'unsetdoc') {
148 $tmpobjectkey = GETPOST('object', 'aZ09');
149 if (!empty($tmpobjectkey)) {
150 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
151 dolibarr_del_const($db, $constforval, $conf->entity);
152 }
153}
154
155
156
157/*
158 * View
159 */
160
161$form = new Form($db);
162
163$help_url = '';
164$page_name = "BookCalSetup";
165
166llxHeader('', $langs->trans($page_name), $help_url);
167
168// Subheader
169$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
170
171print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
172
173// Configuration header
175print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "fa-calendar-check");
176
177// Setup page goes here
178//echo '<span class="opacitymedium">'.$langs->trans("BookCalSetupPage").'</span><br><br>';
179
180if ($action == 'edit') {
181 print $formSetup->generateOutput(true);
182 print '<br>';
183} elseif (!empty($formSetup->items)) {
184 print $formSetup->generateOutput();
185 print '<div class="tabsAction">';
186 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
187 print '</div>';
188} else {
189 print '<br>'.$langs->trans("NothingToSetup");
190}
191
192
193if (empty($setupnotempty)) {
194 print '<br>'.$langs->trans("NothingToSetup");
195}
196
197// Page end
198print dol_get_fiche_end();
199
200llxFooter();
201$db->close();
addDocumentModel($name, $type, $label='', $description='')
Add document model used by doc generator.
dolibarr_set_const($db, $name, $value, $type='chaine', $visible=0, $note='', $entity=1)
Insert a parameter (key,value) into database (delete old key then insert it again).
dolibarr_del_const($db, $name, $entity=1)
Delete a constant.
delDocumentModel($name, $type)
Delete document model used by doc generator.
versioncompare($versionarray1, $versionarray2)
Compare 2 versions (stored into 2 arrays).
Definition admin.lib.php:68
if(!defined('NOREQUIRESOC')) if(!defined( 'NOREQUIRETRAN')) if(!defined('NOTOKENRENEWAL')) if(!defined( 'NOREQUIREMENU')) if(!defined('NOREQUIREHTML')) if(!defined( 'NOREQUIREAJAX')) llxHeader()
Empty header.
Definition wrapper.php:55
llxFooter()
Empty footer.
Definition wrapper.php:69
bookcalAdminPrepareHead()
Prepare admin pages header.
Class to manage generation of HTML components Only common components must be here.
This class help you create setup render.
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.
newToken()
Return the value of token currently saved into session with name 'newtoken'.
GETPOST($paramname, $check='alphanohtml', $method=0, $filter=null, $options=null, $noreplace=0)
Return value of a param into GET or POST supervariable.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.