245 lines
5.5 KiB
PHP
245 lines
5.5 KiB
PHP
<?php
|
|
session_start();
|
|
require __DIR__ . '/data/db.php';
|
|
require __DIR__ . '/functions/logging.php';
|
|
require __DIR__ . '/auth/ldap.php';
|
|
|
|
if (!isset($_SESSION['user'])) {
|
|
$redirect = urlencode($_SERVER['REQUEST_URI']);
|
|
header("Location: login.php?redirect=$redirect");
|
|
exit;
|
|
}
|
|
|
|
$username = $_SESSION['user']['username'];
|
|
$displayName = $_SESSION['user']['displayName'] ?? $username;
|
|
$message = '';
|
|
$isSuccess = true;
|
|
|
|
// Uitloggen knop
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
|
log_action($pdo, $username, 'Uitloggen via wishlist', 'Wishlist script');
|
|
session_unset();
|
|
session_destroy();
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// Verwijderen van wishlist
|
|
if (isset($_POST['delete'])) {
|
|
$stmt = $pdo->prepare("DELETE FROM wishlist WHERE id = ? AND username = ?");
|
|
$stmt->execute([$_POST['delete'], $username]);
|
|
log_action($pdo, $username, 'Wishlist item verwijderd', 'Wishlist script');
|
|
$message = "Je verlanglijstje is verwijderd.";
|
|
}
|
|
|
|
// Opslaan / bijwerken
|
|
if (isset($_POST['save'])) {
|
|
$content = trim($_POST['content'] ?? '');
|
|
$stmt = $pdo->prepare("SELECT id FROM wishlist WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
if ($stmt->rowCount() > 0) {
|
|
$row = $stmt->fetch();
|
|
$stmtUpdate = $pdo->prepare("UPDATE wishlist SET content = ? WHERE id = ?");
|
|
$stmtUpdate->execute([$content, $row['id']]);
|
|
log_action($pdo, $username, 'Wishlist geüpdatet', 'Wishlist script');
|
|
$message = "Je verlanglijstje is bijgewerkt.";
|
|
} else {
|
|
$stmtInsert = $pdo->prepare("INSERT INTO wishlist (username, content) VALUES (?, ?)");
|
|
$stmtInsert->execute([$username, $content]);
|
|
log_action($pdo, $username, 'Wishlist aangemaakt', 'Wishlist script');
|
|
$message = "Je verlanglijstje is aangemaakt!";
|
|
}
|
|
}
|
|
|
|
// Huidige wishlist ophalen
|
|
$stmt = $pdo->prepare("SELECT * FROM wishlist WHERE username = ?");
|
|
$stmt->execute([$username]);
|
|
$wishlist = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
$content = $wishlist['content'] ?? '';
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="nl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Mijn Verlanglijstje</title>
|
|
<style>
|
|
:root {
|
|
--primary: #4c8bf5;
|
|
--accent: #2e6ae3;
|
|
--background: #f7f9fc;
|
|
--card-bg: #fff;
|
|
--border: #ddd;
|
|
--text: #333;
|
|
--muted: #666;
|
|
}
|
|
|
|
body {
|
|
font-family: "Segoe UI", Roboto, sans-serif;
|
|
background: var(--background);
|
|
margin: 0;
|
|
padding: 0;
|
|
color: var(--text);
|
|
}
|
|
|
|
header {
|
|
background: var(--primary);
|
|
color: white;
|
|
padding: 1rem 2rem;
|
|
display: flex;
|
|
justify-content: space-between;
|
|
align-items: center;
|
|
box-shadow: 0 2px 8px rgba(0,0,0,0.1);
|
|
}
|
|
|
|
header h1 {
|
|
margin: 0;
|
|
font-size: 1.4em;
|
|
}
|
|
|
|
main {
|
|
max-width: 800px;
|
|
margin: 30px auto;
|
|
background: var(--card-bg);
|
|
border-radius: 10px;
|
|
box-shadow: 0 4px 12px rgba(0,0,0,0.08);
|
|
padding: 30px 40px;
|
|
}
|
|
|
|
h2 {
|
|
color: var(--primary);
|
|
margin-top: 0;
|
|
}
|
|
|
|
textarea {
|
|
width: 100%;
|
|
height: 300px;
|
|
border-radius: 6px;
|
|
border: 1px solid var(--border);
|
|
padding: 10px;
|
|
font-size: 1em;
|
|
box-sizing: border-box;
|
|
}
|
|
|
|
button {
|
|
padding: 8px 14px;
|
|
border: none;
|
|
border-radius: 6px;
|
|
font-size: 1em;
|
|
cursor: pointer;
|
|
transition: 0.2s;
|
|
}
|
|
|
|
button.save {
|
|
background: var(--accent);
|
|
color: white;
|
|
}
|
|
button.save:hover {
|
|
background: #255bc7;
|
|
}
|
|
|
|
button.delete {
|
|
background: #e74c3c;
|
|
color: white;
|
|
}
|
|
button.delete:hover {
|
|
background: #c0392b;
|
|
}
|
|
|
|
button.logout {
|
|
background: white;
|
|
color: var(--primary);
|
|
font-weight: 600;
|
|
}
|
|
button.logout:hover {
|
|
background: #eef3ff;
|
|
}
|
|
|
|
a.back {
|
|
display: inline-block;
|
|
margin-bottom: 15px;
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
}
|
|
a.back:hover {
|
|
text-decoration: underline;
|
|
}
|
|
|
|
.message {
|
|
padding: 10px 14px;
|
|
border-radius: 6px;
|
|
margin-bottom: 15px;
|
|
font-size: 0.95em;
|
|
}
|
|
.message.success {
|
|
background: #e8f5e9;
|
|
color: #256029;
|
|
border: 1px solid #a5d6a7;
|
|
}
|
|
.message.error {
|
|
background: #fdecea;
|
|
color: #b71c1c;
|
|
border: 1px solid #f5c6cb;
|
|
}
|
|
|
|
footer {
|
|
text-align: center;
|
|
font-size: 0.8em;
|
|
color: var(--muted);
|
|
padding: 20px;
|
|
margin-top: 30px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>🎁 Mijn Verlanglijstje</h1>
|
|
<form method="post">
|
|
<button type="submit" name="logout" class="logout">Afmelden</button>
|
|
</form>
|
|
</header>
|
|
|
|
<main>
|
|
<a href="index.php" class="back">← Terug naar overzicht</a>
|
|
|
|
<h2>Welkom, <?= htmlspecialchars($displayName) ?>!</h2>
|
|
|
|
<?php if ($message): ?>
|
|
<div class="message <?= $isSuccess ? 'success' : 'error' ?>">
|
|
<?= htmlspecialchars($message) ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
|
|
<form method="post">
|
|
<textarea id="content" name="content"><?= htmlspecialchars($content) ?></textarea><br><br>
|
|
<button type="submit" name="save" class="save">💾 Opslaan / Bijwerken</button>
|
|
</form>
|
|
|
|
<?php if ($wishlist): ?>
|
|
<form method="post" style="margin-top:15px;">
|
|
<button type="submit" name="delete" value="<?= $wishlist['id'] ?>" class="delete" onclick="return confirm('Weet je zeker dat je je verlanglijstje wilt verwijderen?');">
|
|
🗑 Verwijderen
|
|
</button>
|
|
</form>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
<footer>
|
|
© <?= date('Y') ?> Lootjes Trekking — Alles voor een gezellige kerst 🎄
|
|
</footer>
|
|
|
|
<script src="js/tinymce/tinymce.min.js"></script>
|
|
<script>
|
|
tinymce.init({
|
|
selector: '#content',
|
|
height: 300,
|
|
menubar: false,
|
|
plugins: 'lists link paste',
|
|
toolbar: 'undo redo | bold italic underline | bullist numlist | link | removeformat',
|
|
paste_as_text: false
|
|
});
|
|
</script>
|
|
</body>
|
|
</html>
|