36692-vm/dashboard.php
2025-12-05 19:51:38 +00:00

87 lines
3.3 KiB
PHP

<?php
if (!isset($_SESSION['user_id'])) {
header('Location: login.php');
exit;
}
require_once 'includes/header.php';
?>
<div class="container mt-5">
<?php
if (isset($_SESSION['message'])) {
echo "<div class='alert alert-success'>" . $_SESSION['message'] . "</div>";
unset($_SESSION['message']);
}
if (isset($_SESSION['error'])) {
echo "<div class='alert alert-danger'>" . $_SESSION['error'] . "</div>";
unset($_SESSION['error']);
}
?>
<div class="row">
<div class="col-md-12">
<h1>Welcome to your Dashboard, <?php echo htmlspecialchars($_SESSION['user_name']); ?>!</h1>
<p>This is your central hub to manage your account and services. More features will be added soon.</p>
</div>
</div>
<div class="row mt-5">
<div class="col-md-12">
<h2>Your Subscribed Services</h2>
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->prepare("SELECT s.name, s.description, us.id as user_service_id FROM services s JOIN user_services us ON s.id = us.service_id WHERE us.user_id = ? AND us.status = 'active'");
$stmt->execute([$_SESSION['user_id']]);
$user_services = $stmt->fetchAll(PDO::FETCH_ASSOC);
if (count($user_services) > 0) {
echo "<ul class='list-group'>";
foreach ($user_services as $service) {
echo "<li class='list-group-item d-flex justify-content-between align-items-center'>";
echo "<div><strong>" . htmlspecialchars($service['name']) . "</strong>: " . htmlspecialchars($service['description']) . "</div>";
echo "<a href='cancel_subscription.php?user_service_id=" . $service['user_service_id'] . "' class='btn btn-danger btn-sm' onclick='return confirm("Are you sure you want to cancel this subscription?")'>Cancel</a>";
echo "</li>";
}
echo "</ul>";
} else {
echo "<p>You are not subscribed to any services yet.</p>";
}
?>
</div>
</div>
<div class="row mt-5">
<div class="col-md-12">
<h2>Available Services</h2>
</div>
</div>
<div class="row">
<?php
require_once 'db/config.php';
$pdo = db();
$stmt = $pdo->query("SELECT * FROM services");
$services = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($services as $service) {
?>
<div class="col-md-4 mb-4">
<div class="card">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($service['name']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($service['description']); ?></p>
<p class="card-text"><strong>$<?php echo htmlspecialchars($service['price']); ?></strong> / <?php echo htmlspecialchars($service['billing_cycle']); ?></p>
<a href="subscribe.php?service_id=<?php echo $service['id']; ?>" class="btn btn-primary">Subscribe</a>
</div>
</div>
</div>
<?php
}
?>
</div>
</div>
<?php require_once 'includes/footer.php'; ?>