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) 2018 Nicolas ZABOURI <info@inovea-conseil.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';
29require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
30require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php';
31
41// Translations
42$langs->loadLangs(array('admin', 'companies', 'members', 'datapolicy'));
43
44// Parameters
45$action = GETPOST('action', 'aZ09');
46$backtopage = GETPOST('backtopage', 'alpha');
47
48if (empty($action)) {
49 $action = 'edit';
50}
51
52$arrayofparameters = array();
53// ThirdParty
54$arrayofparameters['ThirdParty'] = array(
55 'DATAPOLICY_TIERS_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
56 'DATAPOLICY_TIERS_PROSPECT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
57 'DATAPOLICY_TIERS_PROSPECT_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
58 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
59 'DATAPOLICY_TIERS_FOURNISSEUR'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'supplier', 'class="pictofixedwidth"')),
60 );
61// Contact
62if (getDolGlobalString('DATAPOLICY_USE_SPECIFIC_DELAY_FOR_CONTACT')) {
63 $arrayofparameters['Contact'] = array(
64 'DATAPOLICY_CONTACT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
65 'DATAPOLICY_CONTACT_PROSPECT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
66 'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
67 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
68 'DATAPOLICY_CONTACT_FOURNISSEUR' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
69 );
70}
71// Member
72if (isModEnabled('member')) {
73 $arrayofparameters['Member'] = array(
74 'DATAPOLICY_ADHERENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'member', 'class="pictofixedwidth"')),
75 );
76}
77
78$valTab = array(
79 '' => $langs->trans('Never'),
80 '6' => $langs->trans('NB_MONTHS', 6),
81 '12' => $langs->trans('ONE_YEAR'),
82 '24' => $langs->trans('NB_YEARS', 2),
83 '36' => $langs->trans('NB_YEARS', 3),
84 '48' => $langs->trans('NB_YEARS', 4),
85 '60' => $langs->trans('NB_YEARS', 5),
86 '120' => $langs->trans('NB_YEARS', 10),
87 '180' => $langs->trans('NB_YEARS', 15),
88 '240' => $langs->trans('NB_YEARS', 20),
89);
90
91// Security
92if (!isModEnabled("datapolicy")) {
94}
95if (!$user->admin) {
97}
98
99
100'@phan-var-force array<string,array<string,array{type?:string,css?:string,picto?:string}>> $arrayofparameters';
101
102/*
103 * Actions
104 */
105
106$nbdone = 0;
107$error = 0;
108
109foreach ($arrayofparameters as $title => $tab) {
110 foreach ($tab as $key => $val) {
111 // Modify constant only if key was posted (avoid resetting key to the null value)
112 if (GETPOSTISSET($key)) {
113 if (preg_match('/category:/', (string) $val['type'])) {
114 if (GETPOSTINT($key) == '-1') {
115 $val_const = '';
116 } else {
117 $val_const = GETPOSTINT($key);
118 }
119 } else {
120 $val_const = GETPOST($key, 'alpha');
121 }
122
123 $result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity);
124 if ($result < 0) {
125 $error++;
126 break;
127 } else {
128 $nbdone++;
129 }
130 }
131 }
132}
133
134if ($nbdone) {
135 setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
136}
137if ($action == 'update') {
138 $action = 'edit';
139}
140
141
142/*
143 * View
144 */
145
146$page_name = "datapolicySetup";
147llxHeader('', $langs->trans($page_name));
148
149// Subheader
150$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
151
152print load_fiche_titre($langs->trans($page_name), $linkback, 'generic');
153
154// Configuration header
156print dol_get_fiche_head($head, 'settings', '', -1, '');
157
158// Setup page goes here
159print '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span>';
160print $form->textwithpicto('', $langs->trans('DATAPOLICY_Tooltip_SETUP', $langs->trans("DATAPOLICYJob"), $langs->transnoentities("CronList")));
161print '<br>';
162print '<br>';
163print '<br>';
164
165// TODO Show the last date of execution of the job DATAPOLICYJob
166
167if ($action == 'edit') {
168 print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
169 print '<input type="hidden" name="token" value="'.newToken().'">';
170 print '<input type="hidden" name="action" value="update">';
171
172 print '<div class="div-table-responsive">'; // You can use div-table-responsive-no-min if you don't need reserved height for your table
173 print '<table class="tagtable nobottomiftotal liste">';
174
175 print '<tr class="liste_titre"><td class="titlefield"></td>';
176 print '<td>'.$langs->trans("DelayForAnonymization").'</td>';
177 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
178 print '<td>'.$langs->trans("DelayForDeletion").'</td>';
179 }
180 print '</tr>';
181
182 foreach ($arrayofparameters as $title => $tab) {
183 print '<tr class="trforbreak liste_titre"><td class="titlefield trforbreak">'.$langs->trans($title).'</td>';
184 print '<td></td>';
185 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
186 print '<td></td>';
187 }
188 print '</tr>';
189
190 foreach ($tab as $key => $val) {
191 print '<tr class="oddeven"><td>';
192 print $val['picto'];
193 print $langs->trans($key);
194 print '</td><td>';
195 print '<select name="'.$key.'" id="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'">';
196 foreach ($valTab as $key1 => $val1) {
197 print '<option value="'.$key1.'" '.(getDolGlobalString($key) == $key1 ? 'selected="selected"' : '').'>';
198 print $val1;
199 print '</option>';
200 }
201 print '</select>';
202 print ajax_combobox($key);
203 print '</td>';
204 if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) {
205 print '<td>';
206 print $langs->trans("FeatureNotYetAvailable");
207 print '</td>';
208 }
209
210 print '</tr>';
211 }
212 }
213
214 print '</table>';
215 print '</div>';
216
217 print $form->buttonsSaveCancel("Save", '');
218
219 print '</form>';
220 print '<br>';
221} else {
222 print '<table class="noborder centpercent">';
223
224 foreach ($arrayofparameters as $title => $tab) {
225 print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
226 foreach ($tab as $key => $val) {
227 print '<tr class="oddeven"><td>';
228 print $val['picto'];
229 print $langs->trans($key);
230 print '</td><td>'.(getDolGlobalString($key) == '' ? '<span class="opacitymedium">'.$valTab[''].'</span>' : $valTab[getDolGlobalString($key)]).'</td></tr>';
231 }
232 }
233
234 print '</table>';
235
236 print '<div class="tabsAction">';
237 print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
238 print '</div>';
239}
240
241
242// Page end
243print dol_get_fiche_end();
244
245llxFooter();
246$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:459
llxFooter($comment='', $zone='private', $disabledoutputofmessages=0)
Empty footer.
Definition wrapper.php:87
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
datapolicyAdminPrepareHead()
Prepare admin pages header.
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.
getDolGlobalInt($key, $default=0)
Return a Dolibarr global constant int value.
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.