'The database update for additional agents has not run yet.']); exit; } $helpers = ticketHelpers($ticket_id); $edit_user_id = intval($_GET['user_id'] ?? 0); $helper = $helpers[$edit_user_id] ?? null; $is_open = ticketIsOpen($row); // Booked with the lead, at a time of their own, or not at all $mode = $helper ? (intval($helper['follows_lead']) === 1 ? 'lead' : ($helper['start'] !== '' ? 'own' : 'none')) : 'lead'; $own_start = $mode === 'own' ? $helper['start'] : (string) ($row['ticket_schedule'] ?? ''); $own_minutes = $mode === 'own' ? ticketScheduleMinutes($helper['start'], $helper['end']) : ticketScheduleMinutes($row['ticket_schedule'], $row['ticket_schedule_end'] ?? null); $lead_when = $row['ticket_schedule'] ? ticketScheduleWhenText($row['ticket_schedule'], $row['ticket_schedule_end'] ?? null) : ''; // Who can be added: the agents who can open the ticket, but the lead and those on it already $agents = []; if (!$helper) { foreach (ticketMentionAgents($row['ticket_client_id']) as $user_id => $agent) { if ($user_id !== $lead_id && !isset($helpers[$user_id])) { $agents[$user_id] = $agent; } } } $day_user = $helper ? $edit_user_id : intval(array_key_first($agents) ?? 0); $day_name = $helper ? $helper['user_name'] : ($agents[$day_user]['name'] ?? ''); ob_start(); ?>