Abwesenheitskalender erweitert
This commit is contained in:
@@ -2,8 +2,10 @@
|
||||
session_start();
|
||||
require_once("inc/config.inc.php");
|
||||
require_once("inc/functions.inc.php");
|
||||
require_once("inc/vacation_absence.inc.php");
|
||||
|
||||
$user = check_user();
|
||||
vacationAbsenceEnsureSchema($pdo);
|
||||
|
||||
if (!isset($_SESSION['userid'])) {
|
||||
die("Kein Benutzer angemeldet.");
|
||||
@@ -14,6 +16,10 @@ $canManageTeamVacations = can_manage_team_vacations();
|
||||
$message = "";
|
||||
$error = "";
|
||||
$selected_user_id = $user_id;
|
||||
$selected_absence_reason = vacationAbsenceDefaultReason();
|
||||
$start_date = '';
|
||||
$end_date = '';
|
||||
$comment = '';
|
||||
|
||||
$selectableUsers = [];
|
||||
if ($canManageTeamVacations) {
|
||||
@@ -49,6 +55,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$start_date = trim((string)($_POST['start_date'] ?? ''));
|
||||
$end_date = trim((string)($_POST['end_date'] ?? ''));
|
||||
$comment = trim((string)($_POST['comment'] ?? ''));
|
||||
$selected_absence_reason = vacationAbsenceNormalizeReason($_POST['absence_reason'] ?? vacationAbsenceDefaultReason());
|
||||
$selected_user_id = $canManageTeamVacations ? (int)($_POST['user_id'] ?? $user_id) : $user_id;
|
||||
|
||||
$selectedUser = null;
|
||||
@@ -74,7 +81,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$error = "Bitte beide Datumsfelder ausfuellen.";
|
||||
} elseif ($error === "" && $start_date > $end_date) {
|
||||
$error = "Enddatum liegt vor dem Startdatum.";
|
||||
} elseif ($error === "" && $start_date < date("Y-m-d")) {
|
||||
} elseif ($error === "" && vacationAbsenceCountsAgainstEntitlement($selected_absence_reason) && $start_date < date("Y-m-d")) {
|
||||
$error = "Urlaub kann nicht in der Vergangenheit beantragt werden.";
|
||||
} elseif ($error === "") {
|
||||
$stmt = $pdo->prepare("
|
||||
@@ -97,15 +104,20 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
$days = calculateWorkingDays($start_date, $end_date);
|
||||
|
||||
$insert = $pdo->prepare("
|
||||
INSERT INTO vacations (user_id, start_date, end_date, days, comment_user)
|
||||
VALUES (?, ?, ?, ?, ?)
|
||||
INSERT INTO vacations (user_id, start_date, end_date, days, comment_user, absence_reason)
|
||||
VALUES (?, ?, ?, ?, ?, ?)
|
||||
");
|
||||
$insert->execute([$selected_user_id, $start_date, $end_date, $days, $comment]);
|
||||
$insert->execute([$selected_user_id, $start_date, $end_date, $days, $comment, $selected_absence_reason]);
|
||||
|
||||
$reasonLabel = vacationAbsenceReasonLabel($selected_absence_reason);
|
||||
if ($selected_user_id !== $user_id && $selectedUser) {
|
||||
$message = "Urlaub fuer " . $selectedUser['vorname'] . " " . $selectedUser['nachname'] . " erfolgreich eingereicht ($days Werktage).";
|
||||
$message = "Abwesenheit fuer " . $selectedUser['vorname'] . " " . $selectedUser['nachname'] . " erfolgreich eingetragen ($days Werktage, Grund: " . $reasonLabel . ").";
|
||||
} else {
|
||||
$message = "Urlaubsantrag erfolgreich eingereicht ($days Werktage).";
|
||||
if ($selected_absence_reason === 'urlaub') {
|
||||
$message = "Urlaubsantrag erfolgreich eingereicht ($days Werktage).";
|
||||
} else {
|
||||
$message = "Abwesenheitsantrag erfolgreich eingereicht ($days Werktage, Grund: " . $reasonLabel . ").";
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -118,7 +130,7 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
<div class="row">
|
||||
<div class="col-md-8 offset-md-2">
|
||||
|
||||
<h2>Urlaubsantrag</h2>
|
||||
<h2>Abwesenheitsantrag</h2>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert alert-danger"><?php echo htmlspecialchars($error); ?></div>
|
||||
@@ -144,32 +156,44 @@ if ($_SERVER["REQUEST_METHOD"] === "POST") {
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Abwesenheitsgrund:</label>
|
||||
<select name="absence_reason" class="form-control" required>
|
||||
<?php foreach (vacationAbsenceReasonOptions() as $reasonKey => $reasonLabel): ?>
|
||||
<option value="<?php echo htmlspecialchars($reasonKey); ?>" <?php echo ($selected_absence_reason === $reasonKey) ? 'selected' : ''; ?>>
|
||||
<?php echo htmlspecialchars($reasonLabel); ?>
|
||||
</option>
|
||||
<?php endforeach; ?>
|
||||
</select>
|
||||
<small class="form-text text-muted">Nur Urlaub wird auf das Urlaubskontingent angerechnet.</small>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Von:</label>
|
||||
<input type="date" name="start_date" class="form-control" required>
|
||||
<input type="date" name="start_date" class="form-control" value="<?php echo htmlspecialchars($start_date); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Bis:</label>
|
||||
<input type="date" name="end_date" class="form-control" required>
|
||||
<input type="date" name="end_date" class="form-control" value="<?php echo htmlspecialchars($end_date); ?>" required>
|
||||
</div>
|
||||
|
||||
<div class="form-group">
|
||||
<label>Kommentar (optional):</label>
|
||||
<textarea name="comment" class="form-control"></textarea>
|
||||
<textarea name="comment" class="form-control"><?php echo htmlspecialchars($comment); ?></textarea>
|
||||
</div>
|
||||
|
||||
<br>
|
||||
|
||||
<button type="submit" class="btn btn-primary btn-block">
|
||||
<?php echo $canManageTeamVacations ? 'Urlaub eintragen' : 'Urlaub beantragen'; ?>
|
||||
<?php echo $canManageTeamVacations ? 'Abwesenheit eintragen' : 'Abwesenheit beantragen'; ?>
|
||||
</button>
|
||||
|
||||
</form>
|
||||
|
||||
<hr>
|
||||
|
||||
<h4><?php echo $canManageTeamVacations ? 'Urlaubseintraege' : 'Meine Antraege'; ?></h4>
|
||||
<h4><?php echo $canManageTeamVacations ? 'Abwesenheitseintraege' : 'Meine Antraege'; ?></h4>
|
||||
|
||||
<?php
|
||||
$listSql = "
|
||||
@@ -196,6 +220,7 @@ $antraege = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<?php if ($canManageTeamVacations): ?>
|
||||
<th>Mitarbeiter</th>
|
||||
<?php endif; ?>
|
||||
<th>Grund</th>
|
||||
<th>Von</th>
|
||||
<th>Bis</th>
|
||||
<th>Tage</th>
|
||||
@@ -208,6 +233,7 @@ $antraege = $stmt->fetchAll(PDO::FETCH_ASSOC);
|
||||
<?php if ($canManageTeamVacations): ?>
|
||||
<td><?php echo htmlspecialchars(trim($a['vorname'] . ' ' . $a['nachname'])); ?></td>
|
||||
<?php endif; ?>
|
||||
<td><?php echo htmlspecialchars(vacationAbsenceReasonLabel($a['absence_reason'] ?? 'urlaub')); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$a['start_date']); ?></td>
|
||||
<td><?php echo htmlspecialchars((string)$a['end_date']); ?></td>
|
||||
<td><?php echo (int)$a['days']; ?></td>
|
||||
|
||||
Reference in New Issue
Block a user