Files
deskhub/DeskHub-Webseite/staff/dashboard_counts.php
T
2026-10-26 21:19:10 +00:00

30 lines
1.7 KiB
PHP

<?php
require_once __DIR__ . '/../includes/bootstrap.php';
$staff = require_staff_login();
$pdo = get_db();
header('Content-Type: application/json');
$myDeptIds = staff_department_ids($staff);
[$deptFilter, $deptParams] = dept_filter_sql($myDeptIds, 'department_id');
$now = db_now();
$open = $pdo->prepare("SELECT COUNT(*) FROM tickets WHERE status NOT IN ('resolved','closed')" . $deptFilter);
$open->execute($deptParams); $open = (int)$open->fetchColumn();
$mine = $pdo->prepare("SELECT COUNT(*) FROM tickets WHERE assigned_staff_id=? AND status NOT IN ('resolved','closed')" . $deptFilter);
$mine->execute(array_merge([$staff['id']], $deptParams)); $mine = (int)$mine->fetchColumn();
$unassigned = $pdo->prepare("SELECT COUNT(*) FROM tickets WHERE assigned_staff_id IS NULL AND status NOT IN ('resolved','closed')" . $deptFilter);
$unassigned->execute($deptParams); $unassigned = (int)$unassigned->fetchColumn();
$overdue = $pdo->prepare("SELECT COUNT(*) FROM tickets WHERE status NOT IN ('resolved','closed') AND (is_overdue = 1 OR (sla_paused_at IS NULL AND resolution_due_at IS NOT NULL AND resolution_due_at < ?))" . $deptFilter);
$overdue->execute(array_merge([$now], $deptParams)); $overdue = (int)$overdue->fetchColumn();
$unanswered = $pdo->prepare("SELECT COUNT(*) FROM tickets WHERE status = 'open'" . $deptFilter);
$unanswered->execute($deptParams); $unanswered = (int)$unanswered->fetchColumn();
$mentions = $pdo->prepare('SELECT COUNT(*) FROM staff_mentions WHERE mentioned_staff_id=? AND is_read=0');
$mentions->execute([$staff['id']]); $mentions = (int)$mentions->fetchColumn();
echo json_encode(['open'=>$open,'mine'=>$mine,'unassigned'=>$unassigned,'overdue'=>$overdue,'unanswered'=>$unanswered,'mentions'=>$mentions]);