34681-vm/dashboard.php
Flatlogic Bot 373e36aedb 0.1
2025-10-05 01:54:26 +00:00

141 lines
7.3 KiB
PHP

<?php
session_start();
require_once 'db/config.php';
// If user is not logged in, redirect to login page
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$user_name = $_SESSION['user_name'];
$subscription_status = $_SESSION['subscription_status'] ?? 'free';
$quiz_completed = isset($_SESSION['quiz_answers']);
$recommended_skills = [];
if ($quiz_completed) {
try {
$p_interest = $_SESSION['quiz_answers']['interests'];
$pdo = db();
// Fetch all skills in the category, not just free ones
$stmt = $pdo->prepare("SELECT * FROM skills WHERE category = ?");
$stmt->execute([$p_interest]);
$recommended_skills = $stmt->fetchAll(PDO::FETCH_ASSOC);
} catch (PDOException $e) {
error_log("Database error fetching skills: " . $e->getMessage());
}
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - SunSkills</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.11.3/font/bootstrap-icons.min.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<nav class="navbar navbar-expand-lg navbar-light sticky-top">
<div class="container">
<a class="navbar-brand" href="index.php">SunSkills</a>
<button class="navbar-toggler" type="button" data-bs-toggle="collapse" data-bs-target="#navbarNav">
<span class="navbar-toggler-icon"></span>
</button>
<div class="collapse navbar-collapse" id="navbarNav">
<ul class="navbar-nav ms-auto">
<?php if ($subscription_status == 'free'): ?>
<li class="nav-item"><a class="nav-link btn btn-warning text-dark" href="pricing.php">Upgrade</a></li>
<?php endif; ?>
<li class="nav-item"><a class="nav-link" href="logout.php">Logout</a></li>
</ul>
</div>
</div>
</nav>
<main class="container py-5">
<div class="row">
<div class="col-md-12">
<h1>Welcome, <?php echo htmlspecialchars($user_name); ?>!</h1>
<p class="lead">Your subscription status: <span class="fw-bold <?php echo $subscription_status == 'premium' ? 'text-success' : 'text-warning'; ?>"><?php echo htmlspecialchars(ucfirst($subscription_status)); ?></span></p>
<?php if (isset($_SESSION['success_message'])): ?>
<div class="alert alert-success" role="alert">
<?php echo $_SESSION['success_message']; unset($_SESSION['success_message']); ?>
</div>
<?php endif; ?>
<?php if (isset($_SESSION['error_message'])): ?>
<div class="alert alert-danger" role="alert">
<?php echo $_SESSION['error_message']; unset($_SESSION['error_message']); ?>
</div>
<?php endif; ?>
<?php if ($quiz_completed && !empty($recommended_skills)): ?>
<div class="mt-5">
<h3>Here are your recommended skills!</h3>
<p>Based on your interests in <strong><?php echo htmlspecialchars($_SESSION['quiz_answers']['interests']); ?></strong>, we think you'll love these:</p>
<div class="row">
<?php foreach ($recommended_skills as $skill):
$is_premium = $skill['is_premium'];
$can_access = ($subscription_status == 'premium' || !$is_premium);
?>
<div class="col-md-6 col-lg-4 mb-4">
<div class="card h-100 <?php echo $is_premium ? 'border-warning' : ''; ?>">
<?php if ($is_premium): ?>
<div class="premium-badge">Premium <i class="bi bi-star-fill"></i></div>
<?php endif; ?>
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($skill['title']); ?></h5>
<p class="card-text"><?php echo htmlspecialchars($skill['description']); ?></p>
<div class="ratio ratio-16x9">
<?php if ($can_access): ?>
<iframe src="<?php echo htmlspecialchars($skill['video_url']); ?>" title="<?php echo htmlspecialchars($skill['title']); ?>" allowfullscreen></iframe>
<?php else: ?>
<div class="locked-overlay">
<i class="bi bi-lock-fill"></i>
<p>Upgrade to watch</p>
</div>
<?php endif; ?>
</div>
</div>
<div class="card-footer">
<?php if ($can_access): ?>
<a href="#" class="btn btn-primary w-100">Start Learning</a>
<?php else: ?>
<a href="pricing.php" class="btn btn-warning w-100">Upgrade to Premium</a>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
</div>
<?php elseif ($quiz_completed): ?>
<div class="mt-5">
<h3>No recommendations found yet</h3>
<p>We couldn't find any skills matching your interest in "<?php echo htmlspecialchars($_SESSION['quiz_answers']['interests']); ?>". Please check back later as we add more courses!</p>
</div>
<?php else: ?>
<div class="mt-5 text-center">
<h3>Let's Personalize Your Journey!</h3>
<p>To unlock skill recommendations tailored just for you, please take our quick 3-question quiz.</p>
<a href="quiz.php" class="btn btn-primary btn-lg">Take the Quiz</a>
</div>
<?php endif; ?>
</div>
</div>
</main>
<footer class="footer mt-auto py-3 bg-light">
<div class="container text-center">
<p>&copy; <?php echo date("Y"); ?> SunSkills. All Rights Reserved.</p>
<p><a href="privacy.php">Privacy Policy</a></p>
</div>
</footer>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.2/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>