request_removal_reminder.php 3.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. if (PHP_SAPI != 'cli') {
  5. exit('Run this script through the command line or comment this line in the code');
  6. }
  7. $urlList = UrlManager::get_url_data();
  8. $defaultSenderId = 1;
  9. // Loop all portals
  10. foreach ($urlList as $url) {
  11. // Set access_url in order to get the correct url links and admins
  12. $_configuration['access_url'] = $url['id'];
  13. $sql = '';
  14. $user_table = Database::get_main_table(TABLE_MAIN_USER);
  15. $admin_table = Database::get_main_table(TABLE_MAIN_ADMIN);
  16. $sql .= "SELECT u.id, v.updated_at FROM $user_table u";
  17. // adding the filter to see the user's only of the current access_url
  18. if (api_get_multiple_access_url()) {
  19. $access_url_rel_user_table = Database::get_main_table(TABLE_MAIN_ACCESS_URL_REL_USER);
  20. $sql .= " INNER JOIN $access_url_rel_user_table url_rel_user
  21. ON (u.id = url_rel_user.user_id)";
  22. }
  23. $extraFields = UserManager::createDataPrivacyExtraFields();
  24. $extraFieldId = $extraFields['delete_legal'];
  25. $extraFieldIdDeleteAccount = $extraFields['delete_account_extra_field'];
  26. $extraFieldValue = Database::get_main_table(TABLE_EXTRA_FIELD_VALUES);
  27. $sql .= " INNER JOIN $extraFieldValue v
  28. ON (
  29. u.id = v.item_id AND
  30. (field_id = $extraFieldId OR field_id = $extraFieldIdDeleteAccount) AND
  31. v.value = 1
  32. ) ";
  33. $sql .= " WHERE 1 = 1 ";
  34. if (api_get_multiple_access_url()) {
  35. $sql .= " AND url_rel_user.access_url_id = ".api_get_current_access_url_id();
  36. }
  37. $numberOfDays = 7;
  38. $date = new DateTime();
  39. $date->sub(new \DateInterval('P'.$numberOfDays.'D'));
  40. $dateToString = $date->format('Y-m-d h:i:s');
  41. $sql .= " AND v.updated_at < '$dateToString'";
  42. $url = api_get_path(WEB_CODE_PATH).'admin/user_list_consent.php';
  43. $link = Display::url($url, $url);
  44. $subject = get_lang('A user is waiting for an action about his/her personal data request');
  45. $email = api_get_configuration_value('data_protection_officer_email');
  46. $message = 'Checking requests from '.strip_tags(Display::dateToStringAgoAndLongDate($dateToString))."\n";
  47. $result = Database::query($sql);
  48. while ($user = Database::fetch_array($result, 'ASSOC')) {
  49. $userId = $user['id'];
  50. $userInfo = api_get_user_info($userId);
  51. if ($userInfo) {
  52. $content = sprintf(
  53. get_lang('The user %s is waiting for an action about it\'s personal data request.
  54. To manage personal data requests you can follow this link : %s'),
  55. $userInfo['complete_name'],
  56. $link
  57. );
  58. if (!empty($email)) {
  59. api_mail_html('', $email, $subject, $content);
  60. } else {
  61. MessageManager::sendMessageToAllAdminUsers($defaultSenderId, $subject, $content);
  62. }
  63. $date = strip_tags(Display::dateToStringAgoAndLongDate($user['updated_at']));
  64. $message .= "User ".$userInfo['complete_name_with_username']." is waiting for an action since $date \n";
  65. }
  66. }
  67. echo $message;
  68. }