Zmiany w API
This commit is contained in:
@@ -19,7 +19,7 @@ try {
|
||||
|
||||
// === GET ALL PLACES ===
|
||||
$places = $pdo->query("
|
||||
SELECT id, type, name, woj
|
||||
SELECT id, name, woj
|
||||
FROM salon_places
|
||||
ORDER BY id ASC
|
||||
")->fetchAll();
|
||||
@@ -30,7 +30,7 @@ foreach ($places as $place) {
|
||||
|
||||
// === GET SHOPS FOR PLACE ===
|
||||
$stmt = $pdo->prepare("
|
||||
SELECT address, open_hours, url_address, lat, lng
|
||||
SELECT address, open_hours, url_address, url_shop, lat, lng
|
||||
FROM shops
|
||||
WHERE place_id = ?
|
||||
ORDER BY id ASC
|
||||
@@ -40,17 +40,32 @@ foreach ($places as $place) {
|
||||
$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'],
|
||||
$shopItem = [
|
||||
'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[] = [
|
||||
'type' => $place['type'],
|
||||
'type' => "city", //! do sprawdzenia czy city jest potrzebne
|
||||
'name' => $place['name'],
|
||||
'woj' => $place['woj'] === null ? false : $place['woj'],
|
||||
'shops' => $shops
|
||||
|
||||
@@ -6,11 +6,10 @@ if ($_POST) {
|
||||
|
||||
// === Dodajemy miejsce ===
|
||||
$stmt = $pdo->prepare("
|
||||
INSERT INTO salon_places (type, name, woj)
|
||||
VALUES (?, ?, ?)
|
||||
INSERT INTO salon_places (name, woj)
|
||||
VALUES (?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
$_POST['type'],
|
||||
$_POST['name'],
|
||||
$_POST['woj'] ?: null
|
||||
]);
|
||||
@@ -19,7 +18,7 @@ if ($_POST) {
|
||||
|
||||
// === Dodajemy sklep (shop) ===
|
||||
$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 (?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$stmt->execute([
|
||||
@@ -27,6 +26,7 @@ if ($_POST) {
|
||||
$_POST['address'] ?: null,
|
||||
$_POST['open_hours'] ?: null,
|
||||
$_POST['url_address'],
|
||||
$_POST['url_shop'],
|
||||
$_POST['lat'],
|
||||
$_POST['lng'],
|
||||
]);
|
||||
|
||||
@@ -15,9 +15,8 @@ $shops = $shops->fetchAll();
|
||||
|
||||
if ($_POST) {
|
||||
// Aktualizujemy miejsce
|
||||
$pdo->prepare("UPDATE salon_places SET type=?, name=?, woj=? WHERE id=?")
|
||||
$pdo->prepare("UPDATE salon_places SET name=?, woj=? WHERE id=?")
|
||||
->execute([
|
||||
$_POST['type'],
|
||||
$_POST['name'],
|
||||
$_POST['woj'] ?: null,
|
||||
$id
|
||||
@@ -27,12 +26,13 @@ if ($_POST) {
|
||||
$shopId = $shops[0]['id'] ?? null;
|
||||
if ($shopId) {
|
||||
$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=?
|
||||
")->execute([
|
||||
$_POST['address'] ?: null,
|
||||
$_POST['open_hours'] ?: null,
|
||||
$_POST['url_address'],
|
||||
$_POST['url_shop'],
|
||||
$_POST['lat'],
|
||||
$_POST['lng'],
|
||||
$shopId
|
||||
|
||||
@@ -1,7 +1,18 @@
|
||||
<?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';
|
||||
?>
|
||||
|
||||
@@ -19,22 +30,22 @@ include __DIR__ . '/components/header.php';
|
||||
<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">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">Adres</th>
|
||||
<th class="px-6 py-3 text-left text-xs font-medium text-gray-500 uppercase tracking-wider">Akcje</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody class="bg-white divide-y divide-gray-200">
|
||||
<?php foreach ($places as $p): ?>
|
||||
<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 font-medium text-gray-900"><?= htmlspecialchars($p['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['place_id'] ?></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['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">
|
||||
<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>
|
||||
<a href="actions/delete.php?id=<?= $p['id'] ?>"
|
||||
<a href="actions/delete.php?id=<?= $p['place_id'] ?>"
|
||||
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>
|
||||
</td>
|
||||
|
||||
@@ -7,27 +7,17 @@
|
||||
<div class="bg-white shadow-lg rounded-lg p-8">
|
||||
<h1 class="text-2xl font-bold mb-6">Dodaj nowe miejsce / salon</h1>
|
||||
<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 -->
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
|
||||
<!-- Woj -->
|
||||
<div>
|
||||
<label class="block mb-1 font-medium text-gray-700">Woj (opcjonalnie)</label>
|
||||
<select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
||||
<option value="">Brak</option>
|
||||
<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" required>
|
||||
<option value="" selected disabled>Wybierz województwo</option>
|
||||
<option value="Dolnośląskie">Dolnośląskie</option>
|
||||
<option value="Kujawsko-Pomorskie">Kujawsko-Pomorskie</option>
|
||||
<option value="Lubelskie">Lubelskie</option>
|
||||
@@ -53,13 +43,18 @@
|
||||
<h2 class="text-xl font-semibold mb-4">Dane sklepu</h2>
|
||||
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<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>
|
||||
@@ -69,12 +64,12 @@
|
||||
|
||||
<div class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -24,27 +24,16 @@ $shops = $stmt->fetchAll();
|
||||
<div class="bg-white shadow-lg rounded-lg p-8">
|
||||
<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">
|
||||
|
||||
<!-- 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 -->
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
|
||||
<!-- Woj -->
|
||||
<div>
|
||||
<label class="block mb-1 font-medium text-gray-700">Woj (opcjonalnie)</label>
|
||||
<select name="woj" class="w-full p-3 border rounded-md focus:outline-none focus:ring-2 focus:ring-blue-500">
|
||||
<option value="" <?= !$place['woj']?'selected':'' ?>>Brak</option>
|
||||
<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" required>
|
||||
<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="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>
|
||||
|
||||
<div>
|
||||
<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">
|
||||
<label class="block mb-1 font-medium text-gray-700">Adres *</label>
|
||||
<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>
|
||||
<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>
|
||||
<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 class="grid grid-cols-2 gap-4">
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
<div>
|
||||
<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">
|
||||
<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" required>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
Reference in New Issue
Block a user