110 lines
3.4 KiB
PHP
110 lines
3.4 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">
|
|
<title>Lootjes Trekking</title>
|
|
<style>
|
|
body { font-family: Arial, sans-serif; margin: 20px; }
|
|
h2 { color: #333; }
|
|
button { padding: 6px 12px; margin-top: 8px; }
|
|
a { color: #0066cc; text-decoration: none; }
|
|
a:hover { text-decoration: underline; }
|
|
.wishlist-box { border: 1px solid #ccc; padding: 10px; margin-top: 10px; background: #fafafa; }
|
|
.info { color: #555; }
|
|
.admin-link { margin-top: 20px; display: block; font-weight: bold; }
|
|
</style>
|
|
</head>
|
|
<body>
|
|
|
|
<h2>Welkom, <?= htmlspecialchars($displayName) ?>!</h2>
|
|
|
|
<form method="post" style="margin-bottom:15px;">
|
|
<button type="submit" name="logout">Uitloggen</button>
|
|
</form>
|
|
|
|
<p><a href="wishlist.php">Mijn eigen verlanglijstje aanpassen</a></p>
|
|
|
|
<?php if ($isAdmin): ?>
|
|
<p class="admin-link"><a href="admin.php">🛠 Naar de adminpagina</a></p>
|
|
<?php endif; ?>
|
|
|
|
<hr>
|
|
|
|
<?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 trekt voor:</strong> <?= htmlspecialchars($lootje) ?></p>
|
|
|
|
<?php if ($ontvanger_wishlist): ?>
|
|
<p><strong>Verlanglijstje van <?= htmlspecialchars($lootje) ?>:</strong></p>
|
|
<div style="border:1px solid #ddd; padding:10px; background:#fff;">
|
|
<?= nl2br(htmlspecialchars($ontvanger_wishlist)) ?>
|
|
</div>
|
|
<?php else: ?>
|
|
<p class="info">Deze gebruiker heeft nog geen verlanglijstje ingevuld.</p>
|
|
<?php endif; ?>
|
|
</div>
|
|
<?php endif; ?>
|
|
<?php endif; ?>
|
|
|
|
</body>
|
|
</html>
|