trim($_POST['title'] ?? ''), 'slug' => trim($_POST['slug'] ?? ''), 'subtitle' => trim($_POST['subtitle'] ?? ''), 'summary' => trim($_POST['summary'] ?? ''), 'description' => trim($_POST['description'] ?? ''), 'cor' => trim($_POST['cor'] ?? '#C2D500'), 'location' => trim($_POST['location'] ?? ''), 'event_starts_at' => trim($_POST['event_starts_at'] ?? ''), 'event_ends_at' => trim($_POST['event_ends_at'] ?? ''), 'publish_from' => trim($_POST['publish_from'] ?? ''), 'publish_until' => trim($_POST['publish_until'] ?? ''), 'is_active' => isset($_POST['is_active']) ? 1 : 0, 'cta_label' => trim($_POST['cta_label'] ?? ''), 'cta_url' => trim($_POST['cta_url'] ?? ''), 'show_lead_form' => isset($_POST['show_lead_form']) ? 1 : 0, 'gym_id' => (int) ($_POST['gym_id'] ?? 0) ?: null, 'hero_image' => '', ]; if ($data['title'] === '') $errors[] = 'O título é obrigatório.'; if ($data['publish_from'] === '') $errors[] = 'A data de início da publicação é obrigatória.'; if ($data['publish_until'] === '') $errors[] = 'A data de fim da publicação é obrigatória.'; if ($data['publish_from'] !== '' && $data['publish_until'] !== '' && strtotime($data['publish_until']) < strtotime($data['publish_from'])) { $errors[] = 'A data de fim da publicação não pode ser anterior à de início.'; } if (!$errors) { $hero_err = null; $uploaded = events_image_upload($_FILES['hero_file'] ?? [], $hero_err); if ($hero_err) $errors[] = $hero_err; elseif ($uploaded) $data['hero_image'] = $uploaded; } if (!$errors) { $data['slug'] = events_make_slug($pdo, $data['slug'] !== '' ? $data['slug'] : $data['title']); $id = db_events_create($pdo, $data); session()->setFlashdata('success', 'Evento criado.'); header('Location: ' . base_url('views/admin/events/edit.php?id=' . $id)); exit; } } $page_title = 'Adicionar Evento'; include __DIR__ . '/../../../includes/header.php'; ?>

Adicionar Evento

Voltar
Cancelar