Zmiany w API

This commit is contained in:
2025-12-18 13:45:56 +01:00
parent 1d05064a51
commit 58e1112bd2
6 changed files with 83 additions and 68 deletions

View File

@@ -19,7 +19,7 @@ try {
// === GET ALL PLACES === // === GET ALL PLACES ===
$places = $pdo->query(" $places = $pdo->query("
SELECT id, type, name, woj SELECT id, name, woj
FROM salon_places FROM salon_places
ORDER BY id ASC ORDER BY id ASC
")->fetchAll(); ")->fetchAll();
@@ -30,7 +30,7 @@ foreach ($places as $place) {
// === GET SHOPS FOR PLACE === // === GET SHOPS FOR PLACE ===
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
SELECT address, open_hours, url_address, lat, lng SELECT address, open_hours, url_address, url_shop, lat, lng
FROM shops FROM shops
WHERE place_id = ? WHERE place_id = ?
ORDER BY id ASC ORDER BY id ASC
@@ -40,17 +40,32 @@ foreach ($places as $place) {
$shops = []; $shops = [];
foreach ($stmt as $shop) { foreach ($stmt as $shop) {
$shops[] = [ $shopItem = [
'address' => $shop['address'], 'lat' => (string)$shop['lat'],
'openHours' => $shop['open_hours'], 'lng' => (string)$shop['lng'],
'urlAddress'=> $shop['url_address'],
'lat' => (string)$shop['lat'],
'lng' => (string)$shop['lng'],
]; ];
if (!empty($shop['address'])) {
$shopItem['address'] = $shop['address'];
}
if (!empty($shop['openHours'])) {
$shopItem['openHours'] = $shop['open_hours'];
}
if (!empty($shop['url_address'])) {
$shopItem['urlAddress'] = $shop['url_address'];
}
if (!empty($shop['url_shop'])) {
$shopItem['shopUrl'] = $shop['url_shop'];
}
$shops[] = $shopItem;
} }
$result[] = [ $result[] = [
'type' => $place['type'], 'type' => "city", //! do sprawdzenia czy city jest potrzebne
'name' => $place['name'], 'name' => $place['name'],
'woj' => $place['woj'] === null ? false : $place['woj'], 'woj' => $place['woj'] === null ? false : $place['woj'],
'shops' => $shops 'shops' => $shops

View File

@@ -6,11 +6,10 @@ if ($_POST) {
// === Dodajemy miejsce === // === Dodajemy miejsce ===
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
INSERT INTO salon_places (type, name, woj) INSERT INTO salon_places (name, woj)
VALUES (?, ?, ?) VALUES (?, ?)
"); ");
$stmt->execute([ $stmt->execute([
$_POST['type'],
$_POST['name'], $_POST['name'],
$_POST['woj'] ?: null $_POST['woj'] ?: null
]); ]);
@@ -19,7 +18,7 @@ if ($_POST) {
// === Dodajemy sklep (shop) === // === Dodajemy sklep (shop) ===
$stmt = $pdo->prepare(" $stmt = $pdo->prepare("
INSERT INTO shops (place_id, address, open_hours, url_address, lat, lng) INSERT INTO shops (place_id, address, open_hours, url_address, url_shop, lat, lng)
VALUES (?, ?, ?, ?, ?, ?) VALUES (?, ?, ?, ?, ?, ?)
"); ");
$stmt->execute([ $stmt->execute([
@@ -27,6 +26,7 @@ if ($_POST) {
$_POST['address'] ?: null, $_POST['address'] ?: null,
$_POST['open_hours'] ?: null, $_POST['open_hours'] ?: null,
$_POST['url_address'], $_POST['url_address'],
$_POST['url_shop'],
$_POST['lat'], $_POST['lat'],
$_POST['lng'], $_POST['lng'],
]); ]);

View File

@@ -15,9 +15,8 @@ $shops = $shops->fetchAll();
if ($_POST) { if ($_POST) {
// Aktualizujemy miejsce // Aktualizujemy miejsce
$pdo->prepare("UPDATE salon_places SET type=?, name=?, woj=? WHERE id=?") $pdo->prepare("UPDATE salon_places SET name=?, woj=? WHERE id=?")
->execute([ ->execute([
$_POST['type'],
$_POST['name'], $_POST['name'],
$_POST['woj'] ?: null, $_POST['woj'] ?: null,
$id $id
@@ -27,12 +26,13 @@ if ($_POST) {
$shopId = $shops[0]['id'] ?? null; $shopId = $shops[0]['id'] ?? null;
if ($shopId) { if ($shopId) {
$pdo->prepare(" $pdo->prepare("
UPDATE shops SET address=?, open_hours=?, url_address=?, lat=?, lng=? UPDATE shops SET address=?, open_hours=?, url_address=?, url_shop=?, lat=?, lng=?
WHERE id=? WHERE id=?
")->execute([ ")->execute([
$_POST['address'] ?: null, $_POST['address'] ?: null,
$_POST['open_hours'] ?: null, $_POST['open_hours'] ?: null,
$_POST['url_address'], $_POST['url_address'],
$_POST['url_shop'],
$_POST['lat'], $_POST['lat'],
$_POST['lng'], $_POST['lng'],
$shopId $shopId

View File

@@ -1,7 +1,18 @@
<?php <?php
require __DIR__ . '/db.php'; require __DIR__ . '/db.php';
$places = $pdo->query("SELECT * FROM salon_places ORDER BY id DESC")->fetchAll(); $places = $pdo->query("
SELECT
p.id AS place_id,
p.name AS place_name,
p.woj,
s.id AS shop_id,
s.address,
s.open_hours
FROM salon_places p
LEFT JOIN shops s ON s.place_id = p.id
ORDER BY p.id DESC, s.id ASC")->fetchAll();
include __DIR__ . '/components/header.php'; include __DIR__ . '/components/header.php';
?> ?>
@@ -19,22 +30,22 @@ include __DIR__ . '/components/header.php';
<tr> <tr>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">ID</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nazwa</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Nazwa</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Typ</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Woj</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Woj</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Adres</th>
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Akcje</th> <th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Akcje</th>
</tr> </tr>
</thead> </thead>
<tbody class="bg-white divide-y divide-gray-200"> <tbody class="bg-white divide-y divide-gray-200">
<?php foreach ($places as $p): ?> <?php foreach ($places as $p): ?>
<tr class="hover:bg-gray-50 transition-colors"> <tr class="hover:bg-gray-50 transition-colors">
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['id'] ?></td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['place_id'] ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><?= htmlspecialchars($p['name']) ?></td> <td class="px-6 py-4 whitespace-nowrap text-sm font-medium text-gray-900"><?= htmlspecialchars($p['place_name']) ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['type'] ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['woj'] ?: '—' ?></td> <td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['woj'] ?: '—' ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm text-gray-700"><?= $p['address'] ?: '—' ?></td>
<td class="px-6 py-4 whitespace-nowrap text-sm flex gap-2"> <td class="px-6 py-4 whitespace-nowrap text-sm flex gap-2">
<a href="pages/edit.php?id=<?= $p['id'] ?>" <a href="pages/edit.php?id=<?= $p['place_id'] ?>"
class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md shadow transition-colors">Edytuj</a> class="bg-blue-600 hover:bg-blue-700 text-white px-3 py-1 rounded-md shadow transition-colors">Edytuj</a>
<a href="actions/delete.php?id=<?= $p['id'] ?>" <a href="actions/delete.php?id=<?= $p['place_id'] ?>"
onclick="return confirm('Usunąć?')" onclick="return confirm('Usunąć?')"
class="bg-red-600 hover:bg-red-700 text-white px-3 py-1 rounded-md shadow transition-colors">Usuń</a> class="bg-red-600 hover:bg-red-700 text-white px-3 py-1 rounded-md shadow transition-colors">Usuń</a>
</td> </td>

View File

@@ -7,27 +7,17 @@
<div class="bg-white shadow-lg rounded-lg p-8"> <div class="bg-white shadow-lg rounded-lg p-8">
<h1 class="text-2xl font-bold mb-6">Dodaj nowe miejsce / salon</h1> <h1 class="text-2xl font-bold mb-6">Dodaj nowe miejsce / salon</h1>
<form method="post" action="../actions/add.php" class="space-y-4"> <form method="post" action="../actions/add.php" class="space-y-4">
<!-- Typ miejsca -->
<div>
<label class="block mb-1 font-medium text-gray-700">Typ miejsca</label>
<select name="type" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="city">City</option>
<option value="woj">Woj</option>
</select>
</div>
<!-- Nazwa --> <!-- Nazwa -->
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Nazwa</label> <label class="block mb-1 font-medium text-gray-700">Nazwa *</label>
<input name="name" type="text" placeholder="np. Myszków" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="name" type="text" placeholder="np. Myszków" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<!-- Woj --> <!-- Woj -->
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Woj (opcjonalnie)</label> <label class="block mb-1 font-medium text-gray-700">Województwo *</label>
<select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<option value="">Brak</option> <option value="" selected disabled>Wybierz województwo</option>
<option value="Dolnośląskie">Dolnośląskie</option> <option value="Dolnośląskie">Dolnośląskie</option>
<option value="Kujawsko-Pomorskie">Kujawsko-Pomorskie</option> <option value="Kujawsko-Pomorskie">Kujawsko-Pomorskie</option>
<option value="Lubelskie">Lubelskie</option> <option value="Lubelskie">Lubelskie</option>
@@ -53,13 +43,18 @@
<h2 class="text-xl font-semibold mb-4">Dane sklepu</h2> <h2 class="text-xl font-semibold mb-4">Dane sklepu</h2>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Adres</label> <label class="block mb-1 font-medium text-gray-700">Adres *</label>
<input name="address" type="text" placeholder="ul. Kościuszki 67" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="address" type="text" placeholder="ul. Kościuszki 67" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Godziny otwarcia</label> <label class="block mb-1 font-medium text-gray-700">Godziny otwarcia</label>
<input name="open_hours" type="text" placeholder="pn.-pt. 9-17 sob. 9-14" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="open_hours" type="text" placeholder="pn.-pt. 8-16 sob. 9-15" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block mb-1 font-medium text-gray-700">Link do strony</label>
<input name="url_shop" type="text" placeholder="https://moodo.pl/Salon-Moodo-...-123.html" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div> </div>
<div> <div>
@@ -69,12 +64,12 @@
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Lat</label> <label class="block mb-1 font-medium text-gray-700">Lat *</label>
<input name="lat" type="text" placeholder="50.5770991" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="lat" type="text" placeholder="50.5770991" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Lng</label> <label class="block mb-1 font-medium text-gray-700">Lng *</label>
<input name="lng" type="text" placeholder="19.3240021" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="lng" type="text" placeholder="19.3240021" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
</div> </div>

View File

@@ -24,27 +24,16 @@ $shops = $stmt->fetchAll();
<div class="bg-white shadow-lg rounded-lg p-8"> <div class="bg-white shadow-lg rounded-lg p-8">
<h1 class="text-2xl font-bold mb-6">Edytuj miejsce / salon</h1> <h1 class="text-2xl font-bold mb-6">Edytuj miejsce / salon</h1>
<form method="post" action="../actions/edit.php?id=<?= $id ?>" class="space-y-4"> <form method="post" action="../actions/edit.php?id=<?= $id ?>" class="space-y-4">
<!-- Typ -->
<div>
<label class="block mb-1 font-medium text-gray-700">Typ miejsca</label>
<select name="type" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
<option value="city" <?= $place['type']=='city'?'selected':'' ?>>City</option>
<option value="woj" <?= $place['type']=='woj'?'selected':'' ?>>Woj</option>
</select>
</div>
<!-- Nazwa --> <!-- Nazwa -->
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Nazwa</label> <label class="block mb-1 font-medium text-gray-700">Nazwa *</label>
<input name="name" type="text" value="<?= htmlspecialchars($place['name']) ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="name" type="text" value="<?= htmlspecialchars($place['name']) ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<!-- Woj --> <!-- Woj -->
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Woj (opcjonalnie)</label> <label class="block mb-1 font-medium text-gray-700">Województwo *</label>
<select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
<option value="" <?= !$place['woj']?'selected':'' ?>>Brak</option>
<option value="Dolnośląskie" <?= $place['woj']=='Dolnośląskie'?'selected':'' ?>>Dolnośląskie</option> <option value="Dolnośląskie" <?= $place['woj']=='Dolnośląskie'?'selected':'' ?>>Dolnośląskie</option>
<option value="Kujawsko-Pomorskie" <?= $place['woj']=='Kujawsko-Pomorskie'?'selected':'' ?>>Kujawsko-Pomorskie</option> <option value="Kujawsko-Pomorskie" <?= $place['woj']=='Kujawsko-Pomorskie'?'selected':'' ?>>Kujawsko-Pomorskie</option>
<option value="Lubelskie" <?= $place['woj']=='Lubelskie'?'selected':'' ?>>Lubelskie</option> <option value="Lubelskie" <?= $place['woj']=='Lubelskie'?'selected':'' ?>>Lubelskie</option>
@@ -68,28 +57,33 @@ $shops = $stmt->fetchAll();
<h2 class="text-xl font-semibold mb-4">Dane sklepu</h2> <h2 class="text-xl font-semibold mb-4">Dane sklepu</h2>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Adres</label> <label class="block mb-1 font-medium text-gray-700">Adres *</label>
<input name="address" type="text" value="<?= htmlspecialchars($shops[0]['address'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="address" type="text" placeholder="ul. Kościuszki 67" value="<?= htmlspecialchars($shops[0]['address'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Godziny otwarcia</label> <label class="block mb-1 font-medium text-gray-700">Godziny otwarcia</label>
<input name="open_hours" type="text" value="<?= htmlspecialchars($shops[0]['open_hours'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="open_hours" type="text" placeholder="pn.-pt. 8-16 sob. 9-15" value="<?= htmlspecialchars($shops[0]['open_hours'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div>
<div>
<label class="block mb-1 font-medium text-gray-700">Link do strony</label>
<input name="url_shop" type="text" placeholder="https://moodo.pl/Salon-Moodo-...-123.html" value="<?= htmlspecialchars($shops[0]['url_shop'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div> </div>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Google Maps URL</label> <label class="block mb-1 font-medium text-gray-700">Google Maps URL</label>
<input name="url_address" type="text" value="<?= htmlspecialchars($shops[0]['url_address'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="url_address" type="text" placeholder="https://maps.google.com/..." value="<?= htmlspecialchars($shops[0]['url_address'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
</div> </div>
<div class="grid grid-cols-2 gap-4"> <div class="grid grid-cols-2 gap-4">
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Lat</label> <label class="block mb-1 font-medium text-gray-700">Lat *</label>
<input name="lat" type="text" value="<?= htmlspecialchars($shops[0]['lat'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="lat" type="text" value="<?= htmlspecialchars($shops[0]['lat'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
<div> <div>
<label class="block mb-1 font-medium text-gray-700">Lng</label> <label class="block mb-1 font-medium text-gray-700">Lng *</label>
<input name="lng" type="text" value="<?= htmlspecialchars($shops[0]['lng'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500"> <input name="lng" type="text" value="<?= htmlspecialchars($shops[0]['lng'] ?? '') ?>" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500" required>
</div> </div>
</div> </div>