Layout angepasst

This commit is contained in:
Borgal
2025-10-31 15:04:16 +01:00
parent 8804920129
commit 9782304e61

View File

@@ -1,49 +1,42 @@
<?php <?php
// vacation.php
// Korrektur: Die Pfade gehen jetzt direkt in den 'inc' Ordner.
include('inc/check_login.php'); include('inc/check_login.php');
include('inc/db.php'); include('inc/db.php');
require_once 'inc/helpers.php'; require_once 'inc/helpers.php';
$message = ''; $message = '';
$message_type = ''; $message_type = '';
$logged_in_user_id = intval($_SESSION['user_id'] ?? 1); // Stellen Sie sicher, dass die User-ID verfügbar ist $logged_in_user_id = (int)($_SESSION['user_id'] ?? 1);
// Aktion verarbeiten (Hinzufügen oder Löschen) // --- Hinzufügen ---
if ($_SERVER["REQUEST_METHOD"] == "POST") { if ($_SERVER["REQUEST_METHOD"] == "POST" && isset($_POST['action']) && $_POST['action'] == 'add_vacation') {
if (isset($_POST['action']) && $_POST['action'] == 'add_vacation') { $start_date = $_POST['start_date'] ?? '';
$start_date = $_POST['start_date']; $end_date = $_POST['end_date'] ?? '';
$end_date = $_POST['end_date'];
// Eingabe validieren if (empty($start_date) || empty($end_date)) {
if (empty($start_date) || empty($end_date)) { $message = "Bitte geben Sie ein Start- und Enddatum an.";
$message = "Bitte geben Sie ein Start- und Enddatum an."; $message_type = "danger";
$message_type = "danger"; } elseif (strtotime($end_date) < strtotime($start_date)) {
} elseif (strtotime($end_date) < strtotime($start_date)) { $message = "Das Enddatum kann nicht vor dem Startdatum liegen.";
$message = "Das Enddatum kann nicht vor dem Startdatum liegen."; $message_type = "danger";
$message_type = "danger"; } else {
} else { $stmt = mysqli_prepare($conn, "INSERT INTO vacations (user_id, start_date, end_date) VALUES (?, ?, ?)");
// Termin in die Datenbank einfügen if ($stmt) {
$stmt = mysqli_prepare($conn, "INSERT INTO vacations (user_id, start_date, end_date) VALUES (?, ?, ?)"); mysqli_stmt_bind_param($stmt, "iss", $logged_in_user_id, $start_date, $end_date);
if ($stmt) { if (mysqli_stmt_execute($stmt)) {
mysqli_stmt_bind_param($stmt, "iss", $logged_in_user_id, $start_date, $end_date); $message = "Urlaub erfolgreich hinzugefügt.";
if (mysqli_stmt_execute($stmt)) { $message_type = "success";
$message = "Urlaub erfolgreich hinzugefügt."; } else {
$message_type = "success"; $message = "Fehler beim Hinzufügen des Urlaubs.";
} else { $message_type = "danger";
$message = "Fehler beim Hinzufügen des Urlaubs: " . mysqli_error($conn);
$message_type = "danger";
}
mysqli_stmt_close($stmt);
} }
mysqli_stmt_close($stmt);
} }
} }
} }
// Löschen-Aktion // --- Löschen ---
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) { if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
$vacation_id = intval($_GET['id']); $vacation_id = (int)$_GET['id'];
// Überprüfen, ob die ID zum eingeloggten Benutzer gehört
$stmt = mysqli_prepare($conn, "DELETE FROM vacations WHERE id = ? AND user_id = ?"); $stmt = mysqli_prepare($conn, "DELETE FROM vacations WHERE id = ? AND user_id = ?");
if ($stmt) { if ($stmt) {
mysqli_stmt_bind_param($stmt, "ii", $vacation_id, $logged_in_user_id); mysqli_stmt_bind_param($stmt, "ii", $vacation_id, $logged_in_user_id);
@@ -58,7 +51,7 @@ if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id']))
} }
} }
// Alle bestehenden Urlaube des Benutzers abrufen // --- Daten laden ---
$vacations = []; $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 = ? ORDER BY start_date DESC");
if ($stmt) { if ($stmt) {
@@ -75,33 +68,35 @@ require_once 'inc/header.php';
?> ?>
<div class="container mt-5"> <div class="container mt-5">
<h2 class="mb-4">Abwesenheitsassistent</h2>
<?php if ($message): ?> <?php if ($message): ?>
<div class="alert alert-<?= htmlspecialchars($message_type) ?> alert-dismissible fade show" role="alert"> <div class="alert alert-<?= htmlspecialchars($message_type) ?> alert-dismissible fade show" role="alert">
<?= htmlspecialchars($message) ?> <?= htmlspecialchars($message) ?>
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button> <button type="button" class="btn-close" data-bs-dismiss="alert"></button>
</div> </div>
<?php endif; ?> <?php endif; ?>
<div class="d-flex justify-content-between align-items-center mb-4">
<h2 class="mb-0">Abwesenheitsassistent</h2>
</div>
<div class="card shadow mb-4"> <div class="card shadow mb-4">
<div class="card-header bg-light"> <div class="card-header bg-primary-subtle text-secondary">
<h5 class="mb-0">Urlaub eintragen</h5> <h4 class="mb-0">Urlaub eintragen</h4>
</div> </div>
<div class="card-body"> <div class="card-body">
<form action="vacation.php" method="post"> <form action="vacation.php" method="post">
<input type="hidden" name="action" value="add_vacation"> <input type="hidden" name="action" value="add_vacation">
<div class="row g-3"> <div class="row g-3">
<div class="col-md-5"> <div class="col-md-5">
<label for="start_date" class="form-label">Startdatum</label> <label class="form-label">Startdatum</label>
<input type="date" class="form-control" id="start_date" name="start_date" required> <input type="date" class="form-control" name="start_date" required>
</div> </div>
<div class="col-md-5"> <div class="col-md-5">
<label for="end_date" class="form-label">Enddatum</label> <label class="form-label">Enddatum</label>
<input type="date" class="form-control" id="end_date" name="end_date" required> <input type="date" class="form-control" name="end_date" required>
</div> </div>
<div class="col-md-2 d-flex align-items-end"> <div class="col-md-2 d-flex align-items-end">
<button type="submit" class="btn btn-primary w-100">Hinzufügen</button> <button type="submit" class="btn btn-sm btn-outline-primary w-100">Hinzufügen</button>
</div> </div>
</div> </div>
</form> </form>
@@ -109,25 +104,46 @@ require_once 'inc/header.php';
</div> </div>
<div class="card shadow"> <div class="card shadow">
<div class="card-header bg-light"> <div class="card-header bg-secondary bg-opacity-50 text-secondary">
<h5 class="mb-0">Eingetragene Urlaube</h5> <h4 class="mb-0">Eingetragene Urlaube</h4>
</div> </div>
<div class="card-body"> <div class="card-body">
<?php if (empty($vacations)): ?> <?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 Urlaube eingetragen.</p>
<?php else: ?> <?php else: ?>
<ul class="list-group list-group-flush"> <div class="table-responsive">
<?php foreach ($vacations as $vacation): ?> <table class="table table-striped table-hover">
<li class="list-group-item d-flex justify-content-between align-items-center"> <thead>
<span> <tr>
Vom <?= date('d.m.Y', strtotime($vacation['start_date'])) ?> bis <?= date('d.m.Y', strtotime($vacation['end_date'])) ?> <th>Zeitraum</th>
</span> <th class="text-end">Aktionen</th>
<a href="vacation.php?action=delete&id=<?= htmlspecialchars($vacation['id']) ?>" class="btn btn-sm btn-danger" onclick="return confirm('Sind Sie sicher, dass Sie diesen Urlaub löschen möchten?');"> </tr>
Löschen </thead>
</a> <tbody>
</li> <?php foreach ($vacations as $vacation): ?>
<?php endforeach; ?> <tr>
</ul> <td>
Vom <?= date('d.m.Y', strtotime($vacation['start_date'])) ?> bis <?= date('d.m.Y', strtotime($vacation['end_date'])) ?>
</td>
<td class="text-end align-middle">
<div class="dropdown">
<a href="#" class="text-secondary" role="button" data-bs-toggle="dropdown" aria-expanded="false">
<span class="material-icons">more_vert</span>
</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?')">
<span class="material-icons me-2">delete_outline</span> Löschen
</a>
</li>
</ul>
</div>
</td>
</tr>
<?php endforeach; ?>
</tbody>
</table>
</div>
<?php endif; ?> <?php endif; ?>
</div> </div>
</div> </div>