dolibarr  20.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  *
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
27 require '../../main.inc.php';
28 require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
29 require_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 
38 $arrayofparameters = array();
39 $arrayofparameters['ThirdParty'] = array(
40  'DATAPOLICY_TIERS_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
41  'DATAPOLICY_TIERS_PROSPECT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
42  'DATAPOLICY_TIERS_PROSPECT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
43  'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'company', 'class="pictofixedwidth"')),
44  'DATAPOLICY_TIERS_FOURNISSEUR' => array('css' => 'minwidth200', 'picto' => img_picto('', 'supplier', 'class="pictofixedwidth"')),
45 );
46 if (getDolGlobalString('DATAPOLICY_USE_SPECIFIC_DELAY_FOR_CONTACT')) {
47  $arrayofparameters['Contact'] = array(
48  'DATAPOLICY_CONTACT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
49  'DATAPOLICY_CONTACT_PROSPECT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
50  'DATAPOLICY_CONTACT_PROSPECT_CLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
51  'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
52  'DATAPOLICY_CONTACT_FOURNISSEUR' => array('css' => 'minwidth200', 'picto' => img_picto('', 'contact', 'class="pictofixedwidth"')),
53  );
54 }
55 if (isModEnabled('member')) {
56  $arrayofparameters['Member'] = array(
57  'DATAPOLICY_ADHERENT' => array('css' => 'minwidth200', 'picto' => img_picto('', 'member', 'class="pictofixedwidth"')),
58  );
59 }
60 
61 $valTab = array(
62  '' => $langs->trans('Never'),
63  '6' => $langs->trans('NB_MONTHS', 6),
64  '12' => $langs->trans('ONE_YEAR'),
65  '24' => $langs->trans('NB_YEARS', 2),
66  '36' => $langs->trans('NB_YEARS', 3),
67  '48' => $langs->trans('NB_YEARS', 4),
68  '60' => $langs->trans('NB_YEARS', 5),
69  '120' => $langs->trans('NB_YEARS', 10),
70  '180' => $langs->trans('NB_YEARS', 15),
71  '240' => $langs->trans('NB_YEARS', 20),
72 );
73 
74 // Security
75 if (!isModEnabled("datapolicy")) {
77 }
78 if (!$user->admin) {
80 }
81 
82 
83 '@phan-var-force array<string,array<string,array{type?:string,css?:string,picto?:string}>> $arrayofparameters';
84 
85 /*
86  * Actions
87  */
88 foreach ($arrayofparameters as $title => $tab) {
89  foreach ($tab as $key => $val) {
90  // Modify constant only if key was posted (avoid resetting key to the null value)
91  if (GETPOSTISSET($key)) {
92  if (preg_match('/category:/', (string) $val['type'])) {
93  if (GETPOSTINT($key) == '-1') {
94  $val_const = '';
95  } else {
96  $val_const = GETPOSTINT($key);
97  }
98  } else {
99  $val_const = GETPOST($key, 'alpha');
100  }
101 
102  $result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity);
103  if ($result < 0) {
104  $error++;
105  break;
106  }
107  }
108  }
109 }
110 
111 
112 
113 /*
114  * View
115  */
116 
117 $page_name = "datapolicySetup";
118 llxHeader('', $langs->trans($page_name));
119 
120 // Subheader
121 $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
122 
123 print load_fiche_titre($langs->trans($page_name), $linkback, 'generic');
124 
125 // Configuration header
127 print dol_get_fiche_head($head, 'settings', '', -1, '');
128 
129 // Setup page goes here
130 echo '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span><br><br>';
131 
132 
133 if ($action == 'edit') {
134  print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
135  print '<input type="hidden" name="token" value="'.newToken().'">';
136  print '<input type="hidden" name="action" value="update">';
137 
138  print '<table class="noborder centpercent">';
139  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
140 
141  foreach ($arrayofparameters as $title => $tab) {
142  print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
143  foreach ($tab as $key => $val) {
144  print '<tr class="oddeven"><td>';
145  print $val['picto'];
146  print $form->textwithpicto($langs->trans($key), $langs->trans('DATAPOLICY_Tooltip_SETUP'));
147  print '</td><td>';
148  print '<select name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'">';
149  foreach ($valTab as $key1 => $val1) {
150  print '<option value="'.$key1.'" '.(getDolGlobalString($key) == $key1 ? 'selected="selected"' : '').'>';
151  print $val1;
152  print '</option>';
153  }
154  print '</select>';
155  print '</td></tr>';
156  }
157  }
158 
159  print '</table>';
160 
161  print '<br><div class="center">';
162  print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
163  print '</div>';
164 
165  print '</form>';
166  print '<br>';
167 } else {
168  print '<table class="noborder centpercent">';
169  print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
170 
171  foreach ($arrayofparameters as $title => $tab) {
172  print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
173  foreach ($tab as $key => $val) {
174  print '<tr class="oddeven"><td>';
175  print $val['picto'];
176  print $form->textwithpicto($langs->trans($key), $langs->trans('DATAPOLICY_Tooltip_SETUP'));
177  print '</td><td>'.(getDolGlobalString($key) == '' ? $langs->trans('None') : $valTab[getDolGlobalString($key)]).'</td></tr>';
178  }
179  }
180 
181  print '</table>';
182 
183  print '<div class="tabsAction">';
184  print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
185  print '</div>';
186 }
187 
188 
189 // Page end
190 print dol_get_fiche_end();
191 
192 llxFooter();
193 $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).
Definition: admin.lib.php:656
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
datapolicyAdminPrepareHead()
Prepare admin pages header.
load_fiche_titre($title, $morehtmlright='', $picto='generic', $pictoisfullpath=0, $id='', $morecssontable='', $morehtmlcenter='')
Load a title with picto.
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.
GETPOSTISSET($paramname)
Return true if we are in a context of submitting the parameter $paramname from a POST of a form.
getDolGlobalString($key, $default='')
Return dolibarr global constant string value.
isModEnabled($module)
Is Dolibarr module enabled.
accessforbidden($message='', $printheader=1, $printfooter=1, $showonlymessage=0, $params=null)
Show a message to say access is forbidden and stop program.