Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
include "db.php";
// Get the user ID from the URL
$profile_user_id = isset($_GET['id']) ? (int)$_GET['id'] : 0;
// If no user ID is provided, redirect to homepage
if ($profile_user_id === 0) {
header("Location: homepage.php");
exit();
}
// Check if the logged-in user is viewing their own profile
$is_own_profile = isset($_SESSION['user_id']) && $_SESSION['user_id'] === $profile_user_id;
$logged_in = isset($_SESSION['user_id']);
// Get the user's information
$stmt = $conn->prepare("SELECT username, profile_photo, bio FROM users WHERE id = ?");
$stmt->execute([$profile_user_id]);
$user = $stmt->fetch();
// If user doesn't exist, redirect to homepage
if (!$user) {
header("Location: homepage.php");
exit();
}
// Get the user's public lists
$stmt = $conn->prepare("
SELECT wl.id, wl.name, wl.created_at, wl.score, COUNT(lw.id) as word_count
FROM word_lists wl
LEFT JOIN list_words lw ON wl.id = lw.list_id
WHERE wl.user_id = ? AND wl.public = 1
GROUP BY wl.id
ORDER BY wl.created_at DESC
");
$stmt->execute([$profile_user_id]);
$public_lists = $stmt->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title><?= htmlspecialchars($user['username']) ?>'s Profile - ELearner</title>
<link href="https://cdn.jsdelivr.net/npm/tailwindcss@2.2.19/dist/tailwind.min.css" rel="stylesheet">
<link rel="stylesheet" href="styles.css">
<link rel="stylesheet" href="font-styles.css">
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/5.15.3/css/all.min.css">
<style>
.profile-photo {
width: 150px;
height: 150px;
object-fit: cover;
border-radius: 50%;
}
</style>
</head>
<body class="bg-gray-100 min-h-screen">
<div class="container mx-auto px-4 py-4 sm:py-8">
<header class="bg-white rounded-lg shadow-md p-4 sm:p-6 mb-6 sm:mb-8">
<div class="flex flex-wrap items-center justify-between">
<div class="flex items-center">
<a href="homepage.php">
<img src="images/icon-e-learner-blue.png" alt="ELearner Logo" class="h-10 sm:h-12 mr-3 sm:mr-4">
</a>
<div>
<h1 class="text-2xl sm:text-3xl font-bold text-blue-600">ELearner</h1>
<p class="text-sm sm:text-base text-gray-600">Viewing <?= htmlspecialchars($user['username']) ?>'s Profile</p>
</div>
</div>
<!-- Mobile menu button -->
<button id="mobileMenuBtn" class="md:hidden p-2 rounded text-blue-600 hover:bg-blue-100">
<svg class="w-6 h-6" fill="none" stroke="currentColor" viewBox="0 0 24 24" xmlns="http://www.w3.org/2000/svg">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M4 6h16M4 12h16M4 18h16"></path>
</svg>
</button>
<nav id="desktopMenu" class="hidden md:block">
<ul class="flex space-x-4 sm:space-x-6">
<li><a href="homepage.php" class="text-blue-500 font-medium hover:underline">Home</a></li>
<?php if($logged_in): ?>
<li><a href="index.php" class="text-blue-500 font-medium hover:underline">Vocabulary Tool</a></li>
<li><a href="my_lists.php" class="text-blue-500 font-medium hover:underline">My Lists</a></li>
<li><a href="list_hub.php" class="text-blue-500 font-medium hover:underline">List Hub</a></li>
<li><a href="profile.php" class="text-blue-500 font-medium hover:underline">My Profile</a></li>
<?php if(isset($_SESSION['is_admin']) && $_SESSION['is_admin'] == 1): ?>
<li><a href="admin.php" class="text-purple-500 font-medium hover:underline">Admin</a></li>
<?php endif; ?>
<li><a href="logout.php" class="text-red-500 font-medium hover:underline">Logout</a></li>
<?php else: ?>
<li><a href="login.php" class="text-blue-500 font-medium hover:underline">Login</a></li>
<li><a href="register.php" class="text-blue-500 font-medium hover:underline">Register</a></li>
<?php endif; ?>
<li>
<button id="fontToggleBtn" class="bg-purple-500 text-white px-3 py-1 rounded hover:bg-purple-600">
Toggle Font
</button>
</li>
</ul>
</nav>
</div>
<!-- Mobile menu, hidden by default -->
<nav id="mobileMenu" class="md:hidden hidden mt-4 pb-2">
<ul class="flex flex-col space-y-3">
<li><a href="homepage.php" class="block text-blue-500 font-medium hover:underline">Home</a></li>
<?php if($logged_in): ?>
<li><a href="index.php" class="block text-blue-500 font-medium hover:underline">Vocabulary Tool</a></li>
<li><a href="my_lists.php" class="block text-blue-500 font-medium hover:underline">My Lists</a></li>
<li><a href="list_hub.php" class="block text-blue-500 font-medium hover:underline">List Hub</a></li>
<li><a href="profile.php" class="block text-blue-500 font-medium hover:underline">My Profile</a></li>
<?php if(isset($_SESSION['is_admin']) && $_SESSION['is_admin'] == 1): ?>
<li><a href="admin.php" class="block text-purple-500 font-medium hover:underline">Admin</a></li>
<?php endif; ?>
<li><a href="logout.php" class="block text-red-500 font-medium hover:underline">Logout</a></li>
<?php else: ?>
<li><a href="login.php" class="block text-blue-500 font-medium hover:underline">Login</a></li>
<li><a href="register.php" class="block text-blue-500 font-medium hover:underline">Register</a></li>
<?php endif; ?>
<li>
<button id="mobileFontToggleBtn" class="bg-purple-500 text-white px-3 py-1 rounded hover:bg-purple-600">
Toggle Font
</button>
</li>
</ul>
</nav>
</header>
<div class="flex flex-col md:flex-row gap-6">
<!-- User Profile Card -->
<div class="w-full md:w-1/3">
<div class="bg-white rounded-lg shadow-md p-6 text-center">
<h2 class="text-xl font-bold mb-4">User Profile</h2>
<div class="mb-4">
<?php if (!empty($user['profile_photo']) && file_exists($user['profile_photo'])): ?>
<img src="<?= htmlspecialchars($user['profile_photo']) ?>" alt="Profile Photo" class="profile-photo mx-auto">
<?php else: ?>
<div class="profile-photo bg-gray-200 flex items-center justify-center mx-auto">
<i class="fas fa-user text-gray-400 text-5xl"></i>
</div>
<?php endif; ?>
</div>
<h3 class="text-lg font-medium"><?= htmlspecialchars($user['username']) ?></h3>
<?php if ($is_own_profile): ?>
<div class="mt-4">
<a href="profile.php" class="text-blue-500 hover:underline">
<i class="fas fa-edit mr-1"></i> Edit Your Profile
</a>
</div>
<?php endif; ?>
<div class="mt-6 text-left">
<h4 class="font-medium mb-2 border-b pb-1">About <?= htmlspecialchars($user['username']) ?></h4>
<?php if (!empty($user['bio'])): ?>
<p class="text-gray-700 whitespace-pre-line"><?= nl2br(htmlspecialchars($user['bio'])) ?></p>
<?php else: ?>
<p class="text-gray-500 italic">No bio available.</p>
<?php endif; ?>
</div>
</div>
</div>
<!-- User's Public Lists -->
<div class="w-full md:w-2/3">
<div class="bg-white rounded-lg shadow-md p-6">
<h2 class="text-xl font-bold mb-6"><?= htmlspecialchars($user['username']) ?>'s Public Lists</h2>
<?php if (count($public_lists) === 0): ?>
<div class="bg-gray-50 p-4 rounded text-center">
<p class="text-gray-500">
<?= htmlspecialchars($user['username']) ?> has not published any lists yet.
</p>
</div>
<?php else: ?>
<div class="space-y-4">
<?php foreach ($public_lists as $list): ?>
<div class="border rounded-lg p-4 hover:shadow-md transition-shadow">
<div class="flex justify-between items-start">
<div>
<h3 class="font-medium text-lg"><?= htmlspecialchars($list['name']) ?></h3>
<p class="text-sm text-gray-500">
<?= $list['word_count'] ?> words • Created on <?= date('F j, Y', strtotime($list['created_at'])) ?>
</p>
</div>
<?php if ($list['score'] !== null): ?>
<div class="bg-blue-50 px-3 py-1 rounded-full text-sm">
<span class="font-medium">Score: </span>
<span class="<?= $list['score'] >= 80 ? 'text-green-600' : ($list['score'] >= 50 ? 'text-yellow-600' : 'text-red-600') ?> font-medium">
<?= $list['score'] ?>%
</span>
</div>
<?php endif; ?>
</div>
<div class="mt-3 flex justify-end">
<a href="list_hub.php?preview=<?= $list['id'] ?>" class="text-blue-500 hover:underline flex items-center">
<i class="fas fa-eye mr-1"></i> View List
</a>
<?php if($logged_in && !$is_own_profile): ?>
<form method="post" action="list_hub.php" class="ml-4">
<input type="hidden" name="list_id" value="<?= $list['id'] ?>">
<button type="submit" name="copy_list" class="text-green-500 hover:underline flex items-center">
<i class="fas fa-copy mr-1"></i> Save to My Lists
</button>
</form>
<?php endif; ?>
</div>
</div>
<?php endforeach; ?>
</div>
<div class="mt-6">
<a href="list_hub.php" class="text-blue-500 hover:underline">
<i class="fas fa-arrow-left mr-1"></i> Back to List Hub
</a>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
<script>
// Mobile menu toggle
document.getElementById("mobileMenuBtn").addEventListener("click", function() {
const mobileMenu = document.getElementById("mobileMenu");
mobileMenu.classList.toggle("hidden");
});
// Copy font toggle functionality to mobile button
if (document.getElementById("mobileFontToggleBtn")) {
document.getElementById("mobileFontToggleBtn").addEventListener("click", function() {
document.getElementById("fontToggleBtn").click();
});
}
</script>
<script src="font-toggle.js"></script>
</body>
</html>