rebuild events
All checks were successful
Deploy / deploy (push) Successful in 59s

This commit is contained in:
2026-08-04 20:59:40 +02:00
parent 1a58ec91de
commit 9cfa26a031
11 changed files with 489 additions and 50 deletions

View File

@@ -32,6 +32,66 @@ $latValue = $editingEvent ? (string)($editEvent['lat'] ?? '') : (string)($editLi
$lngValue = $editingEvent ? (string)($editEvent['lng'] ?? '') : (string)($editListing['lng'] ?? '');
$visibilityValue = $editingEvent ? (string)($editEvent['visibility'] ?? 'public') : (string)($editListing['visibility'] ?? 'public');
$categorySlugValue = $editingListing ? (string)($editListing['category_slug'] ?? '') : '';
$openingHoursValue = $editingListing ? (string)($editListing['opening_hours_note'] ?? '') : '';
$recurrenceRuleValue = $editingListing ? (string)($editListing['recurrence_rule'] ?? '') : '';
$recurrenceUntilValue = '';
if ($editingListing && !empty($editListing['recurrence_until'])) {
$recurrenceUntilValue = date('Y-m-d\TH:i', strtotime((string)$editListing['recurrence_until']));
}
$recurrenceModeValue = 'single';
if (str_contains($recurrenceRuleValue, 'FREQ=DAILY')) {
$recurrenceModeValue = 'daily';
} elseif (str_contains($recurrenceRuleValue, 'BYDAY=MO,TU,WE,TH,FR')) {
$recurrenceModeValue = 'weekdays';
} elseif (str_contains($recurrenceRuleValue, 'BYDAY=')) {
$recurrenceModeValue = 'custom_weekdays';
} elseif (str_contains($recurrenceRuleValue, 'FREQ=WEEKLY')) {
$recurrenceModeValue = 'weekly';
}
$selectedWeekdays = [];
if (preg_match('/BYDAY=([A-Z,]+)/', $recurrenceRuleValue, $matches)) {
$map = ['MO' => 'mo', 'TU' => 'di', 'WE' => 'mi', 'TH' => 'do', 'FR' => 'fr', 'SA' => 'sa', 'SU' => 'so'];
foreach (explode(',', $matches[1]) as $day) {
if (isset($map[$day])) {
$selectedWeekdays[] = $map[$day];
}
}
}
$priceModeValue = 'none';
$freeChildUntilAge = '';
$priceChildAmount = '';
$priceChildAgeFrom = '';
$priceChildAgeTo = '';
$priceAdultAmount = '';
$priceAdultAgeFrom = '';
if ($editingListing && !empty($editListing['prices']) && is_array($editListing['prices'])) {
foreach ($editListing['prices'] as $priceRow) {
$audience = (string)($priceRow['audience'] ?? '');
$priceType = (string)($priceRow['price_type'] ?? '');
$note = (string)($priceRow['note'] ?? '');
if ($priceType === 'free') {
$priceModeValue = 'free_child_rule';
if (preg_match('/bis\s+(\d+)/u', $note, $m)) {
$freeChildUntilAge = $m[1];
}
} elseif ($audience === 'child') {
$priceModeValue = 'paid';
$priceChildAmount = (string)($priceRow['amount'] ?? '');
if (preg_match('/ab\s+(\d+)/u', $note, $m)) {
$priceChildAgeFrom = $m[1];
}
if (preg_match('/bis\s+(\d+)/u', $note, $m)) {
$priceChildAgeTo = $m[1];
}
} elseif ($audience === 'adult') {
$priceModeValue = 'paid';
$priceAdultAmount = (string)($priceRow['amount'] ?? '');
if (preg_match('/ab\s+(\d+)/u', $note, $m)) {
$priceAdultAgeFrom = $m[1];
}
}
}
}
$editingChild = isset($editChild) && $editChild !== null;
$childAction = $editingChild ? 'child_update' : 'child_add';
$childModalTitle = $editingChild ? 'Kind bearbeiten' : 'Kind hinzufügen';
@@ -857,6 +917,13 @@ if (!empty($canManageSystemSettings)) {
<?php if ($editingListing && $editListing): ?>
<input type="hidden" name="listing_id" value="<?= (int)$editListing['id'] ?>">
<?php endif; ?>
<datalist id="existingPlacesList">
<?php foreach ($placeSuggestions as $placeSuggestion): ?>
<option value="<?= htmlspecialchars((string)$placeSuggestion['title'], ENT_QUOTES) ?>" data-place='<?= htmlspecialchars(json_encode($placeSuggestion, JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES), ENT_QUOTES) ?>'>
<?= htmlspecialchars(trim(implode(', ', array_filter([(string)($placeSuggestion['street'] ?? ''), trim((string)($placeSuggestion['zip'] ?? '') . ' ' . (string)($placeSuggestion['city'] ?? '')), (string)($placeSuggestion['region'] ?? '')]))), ENT_QUOTES) ?>
</option>
<?php endforeach; ?>
</datalist>
<?php if (!$editing): ?>
<div class="stack gap-8">
<label class="label">Was möchtest du anlegen?</label>
@@ -875,19 +942,24 @@ if (!empty($canManageSystemSettings)) {
</p>
</div>
<?php endif; ?>
<div class="form-grid">
<div class="form-grid" id="titleDescriptionRow">
<div class="stack gap-6">
<label class="label" for="evTitle">Titel</label>
<input id="evTitle" name="title" class="input" placeholder="z. B. Väter-Kaffee im Park" required value="<?= htmlspecialchars($titleValue, ENT_QUOTES) ?>">
</div>
<div class="stack gap-6">
<label class="label" for="evTeaser">Kurzbeschreibung</label>
<input id="evTeaser" name="teaser" class="input" placeholder="Kurztext für Gäste" required value="<?= htmlspecialchars($teaserValue, ENT_QUOTES) ?>">
</div>
</div>
<div class="stack gap-6">
<label class="label" for="evDesc">Beschreibung (voll)</label>
<textarea id="evDesc" name="description" class="textarea" rows="3" placeholder="Was soll passieren, was mitbringen?" required><?= htmlspecialchars($descriptionValue, ENT_QUOTES) ?></textarea>
<p class="muted small" style="margin:0;">Die Kurzbeschreibung wird intern automatisch aus deinem Text erzeugt.</p>
</div>
<div class="stack gap-6" id="placeLookupWrap">
<label class="label" for="existingPlaceLookup">Vorhandenen Ort suchen (optional)</label>
<div class="flex gap-8" style="flex-wrap:wrap;">
<input id="existingPlaceLookup" class="input" list="existingPlacesList" placeholder="z. B. Tierpark, Café, Spielplatz" style="flex:1;">
<button class="btn ghost" type="button" id="btnUseExistingPlace">Ort übernehmen</button>
</div>
<p class="muted small" style="margin:0;">Wenn ein passender Ort schon existiert, kannst du ihn übernehmen. Falls nichts passt, legst du unten einfach einen neuen Ort an.</p>
</div>
<div class="form-grid" id="eventDateRow">
<div class="stack gap-6">
@@ -911,6 +983,32 @@ if (!empty($canManageSystemSettings)) {
</select>
<p class="muted small" style="margin:0;">Für Orte und sonstige Veranstaltungen, damit Spielplatz, Café, Restaurant, Zoo oder Zirkus sauber unterscheidbar bleiben.</p>
</div>
<div class="stack gap-6" id="placeOpeningHoursWrap">
<label class="label" for="openingHoursNote">Öffnungszeiten / Hinweise</label>
<textarea id="openingHoursNote" name="opening_hours_note" class="textarea" rows="2" placeholder="z. B. täglich 10:00 bis 18:00 Uhr"><?= htmlspecialchars($openingHoursValue, ENT_QUOTES) ?></textarea>
</div>
<div class="stack gap-6" id="eventRecurrenceWrap">
<label class="label" for="recurrenceMode">Wiederholung</label>
<select id="recurrenceMode" name="recurrence_mode" class="select">
<option value="single" <?= $recurrenceModeValue === 'single' ? 'selected' : '' ?>>Einmalig</option>
<option value="daily" <?= $recurrenceModeValue === 'daily' ? 'selected' : '' ?>>Täglich</option>
<option value="weekly" <?= $recurrenceModeValue === 'weekly' ? 'selected' : '' ?>>Wöchentlich</option>
<option value="weekdays" <?= $recurrenceModeValue === 'weekdays' ? 'selected' : '' ?>>Montag bis Freitag</option>
<option value="custom_weekdays" <?= $recurrenceModeValue === 'custom_weekdays' ? 'selected' : '' ?>>Bestimmte Wochentage</option>
</select>
<div class="chips" id="recurrenceWeekdaysWrap" style="flex-wrap:wrap;">
<?php foreach (['mo' => 'Mo', 'di' => 'Di', 'mi' => 'Mi', 'do' => 'Do', 'fr' => 'Fr', 'sa' => 'Sa', 'so' => 'So'] as $weekdayValue => $weekdayLabel): ?>
<label class="chip" style="cursor:pointer;">
<input type="checkbox" name="recurrence_weekdays[]" value="<?= htmlspecialchars($weekdayValue, ENT_QUOTES) ?>" <?= in_array($weekdayValue, $selectedWeekdays, true) ? 'checked' : '' ?> style="margin-right:6px;">
<?= htmlspecialchars($weekdayLabel, ENT_QUOTES) ?>
</label>
<?php endforeach; ?>
</div>
<div class="stack gap-6">
<label class="label" for="recurrenceUntil">Wiederholen bis</label>
<input id="recurrenceUntil" name="recurrence_until" class="input" type="datetime-local" value="<?= htmlspecialchars($recurrenceUntilValue, ENT_QUOTES) ?>">
</div>
</div>
<div class="form-grid">
<div class="stack gap-6">
<label class="label" for="evZip">PLZ</label>
@@ -933,9 +1031,11 @@ if (!empty($canManageSystemSettings)) {
</div>
</div>
<div class="flex gap-8" style="flex-wrap:wrap; align-items:center;">
<button class="btn ghost" type="button" id="btnEventAddressSearch">Adresse suchen</button>
<button class="btn ghost" type="button" id="btnAddrToMap">Adresse auf Karte setzen</button>
<span class="muted small">Hält Karte und Adresse synchron.</span>
</div>
<div id="eventAddressStatus" class="muted small" style="margin:0;"></div>
<input type="hidden" id="evLat" name="lat" value="<?= htmlspecialchars($latValue, ENT_QUOTES) ?>">
<input type="hidden" id="evLng" name="lng" value="<?= htmlspecialchars($lngValue, ENT_QUOTES) ?>">
<div class="stack gap-6">
@@ -961,6 +1061,46 @@ if (!empty($canManageSystemSettings)) {
</select>
</div>
</div>
<div class="stack gap-10" id="eventPricingWrap">
<label class="label" for="priceMode">Eintritt / Kosten</label>
<select id="priceMode" name="price_mode" class="select">
<option value="none" <?= $priceModeValue === 'none' ? 'selected' : '' ?>>Keine Preisangabe</option>
<option value="free_child_rule" <?= $priceModeValue === 'free_child_rule' ? 'selected' : '' ?>>Frei für Kinder bis zu einem Alter</option>
<option value="paid" <?= $priceModeValue === 'paid' ? 'selected' : '' ?>>Bezahlter Eintritt</option>
</select>
<div class="form-grid" id="freeChildRuleWrap">
<div class="stack gap-6">
<label class="label" for="freeChildUntilAge">Kinder frei bis Alter</label>
<input id="freeChildUntilAge" name="free_child_until_age" class="input" type="number" min="0" max="25" value="<?= htmlspecialchars($freeChildUntilAge, ENT_QUOTES) ?>">
</div>
</div>
<div class="stack gap-12" id="paidPricingWrap">
<div class="form-grid">
<div class="stack gap-6">
<label class="label" for="priceChildAmount">Preis pro Kind</label>
<input id="priceChildAmount" name="price_child_amount" class="input" inputmode="decimal" placeholder="z. B. 12,50" value="<?= htmlspecialchars($priceChildAmount, ENT_QUOTES) ?>">
</div>
<div class="stack gap-6">
<label class="label" for="priceAdultAmount">Preis pro Erwachsener</label>
<input id="priceAdultAmount" name="price_adult_amount" class="input" inputmode="decimal" placeholder="z. B. 18,00" value="<?= htmlspecialchars($priceAdultAmount, ENT_QUOTES) ?>">
</div>
</div>
<div class="form-grid">
<div class="stack gap-6">
<label class="label" for="priceChildAgeFrom">Kind ab Alter</label>
<input id="priceChildAgeFrom" name="price_child_age_from" class="input" type="number" min="0" max="25" value="<?= htmlspecialchars($priceChildAgeFrom, ENT_QUOTES) ?>">
</div>
<div class="stack gap-6">
<label class="label" for="priceChildAgeTo">Kind bis Alter</label>
<input id="priceChildAgeTo" name="price_child_age_to" class="input" type="number" min="0" max="25" value="<?= htmlspecialchars($priceChildAgeTo, ENT_QUOTES) ?>">
</div>
</div>
<div class="stack gap-6">
<label class="label" for="priceAdultAgeFrom">Erwachsener ab Alter</label>
<input id="priceAdultAgeFrom" name="price_adult_age_from" class="input" type="number" min="0" max="25" value="<?= htmlspecialchars($priceAdultAgeFrom, ENT_QUOTES) ?>">
</div>
</div>
</div>
<label class="label" id="eventKidsWrap" style="display:flex; align-items:center; gap:8px;">
<input type="checkbox" name="allow_kids" <?= $allowNoKidsChecked ? 'checked' : '' ?>> Event ohne Kinder
</label>
@@ -999,6 +1139,8 @@ if (!empty($canManageSystemSettings)) {
const mapContainer = document.getElementById('mapContainer');
const btnMapSearch = document.getElementById('btnMapSearch');
const btnAddrToMap = document.getElementById('btnAddrToMap');
const btnEventAddressSearch = document.getElementById('btnEventAddressSearch');
const eventAddressStatus = document.getElementById('eventAddressStatus');
const mapSearch = document.getElementById('mapSearch');
const latInput = document.getElementById('evLat');
const lngInput = document.getElementById('evLng');
@@ -1009,8 +1151,19 @@ if (!empty($canManageSystemSettings)) {
const eventLocationLabelWrap = document.getElementById('eventLocationLabelWrap');
const eventCategoryWrap = document.getElementById('eventCategoryWrap');
const eventKidsWrap = document.getElementById('eventKidsWrap');
const eventPricingWrap = document.getElementById('eventPricingWrap');
const placeLookupWrap = document.getElementById('placeLookupWrap');
const placeOpeningHoursWrap = document.getElementById('placeOpeningHoursWrap');
const eventRecurrenceWrap = document.getElementById('eventRecurrenceWrap');
const eventDateInput = document.getElementById('evDate');
const categorySelect = document.getElementById('listingCategorySlug');
const priceModeSelect = document.getElementById('priceMode');
const freeChildRuleWrap = document.getElementById('freeChildRuleWrap');
const paidPricingWrap = document.getElementById('paidPricingWrap');
const recurrenceModeSelect = document.getElementById('recurrenceMode');
const recurrenceWeekdaysWrap = document.getElementById('recurrenceWeekdaysWrap');
const existingPlaceLookup = document.getElementById('existingPlaceLookup');
const btnUseExistingPlace = document.getElementById('btnUseExistingPlace');
const streetInput = document.getElementById('evStreet');
const zipInput = document.getElementById('evZip');
const cityInput = document.getElementById('evCity');
@@ -1030,6 +1183,24 @@ if (!empty($canManageSystemSettings)) {
const profileAddressResults = document.getElementById('profileAddressResults');
const profileAddressResultsModal = document.getElementById('modalProfileAddressResults');
let map, marker;
const existingPlaces = <?= json_encode($placeSuggestions ?? [], JSON_UNESCAPED_UNICODE | JSON_UNESCAPED_SLASHES) ?>;
function normalizeGeoResult(result) {
const address = result.address || {};
const street = [address.road || '', address.house_number || ''].filter(Boolean).join(' ').trim();
const region = address.city_district || address.suburb || address.state || address.county || address.region || address.state_district || '';
const city = address.city || address.town || address.village || '';
return {
label: result.display_name || '',
street,
zip: address.postcode || '',
city,
region,
lat: parseFloat(result.lat),
lng: parseFloat(result.lon),
};
}
function syncEventEntryKind(nextKind) {
const kind = nextKind || entryKindInput?.value || 'event';
@@ -1037,7 +1208,7 @@ if (!empty($canManageSystemSettings)) {
entryKindButtons.forEach((button) => {
const active = button.getAttribute('data-entry-kind-choice') === kind;
button.classList.toggle('is-active', active);
button.className = active ? 'btn' : 'btn ghost';
button.setAttribute('aria-pressed', active ? 'true' : 'false');
});
@@ -1057,6 +1228,23 @@ if (!empty($canManageSystemSettings)) {
if (eventCategoryWrap) eventCategoryWrap.hidden = kind === 'event';
if (categorySelect) categorySelect.required = kind !== 'event';
if (eventKidsWrap) eventKidsWrap.hidden = kind !== 'event';
if (eventPricingWrap) eventPricingWrap.hidden = kind === 'event';
if (placeLookupWrap) placeLookupWrap.hidden = kind === 'event';
if (placeOpeningHoursWrap) placeOpeningHoursWrap.hidden = kind !== 'place';
if (eventRecurrenceWrap) eventRecurrenceWrap.hidden = kind !== 'editorial_event';
syncPriceModeVisibility();
syncRecurrenceVisibility();
}
function syncPriceModeVisibility() {
const mode = priceModeSelect?.value || 'none';
if (freeChildRuleWrap) freeChildRuleWrap.hidden = mode !== 'free_child_rule';
if (paidPricingWrap) paidPricingWrap.hidden = mode !== 'paid';
}
function syncRecurrenceVisibility() {
const mode = recurrenceModeSelect?.value || 'single';
if (recurrenceWeekdaysWrap) recurrenceWeekdaysWrap.hidden = mode !== 'custom_weekdays';
}
entryKindButtons.forEach((button) => {
@@ -1064,8 +1252,36 @@ if (!empty($canManageSystemSettings)) {
syncEventEntryKind(button.getAttribute('data-entry-kind-choice') || 'event');
});
});
priceModeSelect?.addEventListener('change', syncPriceModeVisibility);
recurrenceModeSelect?.addEventListener('change', syncRecurrenceVisibility);
syncEventEntryKind(entryKindInput?.value || 'event');
syncPriceModeVisibility();
syncRecurrenceVisibility();
function applyExistingPlace(place) {
if (!place) return;
if (document.getElementById('evTitle') && !document.getElementById('evTitle').value.trim()) {
document.getElementById('evTitle').value = place.title || '';
}
if (streetInput) streetInput.value = place.street || '';
if (zipInput) zipInput.value = place.zip || '';
if (cityInput) cityInput.value = place.city || '';
if (regionInput) regionInput.value = place.region || '';
if (categorySelect && place.place_kind) categorySelect.value = place.place_kind;
}
btnUseExistingPlace?.addEventListener('click', () => {
const query = (existingPlaceLookup?.value || '').trim().toLowerCase();
if (!query) return;
const match = existingPlaces.find((place) => String(place.title || '').trim().toLowerCase() === query);
if (match) {
applyExistingPlace(match);
if (eventAddressStatus) eventAddressStatus.textContent = 'Vorhandener Ort übernommen.';
return;
}
if (eventAddressStatus) eventAddressStatus.textContent = 'Kein vorhandener Ort exakt gefunden. Du kannst unten einen neuen Ort anlegen.';
});
function ensureLeaflet(callback) {
if (!window.PKTConsent || !window.PKTConsent.has('external_services')) {
@@ -1248,6 +1464,32 @@ if (!empty($canManageSystemSettings)) {
geocodeAndPlace(parts.join(', '));
});
btnEventAddressSearch?.addEventListener('click', () => {
const parts = [
streetInput?.value || '',
zipInput?.value || '',
cityInput?.value || '',
regionInput?.value || '',
].map(v => v.trim()).filter(Boolean);
if (!parts.length) {
alert('Bitte zuerst mindestens einen Teil der Adresse eingeben.');
return;
}
if (eventAddressStatus) eventAddressStatus.textContent = 'Suche passende Adressen ...';
geocodeAddressCandidates(parts.join(', '), (results) => {
const first = results?.[0];
if (!first) return;
const normalized = normalizeGeoResult(first);
if (streetInput && normalized.street) streetInput.value = normalized.street;
if (zipInput && normalized.zip) zipInput.value = normalized.zip;
if (cityInput && normalized.city) cityInput.value = normalized.city;
if (regionInput) regionInput.value = normalized.region;
if (latInput) latInput.value = Number.isNaN(normalized.lat) ? '' : normalized.lat.toFixed(7);
if (lngInput) lngInput.value = Number.isNaN(normalized.lng) ? '' : normalized.lng.toFixed(7);
if (eventAddressStatus) eventAddressStatus.textContent = `Gewählte Adresse: ${normalized.label || [normalized.street, `${normalized.zip} ${normalized.city}`.trim(), normalized.region].filter(Boolean).join(', ')}`;
});
});
(function(){
const setProfileStatus = (message = '') => {
if (!profileAddressStatus) return;
@@ -1272,20 +1514,7 @@ if (!empty($canManageSystemSettings)) {
};
const normalizeResult = (result) => {
const address = result.address || {};
const street = [address.road || '', address.house_number || ''].filter(Boolean).join(' ').trim();
const region = address.city_district || address.suburb || address.state || address.county || address.region || address.state_district || '';
const city = address.city || address.town || address.village || '';
return {
label: result.display_name || '',
street,
zip: address.postcode || '',
city,
region,
lat: parseFloat(result.lat),
lng: parseFloat(result.lon),
};
return normalizeGeoResult(result);
};
const applyProfileAddress = (result) => {