dolibarr 21.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) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
4 * Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
5 *
6 * This program is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <https://www.gnu.org/licenses/>.
18 */
19
26// Load Dolibarr environment
27require '../../main.inc.php';
28require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php';
30
31// Translations
32$langs->loadLangs(array('admin', 'companies', 'members', 'datapolicy'));
33
34// Parameters
35$action = GETPOST('action', 'aZ09');
36$backtopage = GETPOST('backtopage', 'alpha');
37
38if (empty($action)) {
39 $action = 'edit';
40}
41
42$arrayofparameters = array();
43$arrayofparameters['ThirdParty'] = array(
44 'DATAPOLICY_TIERS_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
45 'DATAPOLICY_TIERS_PROSPECT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
46 'DATAPOLICY_TIERS_PROSPECT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
47 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
48 'DATAPOLICY_TIERS_FOURNISSEUR' => array('css' => 'minwidth200', 'picto' => img_picto('', 'supplier', 'class="pictofixedwidth"')),
49);
50if (getDolGlobalString('DATAPOLICY_USE_SPECIFIC_DELAY_FOR_CONTACT')) {
51 $arrayofparameters['Contact'] = array(
52 'DATAPOLICY_CONTACT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
53 'DATAPOLICY_CONTACT_PROSPECT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
54 'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
55 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
56 'DATAPOLICY_CONTACT_FOURNISSEUR' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
57 );
58}
59if (isModEnabled('member')) {
60 $arrayofparameters['Member'] = array(
61 'DATAPOLICY_ADHERENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'member', 'class="pictofixedwidth"')),
62 );
63}
64
65$valTab = array(
66 '' => $langs->trans('Never'),
67 '6' => $langs->trans('NB_MONTHS', 6),
68 '12' => $langs->trans('ONE_YEAR'),
69 '24' => $langs->trans('NB_YEARS', 2),
70 '36' => $langs->trans('NB_YEARS', 3),
71 '48' => $langs->trans('NB_YEARS', 4),
72 '60' => $langs->trans('NB_YEARS', 5),
73 '120' => $langs->trans('NB_YEARS', 10),
74 '180' => $langs->trans('NB_YEARS', 15),
75 '240' => $langs->trans('NB_YEARS', 20),
76);
77
78// Security
79if (!isModEnabled("datapolicy")) {
81}
82if (!$user->admin) {
84}
85
86
87'@phan-var-force array<string,array<string,array{type?:string,css?:string,picto?:string}>> $arrayofparameters';
88
89/*
90 * Actions
91 */
92
93$nbdone = 0;
94
95foreach ($arrayofparameters as $title => $tab) {
96 foreach ($tab as $key => $val) {
97 // Modify constant only if key was posted (avoid resetting key to the null value)
98 if (GETPOSTISSET($key)) {
99 if (preg_match('/category:/', (string) $val['type'])) {
100 if (GETPOSTINT($key) == '-1') {
101 $val_const = '';
102 } else {
103 $val_const = GETPOSTINT($key);
104 }
105 } else {
106 $val_const = GETPOST($key, 'alpha');
107 }
108
109 $result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity);
110 if ($result < 0) {
111 $error++;
112 break;
113 } else {
114 $nbdone++;
115 }
116 }
117 }
118}
119
120if ($nbdone) {
121 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
122}
123if ($action == 'update') {
124 $action = 'edit';
125}
126
127
128/*
129 * View
130 */
131
132$page_name = "datapolicySetup";
133llxHeader('', $langs->trans($page_name));
134
135// Subheader
136$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
137
138print load_fiche_titre($langs->trans($page_name), $linkback, 'generic');
139
140// Configuration header
142print dol_get_fiche_head($head, 'settings', '', -1, '');
143
144// Setup page goes here
145print '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span><br>';
146// print $form->textwithpicto('', $langs->trans('DATAPOLICY_Tooltip_SETUP'));
147print '<br>';
148
149
150if ($action == 'edit') {
151 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
152 print '<input type="hidden" name="token" value="'.newToken().'">';
153 print '<input type="hidden" name="action" value="update">';
154
155 print '<table class="noborder centpercent">';
156 //print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td></td></tr>';
157
158 foreach ($arrayofparameters as $title => $tab) {
159 print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
160 foreach ($tab as $key => $val) {
161 print '<tr class="oddeven"><td>';
162 print $val['picto'];
163 print $langs->trans($key);
164 print '</td><td>';
165 print '<select name="'.$key.'" id="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'">';
166 foreach ($valTab as $key1 => $val1) {
167 print '<option value="'.$key1.'" '.(getDolGlobalString($key) == $key1 ? 'selected="selected"' : '').'>';
168 print $val1;
169 print '</option>';
170 }
171 print '</select>';
172 print ajax_combobox($key);
173 print '</td></tr>';
174 }
175 }
176
177 print '</table>';
178
179 print $form->buttonsSaveCancel("Save", '');
180
181 print '</form>';
182 print '<br>';
183} else {
184 print '<table class="noborder centpercent">';
185 //print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td></td></tr>';
186
187 foreach ($arrayofparameters as $title => $tab) {
188 print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
189 foreach ($tab as $key => $val) {
190 print '<tr class="oddeven"><td>';
191 print $val['picto'];
192 print $langs->trans($key);
193 print '</td><td>'.(getDolGlobalString($key) == '' ? '<span class="opacitymedium">'.$valTab[''].'</span>' : $valTab[getDolGlobalString($key)]).'</td></tr>';
194 }
195 }
196
197 print '</table>';
198
199 print '<div class="tabsAction">';
200 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
201 print '</div>';
202}
203
204
205// Page end
206print dol_get_fiche_end();
207
208llxFooter();
209$db->close();
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).
ajax_combobox($htmlname, $events=array(), $minLengthToAutocomplete=0, $forcefocus=0, $widthTypeOfAutocomplete='resolve', $idforemptyvalue='-1', $morecss='')
Convert a html select field into an ajax combobox.
Definition ajax.lib.php:457
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:70
datapolicyAdminPrepareHead()
Prepare admin pages header.
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.
img_picto($titlealt, $picto, $moreatt='', $pictoisfullpath=0, $srconly=0, $notitle=0, $alt='', $morecss='', $marginleftonlyshort=2)
Show picto whatever it's its name (generic function)
GETPOSTINT($paramname, $method=0)
Return the value of a $_GET or $_POST supervariable, converted into integer.
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.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.