34921-vm/dashboard.php
Flatlogic Bot a60b54ddf4 1.9
2025-10-14 14:21:30 +00:00

160 lines
6.4 KiB
PHP
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

<?php
session_start();
require_once 'db/config.php';
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit;
}
$userId = $_SESSION['user_id'];
$stmt = db()->prepare("SELECT * FROM users WHERE id = ?");
$stmt->execute([$userId]);
$user = $stmt->fetch(PDO::FETCH_ASSOC);
if (!$user) {
session_destroy();
header("Location: login.php");
exit;
}
// Fetch all skills
$skills_by_category = [];
$stmt = db()->query("SELECT * FROM skills ORDER BY category, title");
$all_skills = $stmt->fetchAll(PDO::FETCH_ASSOC);
foreach ($all_skills as $skill) {
$skills_by_category[$skill['category']][] = $skill;
}
// Fetch enrolled skills for the current user
$stmt = db()->prepare("
SELECT s.id, s.title, s.category, s.thumbnail, e.progress
FROM enrollments e
JOIN skills s ON e.skill_id = s.id
WHERE e.user_id = ?
");
$stmt->execute([$userId]);
$enrolled_skills = $stmt->fetchAll(PDO::FETCH_ASSOC);
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>Dashboard - TAP2SKILL</title>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.5/font/bootstrap-icons.css">
<link rel="stylesheet" href="assets/css/custom.css?v=<?php echo time(); ?>">
</head>
<body>
<div class="sidebar">
<a class="navbar-brand" href="index.php">TAP2SKILL</a>
<hr>
<ul class="nav flex-column">
<li class="nav-item">
<a class="nav-link active" href="dashboard.php">
<i class="bi bi-grid-1x2-fill"></i>
Dashboard
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="bi bi-person-circle"></i>
Profile
</a>
</li>
<li class="nav-item">
<a class="nav-link" href="#">
<i class="bi bi-gear-fill"></i>
Settings
</a>
</li>
</ul>
<hr>
<a href="logout.php" class="btn btn-outline-primary">Logout</a>
</div>
<div class="main-content">
<div class="container-fluid">
<div class="d-flex justify-content-between flex-wrap flex-md-nowrap align-items-center pt-3 pb-2 mb-3 border-bottom">
<h1 class="h2">Welcome, <?php echo htmlspecialchars($user['username']); ?>!</h1>
</div>
<!-- Quick Access Buttons -->
<div class="row mb-4">
<div class="col-md-4">
<a href="#skill-explorer" class="btn btn-primary btn-lg w-100">Explore Skills</a>
</div>
<div class="col-md-4">
<a href="#enrolled-skills" class="btn btn-success btn-lg w-100">Continue Learning</a>
</div>
<div class="col-md-4">
<a href="#" class="btn btn-info btn-lg w-100">Community</a>
</div>
</div>
<!-- Enrolled Skills Section -->
<section id="enrolled-skills" class="mb-5">
<h2 class="h4">My Enrolled Skills</h2>
<div class="row">
<?php if (empty($enrolled_skills)): ?>
<div class="col">
<div class="card">
<div class="card-body text-center">
<p class="card-text">You havent enrolled in any skills yet. Explore new skills to start learning!</p>
<a href="#skill-explorer" class="btn btn-primary">Explore Skills</a>
</div>
</div>
</div>
<?php else: ?>
<?php foreach ($enrolled_skills as $skill): ?>
<div class="col-md-6 col-lg-4 mb-3">
<div class="card">
<img src="<?php echo htmlspecialchars($skill['thumbnail']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($skill['title']); ?>">
<div class="card-body">
<h5 class="card-title"><?php echo htmlspecialchars($skill['title']); ?></h5>
<p class="card-text text-muted"><?php echo htmlspecialchars($skill['category']); ?></p>
<div class="progress mb-2">
<div class="progress-bar" role="progressbar" style="width: <?php echo $skill['progress']; ?>%;" aria-valuenow="<?php echo $skill['progress']; ?>" aria-valuemin="0" aria-valuemax="100"><?php echo $skill['progress']; ?>%</div>
</div>
<a href="learn.php?skill_id=<?php echo $skill['id']; ?>" class="btn btn-primary mt-3">Continue Learning</a>
</div>
</div>
</div>
<?php endforeach; ?>
<?php endif; ?>
</div>
</section>
<!-- Skill Explorer Section -->
<section id="skill-explorer">
<h2 class="h4">Skill Explorer</h2>
<?php foreach ($skills_by_category as $category => $skills): ?>
<h3 class="h5 mt-4"><?php echo htmlspecialchars($category); ?></h3>
<div class="row">
<?php foreach ($skills as $skill): ?>
<div class="col-md-6 col-lg-3 mb-3">
<div class="card h-100">
<img src="<?php echo htmlspecialchars($skill['thumbnail']); ?>" class="card-img-top" alt="<?php echo htmlspecialchars($skill['title']); ?>">
<div class="card-body d-flex flex-column">
<h5 class="card-title"><?php echo htmlspecialchars($skill['title']); ?></h5>
<p class="card-text flex-grow-1"><?php echo htmlspecialchars($skill['description']); ?></p>
<a href="#" class="btn btn-outline-primary mt-auto">Enroll</a>
</div>
</div>
</div>
<?php endforeach; ?>
</div>
<?php endforeach; ?>
</section>
</div>
</div>
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/js/bootstrap.bundle.min.js"></script>
</body>
</html>