223 lines
4.9 KiB
PHP
223 lines
4.9 KiB
PHP
<?php
|
|
session_start();
|
|
require __DIR__ . '/data/db.php';
|
|
require __DIR__ . '/functions/logging.php';
|
|
require __DIR__ . '/auth/ldap.php';
|
|
require __DIR__ . '/functions/ldap_groups.php';
|
|
|
|
$config = require __DIR__ . '/config/config.php';
|
|
|
|
// --- Redirect naar login als niet ingelogd ---
|
|
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;
|
|
$isAdmin = in_array($username, $config['admin_usernames'] ?? []);
|
|
$message = '';
|
|
|
|
// --- Uitloggen ---
|
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
|
log_action($pdo, $username, 'Uitloggen via index', 'Index pagina');
|
|
session_unset();
|
|
session_destroy();
|
|
header('Location: login.php');
|
|
exit;
|
|
}
|
|
|
|
// --- Actieve ronde ophalen ---
|
|
$stmt = $pdo->prepare("SELECT * FROM lootjes_rondes WHERE status='open' ORDER BY created_at DESC LIMIT 1");
|
|
$stmt->execute();
|
|
$current_round = $stmt->fetch(PDO::FETCH_ASSOC);
|
|
|
|
// --- Lootje van gebruiker ophalen ---
|
|
$lootje = null;
|
|
$ontvanger_wishlist = null;
|
|
|
|
if ($current_round) {
|
|
$stmtLootje = $pdo->prepare("SELECT ontvanger FROM lootjes WHERE ronde_id=? AND gever=?");
|
|
$stmtLootje->execute([$current_round['id'], $username]);
|
|
$lootje = $stmtLootje->fetchColumn();
|
|
|
|
if ($lootje) {
|
|
$stmtWishlist = $pdo->prepare("SELECT content FROM wishlist WHERE username=?");
|
|
$stmtWishlist->execute([$lootje]);
|
|
$ontvanger_wishlist = $stmtWishlist->fetchColumn();
|
|
}
|
|
}
|
|
?>
|
|
<!DOCTYPE html>
|
|
<html lang="nl">
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
|
<title>Lootjes Trekking</title>
|
|
<style>
|
|
:root {
|
|
--primary: #4c8bf5;
|
|
--secondary: #f7f9fc;
|
|
--accent: #2e6ae3;
|
|
--text: #333;
|
|
--muted: #777;
|
|
--card-bg: #fff;
|
|
--border: #ddd;
|
|
}
|
|
|
|
body {
|
|
font-family: "Segoe UI", Roboto, sans-serif;
|
|
background: var(--secondary);
|
|
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 {
|
|
font-size: 1.4em;
|
|
margin: 0;
|
|
}
|
|
|
|
header form {
|
|
margin: 0;
|
|
}
|
|
|
|
button.logout {
|
|
background: white;
|
|
color: var(--primary);
|
|
border: none;
|
|
border-radius: 6px;
|
|
padding: 6px 12px;
|
|
cursor: pointer;
|
|
font-weight: 600;
|
|
transition: 0.2s;
|
|
}
|
|
button.logout:hover {
|
|
background: #e9efff;
|
|
}
|
|
|
|
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;
|
|
}
|
|
|
|
a {
|
|
color: var(--accent);
|
|
text-decoration: none;
|
|
font-weight: 500;
|
|
}
|
|
a:hover { text-decoration: underline; }
|
|
|
|
.info {
|
|
color: var(--muted);
|
|
font-style: italic;
|
|
}
|
|
|
|
.wishlist-box {
|
|
background: #fafbff;
|
|
border: 1px solid var(--border);
|
|
padding: 15px;
|
|
border-radius: 8px;
|
|
margin-top: 15px;
|
|
}
|
|
|
|
.wishlist-content {
|
|
background: #fff;
|
|
border: 1px solid #eee;
|
|
padding: 12px;
|
|
border-radius: 6px;
|
|
margin-top: 8px;
|
|
}
|
|
|
|
.admin-link {
|
|
display: inline-block;
|
|
background: var(--accent);
|
|
color: white;
|
|
padding: 8px 12px;
|
|
border-radius: 6px;
|
|
text-decoration: none;
|
|
font-weight: 600;
|
|
margin-top: 10px;
|
|
transition: background 0.2s;
|
|
}
|
|
.admin-link:hover {
|
|
background: #255bc7;
|
|
}
|
|
|
|
footer {
|
|
text-align: center;
|
|
font-size: 0.8em;
|
|
color: var(--muted);
|
|
padding: 20px;
|
|
margin-top: 30px;
|
|
}
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<header>
|
|
<h1>Lootjes Trekking</h1>
|
|
<form method="post">
|
|
<button type="submit" name="logout" class="logout">Afmelden</button>
|
|
</form>
|
|
</header>
|
|
|
|
<main>
|
|
<h2>Welkom, <?= htmlspecialchars($displayName) ?>!</h2>
|
|
|
|
<p><a href="wishlist.php">Mijn verlanglijstje aanpassen</a></p>
|
|
|
|
<?php if ($isAdmin): ?>
|
|
<p><a href="admin.php" class="admin-link">Adminpagina</a></p>
|
|
<?php endif; ?>
|
|
|
|
<hr style="margin: 25px 0; border: none; border-top: 1px solid #eee;">
|
|
|
|
<?php if (!$current_round): ?>
|
|
<p class="info">Er is momenteel geen actieve trekking.</p>
|
|
|
|
<?php else: ?>
|
|
<h3>Actieve ronde: <?= htmlspecialchars($current_round['naam']) ?></h3>
|
|
|
|
<?php if (!$lootje): ?>
|
|
<p class="info">Je lootje is nog niet toegewezen.</p>
|
|
<?php else: ?>
|
|
<div class="wishlist-box">
|
|
<p><strong>Jij hebt getrokken:</strong> <?= htmlspecialchars($lootje) ?></p>
|
|
|
|
<?php if ($ontvanger_wishlist): ?>
|
|
<p><strong>Verlanglijstje van <?= htmlspecialchars($lootje) ?>:</strong></p>
|
|
<div class="wishlist-content">
|
|
<?= $ontvanger_wishlist ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="info">Deze gebruiker heeft nog geen verlanglijstje ingevuld.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
</main>
|
|
|
|
</body>
|
|
</html>
|