setup.php 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. <?php
  2. /* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
  3. * Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.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. /**
  19. * \file htdocs/datapolicy/admin/setup.php
  20. * \ingroup datapolicy
  21. * \brief Datapolicy setup page to define duration of data keeping.
  22. */
  23. // Load Dolibarr environment
  24. require '../../main.inc.php';
  25. require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
  26. require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php';
  27. // Translations
  28. $langs->loadLangs(array('admin', 'companies', 'members', 'datapolicy'));
  29. // Parameters
  30. $action = GETPOST('action', 'aZ09');
  31. $backtopage = GETPOST('backtopage', 'alpha');
  32. $arrayofparameters = array();
  33. $arrayofparameters['ThirdParty'] = array(
  34. 'DATAPOLICY_TIERS_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
  35. 'DATAPOLICY_TIERS_PROSPECT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
  36. 'DATAPOLICY_TIERS_PROSPECT_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
  37. 'DATAPOLICY_TIERS_NIPROSPECT_NICLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'company', 'class="pictofixedwidth"')),
  38. 'DATAPOLICY_TIERS_FOURNISSEUR'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'supplier', 'class="pictofixedwidth"')),
  39. );
  40. if (!empty($conf->global->DATAPOLICY_USE_SPECIFIC_DELAY_FOR_CONTACT)) {
  41. $arrayofparameters['Contact'] = array(
  42. 'DATAPOLICY_CONTACT_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'contact', 'class="pictofixedwidth"')),
  43. 'DATAPOLICY_CONTACT_PROSPECT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'contact', 'class="pictofixedwidth"')),
  44. 'DATAPOLICY_CONTACT_PROSPECT_CLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'contact', 'class="pictofixedwidth"')),
  45. 'DATAPOLICY_CONTACT_NIPROSPECT_NICLIENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'contact', 'class="pictofixedwidth"')),
  46. 'DATAPOLICY_CONTACT_FOURNISSEUR'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'contact', 'class="pictofixedwidth"')),
  47. );
  48. }
  49. if (isModEnabled('adherent')) {
  50. $arrayofparameters['Member'] = array(
  51. 'DATAPOLICY_ADHERENT'=>array('css'=>'minwidth200', 'picto'=>img_picto('', 'member', 'class="pictofixedwidth"')),
  52. );
  53. }
  54. $valTab = array(
  55. '' => $langs->trans('Never'),
  56. '6' => $langs->trans('NB_MONTHS', 6),
  57. '12' => $langs->trans('ONE_YEAR'),
  58. '24' => $langs->trans('NB_YEARS', 2),
  59. '36' => $langs->trans('NB_YEARS', 3),
  60. '48' => $langs->trans('NB_YEARS', 4),
  61. '60' => $langs->trans('NB_YEARS', 5),
  62. '120' => $langs->trans('NB_YEARS', 10),
  63. '180' => $langs->trans('NB_YEARS', 15),
  64. '240' => $langs->trans('NB_YEARS', 20),
  65. );
  66. // Security
  67. if (!isModEnabled("datapolicy")) {
  68. accessforbidden();
  69. }
  70. if (!$user->admin) {
  71. accessforbidden();
  72. }
  73. /*
  74. * Actions
  75. */
  76. foreach ($arrayofparameters as $title => $tab) {
  77. foreach ($tab as $key => $val) {
  78. // Modify constant only if key was posted (avoid resetting key to the null value)
  79. if (GETPOSTISSET($key)) {
  80. if (preg_match('/category:/', $val['type'])) {
  81. if (GETPOST($key, 'int') == '-1') {
  82. $val_const = '';
  83. } else {
  84. $val_const = GETPOST($key, 'int');
  85. }
  86. } else {
  87. $val_const = GETPOST($key, 'alpha');
  88. }
  89. $result = dolibarr_set_const($db, $key, $val_const, 'chaine', 0, '', $conf->entity);
  90. if ($result < 0) {
  91. $error++;
  92. break;
  93. }
  94. }
  95. }
  96. }
  97. /*
  98. * View
  99. */
  100. $page_name = "datapolicySetup";
  101. llxHeader('', $langs->trans($page_name));
  102. // Subheader
  103. $linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.$langs->trans("BackToModuleList").'</a>';
  104. print load_fiche_titre($langs->trans($page_name), $linkback, 'generic');
  105. // Configuration header
  106. $head = datapolicyAdminPrepareHead();
  107. print dol_get_fiche_head($head, 'settings', '', -1, '');
  108. // Setup page goes here
  109. echo '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span><br><br>';
  110. if ($action == 'edit') {
  111. print '<form method="POST" action="'.$_SERVER["PHP_SELF"].'">';
  112. print '<input type="hidden" name="token" value="'.newToken().'">';
  113. print '<input type="hidden" name="action" value="update">';
  114. print '<table class="noborder centpercent">';
  115. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  116. foreach ($arrayofparameters as $title => $tab) {
  117. print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
  118. foreach ($tab as $key => $val) {
  119. print '<tr class="oddeven"><td>';
  120. print $val['picto'];
  121. print $form->textwithpicto($langs->trans($key), $langs->trans('DATAPOLICY_Tooltip_SETUP'));
  122. print '</td><td>';
  123. print '<select name="'.$key.'" class="flat '.(empty($val['css']) ? 'minwidth200' : $val['css']).'">';
  124. foreach ($valTab as $key1 => $val1) {
  125. print '<option value="'.$key1.'" '.($conf->global->$key == $key1 ? 'selected="selected"' : '').'>';
  126. print $val1;
  127. print '</option>';
  128. }
  129. print '</select>';
  130. print '</td></tr>';
  131. }
  132. }
  133. print '</table>';
  134. print '<br><div class="center">';
  135. print '<input class="button button-save" type="submit" value="'.$langs->trans("Save").'">';
  136. print '</div>';
  137. print '</form>';
  138. print '<br>';
  139. } else {
  140. print '<table class="noborder centpercent">';
  141. print '<tr class="liste_titre"><td class="titlefield">'.$langs->trans("Parameter").'</td><td>'.$langs->trans("Value").'</td></tr>';
  142. foreach ($arrayofparameters as $title => $tab) {
  143. print '<tr class="trforbreak"><td class="titlefield trforbreak" colspan="2">'.$langs->trans($title).'</td></tr>';
  144. foreach ($tab as $key => $val) {
  145. print '<tr class="oddeven"><td>';
  146. print $val['picto'];
  147. print $form->textwithpicto($langs->trans($key), $langs->trans('DATAPOLICY_Tooltip_SETUP'));
  148. print '</td><td>'.($conf->global->$key == '' ? $langs->trans('None') : $valTab[$conf->global->$key]).'</td></tr>';
  149. }
  150. }
  151. print '</table>';
  152. print '<div class="tabsAction">';
  153. print '<a class="butAction" href="'.$_SERVER["PHP_SELF"].'?action=edit&token='.newToken().'">'.$langs->trans("Modify").'</a>';
  154. print '</div>';
  155. }
  156. // Page end
  157. print dol_get_fiche_end();
  158. llxFooter();
  159. $db->close();