admin
This commit is contained in:
232
admin.php
232
admin.php
@@ -1,13 +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';
|
||||
@@ -15,7 +5,7 @@ require __DIR__ . '/functions/logging.php';
|
||||
require __DIR__ . '/functions/ldap_groups.php';
|
||||
$config = require __DIR__ . '/config/config.php';
|
||||
|
||||
// Alleen admin toegang
|
||||
// --- Alleen admin toegang ---
|
||||
if (!isset($_SESSION['user']) || !in_array($_SESSION['user']['username'], $config['admin_usernames'])) {
|
||||
die("Toegang geweigerd. Alleen admin.");
|
||||
}
|
||||
@@ -23,7 +13,7 @@ if (!isset($_SESSION['user']) || !in_array($_SESSION['user']['username'], $confi
|
||||
$message = '';
|
||||
$members = get_group_members('APP_LootjesTrekken');
|
||||
|
||||
// Afmelden knop
|
||||
// --- Afmelden knop ---
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
||||
log_action($pdo, $_SESSION['user']['username'], 'Uitloggen via admin', 'Admin pagina');
|
||||
session_unset();
|
||||
@@ -32,14 +22,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
||||
exit;
|
||||
}
|
||||
|
||||
// Nieuwe ronde starten
|
||||
// --- Nieuwe ronde starten ---
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_round'])) {
|
||||
if (count($members) < 2) {
|
||||
$message = "Niet genoeg deelnemers om een ronde te starten.";
|
||||
} else {
|
||||
try {
|
||||
$rondeNaam = "Ronde " . date('Y-m-d H:i:s');
|
||||
|
||||
$pdo->beginTransaction();
|
||||
|
||||
$stmt = $pdo->prepare("INSERT INTO lootjes_rondes (naam) VALUES (?)");
|
||||
@@ -75,15 +64,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_round'])) {
|
||||
$pdo->commit();
|
||||
|
||||
log_action($pdo, $_SESSION['user']['username'], "Nieuwe ronde gestart: $rondeNaam", "Admin pagina");
|
||||
$message = "Nieuwe ronde '$rondeNaam' succesvol gestart!";
|
||||
$message = "✅ Nieuwe ronde '$rondeNaam' succesvol gestart!";
|
||||
} catch (Exception $e) {
|
||||
$pdo->rollBack();
|
||||
$message = "Fout bij starten van nieuwe ronde: " . $e->getMessage();
|
||||
$message = "❌ Fout bij starten van nieuwe ronde: " . $e->getMessage();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Ronde afronden
|
||||
// --- Ronde afronden ---
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['close_round'])) {
|
||||
$ronde_id = $_POST['round_id'] ?? 0;
|
||||
if ($ronde_id) {
|
||||
@@ -94,7 +83,7 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['close_round'])) {
|
||||
}
|
||||
}
|
||||
|
||||
// Huidige rondes ophalen (nieuwste eerst)
|
||||
// --- Huidige rondes ophalen ---
|
||||
try {
|
||||
$stmt = $pdo->query("SELECT * FROM lootjes_rondes ORDER BY created_at DESC");
|
||||
$rondes = $stmt->fetchAll();
|
||||
@@ -102,74 +91,173 @@ try {
|
||||
die("Fout bij ophalen van rondes: " . $e->getMessage());
|
||||
}
|
||||
?>
|
||||
|
||||
<!DOCTYPE html>
|
||||
<html lang="nl">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Admin - Lootjesbeheer</title>
|
||||
<style>
|
||||
body { font-family: Arial, sans-serif; }
|
||||
table { border-collapse: collapse; width: 100%; margin-top: 10px; }
|
||||
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
|
||||
th { background-color: #f4f4f4; }
|
||||
button { padding: 5px 10px; margin: 2px; }
|
||||
.message { color: green; }
|
||||
:root {
|
||||
--primary: #4c8bf5;
|
||||
--accent: #2e6ae3;
|
||||
--background: #f7f9fc;
|
||||
--card-bg: #fff;
|
||||
--border: #ddd;
|
||||
--text: #333;
|
||||
}
|
||||
body {
|
||||
font-family: "Segoe UI", Roboto, sans-serif;
|
||||
background: var(--background);
|
||||
margin: 0;
|
||||
color: var(--text);
|
||||
}
|
||||
header {
|
||||
background: var(--primary);
|
||||
color: white;
|
||||
padding: 1rem 2rem;
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: center;
|
||||
}
|
||||
header h1 {
|
||||
margin: 0;
|
||||
font-size: 1.3em;
|
||||
}
|
||||
nav a {
|
||||
color: white;
|
||||
margin-left: 20px;
|
||||
text-decoration: none;
|
||||
font-weight: 600;
|
||||
}
|
||||
nav a:hover {
|
||||
text-decoration: underline;
|
||||
}
|
||||
main {
|
||||
max-width: 1000px;
|
||||
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, h3 {
|
||||
color: var(--accent);
|
||||
}
|
||||
table {
|
||||
width: 100%;
|
||||
border-collapse: collapse;
|
||||
margin-top: 10px;
|
||||
}
|
||||
th, td {
|
||||
border: 1px solid #ccc;
|
||||
padding: 8px;
|
||||
text-align: left;
|
||||
}
|
||||
th {
|
||||
background: #f4f4f4;
|
||||
}
|
||||
button {
|
||||
padding: 6px 12px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
cursor: pointer;
|
||||
}
|
||||
button:hover {
|
||||
opacity: 0.9;
|
||||
}
|
||||
button.logout {
|
||||
background: white;
|
||||
color: var(--primary);
|
||||
}
|
||||
button.close {
|
||||
background: #e67e22;
|
||||
color: white;
|
||||
}
|
||||
button.start {
|
||||
background: var(--accent);
|
||||
color: white;
|
||||
}
|
||||
.message {
|
||||
margin: 15px 0;
|
||||
padding: 10px;
|
||||
border-radius: 6px;
|
||||
background: #eef3ff;
|
||||
border: 1px solid #cdd7fb;
|
||||
}
|
||||
footer {
|
||||
text-align: center;
|
||||
font-size: 0.8em;
|
||||
color: #777;
|
||||
margin-top: 30px;
|
||||
padding-bottom: 20px;
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h2>Admin - Lootjesbeheer</h2>
|
||||
<header>
|
||||
<h1>🎩 Adminpaneel - Lootjesbeheer</h1>
|
||||
<nav>
|
||||
<a href="index.php">🏠 Terug naar overzicht</a>
|
||||
<a href="show_log.php">📜 Bekijk log</a>
|
||||
<form method="post" style="display:inline;">
|
||||
<button type="submit" name="logout" class="logout">🚪 Afmelden</button>
|
||||
</form>
|
||||
</nav>
|
||||
</header>
|
||||
|
||||
<form method="post">
|
||||
<button type="submit" name="logout">Uitloggen</button>
|
||||
</form>
|
||||
<main>
|
||||
<?php if ($message): ?>
|
||||
<div class="message"><?= htmlspecialchars($message) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<?php if ($message): ?>
|
||||
<p class="message"><?= htmlspecialchars($message) ?></p>
|
||||
<?php endif; ?>
|
||||
<form method="post" style="margin-bottom:20px;">
|
||||
<button type="submit" name="start_round" class="start">➕ Nieuwe ronde starten</button>
|
||||
</form>
|
||||
|
||||
<form method="post">
|
||||
<button type="submit" name="start_round">Nieuwe ronde starten</button>
|
||||
</form>
|
||||
<h3>📅 Rondes</h3>
|
||||
<table>
|
||||
<tr><th>ID</th><th>Naam</th><th>Status</th><th>Acties</th><th>Lootjes</th></tr>
|
||||
<?php foreach ($rondes as $r): ?>
|
||||
<tr>
|
||||
<td><?= $r['id'] ?></td>
|
||||
<td><?= htmlspecialchars($r['naam']) ?></td>
|
||||
<td><?= htmlspecialchars($r['status']) ?></td>
|
||||
<td>
|
||||
<?php if ($r['status'] === 'open'): ?>
|
||||
<form method="post" style="display:inline;">
|
||||
<input type="hidden" name="round_id" value="<?= $r['id'] ?>">
|
||||
<button type="submit" name="close_round" class="close">Ronde afronden</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
✅ Afgerond
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$stmtLootjes = $pdo->prepare("SELECT gever, ontvanger FROM lootjes WHERE ronde_id=?");
|
||||
$stmtLootjes->execute([$r['id']]);
|
||||
$lootjes = $stmtLootjes->fetchAll();
|
||||
if ($lootjes):
|
||||
?>
|
||||
<ul style="margin:0; padding-left:15px;">
|
||||
<?php foreach ($lootjes as $l): ?>
|
||||
<li><?= htmlspecialchars($l['gever']) ?> → <?= htmlspecialchars($l['ontvanger']) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
Nog geen lootjes
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
</main>
|
||||
|
||||
<h3>Rondes</h3>
|
||||
<table>
|
||||
<tr><th>ID</th><th>Naam</th><th>Status</th><th>Acties</th><th>Lootjes</th></tr>
|
||||
<?php foreach ($rondes as $r): ?>
|
||||
<tr>
|
||||
<td><?= $r['id'] ?></td>
|
||||
<td><?= htmlspecialchars($r['naam']) ?></td>
|
||||
<td><?= $r['status'] ?></td>
|
||||
<td>
|
||||
<?php if ($r['status'] === 'open'): ?>
|
||||
<form method="post" style="display:inline">
|
||||
<input type="hidden" name="round_id" value="<?= $r['id'] ?>">
|
||||
<button type="submit" name="close_round">Ronde afronden</button>
|
||||
</form>
|
||||
<?php else: ?>
|
||||
Afgerond
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?php
|
||||
$stmtLootjes = $pdo->prepare("SELECT gever, ontvanger FROM lootjes WHERE ronde_id=?");
|
||||
$stmtLootjes->execute([$r['id']]);
|
||||
$lootjes = $stmtLootjes->fetchAll();
|
||||
if ($lootjes):
|
||||
?>
|
||||
<ul style="margin:0; padding-left:15px;">
|
||||
<?php foreach ($lootjes as $l): ?>
|
||||
<li><?= htmlspecialchars($l['gever']) ?> → <?= htmlspecialchars($l['ontvanger']) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php else: ?>
|
||||
Nog geen lootjes
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</table>
|
||||
<footer>
|
||||
© <?= date('Y') ?> Lootjes Trekking — Beheerderspaneel 🎁
|
||||
</footer>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
|
||||
Reference in New Issue
Block a user