v1.3.2 - Abwesenheiten überarbeitet
This commit is contained in:
83
vacation.php
83
vacation.php
@@ -51,9 +51,15 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
|
||||
}
|
||||
}
|
||||
|
||||
// --- Daten laden ---
|
||||
// --- Eigene Abwesenheiten (nur aktuell oder zukünftig) ---
|
||||
$vacations = [];
|
||||
$stmt = mysqli_prepare($conn, "SELECT id, start_date, end_date FROM vacations WHERE user_id = ? ORDER BY start_date DESC");
|
||||
$stmt = mysqli_prepare($conn, "
|
||||
SELECT id, start_date, end_date
|
||||
FROM vacations
|
||||
WHERE user_id = ?
|
||||
AND end_date >= CURDATE()
|
||||
ORDER BY start_date ASC
|
||||
");
|
||||
if ($stmt) {
|
||||
mysqli_stmt_bind_param($stmt, "i", $logged_in_user_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
@@ -64,6 +70,38 @@ if ($stmt) {
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
|
||||
// --- Prüfen, ob Admin ---
|
||||
$is_admin = false;
|
||||
$stmt = mysqli_prepare($conn, "SELECT role FROM users WHERE id = ?");
|
||||
if ($stmt) {
|
||||
mysqli_stmt_bind_param($stmt, "i", $logged_in_user_id);
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
$user = mysqli_fetch_assoc($result);
|
||||
$is_admin = ($user && $user['role'] === 'admin');
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
|
||||
// --- Alle Abwesenheiten (nur aktuell oder zukünftig, nur für Admins) ---
|
||||
$all_vacations = [];
|
||||
if ($is_admin) {
|
||||
$stmt = mysqli_prepare($conn, "
|
||||
SELECT v.id, v.start_date, v.end_date, u.username
|
||||
FROM vacations v
|
||||
JOIN users u ON v.user_id = u.id
|
||||
WHERE v.end_date >= CURDATE()
|
||||
ORDER BY v.start_date ASC, u.username ASC
|
||||
");
|
||||
if ($stmt) {
|
||||
mysqli_stmt_execute($stmt);
|
||||
$result = mysqli_stmt_get_result($stmt);
|
||||
while ($row = mysqli_fetch_assoc($result)) {
|
||||
$all_vacations[] = $row;
|
||||
}
|
||||
mysqli_stmt_close($stmt);
|
||||
}
|
||||
}
|
||||
|
||||
require_once 'inc/header.php';
|
||||
?>
|
||||
|
||||
@@ -79,6 +117,7 @@ require_once 'inc/header.php';
|
||||
<h2 class="mb-0">Abwesenheitsassistent</h2>
|
||||
</div>
|
||||
|
||||
<!-- Eigenen Urlaub eintragen -->
|
||||
<div class="card shadow mb-4">
|
||||
<div class="card-header bg-primary-subtle text-secondary">
|
||||
<h4 class="mb-0">Urlaub eintragen</h4>
|
||||
@@ -103,13 +142,14 @@ require_once 'inc/header.php';
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Eigene Abwesenheiten -->
|
||||
<div class="card shadow">
|
||||
<div class="card-header bg-secondary bg-opacity-50 text-secondary">
|
||||
<h4 class="mb-0">Eingetragene Urlaube</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<?php if (empty($vacations)): ?>
|
||||
<p class="text-muted text-center">Es sind keine Urlaube eingetragen.</p>
|
||||
<p class="text-muted text-center">Es sind keine aktuellen oder zukünftigen Urlaube eingetragen.</p>
|
||||
<?php else: ?>
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
@@ -132,7 +172,9 @@ require_once 'inc/header.php';
|
||||
</a>
|
||||
<ul class="dropdown-menu dropdown-menu-end">
|
||||
<li>
|
||||
<a class="dropdown-item d-flex align-items-center text-danger" href="vacation.php?action=delete&id=<?= htmlspecialchars($vacation['id']) ?>" onclick="return confirm('Wirklich löschen?')">
|
||||
<a class="dropdown-item d-flex align-items-center text-danger"
|
||||
href="vacation.php?action=delete&id=<?= htmlspecialchars($vacation['id']) ?>"
|
||||
onclick="return confirm('Wirklich löschen?')">
|
||||
<span class="material-icons me-2">delete_outline</span> Löschen
|
||||
</a>
|
||||
</li>
|
||||
@@ -147,6 +189,39 @@ require_once 'inc/header.php';
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alle Abwesenheiten (nur für Admins) -->
|
||||
<?php if ($is_admin && !empty($all_vacations)): ?>
|
||||
<div class="card shadow mt-4">
|
||||
<div class="card-header bg-info bg-opacity-25 text-dark">
|
||||
<h4 class="mb-0">Abwesenheiten aller Nutzer (aktuell & zukünftig)</h4>
|
||||
</div>
|
||||
<div class="card-body">
|
||||
<div class="table-responsive">
|
||||
<table class="table table-striped table-hover">
|
||||
<thead>
|
||||
<tr>
|
||||
<th>Nutzer</th>
|
||||
<th>Zeitraum</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
<?php foreach ($all_vacations as $vac): ?>
|
||||
<tr>
|
||||
<td><?= htmlspecialchars($vac['username']) ?></td>
|
||||
<td>
|
||||
Vom <?= date('d.m.Y', strtotime($vac['start_date'])) ?>
|
||||
bis <?= date('d.m.Y', strtotime($vac['end_date'])) ?>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</div>
|
||||
|
||||
<?php include('inc/footer.php'); ?>
|
||||
Reference in New Issue
Block a user