feat: added adminpanel with overview; added holiday page with functionality; added payout page + functionality; added notification Feature
This commit is contained in:
53
admin.php
53
admin.php
@@ -0,0 +1,53 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'config.php';
|
||||
require 'db.php';
|
||||
|
||||
// Nur Admins dürfen hier rein
|
||||
if (!$_SESSION['user']['hasRole']) {
|
||||
die("❌ Kein Zugriff!");
|
||||
}
|
||||
|
||||
// Alle offenen Benachrichtigungen laden
|
||||
$result = $dbhandle->query("
|
||||
SELECT n.id, u.discord_name, n.message, n.type, n.created_at
|
||||
FROM notifications n
|
||||
JOIN users u ON n.user_id = u.id
|
||||
WHERE n.is_read = 0
|
||||
ORDER BY n.created_at DESC
|
||||
");
|
||||
?>
|
||||
<?php require "header.php"?>
|
||||
<head>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<h1>📢 Admin-Dashboard</h1>
|
||||
|
||||
<div id="notifications">
|
||||
<?php while ($row = $result->fetch_assoc()): ?>
|
||||
<div class="notif">
|
||||
<b><?= htmlspecialchars($row['discord_name']) ?></b>
|
||||
<?= htmlspecialchars($row['message']) ?>
|
||||
<small>(<?= $row['created_at'] ?>)</small>
|
||||
<form method="post" action="mark_as_read.php">
|
||||
<input type="hidden" name="notif_id" value="<?= $row['id'] ?>">
|
||||
<button type="submit">✔ Erledigt</button>
|
||||
</form>
|
||||
</div>
|
||||
<?php endwhile; ?>
|
||||
</div>
|
||||
|
||||
<script>
|
||||
// Alle 5 Sekunden nach neuen Benachrichtigungen schauen
|
||||
setInterval(() => {
|
||||
fetch('get_notifications.php')
|
||||
.then(response => response.text())
|
||||
.then(data => {
|
||||
document.getElementById('notifications').innerHTML = data;
|
||||
});
|
||||
}, 5000);
|
||||
</script>
|
||||
|
||||
</body>
|
||||
|
||||
19
get_notifications.php
Normal file
19
get_notifications.php
Normal file
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
require 'config.php';
|
||||
require 'db.php';
|
||||
|
||||
$result = $dbhandle->query("
|
||||
SELECT n.id, u.discord_name, n.message, n.type, n.created_at
|
||||
FROM notifications n
|
||||
JOIN users u ON n.user_id = u.id
|
||||
WHERE n.is_read = 0
|
||||
ORDER BY n.created_at DESC
|
||||
");
|
||||
|
||||
while ($row = $result->fetch_assoc()) {
|
||||
echo "<div class='notif'>";
|
||||
echo "<b>".htmlspecialchars($row['discord_name'])."</b> ";
|
||||
echo htmlspecialchars($row['message']);
|
||||
echo " <small>(".htmlspecialchars($row['created_at']).")</small>";
|
||||
echo "</div>";
|
||||
}
|
||||
@@ -9,10 +9,10 @@ if (session_status() === PHP_SESSION_NONE) {
|
||||
<?php if ($_SESSION['user']['hasRole']): ?>
|
||||
<a href="registration.php">✍️ Eintragung</a>
|
||||
<div class="dropdown">
|
||||
<a href="#">📂 Verwaltung ▼</a>
|
||||
<a href="admin.php">📂 Verwaltung ▼</a>
|
||||
<div class="dropdown-content">
|
||||
<a href="statistik.php">📊 Statistik</a>
|
||||
<a href="lager.php">🔧 Lager</a>
|
||||
<a href="holiday.php">🏖️ Urlaubsantrag</a>
|
||||
<a href="payout.php">🔧 Auszahlung</a>
|
||||
<a href="personal.php">📝 Personalakten</a>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
43
holiday.php
Normal file
43
holiday.php
Normal file
@@ -0,0 +1,43 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'config.php';
|
||||
require 'db.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$userId = $_SESSION['user']['id'];
|
||||
$von = $_POST['von'];
|
||||
$bis = $_POST['bis'];
|
||||
$grund = $dbhandle->real_escape_string($_POST['grund']);
|
||||
|
||||
// Urlaub eintragen
|
||||
$stmt = $dbhandle->prepare("INSERT INTO urlaub (user_id, von, bis, grund) VALUES (?, ?, ?, ?)");
|
||||
$stmt->bind_param("isss", $userId, $von, $bis, $grund);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Benachrichtigung für Admins
|
||||
$message = "hat einen Urlaubsantrag gestellt: {$von} bis {$bis}.";
|
||||
$notif = $dbhandle->prepare("INSERT INTO notifications (user_id, message, type) VALUES (?, ?, 'urlaub')");
|
||||
$notif->bind_param("is", $userId, $message);
|
||||
$notif->execute();
|
||||
$notif->close();
|
||||
|
||||
echo "✅ Urlaub beantragt!";
|
||||
}
|
||||
?>
|
||||
<?php require "header.php"?>
|
||||
<head>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
<label>Von:</label>
|
||||
<input type="date" name="von" required>
|
||||
<label>Bis:</label>
|
||||
<input type="date" name="bis" required>
|
||||
<label>Grund:</label>
|
||||
<textarea name="grund"></textarea>
|
||||
<button type="submit">Urlaub beantragen</button>
|
||||
</form>
|
||||
|
||||
</body>
|
||||
37
payout.php
Normal file
37
payout.php
Normal file
@@ -0,0 +1,37 @@
|
||||
<?php
|
||||
session_start();
|
||||
require 'config.php';
|
||||
require 'db.php';
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST') {
|
||||
$userId = $_SESSION['user']['id'];
|
||||
$betrag = floatval($_POST['betrag']);
|
||||
|
||||
// Auszahlung eintragen
|
||||
$stmt = $dbhandle->prepare("INSERT INTO payouts (user_id, betrag) VALUES (?, ?)");
|
||||
$stmt->bind_param("id", $userId, $betrag);
|
||||
$stmt->execute();
|
||||
$stmt->close();
|
||||
|
||||
// Benachrichtigung für Admins
|
||||
$message = "hat eine Auszahlung in Höhe von {$betrag}€ beantragt.";
|
||||
$notif = $dbhandle->prepare("INSERT INTO notifications (user_id, message, type) VALUES (?, ?, 'payout')");
|
||||
$notif->bind_param("is", $userId, $message);
|
||||
$notif->execute();
|
||||
$notif->close();
|
||||
|
||||
echo "✅ Auszahlung beantragt!";
|
||||
}
|
||||
?>
|
||||
<?php require "header.php"?>
|
||||
<head>
|
||||
<link rel="stylesheet" href="style.css">
|
||||
</head>
|
||||
<body>
|
||||
<form method="post">
|
||||
<label>Betrag (€):</label>
|
||||
<input type="number" name="betrag" step="0.01" required>
|
||||
<button type="submit">Auszahlung beantragen</button>
|
||||
</form>
|
||||
</body>
|
||||
|
||||
Reference in New Issue
Block a user