Add mini admin panel

This commit is contained in:
Roman Pyrih
2025-12-17 12:02:31 +01:00
parent eb422001e3
commit 1d05064a51
12 changed files with 499 additions and 0 deletions

36
salony/actions/add.php Normal file
View File

@@ -0,0 +1,36 @@
<?php
require __DIR__ . '/../db.php';
if ($_POST) {
// === Dodajemy miejsce ===
$stmt = $pdo->prepare("
INSERT INTO salon_places (type, name, woj)
VALUES (?, ?, ?)
");
$stmt->execute([
$_POST['type'],
$_POST['name'],
$_POST['woj'] ?: null
]);
$placeId = $pdo->lastInsertId();
// === Dodajemy sklep (shop) ===
$stmt = $pdo->prepare("
INSERT INTO shops (place_id, address, open_hours, url_address, lat, lng)
VALUES (?, ?, ?, ?, ?, ?)
");
$stmt->execute([
$placeId,
$_POST['address'] ?: null,
$_POST['open_hours'] ?: null,
$_POST['url_address'],
$_POST['lat'],
$_POST['lng'],
]);
header('Location: ../');
exit;
}

13
salony/actions/delete.php Normal file
View File

@@ -0,0 +1,13 @@
<?php
require __DIR__ . '/../db.php';
$id = (int)$_GET['id'];
// Usuwamy sklepy powiązane z miejscem
$pdo->prepare("DELETE FROM shops WHERE place_id = ?")->execute([$id]);
// Usuwamy miejsce
$pdo->prepare("DELETE FROM salon_places WHERE id = ?")->execute([$id]);
header('Location: ../');
exit;

44
salony/actions/edit.php Normal file
View File

@@ -0,0 +1,44 @@
<?php
require __DIR__ . '/../db.php';
$id = (int)($_GET['id'] ?? 0);
if (!$id) {
echo "Brak ID.";
exit;
}
// Pobieramy miejsce
$shops = $pdo->prepare("SELECT * FROM shops WHERE place_id=?");
$shops->execute([$id]);
$shops = $shops->fetchAll();
if ($_POST) {
// Aktualizujemy miejsce
$pdo->prepare("UPDATE salon_places SET type=?, name=?, woj=? WHERE id=?")
->execute([
$_POST['type'],
$_POST['name'],
$_POST['woj'] ?: null,
$id
]);
// Aktualizujemy pierwszy sklep (shop)
$shopId = $shops[0]['id'] ?? null;
if ($shopId) {
$pdo->prepare("
UPDATE shops SET address=?, open_hours=?, url_address=?, lat=?, lng=?
WHERE id=?
")->execute([
$_POST['address'] ?: null,
$_POST['open_hours'] ?: null,
$_POST['url_address'],
$_POST['lat'],
$_POST['lng'],
$shopId
]);
}
header('Location: ../');
exit;
}