mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +00:00
Reply type after posting and the reply box on return: a reply's Edit or Change Type offers Internal note, Public note and Email reply, which makes it public and emails it on Save and Email to the To line from its writer by name with their signature and files while the ticket is open, mail is set up, the contact has an address and it hasn't been emailed, counting a newly client-visible note as the first response and giving an unassigned ticket to its writer with a history line; drafts keep their reply type (DB 4.4.0) and coming back to a ticket with a draft or a timer that was already running opens the reply box on the draft's type or the last type picked there, else Internal note, without moving the page (ticketReplyFiles()); 26.12.4 changelog
This commit is contained in:
@@ -6,7 +6,7 @@ This file documents all notable changes made to ITFlow.
|
||||
|
||||
### Upgrading to 26.12.4
|
||||
|
||||
Update from Maintenance > Update as usual. This release has two database changes: 4.3.8, which lets ITFlow remind clients before their autopay card expires - a setting for it, and on each saved card when it was last checked with Stripe, which reminders went out and the key in their link - and 4.3.9, which adds the table that keeps email routing rules.
|
||||
Update from Maintenance > Update as usual. This release has three database changes: 4.3.8, which lets ITFlow remind clients before their autopay card expires - a setting for it, and on each saved card when it was last checked with Stripe, which reminders went out and the key in their link - 4.3.9, which adds the table that keeps email routing rules, and 4.4.0, which keeps the reply type with an unsent reply.
|
||||
|
||||
### New Features & Updates
|
||||
|
||||
@@ -17,6 +17,8 @@ Update from Maintenance > Update as usual. This release has two database changes
|
||||
- Email routing rules, in Admin > Email Routing: pick an address or a domain - alerts@vendor.example, or vendor.example - and, if you like, words its subject has, and say where its new tickets go: a client and a contact, a category, a priority, an agent and a ticket template. A vendor's monitoring alerts about one client go to that client at High priority and land with the technician who looks after them, with the template's tasks already on the ticket. A rule decides the client over the sender's own contact or domain, and takes email even with tickets from unknown senders off. What it leaves as it is comes from its template. When more than one rule fits, the most exact wins - an address before a domain, a subdomain before its domain, and a rule with subject words before one without. Replies to a ticket still go on that ticket, Ignored Senders are still set aside first, and out-of-office replies are never routed. The sender is only answered and copied in when they are the ticket's contact, so a system's address isn't sent "we have your email" or every reply, and nobody at the client is emailed about an alert they didn't send. The agent a rule assigns is told, as when a ticket is assigned by hand. Each rule shows how many tickets it has routed and when the last was, and warns when it takes another client's contacts or domain, when Ignored Senders sets its email aside first, or when its client, contact, category, agent or template has been archived. Try an Email in Settings > Tickets shows which rule an email would meet and what it would do, and Email to ticket links to the page.
|
||||
- An agent's email to a client now comes from them by name: "Tess Tech | PittPC Support", at the ticket mailbox's address, so the client sees who wrote and their reply still goes on the ticket. That's their email replies, resolving a ticket with a note, closing one for no response, and the "your ticket is with" note. ITFlow's automatic emails - we have your email, closed, a booked visit - and emails to your team keep the mailbox's name. Admin > Mail > From addresses shows how it reads.
|
||||
- Try an Email in Settings > Tickets now asks the very questions the mailbox asks, in the same order, from the same code - so what it shows is what happens to the email. An out-of-office is now checked where the mailbox checks it, after the ticket number.
|
||||
- Change who sees a reply after it's posted: a reply's ⋮ has Edit or Change Type, with Internal note, Public note and Email reply. Email reply makes it public and emails it when you click Save and Email - to the people in its To line, from whoever wrote it by name, with their signature and its files - as the reply box would. It's offered while the ticket isn't closed, mail is set up and the contact has an email address, until the reply has been emailed. A note the client can see now counts as the first response, and a ticket nobody had becomes its writer's, as with a reply from the reply box. The ticket's history says who changed it, and how.
|
||||
- Coming back to a ticket with a reply on the go opens the reply box for you. An unsent reply - kept as a draft as you type - opens on the type you picked for it (internal note, public note, email or text) with your words in it. A ticket whose timer is still running opens on the type you picked last there in this browser, or Internal note. A timer that only started as you opened the ticket leaves the box shut, and the page isn't moved down to it.
|
||||
|
||||
### Bug Fixes
|
||||
|
||||
@@ -38,6 +40,8 @@ Update from Maintenance > Update as usual. This release has two database changes
|
||||
- Email routing rules (DB 4.3.9, `email_routing_rules`): new `functions/mail_route.php`. A rule is `routing_rule_match` (an address or a domain, cleaned by `mailIgnoreClean()` and matched by `mailIgnoreMatches()`, so a domain takes its subdomains), optional `routing_rule_subject` (case-insensitive, whitespace-collapsed substring), and what it sets: `routing_rule_client_id`, `routing_rule_contact_id`, `routing_rule_category_id`, `routing_rule_priority`, `routing_rule_assigned_to`, `routing_rule_ticket_template_id` - 0 or '' for none - with a note, a hit count and `routing_rule_matched_at`. `mailRouteFind()` takes the most exact match (`mailRouteExactness()`: address, then more domain labels, then longer subject words, then the older rule); `mailRouteFor()` adds `mailRouteTargets()`, which re-checks each target (client and contact not archived and the contact the client's, category, active agent, template not archived) and lists what's `gone`. In `cron/ticket_email_parser.php` the rule is found after the thread, ticket-number and forward steps and never for an out-of-office; with a client it replaces `$picked`/`$domain_row`, its contact is the rule's, else the sender as that client's contact, and a client with no contact gets its own `addTicket()` call before the domain step. `$email['route']` carries the rule, with `quiet` when the sender isn't the ticket's contact (or a website form's visitor, or a new contact at a client's domain), and `$email['sender']` when the ticket's contact isn't the sender. `addTicket()` now sets priority, category, agent and billable from `mailRouteTicketFields()` (the rule's, else the template's), Open when assigned, logs the rule in the ticket history, runs `ticketTemplateFinish(..., true, true)` for the template, notifies and emails the assignee (`ticketMailAssigned()`), and when `quiet` skips the sender CC, the created email and `ticketMailColleaguesNew()`; the from line, audit, forged note and copied-CC exclusion use the sender. A quiet email is never a similar-subject reply (`linkSimilarTicket($new, $similar, 'route')`, whose third argument is now the reason - 'forward' or 'route'), step 6 runs for a routed email whatever `config_ticket_email_parse_unknown_senders` says, and the hit is counted only when a ticket was made. Admin page `admin/email_routing_rules.php` (standard list, search across sender, words, client, contact, category, agent, template and note), modal `admin/modals/email_routing_rule/email_routing_rule.php` (its contact list reloads from `agent/ajax.php?get_client_contacts`), handlers `admin/post/email_routing_rule.php` (`add_routing_rule`, `edit_routing_rule`, `delete_routing_rule`; `mailRouteReach()` for the other-clients warning). `ticketMailTry()` adds an "An email routing rule?" step and `ticketMailTryRoute()` for the outcome.
|
||||
- Agent's name in the From name: `ticketEmailFrom($agent_name = '')` in `functions/ticket.php` now takes the agent's name and gives `ticketEmailFromName($agent_name, $mailbox_name)` - "Agent | Mailbox", the agent alone when the mailbox has no name or the same one, the mailbox's name unchanged without an agent; line breaks, quotes and angle brackets are removed, HTML entities decoded, and it is cut to 255. `ticketMailSend()` reads the agent from its `ticket_reply_id` (`ticketReplyAgentName()`: a Public reply whose `ticket_reply_by` is a `user_type` 1 user) or a new `agent_name` option, which `ticketMailReply()` passes from `$by` when there is no reply id (the email previews). So the reply, `ticketMailResolved()` with a note, `ticketResolveNoResponse()` and the first-response "assigned" note in `ticketStatusMovedByAgent()` carry it; the created, closed, scheduled and client-reply-relay emails and `ticketMailAgents()` don't. No database change.
|
||||
- Where an email goes is decided in one place: `ticketMailDecide(array $in)` in new `functions/ticket_mail_decide.php`, used by `cron/ticket_email_parser.php` and `ticketMailTry()`. It takes raw facts - `from`, `from_name`, `subject`, `visitor` (a website form's Reply-To), `thread_ticket_id` (null when it can't be known), `automatic`, `forged`, `answers_ours` (null when unknown), `unprocessed`, `forward` - and runs steps 1-6 (thread, ticket number, the agent who may be forwarding, the routing rule, the sender's contact or domain, the out-of-office set-aside, similar subject, contact, routed client, client domain, unknown senders), returning `steps` ([question, answer], what Try an Email shows) and an `action` - `reply` (`ticket_id`, `by`), `ticket` (`client_id`, `client_name`, `contact`, `new_contact`, `picked`, `sender`, `similar`, `link_why`, `taken`), `set_aside` or `leave` (`why`, `not_ours`, `answers_unknown`) - with `agent`, `route` and `quiet`. The parser keeps its first checks (own address, bounce, ignored sender, Reply-To, duplicate Message-ID, Unprocessed Email asks), then carries the decision out; when `agent` is set it reads the forward and calls `ticketMailDecide()` again with `forward`, which skips steps 1-2 as before. `ticketMailTry()` keeps its own first checks and turns the decision into an outcome with `ticketMailTryOutcome()`. Changes in behaviour: the similar-subject check compares raw subjects and the CC lookup escapes the sender once (it was escaped twice, missing an address with an apostrophe), an out-of-office that isn't set aside is left in the inbox rather than going on to the similar-subject step, and a reply whose ticket vanished between the lookup and `addReply()` waits in Unprocessed Email instead of becoming a new ticket.
|
||||
- Reply type after posting: `agent/modals/ticket/ticket_reply_edit.php` offers `Email` beside `Internal` and `Public` (while the ticket isn't closed, `config_smtp_provider` is set, the contact has an email address and `ticket_reply_emailed` isn't 1), with the ticket's To line (`ticketReplyRecipients()`). `edit_ticket_reply` saves it Public, appends the writer's `user_config_signature`, emails it with `ticketMailReply()` (from the writer by name via its `ticket_reply_id`, the To line by `ticketReplyRecipientsPick()`, its files by new `ticketReplyFiles()` in `functions/ticket_mail_thread.php`, which the client-reply relay now uses too) and `smsTicketReplyNotify()`. A reply that becomes Public, or is emailed, sets the first response when there is none and, with `ticketReplyAssigns()`, assigns an unassigned ticket to its writer (the editing agent when the writer isn't an active agent). The history line names the change. Refused emails say why: closed, emailed already, no mail, no contact email.
|
||||
- Reply drafts keep their type (DB 4.4.0, `ticket_reply_drafts.draft_type`, NULL for older drafts): `ticketReplyDraftSave($ticket_id, $user_id, $html, $type = null)`, `ticketReplyDraft()` returns `type`, `agent/ajax.php?ticket_reply_draft` takes `type`, and `agent/js/ticket_reply_extras.js` sends the picked `public_reply_type` with each save (and beacon), saving again when the type changes with words in the box. `agent/ticket.php` puts `data-draft-type` on the reply form; as the page is drawn the composer opens (the `show` class, no focus or scroll) on the draft's type, or - when `localStorage[ticketId + '-startTime']` was there before the timer script ran - on `localStorage['ticket-reply-type-' + ticketId]`, kept as a type is picked and cleared on Cancel and on sending, else Internal note; a type that can't be used now (email with no contact address, an opted-out text) falls back to Internal note. The reply menu item reads Edit or Change Type.
|
||||
|
||||
## [26.12.3]
|
||||
|
||||
|
||||
20
admin/database_updates/4.4.0.php
Normal file
20
admin/database_updates/4.4.0.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* ITFlow - Database update to version 4.4.0 (from 4.3.9)
|
||||
* Included by admin/database_updates.php - do not access directly
|
||||
*
|
||||
* ticket_reply_drafts.draft_type - how an agent's unsent reply was to go: 0 internal note, 1 public note, 2 email
|
||||
* reply, 3 text reply (the reply box's public_reply_type). The ticket page opens the reply box on it when the agent
|
||||
* comes back (functions/ticket_reply_draft.php). NULL for a draft kept before this update - opened as an internal note.
|
||||
*
|
||||
* Re-runnable: the column is made only where it isn't there.
|
||||
*/
|
||||
|
||||
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
|
||||
|
||||
$itflow_draft_type = mysqli_query($mysqli, "SELECT 1 FROM information_schema.COLUMNS
|
||||
WHERE TABLE_SCHEMA = DATABASE() AND TABLE_NAME = 'ticket_reply_drafts' AND COLUMN_NAME = 'draft_type' LIMIT 1");
|
||||
if (!$itflow_draft_type || mysqli_num_rows($itflow_draft_type) === 0) {
|
||||
mysqli_query($mysqli, "ALTER TABLE `ticket_reply_drafts` ADD `draft_type` tinyint(1) DEFAULT NULL AFTER `draft_body`");
|
||||
}
|
||||
@@ -1574,7 +1574,7 @@ if (isset($_GET['kb_picker']) || isset($_GET['kb_article_reply'])) {
|
||||
|
||||
/*
|
||||
* The reply an agent is writing on a ticket, kept as they type (agent/js/ticket_reply_extras.js;
|
||||
* functions/ticket_reply_draft.php). POST ticket_id and html - empty drops it; answers whether one
|
||||
* functions/ticket_reply_draft.php). POST ticket_id, html - empty drops it - and type, how it was to go; answers whether one
|
||||
* is kept now, and the time on the agent's clock.
|
||||
*/
|
||||
if (isset($_POST['ticket_reply_draft'])) {
|
||||
@@ -1592,7 +1592,7 @@ if (isset($_POST['ticket_reply_draft'])) {
|
||||
echo json_encode(['ok' => false]);
|
||||
exit;
|
||||
}
|
||||
ticketReplyDraftSave($draft_ticket['ticket_id'], $session_user_id, (string) ($_POST['html'] ?? ''));
|
||||
ticketReplyDraftSave($draft_ticket['ticket_id'], $session_user_id, (string) ($_POST['html'] ?? ''), $_POST['type'] ?? null);
|
||||
$kept = ticketReplyDraft($draft_ticket['ticket_id'], $session_user_id) !== null;
|
||||
echo json_encode(['ok' => true, 'kept' => $kept, 'time' => date('g:i A', strtotime(timezoneToView(date('Y-m-d H:i:s'))))]);
|
||||
exit;
|
||||
|
||||
@@ -2,9 +2,9 @@
|
||||
* The ticket page's reply form (agent/ticket.php):
|
||||
*
|
||||
* - Drafts. What is typed is kept as it is written (agent/ajax.php ticket_reply_draft ->
|
||||
* functions/ticket_reply_draft.php) - a moment after typing stops, and as the page is left - and
|
||||
* the page puts it back in the reply box next time. Discard it drops it. Sending drops it too,
|
||||
* on the server.
|
||||
* functions/ticket_reply_draft.php) - a moment after typing stops, and as the page is left - with how
|
||||
* it was to go (the reply type picked), and the page puts it back in the reply box next time, open
|
||||
* on that type. Discard it drops it. Sending drops it too, on the server.
|
||||
* - Files dropped on the reply box go in its Attach files field.
|
||||
* - +15m, +30m and +1h add to Time worked. The timer stops at the new total, as it does when the
|
||||
* time is typed.
|
||||
@@ -56,8 +56,15 @@
|
||||
var drafts = form.dataset.drafts === '1';
|
||||
var saveTimer = null;
|
||||
var lastSaved = null;
|
||||
var lastType = null;
|
||||
var sending = false;
|
||||
|
||||
// How it is to go - the reply type picked, '' while none is
|
||||
function replyType() {
|
||||
var picked = form.querySelector('input[name="public_reply_type"]:checked');
|
||||
return picked ? picked.value : '';
|
||||
}
|
||||
|
||||
function setStatus(text) {
|
||||
if (status) {
|
||||
status.textContent = text;
|
||||
@@ -67,11 +74,13 @@
|
||||
function saveDraft() {
|
||||
saveTimer = null;
|
||||
var html = content();
|
||||
if (sending || lastSaved === null || html === lastSaved) {
|
||||
var type = replyType();
|
||||
if (sending || lastSaved === null || (html === lastSaved && type === lastType)) {
|
||||
return;
|
||||
}
|
||||
itflowPost('ajax.php', { ticket_reply_draft: 1, csrf_token: csrf, ticket_id: ticketId, html: html }, function (answer) {
|
||||
itflowPost('ajax.php', { ticket_reply_draft: 1, csrf_token: csrf, ticket_id: ticketId, html: html, type: type }, function (answer) {
|
||||
lastSaved = html;
|
||||
lastType = type;
|
||||
var ed = editor();
|
||||
if (ed && content() === html) {
|
||||
ed.setDirty(false);
|
||||
@@ -100,6 +109,7 @@
|
||||
var ed = editor();
|
||||
if (ed) {
|
||||
lastSaved = ed.getContent();
|
||||
lastType = replyType();
|
||||
// SetContent is a canned response or an AI rewrite going in
|
||||
ed.on('input change keyup SetContent Undo Redo', queueSave);
|
||||
return true;
|
||||
@@ -123,6 +133,7 @@
|
||||
var textarea = document.getElementById('ticket_reply');
|
||||
if (textarea) {
|
||||
lastSaved = textarea.value;
|
||||
lastType = replyType();
|
||||
textarea.addEventListener('input', queueSave);
|
||||
}
|
||||
return;
|
||||
@@ -136,7 +147,7 @@
|
||||
return;
|
||||
}
|
||||
var html = content();
|
||||
if (html === lastSaved) {
|
||||
if (html === lastSaved && replyType() === lastType) {
|
||||
return;
|
||||
}
|
||||
var data = new FormData();
|
||||
@@ -144,6 +155,7 @@
|
||||
data.append('csrf_token', csrf);
|
||||
data.append('ticket_id', ticketId);
|
||||
data.append('html', html);
|
||||
data.append('type', replyType());
|
||||
// As a file, past a web application firewall (js/http.js)
|
||||
if (window.itflowFields) {
|
||||
window.itflowFields.pack(data, ['html']);
|
||||
@@ -151,6 +163,15 @@
|
||||
navigator.sendBeacon('ajax.php', data);
|
||||
});
|
||||
|
||||
// Another type picked, with something written - kept with the draft, so it opens on it next time
|
||||
form.querySelectorAll('input[name="public_reply_type"]').forEach(function (radio) {
|
||||
radio.addEventListener('change', function () {
|
||||
if (hasWords()) {
|
||||
queueSave();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
var discard = form.querySelector('[data-reply-draft-discard]');
|
||||
if (discard) {
|
||||
discard.addEventListener('click', function (e) {
|
||||
|
||||
@@ -1,15 +1,23 @@
|
||||
<?php
|
||||
|
||||
/*
|
||||
* Edit Reply - an agent's reply or note on a ticket: its words, its time, and who sees it. Internal note, public note -
|
||||
* or email reply, which makes it public and emails it now to the people in To, as the reply box would (with its
|
||||
* writer's signature, from them by name, its files with it). Email reply is there while the ticket isn't closed, mail is
|
||||
* set up and the reply hasn't been emailed yet. Saved by edit_ticket_reply (agent/post/ticket.php).
|
||||
*/
|
||||
|
||||
require_once '../../../includes/modal_header.php';
|
||||
|
||||
enforceUserPermission('module_support', 2);
|
||||
|
||||
$ticket_reply_id = intval($_GET['id']);
|
||||
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_client_id, ticket_reply, ticket_reply_time_worked, ticket_reply_type, ticket_reply_created_at,
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_client_id, ticket_closed_at, ticket_reply, ticket_reply_time_worked, ticket_reply_type, ticket_reply_created_at, ticket_reply_by, user_name AS reply_by_name,
|
||||
" . (ticketWorkTimesReady() ? 'ticket_reply_work_start, ticket_reply_work_end,' : 'NULL AS ticket_reply_work_start, NULL AS ticket_reply_work_end,') . "
|
||||
" . (ticketReplyEmailReady() ? 'ticket_reply_emailed, ticket_reply_emailed_to' : 'NULL AS ticket_reply_emailed, NULL AS ticket_reply_emailed_to') . " FROM ticket_replies
|
||||
LEFT JOIN tickets ON ticket_id = ticket_reply_ticket_id
|
||||
LEFT JOIN users ON user_id = ticket_reply_by AND user_type = 1
|
||||
WHERE ticket_reply_id = $ticket_reply_id
|
||||
LIMIT 1"
|
||||
);
|
||||
@@ -29,6 +37,14 @@ if ($client_id) {
|
||||
enforceClientAccess();
|
||||
}
|
||||
|
||||
// Emailing it from here - as the reply box can: mail set up and a contact with an email address - not on a closed ticket,
|
||||
// nor a second time
|
||||
$contact_email = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_email FROM tickets JOIN contacts ON contact_id = ticket_contact_id WHERE ticket_id = " . intval($row['ticket_id'])))[0] ?? '');
|
||||
$can_email = $row['ticket_reply_type'] !== 'Client' && empty($row['ticket_closed_at']) && intval($row['ticket_reply_emailed']) !== 1
|
||||
&& $contact_email !== '' && !empty($config_smtp_provider);
|
||||
$reply_to = $can_email && ticketReplyRecipientsReady() ? ticketReplyRecipients(intval($row['ticket_id'])) : [];
|
||||
$writer = $row['reply_by_name'] !== null ? (string) $row['reply_by_name'] : '';
|
||||
|
||||
// Who it was emailed to - they have it as it was sent
|
||||
$emailed_to = '';
|
||||
if (intval($row['ticket_reply_emailed']) === 1) {
|
||||
@@ -54,16 +70,41 @@ ob_start();
|
||||
|
||||
<div class="modal-body">
|
||||
|
||||
<div class="mb-3">
|
||||
<div class="btn-group w-100" role="group">
|
||||
<div class="mb-3" data-reply-edit-types>
|
||||
<div class="btn-group w-100" role="group" aria-label="Who sees it">
|
||||
<input class="btn-check" id="ticket_reply_type_opt0" type="radio" name="ticket_reply_type" value="Internal" <?php if ($ticket_reply_type == 'Internal') { echo "checked"; } ?>>
|
||||
<label class="btn btn-outline-secondary" for="ticket_reply_type_opt0"><i class="fas fa-fw fa-lock me-1"></i>Internal note</label>
|
||||
<label class="btn btn-outline-dark" for="ticket_reply_type_opt0"><i class="fas fa-fw fa-lock me-1"></i>Internal note</label>
|
||||
<input class="btn-check" id="ticket_reply_type_opt1" type="radio" name="ticket_reply_type" value="Public" <?php if ($ticket_reply_type == 'Public') { echo "checked"; } ?>>
|
||||
<label class="btn btn-outline-secondary" for="ticket_reply_type_opt1"><i class="fas fa-fw fa-eye me-1"></i>Public</label>
|
||||
<label class="btn btn-outline-info" for="ticket_reply_type_opt1"><i class="fas fa-fw fa-eye me-1"></i>Public note</label>
|
||||
<?php if ($can_email) { ?>
|
||||
<input class="btn-check" id="ticket_reply_type_opt2" type="radio" name="ticket_reply_type" value="Email">
|
||||
<label class="btn btn-outline-info" for="ticket_reply_type_opt2"><i class="fas fa-fw fa-paper-plane me-1"></i>Email reply</label>
|
||||
<?php } ?>
|
||||
</div>
|
||||
<div class="form-text">Public replies show in the client portal. Saving here never sends an email.</div>
|
||||
<div class="form-text" data-reply-edit-says="Internal"<?= $ticket_reply_type == 'Internal' ? '' : ' hidden' ?>><i class="fas fa-fw fa-lock me-1"></i>Only your team can see this.</div>
|
||||
<div class="form-text" data-reply-edit-says="Public"<?= $ticket_reply_type == 'Public' ? '' : ' hidden' ?>><i class="fas fa-fw fa-eye me-1"></i>The client can see this in the portal. <strong>No email is sent.</strong></div>
|
||||
<?php if ($can_email) { ?>
|
||||
<div class="form-text" data-reply-edit-says="Email" hidden>
|
||||
<i class="fas fa-fw fa-paper-plane me-1"></i>Saving emails it now to the people in To, and it shows in the portal - from <?= $writer !== '' ? escapeHtml($writer) . ' by name, with their signature' : 'the ticket mailbox' ?>, and its files with it.
|
||||
</div>
|
||||
<?php } ?>
|
||||
</div>
|
||||
|
||||
<?php if ($can_email && $reply_to) { ?>
|
||||
<!-- Who it is emailed to - the ticket's To line, as the reply box has it (functions/ticket_reply_recipients.php) -->
|
||||
<div class="mb-3" data-reply-edit-to hidden>
|
||||
<input type="hidden" name="email_to_shown" value="1" disabled>
|
||||
<div class="input-group">
|
||||
<span class="input-group-text"><i class="fas fa-fw fa-envelope me-1"></i>To</span>
|
||||
<select class="form-select select2" name="email_to[]" multiple data-tags="true" data-avatar="initials" data-placeholder="Type a name or an email address" aria-label="Email it to">
|
||||
<?php foreach ($reply_to as $reply_to_email => $reply_to_person) { ?>
|
||||
<option value="<?= escapeHtml($reply_to_email) ?>"<?= $reply_to_person['send'] ? ' selected' : '' ?><?= $reply_to_person['look'] ?><?= selectOptionData(['description' => TICKET_REPLY_TO_GROUPS[$reply_to_person['group']] . ($reply_to_person['name'] !== '' ? " - $reply_to_email" : ''), 'keywords' => $reply_to_email]) ?>><?= escapeHtml($reply_to_person['name'] !== '' ? $reply_to_person['name'] : $reply_to_email) ?></option>
|
||||
<?php } ?>
|
||||
</select>
|
||||
</div>
|
||||
</div>
|
||||
<?php } ?>
|
||||
|
||||
<?php if ($emailed_to !== '') { ?>
|
||||
<div class="alert alert-info small py-2" data-reply-edit-emailed>
|
||||
<i class="fas fa-fw fa-paper-plane me-1"></i>This was emailed to <strong><?= escapeHtml($emailed_to) ?></strong>. They keep the email as it was sent - what you change here only changes the ticket<?= $ticket_reply_type == 'Public' ? ' and the portal' : '' ?>.
|
||||
@@ -115,11 +156,42 @@ ob_start();
|
||||
|
||||
</div>
|
||||
<div class="modal-footer">
|
||||
<button type="submit" name="edit_ticket_reply" class="btn btn-primary fw-bold"><i class="fas fa-check me-2"></i>Save</button>
|
||||
<button type="submit" name="edit_ticket_reply" class="btn btn-primary fw-bold" data-reply-edit-save><i class="fas fa-check me-2"></i><span>Save</span></button>
|
||||
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fas fa-times me-2"></i>Cancel</button>
|
||||
</div>
|
||||
</form>
|
||||
|
||||
<script>
|
||||
(function () {
|
||||
// What the picked type means, the To line for an email, and the button saying what it does
|
||||
const box = document.querySelector('.modal.show [data-reply-edit-types]') || document.querySelector('[data-reply-edit-types]');
|
||||
if (!box) {
|
||||
return;
|
||||
}
|
||||
const form = box.closest('form');
|
||||
const to = form.querySelector('[data-reply-edit-to]');
|
||||
const save = form.querySelector('[data-reply-edit-save] span');
|
||||
function show() {
|
||||
const picked = form.querySelector('input[name="ticket_reply_type"]:checked');
|
||||
const type = picked ? picked.value : '';
|
||||
form.querySelectorAll('[data-reply-edit-says]').forEach(function (line) {
|
||||
line.hidden = line.dataset.replyEditSays !== type;
|
||||
});
|
||||
if (to) {
|
||||
to.hidden = type !== 'Email';
|
||||
to.querySelector('[name="email_to_shown"]').disabled = type !== 'Email';
|
||||
}
|
||||
if (save) {
|
||||
save.textContent = type === 'Email' ? 'Save and Email' : 'Save';
|
||||
}
|
||||
}
|
||||
form.querySelectorAll('input[name="ticket_reply_type"]').forEach(function (radio) {
|
||||
radio.addEventListener('change', show);
|
||||
});
|
||||
show();
|
||||
})();
|
||||
</script>
|
||||
|
||||
<?php
|
||||
|
||||
require_once '../../../includes/modal_footer.php';
|
||||
|
||||
@@ -1379,10 +1379,42 @@ if (isset($_POST['edit_ticket_reply'])) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
// Public or internal - anything else keeps what it was
|
||||
$ticket_reply_type = in_array($_POST['ticket_reply_type'] ?? '', ['Public', 'Internal'], true) ? $_POST['ticket_reply_type'] : $reply['ticket_reply_type'];
|
||||
// Internal or public - or Email: public, and emailed now as the reply box would (ticket_reply_edit.php). Anything else
|
||||
// keeps what it was
|
||||
$ticket_id = intval($row['ticket_id']);
|
||||
$picked_type = (string) ($_POST['ticket_reply_type'] ?? '');
|
||||
$send_email = $picked_type === 'Email';
|
||||
$ticket_reply_type = $send_email ? 'Public' : (in_array($picked_type, ['Public', 'Internal'], true) ? $picked_type : $reply['ticket_reply_type']);
|
||||
$was_type = (string) $reply['ticket_reply_type'];
|
||||
|
||||
// Who wrote it - the email is from them by name, with their signature - and whether it went by email before
|
||||
$written = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_reply_by, user_name, user_status, user_archived_at" . (ticketReplyEmailReady() ? ', ticket_reply_emailed' : ', 0 AS ticket_reply_emailed') . "
|
||||
FROM ticket_replies LEFT JOIN users ON user_id = ticket_reply_by AND user_type = 1 WHERE ticket_reply_id = $ticket_reply_id"));
|
||||
$writer_id = $written['user_name'] !== null ? intval($written['ticket_reply_by']) : 0;
|
||||
$writer_name = $written['user_name'] !== null ? (string) $written['user_name'] : stripslashes((string) $session_name);
|
||||
|
||||
// Emailed only as the reply box can: not on a closed ticket, not a second time, with mail set up and a contact to email
|
||||
$email_refused = '';
|
||||
if ($send_email) {
|
||||
$contact_email = (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT contact_email FROM contacts WHERE contact_id = " . intval($row['ticket_contact_id'])))[0] ?? '');
|
||||
if (!empty($row['ticket_closed_at'])) {
|
||||
$email_refused = 'the ticket is closed';
|
||||
} elseif (intval($written['ticket_reply_emailed']) === 1) {
|
||||
$email_refused = 'it was emailed already';
|
||||
} elseif (empty($config_smtp_provider)) {
|
||||
$email_refused = 'mail isn\'t set up';
|
||||
} elseif ($contact_email === '') {
|
||||
$email_refused = 'the ticket has no contact with an email address';
|
||||
}
|
||||
$send_email = $email_refused === '';
|
||||
}
|
||||
|
||||
// Its @mentions put right - made public, it mentions nobody
|
||||
[$ticket_reply_html, $mentioned] = ticketMentionsFromHtml((string) ($_POST['ticket_reply'] ?? ''), $row['ticket_client_id'], $ticket_reply_type === 'Internal');
|
||||
// Emailed, it ends with its writer's signature, as one sent from the reply box does
|
||||
if ($send_email && trim($ticket_reply_html) !== '') {
|
||||
$ticket_reply_html .= (string) getFieldById('user_settings', $writer_id ?: intval($session_user_id), 'user_config_signature');
|
||||
}
|
||||
$ticket_reply = mysqli_real_escape_string($mysqli, $ticket_reply_html);
|
||||
$ticket_reply_time_worked = escapeSql(ticketTimeWorked($_POST['time'] ?? ''));
|
||||
|
||||
@@ -1427,9 +1459,61 @@ if (isset($_POST['edit_ticket_reply'])) {
|
||||
logTicketHistory(intval($row['ticket_id']), "$session_name mentioned " . escapeSql(ticketMentionNames($told)) . " in an internal note");
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Reply", "$session_name edited a reply on ticket " . escapeSql(ticketReference($row)), $client_id, intval($row['ticket_id']));
|
||||
// Emailed now - to the people in To, from its writer by name, with its files - and a text saying so, when Texts to clients
|
||||
// says each reply (functions/sms.php)
|
||||
$emailed_to = 0;
|
||||
$email_to = null;
|
||||
$files_skipped = [];
|
||||
if ($send_email) {
|
||||
if (!empty($_POST['email_to_shown']) && ticketReplyRecipientsReady()) {
|
||||
$email_to = ticketReplyRecipientsPick($ticket_id, (array) ($_POST['email_to'] ?? []));
|
||||
}
|
||||
$files = filterEmailableAttachments(ticketReplyFiles($ticket_id, $ticket_reply_id));
|
||||
$files_skipped = $files['skipped'];
|
||||
$emailed_to = ticketMailReply($ticket_id, (string) getFieldById('ticket_replies', $ticket_reply_id, 'ticket_reply'), $writer_name, false, $files['send'], $ticket_reply_id, $email_to);
|
||||
if ($emailed_to) {
|
||||
smsTicketReplyNotify($row);
|
||||
}
|
||||
}
|
||||
|
||||
flashAlert("Reply saved" . ($told ? " - <strong>" . escapeHtml(ticketMentionNames($told)) . "</strong> " . (count($told) === 1 ? 'was' : 'were') . " told" : ''));
|
||||
// The client sees it now - as a reply from the reply box: the ticket's first response, and its writer's when nobody had it
|
||||
$taken = false;
|
||||
if ($ticket_reply_type === 'Public' && ($was_type !== 'Public' || $emailed_to)) {
|
||||
if (empty($row['ticket_first_response_at'])) {
|
||||
setTicketFirstResponse($ticket_id);
|
||||
}
|
||||
if (!intval($row['ticket_assigned_to']) && ticketReplyAssigns()) {
|
||||
$assign_to = $writer_id && intval($written['user_status']) === 1 && $written['user_archived_at'] === null ? $writer_id : intval($session_user_id);
|
||||
[$taken] = ticketChangeAssignee($ticket_id, $assign_to);
|
||||
}
|
||||
}
|
||||
|
||||
// Its history says who changed who sees it
|
||||
$whose = $writer_id && $writer_id === intval($session_user_id) ? 'their' : escapeSql($writer_name) . "'s";
|
||||
$kind_words = ['Internal' => 'internal note', 'Public' => 'public note'];
|
||||
if ($emailed_to) {
|
||||
logTicketHistory($ticket_id, "$session_name " . ($was_type === 'Internal' ? "made $whose internal note public and emailed it" : "emailed $whose public note") . " to $emailed_to " . ($emailed_to === 1 ? 'person' : 'people'));
|
||||
} elseif ($ticket_reply_type !== $was_type && isset($kind_words[$was_type])) {
|
||||
logTicketHistory($ticket_id, "$session_name made $whose " . $kind_words[$was_type] . ' ' . ($ticket_reply_type === 'Public' ? 'public' : 'internal'));
|
||||
}
|
||||
|
||||
logAudit("Ticket", "Reply", "$session_name edited a reply on ticket " . escapeSql(ticketReference($row)) . ($emailed_to ? " and emailed it to $emailed_to" : ''), $client_id, intval($row['ticket_id']));
|
||||
|
||||
$told_words = $told ? " - <strong>" . escapeHtml(ticketMentionNames($told)) . "</strong> " . (count($told) === 1 ? 'was' : 'were') . " told" : '';
|
||||
// Files too big for the email stay on the ticket - said with the rest, not in place of it
|
||||
$skipped_words = $files_skipped ? ' - too large to email, so only on the ticket: <strong>' . implode(', ', array_map(function ($file) {
|
||||
return escapeHtml($file['name']);
|
||||
}, $files_skipped)) . '</strong>' : '';
|
||||
$taken_words = $taken ? ' - the ticket is now assigned to ' . escapeHtml($writer_id && $assign_to === $writer_id ? $writer_name : 'you') : '';
|
||||
if ($email_refused !== '') {
|
||||
flashAlert("Reply saved and made public, but not emailed - $email_refused" . $taken_words, 'warning');
|
||||
} elseif ($picked_type === 'Email' && !$emailed_to) {
|
||||
flashAlert("Reply saved and made public, but not emailed - " . (!emailReady() ? 'mail isn\'t set up' : ($email_to === [] ? 'nobody was in To' : 'there\'s no contact or CC with an email address to send it to')) . $taken_words, 'warning');
|
||||
} elseif ($emailed_to) {
|
||||
flashAlert("Reply saved and emailed to <strong>$emailed_to</strong> " . ($emailed_to === 1 ? 'person' : 'people') . $taken_words . $told_words . $skipped_words, $skipped_words !== '' ? 'warning' : 'success');
|
||||
} else {
|
||||
flashAlert("Reply saved" . ($ticket_reply_type !== $was_type ? ($ticket_reply_type === 'Public' ? ' - the client can see it now, not emailed' : ' - only your team can see it now') : '') . $taken_words . $told_words);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -864,7 +864,7 @@ if (isset($_GET['ticket_id'])) {
|
||||
|
||||
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off" id="ticketReplyForm"
|
||||
data-billable="<?= $config_module_enable_accounting && $ticket_billable ? 1 : 0 ?>" data-drafts="<?= ticketReplyDraftsReady() ? 1 : 0 ?>"
|
||||
data-undo-seconds="<?= ticketReplySendReady() ? ticketReplyUndoSeconds() : 0 ?>">
|
||||
data-undo-seconds="<?= ticketReplySendReady() ? ticketReplyUndoSeconds() : 0 ?>"<?= $reply_draft ? ' data-draft-type="' . intval($reply_draft['type'] ?? 0) . '"' : '' ?>>
|
||||
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
|
||||
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
|
||||
|
||||
@@ -901,7 +901,7 @@ if (isset($_GET['ticket_id'])) {
|
||||
|
||||
<?php if ($reply_draft) { ?>
|
||||
<div class="small text-body-secondary mt-2" data-reply-draft-note>
|
||||
<i class="fas fa-fw fa-pen me-1"></i>Your unsent reply from <span title="<?= escapeHtml(timezoneToView($reply_draft['updated_at'])) ?>"><?= escapeHtml(timeAgo($reply_draft['updated_at'])) ?></span> is kept - pick how to send it to carry on, or <a href="#" data-reply-draft-discard>discard it</a>.
|
||||
<i class="fas fa-fw fa-pen me-1"></i>Your unsent reply from <span title="<?= escapeHtml(timezoneToView($reply_draft['updated_at'])) ?>"><?= escapeHtml(timeAgo($reply_draft['updated_at'])) ?></span> is kept below - carry on with it, or <a href="#" data-reply-draft-discard>discard it</a>.
|
||||
</div>
|
||||
<?php } ?>
|
||||
<!-- Files dropped on the reply box before a type is picked (agent/js/ticket_reply_extras.js) -->
|
||||
@@ -1224,7 +1224,7 @@ if (isset($_GET['ticket_id'])) {
|
||||
<?php if ($ticket_reply_type !== "Client" && !$ticket_is_closed) { ?>
|
||||
<a href="#" class="dropdown-item ajax-modal" data-modal-size="lg"
|
||||
data-modal-url="modals/ticket/ticket_reply_edit.php?id=<?= $ticket_reply_id ?>">
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit
|
||||
<i class="fas fa-fw fa-edit me-2"></i>Edit or Change Type
|
||||
</a>
|
||||
<?php } ?>
|
||||
<?php if ($ticket_reply_type === "Client" && !$ticket_is_closed) { ?>
|
||||
@@ -2381,9 +2381,23 @@ if (isset($ticket_is_open) && empty($ticket_closed_at)) { ?>
|
||||
});
|
||||
}
|
||||
|
||||
// The type picked last on this ticket, in this browser - for coming back to it while its timer runs
|
||||
const replyTicketId = <?= intval($ticket_id) ?>;
|
||||
const replyTypeKey = 'ticket-reply-type-' + replyTicketId;
|
||||
function rememberReplyType(type) {
|
||||
try {
|
||||
if (type === null) {
|
||||
localStorage.removeItem(replyTypeKey);
|
||||
} else {
|
||||
localStorage.setItem(replyTypeKey, type);
|
||||
}
|
||||
} catch (e) {}
|
||||
}
|
||||
|
||||
// Only ever opens. Switching Internal -> Public mid-draft must not throw the draft away.
|
||||
replyTypes.forEach(radio => radio.addEventListener('change', () => {
|
||||
showReplyType(radio.value);
|
||||
rememberReplyType(radio.value);
|
||||
replyComposerCollapse.show();
|
||||
}));
|
||||
|
||||
@@ -2401,11 +2415,40 @@ if (isset($ticket_is_open) && empty($ticket_closed_at)) { ?>
|
||||
}
|
||||
});
|
||||
|
||||
/*
|
||||
* Back on a ticket with a reply on the go - an unsent reply kept as a draft, or its timer running from before this
|
||||
* page (not one that only started now, with Start the timer on opening a ticket): the reply box is open, on the
|
||||
* type it was - the draft's, else the one picked last here - and an internal note when neither is known or that
|
||||
* type can't be used now. Opened as the page is drawn, without moving the page to it or taking the focus.
|
||||
*/
|
||||
const replyFormEl = replyComposer.closest('form');
|
||||
let replyTimerRunning = false;
|
||||
let replyTypeRemembered = null;
|
||||
try {
|
||||
replyTimerRunning = !!localStorage.getItem(replyTicketId + '-startTime');
|
||||
replyTypeRemembered = localStorage.getItem(replyTypeKey);
|
||||
} catch (e) {}
|
||||
const replyDraftType = replyFormEl && replyFormEl.dataset.draftType !== undefined ? replyFormEl.dataset.draftType : null;
|
||||
const replyOpenOn = replyDraftType !== null ? replyDraftType : (replyTimerRunning ? (replyTypeRemembered || '0') : null);
|
||||
if (replyOpenOn !== null) {
|
||||
let radio = document.querySelector('input[name="public_reply_type"][value="' + CSS.escape(replyOpenOn) + '"]');
|
||||
if (!radio || radio.disabled) {
|
||||
radio = document.getElementById('public_reply_type_opt0');
|
||||
}
|
||||
if (radio) {
|
||||
radio.checked = true;
|
||||
showReplyType(radio.value);
|
||||
replyComposer.classList.add('show');
|
||||
replyComposer.dataset.openedOnReturn = replyDraftType !== null ? 'draft' : 'timer';
|
||||
}
|
||||
}
|
||||
|
||||
const cancelReply = document.getElementById('cancelReply');
|
||||
if (cancelReply) {
|
||||
cancelReply.addEventListener('click', function () {
|
||||
replyComposerCollapse.hide();
|
||||
replyTypes.forEach(radio => { radio.checked = false; });
|
||||
rememberReplyType(null);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -2426,7 +2469,10 @@ if (isset($ticket_is_open) && empty($ticket_closed_at)) { ?>
|
||||
replyToProblem.textContent = problem;
|
||||
replyToProblem.hidden = false;
|
||||
replyTo.scrollIntoView({ block: 'nearest' });
|
||||
return;
|
||||
}
|
||||
// On its way - the next visit starts from nothing picked, not this type
|
||||
rememberReplyType(null);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
1
db.sql
1
db.sql
@@ -5118,6 +5118,7 @@ CREATE TABLE `ticket_reply_drafts` (
|
||||
`ticket_id` int(11) NOT NULL,
|
||||
`user_id` int(11) NOT NULL,
|
||||
`draft_body` longtext NOT NULL,
|
||||
`draft_type` tinyint(1) DEFAULT NULL,
|
||||
`draft_updated_at` datetime NOT NULL DEFAULT current_timestamp(),
|
||||
PRIMARY KEY (`ticket_id`,`user_id`),
|
||||
KEY `draft_updated_at` (`draft_updated_at`)
|
||||
|
||||
@@ -424,16 +424,7 @@ function ticketMailRelayClientReply($ticket_id, $reply_id, $by, $author_email, a
|
||||
return 0;
|
||||
}
|
||||
// Its files, as an agent's reply sends them - not the email itself, kept beside it
|
||||
$attachments = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_attachment_name, ticket_attachment_reference_name FROM ticket_attachments
|
||||
WHERE ticket_attachment_reply_id = $reply_id AND ticket_attachment_ticket_id = " . intval($ticket_id) . " AND ticket_attachment_name <> 'Original-parsed-email.eml'"
|
||||
. (ticketPicturesReady() ? ' AND ticket_attachment_inline = 0' : ''));
|
||||
while ($file = mysqli_fetch_assoc($sql)) {
|
||||
$path = 'uploads/tickets/' . intval($ticket_id) . '/' . basename((string) $file['ticket_attachment_reference_name']);
|
||||
if (is_file(dirname(__DIR__) . '/' . $path)) {
|
||||
$attachments[] = ['path' => $path, 'name' => (string) $file['ticket_attachment_name'], 'size' => filesize(dirname(__DIR__) . '/' . $path)];
|
||||
}
|
||||
}
|
||||
$attachments = ticketReplyFiles($ticket_id, $reply_id);
|
||||
// What they wrote - without the "Email from: ... :-" line the email parser puts on what it saves
|
||||
$message = (string) preg_replace('#^\s*<i>\s*Email from:.*?</i>(\s*<br\s*/?>)*#is', '', (string) $reply['ticket_reply']);
|
||||
return ticketMailSend($ticket_id, ticketEmailContent($row, 'client_reply', ['message' => $message, 'skip' => (string) $reply['ticket_reply'], 'by' => (string) $by]), [
|
||||
@@ -443,3 +434,22 @@ function ticketMailRelayClientReply($ticket_id, $reply_id, $by, $author_email, a
|
||||
'auto' => 'generated',
|
||||
]);
|
||||
}
|
||||
|
||||
/*
|
||||
* A reply's files, to email with it - ['path' (from ITFlow's folder), 'name', 'size'] each: not the email it came in as
|
||||
* (Original-parsed-email.eml), nor a picture shown inside it, and only those still on disk.
|
||||
*/
|
||||
function ticketReplyFiles($ticket_id, $reply_id) {
|
||||
global $mysqli;
|
||||
$files = [];
|
||||
$sql = mysqli_query($mysqli, "SELECT ticket_attachment_name, ticket_attachment_reference_name FROM ticket_attachments
|
||||
WHERE ticket_attachment_reply_id = " . intval($reply_id) . " AND ticket_attachment_ticket_id = " . intval($ticket_id) . " AND ticket_attachment_name <> 'Original-parsed-email.eml'"
|
||||
. (ticketPicturesReady() ? ' AND ticket_attachment_inline = 0' : ''));
|
||||
while ($sql && ($file = mysqli_fetch_assoc($sql))) {
|
||||
$path = 'uploads/tickets/' . intval($ticket_id) . '/' . basename((string) $file['ticket_attachment_reference_name']);
|
||||
if (is_file(dirname(__DIR__) . '/' . $path)) {
|
||||
$files[] = ['path' => $path, 'name' => (string) $file['ticket_attachment_name'], 'size' => filesize(dirname(__DIR__) . '/' . $path)];
|
||||
}
|
||||
}
|
||||
return $files;
|
||||
}
|
||||
|
||||
@@ -4,10 +4,14 @@
|
||||
* ITFlow - reply drafts. The reply an agent is writing on a ticket is kept as they type
|
||||
* (agent/js/ticket_reply_extras.js posting to agent/ajax.php), one per agent per ticket, so leaving
|
||||
* the page, closing the browser or being signed out doesn't lose it. The ticket page puts it back
|
||||
* in the reply box. It goes when the reply is sent (add_ticket_reply), when the agent discards it,
|
||||
* in the reply box, and opens the box on how it was to go - an internal note, a public note, an email or a text reply
|
||||
* (4.4.0, draft_type). It goes when the reply is sent (add_ticket_reply), when the agent discards it,
|
||||
* and nightly once it is a month old or its ticket is closed (cron/nightly_tasks.php).
|
||||
*/
|
||||
|
||||
/** The reply box's types - public_reply_type - a draft can have. */
|
||||
const TICKET_REPLY_DRAFT_TYPES = [0 => 'Internal note', 1 => 'Public note', 2 => 'Email reply', 3 => 'Text reply'];
|
||||
|
||||
/** Whether the 4.0.1 update has run - the ticket_reply_drafts table. */
|
||||
function ticketReplyDraftsReady() {
|
||||
global $mysqli;
|
||||
@@ -24,19 +28,34 @@ function ticketReplyDraftsReady() {
|
||||
return $ready;
|
||||
}
|
||||
|
||||
/** An agent's draft on a ticket - ['body' (HTML, as typed), 'updated_at'] - or null. */
|
||||
/** Whether the 4.4.0 update has run - a draft keeps how it was to go (draft_type). */
|
||||
function ticketReplyDraftTypeReady() {
|
||||
global $mysqli;
|
||||
static $ready = null;
|
||||
if ($ready === null) {
|
||||
$version = defined('CURRENT_DATABASE_VERSION') ? CURRENT_DATABASE_VERSION
|
||||
: (string) (mysqli_fetch_row(mysqli_query($mysqli, "SELECT config_current_database_version FROM settings WHERE company_id = 1"))[0] ?? '0');
|
||||
$ready = version_compare($version, '4.4.0', '>=');
|
||||
}
|
||||
return $ready;
|
||||
}
|
||||
|
||||
/** An agent's draft on a ticket - ['body' (HTML, as typed), 'type' (public_reply_type, or null), 'updated_at'] - or null. */
|
||||
function ticketReplyDraft($ticket_id, $user_id) {
|
||||
global $mysqli;
|
||||
if (!ticketReplyDraftsReady()) {
|
||||
return null;
|
||||
}
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT draft_body, draft_updated_at FROM ticket_reply_drafts
|
||||
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT draft_body, " . (ticketReplyDraftTypeReady() ? 'draft_type' : 'NULL AS draft_type') . ", draft_updated_at FROM ticket_reply_drafts
|
||||
WHERE ticket_id = " . intval($ticket_id) . " AND user_id = " . intval($user_id) . " LIMIT 1"));
|
||||
return $row ? ['body' => (string) $row['draft_body'], 'updated_at' => $row['draft_updated_at']] : null;
|
||||
return $row ? ['body' => (string) $row['draft_body'], 'type' => $row['draft_type'] !== null ? intval($row['draft_type']) : null, 'updated_at' => $row['draft_updated_at']] : null;
|
||||
}
|
||||
|
||||
/** Keep an agent's draft - made safe first. Nothing worth keeping (no words, no picture) drops it. */
|
||||
function ticketReplyDraftSave($ticket_id, $user_id, $html) {
|
||||
/*
|
||||
* Keep an agent's draft - made safe first - and how it was to go, $type (public_reply_type; null keeps what it had).
|
||||
* Nothing worth keeping (no words, no picture) drops it.
|
||||
*/
|
||||
function ticketReplyDraftSave($ticket_id, $user_id, $html, $type = null) {
|
||||
global $mysqli;
|
||||
if (!ticketReplyDraftsReady()) {
|
||||
return false;
|
||||
@@ -50,8 +69,12 @@ function ticketReplyDraftSave($ticket_id, $user_id, $html) {
|
||||
$ticket_id = intval($ticket_id);
|
||||
$user_id = intval($user_id);
|
||||
$body = mysqli_real_escape_string($mysqli, $html);
|
||||
mysqli_query($mysqli, "INSERT INTO ticket_reply_drafts SET ticket_id = $ticket_id, user_id = $user_id, draft_body = '$body', draft_updated_at = NOW()
|
||||
ON DUPLICATE KEY UPDATE draft_body = '$body', draft_updated_at = NOW()");
|
||||
$type_sql = '';
|
||||
if (ticketReplyDraftTypeReady() && $type !== null && $type !== '' && isset(TICKET_REPLY_DRAFT_TYPES[intval($type)])) {
|
||||
$type_sql = ', draft_type = ' . intval($type);
|
||||
}
|
||||
mysqli_query($mysqli, "INSERT INTO ticket_reply_drafts SET ticket_id = $ticket_id, user_id = $user_id, draft_body = '$body'$type_sql, draft_updated_at = NOW()
|
||||
ON DUPLICATE KEY UPDATE draft_body = '$body'$type_sql, draft_updated_at = NOW()");
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user