index.php 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234
  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. $addressDisclaimerConfigRaw = $app['address_disclaimer'] ?? ($app['address_disclaimer_text'] ?? '');
  24. if (is_string($addressDisclaimerConfigRaw)) {
  25. $addressDisclaimerText = $addressDisclaimerConfigRaw;
  26. } elseif (is_array($addressDisclaimerConfigRaw)) {
  27. $addressDisclaimerText = (string) ($addressDisclaimerConfigRaw['text'] ?? '');
  28. } else {
  29. $addressDisclaimerText = '';
  30. }
  31. $baseUrl = Bootstrap::baseUrl();
  32. /** @param array<string, mixed> $field */
  33. function renderField(array $field, string $addressDisclaimerText): void
  34. {
  35. $keyRaw = (string) ($field['key'] ?? '');
  36. $key = htmlspecialchars($keyRaw);
  37. $label = htmlspecialchars((string) $field['label']);
  38. $type = (string) ($field['type'] ?? 'text');
  39. $requiredAlways = (bool) ($field['required'] ?? false);
  40. $requiredConditional = isset($field['required_if']) && is_array($field['required_if']);
  41. $required = $requiredAlways ? 'required' : '';
  42. $requiredLabel = '';
  43. if ($requiredAlways) {
  44. $requiredLabel = ' <span class="required-mark required-mark-field" aria-hidden="true">* Pflichtfeld</span>';
  45. } elseif ($requiredConditional) {
  46. $requiredLabel = ' <span class="required-mark required-mark-field" aria-hidden="true">* Pflichtfeld</span>';
  47. }
  48. $fieldClass = 'field';
  49. if ($requiredAlways || $requiredConditional) {
  50. $fieldClass .= ' mandatory-field';
  51. }
  52. if ($requiredAlways) {
  53. $fieldClass .= ' mandatory-field-hard';
  54. }
  55. echo '<div class="' . $fieldClass . '" data-field="' . $key . '">';
  56. if ($type === 'checkbox') {
  57. echo '<label class="checkbox-label"><input type="checkbox" name="form_data[' . $key . ']" value="1" ' . $required . '> ' . $label . $requiredLabel . '</label>';
  58. } else {
  59. echo '<label for="' . $key . '">' . $label . $requiredLabel . '</label>';
  60. if ($type === 'textarea') {
  61. echo '<textarea id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '></textarea>';
  62. } elseif ($type === 'select') {
  63. echo '<select id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '>';
  64. echo '<option value="">Bitte wählen</option>';
  65. foreach (($field['options'] ?? []) as $option) {
  66. if (!is_array($option)) {
  67. continue;
  68. }
  69. $value = htmlspecialchars((string) ($option['value'] ?? ''));
  70. $optLabel = htmlspecialchars((string) ($option['label'] ?? ''));
  71. echo '<option value="' . $value . '">' . $optLabel . '</option>';
  72. }
  73. echo '</select>';
  74. } elseif ($type === 'file') {
  75. $accept = htmlspecialchars((string) ($field['accept'] ?? ''));
  76. $description = trim((string) ($field['description'] ?? ''));
  77. $fileInputId = $key . '_file';
  78. $cameraInputId = $key . '_camera';
  79. echo '<div class="upload-control" data-upload-key="' . $key . '">';
  80. echo '<div class="upload-actions">';
  81. echo '<label class="upload-action-btn" for="' . $fileInputId . '">Datei auswählen</label>';
  82. echo '<label class="upload-action-btn upload-action-btn-camera" for="' . $cameraInputId . '">Foto aufnehmen</label>';
  83. echo '</div>';
  84. if ($description !== '') {
  85. echo '<small class="hint">' . nl2br(htmlspecialchars($description)) . '</small>';
  86. }
  87. echo '<input id="' . $fileInputId . '" class="upload-native-input" type="file" name="' . $key . '" accept="' . $accept . '">';
  88. echo '<input id="' . $cameraInputId . '" class="upload-native-input" type="file" name="' . $key . '__camera" accept="image/*" capture="environment">';
  89. echo '<p class="upload-selected" data-upload-selected="' . $key . '">Keine Datei gewählt</p>';
  90. echo '</div>';
  91. echo '<div class="upload-list" data-upload-list="' . $key . '"></div>';
  92. } else {
  93. $inputType = htmlspecialchars($type);
  94. echo '<input id="' . $key . '" type="' . $inputType . '" name="form_data[' . $key . ']" ' . $required . '>';
  95. }
  96. }
  97. $subtext = trim((string) ($field['subtext'] ?? ''));
  98. if ($subtext !== '') {
  99. echo '<small class="hint">' . nl2br(htmlspecialchars($subtext)) . '</small>';
  100. }
  101. if ($keyRaw === 'strasse' && trim($addressDisclaimerText) !== '') {
  102. echo '<div class="address-disclaimer">' . nl2br(htmlspecialchars($addressDisclaimerText)) . '</div>';
  103. }
  104. if (isset($field['required_if']) && is_array($field['required_if'])) {
  105. $depField = htmlspecialchars((string) ($field['required_if']['field'] ?? ''));
  106. $depValue = htmlspecialchars((string) ($field['required_if']['equals'] ?? ''));
  107. }
  108. echo '<div class="error" data-error-for="' . $key . '"></div>';
  109. echo '</div>';
  110. }
  111. ?><!doctype html>
  112. <html lang="de">
  113. <head>
  114. <meta charset="utf-8">
  115. <meta name="viewport" content="width=device-width, initial-scale=1">
  116. <title><?= htmlspecialchars((string) $app['project_name']) ?></title>
  117. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/tokens.css')) ?>">
  118. <link rel="stylesheet" href="<?= htmlspecialchars(Bootstrap::url('assets/css/base.css')) ?>">
  119. </head>
  120. <body>
  121. <header class="site-header">
  122. <div class="container header-inner">
  123. <a class="brand" href="<?= htmlspecialchars(Bootstrap::url('index.php')) ?>">
  124. <img class="brand-logo" src="<?= htmlspecialchars(Bootstrap::url('assets/images/feuerwehr-Logo-invers.webp')) ?>" alt="Feuerwehr Logo">
  125. <div>
  126. <div class="brand-title"><?= htmlspecialchars((string) $app['project_name']) ?></div>
  127. <div class="brand-subtitle">Feuerwehr Freising</div>
  128. </div>
  129. </a>
  130. </div>
  131. </header>
  132. <main class="container">
  133. <h1>Digitaler Mitgliedsantrag Feuerwehrverein</h1>
  134. <section id="disclaimerSection" class="card">
  135. <h2><?= htmlspecialchars($disclaimerTitle) ?></h2>
  136. <p class="disclaimer-text"><?= nl2br(htmlspecialchars($disclaimerText)) ?></p>
  137. <div class="field disclaimer-ack-field">
  138. <label class="checkbox-label">
  139. <input id="disclaimerReadCheckbox" type="checkbox" value="1">
  140. Ich habe den Hinweis gelesen und verstanden.
  141. </label>
  142. <div id="disclaimerReadError" class="error"></div>
  143. </div>
  144. <button id="acceptDisclaimerBtn" type="button" class="btn" disabled><?= htmlspecialchars($disclaimerAcceptLabel) ?></button>
  145. </section>
  146. <section id="wizardSection" class="card hidden">
  147. <h2>Mitgliedsantrag</h2>
  148. <p class="required-legend"><span class="required-mark" aria-hidden="true">*</span> Pflichtfeld</p>
  149. <div id="progress" class="progress"></div>
  150. <form id="applicationForm" enctype="multipart/form-data" novalidate>
  151. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  152. <input type="hidden" id="applicationEmail" name="email" value="">
  153. <input type="hidden" id="applicationWebsite" name="website" value="">
  154. <?php foreach ($steps as $index => $step): ?>
  155. <section class="step hidden" data-step="<?= $index + 1 ?>">
  156. <h3>Schritt <?= $index + 1 ?>: <?= htmlspecialchars((string) ($step['title'] ?? '')) ?></h3>
  157. <p><?= htmlspecialchars((string) ($step['description'] ?? '')) ?></p>
  158. <?php foreach (($step['fields'] ?? []) as $field): ?>
  159. <?php if (is_array($field)) { renderField($field, $addressDisclaimerText); } ?>
  160. <?php endforeach; ?>
  161. </section>
  162. <?php endforeach; ?>
  163. <section id="summarySection" class="step-summary hidden">
  164. <h3>Zusammenfassung</h3>
  165. <p>Bitte prüfen Sie alle Angaben vor dem verbindlichen Absenden.</p>
  166. <div id="summaryMissingNotice" class="summary-missing-note hidden" role="status" aria-live="polite"></div>
  167. <div id="summaryContent" class="summary-content"></div>
  168. </section>
  169. <div class="wizard-actions">
  170. <button type="button" id="prevBtn" class="btn btn-secondary">Zurück</button>
  171. <button type="button" id="nextBtn" class="btn">Weiter</button>
  172. <button type="button" id="submitBtn" class="btn hidden">
  173. <span data-submit-label>Verbindlich absenden</span>
  174. <span id="submitSpinner" class="btn-spinner hidden" aria-hidden="true"></span>
  175. </button>
  176. </div>
  177. <p id="feedbackMessage" class="status-text" role="status" aria-live="polite"></p>
  178. </form>
  179. </section>
  180. <section id="startSection" class="card hidden">
  181. <h2>Status</h2>
  182. <p id="startIntroText">Bitte E-Mail eingeben. Bestehende Entwürfe werden automatisch geladen.</p>
  183. <form id="startForm" novalidate>
  184. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  185. <div class="hp-field" aria-hidden="true">
  186. <label for="website">Website</label>
  187. <input id="website" type="text" name="website" autocomplete="off" tabindex="-1">
  188. </div>
  189. <div class="field" id="startEmailField">
  190. <label for="startEmail">E-Mail <span class="required-mark required-mark-field-start" aria-hidden="true">* Pflichtfeld</span></label>
  191. <input id="startEmail" type="email" name="email" required inputmode="email" autocomplete="email">
  192. <div id="startEmailError" class="error"></div>
  193. </div>
  194. <div class="inline-actions" id="startActions">
  195. <button id="startSubmitBtn" type="submit" class="btn">Formular laden</button>
  196. </div>
  197. <div id="compactStatusBox" class="compact-status hidden">
  198. <p><strong>E-Mail:</strong> <span id="statusEmailValue">-</span></p>
  199. <p><strong>Speicherstatus:</strong> <span id="draftStatusValue">Noch nicht gespeichert</span></p>
  200. <button id="resetDataBtn" type="button" class="btn btn-small">Gespeicherte Daten löschen und neu starten</button>
  201. </div>
  202. <p id="startFeedbackMessage" class="status-text" role="status" aria-live="polite"></p>
  203. </form>
  204. </section>
  205. </main>
  206. <script>
  207. window.APP_BOOT = {
  208. steps: <?= json_encode($steps, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  209. csrf: <?= json_encode($csrf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  210. contactEmail: <?= json_encode((string) ($app['contact_email'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  211. baseUrl: <?= json_encode($baseUrl, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
  212. };
  213. </script>
  214. <script src="<?= htmlspecialchars(Bootstrap::url('assets/js/form.js')) ?>"></script>
  215. </body>
  216. </html>