Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
include "db.php";
// Get all reviews with usernames
try {
$stmt = $conn->prepare("
SELECT r.*, u.username
FROM reviews r
JOIN users u ON r.user_id = u.id
ORDER BY r.created_at DESC
");
$stmt->execute();
$reviews = $stmt->fetchAll();
} catch (PDOException $e) {
$reviews = [];
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>All Reviews - 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">
</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">User Reviews</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(isset($_SESSION['user_id'])): ?>
<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(isset($_SESSION['user_id'])): ?>
<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>
<main class="bg-white rounded-lg shadow-md p-4 sm:p-6">
<div class="flex justify-between items-center mb-6">
<h2 class="text-xl sm:text-2xl font-bold">All User Reviews</h2>
<?php if(isset($_SESSION['user_id'])): ?>
<a href="review.php" class="inline-block bg-yellow-500 text-white px-4 py-2 rounded hover:bg-yellow-600">Leave a Review</a>
<?php endif; ?>
</div>
<?php if (count($reviews) === 0): ?>
<div class="bg-gray-50 p-6 rounded text-center">
<p class="text-gray-500">No reviews yet. Be the first to share your experience!</p>
<?php if(isset($_SESSION['user_id'])): ?>
<a href="review.php" class="inline-block bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600 mt-4">Write a Review</a>
<?php else: ?>
<p class="text-gray-500 mt-4">Please <a href="login.php" class="text-blue-500 hover:underline">login</a> to leave a review.</p>
<?php endif; ?>
</div>
<?php else: ?>
<div class="grid grid-cols-1 md:grid-cols-2 gap-4">
<?php foreach ($reviews as $review): ?>
<div class="bg-gray-50 p-4 rounded border border-gray-200">
<div class="flex justify-between mb-2">
<span class="font-medium"><?= htmlspecialchars($review['username']) ?></span>
<span class="text-gray-500 text-sm"><?= date('M j, Y', strtotime($review['created_at'])) ?></span>
</div>
<div class="mb-2 text-yellow-500">
<?php for ($i = 0; $i < 5; $i++): ?>
<?php if ($i < $review['rating']): ?>
<i class="fas fa-star"></i>
<?php else: ?>
<i class="far fa-star"></i>
<?php endif; ?>
<?php endfor; ?>
</div>
<p class="text-gray-700"><?= htmlspecialchars($review['comment']) ?></p>
<?php if(isset($_SESSION['user_id']) && $_SESSION['user_id'] == $review['user_id']): ?>
<div class="mt-3 pt-2 border-t border-gray-100">
<a href="review.php" class="text-blue-500 hover:underline">Edit/Delete Your Review</a>
</div>
<?php endif; ?>
</div>
<?php endforeach; ?>
</div>
<?php endif; ?>
<div class="mt-6">
<a href="homepage.php" class="text-blue-500 hover:underline">← Back to Homepage</a>
</div>
</main>
</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>