From a27c5d684acda2aa34cee4ed06c6d8e6035cf484 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Nov 2026 17:55:25 -0500 Subject: [PATCH] Tickets: Quick ticket, a + in the top bar, takes the client, contact found by name email or phone, and the issue, lists the contact's open tickets with Work on this one, raises it through add_ticket and opens it with its timer running, with what it starts with set in Admin Settings Tickets; a stopwatch in the top bar lists the ticket timers in this browser to open, pause, resume or throw away; database 3.7.6 adds the Quick tickets settings; 26.11.9 changelog entries --- CHANGELOG.md | 5 +- admin/database_updates/3.7.6.php | 48 ++++ admin/post/settings_ticket.php | 39 +++- admin/settings_ticket.php | 25 +++ agent/ajax.php | 61 ++++- agent/js/ticket_quick.js | 154 +++++++++++++ agent/modals/ticket/ticket_quick.php | 128 +++++++++++ agent/post/ticket.php | 13 +- agent/ticket.php | 1 + css/itflow_custom.css | 31 +++ db.sql | 10 + functions.php | 1 + functions/quick_ticket.php | 161 ++++++++++++++ functions/settings.php | 22 ++ includes/footer.php | 1 + includes/top_nav.php | 29 +++ js/ticket_timers.js | 318 +++++++++++++++++++++++++++ 17 files changed, 1033 insertions(+), 14 deletions(-) create mode 100644 admin/database_updates/3.7.6.php create mode 100644 agent/js/ticket_quick.js create mode 100644 agent/modals/ticket/ticket_quick.php create mode 100644 functions/quick_ticket.php create mode 100644 js/ticket_timers.js diff --git a/CHANGELOG.md b/CHANGELOG.md index 0b37d2bc4..7b946e4f0 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow. ### Upgrading -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's nine database changes (3.6.6 to 3.7.5) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one 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, and a table for who a ticket's email replies go to, and change nothing that is there. Nothing else is required. This release has eleven 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 ten database changes (3.6.6 to 3.7.6) in the same pass. They add four tables for RMM providers and their alerts, a setting for device actions and one 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, and the settings for Quick tickets, and change nothing that is there. Nothing else is required. This release has eleven 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 @@ -83,6 +83,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Ticket Statuses: a status can count as the first response. An agent moving a ticket nobody has answered yet into it - setting it by hand or in a reply, or assigning a new ticket, which opens it - meets (or misses) the SLA's response target then. It can count quietly, or once the contact and watchers are emailed a "ticket assigned" message, kept on the ticket as a public note - an "Assigned" status, say. The message is set in Admin > Settings > Tickets, under Messages to clients. A client's own reply moving a ticket never counts. From Mountaineer IT's build of ITFlow. - Tickets: Resolve - no response, on the arrow beside a ticket's Resolve button, is for a client who never answered after several tries. It shows the message from Admin > Settings > Tickets filled in for the ticket, to change before it goes; the message goes on the ticket as a public note and, with client emails on, to the contact and watchers in place of the usual "resolved" words. The ticket is resolved and closes on its own as usual, but without the email asking how we did. If they reply before then, it reopens. From Mountaineer IT's build of ITFlow. - Tickets: Email reply has a To line. It starts with the contact, the watchers and anyone at the client who asked for every update on their company's tickets; the technician it's assigned to, the client's other contacts or any email address typed in can be added, and anyone taken out. Everyone in To gets the email, each told why. What was changed is kept for the ticket, so its next email reply starts with the same people - taking a watcher out of To doesn't stop them watching. A reply sent to several tickets at once still goes to each one's contact and watchers. From Mountaineer IT's build of ITFlow. +- Tickets: Quick ticket - the + in the top bar, on every page - is for a call or someone at your desk: the client (on a client's page, that one), the contact, found by name, email address or phone number, and what the issue is. The contact's tickets still open are listed first, with who has each, so the same problem isn't raised twice - Work on this one goes to one of them instead, with its timer running. Make ticket raises it as New Ticket would and opens it with its timer already running. Admin > Settings > Tickets, Quick tickets, sets what these tickets start with: who they go to, the status, priority, category and billing, when the timer starts, whether the contact starts on the client's primary and whether they're emailed. From Mountaineer IT's build of ITFlow. +- Tickets: a stopwatch in the top bar shows the ticket timers running or paused in your browser, pulsing while one runs, so time isn't lost on a ticket you moved away from. It lists each ticket and its time, to go back to it, pause or resume the timer, or throw its time away. From Mountaineer IT's build of ITFlow. ### Bug Fixes @@ -197,6 +199,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Database 3.7.3: `ticket_statuses.ticket_status_reply_status_id` - 0, or the status a client's reply moves a ticket in it to; `ticketStatusAfterClientReply()` takes it while it is one of `ticketStatusReplyTargets()`, so a target switched off falls back, and deleting a status clears it from the others - and `ticket_status_first_response` (0, 1 or 2, `TICKET_STATUS_FIRST_RESPONSE`), and `settings.config_ticket_assigned_message` (NULL is `TICKET_ASSIGNED_MESSAGE`). The status form posts `client_reply` as `1`, `0` or `to-`, and `first_response`. `ticketStatusMovedByAgent($ticket_id, $from, $to)` is called where an agent moves a ticket - `ticketChangeStatus()`, `ticketChangeAssignee()`, `add_ticket`, `add_ticket_reply`, `bulk_ticket_reply`, `bulk_assign_ticket`, taking a text as a ticket and `ticket_replies/create`, not API ticket creation. With the email it inserts the message, filled by `cannedResponsePlaceholders()`, as a public note and sends it with `ticketEmailContent()`'s new `assigned` kind, keeping the note and calling `setTicketFirstResponse()` only when `ticketMailSend()` queued one. From Mountaineer IT's build of ITFlow. - Database 3.7.4: `tickets.ticket_no_response_at`, the `ticket_resolved_at` of a resolution that was "no response" - `ticketIsNoResponse()` while the two match, so a reopen and a later resolve leave it behind - and `settings.config_ticket_no_response_message` (NULL is `TICKET_NO_RESPONSE_MESSAGE`). `resolve_ticket_no_response` (`agent/post/ticket.php`, window `agent/modals/ticket/ticket_resolve_no_response.php`) checks the ticket is open with its tasks done, and `ticketResolveNoResponse()` inserts the message as a public note, calls `ticketResolve()` and sends `ticketEmailContent()`'s `resolved` kind with `no_response`, the message in place of its words. `ticketMailClosed()` sends nothing for such a ticket. The Resolve button is a group with a split arrow, and the group carries `data-ticket-resolve`, so ticking a task swaps it whole. From Mountaineer IT's build of ITFlow. - Database 3.7.5: `ticket_mail_choices` - per ticket, the addresses put in or taken out of the To line where that differs from the default (the contact, watchers and `ticketColleagueRecipients()` in; the assigned agent, the client's other contacts and typed addresses out), going with the ticket. `functions/ticket_reply_recipients.php`: `ticketReplyRecipients()` lists who the To line offers, `ticketReplyRecipientsPick()` keeps the posted choice and returns `emailQueue()` recipients with why each gets it, `ticketReplyRecipientsForget()` clears it. `add_ticket_reply` sends to them when `email_to_shown` is posted with `email_to[]`, through `ticketMailReply()`'s new `$to` and `ticketMailSend()`'s `recipients` option; without it - the bulk reply, the API, an older form - to the contact and watchers as before. `change_client_ticket` takes off watchers who are neither agents nor the new client's contacts, and forgets the ticket's choices. From Mountaineer IT's build of ITFlow. +- Database 3.7.6: `config_quick_ticket_on`, `_assign` ('me', 'nobody' or a user id), `_status`, `_priority`, `_category`, `_billable` (-1 is `config_ticket_default_billable`), `_timer` (make, open or off), `_primary`, `_open_tickets` and `_email_client` in `settings`, read by `quickTicketSettings()` (`functions/quick_ticket.php`). `includes/top_nav.php` has the + (an `ajax-modal` of `agent/modals/ticket/ticket_quick.php`, with `agent/js/ticket_quick.js`) and the timers menu (`js/ticket_timers.js`, loaded from `includes/footer.php`). The window posts `add_ticket` with `quick_ticket`, plain-text `details` (made HTML by `quickTicketDetailsHtml()`), `status`, `category_id`, `billable` and `quick_ticket_timer`, the browser's clock in ms; `add_ticket` skips `ticketMailCreated()` when `_email_client` is off and calls `quickTicketAfterCreate()`, which logs the history line and keeps the start in the session for `quickTicketTimerScript()`, printed on the ticket page before `agent/js/ticket_time_tracking.js`. `agent/ajax.php`: `ticket_also_open` takes `work` (who has each, when it last moved, a Work on this one button with `data-ticket-work`, up to 10, and a line when there are none), `get_client_contacts` also returns `contact_phone` and `contact_mobile`, and `ticket_timer_tickets` returns the reference, subject, client and state of the tickets behind the timers the agent can open. The timers read and write the same `-startTime`, `-pausedTime` and `ticket-timer-running-` keys, and on the ticket's own page press its `#startStopTimer`. From Mountaineer IT's build of ITFlow. ## [26.11.8] diff --git a/admin/database_updates/3.7.6.php b/admin/database_updates/3.7.6.php new file mode 100644 index 000000000..22136a89c --- /dev/null +++ b/admin/database_updates/3.7.6.php @@ -0,0 +1,48 @@ + Settings > Tickets, Quick tickets: + * config_quick_ticket_on the button shows, for those who can make tickets + * config_quick_ticket_assign 'me' (the agent making it), 'nobody', or an agent's id + * config_quick_ticket_status 0 (New, or Open once someone has it), or a status an agent can pick + * config_quick_ticket_priority Low, Medium, High or Urgent + * config_quick_ticket_category 0, or a ticket category + * config_quick_ticket_billable -1 as a new ticket starts (config_ticket_default_billable), else 1 or 0 + * config_quick_ticket_timer make, open or off - when its timer counts from + * config_quick_ticket_primary the contact starts on the client's primary contact + * config_quick_ticket_open_tickets the window shows the contact's open tickets + * config_quick_ticket_email_client the contact gets the "ticket created" email (with client emails on) + * + * Re-runnable: each column is added only where it isn't there yet. + */ + +defined('FROM_DB_UPDATER') || die("Direct file access is not allowed"); + + $itflow_column = function ($table, $column) use ($mysqli) { + $result = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS + WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = '$table' AND COLUMN_NAME = '$column' LIMIT 1"); + return $result && mysqli_num_rows($result) > 0; + }; + + $itflow_after = 'config_ticket_no_response_message'; + foreach ([ + 'config_quick_ticket_on' => "tinyint(1) NOT NULL DEFAULT 1", + 'config_quick_ticket_assign' => "varchar(10) NOT NULL DEFAULT 'me'", + 'config_quick_ticket_status' => "int(11) NOT NULL DEFAULT 0", + 'config_quick_ticket_priority' => "varchar(10) NOT NULL DEFAULT 'Medium'", + 'config_quick_ticket_category' => "int(11) NOT NULL DEFAULT 0", + 'config_quick_ticket_billable' => "tinyint(1) NOT NULL DEFAULT -1", + 'config_quick_ticket_timer' => "varchar(10) NOT NULL DEFAULT 'make'", + 'config_quick_ticket_primary' => "tinyint(1) NOT NULL DEFAULT 1", + 'config_quick_ticket_open_tickets' => "tinyint(1) NOT NULL DEFAULT 1", + 'config_quick_ticket_email_client' => "tinyint(1) NOT NULL DEFAULT 1", + ] as $itflow_name => $itflow_type) { + if (!$itflow_column('settings', $itflow_name)) { + mysqli_query($mysqli, "ALTER TABLE `settings` ADD `$itflow_name` $itflow_type AFTER `$itflow_after`"); + } + $itflow_after = $itflow_name; + } diff --git a/admin/post/settings_ticket.php b/admin/post/settings_ticket.php index ee9581e1d..fd2e6bef2 100644 --- a/admin/post/settings_ticket.php +++ b/admin/post/settings_ticket.php @@ -3,8 +3,8 @@ /* * Admin > Settings > Tickets (admin/settings_ticket.php): * edit_ticket_settings saves the numbering, email and text to ticket, who hears of a - * new ticket and whether AI triages it, the timer and billing, the messages to - * clients, closing and the tickets page. A next + * new ticket and whether AI triages it, what a quick ticket starts with, the timer + * and billing, the messages to clients, closing and the tickets page. A next * number already in use, an email address that isn't one or a closing time * out of range comes back to the page saying so - nothing is saved. Billable * by default is only on the page with accounting on, so is kept as it is @@ -22,7 +22,9 @@ if (isset($_POST['edit_ticket_settings'])) { 'config_ticket_new_ticket_notification_email', 'config_ticket_timer_autostart', 'config_ticket_default_billable', 'config_ticket_autoclose_hours', 'config_ticket_default_view', 'config_ticket_ordering', 'config_ticket_moving_columns'], aiTriageReady() ? ['config_ticket_ai_triage'] : [], settingsColumnExists($mysqli, 'config_ticket_sms_parse') ? ['config_ticket_sms_parse', 'config_ticket_sms_unknown_senders', 'config_ticket_sms_acknowledge'] : [], - ticketStatusReplyReady() ? ['config_ticket_assigned_message'] : [], ticketNoResponseReady() ? ['config_ticket_no_response_message'] : [])); + ticketStatusReplyReady() ? ['config_ticket_assigned_message'] : [], ticketNoResponseReady() ? ['config_ticket_no_response_message'] : [], + quickTicketReady() ? ['config_quick_ticket_on', 'config_quick_ticket_assign', 'config_quick_ticket_status', 'config_quick_ticket_priority', 'config_quick_ticket_category', + 'config_quick_ticket_billable', 'config_quick_ticket_timer', 'config_quick_ticket_primary', 'config_quick_ticket_open_tickets', 'config_quick_ticket_email_client'] : [])); // What was sent, and what is saved for anything that wasn't - a switch not sent is off $in = $_POST + array_map(function ($value) { return (string) $value; }, $before); @@ -56,6 +58,37 @@ if (isset($_POST['edit_ticket_settings'])) { } } + // Quick tickets - once the database has them. Billable is only on the page with accounting on + if (array_key_exists('config_quick_ticket_on', $before)) { + foreach (['config_quick_ticket_on', 'config_quick_ticket_primary', 'config_quick_ticket_open_tickets', 'config_quick_ticket_email_client'] as $switch) { + $after[$switch] = empty($_POST[$switch]) ? 0 : 1; + } + $quick_assign = (string) $in['config_quick_ticket_assign']; + $after['config_quick_ticket_assign'] = in_array($quick_assign, ['me', 'nobody'], true) ? $quick_assign : (string) ticketAgentId(intval($quick_assign)); + if ($after['config_quick_ticket_assign'] === '0') { + $errors['config_quick_ticket_assign'] = 'Pick who it goes to from the list.'; + } + $after['config_quick_ticket_status'] = intval($in['config_quick_ticket_status']); + if ($after['config_quick_ticket_status'] && !isset(ticketPickableStatuses()[$after['config_quick_ticket_status']])) { + $errors['config_quick_ticket_status'] = 'Pick the status from the list.'; + } + $after['config_quick_ticket_priority'] = (string) $in['config_quick_ticket_priority']; + if (!in_array($after['config_quick_ticket_priority'], ['Low', 'Medium', 'High', 'Urgent'], true)) { + $errors['config_quick_ticket_priority'] = 'Pick the priority from the list.'; + } + $after['config_quick_ticket_category'] = ticketCategoryId($in['config_quick_ticket_category']); + if ($config_module_enable_accounting) { + $after['config_quick_ticket_billable'] = intval($in['config_quick_ticket_billable']); + if (!isset(QUICK_TICKET_BILLABLE[$after['config_quick_ticket_billable']])) { + $errors['config_quick_ticket_billable'] = 'Pick whether it bills from the list.'; + } + } + $after['config_quick_ticket_timer'] = (string) $in['config_quick_ticket_timer']; + if (!isset(QUICK_TICKET_TIMER[$after['config_quick_ticket_timer']])) { + $errors['config_quick_ticket_timer'] = 'Pick when its timer starts from the list.'; + } + } + if ($problem = settingsEmailProblem($after['config_ticket_new_ticket_notification_email'])) { $errors['config_ticket_new_ticket_notification_email'] = $problem; } diff --git a/admin/settings_ticket.php b/admin/settings_ticket.php index c31375fe7..7cf0913b9 100644 --- a/admin/settings_ticket.php +++ b/admin/settings_ticket.php @@ -69,6 +69,31 @@ echo settingsPageStart('ticket'); + + in the top bar - the client, the contact and the issue, for a call or a walk-up. It shows the contact\'s tickets still open first, so the same problem isn\'t raised twice. These are what a quick ticket starts with.', 'quick') ?> + 'For everyone who can make tickets.']) ?> +
+ 'fa-user-check', 'search' => true, + 'help' => 'The window has an "Assign it to ..." switch, to change it for one ticket.']) ?> + 'fa-info-circle']) ?> + 'Low', 'Medium' => 'Medium', 'High' => 'High', 'Urgent' => 'Urgent'], ['icon' => 'fa-thermometer-half', + 'help' => 'The window can change it for one ticket. Its SLA follows the priority, as any ticket\'s does.']) ?> + 'fa-layer-group', 'search' => true, + 'options_html' => '' . categoryOptionsHtml('Ticket', $quick['category'] ?: null)]) ?> + + 'fa-dollar-sign']) ?> + + 'fa-stopwatch', + 'help' => 'It runs on the ticket page, as a ticket\'s timer does, until the time goes on a reply.']) ?> + 'Off, the contact starts empty, to be picked.']) ?> + 'Not resolved or closed - with Work on this one, to go to one instead.']) ?> + 'The "ticket created" email, as New Ticket sends it.' + . (intval($config_ticket_client_general_notifications) === 1 ? '' : ' Emails to clients are off in Notifications, so none goes either way.')]) ?> +
+ + + Ticket Statuses) $assigned_sent_by = array_column(array_filter(ticketStatusesAll(), function ($status) { diff --git a/agent/ajax.php b/agent/ajax.php index 6879b30e7..6a4fa7e38 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -1269,7 +1269,7 @@ if (isset($_GET['get_client_contacts'])) { $contact_sql = mysqli_query( $mysqli, - "SELECT contact_id, contact_name, contact_title, contact_email, contact_photo, contact_primary, contact_important, contact_technical, contact_location_id FROM contacts + "SELECT contact_id, contact_name, contact_title, contact_email, contact_phone, contact_mobile, contact_photo, contact_primary, contact_important, contact_technical, contact_location_id FROM contacts LEFT JOIN clients on contact_client_id = client_id WHERE contacts.contact_archived_at IS NULL AND contact_client_id = $client_id " . clientScopeSql('contact_client_id') . " @@ -1293,7 +1293,9 @@ if (isset($_GET['get_client_contacts'])) { /* * New Ticket - the other open tickets for the contact or asset picked, so a - * second ticket for the same problem shows up before it is raised. + * second ticket for the same problem shows up before it is raised. With work + * (Quick ticket - agent/js/ticket_quick.js), who has each and when it last + * moved, a Work on this one button on each, and a line when there are none. */ if (isset($_GET['ticket_also_open'])) { enforceUserPermission('module_support', 2); @@ -1307,23 +1309,68 @@ if (isset($_GET['ticket_also_open'])) { } $also_contact_id = ticketClientOwnedId('contact', $_GET['contact_id'] ?? 0, $client_id); $also_asset_id = ticketClientOwnedId('asset', $_GET['asset_id'] ?? 0, $client_id); - $rows = ticketAlsoOpen($also_contact_id, $also_asset_id, 0, 5); + $also_work = !empty($_GET['work']); + $rows = ticketAlsoOpen($also_contact_id, $also_asset_id, 0, $also_work ? 10 : 5); $html = ''; if ($rows) { $html = '
Already open for ' - . ($also_contact_id && $also_asset_id ? 'this contact or asset' : ($also_contact_id ? 'this contact' : 'this asset')) . '
'; + . ($also_contact_id && $also_asset_id ? 'this contact or asset' : ($also_contact_id ? 'this contact' : 'this asset')) . ($also_work ? ' (' . count($rows) . ')' : '') . '
' + . ($also_work ? '
' : ''); foreach ($rows as $row) { - $html .= '
' . ticketLink($row) - . ' ' . ticketStatusHtml($row['ticket_status_name'], $row['ticket_status_color'], 'detail') . '
'; + if ($also_work) { + // From the top bar on any page, admin's too - so the agent's address in full + $also_url = '/agent/' . ticketUrl(intval($row['ticket_id']), $client_id); + $also_who = !intval($row['ticket_assigned_to']) ? 'Nobody has it' : (intval($row['ticket_assigned_to']) === intval($session_user_id) ? 'Yours' : (string) $row['user_name']); + $html .= '
' + . '
' + . '
' . escapeHtml($also_who) . ' · ' . escapeHtml(timeAgo($row['ticket_updated_at'] ?: $row['ticket_created_at'])) . '
' + . '' . ticketStatusHtml($row['ticket_status_name'], $row['ticket_status_color'], 'detail') . '' + . '
'; + } else { + $html .= '
' . ticketLink($row) + . ' ' . ticketStatusHtml($row['ticket_status_name'], $row['ticket_status_color'], 'detail') . '
'; + } } - $html .= '
Add to one of these instead, if it is the same problem.
'; + $html .= ($also_work ? '' : '') . '
Add to one of these instead, if it is the same problem.
'; + } elseif ($also_work && $also_contact_id) { + $html = '
No open tickets for this contact.
'; } echo json_encode(['html' => $html]); exit; } +/* + * The tickets behind the timers in this browser (js/ticket_timers.js) - each + * one's number, subject, client and whether it is still open. Only tickets + * the agent can open come back. + */ +if (isset($_GET['ticket_timer_tickets'])) { + header('Content-Type: application/json'); + + $ids = array_slice(array_values(array_unique(array_filter(array_map('intval', explode(',', (string) ($_GET['ids'] ?? '')))))), 0, 100); + $timer_tickets = []; + if ($ids && lookupUserPermission('module_support') >= 1) { + $sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_client_id, ticket_resolved_at, ticket_closed_at, ticket_archived_at, client_name + FROM tickets LEFT JOIN clients ON client_id = ticket_client_id + WHERE ticket_id IN (" . implode(',', $ids) . ") " . clientScopeSql('ticket_client_id')); + while ($row = mysqli_fetch_assoc($sql)) { + $timer_tickets[intval($row['ticket_id'])] = [ + 'reference' => ticketReference($row), + 'subject' => html_entity_decode((string) $row['ticket_subject'], ENT_QUOTES, 'UTF-8'), + 'client' => html_entity_decode((string) $row['client_name'], ENT_QUOTES, 'UTF-8'), + 'client_id' => intval($row['ticket_client_id']), + 'open' => ticketIsOpen($row) && empty($row['ticket_archived_at']), + 'state' => !empty($row['ticket_closed_at']) ? 'Closed' : (!empty($row['ticket_resolved_at']) ? 'Resolved' : (!empty($row['ticket_archived_at']) ? 'Archived' : '')), + ]; + } + } + echo json_encode((object) $timer_tickets); + exit; +} + /* * Returns ordered list of active assets for a specified client */ diff --git a/agent/js/ticket_quick.js b/agent/js/ticket_quick.js new file mode 100644 index 000000000..1cd5227fc --- /dev/null +++ b/agent/js/ticket_quick.js @@ -0,0 +1,154 @@ +/* + * Quick ticket's window (agent/modals/ticket/ticket_quick.php): the client's + * contacts once it is picked - its primary to start with, when the setting + * says so - and the contact's tickets still open, with Work on this one to go + * to one instead. Make ticket sends when the new ticket's timer counts from, + * by this browser's clock, as the ticket page's timer is this browser's + * (agent/js/ticket_time_tracking.js). Run again each time the window opens. + */ +(function () { + 'use strict'; + + const form = document.getElementById('quickTicketForm'); + if (!form || form.dataset.ready) { + return; + } + form.dataset.ready = '1'; + + const openedAt = Date.now(); + const timerMode = form.dataset.timer; + const client = document.getElementById('quickTicketClient'); + const contact = document.getElementById('quickTicketContact'); + const openBox = document.getElementById('quickTicketOpen'); + const subject = document.getElementById('quickTicketSubject'); + let contactRequest = 0; + let openRequest = 0; + + function timerStart() { + return timerMode === 'open' ? openedAt : Date.now(); + } + + // The ticket's timer as the ticket page keeps it - only one that isn't there already + function startTimer(ticketId, from) { + try { + if (!localStorage.getItem(ticketId + '-startTime') && !localStorage.getItem(ticketId + '-pausedTime')) { + localStorage.setItem(ticketId + '-startTime', String(from)); + localStorage.setItem('ticket-timer-running-' + ticketId, 'true'); + } + } catch (e) { + // No storage - the ticket opens without a running timer + } + } + + function contactsOnly(label) { + contact.innerHTML = ''; + contact.add(new Option(label, '0')); + } + + // The contact's tickets still open + function loadOpen() { + const mine = ++openRequest; + openBox.innerHTML = ''; + if (form.dataset.openTickets !== '1' || !client.value || contact.value === '0') { + return; + } + itflowGet('/agent/ajax.php', { ticket_also_open: 1, work: 1, client_id: client.value, contact_id: contact.value }, function (data) { + if (mine !== openRequest) { + return; + } + try { + openBox.innerHTML = JSON.parse(data).html || ''; + } catch (e) { + openBox.innerHTML = ''; + } + }); + } + + // The client's contacts - found by name, email address or phone number + function loadContacts() { + const mine = ++contactRequest; + openBox.innerHTML = ''; + contact.disabled = true; + contactsOnly(client.value ? 'Loading...' : 'Pick the client first'); + if (!client.value) { + return; + } + itflowGet('/agent/ajax.php', { get_client_contacts: 'true', client_id: client.value }, function (data) { + if (mine !== contactRequest) { + return; + } + let contacts = []; + try { + contacts = JSON.parse(data).contacts || []; + } catch (e) { + contacts = []; + } + contactsOnly('- No One -'); + contacts.forEach(function (row) { + const option = new Option(row.contact_name, row.contact_id); + const details = []; + if (row.contact_title) { + details.push(row.contact_title); + } + if (row.contact_primary == '1') { + details.push('Primary'); + } else if (row.contact_technical == '1') { + details.push('Technical'); + } + option.dataset.description = details.join(' · '); + option.dataset.keywords = [row.contact_email, row.contact_phone, row.contact_mobile] + .concat([row.contact_phone, row.contact_mobile].map(function (number) { return String(number || '').replace(/\D/g, ''); })) + .filter(Boolean).join(' '); + option.dataset.initials = row.contact_initials; + option.dataset.shape = 'circle'; + option.dataset.tone = row.contact_tone || 'secondary'; + option.dataset.soft = '1'; + if (row.contact_photo_url) { + option.dataset.image = row.contact_photo_url; + } + contact.add(option); + }); + contact.disabled = false; + const primary = form.dataset.primary === '1' ? contacts.find(function (row) { return row.contact_primary == '1'; }) : null; + contact.value = primary ? String(primary.contact_id) : '0'; + loadOpen(); + }); + } + + client.addEventListener('change', loadContacts); + contact.addEventListener('change', loadOpen); + + // Work on this one - its timer started, as a new one's would be + openBox.addEventListener('click', function (e) { + const button = e.target.closest('[data-ticket-work]'); + if (!button) { + return; + } + if (timerMode !== 'off') { + startTimer(button.dataset.ticketWork, timerStart()); + } + window.location.href = button.dataset.url; + }); + + form.addEventListener('submit', function () { + document.getElementById('quickTicketTimer').value = timerMode === 'off' ? '' : String(timerStart()); + }); + + // Ready to type - the issue, or the client first. After the window's own focus (js/app.js), which parks it on the dialog + const modal = form.closest('.modal'); + if (modal) { + modal.addEventListener('shown.bs.modal', function () { + setTimeout(function () { + if (client.value) { + subject.focus(); + } else if (client.itflowSelect) { + client.itflowSelect.control.focus(); + } + }, 0); + }); + } + + if (client.value) { + loadContacts(); + } +})(); diff --git a/agent/modals/ticket/ticket_quick.php b/agent/modals/ticket/ticket_quick.php new file mode 100644 index 000000000..f37679b26 --- /dev/null +++ b/agent/modals/ticket/ticket_quick.php @@ -0,0 +1,128 @@ + Settings > Tickets. + * Opened on a client's page, it starts on that client. Script: + * agent/js/ticket_quick.js. + */ + +enforceUserPermission('module_support', 2); + +if (!quickTicketCan()) { + echo json_encode(['error' => 'Quick ticket is switched off - New Ticket is on the Tickets page.']); + exit; +} + +$quick = quickTicketSettings(); +$client_id = intval($_GET['client_id'] ?? 0); +if ($client_id && !hasClientAccess($client_id)) { + $client_id = 0; +} +$assignee = quickTicketAssignee(); +$assignee_name = $assignee && $assignee !== intval($session_user_id) ? (string) getFieldById('users', $assignee, 'user_name') : ''; +$status = isset(ticketPickableStatuses()[$quick['status']]) ? $quick['status'] : 0; + +ob_start(); + +?> + +
+ + + + + + + + + + + +
+ + + + + diff --git a/css/itflow_custom.css b/css/itflow_custom.css index 4ff776e2c..b492f7fb9 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -2457,6 +2457,37 @@ body { align-items: center; padding: .75rem 1rem .25rem; } +/* Ticket timers in the top bar (js/ticket_timers.js) - the stopwatch pulses while one runs */ +#itflowTimers.is-running > .nav-link { + color: var(--bs-warning); +} +#itflowTimers.is-running .fa-stopwatch { + animation: itflow-timer-pulse 1.6s ease-in-out infinite; +} +@keyframes itflow-timer-pulse { + 50% { opacity: .45; } +} +@media (prefers-reduced-motion: reduce) { + #itflowTimers.is-running .fa-stopwatch { + animation: none; + } +} +.itflow-timer-row { + padding: .6rem 1rem; + border-bottom: 1px solid var(--bs-border-color); +} +.itflow-timer-row:last-child { + border-bottom: 0; +} +.itflow-timer-time { + font-variant-numeric: tabular-nums; + font-weight: 600; +} +/* Quick ticket's list of the contact's open tickets - a long one scrolls in place */ +.itflow-also-open-list { + max-height: 15rem; + overflow-y: auto; +} .itflow-notify-tabs { gap: 1rem; padding: 0 1rem; diff --git a/db.sql b/db.sql index e3ce236bd..86ce36a12 100644 --- a/db.sql +++ b/db.sql @@ -3365,6 +3365,16 @@ CREATE TABLE `settings` ( `config_ticket_timer_autostart` tinyint(1) NOT NULL DEFAULT 0, `config_ticket_assigned_message` text DEFAULT NULL, `config_ticket_no_response_message` text DEFAULT NULL, + `config_quick_ticket_on` tinyint(1) NOT NULL DEFAULT 1, + `config_quick_ticket_assign` varchar(10) NOT NULL DEFAULT 'me', + `config_quick_ticket_status` int(11) NOT NULL DEFAULT 0, + `config_quick_ticket_priority` varchar(10) NOT NULL DEFAULT 'Medium', + `config_quick_ticket_category` int(11) NOT NULL DEFAULT 0, + `config_quick_ticket_billable` tinyint(1) NOT NULL DEFAULT -1, + `config_quick_ticket_timer` varchar(10) NOT NULL DEFAULT 'make', + `config_quick_ticket_primary` tinyint(1) NOT NULL DEFAULT 1, + `config_quick_ticket_open_tickets` tinyint(1) NOT NULL DEFAULT 1, + `config_quick_ticket_email_client` tinyint(1) NOT NULL DEFAULT 1, `config_enable_cron` tinyint(1) NOT NULL DEFAULT 1, `config_recurring_auto_send_invoice` tinyint(1) NOT NULL DEFAULT 1, `config_enable_alert_domain_expire` tinyint(1) NOT NULL DEFAULT 1, diff --git a/functions.php b/functions.php index 6f38648c8..e8cc96207 100644 --- a/functions.php +++ b/functions.php @@ -109,6 +109,7 @@ require_once __DIR__ . '/functions/rmm_tactical.php'; require_once __DIR__ . '/functions/client_onboarding.php'; require_once __DIR__ . '/functions/ticket_mention.php'; require_once __DIR__ . '/functions/ticket_reply_recipients.php'; +require_once __DIR__ . '/functions/quick_ticket.php'; require_once __DIR__ . '/functions/getting_started.php'; require_once __DIR__ . '/functions/settings.php'; require_once __DIR__ . '/functions/mail_queue.php'; diff --git a/functions/quick_ticket.php b/functions/quick_ticket.php new file mode 100644 index 000000000..ea6e79428 --- /dev/null +++ b/functions/quick_ticket.php @@ -0,0 +1,161 @@ + Settings > Tickets, Quick tickets (config_quick_ticket_*, 3.7.6). + * + * The timer is the ticket page's own (agent/js/ticket_time_tracking.js), kept + * in the browser. The window sends when it should count from - Make ticket + * pressed, or the window opened, by the browser's clock - and the ticket + * page's first load starts it from then (quickTicketTimerScript()). + */ + +/** When a quick ticket's timer counts from. */ +const QUICK_TICKET_TIMER = [ + 'make' => 'From when Make ticket is pressed', + 'open' => 'From when the window was opened - the start of the call', + 'off' => 'Don\'t start it - as for any ticket', +]; + +/** Whether the 3.7.6 update has run - the Quick tickets settings. Until it has, the button shows with the built-in ones. */ +function quickTicketReady() { + global $mysqli; + static $ready = null; + if ($ready === null) { + if (defined('CURRENT_DATABASE_VERSION')) { + $version = CURRENT_DATABASE_VERSION; + } else { + $result = mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1"); + $version = $result && ($row = mysqli_fetch_row($result)) ? (string) $row[0] : '0'; + } + $ready = version_compare($version, '3.7.6', '>='); + } + return $ready; +} + +/** The Quick tickets settings - as saved, or the built-in ones. */ +function quickTicketSettings() { + global $mysqli; + static $settings = null; + if ($settings !== null) { + return $settings; + } + $row = []; + if (quickTicketReady()) { + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_quick_ticket_on, config_quick_ticket_assign, config_quick_ticket_status, config_quick_ticket_priority, + config_quick_ticket_category, config_quick_ticket_billable, config_quick_ticket_timer, config_quick_ticket_primary, config_quick_ticket_open_tickets, + config_quick_ticket_email_client FROM settings WHERE company_id = 1")) ?: []; + } + $priority = (string) ($row['config_quick_ticket_priority'] ?? 'Medium'); + $timer = (string) ($row['config_quick_ticket_timer'] ?? 'make'); + $settings = [ + 'on' => intval($row['config_quick_ticket_on'] ?? 1) === 1, + // 'me' - the agent making it, 'nobody', or an agent's id + 'assign' => (string) ($row['config_quick_ticket_assign'] ?? 'me'), + // 0 - New, or Open once someone has it; else one an agent can pick (ticketPickableStatuses()) + 'status' => intval($row['config_quick_ticket_status'] ?? 0), + 'priority' => in_array($priority, ['Low', 'Medium', 'High', 'Urgent'], true) ? $priority : 'Medium', + 'category' => intval($row['config_quick_ticket_category'] ?? 0), + // -1 - as Time and billing says a new ticket starts; else 1 or 0 + 'billable' => in_array(intval($row['config_quick_ticket_billable'] ?? -1), [0, 1], true) ? intval($row['config_quick_ticket_billable']) : -1, + 'timer' => isset(QUICK_TICKET_TIMER[$timer]) ? $timer : 'make', + 'primary' => intval($row['config_quick_ticket_primary'] ?? 1) === 1, + 'open_tickets' => intval($row['config_quick_ticket_open_tickets'] ?? 1) === 1, + 'email_client' => intval($row['config_quick_ticket_email_client'] ?? 1) === 1, + ]; + return $settings; +} + +/** Whether the signed-in agent gets the button - ticketing on, Support edit (as New Ticket), and Quick tickets on. */ +function quickTicketCan() { + global $config_module_enable_ticketing, $session_user_id; + return !empty($session_user_id) && !empty($config_module_enable_ticketing) && lookupUserPermission('module_support') >= 2 && quickTicketSettings()['on']; +} + +/** Who a quick ticket goes to, from the setting - 0 for nobody. */ +function quickTicketAssignee() { + global $session_user_id; + $assign = quickTicketSettings()['assign']; + if ($assign === 'me') { + return intval($session_user_id); + } + return $assign === 'nobody' ? 0 : ticketAgentId(intval($assign)); +} + +/** Whether a quick ticket starts billable - the setting, else what a new ticket starts as. */ +function quickTicketBillable() { + global $config_ticket_default_billable; + $billable = quickTicketSettings()['billable']; + return $billable === -1 ? intval($config_ticket_default_billable) === 1 : $billable === 1; +} + +/** What the window's "More detail" box says, as a ticket's details keep it - HTML, its lines kept. */ +function quickTicketDetailsHtml($text) { + $text = trim(str_replace("\r\n", "\n", mb_substr((string) $text, 0, 20000))); + return $text === '' ? '' : '

' . nl2br(escapeHtml($text), false) . '

'; +} + +/* + * After add_ticket made a quick ticket: a line in its history, and when its + * timer counts from - kept for the ticket page's first load. $start is the + * browser's clock in milliseconds. + */ +function quickTicketAfterCreate($ticket_id, $start) { + global $session_name; + $ticket_id = intval($ticket_id); + logTicketHistory($ticket_id, "$session_name raised it with Quick ticket"); + $start = (string) $start; + if (quickTicketSettings()['timer'] !== 'off' && preg_match('/^\d{12,14}$/', $start)) { + $_SESSION['quick_ticket_timer'][$ticket_id] = $start; + } +} + +/* + * The ticket page's first load after a quick ticket - the timer started from + * when the window said, before agent/js/ticket_time_tracking.js reads it. + * Only a timer that isn't there yet. '' when there's none to start. + */ +function quickTicketTimerScript($ticket_id) { + $ticket_id = intval($ticket_id); + $start = (string) ($_SESSION['quick_ticket_timer'][$ticket_id] ?? ''); + if ($start === '') { + return ''; + } + unset($_SESSION['quick_ticket_timer'][$ticket_id]); + return ''; +} + +/** The agents a quick ticket can go to, for the setting - 'me', 'nobody' and each agent by id. */ +function quickTicketAssignChoices() { + global $mysqli; + $choices = ['me' => 'The agent making it', 'nobody' => 'Nobody']; + $sql = mysqli_query($mysqli, "SELECT user_id, user_name FROM users WHERE user_type = 1 AND user_status = 1 AND user_archived_at IS NULL ORDER BY user_name ASC"); + while ($row = mysqli_fetch_assoc($sql)) { + $choices[(string) intval($row['user_id'])] = (string) $row['user_name']; + } + return $choices; +} + +/** Whether a quick ticket starts billable, for the setting. */ +const QUICK_TICKET_BILLABLE = [-1 => 'As a new ticket starts - Time and billing, above', 1 => 'Billable', 0 => 'Not billable']; + +/** The statuses a quick ticket can start in, for the setting. */ +function quickTicketStatusChoices() { + $choices = [0 => 'New, or Open once someone has it']; + foreach (ticketPickableStatuses() as $status_id => $status) { + $choices[$status_id] = $status['ticket_status_name']; + } + return $choices; +} diff --git a/functions/settings.php b/functions/settings.php index c92dc13ce..19b695a6a 100644 --- a/functions/settings.php +++ b/functions/settings.php @@ -156,6 +156,20 @@ function settingsFields() { 'config_ticket_sms_parse' => ['page' => 'ticket', 'section' => 'Text to ticket', 'label' => 'Turn texts into tickets', 'words' => 'text sms message mobile phone skyetel to ticket'] + $on_off, 'config_ticket_sms_unknown_senders' => ['page' => 'ticket', 'section' => 'Text to ticket', 'label' => 'From unknown numbers too', 'words' => 'text sms unknown numbers anyone'] + $on_off, 'config_ticket_sms_acknowledge' => ['page' => 'ticket', 'section' => 'Text to ticket', 'label' => 'Text back the ticket number', 'words' => 'text sms acknowledge reply confirm number'] + $on_off, + 'config_quick_ticket_on' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Show the Quick ticket button', 'words' => 'quick ticket top bar plus call walk-up button'] + $on_off, + 'config_quick_ticket_assign' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Quick ticket goes to', 'kind' => 'select', 'options' => 'quick_ticket_assign', + 'words' => 'quick ticket assign agent technician'], + 'config_quick_ticket_status' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Quick ticket starts in', 'kind' => 'select', 'options' => 'quick_ticket_status', + 'words' => 'quick ticket status'], + 'config_quick_ticket_priority' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Quick ticket priority', 'words' => 'quick ticket priority'], + 'config_quick_ticket_category' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Quick ticket category', 'kind' => 'category', 'words' => 'quick ticket category'], + 'config_quick_ticket_billable' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Quick ticket billing', 'kind' => 'select', 'options' => 'quick_ticket_billable', + 'words' => 'quick ticket billable bill'], + 'config_quick_ticket_timer' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Start a quick ticket\'s timer', 'kind' => 'select', 'options' => 'quick_ticket_timer', + 'words' => 'quick ticket timer time tracking call'], + 'config_quick_ticket_primary' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Start on the client\'s primary contact', 'words' => 'quick ticket primary contact'] + $on_off, + 'config_quick_ticket_open_tickets' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Show the contact\'s open tickets', 'words' => 'quick ticket open tickets duplicate'] + $on_off, + 'config_quick_ticket_email_client' => ['page' => 'ticket', 'section' => 'Quick tickets', 'label' => 'Email the contact that it was opened', 'words' => 'quick ticket email contact created'] + $on_off, 'config_ticket_default_billable' => ['page' => 'ticket', 'section' => 'Time and billing', 'label' => 'New tickets are billable', 'words' => 'billable default bill'] + $on_off, 'config_ticket_timer_autostart' => ['page' => 'ticket', 'section' => 'Time and billing', 'label' => 'Start the timer on opening a ticket', 'words' => 'timer autostart time tracking'] + $on_off, 'config_ticket_autoclose_hours' => ['page' => 'ticket', 'section' => 'Closing', 'label' => 'Close resolved tickets after', 'words' => 'auto close autoclose resolved hours'], @@ -662,6 +676,14 @@ function settingsLogValue($name, $value) { $options = settingsMailEncryption(); } elseif ($options === 'ai_triage') { $options = [0 => 'off', 1 => 'suggest', 2 => 'fill in']; + } elseif ($options === 'quick_ticket_assign') { + $options = quickTicketAssignChoices(); + } elseif ($options === 'quick_ticket_status') { + $options = quickTicketStatusChoices(); + } elseif ($options === 'quick_ticket_billable') { + $options = QUICK_TICKET_BILLABLE; + } elseif ($options === 'quick_ticket_timer') { + $options = QUICK_TICKET_TIMER; } elseif (is_string($options)) { $options = settingsLocalizationArrays()[$options] ?? []; } diff --git a/includes/footer.php b/includes/footer.php index 76f14a18a..d655e6fa4 100644 --- a/includes/footer.php +++ b/includes/footer.php @@ -98,6 +98,7 @@ try { + diff --git a/includes/top_nav.php b/includes/top_nav.php index 5f90b1c21..372763f14 100644 --- a/includes/top_nav.php +++ b/includes/top_nav.php @@ -37,6 +37,35 @@ + + + + + + + + + +