format('Y'); $month = isset($_GET['month']) ? (int)$_GET['month'] : (int)$now->format('n'); $year = max(2020, min(2099, $year)); $month = max(1, min(12, $month)); $first = new DateTimeImmutable(sprintf('%04d-%02d-01', $year, $month)); $month_start = $first->format('Y-m-d'); $month_end = $first->modify('last day of this month')->format('Y-m-d'); $days = (int)$first->format('t'); $prev = $first->modify('-1 month'); $next = $first->modify('+1 month'); $prev_url = '?year=' . $prev->format('Y') . '&month=' . $prev->format('n'); $next_url = '?year=' . $next->format('Y') . '&month=' . $next->format('n'); $stmt = db()->prepare( 'SELECT date, schicht FROM dienstplan WHERE user_id = ? AND date >= ? AND date <= ?' ); $stmt->execute([$user_id, $month_start, $month_end]); $schichten = []; foreach ($stmt->fetchAll() as $row) { $schichten[$row['date']] = $row['schicht']; } $stmt = db()->prepare(" SELECT von, bis, 'urlaub' AS typ FROM requests_urlaubsantrag WHERE user_id = ? AND status = 'accepted' AND bis >= ? AND von <= ? UNION ALL SELECT von, bis, 'abwesenheit' AS typ FROM requests_abwesenheitsantrag WHERE user_id = ? AND status = 'accepted' AND bis >= ? AND von <= ? "); $stmt->execute([$user_id, $month_start, $month_end, $user_id, $month_start, $month_end]); $overlays = []; foreach ($stmt->fetchAll() as $row) { $cursor = new DateTimeImmutable($row['von']); $end = new DateTimeImmutable($row['bis']); while ($cursor <= $end) { $key = $cursor->format('Y-m-d'); if ($key >= $month_start && $key <= $month_end) { $overlays[$key] = $row['typ']; } $cursor = $cursor->modify('+1 day'); } } $today_str = $now->format('Y-m-d'); $ea_stmt = db()->prepare('SELECT ort FROM einsatzanweisung WHERE user_id = ?'); $ea_stmt->execute([$user_id]); $ea_row = $ea_stmt->fetch(); $ea_ort = ($ea_row && $ea_row['ort'] !== '') ? $ea_row['ort'] : ''; $schicht_labels = ['frueh' => 'Früh', 'spaet' => 'Spät', 'nacht' => 'Nacht']; $weekdays = ['Mo', 'Di', 'Mi', 'Do', 'Fr', 'Sa', 'So']; $months_de = ['', 'Januar', 'Februar', 'März', 'April', 'Mai', 'Juni', 'Juli', 'August', 'September', 'Oktober', 'November', 'Dezember']; layout_start('Dienstplan', 'dienstplan'); ?>
📍 Einsatzort: = e($ea_ort) ?>