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

This commit is contained in:
johnnyq
2026-11-17 17:52:35 -05:00
parent 0cc24e286e
commit 96eec95fb8
15 changed files with 317 additions and 33 deletions

View File

@@ -0,0 +1,37 @@
<?php
/*
* ITFlow - Database update to version 3.7.3 (from 3.7.2)
* Included by admin/database_updates.php - do not access directly
*
* Ticket statuses (functions/ticket_status.php):
* ticket_statuses.ticket_status_reply_status_id - the status a client's reply moves a ticket in
* this status to (a "Client responded" status, say); 0 does what ticket_status_client_reply says.
* ticket_statuses.ticket_status_first_response - an agent moving a ticket into this status before
* anyone has answered counts as its first response: 0 no, 1 yes, 2 yes once the client has been
* emailed the "ticket assigned" message.
* settings.config_ticket_assigned_message - that message, as typed in Admin > 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`");
}

View File

@@ -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) :
</small>
</div>
<div class="mb-1">
<div class="<?= $s_id && !ticketStatusCanBeFirstResponse($s_id) ? 'mb-1' : 'mb-3' ?>">
<label class="form-label">When the client replies</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-reply"></i></span>
<?php if ($s_builtin) { ?>
<?php if ($s_id === TICKET_STATUS_CLOSED || ($s_builtin && !ticketStatusReplyReady())) { ?>
<input type="text" class="form-control" value="<?= [TICKET_STATUS_OPEN => 'It stays Open', TICKET_STATUS_RESOLVED => 'It is reopened - back to Open', TICKET_STATUS_CLOSED => 'They can\'t - they are told to raise a new ticket'][$s_id] ?? 'It moves back to Open' ?>" readonly>
<?php } else { ?>
<select class="form-select" name="client_reply">
<?php foreach (TICKET_STATUS_CLIENT_REPLY as $value => $reply) { ?>
<option value="<?= $value ?>"<?= $value === $s_reply ? ' selected' : '' ?>><?= escapeHtml($reply['label']) ?></option>
<select class="form-select select2" name="client_reply">
<?php foreach ($s_reply_choices as $value => $label) { ?>
<option value="<?= escapeHtml($value) ?>"<?= (string) $value === $s_reply_value ? ' selected' : '' ?>><?= escapeHtml($label) ?></option>
<?php } ?>
</select>
<?php } ?>
</div>
<small class="text-secondary">
<?php if ($s_builtin) { ?>
<i class="fas fa-fw fa-lock me-1"></i>Fixed for ITFlow's own statuses.
<?php if ($s_id === TICKET_STATUS_CLOSED) { ?>
<i class="fas fa-fw fa-lock me-1"></i>A closed ticket takes no replies.
<?php } else { ?>
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<?= $s_builtin ? '' : '; 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.
<?php } ?>
</small>
</div>
<?php if (ticketStatusReplyReady() && (!$s_id || ticketStatusCanBeFirstResponse($s_id))) { ?>
<div class="mb-1">
<label class="form-label">Counts as the first response</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-comment-dots"></i></span>
<select class="form-select" name="first_response">
<?php foreach (TICKET_STATUS_FIRST_RESPONSE as $value => $first_response) { ?>
<option value="<?= $value ?>"<?= $value === $s_first_response ? ' selected' : '' ?>><?= escapeHtml($first_response['label']) ?></option>
<?php } ?>
</select>
</div>
<small class="text-secondary">
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 <a href="settings_ticket.php#messages">Settings &gt; Tickets</a>, kept on the ticket as a public note; if nobody could be emailed, it doesn't count.
</small>
</div>
<?php } ?>
</div>
<script src="<?= staticFileUrl('/js/ticket_status_form.js') ?>"></script>

View File

@@ -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;

View File

@@ -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");

View File

@@ -69,6 +69,18 @@ echo settingsPageStart('ticket');
<?php } ?>
<?= settingsSectionEnd() ?>
<?php if (ticketStatusReplyReady()) {
// The statuses that send it now (Admin > 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'); ?>
<?= settingsSectionStart('messages', 'Messages to clients', 'Sent for you as a ticket moves along. Words in square brackets are filled in from the ticket - <code>[Ticket]</code>, <code>[Subject]</code>, <code>[Contact]</code>, <code>[First Name]</code>, <code>[Client]</code>, <code>[Agent]</code>, <code>[Ticket Link]</code>, <code>[Date]</code> and the others canned responses take. The email greets each person by name, so the message needn\'t.', 'messages') ?>
<?= settingsTextarea('config_ticket_assigned_message', ticketAssignedMessage(), ['rows' => 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 <a href="ticket_statuses.php">Ticket Statuses</a>. It is kept on the ticket as a public note. <code>[Agent]</code> is who it is assigned to. '
. ($assigned_sent_by ? 'Sent on moving into <strong>' . escapeHtml(implode(', ', $assigned_sent_by)) . '</strong>.' : 'No status sends it yet.')]) ?>
<?= settingsSectionEnd() ?>
<?php } ?>
<?= settingsSectionStart('closing', 'Closing', 'A resolved ticket waits for the client to say it isn\'t, then closes by itself, each night.') ?>
<?= settingsInput('config_ticket_autoclose_hours', intval($config_ticket_autoclose_hours), ['icon' => 'fa-clock', 'type' => 'number', 'min' => 24, 'max' => 8760, 'required' => true,
'suffix' => 'hours', 'help' => 'From when it was last changed. 72 is three days.']) ?>

View File

@@ -126,9 +126,15 @@ $csrf = $_SESSION['csrf_token'];
$clock_html = $ticket_status_id === TICKET_STATUS_CLOSED
? '<span class="text-body-secondary">Stopped</span>'
: ($paused ? '<span class="text-warning-emphasis"><i class="fas fa-fw fa-pause-circle me-1"></i>Paused</span>' : '<span class="text-body-secondary"><i class="fas fa-fw fa-play-circle me-1"></i>Runs</span>');
// 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
? '<span class="text-body-secondary" title="A closed ticket can\'t be replied to - the client is told to raise a new one">Can\'t reply</span>'
: '<span class="text-body-secondary"><i class="fas fa-fw ' . $reply['icon'] . ' me-1"></i>' . ([TICKET_STATUS_NEW => 'Opens it', TICKET_STATUS_OPEN => 'Stays Open', TICKET_STATUS_RESOLVED => 'Reopens it'][$ticket_status_id] ?? $reply['short']) . '</span>';
: ($reply_to_row
? '<span class="text-body-secondary"><i class="fas fa-fw fa-share me-1"></i>To ' . ticketStatusBadgeHtml($reply_to_row['ticket_status_name'], $reply_to_row['ticket_status_color']) . '</span>'
: '<span class="text-body-secondary"><i class="fas fa-fw ' . $reply['icon'] . ' me-1"></i>' . ([TICKET_STATUS_NEW => 'Opens it', TICKET_STATUS_OPEN => 'Stays Open', TICKET_STATUS_RESOLVED => 'Reopens it'][$ticket_status_id] ?? $reply['short']) . '</span>');
$first_response = TICKET_STATUS_FIRST_RESPONSE[intval($row['ticket_status_first_response'] ?? 0)] ?? TICKET_STATUS_FIRST_RESPONSE[0];
?>
<tr data-ticket-status-id="<?= $ticket_status_id ?>">
<?php if ($can_reorder) { ?>
@@ -147,6 +153,9 @@ $csrf = $_SESSION['csrf_token'];
<?php if ($about !== '') { ?>
<div class="small text-body-secondary mt-1"><?= escapeHtml($about) ?></div>
<?php } ?>
<?php if ($first_response['short'] !== '') { ?>
<div class="small text-success-emphasis mt-1" title="An agent moving a ticket into it before anyone has answered meets the SLA's response target"><i class="fas fa-fw fa-comment-dots me-1"></i><?= escapeHtml($first_response['short']) ?></div>
<?php } ?>
<!-- On smaller screens the clock and replies come along under the name -->
<div class="d-lg-none mt-1 small d-flex flex-wrap gap-3">
<span class="d-md-none"><?= $clock_html ?></span>
@@ -163,7 +172,7 @@ $csrf = $_SESSION['csrf_token'];
<?php } ?>
</td>
<td class="d-none d-md-table-cell text-nowrap"><?= $clock_html . $fixed ?></td>
<td class="d-none d-lg-table-cell text-nowrap"><?= $reply_html . $fixed ?></td>
<td class="d-none d-lg-table-cell text-nowrap"><?= $reply_html . ($ticket_status_id === TICKET_STATUS_CLOSED ? $fixed : '') ?></td>
<td class="text-end">
<div class="dropdown dropstart">
<button class="btn btn-sm btn-light" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-fw fa-ellipsis-v"></i></button>