Current directory: /home/klas4s23/domains/585455.klas4s23.mid-ica.nl/public_html/Gastenboek/uploads
<?php
session_start();
include "db.php";
if (!isset($_SESSION['user_id'])) {
header("Location: login.php");
exit();
}
$user_id = $_SESSION['user_id'];
$success_message = "";
$error_message = "";
// Fetch user's word lists (including is_copy flag)
$stmt = $conn->prepare("
SELECT wl.id, wl.name, wl.created_at, wl.score, wl.public, wl.is_copy, 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 = ?
GROUP BY wl.id
ORDER BY wl.created_at DESC
");
$stmt->execute([$user_id]);
$lists = $stmt->fetchAll();
// If viewing a specific list
$current_list = null;
$list_words = [];
if (isset($_GET['list_id']) && is_numeric($_GET['list_id'])) {
$list_id = $_GET['list_id'];
// Get list details
$stmt = $conn->prepare("SELECT * FROM word_lists WHERE id = ? AND user_id = ?");
$stmt->execute([$list_id, $user_id]);
$current_list = $stmt->fetch();
if ($current_list) {
// Get words in this list
$stmt = $conn->prepare("SELECT * FROM list_words WHERE list_id = ? ORDER BY id");
$stmt->execute([$list_id]);
$list_words = $stmt->fetchAll();
}
}
// Handle editing mode
$editing_mode = isset($_GET['edit']) && $_GET['edit'] == 1 && $current_list;
// Handle list renaming
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['rename_list'])) {
$list_id = $_POST['list_id'];
$new_name = $_POST['new_name'];
$stmt = $conn->prepare("UPDATE word_lists SET name = ? WHERE id = ? AND user_id = ?");
$stmt->execute([$new_name, $list_id, $user_id]);
// Redirect to refresh
header("Location: my_lists.php?list_id=" . $list_id);
exit();
}
// Handle list deletion
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_list'])) {
$list_id = $_POST['list_id'];
$stmt = $conn->prepare("DELETE FROM word_lists WHERE id = ? AND user_id = ?");
$stmt->execute([$list_id, $user_id]);
// Redirect to the lists page
header("Location: my_lists.php");
exit();
}
// Handle word deletion
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['delete_word'])) {
$word_id = (int)$_POST['word_id'];
$list_id = (int)$_POST['list_id'];
$stmt = $conn->prepare("DELETE FROM list_words WHERE id = ? AND list_id = ?");
$stmt->execute([$word_id, $list_id]);
// Redirect to refresh the page
header("Location: my_lists.php?list_id=$list_id&edit=1");
exit();
}
// Handle word editing
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['edit_word'])) {
$word_id = (int)$_POST['word_id'];
$list_id = (int)$_POST['list_id'];
$dutch = trim($_POST['dutch']);
$english = trim($_POST['english']);
// Basic validation
if (empty($dutch) || empty($english)) {
$error_message = "Both Dutch and English words are required.";
} else {
$stmt = $conn->prepare("UPDATE list_words SET dutch = ?, english = ? WHERE id = ? AND list_id = ?");
$stmt->execute([$dutch, $english, $word_id, $list_id]);
// Redirect to refresh the page
header("Location: my_lists.php?list_id=$list_id&edit=1");
exit();
}
}
// Handle adding a new word
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['add_word'])) {
$list_id = (int)$_POST['list_id'];
$dutch = trim($_POST['dutch']);
$english = trim($_POST['english']);
// Basic validation
if (empty($dutch) || empty($english)) {
$error_message = "Both Dutch and English words are required.";
} else {
$stmt = $conn->prepare("INSERT INTO list_words (list_id, dutch, english) VALUES (?, ?, ?)");
$stmt->execute([$list_id, $dutch, $english]);
// Redirect to refresh the page
header("Location: my_lists.php?list_id=$list_id&edit=1");
exit();
}
}
// Handle toggling list visibility (private/public)
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['toggle_visibility'])) {
$list_id = $_POST['list_id'];
$current_visibility = $_POST['current_visibility'];
$new_visibility = $current_visibility == 1 ? 0 : 1; // Toggle between 0 and 1
// First check if this is a copied list - don't allow making it public
$stmt = $conn->prepare("SELECT is_copy FROM word_lists WHERE id = ? AND user_id = ?");
$stmt->execute([$list_id, $user_id]);
$list_data = $stmt->fetch();
if ($list_data && $list_data['is_copy'] == 1 && $new_visibility == 1) {
// If trying to make a copied list public, redirect with an error
$_SESSION['list_error'] = "Copied lists cannot be made public. Only your original lists can be shared in the List Hub.";
// Redirect to refresh (with list_id if we were viewing a specific list)
if (isset($_GET['list_id'])) {
header("Location: my_lists.php?list_id=" . $_GET['list_id']);
} else {
header("Location: my_lists.php");
}
exit();
}
// If not a copied list or making it private, proceed with the update
$stmt = $conn->prepare("UPDATE word_lists SET public = ? WHERE id = ? AND user_id = ?");
$stmt->execute([$new_visibility, $list_id, $user_id]);
// Redirect to refresh (with list_id if we were viewing a specific list)
if (isset($_GET['list_id'])) {
header("Location: my_lists.php?list_id=" . $_GET['list_id']);
} else {
header("Location: my_lists.php");
}
exit();
}
// Process "score_updated" parameter
if (isset($_GET['score_updated']) && $_GET['score_updated'] == 1) {
$success_message = "Your score has been updated successfully!";
}
?>
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>My Word Lists - 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 flex flex-col">
<div class="main-content flex-1">
<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">Your saved word lists</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>
<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>
<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>
<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>
<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>
<?php if(isset($_SESSION['list_error'])): ?>
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
<?= $_SESSION['list_error'] ?>
</div>
<?php unset($_SESSION['list_error']); ?>
<?php endif; ?>
<?php if($success_message): ?>
<div class="bg-green-100 border border-green-400 text-green-700 px-4 py-3 rounded mb-4">
<?= $success_message ?>
</div>
<?php endif; ?>
<?php if($error_message): ?>
<div class="bg-red-100 border border-red-400 text-red-700 px-4 py-3 rounded mb-4">
<?= $error_message ?>
</div>
<?php endif; ?>
<div class="flex flex-col lg:flex-row flex-wrap -mx-4">
<!-- List selection - full width on mobile, 1/3 on larger screens -->
<div class="w-full lg:w-1/3 px-4 mb-6">
<div class="bg-white p-4 sm:p-6 rounded-lg shadow-lg h-full">
<div class="flex justify-between items-center mb-4">
<h2 class="text-xl font-bold">My Word Lists</h2>
<a href="list_hub.php" class="text-blue-500 hover:text-blue-700 flex items-center">
<i class="fas fa-globe-americas mr-1"></i> List Hub
</a>
</div>
<?php if (count($lists) === 0): ?>
<p class="text-gray-500">You haven't saved any word lists yet.</p>
<div class="mt-4">
<a href="index.php" class="inline-block bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
Create Your First List
</a>
</div>
<?php else: ?>
<ul class="divide-y divide-gray-200">
<?php foreach ($lists as $list): ?>
<li class="py-3">
<div class="flex items-center">
<a href="?list_id=<?= $list['id'] ?>" class="flex-grow block hover:bg-gray-50 rounded p-2 <?= (isset($_GET['list_id']) && $_GET['list_id'] == $list['id']) ? 'bg-blue-50' : '' ?>">
<div class="flex items-center">
<div class="flex-grow">
<div class="font-medium">
<?= htmlspecialchars($list['name']) ?>
<?php if($list['is_copy'] == 1): ?>
<span class="text-xs text-orange-500">(copied)</span>
<?php endif; ?>
</div>
<div class="text-sm text-gray-500">
<?= $list['word_count'] ?> words •
<?= date('M j, Y', strtotime($list['created_at'])) ?>
<?php if($list['score'] !== null): ?>
• Score: <span class="font-medium"><?= $list['score'] ?>%</span>
<?php endif; ?>
</div>
</div>
<?php if($list['public']): ?>
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-green-100 text-green-800">
<i class="fas fa-globe-americas mr-1"></i> Public
</span>
<?php elseif($list['is_copy'] == 1): ?>
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-orange-100 text-orange-800">
<i class="fas fa-copy mr-1"></i> Copied
</span>
<?php else: ?>
<span class="ml-2 inline-flex items-center px-2.5 py-0.5 rounded-full text-xs font-medium bg-gray-100 text-gray-800">
<i class="fas fa-lock mr-1"></i> Private
</span>
<?php endif; ?>
</div>
</a>
</div>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
</div>
<!-- Word list details - full width on mobile, 2/3 on larger screens -->
<div class="w-full lg:w-2/3 px-4">
<div class="bg-white p-4 sm:p-6 rounded-lg shadow-lg">
<?php if ($current_list): ?>
<div class="flex flex-wrap justify-between items-center mb-6">
<h2 class="text-xl font-bold mb-2 sm:mb-0"><?= htmlspecialchars($current_list['name']) ?></h2>
<div class="flex flex-wrap gap-2">
<a href="learn_list.php?list_id=<?= $current_list['id'] ?>" class="bg-blue-500 text-white px-3 py-1 rounded hover:bg-blue-600">
<i class="fas fa-graduation-cap mr-1"></i> Start Learning
</a>
<?php if (!$editing_mode): ?>
<a href="?list_id=<?= $current_list['id'] ?>&edit=1" class="bg-purple-500 text-white px-3 py-1 rounded hover:bg-purple-600">
<i class="fas fa-edit mr-1"></i> Edit Words
</a>
<?php else: ?>
<a href="?list_id=<?= $current_list['id'] ?>" class="bg-gray-500 text-white px-3 py-1 rounded hover:bg-gray-600">
<i class="fas fa-eye mr-1"></i> View Mode
</a>
<?php endif; ?>
<button id="renameButton" class="bg-yellow-500 text-white px-3 py-1 rounded hover:bg-yellow-600">
<i class="fas fa-edit mr-1"></i> Rename
</button>
<?php if($current_list['is_copy'] == 1): ?>
<!-- Disable public toggle for copied lists -->
<button disabled class="bg-gray-400 text-white px-3 py-1 rounded cursor-not-allowed" title="Copied lists cannot be made public">
<i class="fas fa-lock mr-1"></i> Cannot Make Public
</button>
<?php else: ?>
<!-- Regular public toggle for original lists -->
<form method="post" class="inline">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<input type="hidden" name="current_visibility" value="<?= $current_list['public'] ?>">
<button type="submit" name="toggle_visibility" class="<?= $current_list['public'] ? 'bg-green-500 hover:bg-green-600' : 'bg-gray-500 hover:bg-gray-600' ?> text-white px-3 py-1 rounded">
<?php if($current_list['public']): ?>
<i class="fas fa-lock mr-1"></i> Make Private
<?php else: ?>
<i class="fas fa-globe-americas mr-1"></i> Make Public
<?php endif; ?>
</button>
</form>
<?php endif; ?>
<form method="post" onsubmit="return confirm('Are you sure you want to delete this list?');">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<button type="submit" name="delete_list" class="bg-red-500 text-white px-3 py-1 rounded hover:bg-red-600">
<i class="fas fa-trash-alt mr-1"></i> Delete
</button>
</form>
</div>
</div>
<!-- Rename Form (hidden by default) -->
<div id="renameForm" class="mb-6 hidden">
<form method="post" class="flex flex-wrap gap-2">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<input type="text" name="new_name" value="<?= htmlspecialchars($current_list['name']) ?>"
class="flex-grow p-2 border rounded" required>
<button type="submit" name="rename_list" class="bg-green-500 text-white px-3 py-1 rounded hover:bg-green-600">
<i class="fas fa-save mr-1"></i> Save
</button>
<button type="button" id="cancelRename" class="bg-gray-300 text-gray-800 px-3 py-1 rounded hover:bg-gray-400">
<i class="fas fa-times mr-1"></i> Cancel
</button>
</form>
</div>
<div class="flex flex-wrap gap-4 mb-4">
<p class="text-gray-500">
Created on <?= date('F j, Y', strtotime($current_list['created_at'])) ?>
<?php if($current_list['score'] !== null): ?>
• Current score: <span class="font-medium <?= $current_list['score'] >= 80 ? 'text-green-500' : ($current_list['score'] >= 50 ? 'text-yellow-500' : 'text-red-500') ?>"><?= $current_list['score'] ?>%</span>
<?php endif; ?>
</p>
<p>
<?php if($current_list['is_copy'] == 1): ?>
<span class="text-orange-600">
<i class="fas fa-copy"></i> This is a copied list and cannot be made public
</span>
<?php elseif($current_list['public']): ?>
<span class="text-green-600">
<i class="fas fa-globe-americas"></i> This list is public and visible in the List Hub
</span>
<?php else: ?>
<span class="text-gray-600">
<i class="fas fa-lock"></i> This list is private and only visible to you
</span>
<?php endif; ?>
</p>
</div>
<?php if (count($list_words) === 0): ?>
<div class="bg-yellow-50 p-4 rounded-md">
<p class="text-yellow-700">This list is empty. You can add words from the Vocabulary Tool.</p>
<?php if ($editing_mode): ?>
<!-- Add word form in editing mode -->
<div class="mt-4 p-4 bg-white border rounded">
<h3 class="font-medium mb-3">Add New Word</h3>
<form method="post" class="space-y-3">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label class="block text-sm text-gray-600 mb-1">Dutch</label>
<input type="text" name="dutch" class="w-full p-2 border rounded" required>
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">English</label>
<input type="text" name="english" class="w-full p-2 border rounded" required>
</div>
</div>
<button type="submit" name="add_word" class="bg-green-500 text-white px-3 py-2 rounded hover:bg-green-600">
<i class="fas fa-plus mr-1"></i> Add Word
</button>
</form>
</div>
<?php else: ?>
<a href="index.php" class="inline-block mt-2 text-blue-500 hover:underline">Go to Vocabulary Tool</a>
<?php endif; ?>
</div>
<?php else: ?>
<?php if ($editing_mode): ?>
<!-- Add word form in editing mode -->
<div class="mb-4 p-4 bg-gray-50 border rounded">
<h3 class="font-medium mb-3">Add New Word</h3>
<form method="post" class="space-y-3">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<div class="grid grid-cols-1 sm:grid-cols-2 gap-3">
<div>
<label class="block text-sm text-gray-600 mb-1">Dutch</label>
<input type="text" name="dutch" class="w-full p-2 border rounded" required>
</div>
<div>
<label class="block text-sm text-gray-600 mb-1">English</label>
<input type="text" name="english" class="w-full p-2 border rounded" required>
</div>
</div>
<button type="submit" name="add_word" class="bg-green-500 text-white px-3 py-2 rounded hover:bg-green-600">
<i class="fas fa-plus mr-1"></i> Add Word
</button>
</form>
</div>
<?php endif; ?>
<div class="overflow-x-auto">
<table class="w-full border">
<thead>
<tr class="bg-gray-200">
<th class="border p-2">Nederlands</th>
<th class="border p-2">Engels</th>
<?php if ($editing_mode): ?>
<th class="border p-2 w-36">Actions</th>
<?php endif; ?>
</tr>
</thead>
<tbody>
<?php foreach ($list_words as $word): ?>
<tr>
<?php if ($editing_mode): ?>
<form method="post">
<input type="hidden" name="word_id" value="<?= $word['id'] ?>">
<input type="hidden" name="list_id" value="<?= $current_list['id'] ?>">
<td class="border p-2">
<input type="text" name="dutch" value="<?= htmlspecialchars($word['dutch']) ?>"
class="w-full p-1 border" required>
</td>
<td class="border p-2">
<input type="text" name="english" value="<?= htmlspecialchars($word['english']) ?>"
class="w-full p-1 border" required>
</td>
<td class="border p-2">
<div class="flex space-x-2">
<button type="submit" name="edit_word" class="bg-blue-500 text-white p-1 rounded hover:bg-blue-600 text-sm w-20">
<i class="fas fa-save mr-1"></i> Save
</button>
<button type="submit" name="delete_word" class="bg-red-500 text-white p-1 rounded hover:bg-red-600 text-sm"
onclick="return confirm('Are you sure you want to delete this word?')">
<i class="fas fa-trash-alt"></i>
</button>
</div>
</td>
</form>
<?php else: ?>
<td class="border p-2"><?= htmlspecialchars($word['dutch']) ?></td>
<td class="border p-2"><?= htmlspecialchars($word['english']) ?></td>
<?php endif; ?>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?>
<?php else: ?>
<div class="text-center py-12">
<h2 class="text-xl font-bold mb-2">Select a Word List</h2>
<p class="text-gray-500">Choose a list from the sidebar to view its contents.</p>
<div class="mt-6">
<a href="list_hub.php" class="inline-block bg-blue-500 text-white px-4 py-2 rounded hover:bg-blue-600">
<i class="fas fa-globe-americas mr-2"></i> Browse Public Lists
</a>
</div>
</div>
<?php endif; ?>
</div>
</div>
</div>
</div>
</div>
<?php include "footer.php"; ?>
<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() {
// Trigger the same behavior as the desktop button
document.getElementById("fontToggleBtn").click();
});
}
// Rename functionality
document.addEventListener('DOMContentLoaded', function() {
const renameButton = document.getElementById('renameButton');
const renameForm = document.getElementById('renameForm');
const cancelRename = document.getElementById('cancelRename');
if (renameButton) {
renameButton.addEventListener('click', function() {
renameForm.classList.remove('hidden');
renameButton.parentElement.classList.add('hidden');
});
}
if (cancelRename) {
cancelRename.addEventListener('click', function() {
renameForm.classList.add('hidden');
renameButton.parentElement.classList.remove('hidden');
});
}
});
</script>
<script src="font-toggle.js"></script>
</body>
</html>