mirror of
https://github.com/itflow-org/itflow
synced 2026-12-03 09:39:02 +00:00
Contact alternate email (DB 4.4.1): one more address per contact in the contact window under Email, shown on their page, quick look and the Reach column, searched by the contacts, clients, tickets and global searches, exported and imported as Alternate Email and in the API as contact_email_alt, and recognized on incoming email as theirs - a new ticket as them at their client even with unknown senders off, and their reply by ticket number, conversation or subject - with the ticket's from line showing the address it came from while everything ITFlow sends still goes to their Email and neither address is copied in; the duplicate warning, Try an Email, Unprocessed Email and the ignored sender and routing rule warnings count it too, and the same-as-Email warning shows while typing (contactEmailSql(), contactHasEmail(), contactEmailMatchSql()); 26.12.4 changelog
This commit is contained in:
@@ -204,3 +204,82 @@ function quickAddButton($type, $client_id = 0, $class = 'btn btn-outline-seconda
|
||||
. (intval($client_id) ? ' data-quick-add-client="' . intval($client_id) . '"' : '')
|
||||
. ' title="' . $titles[$type] . '" aria-label="' . $titles[$type] . '"><i class="fas fa-fw fa-plus"></i></button>';
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ Alternate email (4.4.1) */
|
||||
|
||||
/** Whether the 4.4.1 update has run - contacts have an alternate email (contact_email_alt). */
|
||||
function contactEmailAltReady() {
|
||||
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.1', '>=');
|
||||
}
|
||||
return $ready;
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL for a contact whose email or alternate email is $email (raw) - for finding who an email is from. $table, a table
|
||||
* alias in front of the columns, as "c." for c.contact_email. An empty address finds nobody.
|
||||
*/
|
||||
function contactEmailSql($email, $table = '') {
|
||||
$email = trim((string) $email);
|
||||
if ($email === '') {
|
||||
return '0';
|
||||
}
|
||||
$email_sql = escapeSql($email);
|
||||
return contactEmailAltReady() ? "({$table}contact_email = '$email_sql' OR {$table}contact_email_alt = '$email_sql')" : "{$table}contact_email = '$email_sql'";
|
||||
}
|
||||
|
||||
/** The alternate email as a SELECT column - '' before the 4.4.1 update. */
|
||||
function contactEmailAltColumn() {
|
||||
return contactEmailAltReady() ? 'contact_email_alt' : "'' AS contact_email_alt";
|
||||
}
|
||||
|
||||
/** " OR contact_email_alt LIKE '%...%'" for a search, $like SQL-escaped as the search's own - '' before the 4.4.1 update. */
|
||||
function contactEmailAltLikeSql($like, $table = '') {
|
||||
return contactEmailAltReady() ? " OR {$table}contact_email_alt LIKE '%$like%'" : '';
|
||||
}
|
||||
|
||||
/** Whether $email (raw) is the contact's ($row: contact_email, contact_email_alt) - their email or their alternate one, any case. */
|
||||
function contactHasEmail(array $row, $email) {
|
||||
$email = strtolower(trim((string) $email));
|
||||
if ($email === '') {
|
||||
return false;
|
||||
}
|
||||
return strtolower(trim((string) ($row['contact_email'] ?? ''))) === $email || strtolower(trim((string) ($row['contact_email_alt'] ?? ''))) === $email;
|
||||
}
|
||||
|
||||
/*
|
||||
* An alternate email as posted, trimmed - an address, at most 200 characters, and not the contact's own email ($email, in any
|
||||
* case) - or '' for none.
|
||||
*/
|
||||
function contactEmailAltClean($alt, $email = '') {
|
||||
$alt = trim((string) $alt);
|
||||
if ($alt === '' || mb_strlen($alt) > 200 || !filter_var($alt, FILTER_VALIDATE_EMAIL) || strtolower($alt) === strtolower(trim((string) $email))) {
|
||||
return '';
|
||||
}
|
||||
return $alt;
|
||||
}
|
||||
|
||||
/*
|
||||
* SQL for a contact with an address that $match takes - an address, or a domain and its subdomains, as an ignored sender
|
||||
* or an email routing rule has it - by their email or their alternate one. Any case. For the warnings on saving one.
|
||||
*/
|
||||
function contactEmailMatchSql($match) {
|
||||
$match = strtolower(trim((string) $match));
|
||||
if ($match === '') {
|
||||
return '0';
|
||||
}
|
||||
$parts = [];
|
||||
foreach (contactEmailAltReady() ? ['contact_email', 'contact_email_alt'] : ['contact_email'] as $column) {
|
||||
if (strpos($match, '@') !== false) {
|
||||
$parts[] = "LOWER($column) = '" . escapeSql($match) . "'";
|
||||
} else {
|
||||
$like = escapeSql(str_replace(['\\', '%', '_'], ['\\\\', '\\%', '\\_'], $match));
|
||||
$parts[] = "LOWER($column) LIKE '%@$like' OR LOWER($column) LIKE '%.$like'";
|
||||
}
|
||||
}
|
||||
return '(' . implode(' OR ', $parts) . ')';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user