unsubscribe_account.php 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. <?php
  2. /* For licensing terms, see /license.txt */
  3. require_once __DIR__.'/../inc/global.inc.php';
  4. if (api_get_setting('platform_unsubscribe_allowed') != 'true') {
  5. api_not_allowed();
  6. }
  7. $tool_name = get_lang('Unsubscribe');
  8. $message = Display::return_message(get_lang('UnsubscribeFromPlatform'), 'warning');
  9. $form = new FormValidator('user_add');
  10. $form->addElement(
  11. 'button',
  12. 'submit',
  13. get_lang('Unsubscribe'),
  14. array(
  15. 'onclick' => "javascript:if(!confirm('".addslashes(api_htmlentities(get_lang("UnsubscribeFromPlatformConfirm")))."')) return false;",
  16. )
  17. );
  18. $content = $form->returnForm();
  19. if ($form->validate()) {
  20. $user_info = api_get_user_info();
  21. $result = UserManager::delete_user($user_info['user_id']);
  22. if ($result) {
  23. $message = Display::return_message(
  24. sprintf(
  25. get_lang(
  26. 'UnsubscribeFromPlatformSuccess',
  27. $user_info['username']
  28. )
  29. )
  30. );
  31. $content = null;
  32. online_logout($user_info['user_id'], false);
  33. api_not_allowed(true, $message);
  34. }
  35. }
  36. $tpl = new Template($tool_name);
  37. $tpl->assign('message', $message);
  38. $tpl->assign('content', $content);
  39. $tpl->display_one_col_template();