35 lines
1.0 KiB
PHP
35 lines
1.0 KiB
PHP
<?php
|
|
/**
|
|
* staff/availability_status.php
|
|
* Gibt den aktuellen Verfügbarkeitsstatus aller aktiven Mitarbeiter als JSON zurück.
|
|
* Wird alle 15 Sekunden vom Frontend abgefragt.
|
|
*/
|
|
require_once __DIR__ . '/../includes/bootstrap.php';
|
|
require_staff_login();
|
|
$pdo = get_db();
|
|
|
|
header('Content-Type: application/json');
|
|
header('Cache-Control: no-cache');
|
|
|
|
try {
|
|
staff_run_auto_offline($pdo);
|
|
$rows = $pdo->query(
|
|
"SELECT s.id, s.name, s.is_on_vacation,
|
|
COALESCE(sa.status, 'offline') AS status,
|
|
sa.note
|
|
FROM staff s
|
|
LEFT JOIN staff_availability sa ON sa.staff_id = s.id
|
|
WHERE s.is_active = 1
|
|
ORDER BY s.name"
|
|
)->fetchAll(PDO::FETCH_ASSOC);
|
|
|
|
echo json_encode(array_map(fn($r) => [
|
|
'id' => (int)$r['id'],
|
|
'status' => $r['status'],
|
|
'note' => $r['note'] ?? '',
|
|
'is_on_vacation' => (bool)$r['is_on_vacation'],
|
|
], $rows));
|
|
} catch (Throwable $e) {
|
|
echo json_encode([]);
|
|
}
|