diff --git a/CHANGELOG.md b/CHANGELOG.md index 59c24c152..3f8729f8d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.12 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's thirty-four database changes (3.6.6 to 4.0.1) in the same pass. They add four tables for RMM providers and their alerts, a setting for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's thirty-five database changes (3.6.6 to 4.0.2) in the same pass. They add four tables for RMM providers and their alerts, a setting for API keys in the address, a column marking the emails the mail queue clears once sent, a column and a table for agent banners, two columns for ticket statuses with a setting for the "ticket assigned" message, a column on tickets with a setting for the "no response" message, a table for who a ticket's email replies go to, the settings for Quick tickets, columns on recurring tickets and recurring invoices for booking and making them ahead, two columns on ticket replies for when their time was worked, the settings for cron alerts, a table and a setting for labor costs, a column on users for API / service accounts, columns on tickets and recurring tickets for how long booked work takes, a column each on recurring tickets and calendar events for repeating on a weekday, three columns on agents' settings for their calendar color, what their calendar shows and their own time zone, a table for the agents helping on a ticket, three columns on quote lines with three settings for what a quote line costs and how it is priced, a column each on quote lines and products with a setting for their pictures, two settings and a column on tickets for keeping project tickets apart, a table for your other offices with a column each on agents and invites for which one they work from, three settings for the emails and notices your agents get about their tickets, three settings for sending and reading Microsoft 365 mail through Microsoft Graph, five tables, four settings and a role permission for purchase orders, five settings for switching Dispatch, Bookkeeping, Purchasing, Trips and the calendar on and off, and eight tables, three columns and two settings for the Knowledge Base, who can read its articles, what its readers think of them and their files, a column on documents for how often each is reviewed, a column on agents' settings for compact rows, a table for reply drafts, a table for which tickets each agent has opened, and change nothing that is there. Nothing else is required, but it is a big release, so take a backup before you update. Purchasing starts off - switch it on in Admin > Settings > Modules - and so does the Knowledge Base's public help center, in Admin > Settings > Knowledge Base. This release has thirteen security fixes - see Security. On Apache, ITFlow's own .htaccess now sends security headers: if you show ITFlow inside a frame on another website, it will now refuse to load there. On nginx, add the same headers to your server block if you want them - see Developer Updates. ### Security @@ -151,6 +151,11 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: Apply a template, in a ticket's More actions, adds a template's tasks to a ticket already open (change them first if you like), asks what the template asks, and adds its tags and due time where the ticket has none. - Tickets: emailed replies now keep the email as it arrived, as new tickets already did. Read beside it shows who it was from and to, its headers and everything it said - the reply line trims what shows on the ticket - and the .eml downloads from there. The client portal no longer lists these copies. - Click a picture shrunk to fit in a ticket, document or Knowledge Base article to see it full size - in the client portal too. +- Tickets: the tickets list keeps itself up to date. Once a minute, a ticket that changed - a reply, a new status, someone else picking it up - is updated where it is on the list, and a bar above the list says when tickets have come into the view or left it, with Show to load the list again. A ticket you've ticked waits for Show. +- Tickets: a ticket the client has written on since you last opened it is in bold on the tickets list - a reply from them, or a ticket they raised by email, in the portal or by text. Opening the ticket or its quick look takes the bold away, and so does Bulk Action > Mark as read. Each agent has their own; tickets from before the update count as read. +- Tickets: rest the pointer on a ticket's Activity on the tickets list to see its last reply - who, when and what it said. +- The browser tab shows how many open tickets are assigned to you, such as "(3) Real MSP - Tickets", on every page - kept up to date in the background, so you see it from another tab. +- Desktop notifications: Turn on desktop notifications, at the bottom of the bell's panel, and a ticket assigned to you or a client's reply on one of yours shows as a notification on your computer while you're away from ITFlow. Each browser has its own switch, and asks your permission first. - Modules: Admin > Settings > Modules has five more switches, to take out of ITFlow what your business doesn't use - Dispatch, which comes with Ticketing; Bookkeeping, Purchasing and Trips, which come with invoicing; and the Calendar. Each part is off while the one it comes with is, and shows faded under it. Switched off, a part leaves the menus, the dashboard, search, the reports and the API, and its pages and windows say it is off. Nothing in it is deleted - switched back on, it is all there. Dispatch, Bookkeeping, Trips and the Calendar start on, as before. - Bookkeeping: switch it off when your books are kept somewhere else. Accounts, Transactions, Transfers, Reconcile and the statement imports go, and nobody picks an account: payments and income go into the default payment account, and expenses come out of the default expense account - both in Admin > Settings > Defaults, or the first account when there's no default. An expense is paid by The business or Paid personally. The dashboard leaves out the account balances, and the Tax Package its Accounts section. - Calendar: switched off, the calendar, its events and the calendar feeds go - a subscribed calendar stops getting them. Tickets are still booked from the ticket and on Dispatch, and booked work still shows on the dashboard. @@ -329,6 +334,9 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: `split_ticket_reply` (`agent/modals/ticket/ticket_reply_split.php`) makes a ticket from a Client reply - details from the reply, contact from `ticket_reply_by` when it is the client's, category and billable from the ticket - moves the reply's attachment rows and files to it as ticket attachments, archives the reply, and adds an internal note and history on both. `apply_ticket_template` (`ticket_apply_template.php`, the shared template picker and task rows) adds the submitted tasks after the ticket's own and calls `ticketTemplateFinish()` with the fill-in answers and, when ticked, its defaults. `ticket_add.php` takes `copy_ticket_id`, and `agent/js/tickets_add_modal.js` now fills the lists for a client picked as the window opens even when it can be changed. - Tickets: `cron/ticket_email_parser.php` `addReply()` takes the original message file and keeps it as the reply's `Original-parsed-email.eml` attachment (not a stranger's). `agent/modals/ticket/ticket_email_source.php` reads a kept `.eml` with ImapEngine's `FileMessage` - addresses, date, subject, attachments, the text part (or the HTML as text) and the raw header block - and both attachment lists on the ticket show Read for one. `client/ticket.php` leaves `Original-parsed-email.eml` out, as `guest/guest_view_ticket.php` did. - `js/pretty_content.js` marks a `.prettyContent` picture shown smaller than it is (not one in a link) `itflow-zoomable` and opens it in a fixed layer on click; Escape closes the layer without closing a window under it. +- Tickets: database 4.0.2 adds `ticket_reads` (ticket, agent, `read_at`; ticket 0 is the agent's starting point, made by `ticketReadsSince()` the first time their list loads). `functions/ticket_read.php` has `ticketReadsReady()`, `ticketMarkRead()` (from `agent/ticket.php`, the quick look and the new `bulk_mark_tickets_read`), `ticketUnreadSql()` - a Client reply, or a ticket raised by Email, Portal or Text, newer than the agent's read or starting point, on a ticket not closed, selected as `ticket_unread` on the list view - and `ticketReadsCleanup()`, run nightly for closed or deleted tickets and archived agents. On the list, open subjects that have been read are no longer semibold; unread ones are bold. +- Tickets: list rows carry `data-ticket-id` and `data-ticket-sig`, a hash of what the row shows. `agent/js/tickets_live.js` fetches the same address once a minute while the tab is visible, swaps in rows whose signature changed (not ticked, no menu open), marks rows no longer there `itflow-row-gone`, counts new ones in `[data-tickets-live-bar]` and copies the pills' counts. `agent/js/ticket_reply_peek.js` shows `agent/ajax.php?ticket_reply_peek` - the last reply, or the details when there is none, as `emailPlainText()` - in a Bootstrap popover over `[data-reply-peek]`. +- `js/ticket_pulse.js` (every agent page, for Support) asks `agent/ajax.php?ticket_pulse` once a minute per browser - localStorage keeps the answer and a lock, and other tabs pick it up from the `storage` event - and puts the count of open tickets assigned to the agent (`TICKET_OPEN_SQL` and `ticketAssignedSql()`, as the Mine view) in front of `document.title`. With desktop notifications on (localStorage, per agent and browser, switched from `[data-desktop-notify]` in the bell's panel) it also asks for the assigned tickets not closed and Client replies on them after the last `reply_max`, works out newly assigned ones against the last answer, asks `about=` for up to five, and shows a `Notification` for each - not while an ITFlow tab has had the focus in the last 10 seconds, nor after a gap of more than 10 minutes. ## [26.11.8] diff --git a/admin/database_updates/4.0.2.php b/admin/database_updates/4.0.2.php new file mode 100644 index 000000000..1fe11f079 --- /dev/null +++ b/admin/database_updates/4.0.2.php @@ -0,0 +1,22 @@ + false]); + exit; + } + + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_reply, ticket_reply_type, ticket_reply_created_at, user_name, contact_name + FROM ticket_replies + LEFT JOIN users ON ticket_reply_type <> 'Client' AND ticket_reply_by = user_id + LEFT JOIN contacts ON ticket_reply_type = 'Client' AND ticket_reply_by = contact_id + WHERE ticket_reply_ticket_id = $ticket_id AND ticket_reply_archived_at IS NULL + ORDER BY ticket_reply_id DESC LIMIT 1")); + if ($row) { + $type = $row['ticket_reply_type']; + $peek = [ + 'label' => ['Client' => 'From the client', 'Public' => 'Our reply', 'Internal' => 'Internal note'][$type] ?? 'Internal note', + 'who' => (string) ($type === 'Client' ? $row['contact_name'] : $row['user_name']), + 'at' => $row['ticket_reply_created_at'], + 'html' => $row['ticket_reply'], + ]; + } else { + $peek = ['label' => 'No replies yet - the ticket says', 'who' => '', 'at' => $peek_ticket['ticket_created_at'], 'html' => $peek_ticket['ticket_details']]; + } + + echo json_encode([ + 'ok' => true, + 'label' => $peek['label'], + 'who' => $peek['who'], + 'when' => timeAgo($peek['at']), + 'at' => $peek['at'], + 'text' => emailPlainText($peek['html'], 600), + ]); + exit; +} + +/* + * For the browser tab's title and desktop notifications, from every agent page (js/ticket_pulse.js, + * once a minute per browser): how many open tickets are assigned to this agent - the Mine count. + * With desktop=1 also the tickets not yet closed that are assigned to them, for the page to work + * out which are new, and client replies on those since the reply id it last saw. With about= a + * few of those ids, what they are. + */ +if (isset($_GET['ticket_pulse'])) { + header('Content-Type: application/json'); + + if (lookupUserPermission('module_support') < 1) { + echo json_encode(['ok' => false]); + exit; + } + + $pulse_scope = clientScopeSql('ticket_client_id'); + $pulse_mine = ticketAssignedSql($session_user_id); + + if (isset($_GET['about'])) { + $about = []; + $about_ids = array_slice(array_values(array_filter(array_map('intval', explode(',', (string) $_GET['about'])))), 0, 5); + if ($about_ids) { + $sql = mysqli_query($mysqli, "SELECT tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, client_name + FROM tickets LEFT JOIN clients ON ticket_client_id = client_id + WHERE tickets.ticket_id IN (" . implode(',', $about_ids) . ") AND tickets.ticket_closed_at IS NULL AND $pulse_mine $pulse_scope"); + while ($row = mysqli_fetch_assoc($sql)) { + $about[] = [ + 'id' => intval($row['ticket_id']), + 'ref' => ticketReference($row), + 'subject' => (string) $row['ticket_subject'], + 'client' => intval($row['ticket_client_id']) ? (string) $row['client_name'] : 'Internal', + 'url' => '/agent/' . ticketUrl($row['ticket_id'], $row['ticket_client_id']), + ]; + } + } + echo json_encode(['ok' => true, 'about' => $about]); + exit; + } + + $pulse = ['ok' => true]; + $pulse['count'] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COUNT(tickets.ticket_id) FROM tickets WHERE " . TICKET_OPEN_SQL . " AND $pulse_mine $pulse_scope"))[0]); + + if (!empty($_GET['desktop'])) { + $pulse_ids = []; + $sql = mysqli_query($mysqli, "SELECT tickets.ticket_id FROM tickets WHERE tickets.ticket_closed_at IS NULL AND $pulse_mine $pulse_scope ORDER BY tickets.ticket_id DESC LIMIT 500"); + while ($row = mysqli_fetch_row($sql)) { + $pulse_ids[] = intval($row[0]); + } + $pulse['ids'] = $pulse_ids; + $pulse['reply_max'] = intval(mysqli_fetch_row(mysqli_query($mysqli, "SELECT COALESCE(MAX(ticket_reply_id), 0) FROM ticket_replies"))[0]); + + $pulse['replies'] = []; + $since_reply = intval($_GET['since_reply'] ?? 0); + if ($since_reply > 0 && $pulse_ids) { + $sql = mysqli_query($mysqli, "SELECT ticket_reply_id, ticket_reply, tickets.ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, contact_name + FROM ticket_replies + JOIN tickets ON ticket_reply_ticket_id = tickets.ticket_id + LEFT JOIN contacts ON ticket_reply_by = contact_id + WHERE ticket_reply_id > $since_reply AND ticket_reply_type = 'Client' AND ticket_reply_archived_at IS NULL + AND tickets.ticket_id IN (" . implode(',', $pulse_ids) . ") + ORDER BY ticket_reply_id DESC LIMIT 5"); + while ($row = mysqli_fetch_assoc($sql)) { + $pulse['replies'][] = [ + 'id' => intval($row['ticket_reply_id']), + 'ticket' => intval($row['ticket_id']), + 'ref' => ticketReference($row), + 'subject' => (string) $row['ticket_subject'], + 'who' => (string) ($row['contact_name'] ?? ''), + 'text' => emailPlainText($row['ticket_reply'], 140), + 'url' => '/agent/' . ticketUrl($row['ticket_id'], $row['ticket_client_id']), + ]; + } + } + } + + echo json_encode($pulse); + exit; +} + /* * Make a shared link (agent/modals/share/share_add.php, functions/share.php) * - a login, a document, a file, a secure note, the client's IT documentation diff --git a/agent/js/ticket_reply_peek.js b/agent/js/ticket_reply_peek.js new file mode 100644 index 000000000..9ec439174 --- /dev/null +++ b/agent/js/ticket_reply_peek.js @@ -0,0 +1,128 @@ +/* + * ITFlow - the last reply on a ticket, on the tickets list (agent/ticket_list.php). + * + * Rest the pointer on a ticket's Activity cell ([data-reply-peek]) and a popover shows the last + * reply - who, when, and what it said, as text - from agent/ajax.php?ticket_reply_peek. With no + * replies yet it shows what the ticket says. Text only: it goes in with textContent. + * + * Delegated on document, so rows agent/js/tickets_live.js swaps in work too. + */ +(function () { + 'use strict'; + + // Loaded ahead of the footer's Bootstrap - it is looked for when a popover is wanted + if (!window.matchMedia('(hover: hover)').matches) { + return; + } + + const DELAY_MS = 350; + const cache = {}; + let timer = null; + let current = null; + let popover = null; + + function hide() { + clearTimeout(timer); + timer = null; + if (popover) { + popover.dispose(); + popover = null; + } + if (current && current.dataset.peekTitle !== undefined) { + // The cell's own tooltip back + const titled = current.querySelector('[data-peek-titled]'); + if (titled) { + titled.setAttribute('title', current.dataset.peekTitle); + titled.removeAttribute('data-peek-titled'); + } + delete current.dataset.peekTitle; + } + current = null; + } + + function content(peek) { + const box = document.createElement('div'); + const head = document.createElement('div'); + head.className = 'itflow-reply-peek-head'; + head.textContent = peek.label + (peek.who ? ' - ' + peek.who : '') + ' · ' + peek.when; + head.title = peek.at; + const body = document.createElement('div'); + body.className = 'itflow-reply-peek-text'; + body.textContent = peek.text || 'Nothing written - a picture or a file.'; + box.append(head, body); + return box; + } + + function show(cell, peek) { + if (current !== cell || !peek || !peek.ok || typeof bootstrap === 'undefined') { + return; + } + popover = new bootstrap.Popover(cell, { + trigger: 'manual', + placement: 'left', + fallbackPlacements: ['bottom', 'top'], + container: 'body', + html: true, + sanitize: false, + content: content(peek), + customClass: 'itflow-reply-peek' + }); + popover.show(); + } + + function load(cell) { + const id = cell.dataset.replyPeek; + const row = cell.closest('tr'); + const key = id + ':' + (row ? row.dataset.ticketSig || '' : ''); + if (cache[key]) { + show(cell, cache[key]); + return; + } + fetch('/agent/ajax.php?ticket_reply_peek=' + encodeURIComponent(id), { credentials: 'same-origin' }) + .then(function (r) { return r.ok ? r.json() : null; }) + .then(function (peek) { + if (peek && peek.ok) { + cache[key] = peek; + } + show(cell, peek); + }) + .catch(function () {}); + } + + document.addEventListener('mouseover', function (e) { + const cell = e.target.closest('[data-reply-peek]'); + if (cell === current) { + return; + } + hide(); + if (!cell) { + return; + } + current = cell; + // The native tooltip on the time would sit on top of the popover + const titled = cell.querySelector('[title]'); + if (titled) { + cell.dataset.peekTitle = titled.getAttribute('title'); + titled.setAttribute('data-peek-titled', ''); + titled.removeAttribute('title'); + } + timer = setTimeout(function () { + load(cell); + }, DELAY_MS); + }); + + document.addEventListener('mouseleave', function (e) { + if (e.target === document.documentElement) { + hide(); + } + }, true); + + document.addEventListener('keydown', function (e) { + if (e.key === 'Escape') { + hide(); + } + }); + + document.addEventListener('scroll', hide, true); + window.addEventListener('blur', hide); +})(); diff --git a/agent/js/tickets_live.js b/agent/js/tickets_live.js new file mode 100644 index 000000000..5024d3a6f --- /dev/null +++ b/agent/js/tickets_live.js @@ -0,0 +1,158 @@ +/* + * ITFlow - a tickets list that keeps itself up to date (agent/ticket_list.php). + * + * Once a minute while the tab is in view, and straight away on coming back to it, the page + * fetches itself again - same filters, same view, same page - and compares: + * + * - a row whose data-ticket-sig changed (a reply, a new status, someone else assigned...) is + * swapped in where it is, unless it is ticked or has a menu open - those wait for Show; + * - tickets that came into this view, or left it, are counted in a bar above the list, and its + * Show button loads the list again; + * - the counts on the view pills are brought up to date. + * + * Rows aren't added or taken away under the pointer - only the bar says so. Everything in a + * row is delegated on document (quick picks, quick looks, ticks, the last-reply popover), so a + * swapped row works as before. + */ +(function () { + 'use strict'; + + const POLL_MS = 60000; + const bar = document.querySelector('[data-tickets-live-bar]'); + const table = document.querySelector('.itflow-ticket-list'); + if (!bar || !table || !window.fetch || !window.DOMParser) { + return; + } + + let lastPoll = Date.now(); + let busy = false; + let stopped = false; + + function rowsById(root) { + const rows = {}; + root.querySelectorAll('.itflow-ticket-list tbody > tr[data-ticket-id]').forEach(function (tr) { + rows[tr.dataset.ticketId] = tr; + }); + return rows; + } + + // Ticked, a menu or picker open in it, or being typed in - left alone until Show + function busyRow(tr) { + return !!tr.querySelector('input.bulk-select:checked, .dropdown-menu.show, [aria-expanded="true"]') + || tr.contains(document.activeElement); + } + + function plural(n, one, many) { + return n + ' ' + (n === 1 ? one : many); + } + + function updatePills(doc) { + const now = document.querySelectorAll('.itflow-asset-tabs .nav-link'); + const fresh = doc.querySelectorAll('.itflow-asset-tabs .nav-link'); + if (now.length !== fresh.length) { + return; + } + now.forEach(function (link, i) { + const badge = link.querySelector('.badge'); + const freshBadge = fresh[i].querySelector('.badge'); + if (badge && freshBadge && badge.textContent !== freshBadge.textContent) { + badge.textContent = freshBadge.textContent; + badge.className = freshBadge.className; + } + }); + } + + function compare(doc) { + const now = rowsById(document); + const fresh = rowsById(doc); + let added = 0; + let gone = 0; + let waiting = 0; + + Object.keys(fresh).forEach(function (id) { + const tr = now[id]; + if (!tr) { + added++; + return; + } + // Back in the view after leaving it + tr.classList.remove('itflow-row-gone'); + if (tr.dataset.ticketSig === fresh[id].dataset.ticketSig) { + return; + } + if (busyRow(tr)) { + waiting++; + return; + } + const replacement = document.importNode(fresh[id], true); + replacement.classList.add('itflow-row-updated'); + tr.replaceWith(replacement); + }); + Object.keys(now).forEach(function (id) { + if (!fresh[id] && !now[id].classList.contains('itflow-row-gone')) { + gone++; + now[id].classList.add('itflow-row-gone'); + } + }); + + // Counted from the page as it stands, so a second poll doesn't count the same ones twice + const goneTotal = document.querySelectorAll('.itflow-ticket-list tbody > tr.itflow-row-gone').length; + const parts = []; + if (added) { + parts.push(plural(added, 'new ticket', 'new tickets')); + } + if (goneTotal) { + parts.push(plural(goneTotal, 'ticket', 'tickets') + ' no longer in this view'); + } + if (waiting) { + parts.push(plural(waiting, 'ticked ticket has', 'ticked tickets have') + ' changed'); + } + bar.querySelector('[data-tickets-live-text]').textContent = parts.join(', '); + bar.hidden = !parts.length; + + updatePills(doc); + } + + function poll() { + if (busy || stopped || document.visibilityState !== 'visible') { + return; + } + busy = true; + lastPoll = Date.now(); + fetch(window.location.href, { credentials: 'same-origin' }) + .then(function (r) { + // Signed out - the login page came back instead; stop rather than guess + if (!r.ok || r.redirected) { + stopped = true; + return null; + } + return r.text(); + }) + .then(function (html) { + if (!html) { + return; + } + const doc = new DOMParser().parseFromString(html, 'text/html'); + if (!doc.querySelector('.itflow-ticket-list')) { + stopped = true; + return; + } + compare(doc); + }) + .catch(function () {}) + .finally(function () { + busy = false; + }); + } + + bar.querySelector('[data-tickets-live-show]').addEventListener('click', function () { + window.location.reload(); + }); + + setInterval(poll, POLL_MS); + document.addEventListener('visibilitychange', function () { + if (document.visibilityState === 'visible' && Date.now() - lastPoll > POLL_MS / 2) { + poll(); + } + }); +})(); diff --git a/agent/modals/ticket/ticket.php b/agent/modals/ticket/ticket.php index b440a82d9..9048a8ea2 100644 --- a/agent/modals/ticket/ticket.php +++ b/agent/modals/ticket/ticket.php @@ -41,6 +41,9 @@ if ($client_id) { enforceClientAccess(); } +// The quick look shows the latest replies - seen, as on the ticket page (functions/ticket_read.php) +ticketMarkRead($ticket_id, $session_user_id); + $purifier_config = HTMLPurifier_Config::createDefault(); $purifier_config->set('Cache.DefinitionImpl', null); $purifier_config->set('URI.AllowedSchemes', ['data' => true, 'src' => true, 'http' => true, 'https' => true]); diff --git a/agent/post/ticket.php b/agent/post/ticket.php index a46c62e02..daaeea82f 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -664,6 +664,21 @@ if (isset($_POST['bulk_delete_tickets'])) { } +// Seen, without opening each one - only this agent's bold goes (functions/ticket_read.php) +if (isset($_POST['bulk_mark_tickets_read'])) { + + validateCSRFToken(); + + $ticket_ids = array_keys(ticketsForBulk(1)); + ticketMarkRead($ticket_ids, $session_user_id); + + $count = count($ticket_ids); + flashAlert("Marked $count ticket" . ($count === 1 ? '' : 's') . " as read"); + + redirect(); + +} + if (isset($_POST['bulk_assign_ticket'])) { validateCSRFToken(); diff --git a/agent/ticket.php b/agent/ticket.php index cf3356ad4..f27920b90 100644 --- a/agent/ticket.php +++ b/agent/ticket.php @@ -57,6 +57,9 @@ if (isset($_GET['ticket_id'])) { $ticket = mysqli_fetch_assoc($sql); + // Seen - no longer in bold on this agent's tickets list (functions/ticket_read.php) + ticketMarkRead($ticket_id, $session_user_id); + $client_id = intval($ticket['client_id']); $client_name = escapeHtml($ticket['client_name']); diff --git a/agent/ticket_list.php b/agent/ticket_list.php index ef699b316..468ec73d7 100644 --- a/agent/ticket_list.php +++ b/agent/ticket_list.php @@ -6,7 +6,14 @@ * query parts this runs. Each row: the subject and what it is about, who it * is for, its status, priority and agent (changed in place), when it is due, * and who spoke last - with a dot before the subject when it is our move and - * a red or amber edge when it is late or close to it. + * a red or amber edge when it is late or close to it. The subject is in bold + * when the client has written since this agent last opened the ticket + * (functions/ticket_read.php). + * + * agent/js/tickets_live.js fetches this page again every minute and swaps in + * the rows that changed (by data-ticket-sig), and says when tickets have come + * into or left the view; agent/js/ticket_reply_peek.js shows the last reply + * when the Activity cell is hovered. */ isset($mysqli) || die("Direct file access is not allowed"); @@ -72,6 +79,13 @@ $sort_link = function ($column, $label, $class = '') use ($url_query_strings_sor ?> + +