137 lines
5.8 KiB
PHP
137 lines
5.8 KiB
PHP
<?php
|
|
session_start();
|
|
require_once 'db/config.php';
|
|
|
|
// If the user is not logged in, redirect to the login page
|
|
if (!isset($_SESSION['user_id'])) {
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
$user = null;
|
|
$subscription = null;
|
|
$error_message = '';
|
|
|
|
try {
|
|
$pdo = db();
|
|
|
|
// Fetch user details
|
|
$stmt = $pdo->prepare('SELECT * FROM users WHERE id = ?');
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$user = $stmt->fetch();
|
|
|
|
// Fetch subscription details
|
|
// This part assumes you have a 'subscriptions' table that links to Stripe plan IDs.
|
|
// You might need to adjust the table and column names (e.g., stripe_plan_id, status, etc.)
|
|
$stmt = $pdo->prepare("SELECT * FROM subscriptions WHERE user_id = ? AND status = 'active'");
|
|
$stmt->execute([$_SESSION['user_id']]);
|
|
$subscription = $stmt->fetch();
|
|
|
|
} catch (PDOException $e) {
|
|
$error_message = "Database error: " . $e->getMessage();
|
|
}
|
|
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="en">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>My Profile - AI Recipe Generator</title>
|
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
|
|
<link rel="stylesheet" href="https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&display=swap">
|
|
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
|
|
</head>
|
|
<body>
|
|
|
|
<!-- Navbar -->
|
|
<nav class="navbar navbar-expand-lg navbar-light bg-white fixed-top">
|
|
<div class="container">
|
|
<a class="navbar-brand" href="index.php">AI Recipe Generator</a>
|
|
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav" aria-controls="navbarNav" aria-expanded="false" aria-label="Toggle navigation">
|
|
<span class="navbar-toggler-icon"></span>
|
|
</button>
|
|
<div class="collapse navbar-collapse" id="navbarNav">
|
|
<ul class="navbar-nav ms-auto">
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="index.php">Home</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="pricing.php">Pricing</a>
|
|
</li>
|
|
<?php if (isset($_SESSION['user_id'])): ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link active" href="profile.php">Profile</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="logout.php">Logout</a>
|
|
</li>
|
|
<?php else: ?>
|
|
<li class="nav-item">
|
|
<a class="nav-link" href="login.php">Login</a>
|
|
</li>
|
|
<li class="nav-item">
|
|
<a class="btn btn-primary" href="register.php">Register</a>
|
|
</li>
|
|
<?php endif; ?>
|
|
</ul>
|
|
</div>
|
|
</div>
|
|
</nav>
|
|
|
|
<!-- Main Content -->
|
|
<main>
|
|
<div class="container py-5">
|
|
<div class="auth-container" style="max-width: 800px;">
|
|
<h2 class="text-center mb-4">My Profile</h2>
|
|
|
|
<?php if ($error_message): ?>
|
|
<div class="alert alert-danger"><?php echo htmlspecialchars($error_message); ?></div>
|
|
<?php endif; ?>
|
|
|
|
<?php if (isset($_SESSION['flash_message'])): ?>
|
|
<div class="alert alert-success">
|
|
<?php echo htmlspecialchars($_SESSION['flash_message']); unset($_SESSION['flash_message']); ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<?php if ($user): ?>
|
|
<div class="card mb-4">
|
|
<div class="card-header">Account Details</div>
|
|
<div class="card-body">
|
|
<p><strong>Username:</strong> <?php echo htmlspecialchars($user['username']); ?></p>
|
|
<p><strong>Email:</strong> <?php echo htmlspecialchars($user['email']); ?></p>
|
|
<p><strong>Phone:</strong> <?php echo htmlspecialchars($user['phone_number'] ?? 'Not provided'); ?></p>
|
|
</div>
|
|
</div>
|
|
|
|
<div class="card">
|
|
<div class="card-header">Subscription Status</div>
|
|
<div class="card-body">
|
|
<?php if ($subscription): ?>
|
|
<h5 class="card-title">Active Plan: <span class="text-primary"><?php echo htmlspecialchars(ucfirst(str_replace('price_', '', $subscription['stripe_plan_id']))); ?></span></h5>
|
|
<p><strong>Status:</strong> <span class="badge bg-success"><?php echo htmlspecialchars(ucfirst($subscription['status'])); ?></span></p>
|
|
<p>Subscribed since: <?php echo htmlspecialchars(date("F j, Y", strtotime($subscription['created_at']))); ?></p>
|
|
<a href="cancel_subscription.php" class="btn btn-danger mt-2">Cancel Subscription</a>
|
|
<?php else: ?>
|
|
<p>You are not subscribed to any plan.</p>
|
|
<a href="pricing.php" class="btn btn-primary">View Plans</a>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
<?php endif; ?>
|
|
</div>
|
|
</div>
|
|
</main>
|
|
|
|
<!-- Footer -->
|
|
<footer class="footer">
|
|
<div class="container text-center">
|
|
<p>© <?php echo date("Y"); ?> AI Recipe Generator. All Rights Reserved.</p>
|
|
</div>
|
|
</footer>
|
|
|
|
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
|
|
</body>
|
|
</html>
|