delete.php 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. <?php
  2. declare(strict_types=1);
  3. use App\App\Bootstrap;
  4. use App\Admin\Auth;
  5. use App\Security\Csrf;
  6. use App\Storage\FileSystem;
  7. use App\Storage\JsonStore;
  8. require dirname(__DIR__) . '/src/autoload.php';
  9. Bootstrap::init();
  10. $auth = new Auth();
  11. $auth->requireLogin();
  12. if ($_SERVER['REQUEST_METHOD'] !== 'POST') {
  13. http_response_code(405);
  14. echo 'Method not allowed';
  15. exit;
  16. }
  17. if (!Csrf::validate((string) ($_POST['csrf'] ?? ''))) {
  18. http_response_code(419);
  19. echo 'Ungültiges CSRF-Token.';
  20. exit;
  21. }
  22. $id = trim((string) ($_POST['id'] ?? ''));
  23. if ($id === '') {
  24. http_response_code(422);
  25. echo 'Ungültige ID.';
  26. exit;
  27. }
  28. $store = new JsonStore();
  29. $submission = $store->getSubmissionByKey($id);
  30. if ($submission === null) {
  31. http_response_code(404);
  32. echo 'Antrag nicht gefunden.';
  33. exit;
  34. }
  35. $store->deleteSubmissionByKey($id);
  36. $app = Bootstrap::config('app');
  37. $uploadDir = rtrim((string) $app['storage']['uploads'], '/') . '/' . (string) ($submission['application_key'] ?? '');
  38. FileSystem::removeTree($uploadDir);
  39. header('Location: ' . Bootstrap::url('admin/index.php'));
  40. exit;