<?php
declare(strict_types=1);
require_once __DIR__ . '/app/Helpers/bootstrap.php';
$user=require_login(); if(!in_array($user['role'],['main_admin','admin'],true)){http_response_code(403);exit('Kein Zugriff.');}
$type=(string)($_GET['type']??'');$types=['accommodation'=>['table'=>'accommodations','label'=>'Unterkunft'],'restaurant'=>['table'=>'restaurants','label'=>'Restaurant']];if(!isset($types[$type])){http_response_code(404);exit('Bereich nicht gefunden.');}$meta=$types[$type];$id=filter_input(INPUT_GET,'id',FILTER_VALIDATE_INT,['options'=>['min_range'=>1]]);if(!$id){http_response_code(404);exit('Eintrag nicht gefunden.');}
$q=db()->prepare('SELECT id,name,google_maps_url,plus_code FROM '.table($meta['table']).' WHERE id=:id');$q->execute([':id'=>$id]);$item=$q->fetch();if(!$item){http_response_code(404);exit('Eintrag nicht gefunden.');}$error=null;
if($_SERVER['REQUEST_METHOD']==='POST'){verify_csrf();$maps=trim((string)($_POST['google_maps_url']??''));$plus=trim((string)($_POST['plus_code']??''));if($maps!==''&&!filter_var($maps,FILTER_VALIDATE_URL)){$error='Bitte einen gültigen Google-Maps-Link eingeben.';}else{try{$s=db()->prepare('UPDATE '.table($meta['table']).' SET google_maps_url=:maps,plus_code=:plus WHERE id=:id');$s->execute([':maps'=>$maps?:null,':plus'=>$plus?:null,':id'=>$id]);header('Location: /catalog-edit.php?type='.$type.'&id='.$id);exit;}catch(Throwable $e){$error='Speichern nicht möglich. Bitte zuerst die SQL-Erweiterung importieren.';}}}
?><!doctype html><html lang="de"><head><meta charset="utf-8"><meta name="viewport" content="width=device-width,initial-scale=1"><title>Standort · TripTale</title><style>body{font-family:system-ui,sans-serif;background:#f4f6f8;margin:0;padding:32px;color:#17202a}main{max-width:620px;margin:auto;background:#fff;padding:28px;border-radius:14px}label{display:block;margin-top:16px;font-weight:600}input{box-sizing:border-box;width:100%;padding:11px;margin-top:6px;border:1px solid #b9c1c8;border-radius:7px}.button,button{display:inline-block;padding:9px 12px;background:#126e82;color:#fff;border:0;border-radius:7px;text-decoration:none;font-weight:700;margin-top:20px}.back{background:#e3ebee;color:#126e82}.error{background:#ffe6e3;padding:12px}*{box-sizing:border-box}html,body{max-width:100%;overflow-x:hidden}img,video{max-width:100%;height:auto}input,textarea,select,.editor{max-width:100%}@media(max-width:600px){body{padding:12px!important}header{padding:14px 16px!important;flex-wrap:wrap;gap:10px}main{width:100%!important;margin:18px auto!important;padding:16px!important}.top{flex-wrap:wrap;align-items:flex-start}.top>div{width:100%}.button{margin:4px 4px 4px 0!important}.card,.hero,.day{padding:16px!important}h1{font-size:1.6rem}h2{font-size:1.25rem}}</style><link rel="stylesheet" href="/assets/triptale-ui.css?v=19"></head><body><main><a class="button back" href="/catalog-edit.php?type=<?= $type ?>&id=<?= $id ?>">← Zurück</a><h1>Standort: <?= htmlspecialchars($item['name'],ENT_QUOTES,'UTF-8') ?></h1><?php if($error): ?><p class="error"><?= htmlspecialchars($error,ENT_QUOTES,'UTF-8') ?></p><?php endif; ?><form method="post"><input type="hidden" name="csrf_token" value="<?= htmlspecialchars(csrf_token(),ENT_QUOTES,'UTF-8') ?>"><label>Google-Maps-Link<input name="google_maps_url" type="url" value="<?= htmlspecialchars((string)($_POST['google_maps_url']??$item['google_maps_url']??''),ENT_QUOTES,'UTF-8') ?>"></label><label>Plus Code<input name="plus_code" value="<?= htmlspecialchars((string)($_POST['plus_code']??$item['plus_code']??''),ENT_QUOTES,'UTF-8') ?>"></label><button>Speichern</button></form></main></body></html>
