Compila i dati dell'evento. I campi con * sono obbligatori.
nuovo evento * - event_form.php?id=123 -> modifica evento esistente * Invia a event_save.php (insert/update + redirect). * * Extra rispetto alla v1: * - flatpickr per data/ora (fine = inizio + 1h automatica) * - sede da event_locations (default scuola) o indirizzo personalizzato * - "Calcola coordinate" da indirizzo (geocoding via event_geocode.php) * - copertina drag&drop -> event_upload_cover.php -> assets/uploads/events/ */ $pdo = DBHandlerSelect::getInstance()->getConnection(); function e($value): string { return htmlspecialchars((string) $value, ENT_QUOTES, 'UTF-8'); } $id = isset($_GET['id']) ? (int) $_GET['id'] : 0; $ev = null; if ($id > 0) { $stmt = $pdo->prepare("SELECT * FROM events WHERE id = ?"); $stmt->execute([$id]); $ev = $stmt->fetch(PDO::FETCH_ASSOC); if (!$ev) { header('Location: events.php?message=error'); exit(); } } // Default dal record unico di `option` $opt = $pdo->query("SELECT * FROM `option` LIMIT 1")->fetch(PDO::FETCH_ASSOC); $defaultColor = $opt['event_default_color'] ?? '#4CAF50'; $defaultMaxPerBooking = (int) ($opt['event_default_max_per_booking'] ?? 1); $defReminderEnabled = ($opt['event_reminder_enabled'] ?? 'N') === 'Y'; $defReminderHours = (int) ($opt['event_reminder_hours'] ?? 24); $defOfferHours = (int) ($opt['event_offer_expiry_hours'] ?? 24); // Sedi salvate (se la tabella non esiste ancora, si degrada su indirizzo libero) $locations = []; try { $locations = $pdo->query("SELECT * FROM event_locations ORDER BY is_default DESC, name ASC")->fetchAll(PDO::FETCH_ASSOC); } catch (Throwable $e) { $locations = []; } $val = [ 'title' => $ev['title'] ?? '', 'slug' => $ev['slug'] ?? '', 'organizer_name' => $ev['organizer_name'] ?? '', 'starts_at' => !empty($ev['starts_at']) ? date('Y-m-d H:i', strtotime($ev['starts_at'])) : '', 'ends_at' => !empty($ev['ends_at']) ? date('Y-m-d H:i', strtotime($ev['ends_at'])) : '', 'address' => $ev['address'] ?? '', 'lat' => $ev['lat'] ?? '', 'lng' => $ev['lng'] ?? '', 'cost' => $ev['cost'] ?? '0.00', 'currency' => $ev['currency'] ?? 'EUR', 'max_seats' => $ev['max_seats'] ?? '', 'max_per_booking' => $ev['max_per_booking'] ?? $defaultMaxPerBooking, 'color' => $ev['color'] ?? $defaultColor, 'cover_image' => $ev['cover_image'] ?? '', 'status' => $ev['status'] ?? 'draft', 'description' => $ev['description'] ?? '', 'instructions' => $ev['instructions'] ?? '', 'what_to_bring' => $ev['what_to_bring'] ?? '', 'suitable_for' => $ev['suitable_for'] ?? '', 'gallery' => $ev['gallery'] ?? '', 'waitlist_enabled' => ($ev['waitlist_enabled'] ?? 'Y') === 'Y', 'reminder_enabled' => $ev['reminder_enabled'] ?? null, 'reminder_hours' => $ev['reminder_hours'] ?? '', 'offer_expiry_hours' => $ev['offer_expiry_hours'] ?? '', ]; $isEdit = $id > 0; $pageTitle = $isEdit ? 'Modifica evento' : 'Nuovo evento'; ?>
Compila i dati dell'evento. I campi con * sono obbligatori.