dolibarr 21.0.0-beta
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
30// Libraries
31require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
32require_once '../lib/bookcal.lib.php';
33
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->defaultFieldValue = 'MyBigCompany public interface for Bookcal';
80
81$setupnotempty = + count($formSetup->items);
82
83
84$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
85
86
87/*
88 * Actions
89 */
90
91// For retrocompatibility Dolibarr < 15.0
92if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) {
93 $formSetup->saveConfFromPost();
94}
95
96include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
97
98if ($action == 'updateMask') {
99 $maskconst = GETPOST('maskconst', 'aZ09');
100 $maskvalue = GETPOST('maskvalue', 'alpha');
101
102 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
103 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
104 if (!($res > 0)) {
105 $error++;
106 }
107 }
108
109 if (!$error) {
110 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
111 } else {
112 setEventMessages($langs->trans("Error"), null, 'errors');
113 }
114} elseif ($action == 'setmod') {
115 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
116 $tmpobjectkey = GETPOST('object', 'aZ09');
117 if (!empty($tmpobjectkey)) {
118 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey)."_ADDON";
119 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
120 }
121} elseif ($action == 'set') {
122 // Activate a model
123 $ret = addDocumentModel($value, $type, $label, $scandir);
124} elseif ($action == 'del') {
125 $ret = delDocumentModel($value, $type);
126 if ($ret > 0) {
127 $tmpobjectkey = GETPOST('object', 'aZ09');
128 if (!empty($tmpobjectkey)) {
129 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
130 if (getDolGlobalString($constforval) == "$value") {
131 dolibarr_del_const($db, $constforval, $conf->entity);
132 }
133 }
134 }
135} elseif ($action == 'setdoc') {
136 // Set or unset default model
137 $tmpobjectkey = GETPOST('object', 'aZ09');
138 if (!empty($tmpobjectkey)) {
139 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
140 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
141 // The constant that was read before the new set
142 // We therefore requires a variable to have a coherent view
143 $conf->global->$constforval = $value;
144 }
145
146 // We disable/enable the document template (into llx_document_model table)
147 $ret = delDocumentModel($value, $type);
148 if ($ret > 0) {
149 $ret = addDocumentModel($value, $type, $label, $scandir);
150 }
151 }
152} elseif ($action == 'unsetdoc') {
153 $tmpobjectkey = GETPOST('object', 'aZ09');
154 if (!empty($tmpobjectkey)) {
155 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
156 dolibarr_del_const($db, $constforval, $conf->entity);
157 }
158}
159
160
161
162/*
163 * View
164 */
165
166$form = new Form($db);
167
168$help_url = '';
169$page_name = "BookCalSetup";
170
171llxHeader('', $langs->trans($page_name), $help_url, '', 0, 0, '', '', '', 'mod-bookcal page-admin_setup');
172
173// Subheader
174$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
175
176print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
177
178// Configuration header
180print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "fa-calendar-check");
181
182// Setup page goes here
183//echo '<span class="opacitymedium">'.$langs->trans("BookCalSetupPage").'</span><br><br>';
184
185if ($action == 'edit') {
186 print $formSetup->generateOutput(true);
187 print '<br>';
188} elseif (!empty($formSetup->items)) {
189 print $formSetup->generateOutput();
190 print '<div class="tabsAction">';
191 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
192 print '</div>';
193} else {
194 print '<br>'.$langs->trans("NothingToSetup");
195}
196
197
198if (empty($setupnotempty)) {
199 print '<br>'.$langs->trans("NothingToSetup");
200}
201
202// Page end
203print dol_get_fiche_end();
204
205llxFooter();
206$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:69
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
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.
llxFooter()
Footer empty.
Definition document.php:107
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0, $attop=0)
Set event messages in dol_events session object.
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.
getDolGlobalString($key, $default='')
Return a Dolibarr global constant string value.
global $conf
The following vars must be defined: $type2label $form $conf, $lang, The following vars may also be de...
Definition member.php:79
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.