73 lines
2.9 KiB
PHP
73 lines
2.9 KiB
PHP
<?php
|
|
require_once __DIR__ . '/includes/header.php';
|
|
require_once __DIR__ . '/db/config.php';
|
|
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$user_id = $_SESSION['user_id'];
|
|
$email = $_SESSION['user_email'];
|
|
|
|
$favorite_locations = [];
|
|
$subscriptions = [];
|
|
|
|
try {
|
|
$pdo = db();
|
|
$stmt = $pdo->prepare("SELECT * FROM favorite_locations WHERE user_id = ? ORDER BY city_name ASC");
|
|
$stmt->execute([$user_id]);
|
|
$favorite_locations = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
$stmt = $pdo->prepare("SELECT ws.*, fl.city_name FROM weather_subscriptions ws JOIN favorite_locations fl ON ws.location_id = fl.id WHERE ws.user_id = ?");
|
|
$stmt->execute([$user_id]);
|
|
$subscriptions = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
|
} catch (PDOException $e) {
|
|
error_log("DB Error: " . $e->getMessage());
|
|
}
|
|
|
|
?>
|
|
|
|
<div class="container mt-5">
|
|
<div class="row justify-content-center">
|
|
<div class="col-md-8">
|
|
<div class="card">
|
|
<div class="card-body">
|
|
<h2 class="card-title">User Profile</h2>
|
|
<p><strong>Email:</strong> <?php echo htmlspecialchars($email); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mt-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Favorite Locations</h5>
|
|
<ul class="list-group list-group-flush" id="favorite-locations-list">
|
|
<?php foreach ($favorite_locations as $location): ?>
|
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
|
<?php echo htmlspecialchars($location['city_name']); ?>
|
|
<button class="btn btn-sm btn-danger delete-location-btn" data-id="<?php echo $location['id']; ?>">Delete</button>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card mt-4">
|
|
<div class="card-body">
|
|
<h5 class="card-title">Your Subscriptions</h5>
|
|
<ul id="subscription-list" class="list-group list-group-flush">
|
|
<?php foreach ($subscriptions as $subscription): ?>
|
|
<li class='list-group-item d-flex justify-content-between align-items-center'>
|
|
<?php echo htmlspecialchars($subscription['city_name']) . " at " . htmlspecialchars($subscription['delivery_time']); ?>
|
|
<button class='btn btn-sm btn-danger unsubscribe-btn' data-id='<?php echo $subscription['id']; ?>'>Unsubscribe</button>
|
|
</li>
|
|
<?php endforeach; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
<?php require_once __DIR__ . '/includes/footer.php'; ?>
|