| Server IP : 188.114.96.3 / Your IP : 216.73.216.143 Web Server : Apache System : Linux sv058.home.net.pl 6.8.2 husak_dirty_pages_fix #1 SMP PREEMPT_DYNAMIC Tue Apr 2 22:06:51 CEST 2024 x86_64 User : ( 3194769) PHP Version : 8.5.12 Disable Function : NONE MySQL : OFF | cURL : ON | WGET : ON | Perl : ON | Python : ON | Sudo : ON | Pkexec : OFF Directory : /polana/admin/ |
Upload File : |
<?php
declare(strict_types=1);
require_once dirname(__DIR__) . '/includes/functions.php';
require_login();
$id = (int)($_GET['id'] ?? 0);
$stmt = db()->prepare('SELECT c.*, m.name AS menu_name FROM menu_categories c JOIN menus m ON m.id=c.menu_id WHERE c.id=?');
$stmt->execute([$id]);
$category = $stmt->fetch();
if (!$category) {
http_response_code(404);
exit('Nie znaleziono kategorii.');
}
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
verify_csrf();
$action = (string)($_POST['action'] ?? 'save');
if ($action === 'delete') {
$menuId = (int)$category['menu_id'];
$stmt = db()->prepare('DELETE FROM menu_categories WHERE id=?');
$stmt->execute([$id]);
admin_log('category_delete', 'Usunięto kategorię #' . $id);
flash('success', 'Kategoria została usunięta.');
redirect('/admin/menu.php?id=' . $menuId);
}
$stmt = db()->prepare(
'UPDATE menu_categories SET name=?, description=?, sort_order=?, active=?, name_en=?, name_es=?, name_de=? WHERE id=?'
);
$stmt->execute([
trim((string)$_POST['name']),
trim((string)($_POST['description'] ?? '')),
(int)($_POST['sort_order'] ?? 0),
isset($_POST['active']) ? 1 : 0,
trim((string)($_POST['name_en'] ?? '')),
trim((string)($_POST['name_es'] ?? '')),
trim((string)($_POST['name_de'] ?? '')),
$id,
]);
admin_log('category_update', 'Zapisano kategorię #' . $id);
flash('success', 'Kategoria zapisana.');
redirect('/admin/menu.php?id=' . (int)$category['menu_id']);
}
render_admin_header('Kategoria');
?>
<div class="admin-title-row">
<div>
<h1>Edytuj kategorię</h1>
<p><?= e($category['menu_name']) ?></p>
</div>
<a class="btn btn-light" href="/admin/menu.php?id=<?= (int)$category['menu_id'] ?>">← Wróć</a>
</div>
<form class="form-card form-grid" method="post">
<?= csrf_field() ?>
<input type="hidden" name="action" value="save">
<label>
Nazwa
<input name="name" value="<?= e($category['name']) ?>" required>
</label>
<label>
Nazwa po angielsku (EN)
<input name="name_en" value="<?= e($category['name_en'] ?? '') ?>" placeholder="Starters">
</label>
<label>
Nazwa po hiszpańsku (ES) — edytowalna
<input name="name_es" value="<?= e($category['name_es'] ?? '') ?>" placeholder="Entrantes">
</label>
<label>
Nazwa po niemiecku (DE) — edytowalna
<input name="name_de" value="<?= e($category['name_de'] ?? '') ?>" placeholder="Vorspeisen">
</label>
<label>
Kolejność
<input type="number" name="sort_order" value="<?= (int)$category['sort_order'] ?>">
</label>
<label class="full">
Opis kategorii
<textarea name="description"><?= e($category['description']) ?></textarea>
</label>
<label class="check-row full">
<input type="checkbox" name="active" value="1" <?= (int)$category['active'] ? 'checked' : '' ?>>
Kategoria widoczna
</label>
<div class="full actions">
<button class="btn btn-primary" type="submit">Zapisz</button>
</div>
</form>
<form method="post" class="form-card" onsubmit="return confirm('Usunąć kategorię razem ze wszystkimi daniami?')">
<?= csrf_field() ?>
<input type="hidden" name="action" value="delete">
<button class="btn btn-danger" type="submit">Usuń kategorię</button>
</form>
<?php render_admin_footer(); ?>