admin
This commit is contained in:
65
index.php
65
index.php
@@ -1,14 +1,3 @@
|
||||
<?php
|
||||
session_start();
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
$redirect = urlencode($_SERVER['REQUEST_URI']);
|
||||
header("Location: login.php?redirect=$redirect");
|
||||
exit;
|
||||
}
|
||||
?>
|
||||
|
||||
|
||||
<?php
|
||||
session_start();
|
||||
require __DIR__ . '/data/db.php';
|
||||
@@ -18,15 +7,19 @@ require __DIR__ . '/functions/ldap_groups.php';
|
||||
|
||||
$config = require __DIR__ . '/config/config.php';
|
||||
|
||||
// --- Redirect naar login als niet ingelogd ---
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header('Location: login.php');
|
||||
$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
|
||||
// --- Uitloggen ---
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
||||
log_action($pdo, $username, 'Uitloggen via index', 'Index pagina');
|
||||
session_unset();
|
||||
@@ -35,76 +28,82 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Huidige actieve ronde ophalen
|
||||
// --- 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 voor deze gebruiker ophalen
|
||||
// --- 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) {
|
||||
// Wishlist van de ontvanger ophalen
|
||||
$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>Mijn Lootje</title>
|
||||
<title>Lootjes Trekking</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; }
|
||||
body { font-family: Arial, sans-serif; margin: 20px; }
|
||||
h2 { color: #333; }
|
||||
button { padding: 5px 10px; margin-top: 5px; }
|
||||
textarea { width: 100%; height: 150px; }
|
||||
.wishlist-box { border: 1px solid #ccc; padding: 10px; margin-top: 10px; }
|
||||
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($_SESSION['user']['displayName']) ?>!</h2>
|
||||
<h2>Welkom, <?= htmlspecialchars($displayName) ?>!</h2>
|
||||
|
||||
<form method="post">
|
||||
<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>Er is momenteel geen actieve trekking.</p>
|
||||
<p class="info">Er is momenteel geen actieve trekking.</p>
|
||||
|
||||
<?php else: ?>
|
||||
<h3>Actieve ronde: <?= htmlspecialchars($current_round['naam']) ?></h3>
|
||||
|
||||
<?php if (!$lootje): ?>
|
||||
<p>Je lootje is nog niet toegewezen.</p>
|
||||
<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:#f9f9f9;">
|
||||
<div style="border:1px solid #ddd; padding:10px; background:#fff;">
|
||||
<?= nl2br(htmlspecialchars($ontvanger_wishlist)) ?>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<p>Deze gebruiker heeft nog geen verlanglijstje ingevuld.</p>
|
||||
<p class="info">Deze gebruiker heeft nog geen verlanglijstje ingevuld.</p>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
<?php endif; ?>
|
||||
|
||||
<p>
|
||||
<a href="wishlist.php">Mijn eigen verlanglijstje aanpassen</a>
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user