* Copyright (C) 2018 Nicolas ZABOURI * Copyright (C) 2024 MDW * Copyright (C) 2024 Frédéric France * Copyright (C) 2025 Quentin VIAL--GOUTEYRON * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with this program. If not, see . */ /** * \file htdocs/datapolicy/admin/setup.php * \ingroup datapolicy * \brief Datapolicy setup page to define duration of data keeping. */ // Load Dolibarr environment require '../../main.inc.php'; require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php"; require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php'; require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicycron.class.php'; require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php'; /** * @var Conf $conf * @var DoliDB $db * @var Form $form * @var HookManager $hookmanager * @var Translate $langs * @var User $user */ if (!$langs instanceof Translate) { trigger_error("Langs object was not initialized correctly.", E_USER_ERROR); } // Translations $langs->loadLangs(array('admin', 'companies', 'members', 'cron', 'datapolicy', 'recruitment')); // Parameters $action = GETPOST('action', 'aZ09'); $backtopage = GETPOST('backtopage', 'alpha'); if (empty($action)) { $action = 'edit'; } // Get the array $arrayofparameters from _getDataPolicies $arrayofparameters = array(); $dataPolicyCron = new DataPolicyCron($db); $arrayofelem = $dataPolicyCron->getDataPolicies(); $arrayofparameters = array(); foreach ($arrayofelem as $key => $val) { $arrayofparameters[$val['group']][$key] = array( 'label_key' => $val['label_key'], 'picto' => $val['picto'], 'config_keys' => array( 'anonymize' => $val['const_anonymize'], 'delete' => $val['const_delete'] ) ); } // Dropdown options for delay selection $valTab = array( '' => $langs->trans('Never'), '6' => $langs->trans('NB_MONTHS', 6), '12' => $langs->trans('ONE_YEAR'), '24' => $langs->trans('NB_YEARS', 2), '36' => $langs->trans('NB_YEARS', 3), '48' => $langs->trans('NB_YEARS', 4), '60' => $langs->trans('NB_YEARS', 5), '120' => $langs->trans('NB_YEARS', 10), '180' => $langs->trans('NB_YEARS', 15), '240' => $langs->trans('NB_YEARS', 20), ); // Security if (!isModEnabled("datapolicy")) { accessforbidden(); } if (!$user->admin) { accessforbidden(); } /* * Actions */ // Handle form submission to update constants if ($action == 'update') { $nbdone = 0; $error = 0; // Loop through the data structure to find all possible constants to save. foreach ($arrayofparameters as $tab) { foreach ($tab as $logicalKey => $val) { // Iterate through defined actions ('anonymize', 'delete') for the entity. foreach ($val['config_keys'] as $actionType => $constKey) { // Save the constant only if its value was submitted in the form. if (GETPOSTISSET($constKey)) { $val_const = GETPOST($constKey, 'alpha'); if (dolibarr_set_const($db, $constKey, $val_const, 'chaine', 0, '', $conf->entity) >= 0) { $nbdone++; } else { $error++; } } } } } if ($nbdone > 0) { setEventMessages($langs->trans("SetupSaved"), null, 'mesgs'); } if ($error > 0) { setEventMessages($langs->trans("Error"), null, 'errors'); } $action = 'edit'; } /* * View */ $page_name = "datapolicySetup"; llxHeader('', $langs->trans($page_name)); $linkback = ''.$langs->trans("BackToModuleList").''; print load_fiche_titre($langs->trans($page_name), $linkback, 'generic'); $head = datapolicyAdminPrepareHead(); print dol_get_fiche_head($head, 'settings', '', -1, ''); print ''.$langs->trans("datapolicySetupPage").''; print $form->textwithpicto('', $langs->trans('DATAPOLICY_Tooltip_SETUP', $langs->transnoentitiesnoconv("DATAPOLICYJob"), $langs->transnoentitiesnoconv("CronList"))); if (!isModEnabled('cron')) { print info_admin($langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("CronList")), 0, 0, 'warning'); } else { $tmpjob = new Cronjob($db); $tmpjob->fetch(0, '', '', 'DATAPOLICYJob'); if ($tmpjob->status != $tmpjob::STATUS_ENABLED) { print info_admin($langs->trans("JobMustBeEnabledFirst", $langs->transnoentitiesnoconv("DATAPOLICYJob"), $langs->transnoentitiesnoconv("CronList")), 0, 0, 'warning'); } } print '

'; if ($action == 'edit') { print '
'; print ''; print ''; print '
'; print ''; // Table Headers print ''; print ''; if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { print ''; } print ''; // ============================================================================== // == DYNAMIC VIEW RENDERING // ============================================================================== // Loop through each configuration group (e.g., ThirdParty, Member). foreach ($arrayofparameters as $title => $tab) { print ''; print ''; if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { print ''; } print ''; // Loop through each entity within the group to create a table row. foreach ($tab as $logicalKey => $val) { print ''; // Column 1: Anonymization print ''; // Column 2: Deletion if (getDolGlobalInt('MAIN_FEATURES_LEVEL') >= 2) { print ''; } print ''; } } print '
'.$langs->trans("DelayForAnonymization").''.$langs->trans("DelayForDeletion").'
'.$langs->trans($title).'
'; print $val['picto']; print $langs->trans($val['label_key']); print ''; // Display the dropdown only if a constant key is defined for the 'anonymize' action. if (!empty($val['config_keys']['anonymize'])) { print Form::selectarray($val['config_keys']['anonymize'], $valTab, getDolGlobalString($val['config_keys']['anonymize'])); //var_dump($val); $listoffieldsid = ''; foreach ($arrayofelem[$logicalKey]['anonymize_fields'] as $tmpkey => $tmpval) { if ($tmpval == 'MAKEANONYMOUS') { $listoffieldsid .= ($listoffieldsid ? ', ' : '').$tmpkey.' -> field-anonymous-ID'; } } $otherfields = ''; foreach ($arrayofelem[$logicalKey]['anonymize_fields'] as $tmpkey => $tmpval) { if ($tmpval != 'MAKEANONYMOUS') { $otherfields .= ($otherfields ? ', ' : '').$tmpkey.' -> '.json_encode($tmpval); } } $htmltooltip = $langs->transnoentitiesnoconv("TheFollowingFieldsAreReplaceWith"); $htmltooltip .= '
'.$listoffieldsid.''; $htmltooltip .= '

'.$langs->transnoentitiesnoconv("OtherFieldsAreReplaceWithStaticValues"); $htmltooltip .= '
'.$otherfields.''; print $form->textwithpicto('', $htmltooltip); } print '
'; // Display the dropdown only if a constant key is defined for the 'delete' action. print Form::selectarray($val['config_keys']['delete'], $valTab, getDolGlobalString($val['config_keys']['delete'])); print '
'; print '
'; print $form->buttonsSaveCancel("Save", ''); print '
'; print '
'; } print dol_get_fiche_end(); llxFooter(); $db->close();