index.php 17 KB

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