asdsad
This commit is contained in:
@@ -12,6 +12,44 @@ $info = '';
|
|||||||
$crypto = null;
|
$crypto = null;
|
||||||
try { $crypto = new \App\Crypto($app->config()); } catch (\Throwable) {}
|
try { $crypto = new \App\Crypto($app->config()); } catch (\Throwable) {}
|
||||||
|
|
||||||
|
function geocode_address(?string $street, ?string $zip, ?string $city, ?string $region): array
|
||||||
|
{
|
||||||
|
$parts = array_filter([
|
||||||
|
$street ?: null,
|
||||||
|
$zip ?: null,
|
||||||
|
$city ?: null,
|
||||||
|
$region ?: null,
|
||||||
|
]);
|
||||||
|
if (!$parts) {
|
||||||
|
return [null, null];
|
||||||
|
}
|
||||||
|
|
||||||
|
$query = implode(', ', $parts);
|
||||||
|
$url = 'https://nominatim.openstreetmap.org/search?' . http_build_query([
|
||||||
|
'format' => 'jsonv2',
|
||||||
|
'limit' => 1,
|
||||||
|
'q' => $query,
|
||||||
|
]);
|
||||||
|
|
||||||
|
$ctx = stream_context_create([
|
||||||
|
'http' => [
|
||||||
|
'method' => 'GET',
|
||||||
|
'header' => "User-Agent: papa-kind-treff/1.0\r\nAccept-Language: de\r\n",
|
||||||
|
'timeout' => 6,
|
||||||
|
],
|
||||||
|
]);
|
||||||
|
|
||||||
|
$resp = @file_get_contents($url, false, $ctx);
|
||||||
|
if ($resp === false) {
|
||||||
|
return [null, null];
|
||||||
|
}
|
||||||
|
$json = json_decode($resp, true);
|
||||||
|
if (!is_array($json) || empty($json[0]['lat']) || empty($json[0]['lon'])) {
|
||||||
|
return [null, null];
|
||||||
|
}
|
||||||
|
return [round((float)$json[0]['lat'], 7), round((float)$json[0]['lon'], 7)];
|
||||||
|
}
|
||||||
|
|
||||||
// POST Aktionen
|
// POST Aktionen
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||||
$action = $_POST['action'] ?? '';
|
$action = $_POST['action'] ?? '';
|
||||||
@@ -50,16 +88,25 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
|||||||
]);
|
]);
|
||||||
$info = 'Kind hinzugefügt.';
|
$info = 'Kind hinzugefügt.';
|
||||||
} elseif ($action === 'event_add') {
|
} elseif ($action === 'event_add') {
|
||||||
$stmt = $pdo->prepare('INSERT INTO events (created_by, title, teaser_public, description, location_label, zip, city, region, lat, lng, starts_at, allow_kids, visibility, status, created_at, updated_at) VALUES (:uid, :title, :teaser, :descr, :loc, :zip, :city, :region, NULL, NULL, :start, :allow, :vis, :status, NOW(), NOW())');
|
$street = trim((string)($_POST['street'] ?? ''));
|
||||||
|
$zip = trim((string)($_POST['zip'] ?? ''));
|
||||||
|
$city = trim((string)($_POST['city'] ?? ''));
|
||||||
|
$region = trim((string)($_POST['region'] ?? ''));
|
||||||
|
[$lat, $lng] = geocode_address($street, $zip, $city, $region);
|
||||||
|
|
||||||
|
$stmt = $pdo->prepare('INSERT INTO events (created_by, title, teaser_public, description, location_label, street, zip, city, region, lat, lng, starts_at, allow_kids, visibility, status, created_at, updated_at) VALUES (:uid, :title, :teaser, :descr, :loc, :street, :zip, :city, :region, :lat, :lng, :start, :allow, :vis, :status, NOW(), NOW())');
|
||||||
$stmt->execute([
|
$stmt->execute([
|
||||||
'uid' => $userId,
|
'uid' => $userId,
|
||||||
'title' => trim((string)$_POST['title']),
|
'title' => trim((string)$_POST['title']),
|
||||||
'teaser' => trim((string)$_POST['teaser']),
|
'teaser' => trim((string)$_POST['teaser']),
|
||||||
'descr' => trim((string)$_POST['description']),
|
'descr' => trim((string)$_POST['description']),
|
||||||
'loc' => trim((string)$_POST['location_label']),
|
'loc' => trim((string)$_POST['location_label']),
|
||||||
'zip' => trim((string)$_POST['zip']),
|
'street' => $street ?: null,
|
||||||
'city' => trim((string)$_POST['city']),
|
'zip' => $zip,
|
||||||
'region' => trim((string)$_POST['region']),
|
'city' => $city,
|
||||||
|
'region' => $region,
|
||||||
|
'lat' => $lat,
|
||||||
|
'lng' => $lng,
|
||||||
'start' => $_POST['starts_at'] ?? null,
|
'start' => $_POST['starts_at'] ?? null,
|
||||||
'allow' => isset($_POST['allow_kids']) ? 1 : 0,
|
'allow' => isset($_POST['allow_kids']) ? 1 : 0,
|
||||||
'vis' => $_POST['visibility'] ?? 'public',
|
'vis' => $_POST['visibility'] ?? 'public',
|
||||||
@@ -355,10 +402,17 @@ $events = $stmt->fetchAll(PDO::FETCH_ASSOC) ?: [];
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-grid">
|
<div class="form-grid">
|
||||||
|
<div class="stack gap-6">
|
||||||
|
<label class="label" for="evStreet">Straße / Adresse</label>
|
||||||
|
<input id="evStreet" name="street" class="input" placeholder="z. B. Musterstraße 12">
|
||||||
|
<p class="muted small">Wird zur Karten-/Umkreissuche genutzt.</p>
|
||||||
|
</div>
|
||||||
<div class="stack gap-6">
|
<div class="stack gap-6">
|
||||||
<label class="label" for="evRegion">Region/Bezirk</label>
|
<label class="label" for="evRegion">Region/Bezirk</label>
|
||||||
<input id="evRegion" name="region" class="input">
|
<input id="evRegion" name="region" class="input">
|
||||||
</div>
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="form-grid">
|
||||||
<div class="stack gap-6">
|
<div class="stack gap-6">
|
||||||
<label class="label" for="evVis">Sichtbarkeit</label>
|
<label class="label" for="evVis">Sichtbarkeit</label>
|
||||||
<select id="evVis" name="visibility" class="select">
|
<select id="evVis" name="visibility" class="select">
|
||||||
|
|||||||
@@ -63,6 +63,7 @@ CREATE TABLE events (
|
|||||||
teaser_public VARCHAR(280) NOT NULL,
|
teaser_public VARCHAR(280) NOT NULL,
|
||||||
description TEXT NOT NULL,
|
description TEXT NOT NULL,
|
||||||
location_label VARCHAR(180) NULL,
|
location_label VARCHAR(180) NULL,
|
||||||
|
street VARCHAR(180) NULL,
|
||||||
zip CHAR(5) NULL,
|
zip CHAR(5) NULL,
|
||||||
city VARCHAR(120) NULL,
|
city VARCHAR(120) NULL,
|
||||||
region VARCHAR(120) NULL,
|
region VARCHAR(120) NULL,
|
||||||
|
|||||||
Reference in New Issue
Block a user