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:
johnnyq
2026-12-02 13:36:49 -05:00
parent 8dae372d57
commit 2ad57e2865
31 changed files with 276 additions and 80 deletions

View File

@@ -2602,13 +2602,15 @@ if (isset($_GET['contact_email_check'])) {
// 1. Duplicate check - who has it, where the agent may see them; not the contact being edited
$exclude_contact = intval($_GET['exclude'] ?? 0);
$sql_contacts = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_client_id, contact_archived_at, client_name FROM contacts
// Their email, or their alternate one (contactEmailSql(), functions/contact.php)
$sql_contacts = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_client_id, contact_archived_at, client_name,
" . (contactEmailAltReady() ? "contact_email_alt = '$email' AND contact_email <> '$email'" : '0') . " AS as_alt FROM contacts
LEFT JOIN clients ON client_id = contact_client_id
WHERE contact_email = '$email' AND contact_id != $exclude_contact ORDER BY contact_archived_at IS NOT NULL, contact_id DESC LIMIT 1");
WHERE " . contactEmailSql(stripslashes($email)) . " AND contact_id != $exclude_contact ORDER BY contact_archived_at IS NOT NULL, contact_id DESC LIMIT 1");
if ($row = mysqli_fetch_assoc($sql_contacts)) {
$response['message'] = hasClientAccess($row['contact_client_id'])
? "<i class='far fa-fw fa-copy me-2'></i>Already on file: <a href='contact.php?client_id=" . intval($row['contact_client_id']) . "&contact_id=" . intval($row['contact_id']) . "' target='_blank' rel='noopener'>" . escapeHtml($row['contact_name']) . "</a>"
. " at " . escapeHtml($row['client_name']) . ($row['contact_archived_at'] ? ' (archived)' : '')
. " at " . escapeHtml($row['client_name']) . (intval($row['as_alt']) ? ', as their alternate email' : '') . ($row['contact_archived_at'] ? ' (archived)' : '')
: "<i class='far fa-fw fa-copy me-2'></i>Already on file for a client you cannot open.";
}

View File

@@ -165,7 +165,7 @@ $sql = mysqli_query(
SELECT l.location_id FROM locations l WHERE l.location_client_id = clients.client_id AND l.location_primary = 1 ORDER BY l.location_id LIMIT 1
)
WHERE (client_name LIKE '%$q%' OR client_abbreviation LIKE '%$q%' OR client_type LIKE '%$q%' OR client_referral LIKE '%$q%'
OR contact_email LIKE '%$q%' OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%'
OR contact_email LIKE '%$q%'" . contactEmailAltLikeSql($q) . " OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%'
OR contact_mobile LIKE '%$phone_query%' OR location_address LIKE '%$q%'
OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR location_country LIKE '%$q%'
OR client_tax_id_number LIKE '%$q%'

View File

@@ -28,7 +28,7 @@ enforceUserPermission('module_client');
$contact_id = intval($_GET['contact_id'] ?? 0);
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, contact_archived_at, contact_billing, contact_client_id, contact_created_at,
contact_department, contact_email, " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_id, contact_important, contact_location_id, contact_mobile,
contact_department, contact_email, " . contactEmailAltColumn() . ", " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_id, contact_important, contact_location_id, contact_mobile,
contact_mobile_country_code, contact_name, contact_notes, contact_phone, contact_phone_country_code, contact_photo, contact_pin,
contact_primary, contact_technical, contact_title, contact_updated_at, contact_user_id,
contact_ticket_emails, contact_company_ticket_emails, location_archived_at, location_city, location_name, location_state, user_auth_method, user_token
@@ -56,6 +56,7 @@ $contact_name = escapeHtml($row['contact_name']);
$contact_title = escapeHtml($row['contact_title']);
$contact_department = escapeHtml($row['contact_department']);
$contact_email = escapeHtml($row['contact_email']);
$contact_email_alt = escapeHtml($row['contact_email_alt'] ?? '');
$contact_pin = escapeHtml($row['contact_pin']);
$contact_notes = escapeHtml($row['contact_notes']);
$contact_primary = intval($row['contact_primary']);
@@ -363,7 +364,7 @@ if (!$can_support) {
<h3 class="card-title mb-0"><i class="fas fa-fw fa-phone-alt text-secondary me-2"></i>Reach</h3>
</div>
<div class="card-body">
<?php if ($contact_phone_link || $contact_mobile_link || $contact_email) { ?>
<?php if ($contact_phone_link || $contact_mobile_link || $contact_email || $contact_email_alt) { ?>
<dl class="itflow-asset-dl mb-0">
<?php if ($contact_phone_link) { ?>
<dt>Phone</dt>
@@ -387,6 +388,10 @@ if (!$can_support) {
</dd>
<?php } ?>
<?php } ?>
<?php if ($contact_email_alt) { ?>
<dt>Alternate email</dt>
<dd class="d-flex align-items-center min-w-0" data-contact-email-alt><a class="text-truncate" href="mailto:<?= $contact_email_alt ?>" title="<?= $contact_email_alt ?> - email from it is theirs too"><?= $contact_email_alt ?></a><button type="button" class="itflow-copy clipboardjs" title="Copy alternate email" data-clipboard-text="<?= $contact_email_alt ?>"><i class="far fa-copy"></i></button></dd>
<?php } ?>
</dl>
<?php } else { ?>
<span class="text-body-secondary">No phone or email recorded.</span>

View File

@@ -153,7 +153,7 @@ if ($invites_view) {
}
} else {
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.contact_id, contact_archived_at, contact_billing, contact_client_id,
contact_department, contact_email, " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_important, contact_location_id, contact_mobile,
contact_department, contact_email, " . contactEmailAltColumn() . ", " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_important, contact_location_id, contact_mobile,
contact_mobile_country_code, contact_name, contact_phone, contact_phone_country_code, contact_photo, contact_primary,
contact_technical, contact_title, contact_user_id, client_id, client_name, location_archived_at, location_name, user_auth_method
FROM contacts
@@ -163,7 +163,7 @@ if ($invites_view) {
WHERE $archive_query
$tag_query
AND ($role_query)
AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_department LIKE '%$q%'
AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%'" . contactEmailAltLikeSql($q) . " OR contact_department LIKE '%$q%'
OR contact_phone LIKE '%$phone_query%' OR contact_extension LIKE '%$q%' OR contact_mobile LIKE '%$phone_query%' OR client_name LIKE '%$q%'
OR contacts.contact_id IN (SELECT contact_tags.contact_id FROM contact_tags JOIN tags ON tags.tag_id = contact_tags.tag_id WHERE tag_name LIKE '%$q%'))
" . clientScopeSql('contact_client_id') . "
@@ -583,6 +583,7 @@ $search_title = $invites_view ? 'Email, name or client' : 'Name, title, email, p
$contact_title = escapeHtml($row['contact_title']);
$contact_department = escapeHtml($row['contact_department']);
$contact_email = escapeHtml($row['contact_email']);
$contact_email_alt = escapeHtml($row['contact_email_alt'] ?? '');
$contact_phone_link = contactPhoneLink($row['contact_phone'], $row['contact_phone_country_code'], $row['contact_extension'], 'text-reset');
$contact_mobile_link = contactPhoneLink($row['contact_mobile'], $row['contact_mobile_country_code'], '', 'text-reset');
$contact_primary = intval($row['contact_primary']);
@@ -633,7 +634,10 @@ $search_title = $invites_view ? 'Email, name or client' : 'Name, title, email, p
<?php if ($contact_email) { ?>
<div class="text-nowrap"><i class="far fa-fw fa-envelope text-body-secondary me-1" title="Email"></i><a class="text-reset" href="mailto:<?= $contact_email ?>"><?= $contact_email ?></a><button type="button" class="itflow-copy clipboardjs" title="Copy email" data-clipboard-text="<?= $contact_email ?>"><i class="far fa-copy"></i></button> <?= contactBounceBadge($row) ?> <?= contactUnsubscribeBadge($row) ?></div>
<?php } ?>
<?php if (!$contact_phone_link && !$contact_mobile_link && !$contact_email) { ?>
<?php if ($contact_email_alt) { ?>
<div class="text-nowrap" data-contact-email-alt><i class="fas fa-fw fa-at text-body-secondary me-1" title="Alternate email"></i><a class="text-reset" href="mailto:<?= $contact_email_alt ?>"><?= $contact_email_alt ?></a><button type="button" class="itflow-copy clipboardjs" title="Copy alternate email" data-clipboard-text="<?= $contact_email_alt ?>"><i class="far fa-copy"></i></button></div>
<?php } ?>
<?php if (!$contact_phone_link && !$contact_mobile_link && !$contact_email && !$contact_email_alt) { ?>
<span class="text-body-secondary">-</span>
<?php } ?>
</td>

View File

@@ -19,7 +19,7 @@ enforceUserPermission('module_client');
$contact_id = intval($_GET['id'] ?? 0);
$contact_row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_archived_at, contact_billing, contact_client_id, contact_department,
contact_email, " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_id, contact_important, contact_location_id, contact_mobile, contact_mobile_country_code,
contact_email, " . contactEmailAltColumn() . ", " . contactBounceColumns() . ", " . contactUnsubscribeColumns() . ", contact_extension, contact_id, contact_important, contact_location_id, contact_mobile, contact_mobile_country_code,
contact_name, contact_notes, contact_phone, contact_phone_country_code, contact_photo, contact_pin, contact_primary, contact_technical,
contact_title, contact_user_id, location_archived_at, location_name, user_auth_method
FROM contacts
@@ -43,6 +43,7 @@ $can_support = lookupUserPermission('module_support') >= 1;
$contact_name = escapeHtml($contact_row['contact_name']);
$contact_email = escapeHtml($contact_row['contact_email']);
$contact_email_alt = escapeHtml($contact_row['contact_email_alt'] ?? '');
$contact_pin = escapeHtml($contact_row['contact_pin']);
$contact_notes = escapeHtml($contact_row['contact_notes']);
$contact_archived = !empty($contact_row['contact_archived_at']);
@@ -129,7 +130,7 @@ $quick_tabs = array_filter([
});
$first_tab = array_key_first($quick_tabs);
$has_reach = $contact_phone_link || $contact_mobile_link || $contact_email;
$has_reach = $contact_phone_link || $contact_mobile_link || $contact_email || $contact_email_alt;
ob_start();
@@ -155,7 +156,7 @@ ob_start();
<div class="modal-body">
<?php if ($contact_tags_display || $contact_row['contact_phone'] || $contact_row['contact_mobile'] || $contact_email) { ?>
<?php if ($contact_tags_display || $contact_row['contact_phone'] || $contact_row['contact_mobile'] || $contact_email || $contact_email_alt) { ?>
<div class="d-flex flex-wrap align-items-start justify-content-between gap-2 mb-3">
<div class="min-w-0"><?= $contact_tags_display ?></div>
<div class="d-flex flex-wrap gap-2">
@@ -196,6 +197,12 @@ ob_start();
<span class="d-flex align-items-center min-w-0"><a class="text-truncate" href="mailto:<?= $contact_email ?>"><?= $contact_email ?></a><button type="button" class="itflow-copy clipboardjs" title="Copy email" data-clipboard-text="<?= $contact_email ?>"><i class="far fa-copy"></i></button></span>
</div>
<?php } ?>
<?php if ($contact_email_alt) { ?>
<div class="itflow-glance-item" title="Alternate email - email from it is theirs too" data-contact-email-alt>
<i class="fas fa-fw fa-at"></i>
<span class="d-flex align-items-center min-w-0"><a class="text-truncate" href="mailto:<?= $contact_email_alt ?>"><?= $contact_email_alt ?></a><button type="button" class="itflow-copy clipboardjs" title="Copy alternate email" data-clipboard-text="<?= $contact_email_alt ?>"><i class="far fa-copy"></i></button></span>
</div>
<?php } ?>
</div>
<?php } ?>
<div class="col-sm-6">

View File

@@ -27,7 +27,7 @@ if ($client_id) {
$contact_form_mode = 'add';
$contact_id = 0;
$contact_name = $contact_title = $contact_department = $contact_email = $contact_pin = $contact_notes = $contact_photo = '';
$contact_name = $contact_title = $contact_department = $contact_email = $contact_email_alt = $contact_pin = $contact_notes = $contact_photo = '';
$contact_phone = $contact_phone_country_code = $contact_extension = $contact_mobile = $contact_mobile_country_code = '';
$contact_primary = $contact_important = $contact_billing = $contact_technical = 0;
// Opened from a location's page - start at that location

View File

@@ -6,7 +6,7 @@ enforceUserPermission('module_client', 2);
$contact_id = intval($_GET['id'] ?? 0);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_billing, contact_client_id, contact_department, contact_email,
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_billing, contact_client_id, contact_department, contact_email, " . (contactEmailAltReady() ? 'contact_email_alt' : "'' AS contact_email_alt") . ",
contact_extension, contact_important, contact_location_id, contact_mobile, contact_mobile_country_code, contact_name,
contact_notes, contact_phone, contact_phone_country_code, contact_photo, contact_pin, contact_primary, contact_technical,
contact_title, contact_user_id, user_auth_method FROM contacts
@@ -43,6 +43,7 @@ $contact_phone = escapeHtml(formatPhoneNumber($row['contact_phone'], $row['conta
$contact_mobile_country_code = escapeHtml($row['contact_mobile_country_code']);
$contact_mobile = escapeHtml(formatPhoneNumber($row['contact_mobile'], $row['contact_mobile_country_code'], false));
$contact_email = escapeHtml($row['contact_email']);
$contact_email_alt = escapeHtml($row['contact_email_alt'] ?? '');
$contact_pin = escapeHtml($row['contact_pin']);
$contact_photo = escapeHtml($row['contact_photo']);
$contact_notes = escapeHtml($row['contact_notes']);

View File

@@ -150,6 +150,17 @@ $contact_roles = [
<!-- The address already on file for someone else - as it is typed (agent/ajax.php contact_email_check) -->
<div class="form-text text-warning-emphasis" id="contactFormEmailCheck" data-exclude="<?= $contact_form_mode === 'edit' ? intval($contact_id) : 0 ?>"></div>
</div>
<?php if (contactEmailAltReady()) { ?>
<div class="col-12">
<label class="form-label">Alternate email</label>
<div class="input-group">
<span class="input-group-text"><i class="far fa-envelope fa-fw"></i></span>
<input type="email" class="form-control" name="email_alt" id="contactFormEmailAlt" placeholder="name@personal.example" maxlength="200" value="<?= $contact_email_alt ?? '' ?>">
</div>
<div class="form-text">Email from it is theirs too - their new tickets and replies. What ITFlow sends goes to Email.</div>
<div class="form-text text-warning-emphasis" id="contactFormEmailAltCheck" data-exclude="<?= $contact_form_mode === 'edit' ? intval($contact_id) : 0 ?>"></div>
</div>
<?php } ?>
</div>
<?php if ($contact_form_mode === 'edit') { ?>
@@ -307,20 +318,51 @@ $contact_roles = [
});
}
// An email already on file for someone else
var emailCheck = form.querySelector('#contactFormEmailCheck');
if (emailCheck) {
form.querySelector('#contactFormEmail').addEventListener('change', function () {
var email = this.value.trim();
if (email === '') {
emailCheck.textContent = '';
return;
// An email already on file for someone else - their email or their alternate one - and an alternate the same as Email
var emailMain = form.querySelector('#contactFormEmail');
var emailAlt = form.querySelector('#contactFormEmailAlt');
var emailAltCheck = form.querySelector('#contactFormEmailAltCheck');
var emailAltSame = 'That is their Email already - an alternate is another address.';
var altIsEmail = function () {
return emailMain && emailAlt && emailAlt.value.trim() !== '' && emailMain.value.trim().toLowerCase() === emailAlt.value.trim().toLowerCase();
};
// Said as it is typed, not when the field is left - said then, the line moved Save from under the click
if (emailAlt && emailAltCheck) {
[emailMain, emailAlt].forEach(function (input) {
if (input) {
input.addEventListener('input', function () {
if (altIsEmail()) {
emailAltCheck.textContent = emailAltSame;
} else if (emailAltCheck.textContent === emailAltSame) {
emailAltCheck.textContent = '';
}
});
}
itflowGet('ajax.php', { contact_email_check: 'true', email: email, exclude: emailCheck.dataset.exclude }, function (data) {
emailCheck.innerHTML = JSON.parse(data).message || '';
});
});
}
[['#contactFormEmail', '#contactFormEmailCheck'], ['#contactFormEmailAlt', '#contactFormEmailAltCheck']].forEach(function (pair) {
var input = form.querySelector(pair[0]);
var check = form.querySelector(pair[1]);
if (!input || !check) {
return;
}
input.addEventListener('change', function () {
var email = this.value.trim();
if (email === '') {
check.textContent = '';
return;
}
if (input === emailAlt && altIsEmail()) {
return;
}
itflowGet('ajax.php', { contact_email_check: 'true', email: email, exclude: check.dataset.exclude }, function (data) {
if (input === emailAlt && altIsEmail()) {
return;
}
check.innerHTML = JSON.parse(data).message || '';
});
});
});
// A required field on a tab that isn't showing: show that tab and point
// at the field - otherwise the browser just quietly refuses to send

View File

@@ -23,7 +23,7 @@ $from_name = trim((string) $row['email_unprocessed_from_name']);
$can_add = filter_var($from_email, FILTER_VALIDATE_EMAIL) !== false;
// Open tickets, and ones closed lately - the newest first
$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_closed_at, ticket_status_name, client_name, contact_name, contact_email FROM tickets
$sql_tickets = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_closed_at, ticket_status_name, client_name, contact_name, contact_email, " . contactEmailAltColumn() . " FROM tickets
LEFT JOIN ticket_statuses ON ticket_status_id = ticket_status
LEFT JOIN clients ON client_id = ticket_client_id
LEFT JOIN contacts ON contact_id = ticket_contact_id
@@ -58,7 +58,7 @@ ob_start();
<?php while ($ticket = mysqli_fetch_assoc($sql_tickets)) {
$details = array_filter([(string) $ticket['client_name'], $ticket['ticket_closed_at'] ? 'Closed' : (string) $ticket['ticket_status_name'], (string) $ticket['contact_name']]);
?>
<option value="<?= intval($ticket['ticket_id']) ?>" data-description="<?= escapeHtml(implode(' · ', $details)) ?>" data-keywords="<?= escapeHtml(trim($ticket['ticket_number'] . ' ' . $ticket['client_name'] . ' ' . $ticket['contact_email'])) ?>"><?= escapeHtml(ticketReference($ticket) . ' - ' . $ticket['ticket_subject']) ?></option>
<option value="<?= intval($ticket['ticket_id']) ?>" data-description="<?= escapeHtml(implode(' · ', $details)) ?>" data-keywords="<?= escapeHtml(trim($ticket['ticket_number'] . ' ' . $ticket['client_name'] . ' ' . $ticket['contact_email'] . ' ' . $ticket['contact_email_alt'])) ?>"><?= escapeHtml(ticketReference($ticket) . ' - ' . $ticket['ticket_subject']) ?></option>
<?php } ?>
</select>
</div>

View File

@@ -22,10 +22,10 @@ $from_email = trim((string) $row['email_unprocessed_from_email']);
$from_name = trim((string) $row['email_unprocessed_from_name']);
$can_add = filter_var($from_email, FILTER_VALIDATE_EMAIL) !== false;
// A sender who is a contact already starts picked - their client and them
// A sender who is a contact already - by their email or their alternate one - starts picked: their client and them
$known = $from_email !== '' ? mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_id, contact_client_id FROM contacts
LEFT JOIN clients ON client_id = contact_client_id
WHERE contact_email = '" . escapeSql($from_email) . "' AND contact_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('contact_client_id') . "
WHERE " . contactEmailSql($from_email) . " AND contact_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('contact_client_id') . "
ORDER BY contact_primary DESC, contact_id LIMIT 1")) : null;
$client_id = intval($known['contact_client_id'] ?? 0);
$contact_id = intval($known['contact_id'] ?? 0);

View File

@@ -566,7 +566,7 @@ if (isExportRequest('export_clients')) {
LEFT JOIN client_tags ON client_tags.client_id = clients.client_id
LEFT JOIN tags ON tags.tag_id = client_tags.tag_id
WHERE (client_name LIKE '%$q%' OR client_abbreviation LIKE '%$q%' OR client_type LIKE '%$q%' OR client_referral LIKE '%$q%'
OR contact_email LIKE '%$q%' OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%'
OR contact_email LIKE '%$q%'" . contactEmailAltLikeSql($q) . " OR contact_name LIKE '%$q%' OR contact_phone LIKE '%$phone_query%'
OR contact_mobile LIKE '%$phone_query%' OR location_address LIKE '%$q%'
OR location_city LIKE '%$q%' OR location_state LIKE '%$q%' OR location_zip LIKE '%$q%' OR location_country LIKE '%$q%'
OR tag_name LIKE '%$q%' OR client_tax_id_number LIKE '%$q%')

View File

@@ -42,7 +42,7 @@ if (isset($_POST['add_contact'])) {
$user_id = mysqli_insert_id($mysqli);
}
mysqli_query($mysqli,"INSERT INTO contacts SET contact_name = '$name', contact_title = '$title', contact_phone_country_code = '$phone_country_code', contact_phone = '$phone', contact_extension = '$extension', contact_mobile_country_code = '$mobile_country_code', contact_mobile = '$mobile', contact_email = '$email', contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_department = '$department', contact_location_id = $location_id, contact_user_id = $user_id, contact_client_id = $client_id");
mysqli_query($mysqli,"INSERT INTO contacts SET contact_name = '$name', contact_title = '$title', contact_phone_country_code = '$phone_country_code', contact_phone = '$phone', contact_extension = '$extension', contact_mobile_country_code = '$mobile_country_code', contact_mobile = '$mobile', contact_email = '$email'$email_alt_sql, contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_department = '$department', contact_location_id = $location_id, contact_user_id = $user_id, contact_client_id = $client_id");
$contact_id = mysqli_insert_id($mysqli);
@@ -157,7 +157,7 @@ if (isset($_POST['edit_contact'])) {
}
mysqli_query($mysqli,"UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone_country_code = '$phone_country_code', contact_phone = '$phone', contact_extension = '$extension', contact_mobile_country_code = '$mobile_country_code', contact_mobile = '$mobile', contact_email = '$email', contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_department = '$department', contact_location_id = $location_id, contact_user_id = $contact_user_id WHERE contact_id = $contact_id");
mysqli_query($mysqli,"UPDATE contacts SET contact_name = '$name', contact_title = '$title', contact_phone_country_code = '$phone_country_code', contact_phone = '$phone', contact_extension = '$extension', contact_mobile_country_code = '$mobile_country_code', contact_mobile = '$mobile', contact_email = '$email'$email_alt_sql, contact_pin = '$pin', contact_notes = '$notes', contact_important = $contact_important, contact_billing = $contact_billing, contact_technical = $contact_technical, contact_department = '$department', contact_location_id = $location_id, contact_user_id = $contact_user_id WHERE contact_id = $contact_id");
// A new address hasn't bounced (functions/contact_bounce.php)
if (strtolower(trim((string) $row['contact_email'])) !== strtolower(trim((string) stripslashes($email)))) {
@@ -717,7 +717,7 @@ if (isset($_GET['anonymize_contact'])) {
$contact_id = intval($_GET['anonymize_contact']);
// Get contact & client info
$sql = mysqli_query($mysqli,"SELECT contact_name, contact_email, contact_phone, contact_client_id, contact_user_id FROM contacts WHERE contact_id = $contact_id");
$sql = mysqli_query($mysqli,"SELECT contact_name, contact_email, " . contactEmailAltColumn() . ", contact_phone, contact_client_id, contact_user_id FROM contacts WHERE contact_id = $contact_id");
$row = mysqli_fetch_assoc($sql);
if (!$row) {
flashAlert('That contact no longer exists.', 'error');
@@ -727,7 +727,7 @@ if (isset($_GET['anonymize_contact'])) {
$contact_name = escapeSql($row['contact_name']);
// Redacted as stored, not SQL-escaped - a name with an apostrophe was missed - and never an empty value.
// Longest first, so the first name doesn't take a piece out of the email address before it goes
$info_to_redact = array_values(array_filter(array_map('strval', [$row['contact_name'], explode(" ", (string) $row['contact_name'])[0], $row['contact_email'], $row['contact_phone']]), 'strlen'));
$info_to_redact = array_values(array_filter(array_map('strval', [$row['contact_name'], explode(" ", (string) $row['contact_name'])[0], $row['contact_email'], $row['contact_email_alt'], $row['contact_phone']]), 'strlen'));
usort($info_to_redact, function ($a, $b) {
return strlen($b) - strlen($a);
});
@@ -745,6 +745,9 @@ if (isset($_GET['anonymize_contact'])) {
mysqli_query($mysqli,"UPDATE contacts SET contact_title = '' WHERE contact_id = $contact_id");
mysqli_query($mysqli,"UPDATE contacts SET contact_department = '' WHERE contact_id = $contact_id");
mysqli_query($mysqli,"UPDATE contacts SET contact_email = '' WHERE contact_id = $contact_id");
if (contactEmailAltReady()) {
mysqli_query($mysqli,"UPDATE contacts SET contact_email_alt = '' WHERE contact_id = $contact_id");
}
mysqli_query($mysqli,"UPDATE contacts SET contact_phone = '' WHERE contact_id = $contact_id");
mysqli_query($mysqli,"UPDATE contacts SET contact_extension = '' WHERE contact_id = $contact_id");
mysqli_query($mysqli,"UPDATE contacts SET contact_mobile = '' WHERE contact_id = $contact_id");
@@ -1305,7 +1308,7 @@ if (isExportRequest('export_contacts')) {
LEFT JOIN tags ON tags.tag_id = contact_tags.tag_id
WHERE $archive_query
$tag_query
AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR contact_department LIKE '%$q%' OR contact_phone LIKE '%$q%' OR contact_mobile LIKE '%$q%' OR client_name LIKE '%$q%' OR tag_name LIKE '%$q%')
AND (contact_name LIKE '%$q%' OR contact_title LIKE '%$q%' OR location_name LIKE '%$q%' OR contact_email LIKE '%$q%'" . contactEmailAltLikeSql($q) . " OR contact_department LIKE '%$q%' OR contact_phone LIKE '%$q%' OR contact_mobile LIKE '%$q%' OR client_name LIKE '%$q%' OR tag_name LIKE '%$q%')
" . clientScopeSql('contact_client_id') . "
$client_query
$location_query

View File

@@ -10,6 +10,9 @@ $extension = preg_replace("/[^0-9]/", '', $_POST['extension'] ?? '');
$mobile_country_code = preg_replace("/[^0-9]/", '', $_POST['mobile_country_code'] ?? '');
$mobile = preg_replace("/[^0-9]/", '', $_POST['mobile'] ?? '');
$email = escapeSql($_POST['email'] ?? '');
// Their alternate email - an address, not the same as Email (functions/contact.php); SQL-escaped
$email_alt = escapeSql(contactEmailAltClean($_POST['email_alt'] ?? '', $_POST['email'] ?? ''));
$email_alt_sql = contactEmailAltReady() && isset($_POST['email_alt']) ? ", contact_email_alt = '$email_alt'" : '';
$notes = escapeSql($_POST['notes'] ?? '');
$contact_primary = intval($_POST['contact_primary'] ?? 0);
$contact_important = intval($_POST['contact_important'] ?? 0);

View File

@@ -186,7 +186,7 @@ if ($date_filter_active) {
// Search
if ($q !== '') {
$filter_sql[] = "AND (CONCAT(ticket_prefix, ticket_number) LIKE '%$q%' OR ticket_subject LIKE '%$q%' OR client_name LIKE '%$q%'
OR contact_name LIKE '%$q%' OR contact_email LIKE '%$q%' OR ticket_status_name LIKE '%$q%' OR ticket_priority LIKE '%$q%'
OR contact_name LIKE '%$q%' OR contact_email LIKE '%$q%'" . contactEmailAltLikeSql($q) . " OR ticket_status_name LIKE '%$q%' OR ticket_priority LIKE '%$q%'
OR user_name LIKE '%$q%' OR asset_name LIKE '%$q%' OR vendor_name LIKE '%$q%' OR ticket_vendor_ticket_number LIKE '%$q%' OR category_name LIKE '%$q%'
" . tagSearchSql('ticket', $q, 'tickets.ticket_id') . ")";
}