dolibarr/htdocs/datapolicy/admin/setup.php

329 lines
12 KiB
PHP
Raw Permalink Normal View History

<?php
/* Copyright (C) 2004-2017 Laurent Destailleur <eldy@users.sourceforge.net>
* Copyright (C) 2018 Nicolas ZABOURI <info@inovea-conseil.com>
2024-08-30 13:42:36 +00:00
* Copyright (C) 2024 MDW <mdeweerd@users.noreply.github.com>
* Copyright (C) 2024-2025 Frédéric France <frederic.france@free.fr>
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
* Copyright (C) 2025 Quentin VIAL--GOUTEYRON <quentin.vial-gouteyron@atm-consulting.fr>
*
* 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
2019-09-23 19:55:30 +00:00
* along with this program. If not, see <https://www.gnu.org/licenses/>.
*/
/**
2019-02-24 13:30:02 +00:00
* \file htdocs/datapolicy/admin/setup.php
2018-10-15 12:04:42 +00:00
* \ingroup datapolicy
2022-09-08 14:19:11 +00:00
* \brief Datapolicy setup page to define duration of data keeping.
*/
2022-09-07 18:08:59 +00:00
// Load Dolibarr environment
2018-10-06 01:13:03 +00:00
require '../../main.inc.php';
require_once DOL_DOCUMENT_ROOT."/core/lib/admin.lib.php";
2022-09-08 14:19:11 +00:00
require_once DOL_DOCUMENT_ROOT.'/datapolicy/lib/datapolicy.lib.php';
2025-07-24 12:42:45 +00:00
require_once DOL_DOCUMENT_ROOT.'/datapolicy/class/datapolicycron.class.php';
2025-07-24 10:35:41 +00:00
require_once DOL_DOCUMENT_ROOT.'/cron/class/cronjob.class.php';
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 22:53:20 +00:00
/**
* @var Conf $conf
* @var DoliDB $db
* @var Form $form
add baseline exclude for phpstan (#31632) * add baseline exclude for phpstan * update * update * update * update * update * merge * restore one filter * delete old errors * fix * fix * fix * $moreforfilter can t be empty * fix * enable check * refresh baseline * add phpdoc * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * update phpstan baseline * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix * fix --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2024-11-04 22:53:20 +00:00
* @var HookManager $hookmanager
* @var Translate $langs
* @var User $user
*/
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
if (!$langs instanceof Translate) {
trigger_error("Langs object was not initialized correctly.", E_USER_ERROR);
}
// Translations
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
$langs->loadLangs(array('admin', 'companies', 'members', 'cron', 'datapolicy', 'recruitment'));
// Parameters
2020-09-16 17:39:50 +00:00
$action = GETPOST('action', 'aZ09');
$backtopage = GETPOST('backtopage', 'alpha');
2024-08-30 13:42:36 +00:00
if (empty($action)) {
$action = 'edit';
}
2025-07-24 12:42:45 +00:00
// Get the array $arrayofparameters from _getDataPolicies
2019-12-01 11:12:01 +00:00
$arrayofparameters = array();
2025-07-24 12:42:45 +00:00
$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'],
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
'config_keys' => array(
2025-07-24 12:42:45 +00:00
'anonymize' => $val['const_anonymize'],
'delete' => $val['const_delete']
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
)
);
2019-12-01 11:12:01 +00:00
}
2025-07-24 12:42:45 +00:00
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
// Dropdown options for delay selection
$valTab = array(
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
'' => $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),
);
2022-09-08 14:19:11 +00:00
// Security
if (!isModEnabled("datapolicy")) {
accessforbidden();
}
2021-05-11 12:50:04 +00:00
if (!$user->admin) {
accessforbidden();
}
/*
* Actions
*/
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
// 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++;
}
2021-05-11 12:50:04 +00:00
}
}
}
}
NEW : Major overhaul of DataPolicyCron and add Recruitment policy (#34704) * refactor(datapolicy): redesign setup and logic for GDPR compliance - Introduced a data-driven configuration structure for setup.php. - Added support for a new "recruitment" GDPR datapolicy configuration. - Streamlined code for managing anonymization and deletion delays. - Enhanced dropdown generation logic to improve maintainability. - Simplified data anonymization and deletion methods in cron execution. This change provides more flexibility and modularity while ensuring compliance with GDPR standards. * refactor(datapolicy): enhance data cleaning logic and add modular handlers - Refactored `cleanDataForDataPolicy` method for better readability and efficiency. - Implemented modular handlers for deletion and anonymization (_handleDelete and _handleAnonymize). - Added dynamic argument building for method calls based on policy configurations. - Improved SQL query preparation with placeholders for better database compatibility. - Enhanced error handling and outcome recording in data processing. This update simplifies extensibility and ensures robust handling of datapolicies. * fix precommit * fix * fix(datapolicy): resolve uninitialized langs object and improve type hints - Added a check to ensure `$langs` object is properly initialized, preventing runtime errors. - Improved type hints in `datapolicycron.class.php` for stronger type checking and clarity. - Replaced `empty` checks with `isset` for better null safety in setup.php dropdown logic. - Adjusted SQL placeholders to cast values as strings for compatibility. These changes enhance code robustness, type safety, and error handling. * fix(datapolicy): improve type hints and streamline dropdown logic - Added precise type hints (`string`, `array`) to enhance code clarity and type safety. - Removed redundant condition in dropdown generation for improved maintainability. - Added type specification for `$paramName` in `array_map` to strengthen type checking. - Inserted missing class docblock for `CommonObject` in `datapolicycron.class.php`. These updates lead to cleaner, safer, and more robust code. * fix(datapolicy): improve type hints and streamline form submission logic - Added return type hints (`: int`, `: void`, `: array`) in `datapolicycron.class.php` for better type safety and clarity. - Simplified loop structures in `setup.php` by removing unnecessary variables. - Revised `buttonsSaveCancel` method usage to eliminate redundant cancel parameter logic. - Enhanced maintainability through refactoring `_processPolicyAction`, `_handleDelete`, and `_handleAnonymize` methods. These refinements improve code readability, maintainability, and robustness. * refactor(datapolicy): replace custom dropdown generation with `Form::selectarray` - Removed the custom `$generateSelectHtml` function, simplifying code by using the existing `Form::selectarray` method. - Updated dropdown generation for 'anonymize' and 'delete' actions to align with Dolibarr's standard practices. - Enhances maintainability by leveraging built-in utilities and reducing custom logic. * Update datapolicycron.class.php * Try to fix CI * Update datapolicycron.class.php --------- Co-authored-by: Laurent Destailleur <eldy@destailleur.fr>
2025-07-24 09:41:05 +00:00
if ($nbdone > 0) {
setEventMessages($langs->trans("SetupSaved"), null, 'mesgs');
}
if ($error > 0) {
setEventMessages($langs->trans("Error"), null, 'errors');
}
2024-08-30 13:42:36 +00:00
$action = 'edit';
}
2021-05-11 12:50:04 +00:00
/*
* View
*/
2018-10-15 12:04:42 +00:00
$page_name = "datapolicySetup";
llxHeader('', $langs->trans($page_name));
2025-08-10 01:22:19 +00:00
$linkback = '<a href="'.($backtopage ? $backtopage : DOL_URL_ROOT.'/admin/modules.php?restore_lastsearch_values=1').'">'.img_picto($langs->trans("BackToModuleList"), 'back', 'class="pictofixedwidth"').'<span class="hideonsmartphone">'.$langs->trans("BackToModuleList").'</span></a>';
2021-05-11 12:50:04 +00:00
print load_fiche_titre($langs->trans($page_name), $linkback, 'generic');
2018-10-15 12:04:42 +00:00
$head = datapolicyAdminPrepareHead();
2021-05-11 12:50:04 +00:00
print dol_get_fiche_head($head, 'settings', '', -1, '');
2024-12-30 03:53:07 +00:00
print '<span class="opacitymedium">'.$langs->trans("datapolicySetupPage").'</span>';
2025-07-24 09:45:43 +00:00
print $form->textwithpicto('', $langs->trans('DATAPOLICY_Tooltip_SETUP', $langs->transnoentitiesnoconv("DATAPOLICYJob"), $langs->transnoentitiesnoconv("CronList")));
2025-07-24 10:21:39 +00:00
if (!isModEnabled('cron')) {
2025-07-24 10:35:41 +00:00
print info_admin($langs->trans("ModuleMustBeEnabledFirst", $langs->transnoentitiesnoconv("CronList")), 0, 0, 'warning');
2025-07-24 10:21:39 +00:00
} else {
2025-07-24 10:35:41 +00:00
$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');
} else {
// TODO Show last date/result of execution of the cron job
2025-07-24 10:35:41 +00:00
}
2025-07-24 10:21:39 +00:00
}
print '<br><br>';
print '<form method="POST" action="'.dolBuildUrl($_SERVER["PHP_SELF"]).'">';
2025-08-15 15:20:28 +00:00
print '<input type="hidden" name="token" value="'.newToken().'">';
print '<input type="hidden" name="action" value="update">';
print '<input type="hidden" name="page_y" value="">';
print '<div class="div-table-responsive">';
print '<table class="tagtable nobottomiftotal liste">';
// Table Headers
print '<tr class="liste_titre"><td class="titlefield"></td>';
print '<td>'.$langs->trans("DelayForAnonymization").'</td>';
print '<td>'.$langs->trans("DelayForDeletion").'</td>';
print '</tr>';
// ==============================================================================
// == DYNAMIC VIEW RENDERING
// ==============================================================================
// Loop through each configuration group (e.g., ThirdParty, Member).
foreach ($arrayofparameters as $title => $tab) {
print '<tr class="trforbreak liste_titre"><td class="titlefield trforbreak">'.$langs->trans($title).'</td>';
print '<td></td>';
print '<td></td>';
2024-12-30 03:53:07 +00:00
print '</tr>';
2025-08-15 15:20:28 +00:00
// Loop through each entity within the group to create a table row.
foreach ($tab as $logicalKey => $val) {
print '<tr class="oddeven"><td>';
print $val['picto'];
print $langs->trans($val['label_key']);
print '</td>';
// Column 1: Anonymization
print '<td class="nowraponall">';
// Display the dropdown only if a constant key is defined for the 'anonymize' action.
if (!empty($val['config_keys']['anonymize'])) {
$selectedvalue = getDolGlobalString($val['config_keys']['anonymize']);
2026-01-15 10:19:07 +00:00
print Form::selectarray($val['config_keys']['anonymize'], $valTab, $selectedvalue, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
2025-08-15 15:20:28 +00:00
//var_dump($val);
$listoffieldsid = '';
foreach ($arrayofelem[$logicalKey]['anonymize_fields'] as $tmpkey => $tmpval) {
2026-01-15 10:52:04 +00:00
if (is_array($tmpval)) {
continue;
}
2025-08-15 15:20:28 +00:00
if ($tmpval === 'MAKEANONYMOUS') {
2026-01-15 10:52:04 +00:00
$listoffieldsid .= ($listoffieldsid ? ', ' : '').$tmpkey.' -> '.$tmpkey.'-anon-ID';
} elseif (strpos($tmpval, '__ID__') !== false) {
$listoffieldsid .= ($listoffieldsid ? ', ' : '').$tmpkey.' -> '.$tmpval;
2025-08-15 15:20:28 +00:00
}
}
$otherfields = '';
foreach ($arrayofelem[$logicalKey]['anonymize_fields'] as $tmpkey => $tmpval) {
2026-01-15 10:52:04 +00:00
if ($tmpval !== 'MAKEANONYMOUS' && strpos((string) $tmpval, '__ID__') === false) {
2025-08-15 15:20:28 +00:00
$otherfields .= ($otherfields ? ', ' : '').$tmpkey.' -> '.json_encode($tmpval);
}
}
2024-12-30 03:53:07 +00:00
2025-08-15 15:20:28 +00:00
$sql = $arrayofelem[$logicalKey]['sql_template'];
2025-08-16 00:14:52 +00:00
$sql = preg_replace('/__ENTITY__/', (string) (int) $conf->entity, $sql);
$sql = preg_replace('/__DELAY__/', (string) (int) $selectedvalue, $sql);
2025-08-15 15:20:28 +00:00
$sql = preg_replace('/__NOW__/', "'".dol_print_date(dol_now(), 'standard')."'", $sql);
$sql = preg_replace('/^SELECT [\w+\s+\._]+ FROM/', 'SELECT COUNT(*) as nb FROM', $sql);
$htmltooltip = $langs->transnoentitiesnoconv("TheFollowingFieldsAreReplaceWith");
2026-01-15 10:52:04 +00:00
$htmltooltip .= '<br><small class="opacitymedium">'.$listoffieldsid.'</small>';
2025-08-15 15:20:28 +00:00
$htmltooltip .= '<br><br>'.$langs->transnoentitiesnoconv("OtherFieldsAreReplaceWithStaticValues");
2026-01-15 10:52:04 +00:00
$htmltooltip .= '<br><small class="opacitymedium">'.$otherfields.'</small>';
$htmltooltip .= '<br><br>'.$langs->transnoentitiesnoconv("TechnicalInformation").' - SQL to select record:';
$htmltooltip .= '<br><small class="opacitymedium">'.$sql.'</small>';
print $form->textwithpicto('', $htmltooltip, 1, 'help', 'valignmidde', 1, 3, $val['config_keys']['anonymize']);
2025-08-15 15:20:28 +00:00
print ' &nbsp; ';
if ($action == 'count' && GETPOST('group') == $logicalKey) {
print '<span class="opacitymedium valignmiddle">'.$langs->trans("QualifiedNumber").' : </span>';
$estimatednumber = 0;
if ($sql) {
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$estimatednumber = $obj->nb;
}
} else {
dol_print_error($db);
2025-07-24 12:42:45 +00:00
}
2025-08-15 15:20:28 +00:00
} else {
print 'Error, bad definition of the array of data policies profiles';
2025-07-24 12:42:45 +00:00
}
2025-08-15 15:20:28 +00:00
print '<span class="valignmiddle badge badge-info">'.$estimatednumber.'</span>';
} elseif ($selectedvalue) {
print '<span class="opacitymedium valignmiddle">'.$langs->trans("QualifiedNumber").' : </span>';
print '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=count&group='.urlencode($logicalKey).'">';
print $langs->trans("Calculate");
print '</a>';
}
}
print '</td>';
// Column 2: Deletion
print '<td>';
if (!empty($val['config_keys']['delete'])) {
$selectedvalue = getDolGlobalString($val['config_keys']['delete']);
// Display the dropdown only if a constant key is defined for the 'delete' action.
2026-01-15 10:19:07 +00:00
print Form::selectarray($val['config_keys']['delete'], $valTab, $selectedvalue, 0, 0, 0, '', 0, 0, 0, '', 'minwidth100');
2025-08-15 15:20:28 +00:00
$sql = $arrayofelem[$logicalKey]['sql_template_delete'];
2025-08-16 00:14:52 +00:00
$sql = preg_replace('/__ENTITY__/', (string) (int) $conf->entity, $sql);
$sql = preg_replace('/__DELAY__/', (string) (int) $selectedvalue, $sql);
2025-08-15 15:20:28 +00:00
$sql = preg_replace('/__NOW__/', "'".dol_print_date(dol_now(), 'standard')."'", $sql);
$sql = preg_replace('/^SELECT [\w+\s+\._]+ FROM/', 'SELECT COUNT(*) as nb FROM', $sql);
2026-01-15 10:52:04 +00:00
$htmltooltip = $langs->transnoentitiesnoconv("TechnicalInformation").' - SQL to select record:';
$htmltooltip .= '<br><small class="opacitymedium">'.$sql.'</small>';
print $form->textwithpicto('', $htmltooltip, 1, 'help', 'valignmidde', 1, 3, $val['config_keys']['delete']);
2025-08-15 15:20:28 +00:00
print ' &nbsp; ';
if ($action == 'countdelete' && GETPOST('group') == $logicalKey) {
print '<span class="opacitymedium valignmiddle">'.$langs->trans("QualifiedNumber").' : </span>';
$estimatednumber = 0;
if ($sql) {
$resql = $db->query($sql);
if ($resql) {
$obj = $db->fetch_object($resql);
if ($obj) {
$estimatednumber = $obj->nb;
}
} else {
dol_print_error($db);
2025-07-24 12:42:45 +00:00
}
2025-08-15 15:20:28 +00:00
} else {
print 'Error, bad definition of the array of data policies profiles';
2025-07-24 12:42:45 +00:00
}
2025-08-15 15:20:28 +00:00
print '<span class="valignmiddle badge badge-info">'.$estimatednumber.'</span>';
} elseif ($selectedvalue) {
print '<span class="opacitymedium valignmiddle">'.$langs->trans("QualifiedNumber").' : </span>';
print '<a class="reposition valignmiddle" href="'.$_SERVER["PHP_SELF"].'?action=countdelete&group='.urlencode($logicalKey).'">';
print $langs->trans("Calculate");
print '</a>';
2024-12-30 03:53:07 +00:00
}
}
2025-08-15 15:20:28 +00:00
print '</td>';
print '</tr>';
}
2025-08-15 15:20:28 +00:00
}
2025-08-15 15:20:28 +00:00
print '</table>';
print '</div>';
2025-08-15 15:20:28 +00:00
print $form->buttonsSaveCancel("Save", '', array(), false, 'reposition');
print '</form>';
print '<br>';
2020-10-27 17:19:31 +00:00
print dol_get_fiche_end();
llxFooter();
$db->close();