application.php 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. <?php
  2. declare(strict_types=1);
  3. use App\App\Bootstrap;
  4. use App\Admin\Auth;
  5. use App\Form\FormSchema;
  6. use App\Mail\SubmissionFormatter;
  7. use App\Security\Csrf;
  8. use App\Storage\JsonStore;
  9. require dirname(__DIR__) . '/src/autoload.php';
  10. Bootstrap::init();
  11. $app = Bootstrap::config('app');
  12. $auth = new Auth();
  13. $auth->requireLogin();
  14. $id = trim((string) ($_GET['id'] ?? ''));
  15. $store = new JsonStore();
  16. $submission = $store->getSubmissionByKey($id);
  17. if ($submission === null) {
  18. http_response_code(404);
  19. echo 'Antrag nicht gefunden.';
  20. exit;
  21. }
  22. $schema = new FormSchema();
  23. $formatter = new SubmissionFormatter($schema);
  24. $formattedSteps = $formatter->formatSteps($submission);
  25. $uploadFields = $schema->getUploadFields();
  26. $formData = (array) ($submission['form_data'] ?? []);
  27. $uploads = (array) ($submission['uploads'] ?? []);
  28. $firstName = (string) ($formData['vorname'] ?? '');
  29. $lastName = (string) ($formData['nachname'] ?? '');
  30. $csrf = Csrf::token();
  31. ?><!doctype html>
  32. <html lang="de">
  33. <head>
  34. <meta charset="utf-8">
  35. <meta name="viewport" content="width=device-width, initial-scale=1">
  36. <title>Antragsdetails</title>
  37. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/tokens.css')) ?>">
  38. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/base.css')) ?>">
  39. </head>
  40. <body class="admin-page">
  41. <header class="site-header">
  42. <div class="container header-inner">
  43. <a class="brand" href="<?= htmlspecialchars(Bootstrap::url('admin/index.php')) ?>">
  44. <img class="brand-logo" src="<?= htmlspecialchars(Bootstrap::url('assets/images/feuerwehr-logo-invers.webp')) ?>" alt="Feuerwehr Logo">
  45. <div class="brand-title"><?= htmlspecialchars((string) ($app['project_name'] ?? 'Admin')) ?></div>
  46. </a>
  47. </div>
  48. </header>
  49. <main class="container">
  50. <section class="card">
  51. <p><a href="<?= htmlspecialchars(Bootstrap::url('admin/index.php')) ?>">Zur Übersicht</a></p>
  52. <div class="admin-detail-header">
  53. <h1>Antragsdetails</h1>
  54. <div class="admin-inline-actions">
  55. <form method="get" action="<?= htmlspecialchars(Bootstrap::url('admin/export-pdf.php')) ?>">
  56. <input type="hidden" name="id" value="<?= htmlspecialchars((string) ($submission['application_key'] ?? '')) ?>">
  57. <button type="submit" class="btn btn-small">Export als PDF</button>
  58. </form>
  59. <?php if (!empty($uploads)): ?>
  60. <form method="get" action="<?= htmlspecialchars(Bootstrap::url('admin/download-zip.php')) ?>">
  61. <input type="hidden" name="id" value="<?= htmlspecialchars((string) ($submission['application_key'] ?? '')) ?>">
  62. <button type="submit" class="btn btn-small">Alle Uploads als ZIP herunterladen</button>
  63. </form>
  64. <?php endif; ?>
  65. </div>
  66. </div>
  67. <div class="table-responsive">
  68. <table class="table-compact table-dense admin-meta-table">
  69. <tbody>
  70. <tr>
  71. <th>Vorname</th>
  72. <td><?= htmlspecialchars($firstName !== '' ? $firstName : '-') ?></td>
  73. <th>Nachname</th>
  74. <td><?= htmlspecialchars($lastName !== '' ? $lastName : '-') ?></td>
  75. </tr>
  76. <tr>
  77. <th>E-Mail</th>
  78. <td><?= htmlspecialchars((string) ($submission['email'] ?? '')) ?></td>
  79. <th>Eingereicht</th>
  80. <td><?= htmlspecialchars((string) ($submission['submitted_at'] ?? '')) ?></td>
  81. </tr>
  82. </tbody>
  83. </table>
  84. </div>
  85. <h2>Formulardaten</h2>
  86. <?php if ($formattedSteps === []): ?>
  87. <p>Keine Formulardaten vorhanden.</p>
  88. <?php else: ?>
  89. <?php foreach ($formattedSteps as $step): ?>
  90. <section class="admin-step-block">
  91. <h3><?= htmlspecialchars((string) ($step['title'] ?? '')) ?></h3>
  92. <div class="table-responsive">
  93. <table class="table-compact table-dense admin-form-data-table">
  94. <tbody>
  95. <?php foreach ((array) ($step['fields'] ?? []) as $field): ?>
  96. <tr>
  97. <th><?= htmlspecialchars((string) ($field['label'] ?? '')) ?></th>
  98. <td><?= nl2br(htmlspecialchars((string) ($field['value'] ?? '')), false) ?></td>
  99. </tr>
  100. <?php endforeach; ?>
  101. </tbody>
  102. </table>
  103. </div>
  104. </section>
  105. <?php endforeach; ?>
  106. <?php endif; ?>
  107. <h2>Uploads</h2>
  108. <?php if ($uploads === []): ?>
  109. <p>Keine Uploads vorhanden.</p>
  110. <?php else: ?>
  111. <?php $shownUploadKeys = []; ?>
  112. <?php foreach ($uploadFields as $fieldKey => $fieldDef):
  113. $files = $uploads[$fieldKey] ?? [];
  114. if (!is_array($files) || $files === []) {
  115. continue;
  116. }
  117. $shownUploadKeys[] = $fieldKey;
  118. $uploadLabel = (string) ($fieldDef['label'] ?? $fieldKey);
  119. ?>
  120. <div class="admin-upload-group">
  121. <h3><?= htmlspecialchars($uploadLabel) ?></h3>
  122. <ul class="admin-uploads-list">
  123. <?php foreach ($files as $idx => $file): ?>
  124. <li>
  125. <?= htmlspecialchars((string) ($file['original_filename'] ?? 'Datei')) ?>
  126. - <a href="<?= htmlspecialchars(Bootstrap::url('admin/download.php?id=' . urlencode((string) ($submission['application_key'] ?? '')) . '&field=' . urlencode((string) $fieldKey) . '&index=' . urlencode((string) $idx))) ?>">Download</a>
  127. </li>
  128. <?php endforeach; ?>
  129. </ul>
  130. </div>
  131. <?php endforeach; ?>
  132. <?php foreach ($uploads as $fieldKey => $files):
  133. if (in_array((string) $fieldKey, $shownUploadKeys, true) || !is_array($files) || $files === []) {
  134. continue;
  135. }
  136. ?>
  137. <div class="admin-upload-group">
  138. <h3><?= htmlspecialchars((string) $fieldKey) ?></h3>
  139. <ul class="admin-uploads-list">
  140. <?php foreach ($files as $idx => $file): ?>
  141. <li>
  142. <?= htmlspecialchars((string) ($file['original_filename'] ?? 'Datei')) ?>
  143. - <a href="<?= htmlspecialchars(Bootstrap::url('admin/download.php?id=' . urlencode((string) ($submission['application_key'] ?? '')) . '&field=' . urlencode((string) $fieldKey) . '&index=' . urlencode((string) $idx))) ?>">Download</a>
  144. </li>
  145. <?php endforeach; ?>
  146. </ul>
  147. </div>
  148. <?php endforeach; ?>
  149. <?php endif; ?>
  150. <h2>Löschen</h2>
  151. <form method="post" action="<?= htmlspecialchars(Bootstrap::url('admin/delete.php')) ?>" onsubmit="return confirm('Antrag wirklich löschen? Der Antrag wird für alle Benutzer unwiederbringlich entfernt.');">
  152. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  153. <input type="hidden" name="id" value="<?= htmlspecialchars((string) ($submission['application_key'] ?? '')) ?>">
  154. <button type="submit" class="btn">Antrag löschen</button>
  155. </form>
  156. </section>
  157. </main>
  158. </body>
  159. </html>