From 96eec95fb8bdd2e81c31269cbdb7ad658ae0815a Mon Sep 17 00:00:00 2001 From: johnnyq Date: Tue, 17 Nov 2026 17:52:35 -0500 Subject: [PATCH] Ticket statuses: When the client replies can move a ticket to another status, a Client responded one say, on the built-in statuses as well as your own, falling back to Open when that status is switched off and cleared when it is deleted; a status can count as the first response when an agent moves a ticket nobody has answered into it, quietly or after emailing the contact and watchers a ticket assigned message kept as a public note, counted only when someone got it; the message is set under Messages to clients in Settings Tickets with the canned response placeholders; database 3.7.3 adds ticket_status_reply_status_id, ticket_status_first_response and config_ticket_assigned_message; 26.11.9 changelog entries --- CHANGELOG.md | 5 +- admin/database_updates/3.7.3.php | 37 ++++ .../ticket_status/ticket_status_form.php | 51 ++++- admin/post/settings_ticket.php | 12 +- admin/post/ticket_status.php | 4 +- admin/settings_ticket.php | 12 ++ admin/ticket_statuses.php | 13 +- agent/post/texts.php | 2 + agent/post/ticket.php | 10 + api/v1/ticket_replies/create.php | 2 + db.sql | 3 + functions/settings.php | 2 + functions/ticket.php | 8 + functions/ticket_fields.php | 3 + functions/ticket_status.php | 186 ++++++++++++++++-- 15 files changed, 317 insertions(+), 33 deletions(-) create mode 100644 admin/database_updates/3.7.3.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 14716a7a7..c2e53bcc1 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 six database changes (3.6.6 to 3.7.2) 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, and a column and a table for agent banners, 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 seven database changes (3.6.6 to 3.7.3) 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, and two columns for ticket statuses with a setting for the "ticket assigned" message, 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 @@ -79,6 +79,8 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Tickets: checking off a task, or marking it not done, no longer reloads the page and sends you back to the top - the list, the count and the Resolve button update where you are, so you can work down a long list. The "Completed Task" note shows in the conversation the next time the page loads. - Banners: a note your team sees along the top of their pages - for one client, such as "On credit hold - no work without approval", or for every client. A client's shows on its pages, and on its tickets, invoices, quotes, recurring invoices and projects however they're opened. Anyone who can edit a client adds one from New Banner in the client's ⋮ menu, which lists its banners below to change, archive or delete. Admins add them for every client, and see them all, in Admin > Agent Banners. Each is a Notice, Heads up or Urgent, and shows between its start and end like a portal announcement. Anyone can hide a Notice or Heads up until it's changed; an Urgent one is big and red, first on the page, and can't be hidden. Clients never see banners. - New Ticket: pick the Status a ticket starts in, and book the work as you make it - a date and time, remote or onsite, under Schedule. The booking goes out as it does from the ticket's Schedule window: the assigned agent, the contact and the watchers are emailed the time with a calendar invite, and it is noted on the ticket. Left as it is, a ticket still starts as New, or Open once it is assigned. From Mountaineer IT's build of ITFlow. +- Ticket Statuses: When the client replies can move a ticket to another status - a "Client responded" status, say, so the tickets with a new answer from the client stand out. It can be set on New, Open, On Hold and Resolved as well as your own statuses, for replies by email, in the portal or by text; back to Open is still the default. From Mountaineer IT's build of ITFlow. +- 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. ### Bug Fixes @@ -189,6 +191,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - `includes/filter_header.php` takes `page` as at least 1, and a custom range with `dtf` and no `dtt` as ending `2099-12-31`, as All time does. `admin/modules.php` sorts only on `module_name` or `module_description`. `index.php` sends a session with `client_logged_in` to `/client/` before checking `logged`, which the portal sign-in sets too. `agent/custom/post.php` no longer requires `post/ai.php`, and it and `agent/user/post.php` read `HTTP_REFERER ?? ''`. `api/v1/validate_api_key.php` takes a body that doesn't decode to an array as `[]`, and clamps `limit` to at least 1 and `offset` to at least 0 - with no upper limit, unlike Mountaineer IT's 1000. `clients/delete` removes `uploads/clients/` from `__DIR__`. From Mountaineer IT's build of ITFlow. - The cron dispatcher records a `CronJobStopped` with a code other than 0 (`cronJobStop($message, 1)`) as `Failed`, with its message as `cron_job_last_error` ("Stopped with an error - see App Logs" when it has none), and logs it to App Logs. `persistMailOauthTokens()` (`cron/mail_queue.php`) also sets the run's globals. `cron/update_check.php` keeps the newest 100 `pending_commits`, each subject cut to 300 characters, fewer if the JSON is still over 60,000 bytes; `updateCheckDetails()` adds `commits`, the full count, which `admin/update.php` shows. `scripts/restore_cli.php` reads the time zone only from a settings row that is there, and `backupCurrentDatabaseVersion()` answers `Unknown` when there is no settings table. Contact anonymizing redacts the stored values, longest first; the client duplicate check escapes `%` and `_`; the asset transfer log uses `$asset_name`. From Mountaineer IT's build of ITFlow. - `add_ticket` (`agent/post/ticket.php`) takes `status`, one of `ticketPickableStatuses()` (else New, or Open when assigned, as before), into the INSERT, so `applyTicketSla()` starts the SLA clock paused for a status that pauses it. `schedule` and `onsite` are booked with `ticketSetSchedule()` after the ticket's own emails; a `schedule` that `ticketScheduleValue()` can't read turns the form away before anything is saved. From Mountaineer IT's build of ITFlow. +- 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. ## [26.11.8] diff --git a/admin/database_updates/3.7.3.php b/admin/database_updates/3.7.3.php new file mode 100644 index 000000000..5d60e115c --- /dev/null +++ b/admin/database_updates/3.7.3.php @@ -0,0 +1,37 @@ + Settings > Tickets; + * NULL is the built-in wording. + * + * 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; + }; + + if (!$itflow_column('ticket_statuses', 'ticket_status_reply_status_id')) { + mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_reply_status_id` int(11) NOT NULL DEFAULT 0 AFTER `ticket_status_client_reply`"); + } + + if (!$itflow_column('ticket_statuses', 'ticket_status_first_response')) { + mysqli_query($mysqli, "ALTER TABLE `ticket_statuses` ADD `ticket_status_first_response` tinyint(1) NOT NULL DEFAULT 0 AFTER `ticket_status_reply_status_id`"); + } + + if (!$itflow_column('settings', 'config_ticket_assigned_message')) { + mysqli_query($mysqli, "ALTER TABLE `settings` ADD `config_ticket_assigned_message` text DEFAULT NULL AFTER `config_ticket_timer_autostart`"); + } diff --git a/admin/modals/ticket_status/ticket_status_form.php b/admin/modals/ticket_status/ticket_status_form.php index 895e17d6f..1a5b43701 100644 --- a/admin/modals/ticket_status/ticket_status_form.php +++ b/admin/modals/ticket_status/ticket_status_form.php @@ -3,8 +3,9 @@ /* * A ticket status's fields - for ticket_status_add.php and * ticket_status_edit.php, which set $ticket_status (a ticketStatusRow(), or - * null when new). A built-in status keeps its name and has fixed answers for - * the SLA clock and a client's reply - shown, not asked. The preview of its + * null when new). A built-in status keeps its name and has a fixed answer for + * the SLA clock - shown, not asked; a client's reply moves a ticket in one + * back to Open or to a status picked, and Closed takes none. The preview of its * badge and the colour swatches are js/ticket_status_form.js. The server * checks it all again (ticketStatusFromInput(), ticketStatusProblem()). */ @@ -19,6 +20,19 @@ $s_color = $s ? ticketStatusColor($s['ticket_status_color']) : ticketStatusNextC $s_description = (string) ($s['ticket_status_description'] ?? ''); $s_paused = $s ? intval($s['ticket_status_pauses_sla']) === 1 : false; $s_reply = $s ? (intval($s['ticket_status_client_reply'] ?? 1) === 0 ? 0 : 1) : 1; +$s_reply_to = intval($s['ticket_status_reply_status_id'] ?? 0); +$s_first_response = intval($s['ticket_status_first_response'] ?? 0); +// What a client's reply can do - back to Open (in the words that fit), stay (your own), or move to another status +$s_reply_choices = ['1' => [TICKET_STATUS_NEW => 'Open it', TICKET_STATUS_OPEN => 'It stays Open', TICKET_STATUS_RESOLVED => 'Reopen it - back to Open'][$s_id] ?? 'Move it back to Open']; +if (!$s_builtin) { + $s_reply_choices['0'] = 'Leave it in this status'; +} +foreach (ticketStatusReplyReady() ? ticketStatusReplyTargets($s_id) : [] as $target_id => $target) { + if ($target_id !== TICKET_STATUS_OPEN) { + $s_reply_choices["to-$target_id"] = 'Move it to ' . $target['ticket_status_name']; + } +} +$s_reply_value = $s_reply_to && isset($s_reply_choices["to-$s_reply_to"]) ? "to-$s_reply_to" : (string) ($s_builtin ? 1 : $s_reply); ?> @@ -85,28 +99,45 @@ $s_reply = $s ? (intval($s['ticket_status_client_reply'] ?? 1) === 0 ? 0 : 1) : -
+
- + - + $label) { ?> +
- - Fixed for ITFlow's own statuses. + + A closed ticket takes no replies. - By email or in the portal. Back to Open suits a status that waits on the client; leave it for one like Scheduled, where a "thanks, see you then" shouldn't put it back in the queue. Whoever it is assigned to is told either way. + By email, in the portal or by text. Move it to a status such as "Client responded" to see at a glance which tickets have a new answer; back to Open suits a status that waits on the client. Whoever it is assigned to is told either way.
+ + +
+ +
+ + +
+ + An agent moving a ticket into this status before anyone has answered the client meets - or misses - the SLA's response target then: setting it by hand or in a reply, or assigning a new ticket, which moves it to Open. Once per ticket. With the email, the contact and watchers get the "ticket assigned" message from Settings > Tickets, kept on the ticket as a public note; if nobody could be emailed, it doesn't count. + +
+
diff --git a/admin/post/settings_ticket.php b/admin/post/settings_ticket.php index 71f75986a..249a56b0d 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, closing and the - * tickets page. A next + * new ticket and whether AI triages it, 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 @@ -21,7 +21,8 @@ if (isset($_POST['edit_ticket_settings'])) { $before = settingsCurrent(array_merge(['config_ticket_prefix', 'config_ticket_next_number', 'config_ticket_email_parse', 'config_ticket_email_parse_unknown_senders', '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'] : [])); + settingsColumnExists($mysqli, 'config_ticket_sms_parse') ? ['config_ticket_sms_parse', 'config_ticket_sms_unknown_senders', 'config_ticket_sms_acknowledge'] : [], + ticketStatusReplyReady() ? ['config_ticket_assigned_message'] : [])); // 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); @@ -47,6 +48,11 @@ if (isset($_POST['edit_ticket_settings'])) { if ($config_module_enable_accounting) { $after['config_ticket_default_billable'] = empty($_POST['config_ticket_default_billable']) ? 0 : 1; } + // The "ticket assigned" message - the built-in wording sent back as it is, or nothing, is kept as none, so it follows that wording + if (array_key_exists('config_ticket_assigned_message', $before) && isset($_POST['config_ticket_assigned_message'])) { + $message = mb_substr(trim(str_replace("\r\n", "\n", (string) $_POST['config_ticket_assigned_message'])), 0, 5000); + $after['config_ticket_assigned_message'] = $message === '' || $message === TICKET_ASSIGNED_MESSAGE ? null : $message; + } if ($problem = settingsEmailProblem($after['config_ticket_new_ticket_notification_email'])) { $errors['config_ticket_new_ticket_notification_email'] = $problem; diff --git a/admin/post/ticket_status.php b/admin/post/ticket_status.php index 725325540..603782d73 100644 --- a/admin/post/ticket_status.php +++ b/admin/post/ticket_status.php @@ -4,8 +4,8 @@ * ITFlow - Admin > Ticket Statuses: add and change a status, put them in * order (dragged, or up and down), switch one off or on, and delete one of * your own - moving its tickets first. The five ITFlow has keep their names, - * stay on, and have fixed SLA and client-reply behaviour, whatever a request - * says. The work is in functions/ticket_status.php. + * stay on, have fixed SLA behaviour, and a client's reply never leaves a + * ticket in one, whatever a request says. The work is in functions/ticket_status.php. */ defined('FROM_POST_HANDLER') || die("Direct file access is not allowed"); diff --git a/admin/settings_ticket.php b/admin/settings_ticket.php index 9f1576ccb..4272f1c79 100644 --- a/admin/settings_ticket.php +++ b/admin/settings_ticket.php @@ -69,6 +69,18 @@ echo settingsPageStart('ticket'); + Ticket Statuses) + $assigned_sent_by = array_column(array_filter(ticketStatusesAll(), function ($status) { + return intval($status['ticket_status_first_response']) === 2 && intval($status['ticket_status_active']) === 1; + }), 'ticket_status_name'); ?> + [Ticket], [Subject], [Contact], [First Name], [Client], [Agent], [Ticket Link], [Date] and the others canned responses take. The email greets each person by name, so the message needn\'t.', 'messages') ?> + 5, 'maxlength' => 5000, + 'help' => 'Emailed to the contact and watchers when an agent moves a ticket nobody has answered yet into a status that counts as the first response by emailing the client - set in Ticket Statuses. It is kept on the ticket as a public note. [Agent] is who it is assigned to. ' + . ($assigned_sent_by ? 'Sent on moving into ' . escapeHtml(implode(', ', $assigned_sent_by)) . '.' : 'No status sends it yet.')]) ?> + + + 'fa-clock', 'type' => 'number', 'min' => 24, 'max' => 8760, 'required' => true, 'suffix' => 'hours', 'help' => 'From when it was last changed. 72 is three days.']) ?> diff --git a/admin/ticket_statuses.php b/admin/ticket_statuses.php index 7a372aa1b..a02e7d14b 100644 --- a/admin/ticket_statuses.php +++ b/admin/ticket_statuses.php @@ -126,9 +126,15 @@ $csrf = $_SESSION['csrf_token']; $clock_html = $ticket_status_id === TICKET_STATUS_CLOSED ? 'Stopped' : ($paused ? 'Paused' : 'Runs'); + // Moved to another status by a reply, while that one is in use (ticketStatusAfterClientReply()) + $reply_to = intval($row['ticket_status_reply_status_id'] ?? 0); + $reply_to_row = $reply_to && $ticket_status_id !== TICKET_STATUS_CLOSED ? (ticketStatusReplyTargets($ticket_status_id)[$reply_to] ?? null) : null; $reply_html = $ticket_status_id === TICKET_STATUS_CLOSED ? 'Can\'t reply' - : '' . ([TICKET_STATUS_NEW => 'Opens it', TICKET_STATUS_OPEN => 'Stays Open', TICKET_STATUS_RESOLVED => 'Reopens it'][$ticket_status_id] ?? $reply['short']) . ''; + : ($reply_to_row + ? 'To ' . ticketStatusBadgeHtml($reply_to_row['ticket_status_name'], $reply_to_row['ticket_status_color']) . '' + : '' . ([TICKET_STATUS_NEW => 'Opens it', TICKET_STATUS_OPEN => 'Stays Open', TICKET_STATUS_RESOLVED => 'Reopens it'][$ticket_status_id] ?? $reply['short']) . ''); + $first_response = TICKET_STATUS_FIRST_RESPONSE[intval($row['ticket_status_first_response'] ?? 0)] ?? TICKET_STATUS_FIRST_RESPONSE[0]; ?> @@ -147,6 +153,9 @@ $csrf = $_SESSION['csrf_token'];
+ +
+
@@ -163,7 +172,7 @@ $csrf = $_SESSION['csrf_token']; - +