diff --git a/api/salony/index.php b/api/salony/index.php new file mode 100644 index 0000000..2d2105e --- /dev/null +++ b/api/salony/index.php @@ -0,0 +1,61 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, + ]); +} catch (Throwable $e) { + http_response_code(500); + echo json_encode(['error' => 'DB error']); + exit; +} + +// === GET ALL PLACES === +$places = $pdo->query(" + SELECT id, type, name, woj + FROM salon_places + ORDER BY id ASC +")->fetchAll(); + +$result = []; + +foreach ($places as $place) { + + // === GET SHOPS FOR PLACE === + $stmt = $pdo->prepare(" + SELECT address, open_hours, url_address, lat, lng + FROM shops + WHERE place_id = ? + ORDER BY id ASC + "); + $stmt->execute([$place['id']]); + + $shops = []; + + foreach ($stmt as $shop) { + $shops[] = [ + 'address' => $shop['address'], + 'openHours' => $shop['open_hours'], + 'urlAddress'=> $shop['url_address'], + 'lat' => (string)$shop['lat'], + 'lng' => (string)$shop['lng'], + ]; + } + + $result[] = [ + 'type' => $place['type'], + 'name' => $place['name'], + 'woj' => $place['woj'] === null ? false : $place['woj'], + 'shops' => $shops + ]; +} + +echo json_encode($result, JSON_UNESCAPED_UNICODE | JSON_PRETTY_PRINT); +exit; \ No newline at end of file diff --git a/salony/actions/add.php b/salony/actions/add.php new file mode 100644 index 0000000..7e8ecbf --- /dev/null +++ b/salony/actions/add.php @@ -0,0 +1,36 @@ +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; +} diff --git a/salony/actions/delete.php b/salony/actions/delete.php new file mode 100644 index 0000000..82b7e24 --- /dev/null +++ b/salony/actions/delete.php @@ -0,0 +1,13 @@ +prepare("DELETE FROM shops WHERE place_id = ?")->execute([$id]); + +// Usuwamy miejsce +$pdo->prepare("DELETE FROM salon_places WHERE id = ?")->execute([$id]); + +header('Location: ../'); +exit; diff --git a/salony/actions/edit.php b/salony/actions/edit.php new file mode 100644 index 0000000..39bd908 --- /dev/null +++ b/salony/actions/edit.php @@ -0,0 +1,44 @@ +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; +} diff --git a/salony/components/footer.php b/salony/components/footer.php new file mode 100644 index 0000000..691287b --- /dev/null +++ b/salony/components/footer.php @@ -0,0 +1,2 @@ + + \ No newline at end of file diff --git a/salony/components/header.php b/salony/components/header.php new file mode 100644 index 0000000..8baeabd --- /dev/null +++ b/salony/components/header.php @@ -0,0 +1,36 @@ + + + + + + + Salony Admin + + + +
+

+ Panel +

+ + + + + + + + Wyloguj + + +
+ +
diff --git a/salony/db.php b/salony/db.php new file mode 100644 index 0000000..6dae1b7 --- /dev/null +++ b/salony/db.php @@ -0,0 +1,9 @@ + PDO::ERRMODE_EXCEPTION, + PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC, +]); \ No newline at end of file diff --git a/salony/index.php b/salony/index.php new file mode 100644 index 0000000..665be08 --- /dev/null +++ b/salony/index.php @@ -0,0 +1,48 @@ +query("SELECT * FROM salon_places ORDER BY id DESC")->fetchAll(); +include __DIR__ . '/components/header.php'; +?> + +
+
+

Lista miejsc / salonów

+ + + Dodaj + +
+ +
+ + + + + + + + + + + + + + + + + + + + + +
IDNazwaTypWojAkcje
+ Edytuj + Usuń +
+
+
+ + diff --git a/salony/pages/add.php b/salony/pages/add.php new file mode 100644 index 0000000..57b94a0 --- /dev/null +++ b/salony/pages/add.php @@ -0,0 +1,87 @@ + + +
+
+

Dodaj nowe miejsce / salon

+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +

Dane sklepu

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + + Wstecz +
+
+
+ + diff --git a/salony/pages/edit.php b/salony/pages/edit.php new file mode 100644 index 0000000..76eb02d --- /dev/null +++ b/salony/pages/edit.php @@ -0,0 +1,102 @@ +prepare("SELECT * FROM salon_places WHERE id=?"); +$stmt->execute([$id]); +$place = $stmt->fetch(); + +if (!$place) { + echo "Nie znaleziono miejsca."; + exit; +} + +// Pobieramy sklep (shops) +$stmt = $pdo->prepare("SELECT * FROM shops WHERE place_id=?"); +$stmt->execute([$id]); +$shops = $stmt->fetchAll(); +?> + +
+
+

Edytuj miejsce / salon

+
+ + +
+ + +
+ + +
+ + +
+ + +
+ + +
+ +
+

Dane sklepu

+ +
+ + +
+ +
+ + +
+ +
+ + +
+ +
+
+ + +
+
+ + +
+
+ + + Wstecz +
+
+
+ + diff --git a/salony/pages/login.php b/salony/pages/login.php new file mode 100644 index 0000000..3f180f1 --- /dev/null +++ b/salony/pages/login.php @@ -0,0 +1,56 @@ + + + + + + Logowanie + + + +
+

Panel logowania

+ + +

+ + +
+ + +
+ +
+ + +
+ + +
+ + diff --git a/salony/pages/logout.php b/salony/pages/logout.php new file mode 100644 index 0000000..31cbe17 --- /dev/null +++ b/salony/pages/logout.php @@ -0,0 +1,5 @@ +