admin
This commit is contained in:
184
admin.php
184
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
|
<?php
|
||||||
session_start();
|
session_start();
|
||||||
require __DIR__ . '/data/db.php';
|
require __DIR__ . '/data/db.php';
|
||||||
@@ -15,7 +5,7 @@ require __DIR__ . '/functions/logging.php';
|
|||||||
require __DIR__ . '/functions/ldap_groups.php';
|
require __DIR__ . '/functions/ldap_groups.php';
|
||||||
$config = require __DIR__ . '/config/config.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'])) {
|
if (!isset($_SESSION['user']) || !in_array($_SESSION['user']['username'], $config['admin_usernames'])) {
|
||||||
die("Toegang geweigerd. Alleen admin.");
|
die("Toegang geweigerd. Alleen admin.");
|
||||||
}
|
}
|
||||||
@@ -23,7 +13,7 @@ if (!isset($_SESSION['user']) || !in_array($_SESSION['user']['username'], $confi
|
|||||||
$message = '';
|
$message = '';
|
||||||
$members = get_group_members('APP_LootjesTrekken');
|
$members = get_group_members('APP_LootjesTrekken');
|
||||||
|
|
||||||
// Afmelden knop
|
// --- Afmelden knop ---
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
||||||
log_action($pdo, $_SESSION['user']['username'], 'Uitloggen via admin', 'Admin pagina');
|
log_action($pdo, $_SESSION['user']['username'], 'Uitloggen via admin', 'Admin pagina');
|
||||||
session_unset();
|
session_unset();
|
||||||
@@ -32,14 +22,13 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['logout'])) {
|
|||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Nieuwe ronde starten
|
// --- Nieuwe ronde starten ---
|
||||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_round'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_round'])) {
|
||||||
if (count($members) < 2) {
|
if (count($members) < 2) {
|
||||||
$message = "Niet genoeg deelnemers om een ronde te starten.";
|
$message = "Niet genoeg deelnemers om een ronde te starten.";
|
||||||
} else {
|
} else {
|
||||||
try {
|
try {
|
||||||
$rondeNaam = "Ronde " . date('Y-m-d H:i:s');
|
$rondeNaam = "Ronde " . date('Y-m-d H:i:s');
|
||||||
|
|
||||||
$pdo->beginTransaction();
|
$pdo->beginTransaction();
|
||||||
|
|
||||||
$stmt = $pdo->prepare("INSERT INTO lootjes_rondes (naam) VALUES (?)");
|
$stmt = $pdo->prepare("INSERT INTO lootjes_rondes (naam) VALUES (?)");
|
||||||
@@ -75,15 +64,15 @@ if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['start_round'])) {
|
|||||||
$pdo->commit();
|
$pdo->commit();
|
||||||
|
|
||||||
log_action($pdo, $_SESSION['user']['username'], "Nieuwe ronde gestart: $rondeNaam", "Admin pagina");
|
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) {
|
} catch (Exception $e) {
|
||||||
$pdo->rollBack();
|
$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'])) {
|
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['close_round'])) {
|
||||||
$ronde_id = $_POST['round_id'] ?? 0;
|
$ronde_id = $_POST['round_id'] ?? 0;
|
||||||
if ($ronde_id) {
|
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 {
|
try {
|
||||||
$stmt = $pdo->query("SELECT * FROM lootjes_rondes ORDER BY created_at DESC");
|
$stmt = $pdo->query("SELECT * FROM lootjes_rondes ORDER BY created_at DESC");
|
||||||
$rondes = $stmt->fetchAll();
|
$rondes = $stmt->fetchAll();
|
||||||
@@ -102,53 +91,147 @@ try {
|
|||||||
die("Fout bij ophalen van rondes: " . $e->getMessage());
|
die("Fout bij ophalen van rondes: " . $e->getMessage());
|
||||||
}
|
}
|
||||||
?>
|
?>
|
||||||
|
|
||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="nl">
|
<html lang="nl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
|
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||||
<title>Admin - Lootjesbeheer</title>
|
<title>Admin - Lootjesbeheer</title>
|
||||||
<style>
|
<style>
|
||||||
body { font-family: Arial, sans-serif; }
|
:root {
|
||||||
table { border-collapse: collapse; width: 100%; margin-top: 10px; }
|
--primary: #4c8bf5;
|
||||||
th, td { border: 1px solid #ccc; padding: 8px; text-align: left; }
|
--accent: #2e6ae3;
|
||||||
th { background-color: #f4f4f4; }
|
--background: #f7f9fc;
|
||||||
button { padding: 5px 10px; margin: 2px; }
|
--card-bg: #fff;
|
||||||
.message { color: green; }
|
--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>
|
</style>
|
||||||
</head>
|
</head>
|
||||||
<body>
|
<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">
|
<main>
|
||||||
<button type="submit" name="logout">Uitloggen</button>
|
<?php if ($message): ?>
|
||||||
</form>
|
<div class="message"><?= htmlspecialchars($message) ?></div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
<?php if ($message): ?>
|
<form method="post" style="margin-bottom:20px;">
|
||||||
<p class="message"><?= htmlspecialchars($message) ?></p>
|
<button type="submit" name="start_round" class="start">➕ Nieuwe ronde starten</button>
|
||||||
<?php endif; ?>
|
</form>
|
||||||
|
|
||||||
<form method="post">
|
<h3>📅 Rondes</h3>
|
||||||
<button type="submit" name="start_round">Nieuwe ronde starten</button>
|
<table>
|
||||||
</form>
|
<tr><th>ID</th><th>Naam</th><th>Status</th><th>Acties</th><th>Lootjes</th></tr>
|
||||||
|
<?php foreach ($rondes as $r): ?>
|
||||||
<h3>Rondes</h3>
|
<tr>
|
||||||
<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><?= $r['id'] ?></td>
|
||||||
<td><?= htmlspecialchars($r['naam']) ?></td>
|
<td><?= htmlspecialchars($r['naam']) ?></td>
|
||||||
<td><?= $r['status'] ?></td>
|
<td><?= htmlspecialchars($r['status']) ?></td>
|
||||||
<td>
|
<td>
|
||||||
<?php if ($r['status'] === 'open'): ?>
|
<?php if ($r['status'] === 'open'): ?>
|
||||||
<form method="post" style="display:inline">
|
<form method="post" style="display:inline;">
|
||||||
<input type="hidden" name="round_id" value="<?= $r['id'] ?>">
|
<input type="hidden" name="round_id" value="<?= $r['id'] ?>">
|
||||||
<button type="submit" name="close_round">Ronde afronden</button>
|
<button type="submit" name="close_round" class="close">Ronde afronden</button>
|
||||||
</form>
|
</form>
|
||||||
<?php else: ?>
|
<?php else: ?>
|
||||||
Afgerond
|
✅ Afgerond
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
<td>
|
<td>
|
||||||
@@ -167,9 +250,14 @@ button { padding: 5px 10px; margin: 2px; }
|
|||||||
Nog geen lootjes
|
Nog geen lootjes
|
||||||
<?php endif; ?>
|
<?php endif; ?>
|
||||||
</td>
|
</td>
|
||||||
</tr>
|
</tr>
|
||||||
<?php endforeach; ?>
|
<?php endforeach; ?>
|
||||||
</table>
|
</table>
|
||||||
|
</main>
|
||||||
|
|
||||||
|
<footer>
|
||||||
|
© <?= date('Y') ?> Lootjes Trekking — Beheerderspaneel 🎁
|
||||||
|
</footer>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
|
|||||||
Reference in New Issue
Block a user