Abwesenheiten hinzugefügt
This commit is contained in:
136
vacation.php
Executable file
136
vacation.php
Executable file
@@ -0,0 +1,136 @@
|
|||||||
|
<?php
|
||||||
|
// vacation.php
|
||||||
|
// Korrektur: Die Pfade gehen jetzt direkt in den 'inc' Ordner.
|
||||||
|
include('inc/check_login.php');
|
||||||
|
include('inc/db.php');
|
||||||
|
require_once 'inc/helpers.php';
|
||||||
|
|
||||||
|
$message = '';
|
||||||
|
$message_type = '';
|
||||||
|
$logged_in_user_id = intval($_SESSION['user_id'] ?? 1); // Stellen Sie sicher, dass die User-ID verfügbar ist
|
||||||
|
|
||||||
|
// Aktion verarbeiten (Hinzufügen oder Löschen)
|
||||||
|
if ($_SERVER["REQUEST_METHOD"] == "POST") {
|
||||||
|
if (isset($_POST['action']) && $_POST['action'] == 'add_vacation') {
|
||||||
|
$start_date = $_POST['start_date'];
|
||||||
|
$end_date = $_POST['end_date'];
|
||||||
|
|
||||||
|
// Eingabe validieren
|
||||||
|
if (empty($start_date) || empty($end_date)) {
|
||||||
|
$message = "Bitte geben Sie ein Start- und Enddatum an.";
|
||||||
|
$message_type = "danger";
|
||||||
|
} elseif (strtotime($end_date) < strtotime($start_date)) {
|
||||||
|
$message = "Das Enddatum kann nicht vor dem Startdatum liegen.";
|
||||||
|
$message_type = "danger";
|
||||||
|
} else {
|
||||||
|
// Termin in die Datenbank einfügen
|
||||||
|
$stmt = mysqli_prepare($conn, "INSERT INTO vacations (user_id, start_date, end_date) VALUES (?, ?, ?)");
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, "iss", $logged_in_user_id, $start_date, $end_date);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
$message = "Urlaub erfolgreich hinzugefügt.";
|
||||||
|
$message_type = "success";
|
||||||
|
} else {
|
||||||
|
$message = "Fehler beim Hinzufügen des Urlaubs: " . mysqli_error($conn);
|
||||||
|
$message_type = "danger";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Löschen-Aktion
|
||||||
|
if (isset($_GET['action']) && $_GET['action'] == 'delete' && isset($_GET['id'])) {
|
||||||
|
$vacation_id = intval($_GET['id']);
|
||||||
|
// Überprüfen, ob die ID zum eingeloggten Benutzer gehört
|
||||||
|
$stmt = mysqli_prepare($conn, "DELETE FROM vacations WHERE id = ? AND user_id = ?");
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, "ii", $vacation_id, $logged_in_user_id);
|
||||||
|
if (mysqli_stmt_execute($stmt)) {
|
||||||
|
$message = "Urlaub erfolgreich gelöscht.";
|
||||||
|
$message_type = "success";
|
||||||
|
} else {
|
||||||
|
$message = "Fehler beim Löschen des Urlaubs.";
|
||||||
|
$message_type = "danger";
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Alle bestehenden Urlaube des Benutzers abrufen
|
||||||
|
$vacations = [];
|
||||||
|
$stmt = mysqli_prepare($conn, "SELECT id, start_date, end_date FROM vacations WHERE user_id = ? ORDER BY start_date DESC");
|
||||||
|
if ($stmt) {
|
||||||
|
mysqli_stmt_bind_param($stmt, "i", $logged_in_user_id);
|
||||||
|
mysqli_stmt_execute($stmt);
|
||||||
|
$result = mysqli_stmt_get_result($stmt);
|
||||||
|
while ($row = mysqli_fetch_assoc($result)) {
|
||||||
|
$vacations[] = $row;
|
||||||
|
}
|
||||||
|
mysqli_stmt_close($stmt);
|
||||||
|
}
|
||||||
|
|
||||||
|
require_once 'inc/header.php';
|
||||||
|
?>
|
||||||
|
|
||||||
|
<div class="container mt-5">
|
||||||
|
<h2 class="mb-4">Abwesenheitsassistent</h2>
|
||||||
|
|
||||||
|
<?php if ($message): ?>
|
||||||
|
<div class="alert alert-<?= htmlspecialchars($message_type) ?> alert-dismissible fade show" role="alert">
|
||||||
|
<?= htmlspecialchars($message) ?>
|
||||||
|
<button type="button" class="btn-close" data-bs-dismiss="alert" aria-label="Close"></button>
|
||||||
|
</div>
|
||||||
|
<?php endif; ?>
|
||||||
|
|
||||||
|
<div class="card shadow mb-4">
|
||||||
|
<div class="card-header bg-light">
|
||||||
|
<h5 class="mb-0">Urlaub eintragen</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<form action="vacation.php" method="post">
|
||||||
|
<input type="hidden" name="action" value="add_vacation">
|
||||||
|
<div class="row g-3">
|
||||||
|
<div class="col-md-5">
|
||||||
|
<label for="start_date" class="form-label">Startdatum</label>
|
||||||
|
<input type="date" class="form-control" id="start_date" name="start_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-5">
|
||||||
|
<label for="end_date" class="form-label">Enddatum</label>
|
||||||
|
<input type="date" class="form-control" id="end_date" name="end_date" required>
|
||||||
|
</div>
|
||||||
|
<div class="col-md-2 d-flex align-items-end">
|
||||||
|
<button type="submit" class="btn btn-primary w-100">Hinzufügen</button>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="card shadow">
|
||||||
|
<div class="card-header bg-light">
|
||||||
|
<h5 class="mb-0">Eingetragene Urlaube</h5>
|
||||||
|
</div>
|
||||||
|
<div class="card-body">
|
||||||
|
<?php if (empty($vacations)): ?>
|
||||||
|
<p class="text-muted text-center">Es sind keine Urlaube eingetragen.</p>
|
||||||
|
<?php else: ?>
|
||||||
|
<ul class="list-group list-group-flush">
|
||||||
|
<?php foreach ($vacations as $vacation): ?>
|
||||||
|
<li class="list-group-item d-flex justify-content-between align-items-center">
|
||||||
|
<span>
|
||||||
|
Vom <?= date('d.m.Y', strtotime($vacation['start_date'])) ?> bis <?= date('d.m.Y', strtotime($vacation['end_date'])) ?>
|
||||||
|
</span>
|
||||||
|
<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?');">
|
||||||
|
Löschen
|
||||||
|
</a>
|
||||||
|
</li>
|
||||||
|
<?php endforeach; ?>
|
||||||
|
</ul>
|
||||||
|
<?php endif; ?>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<?php include('inc/footer.php'); ?>
|
||||||
Reference in New Issue
Block a user