index.php 8.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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. /** @param array<string, mixed> $field */
  24. function renderField(array $field): void
  25. {
  26. $key = htmlspecialchars((string) $field['key']);
  27. $label = htmlspecialchars((string) $field['label']);
  28. $type = (string) ($field['type'] ?? 'text');
  29. $required = ((bool) ($field['required'] ?? false)) ? 'required' : '';
  30. echo '<div class="field" data-field="' . $key . '">';
  31. if ($type === 'checkbox') {
  32. echo '<label class="checkbox-label"><input type="checkbox" name="form_data[' . $key . ']" value="1" ' . $required . '> ' . $label . '</label>';
  33. } else {
  34. echo '<label for="' . $key . '">' . $label . '</label>';
  35. if ($type === 'textarea') {
  36. echo '<textarea id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '></textarea>';
  37. } elseif ($type === 'select') {
  38. echo '<select id="' . $key . '" name="form_data[' . $key . ']" ' . $required . '>';
  39. echo '<option value="">Bitte wählen</option>';
  40. foreach (($field['options'] ?? []) as $option) {
  41. if (!is_array($option)) {
  42. continue;
  43. }
  44. $value = htmlspecialchars((string) ($option['value'] ?? ''));
  45. $optLabel = htmlspecialchars((string) ($option['label'] ?? ''));
  46. echo '<option value="' . $value . '">' . $optLabel . '</option>';
  47. }
  48. echo '</select>';
  49. } elseif ($type === 'file') {
  50. $accept = htmlspecialchars((string) ($field['accept'] ?? ''));
  51. $fileInputId = $key . '_file';
  52. $cameraInputId = $key . '_camera';
  53. echo '<div class="upload-control" data-upload-key="' . $key . '">';
  54. echo '<div class="upload-actions">';
  55. echo '<label class="upload-action-btn" for="' . $fileInputId . '">Datei auswählen</label>';
  56. echo '<label class="upload-action-btn upload-action-btn-camera" for="' . $cameraInputId . '">Foto aufnehmen</label>';
  57. echo '</div>';
  58. echo '<input id="' . $fileInputId . '" class="upload-native-input" type="file" name="' . $key . '" accept="' . $accept . '">';
  59. echo '<input id="' . $cameraInputId . '" class="upload-native-input" type="file" name="' . $key . '__camera" accept="image/*" capture="environment">';
  60. echo '<p class="upload-selected" data-upload-selected="' . $key . '">Keine Datei gewählt</p>';
  61. echo '</div>';
  62. echo '<div class="upload-list" data-upload-list="' . $key . '"></div>';
  63. } else {
  64. $inputType = htmlspecialchars($type);
  65. echo '<input id="' . $key . '" type="' . $inputType . '" name="form_data[' . $key . ']" ' . $required . '>';
  66. }
  67. }
  68. if (isset($field['required_if']) && is_array($field['required_if'])) {
  69. $depField = htmlspecialchars((string) ($field['required_if']['field'] ?? ''));
  70. $depValue = htmlspecialchars((string) ($field['required_if']['equals'] ?? ''));
  71. echo '<small class="hint">Pflicht, wenn ' . $depField . ' = ' . $depValue . '.</small>';
  72. }
  73. echo '<div class="error" data-error-for="' . $key . '"></div>';
  74. echo '</div>';
  75. }
  76. ?><!doctype html>
  77. <html lang="de">
  78. <head>
  79. <meta charset="utf-8">
  80. <meta name="viewport" content="width=device-width, initial-scale=1">
  81. <title><?= htmlspecialchars((string) $app['project_name']) ?></title>
  82. <link rel="stylesheet" href="/assets/css/tokens.css">
  83. <link rel="stylesheet" href="/assets/css/base.css">
  84. </head>
  85. <body>
  86. <header class="site-header">
  87. <div class="container header-inner">
  88. <a class="brand" href="/">
  89. <img class="brand-logo" src="/assets/images/feuerwehr-Logo-invers.webp" alt="Feuerwehr Logo">
  90. <div>
  91. <div class="brand-title"><?= htmlspecialchars((string) $app['project_name']) ?></div>
  92. <div class="brand-subtitle">Feuerwehr Freising</div>
  93. </div>
  94. </a>
  95. </div>
  96. </header>
  97. <main class="container">
  98. <h1>Digitaler Mitgliedsantrag Feuerwehrverein</h1>
  99. <section id="disclaimerSection" class="card">
  100. <h2><?= htmlspecialchars($disclaimerTitle) ?></h2>
  101. <p class="disclaimer-text"><?= nl2br(htmlspecialchars($disclaimerText)) ?></p>
  102. <button id="acceptDisclaimerBtn" type="button" class="btn"><?= htmlspecialchars($disclaimerAcceptLabel) ?></button>
  103. </section>
  104. <section id="startSection" class="card hidden">
  105. <h2>Start</h2>
  106. <p id="startIntroText">Bitte E-Mail eingeben. Bestehende Entwürfe werden automatisch geladen.</p>
  107. <form id="startForm" novalidate>
  108. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  109. <div class="hp-field" aria-hidden="true">
  110. <label for="website">Website</label>
  111. <input id="website" type="text" name="website" autocomplete="off" tabindex="-1">
  112. </div>
  113. <div class="field" id="startEmailField">
  114. <label for="startEmail">E-Mail</label>
  115. <input id="startEmail" type="email" name="email" required inputmode="email" autocomplete="email">
  116. </div>
  117. <div class="inline-actions" id="startActions">
  118. <button id="startSubmitBtn" type="submit" class="btn">Formular laden</button>
  119. </div>
  120. <div id="compactStatusBox" class="compact-status hidden">
  121. <p><strong>E-Mail:</strong> <span id="statusEmailValue">-</span></p>
  122. <p><strong>Speicherstatus:</strong> <span id="draftStatusValue">Noch nicht gespeichert</span></p>
  123. <button id="resetDataBtn" type="button" class="btn btn-secondary btn-small">Gespeicherte Daten löschen und neu starten</button>
  124. </div>
  125. <p id="feedbackMessage" class="status-text" role="status" aria-live="polite"></p>
  126. </form>
  127. </section>
  128. <section id="wizardSection" class="card hidden">
  129. <h2>Mitgliedsantrag</h2>
  130. <div id="progress" class="progress"></div>
  131. <form id="applicationForm" enctype="multipart/form-data" novalidate>
  132. <input type="hidden" name="csrf" value="<?= htmlspecialchars($csrf) ?>">
  133. <input type="hidden" id="applicationEmail" name="email" value="">
  134. <input type="hidden" id="applicationWebsite" name="website" value="">
  135. <?php foreach ($steps as $index => $step): ?>
  136. <section class="step hidden" data-step="<?= $index + 1 ?>">
  137. <h3>Schritt <?= $index + 1 ?>: <?= htmlspecialchars((string) ($step['title'] ?? '')) ?></h3>
  138. <p><?= htmlspecialchars((string) ($step['description'] ?? '')) ?></p>
  139. <?php foreach (($step['fields'] ?? []) as $field): ?>
  140. <?php if (is_array($field)) { renderField($field); } ?>
  141. <?php endforeach; ?>
  142. </section>
  143. <?php endforeach; ?>
  144. <div class="wizard-actions">
  145. <button type="button" id="prevBtn" class="btn btn-secondary">Zurück</button>
  146. <button type="button" id="nextBtn" class="btn">Weiter</button>
  147. <button type="button" id="submitBtn" class="btn hidden">Verbindlich absenden</button>
  148. </div>
  149. </form>
  150. </section>
  151. </main>
  152. <script>
  153. window.APP_BOOT = {
  154. steps: <?= json_encode($steps, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  155. csrf: <?= json_encode($csrf, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>,
  156. contactEmail: <?= json_encode((string) ($app['contact_email'] ?? ''), JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>
  157. };
  158. </script>
  159. <script src="/assets/js/form.js"></script>
  160. </body>
  161. </html>