178 lines
9.1 KiB
PHP
178 lines
9.1 KiB
PHP
<?php
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
$pdo = db();
|
|
$single_suggestion = null;
|
|
|
|
if (isset($_GET['id'])) {
|
|
$stmt = $pdo->prepare("SELECT * FROM saved_suggestions WHERE id = ?");
|
|
$stmt->execute([$_GET['id']]);
|
|
$single_suggestion = $stmt->fetch();
|
|
}
|
|
|
|
$stmt = $pdo->query("SELECT * FROM saved_suggestions ORDER BY created_at DESC");
|
|
$suggestions = $stmt->fetchAll();
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Saved Suggestions</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://unpkg.com/leaflet@1.9.4/dist/leaflet.css"/>
|
|
<link href="assets/css/custom.css?v=<?php echo time(); ?>" rel="stylesheet">
|
|
<style>
|
|
.suggestion-card {
|
|
margin-bottom: 2rem;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
<div class="hero">
|
|
<div class="container">
|
|
<h1><?php echo $single_suggestion ? htmlspecialchars($single_suggestion['title']) : 'Your Saved Adventures'; ?></h1>
|
|
<p class="lead"><?php echo $single_suggestion ? 'A shared travel idea' : 'Revisit your favorite Polish destinations.'; ?></p>
|
|
<a href="/" class="btn btn-light">Home</a>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row <?php echo $single_suggestion ? 'justify-content-center' : ''; ?>">
|
|
<?php if ($single_suggestion): ?>
|
|
<div class="col-md-8">
|
|
<div class="card suggestion-card">
|
|
<img src="<?php echo htmlspecialchars($single_suggestion['image_url']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($single_suggestion['title']); ?>">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($single_suggestion['title']); ?></h5>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($single_suggestion['description'])); ?></p>
|
|
|
|
<?php
|
|
$itinerary = json_decode($single_suggestion['itinerary'], true);
|
|
if ($itinerary && !empty($itinerary)):
|
|
?>
|
|
<div class="itinerary-section">
|
|
<h6>Itinerary</h6>
|
|
<ul class="list-group">
|
|
<?php foreach ($itinerary as $day): ?>
|
|
<li class="list-group-item">
|
|
<b>Day <?php echo htmlspecialchars($day['day']); ?>:</b> <?php echo htmlspecialchars(implode(', ', $day['activities'])); ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$location = json_decode($single_suggestion['location'], true);
|
|
if ($location && !empty($location['lat']) && !empty($location['lng'])):
|
|
?>
|
|
<div id="map-single" style="height: 400px;" class="mt-3"></div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php elseif (empty($suggestions)):
|
|
?>
|
|
<div class="col text-center">
|
|
<p>You haven't saved any suggestions yet.</p>
|
|
<a href="/" class="btn btn-primary">Find a new adventure</a>
|
|
</div>
|
|
<?php else: ?>
|
|
<?php foreach ($suggestions as $index => $suggestion): ?>
|
|
<div class="col-md-4">
|
|
<div class="card suggestion-card">
|
|
<img src="<?php echo htmlspecialchars($suggestion['image_url']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($suggestion['title']); ?>">
|
|
<div class="card-body">
|
|
<h5 class="card-title"><?php echo htmlspecialchars($suggestion['title']); ?></h5>
|
|
<p class="card-text"><?php echo nl2br(htmlspecialchars($suggestion['description'])); ?></p>
|
|
|
|
<?php
|
|
$itinerary = json_decode($suggestion['itinerary'], true);
|
|
if ($itinerary && !empty($itinerary)):
|
|
?>
|
|
<div class="itinerary-section">
|
|
<h6>Itinerary</h6>
|
|
<ul class="list-group">
|
|
<?php foreach ($itinerary as $day): ?>
|
|
<li class="list-group-item">
|
|
<b>Day <?php echo htmlspecialchars($day['day']); ?>:</b> <?php echo htmlspecialchars(implode(', ', $day['activities'])); ?>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php
|
|
$location = json_decode($suggestion['location'], true);
|
|
if ($location && !empty($location['lat']) && !empty($location['lng'])):
|
|
?>
|
|
<div id="map-<?php echo $index; ?>" style="height: 200px;" class="mt-3"></div>
|
|
<?php endif; ?>
|
|
|
|
<button class="btn btn-sm btn-outline-secondary mt-2 share-btn" data-id="<?php echo $suggestion['id']; ?>">Share</button>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
|
|
<script src="https://unpkg.com/leaflet@1.9.4/dist/leaflet.js"></script>
|
|
<script>
|
|
document.addEventListener('DOMContentLoaded', function() {
|
|
<?php if ($single_suggestion): ?>
|
|
<?php
|
|
$location = json_decode($single_suggestion['location'], true);
|
|
if ($location && !empty($location['lat']) && !empty($location['lng'])):
|
|
?>
|
|
var mapSingle = L.map('map-single').setView([<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>], 13);
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
}).addTo(mapSingle);
|
|
L.marker([<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>]).addTo(mapSingle)
|
|
.bindPopup(<?php echo json_encode($single_suggestion['title']); ?>)
|
|
.openPopup();
|
|
<?php endif; ?>
|
|
<?php else: ?>
|
|
<?php foreach ($suggestions as $index => $suggestion): ?>
|
|
<?php
|
|
$location = json_decode($suggestion['location'], true);
|
|
if ($location && !empty($location['lat']) && !empty($location['lng'])):
|
|
?>
|
|
var map<?php echo $index; ?> = L.map('map-<?php echo $index; ?>').setView([<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>], 13);
|
|
L.tileLayer('https://{s}.tile.openstreetmap.org/{z}/{x}/{y}.png', {
|
|
attribution: '© <a href="https://www.openstreetmap.org/copyright">OpenStreetMap</a> contributors'
|
|
}).addTo(map<?php echo $index; ?>);
|
|
L.marker([<?php echo $location['lat']; ?>, <?php echo $location['lng']; ?>]).addTo(map<?php echo $index; ?>)
|
|
.bindPopup(<?php echo json_encode($suggestion['title']); ?>)
|
|
.openPopup();
|
|
<?php endif; ?>
|
|
<?php endforeach; ?>
|
|
<?php endif; ?>
|
|
|
|
document.querySelectorAll('.share-btn').forEach(button => {
|
|
button.addEventListener('click', function() {
|
|
const suggestionId = this.dataset.id;
|
|
const shareUrl = `${window.location.origin}/saved.php?id=${suggestionId}`;
|
|
|
|
navigator.clipboard.writeText(shareUrl).then(() => {
|
|
this.textContent = 'Copied!';
|
|
this.disabled = true;
|
|
setTimeout(() => {
|
|
this.textContent = 'Share';
|
|
this.disabled = false;
|
|
}, 2000);
|
|
}).catch(err => {
|
|
console.error('Failed to copy: ', err);
|
|
});
|
|
});
|
|
});
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|
|
|