index.php 7.5 KB

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