dolibarr 25.0.0-alpha
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';
36// Libraries
37require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
38require_once '../lib/bookcal.lib.php';
39
40
41
42// Translations
43$langs->loadLangs(array("admin", "agenda"));
44
45// Initialize a technical object to manage hooks of page. Note that conf->hooks_modules contains an array of hook context
46$hookmanager->initHooks(array('bookcalsetup', 'globalsetup'));
47
48// Access control
49if (!$user->admin) {
51}
52
53// Parameters
54$action = GETPOST('action', 'aZ09');
55$backtopage = GETPOST('backtopage', 'alpha');
56$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
57
58$value = GETPOST('value', 'alpha');
59$label = GETPOST('label', 'alpha');
60$scandir = GETPOST('scan_dir', 'alpha');
61$type = 'myobject';
62
63
64$error = 0;
65$setupnotempty = 0;
66
67// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
68$useFormSetup = 1;
69
70if (!class_exists('FormSetup')) {
71 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
72}
73
74$formSetup = new FormSetup($db);
75
76
77// Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC
78$item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC');
79$item->fieldAttr['placeholder'] = 'MyBigCompany public interface for Bookcal';
80$item->cssClass = 'minwidth300';
81
82$setupnotempty = + count($formSetup->items);
83
84
85$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
86
87
88/*
89 * Actions
90 */
91
92// For retrocompatibility Dolibarr < 15.0
93if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) {
94 $formSetup->saveConfFromPost();
95}
96
97include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
98
99if ($action == 'updateMask') {
100 $maskconst = GETPOST('maskconst', 'aZ09');
101 $maskvalue = GETPOST('maskvalue', 'alpha');
102
103 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
104 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
105 if (!($res > 0)) {
106 $error++;
107 }
108 }
109
110 if (!$error) {
111 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
112 } else {
113 setEventMessages($langs->trans("Error"), null, 'errors');
114 }
115} elseif ($action == 'setmod') {
116 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
117 $tmpobjectkey = GETPOST('object', 'aZ09');
118 if (!empty($tmpobjectkey)) {
119 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey)."_ADDON";
120 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
121 }
122} elseif ($action == 'set') {
123 // Activate a model
124 $ret = addDocumentModel($value, $type, $label, $scandir);
125} elseif ($action == 'del') {
126 $ret = delDocumentModel($value, $type);
127 if ($ret > 0) {
128 $tmpobjectkey = GETPOST('object', 'aZ09');
129 if (!empty($tmpobjectkey)) {
130 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
131 if (getDolGlobalString($constforval) == "$value") {
132 dolibarr_del_const($db, $constforval, $conf->entity);
133 }
134 }
135 }
136} elseif ($action == 'setdoc') {
137 // Set or unset default model
138 $tmpobjectkey = GETPOST('object', 'aZ09');
139 if (!empty($tmpobjectkey)) {
140 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
141 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
142 // The constant that was read before the new set
143 // We therefore requires a variable to have a coherent view
144 $conf->global->$constforval = $value;
145 }
146
147 // We disable/enable the document template (into llx_document_model table)
148 $ret = delDocumentModel($value, $type);
149 if ($ret > 0) {
150 $ret = addDocumentModel($value, $type, $label, $scandir);
151 }
152 }
153} elseif ($action == 'unsetdoc') {
154 $tmpobjectkey = GETPOST('object', 'aZ09');
155 if (!empty($tmpobjectkey)) {
156 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
157 dolibarr_del_const($db, $constforval, $conf->entity);
158 }
159}
160
161
162
163/*
164 * View
165 */
166
167$form = new Form($db);
168
169$help_url = '';
170$page_name = "BookCalSetup";
171$title = $langs->trans($page_name);
172
173llxHeader('', $title, $help_url, '', 0, 0, '', '', '', 'mod-bookcal page-admin_setup');
174
175// Subheader
176$linkback = '<a href="'.($backtopage ? $backtopage : 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>';
177
178print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
179
180// Configuration header
182print dol_get_fiche_head($head, 'settings', $title, -1, "fa-calendar-check");
183
184print '<br>';
185
186if ($action == 'edit') {
187 print $formSetup->generateOutput(true);
188 print '<br>';
189} elseif (!empty($formSetup->items)) {
190 print $formSetup->generateOutput();
191 print '<div class="tabsAction">';
192 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
193 print '</div>';
194} else {
195 print '<br>'.$langs->trans("NothingToSetup");
196}
197
198
199if (empty($setupnotempty)) {
200 print '<br>'.$langs->trans("NothingToSetup");
201}
202
203// Page end
204print dol_get_fiche_end();
205
206llxFooter();
207$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), to know if a version (a,b,c) is lower than (x,...
Definition admin.lib.php:79
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
bookcalAdminPrepareHead()
Prepare admin pages header.
if(!isModEnabled('ai')||!getDolGlobalString('AI_ASSISTANT_ENABLED')) global $conf
The main.inc.php has been included so the following variable are now defined:
Class to manage generation of HTML components Only common components must be here.
This class help you create setup render.
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, $nodefault=0)
Return value of a param into GET or POST supervariable.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
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:542
dol_get_fiche_end($notab=0)
Return tab footer of a card.
Definition html.lib.php:740
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.