dolibarr 19.0.3
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 *
5 * This program is free software: you can redistribute it and/or modify
6 * it under the terms of the GNU General Public License as published by
7 * the Free Software Foundation, either version 3 of the License, or
8 * (at your option) any later version.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <https://www.gnu.org/licenses/>.
17 */
18
25// Load Dolibarr environment
26require '../../main.inc.php';
27
28global $langs, $user;
29
30// Libraries
31require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
32require_once '../lib/bookcal.lib.php';
33//require_once "../class/myclass.class.php";
34
35// Translations
36$langs->loadLangs(array("admin", "agenda"));
37
38// Initialize technical object to manage hooks of page. Note that conf->hooks_modules contains array of hook context
39$hookmanager->initHooks(array('bookcalsetup', 'globalsetup'));
40
41// Access control
42if (!$user->admin) {
44}
45
46// Parameters
47$action = GETPOST('action', 'aZ09');
48$backtopage = GETPOST('backtopage', 'alpha');
49$modulepart = GETPOST('modulepart', 'aZ09'); // Used by actions_setmoduleoptions.inc.php
50
51$value = GETPOST('value', 'alpha');
52$label = GETPOST('label', 'alpha');
53$scandir = GETPOST('scan_dir', 'alpha');
54$type = 'myobject';
55
56
57$error = 0;
58$setupnotempty = 0;
59
60// Set this to 1 to use the factory to manage constants. Warning, the generated module will be compatible with version v15+ only
61$useFormSetup = 1;
62
63if (!class_exists('FormSetup')) {
64 require_once DOL_DOCUMENT_ROOT.'/core/class/html.formsetup.class.php';
65}
66
67$formSetup = new FormSetup($db);
68
69
70// Setup conf BOOKCAL_PUBLIC_INTERFACE_TOPIC
71$item = $formSetup->newItem('BOOKCAL_PUBLIC_INTERFACE_TOPIC');
72$item->defaultFieldValue = 'MyBigCompany public interface for Bookcal';
73/*// Setup conf BOOKCAL_MYPARAM8
74$item = $formSetup->newItem('BOOKCAL_MYPARAM8');
75$TField = array(
76 'test01' => $langs->trans('test01'),
77 'test02' => $langs->trans('test02'),
78 'test03' => $langs->trans('test03'),
79 'test04' => $langs->trans('test04'),
80 'test05' => $langs->trans('test05'),
81 'test06' => $langs->trans('test06'),
82);
83$item->setAsMultiSelect($TField);
84$item->helpText = $langs->transnoentities('BOOKCAL_MYPARAM8');
85
86
87// Setup conf BOOKCAL_MYPARAM9
88$formSetup->newItem('BOOKCAL_MYPARAM9')->setAsSelect($TField);
89
90
91// Setup conf BOOKCAL_MYPARAM10
92$item = $formSetup->newItem('BOOKCAL_MYPARAM10');
93$item->setAsColor();
94$item->defaultFieldValue = '#FF0000';
95$item->nameText = $item->getNameText().' more html text ';
96$item->fieldInputOverride = '';
97$item->helpText = $langs->transnoentities('AnHelpMessage');*/
98//$item->fieldValue = '';
99//$item->fieldAttr = array() ; // fields attribute only for compatible fields like input text
100//$item->fieldOverride = false; // set this var to override field output will override $fieldInputOverride and $fieldOutputOverride too
101//$item->fieldInputOverride = false; // set this var to override field input
102//$item->fieldOutputOverride = false; // set this var to override field output
103
104
105$setupnotempty =+ count($formSetup->items);
106
107
108$dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
109
110
111/*
112 * Actions
113 */
114
115// For retrocompatibility Dolibarr < 15.0
116if (versioncompare(explode('.', DOL_VERSION), array(15)) < 0 && $action == 'update' && !empty($user->admin)) {
117 $formSetup->saveConfFromPost();
118}
119
120include DOL_DOCUMENT_ROOT.'/core/actions_setmoduleoptions.inc.php';
121
122if ($action == 'updateMask') {
123 $maskconst = GETPOST('maskconst', 'aZ09');
124 $maskvalue = GETPOST('maskvalue', 'alpha');
125
126 if ($maskconst && preg_match('/_MASK$/', $maskconst)) {
127 $res = dolibarr_set_const($db, $maskconst, $maskvalue, 'chaine', 0, '', $conf->entity);
128 if (!($res > 0)) {
129 $error++;
130 }
131 }
132
133 if (!$error) {
134 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
135 } else {
136 setEventMessages($langs->trans("Error"), null, 'errors');
137 }
138} elseif ($action == 'specimen') {
139 $modele = GETPOST('module', 'alpha');
140 $tmpobjectkey = GETPOST('object');
141
142 $tmpobject = new $tmpobjectkey($db);
143 $tmpobject->initAsSpecimen();
144
145 // Search template files
146 $file = '';
147 $classname = '';
148 $filefound = 0;
149 $dirmodels = array_merge(array('/'), (array) $conf->modules_parts['models']);
150 foreach ($dirmodels as $reldir) {
151 $file = dol_buildpath($reldir."core/modules/bookcal/doc/pdf_".$modele."_".strtolower($tmpobjectkey).".modules.php", 0);
152 if (file_exists($file)) {
153 $filefound = 1;
154 $classname = "pdf_".$modele."_".strtolower($tmpobjectkey);
155 break;
156 }
157 }
158
159 if ($filefound) {
160 require_once $file;
161
162 $module = new $classname($db);
163
164 if ($module->write_file($tmpobject, $langs) > 0) {
165 header("Location: ".DOL_URL_ROOT."/document.php?modulepart=bookcal-".strtolower($tmpobjectkey)."&file=SPECIMEN.pdf");
166 return;
167 } else {
168 setEventMessages($module->error, null, 'errors');
169 dol_syslog($module->error, LOG_ERR);
170 }
171 } else {
172 setEventMessages($langs->trans("ErrorModuleNotFound"), null, 'errors');
173 dol_syslog($langs->trans("ErrorModuleNotFound"), LOG_ERR);
174 }
175} elseif ($action == 'setmod') {
176 // TODO Check if numbering module chosen can be activated by calling method canBeActivated
177 $tmpobjectkey = GETPOST('object');
178 if (!empty($tmpobjectkey)) {
179 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey)."_ADDON";
180 dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity);
181 }
182} elseif ($action == 'set') {
183 // Activate a model
184 $ret = addDocumentModel($value, $type, $label, $scandir);
185} elseif ($action == 'del') {
186 $ret = delDocumentModel($value, $type);
187 if ($ret > 0) {
188 $tmpobjectkey = GETPOST('object');
189 if (!empty($tmpobjectkey)) {
190 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
191 if (getDolGlobalString($constforval) == "$value") {
192 dolibarr_del_const($db, $constforval, $conf->entity);
193 }
194 }
195 }
196} elseif ($action == 'setdoc') {
197 // Set or unset default model
198 $tmpobjectkey = GETPOST('object');
199 if (!empty($tmpobjectkey)) {
200 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
201 if (dolibarr_set_const($db, $constforval, $value, 'chaine', 0, '', $conf->entity)) {
202 // The constant that was read before the new set
203 // We therefore requires a variable to have a coherent view
204 $conf->global->$constforval = $value;
205 }
206
207 // We disable/enable the document template (into llx_document_model table)
208 $ret = delDocumentModel($value, $type);
209 if ($ret > 0) {
210 $ret = addDocumentModel($value, $type, $label, $scandir);
211 }
212 }
213} elseif ($action == 'unsetdoc') {
214 $tmpobjectkey = GETPOST('object');
215 if (!empty($tmpobjectkey)) {
216 $constforval = 'BOOKCAL_'.strtoupper($tmpobjectkey).'_ADDON_PDF';
217 dolibarr_del_const($db, $constforval, $conf->entity);
218 }
219}
220
221
222
223/*
224 * View
225 */
226
227$form = new Form($db);
228
229$help_url = '';
230$page_name = "BookCalSetup";
231
232llxHeader('', $langs->trans($page_name), $help_url);
233
234// Subheader
235$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
236
237print load_fiche_titre($langs->trans($page_name), $linkback, 'title_setup');
238
239// Configuration header
241print dol_get_fiche_head($head, 'settings', $langs->trans($page_name), -1, "fa-calendar-check");
242
243// Setup page goes here
244//echo '<span class="opacitymedium">'.$langs->trans("BookCalSetupPage").'</span><br><br>';
245
246
247if ($action == 'edit') {
248 print $formSetup->generateOutput(true);
249 print '<br>';
250} elseif (!empty($formSetup->items)) {
251 print $formSetup->generateOutput();
252 print '<div class="tabsAction">';
253 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
254 print '</div>';
255} else {
256 print '<br>'.$langs->trans("NothingToSetup");
257}
258
259
260if (empty($setupnotempty)) {
261 print '<br>'.$langs->trans("NothingToSetup");
262}
263
264// Page end
265print dol_get_fiche_end();
266
267llxFooter();
268$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:67
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($titre, $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.
setEventMessages($mesg, $mesgs, $style='mesgs', $messagekey='', $noduplicate=0)
Set event messages in dol_events session object.
dol_buildpath($path, $type=0, $returnemptyifnotfound=0)
Return path of url or filesystem.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
dol_syslog($message, $level=LOG_INFO, $ident=0, $suffixinfilename='', $restricttologhandler='', $logcontext=null)
Write log message into outputs.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.