diff --git a/DeskHub-Webseite/api/staff/v1/presence.php b/DeskHub-Webseite/api/staff/v1/presence.php new file mode 100644 index 00000000..5a03c7fb --- /dev/null +++ b/DeskHub-Webseite/api/staff/v1/presence.php @@ -0,0 +1,16 @@ + {ok: true, status: "available"|...} + */ +api_require_method('POST'); +$staff = api_require_staff(); +$pdo = get_db(); +staff_touch_activity($pdo, (int) $staff['id']); +$s = $pdo->prepare('SELECT status FROM staff_availability WHERE staff_id = ?'); +$s->execute([(int) $staff['id']]); +api_json(['ok' => true, 'status' => (string) ($s->fetchColumn() ?: 'offline')]); diff --git a/DeskHub-Webseite/api/staff/v1/push_device.php b/DeskHub-Webseite/api/staff/v1/push_device.php new file mode 100644 index 00000000..0955431f --- /dev/null +++ b/DeskHub-Webseite/api/staff/v1/push_device.php @@ -0,0 +1,33 @@ + Status: ob der Server Push senden kann und wie viele Geräte des Mitarbeiters angemeldet sind + * POST {action: "register", token, deviceName?, appVersion?} Gerät anmelden (oder Token erneuern) + * POST {action: "unregister", token} Gerät abmelden (beim Ausloggen) + */ +api_require_method('GET', 'POST'); +$staff = api_require_staff(); +$pdo = get_db(); + +if ($_SERVER['REQUEST_METHOD'] === 'GET') { + $count = $pdo->prepare('SELECT COUNT(*) FROM push_devices WHERE staff_id = ?'); + $count->execute([(int) $staff['id']]); + api_json(['serverConfigured' => fcm_configured(), 'devices' => (int) $count->fetchColumn()]); +} + +$body = api_request_body(); +$action = (string) ($body['action'] ?? 'register'); +$token = trim((string) ($body['token'] ?? '')); +if (!fcm_token_valid($token)) api_error(422, 'TOKEN_INVALID', 'Das Geräte-Token ist ungültig.'); + +if ($action === 'unregister') { + fcm_unregister_device($pdo, (int) $staff['id'], $token); + api_json(['registered' => false]); +} +if ($action !== 'register') api_error(422, 'ACTION_INVALID', 'Unbekannte Aktion.'); + +fcm_register_device($pdo, (int) $staff['id'], $token, (string) ($body['deviceName'] ?? ''), (string) ($body['appVersion'] ?? '')); +api_json(['registered' => true, 'serverConfigured' => fcm_configured()]); \ No newline at end of file diff --git a/DeskHub-Webseite/api/staff/v1/push_prefs.php b/DeskHub-Webseite/api/staff/v1/push_prefs.php new file mode 100644 index 00000000..0e2f2cb6 --- /dev/null +++ b/DeskHub-Webseite/api/staff/v1/push_prefs.php @@ -0,0 +1,30 @@ + {events: [...], eventTypes: [{key, label}], quietFrom, quietTo} + * POST {events: [...], quietFrom: "22:00", quietTo: "06:00"} (leere Zeiten = immer Popups) + */ +api_require_method('GET', 'POST'); +$staff = api_require_staff(); +$pdo = get_db(); + +if ($_SERVER['REQUEST_METHOD'] === 'POST') { + $body = api_request_body(); + $events = array_map('strval', (array) ($body['events'] ?? [])); + $from = trim((string) ($body['quietFrom'] ?? '')); + $to = trim((string) ($body['quietTo'] ?? '')); + if (($from !== '' || $to !== '') && (!fcm_time_valid($from) || !fcm_time_valid($to))) { + api_error(422, 'QUIET_HOURS_INVALID', 'Stille Zeiten bitte als Uhrzeit von/bis angeben (z. B. 22:00 und 06:00).'); + } + fcm_save_prefs($pdo, (int) $staff['id'], $events, $from, $to, array_keys(fcm_event_types_for($staff))); +} + +// Nur Arten anzeigen, die für diesen Mitarbeiter (Rechte) in Frage kommen +$allowed = fcm_event_types_for($staff); +$p = fcm_prefs($pdo, (int) $staff['id']); +$types = []; +foreach ($allowed as $k => $label) $types[] = ['key' => $k, 'label' => $label]; +api_json(['events' => array_values(array_intersect($p['events'], array_keys($allowed))), 'eventTypes' => $types, 'quietFrom' => $p['quiet_from'], 'quietTo' => $p['quiet_to']]); diff --git a/DeskHub-Webseite/api/staff/v1/ticket_update.php b/DeskHub-Webseite/api/staff/v1/ticket_update.php index 5e40aca0..2604e248 100644 --- a/DeskHub-Webseite/api/staff/v1/ticket_update.php +++ b/DeskHub-Webseite/api/staff/v1/ticket_update.php @@ -76,6 +76,7 @@ if (array_key_exists('status', $body) && $body['status'] !== $ticket['status']) } if (array_key_exists('assignedStaffId', $body)) { log_activity($pdo, (int) $ticket['id'], (int) $staff['id'], 'Zuweisung geändert (Mobile App)'); + if ($assignedId !== null && $assignedId !== $currentId) fcm_notify_assignment($ticket, $assignedId, (int) $staff['id']); // Push auf die Android-App des neuen Bearbeiters } if ($chatJustClosed && $ticket['requester_email']) { try {