mirror of
https://github.com/itflow-org/itflow
synced 2026-12-02 00:59:03 +00:00
63 lines
3.2 KiB
PHP
63 lines
3.2 KiB
PHP
<?php
|
|
|
|
/*
|
|
* Sending an agent's reply - Admin > Settings > Tickets, Emails about a ticket (4.3.3):
|
|
*
|
|
* - Undo send: an emailed or texted reply waits config_ticket_reply_undo_seconds on the ticket page, with Undo, before
|
|
* it is posted (agent/js/ticket_reply_extras.js) - Undo leaves it in the reply box, kept as a draft. Nothing reaches
|
|
* the server until then, so there is nothing to take back: not the email, the status, the time or who it's assigned.
|
|
* - Reply-To: an email in a ticket's conversation from an address other than the mailbox ITFlow reads asks for replies
|
|
* at that mailbox (Reply-To), so a reply isn't lost on an address nobody reads - config_ticket_reply_to_read, on.
|
|
*/
|
|
|
|
const TICKET_REPLY_UNDO_CHOICES = [0 => 'Off - send at once', 5 => '5 seconds', 10 => '10 seconds', 20 => '20 seconds', 30 => '30 seconds'];
|
|
const TICKET_REPLY_UNDO_DEFAULT = 10;
|
|
|
|
/** Whether the 4.3.3 update has run - the settings are there. */
|
|
function ticketReplySendReady() {
|
|
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.3.3', '>=');
|
|
}
|
|
return $ready;
|
|
}
|
|
|
|
/** ['undo' => seconds, 'reply_to_read' => bool, 'parse' => bool, 'reads' => the mailbox ITFlow reads, lower case, or ''] - as saved. */
|
|
function ticketReplySendSettings() {
|
|
global $mysqli;
|
|
static $settings = null;
|
|
if ($settings === null) {
|
|
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT config_ticket_email_parse, config_imap_provider, config_imap_username"
|
|
. (ticketReplySendReady() ? ', config_ticket_reply_undo_seconds, config_ticket_reply_to_read' : '') . " FROM settings WHERE company_id = 1")) ?: [];
|
|
$reads = strtolower(trim((string) ($row['config_imap_username'] ?? '')));
|
|
$settings = [
|
|
'undo' => intval($row['config_ticket_reply_undo_seconds'] ?? 0),
|
|
'reply_to_read' => intval($row['config_ticket_reply_to_read'] ?? 0) === 1,
|
|
'parse' => intval($row['config_ticket_email_parse'] ?? 0) === 1 && trim((string) ($row['config_imap_provider'] ?? '')) !== '',
|
|
'reads' => filter_var($reads, FILTER_VALIDATE_EMAIL) ? $reads : '',
|
|
];
|
|
}
|
|
return $settings;
|
|
}
|
|
|
|
/** How long an emailed or texted reply waits on the ticket page, with Undo - 0 when it goes at once. */
|
|
function ticketReplyUndoSeconds() {
|
|
$seconds = ticketReplySendSettings()['undo'];
|
|
return isset(TICKET_REPLY_UNDO_CHOICES[$seconds]) ? $seconds : 0;
|
|
}
|
|
|
|
/*
|
|
* The address a ticket's email from $from_email asks replies to go to - the mailbox ITFlow reads, when email to ticket
|
|
* is on, the setting is, and $from_email is another address - or '' for none, a reply going to From as always.
|
|
*/
|
|
function ticketMailReplyToRead($from_email) {
|
|
$settings = ticketReplySendSettings();
|
|
if (!$settings['parse'] || !$settings['reply_to_read'] || $settings['reads'] === '') {
|
|
return '';
|
|
}
|
|
return $settings['reads'] !== strtolower(trim((string) $from_email)) ? $settings['reads'] : '';
|
|
}
|