index.php 16 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327
  1. <?php
  2. declare(strict_types=1);
  3. use App\App\Bootstrap;
  4. use App\Form\FormSchema;
  5. use App\Security\Csrf;
  6. require __DIR__ . '/src/autoload.php';
  7. Bootstrap::init();
  8. $schema = new FormSchema();
  9. $steps = $schema->getSteps();
  10. $csrf = Csrf::token();
  11. $app = Bootstrap::config('app');
  12. $disclaimerConfigRaw = $app['disclaimer'] ?? [];
  13. if (is_string($disclaimerConfigRaw)) {
  14. $disclaimerConfig = ['text' => $disclaimerConfigRaw];
  15. } elseif (is_array($disclaimerConfigRaw)) {
  16. $disclaimerConfig = $disclaimerConfigRaw;
  17. } else {
  18. $disclaimerConfig = [];
  19. }
  20. $disclaimerTitle = (string) ($disclaimerConfig['title'] ?? 'Hinweis');
  21. $disclaimerText = (string) ($disclaimerConfig['text'] ?? '');
  22. $disclaimerAcceptLabel = (string) ($disclaimerConfig['accept_label'] ?? 'Hinweis gelesen, weiter');
  23. $startConfigRaw = $app['start'] ?? [];
  24. if (is_array($startConfigRaw)) {
  25. $startConfig = $startConfigRaw;
  26. } else {
  27. $startConfig = [];
  28. }
  29. $startIntroText = (string) ($startConfig['intro_text'] ?? 'Bitte E-Mail eingeben. Bestehende Entwürfe werden automatisch geladen.');
  30. $addressDisclaimerConfigRaw = $app['address_disclaimer'] ?? ($app['address_disclaimer_text'] ?? '');
  31. if (is_string($addressDisclaimerConfigRaw)) {
  32. $addressDisclaimerText = $addressDisclaimerConfigRaw;
  33. } elseif (is_array($addressDisclaimerConfigRaw)) {
  34. $addressDisclaimerText = (string) ($addressDisclaimerConfigRaw['text'] ?? '');
  35. } else {
  36. $addressDisclaimerText = '';
  37. }
  38. $baseUrl = Bootstrap::baseUrl();
  39. /** @param array<string, mixed> $field */
  40. function renderField(array $field, string $addressDisclaimerText): void
  41. {
  42. $keyRaw = (string) ($field['key'] ?? '');
  43. $key = htmlspecialchars($keyRaw);
  44. $label = htmlspecialchars((string) $field['label']);
  45. $type = (string) ($field['type'] ?? 'text');
  46. $requiredAlways = (bool) ($field['required'] ?? false);
  47. $requiredConditional = isset($field['required_if']) && is_array($field['required_if']);
  48. $required = $requiredAlways ? 'required' : '';
  49. $requiredLabel = '';
  50. if ($requiredAlways) {
  51. $requiredLabel = ' <span class="required-mark required-mark-field" aria-hidden="true">* Pflichtfeld</span>';
  52. } elseif ($requiredConditional) {
  53. $requiredLabel = ' <span class="required-mark required-mark-field" aria-hidden="true">* Pflichtfeld</span>';
  54. }
  55. $fieldClass = 'field';
  56. if ($requiredAlways || $requiredConditional) {
  57. $fieldClass .= ' mandatory-field';
  58. }
  59. if ($requiredAlways) {
  60. $fieldClass .= ' mandatory-field-hard';
  61. }
  62. echo '<div class="' . $fieldClass . '" data-field="' . $key . '">';
  63. if ($type === 'checkbox') {
  64. echo '<label class="checkbox-label"><input type="checkbox" name="form_data[' . $key . ']" value="1" ' . $required . '> ' . $label . $requiredLabel . '</label>';
  65. } else {
  66. $labelFor = $type === 'table' ? htmlspecialchars($keyRaw . '__r0__c0') : $key;
  67. echo '<label for="' . $labelFor . '">' . $label . $requiredLabel . '</label>';
  68. if ($type === 'textarea') {
  69. echo '<textarea id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '></textarea>';
  70. } elseif ($type === 'select') {
  71. echo '<select id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '>';
  72. echo '<option value="">Bitte wählen</option>';
  73. foreach (($field['options'] ?? []) as $option) {
  74. if (!is_array($option)) {
  75. continue;
  76. }
  77. $value = htmlspecialchars((string) ($option['value'] ?? ''));
  78. $optLabel = htmlspecialchars((string) ($option['label'] ?? ''));
  79. echo '<option value="' . $value . '">' . $optLabel . '</option>';
  80. }
  81. echo '</select>';
  82. } elseif ($type === 'table') {
  83. $rows = (int) ($field['rows'] ?? 4);
  84. if ($rows < 1) {
  85. $rows = 1;
  86. } elseif ($rows > 50) {
  87. $rows = 50;
  88. }
  89. $columns = [];
  90. if (isset($field['columns']) && is_array($field['columns'])) {
  91. foreach ($field['columns'] as $index => $column) {
  92. if (!is_array($column)) {
  93. continue;
  94. }
  95. $columnLabelRaw = trim((string) ($column['label'] ?? ''));
  96. if ($columnLabelRaw === '') {
  97. $columnLabelRaw = 'Spalte ' . ($index + 1);
  98. }
  99. $columnTypeRaw = strtolower(trim((string) ($column['type'] ?? 'text')));
  100. $columnType = in_array($columnTypeRaw, ['text', 'date', 'number', 'email', 'tel'], true) ? $columnTypeRaw : 'text';
  101. $columns[] = [
  102. 'label' => $columnLabelRaw,
  103. 'type' => $columnType,
  104. 'placeholder' => (string) ($column['placeholder'] ?? ''),
  105. ];
  106. }
  107. }
  108. if (empty($columns)) {
  109. $columns = [
  110. ['label' => 'Spalte 1', 'type' => 'text', 'placeholder' => ''],
  111. ['label' => 'Spalte 2', 'type' => 'text', 'placeholder' => ''],
  112. ['label' => 'Spalte 3', 'type' => 'text', 'placeholder' => ''],
  113. ];
  114. }
  115. echo '<input id="' . $key . '" type="hidden" name="form_data[' . $key . ']">';
  116. echo '<div class="table-input-wrapper">';
  117. echo '<div class="table-responsive">';
  118. echo '<table class="form-table-input" data-table-field="1" data-table-key="' . $key . '" data-table-rows="' . (string) $rows . '">';
  119. echo '<thead><tr>';
  120. foreach ($columns as $column) {
  121. echo '<th>' . htmlspecialchars($column['label']) . '</th>';
  122. }
  123. echo '</tr></thead>';
  124. echo '<tbody>';
  125. for ($row = 0; $row < $rows; $row++) {
  126. echo '<tr>';
  127. foreach ($columns as $columnIndex => $column) {
  128. $cellId = $keyRaw . '__r' . $row . '__c' . $columnIndex;
  129. $cellIdEscaped = htmlspecialchars($cellId);
  130. $placeholder = trim((string) ($column['placeholder'] ?? ''));
  131. $placeholderEscaped = htmlspecialchars($placeholder);
  132. $ariaLabel = htmlspecialchars($column['label'] . ' Zeile ' . ($row + 1));
  133. echo '<td>';
  134. echo '<input id="' . $cellIdEscaped . '" class="table-cell-input" type="' . htmlspecialchars((string) $column['type']) . '" data-table-cell="1" data-table-key="' . $key . '" data-row-index="' . (string) $row . '" data-col-index="' . (string) $columnIndex . '" aria-label="' . $ariaLabel . '" autocomplete="off"';
  135. if ($placeholder !== '') {
  136. echo ' placeholder="' . $placeholderEscaped . '"';
  137. }
  138. echo '>';
  139. echo '</td>';
  140. }
  141. echo '</tr>';
  142. }
  143. echo '</tbody>';
  144. echo '</table>';
  145. echo '</div>';
  146. echo '</div>';
  147. } elseif ($type === 'file') {
  148. $accept = htmlspecialchars((string) ($field['accept'] ?? ''));
  149. $description = trim((string) ($field['description'] ?? ''));
  150. $fileInputId = $key . '_file';
  151. $cameraInputId = $key . '_camera';
  152. echo '<div class="upload-control" data-upload-key="' . $key . '">';
  153. echo '<div class="upload-actions">';
  154. echo '<label class="upload-action-btn" for="' . $fileInputId . '">Datei auswählen</label>';
  155. echo '<label class="upload-action-btn upload-action-btn-camera" for="' . $cameraInputId . '">Foto aufnehmen</label>';
  156. echo '</div>';
  157. if ($description !== '') {
  158. echo '<small class="hint">' . nl2br(htmlspecialchars($description)) . '</small>';
  159. }
  160. echo '<input id="' . $fileInputId . '" class="upload-native-input" type="file" name="' . $key . '" accept="' . $accept . '">';
  161. echo '<input id="' . $cameraInputId . '" class="upload-native-input" type="file" name="' . $key . '__camera" accept="image/*" capture="environment">';
  162. echo '<p class="upload-selected" data-upload-selected="' . $key . '">Keine Datei gewählt</p>';
  163. echo '</div>';
  164. echo '<div class="upload-list" data-upload-list="' . $key . '"></div>';
  165. } else {
  166. $inputType = htmlspecialchars($type);
  167. echo '<input id="' . $key . '" type="' . $inputType . '" name="form_data[' . $key . ']" ' . $required . '>';
  168. }
  169. }
  170. $subtext = trim((string) ($field['subtext'] ?? ''));
  171. if ($subtext !== '') {
  172. echo '<small class="hint">' . nl2br(htmlspecialchars($subtext)) . '</small>';
  173. }
  174. if ($keyRaw === 'strasse' && trim($addressDisclaimerText) !== '') {
  175. echo '<div class="address-disclaimer">' . nl2br(htmlspecialchars($addressDisclaimerText)) . '</div>';
  176. }
  177. if (isset($field['required_if']) && is_array($field['required_if'])) {
  178. $depField = htmlspecialchars((string) ($field['required_if']['field'] ?? ''));
  179. $depValue = htmlspecialchars((string) ($field['required_if']['equals'] ?? ''));
  180. }
  181. echo '<div class="error" data-error-for="' . $key . '"></div>';
  182. echo '</div>';
  183. }
  184. ?><!doctype html>
  185. <html lang="de">
  186. <head>
  187. <meta charset="utf-8">
  188. <meta name="viewport" content="width=device-width, initial-scale=1">
  189. <title><?= htmlspecialchars((string) $app['project_name']) ?></title>
  190. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/tokens.css')) ?>">
  191. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/base.css')) ?>">
  192. </head>
  193. <body>
  194. <header class="site-header">
  195. <div class="container header-inner">
  196. <a class="brand" href="<?= htmlspecialchars(Bootstrap::url('index.php')) ?>">
  197. <img class="brand-logo" src="<?= htmlspecialchars(Bootstrap::url('assets/images/feuerwehr-logo-invers.webp')) ?>" alt="Feuerwehr Logo">
  198. <div>
  199. <div class="brand-title"><?= htmlspecialchars((string) $app['project_name']) ?></div>
  200. <div class="brand-subtitle">Feuerwehr Freising</div>
  201. </div>
  202. </a>
  203. </div>
  204. </header>
  205. <main class="container">
  206. <h1>Digitaler Mitgliedsantrag Feuerwehrverein</h1>
  207. <section id="disclaimerSection" class="card hidden">
  208. <h2><?= htmlspecialchars($disclaimerTitle) ?></h2>
  209. <p class="disclaimer-text"><?= nl2br(htmlspecialchars($disclaimerText)) ?></p>
  210. <div class="field disclaimer-ack-field">
  211. <label class="checkbox-label">
  212. <input id="disclaimerReadCheckbox" type="checkbox" value="1">
  213. Ich habe den Hinweis gelesen und verstanden.
  214. </label>
  215. <div id="disclaimerReadError" class="error"></div>
  216. </div>
  217. <button id="acceptDisclaimerBtn" type="button" class="btn" disabled><?= htmlspecialchars($disclaimerAcceptLabel) ?></button>
  218. </section>
  219. <section id="wizardSection" class="card hidden">
  220. <h2>Mitgliedsantrag</h2>
  221. <p class="required-legend"><span class="required-mark" aria-hidden="true">*</span> Pflichtfeld</p>
  222. <div id="progress" class="progress"></div>
  223. <form id="applicationForm" enctype="multipart/form-data" novalidate>
  224. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  225. <input type="hidden" id="applicationEmail" name="email" value="">
  226. <input type="hidden" id="applicationWebsite" name="website" value="">
  227. <?php foreach ($steps as $index => $step): ?>
  228. <section class="step hidden" data-step="<?= $index + 1 ?>">
  229. <h3>Schritt <?= $index + 1 ?>: <?= htmlspecialchars((string) ($step['title'] ?? '')) ?></h3>
  230. <p><?= htmlspecialchars((string) ($step['description'] ?? '')) ?></p>
  231. <?php foreach (($step['fields'] ?? []) as $field): ?>
  232. <?php if (is_array($field)) { renderField($field, $addressDisclaimerText); } ?>
  233. <?php endforeach; ?>
  234. </section>
  235. <?php endforeach; ?>
  236. <section id="summarySection" class="step-summary hidden">
  237. <h3>Zusammenfassung</h3>
  238. <p>Bitte prüfen Sie alle Angaben vor dem verbindlichen Absenden.</p>
  239. <div id="summaryMissingNotice" class="summary-missing-note hidden" role="status" aria-live="polite"></div>
  240. <div id="summaryContent" class="summary-content"></div>
  241. </section>
  242. <div class="wizard-actions">
  243. <button type="button" id="prevBtn" class="btn btn-secondary">Zurück</button>
  244. <button type="button" id="nextBtn" class="btn">Weiter</button>
  245. <button type="button" id="submitBtn" class="btn hidden">
  246. <span data-submit-label>Verbindlich absenden</span>
  247. <span id="submitSpinner" class="btn-spinner hidden" aria-hidden="true"></span>
  248. </button>
  249. </div>
  250. <p id="feedbackMessage" class="status-text" role="status" aria-live="polite"></p>
  251. </form>
  252. </section>
  253. <section id="startSection" class="card">
  254. <h2>Status</h2>
  255. <p id="startIntroText"><?= htmlspecialchars($startIntroText) ?></p>
  256. <form id="startForm" novalidate>
  257. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  258. <div class="hp-field" aria-hidden="true">
  259. <label for="website">Website</label>
  260. <input id="website" type="text" name="website" autocomplete="off" tabindex="-1">
  261. </div>
  262. <div class="field" id="startEmailField">
  263. <label for="startEmail">E-Mail <span class="required-mark required-mark-field-start" aria-hidden="true">* Pflichtfeld</span></label>
  264. <input id="startEmail" type="email" name="email" required inputmode="email" autocomplete="email">
  265. <div id="startEmailError" class="error"></div>
  266. </div>
  267. <div class="inline-actions" id="startActions">
  268. <button id="startSubmitBtn" type="submit" class="btn">Code senden</button>
  269. </div>
  270. <section id="otpSection" class="hidden" aria-live="polite">
  271. <p id="otpInfoText" class="status-text"></p>
  272. <div class="field" id="startOtpField">
  273. <label for="startOtp">Sicherheitscode <span class="required-mark required-mark-field-start" aria-hidden="true">* Pflichtfeld</span></label>
  274. <input id="startOtp" type="text" inputmode="numeric" autocomplete="one-time-code" maxlength="6" pattern="[0-9]{6}">
  275. <div id="startOtpError" class="error"></div>
  276. </div>
  277. <div class="inline-actions" id="otpActions">
  278. <button id="verifyOtpBtn" type="button" class="btn">Code bestätigen</button>
  279. <button id="resendOtpBtn" type="button" class="btn btn-secondary">Code erneut senden</button>
  280. </div>
  281. <p id="otpCooldownMessage" class="status-text"></p>
  282. </section>
  283. <div id="compactStatusBox" class="compact-status hidden">
  284. <p><strong>E-Mail:</strong> <span id="statusEmailValue">-</span></p>
  285. <p><strong>Speicherstatus:</strong> <span id="draftStatusValue">Noch nicht gespeichert</span></p>
  286. <button id="resetDataBtn" type="button" class="btn btn-small">Gespeicherte Daten löschen und neu starten</button>
  287. </div>
  288. <p id="startFeedbackMessage" class="status-text" role="status" aria-live="polite"></p>
  289. </form>
  290. </section>
  291. </main>
  292. <script>
  293. window.APP_BOOT = {
  294. steps: <?= json_encode($steps, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  295. csrf: <?= json_encode($csrf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  296. contactEmail: <?= json_encode((string) ($app['contact_email'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  297. baseUrl: <?= json_encode($baseUrl, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  298. verification: <?= json_encode((array) ($app['verification'] ?? []), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
  299. };
  300. </script>
  301. <script src="<?= htmlspecialchars(Bootstrap::url('assets/js/form.js')) ?>"></script>
  302. </body>
  303. </html>