request_removal_reminder.php 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  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('UserRequestWaitingForAction');
  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('TheUserXIsWaitingForAnActionGoHereX'),
  54. $userInfo['complete_name'],
  55. $link
  56. );
  57. if (!empty($email)) {
  58. api_mail_html('', $email, $subject, $content);
  59. } else {
  60. MessageManager::sendMessageToAllAdminUsers($defaultSenderId, $subject, $content);
  61. }
  62. $date = strip_tags(Display::dateToStringAgoAndLongDate($user['updated_at']));
  63. $message .= "User ".$userInfo['complete_name_with_username']." is waiting for an action since $date \n";
  64. }
  65. }
  66. echo $message;
  67. }