Contacts overhaul: rebuilt contacts list with role tabs and counts, avatars, flag pills, hover copy on phone/mobile/email, inline location picker, linked asset/credential/license/ticket chips and tag filter; contact page rebuilt to match the asset page with header actions, Reach/Details/Quick notes cards and tabbed Assets, Credentials, Tickets, Recurring, Licenses, Documents, Files, Services and Notes; add and edit contact share one tabbed form (Details, Roles, Access, Notes) with field icons, role switches, password generator, duplicate email check and photo removal; contact quick look redone to match the asset quick look; contact avatars now used everywhere a contact appears - contact pickers, ticket header, contact card, client replies, ticket list, kanban, assets, clients list, client header, overview key contacts, credentials, documents, services, invoice/quote/statement recipients, license users and global search - with each contact keeping the same colour throughout; ticket contact pickers show the name with title and role underneath; fixes: permission checks on the add contact modal and contact page/list actions, contact location limited to the contact's own client on add/edit/bulk assign, contacts list no longer selects user account columns, archived assets and credentials left off the contact page and quick look, saving a contact with the client portal disabled no longer clears their portal login method, replacing a photo no longer tries to delete a directory, sort column whitelisted, list counts and tags batched instead of per row, recurring ticket menu markup, undefined index notices, contacts list no longer scrolls sideways on phones, Edit Service shows avatars on unselected contacts and assets, license user labels toggle their checkbox; new functions/contact.php helpers (contactAvatar, contactLink, contactFlagPills, contactPhoneLink, contactAvatarData, contactOptionDescription), shared contact_form.php, contact_location quick pick, removed unused assetContactAvatar and clientOverviewPersonInitials

This commit is contained in:
johnnyq
2026-10-14 18:33:18 -04:00
parent 21c4220c93
commit 234afd25fb
55 changed files with 2795 additions and 3195 deletions

View File

@@ -189,7 +189,8 @@ if (isset($_POST['tag_picker_set']) || isset($_POST['tag_picker_create'])) {
if (isset($_GET['quick_pick_options'])) {
header('Content-Type: application/json');
enforceUserPermission('module_support', 2);
// A contact's location is the clients module's; everything else here is support's
enforceUserPermission(($_GET['field'] ?? '') === 'contact_location' ? 'module_client' : 'module_support', 2);
$field = (string) ($_GET['field'] ?? '');
$options = [];
@@ -210,9 +211,9 @@ if (isset($_GET['quick_pick_options'])) {
$options = quickPickAgents();
} elseif ($field === 'project_manager') {
$options = quickPickAgents('No manager');
} elseif (in_array($field, ASSET_QUICK_FIELDS, true)) {
// Locations and contacts are the asset's client's own - functions/asset.php
$options = assetQuickOptions($field, intval($_GET['scope'] ?? 0));
} elseif (in_array($field, ASSET_QUICK_FIELDS, true) || $field === 'contact_location') {
// Locations and contacts are the client's own - functions/asset.php
$options = assetQuickOptions($field === 'contact_location' ? 'asset_location' : $field, intval($_GET['scope'] ?? 0));
if ($options === null) {
http_response_code(403);
echo json_encode(['error' => 'You cannot see that client.']);
@@ -272,6 +273,40 @@ if (isset($_POST['quick_pick_set'])) {
exit();
}
// A contact's location - contacts of clients this agent can reach, with
// the same permission as Edit Contact (functions/contact.php)
if ($field === 'contact_location') {
$contact_ids = $ticket_ids;
$allowed = lookupUserPermission('module_client') >= 2 && $contact_ids;
foreach ($allowed ? $contact_ids : [] as $id) {
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_client_id FROM contacts WHERE contact_id = $id"));
if (!$row || !hasClientAccess($row['contact_client_id'])) {
$allowed = false;
break;
}
}
if (!$allowed) {
http_response_code(403);
echo json_encode(['error' => 'You cannot change that on these contacts.']);
exit();
}
$message = '';
$response = ['records' => []];
foreach ($contact_ids as $id) {
[$ok, $message] = contactQuickSetLocation($id, $value);
if (!$ok) {
http_response_code(422);
echo json_encode(['error' => $message]);
exit();
}
$response['records'][$id] = contactQuickRecord($id);
}
$response['message'] = count($contact_ids) === 1 ? $message : 'Updated ' . count($contact_ids) . ' contacts';
echo json_encode($response);
exit();
}
// A project's manager or a recurring ticket's assignee - open projects
// and recurring tickets of clients this agent can reach, like their edit modals
if ($field === 'project_manager' || $field === 'recurring_assignee') {
@@ -923,8 +958,9 @@ if (isset($_GET['get_client_contacts'])) {
$response['contacts'] = [];
while ($row = mysqli_fetch_assoc($contact_sql)) {
// For the picker: initials, or the photo when there is one
// For the picker: initials on their own colour, or the photo when there is one
$row['contact_initials'] = personInitials($row['contact_name']);
$row['contact_tone'] = contactAvatarTone($row['contact_id']);
$row['contact_photo_url'] = $row['contact_photo'] ? "/uploads/clients/$client_id/" . rawurlencode($row['contact_photo']) : '';
unset($row['contact_photo']);
$response['contacts'][] = $row;

View File

@@ -532,7 +532,7 @@ if (mysqli_num_rows($sql) == 0) {
<?php if ($can_edit) { ?>
<?= quickPick('asset_contact', $asset_id, (string) $asset_contact_id, assetQuickHtml('asset_contact', $asset_row, 'detail'), 'detail', 0, $client_id) ?>
<?php } elseif ($contact_name) { ?>
<a class="<?= $contact_archived ? 'text-decoration-line-through text-body-secondary' : '' ?>" href="contact.php?client_id=<?= $client_id ?>&contact_id=<?= $asset_contact_id ?>" <?= $contact_archived ? 'title="Archived contact"' : '' ?>><?= $contact_name ?></a>
<?= contactLink($client_id, $asset_contact_id, $asset_row['contact_name'], $asset_row['contact_photo'], ['page' => true, 'archived' => $contact_archived]) ?>
<?php } else { ?>
<span class="text-body-secondary">Nobody</span>
<?php } ?>

View File

@@ -354,7 +354,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'
<div class="col-lg-1 col-md-12">
<div class="d-flex justify-content-end gap-2">
<a href="?<?= $client_url ?>archived=<?= $archived ? 0 : 1 ?>"
class="btn btn-<?= $archived ? 'primary' : 'default' ?>" title="Archived">
class="btn <?= $archived ? 'btn-dark' : 'btn-outline-dark' ?>" title="<?= $archived ? 'Back to active assets' : 'Show archived assets' ?>">
<i class="fa fa-fw fa-archive"></i><span class="d-lg-none ms-2">Archived</span>
</a>
<div class="dropdown" id="bulkActionButton" hidden>
@@ -659,7 +659,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets'
<?php if ($can_edit) { ?>
<?= quickPick('asset_contact', $asset_id, (string) $asset_contact_id, assetQuickHtml('asset_contact', $row), 'list', 0, $client_id) ?>
<?php } elseif ($contact_name) { ?>
<a class="ajax-modal <?= $contact_archived ? 'text-decoration-line-through text-body-secondary' : '' ?>" href="#" data-modal-url="modals/contact/contact.php?id=<?= $asset_contact_id ?>" data-modal-size="lg" <?= $contact_archived ? 'title="Archived contact"' : '' ?>><?= $contact_name ?></a>
<?= contactLink($client_id, $asset_contact_id, $row['contact_name'], $row['contact_photo'], ['archived' => $contact_archived]) ?>
<?php } else { ?>
<span class="text-body-secondary">-</span>
<?php } ?>

View File

@@ -173,23 +173,15 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
<?php foreach ($overview_contacts as $person) {
$person_id = intval($person['contact_id']);
$person_name = escapeHtml($person['contact_name']);
$person_photo = escapeHtml($person['contact_photo']);
$person_phone = escapeHtml(formatPhoneNumber($person['contact_phone'], $person['contact_phone_country_code']));
$person_mobile = escapeHtml(formatPhoneNumber($person['contact_mobile'], $person['contact_mobile_country_code']));
$person_email = escapeHtml($person['contact_email']);
$person_flags = array_keys(array_filter(['Primary' => $person['contact_primary'], 'Billing' => $person['contact_billing'], 'Technical' => $person['contact_technical'], 'Important' => $person['contact_important']]));
?>
<div class="list-group-item d-flex gap-3 py-2">
<?php if ($person_photo) { ?>
<img class="itflow-ov-person rounded-circle" src="../uploads/clients/<?= $client_id ?>/<?= $person_photo ?>" alt="">
<?php } else { ?>
<span class="itflow-ov-person rounded-circle bg-secondary-subtle text-secondary-emphasis" aria-hidden="true"><?= escapeHtml(clientOverviewPersonInitials($person['contact_name'])) ?></span>
<?php } ?>
<?= contactAvatar($client_id, $person_id, $person['contact_name'], $person['contact_photo']) ?>
<div class="overflow-hidden flex-grow-1">
<a class="ajax-modal fw-semibold" href="#" data-modal-url="modals/contact/contact.php?client_id=<?= $client_id ?>&id=<?= $person_id ?>" data-modal-size="lg"><?= $person_name ?></a>
<?php foreach ($person_flags as $flag) { ?>
<span class="badge rounded-pill <?= $flag === 'Primary' ? 'text-bg-success' : 'bg-secondary-subtle text-secondary-emphasis' ?> fw-normal ms-1"><?= $flag ?></span>
<?php } ?>
<span class="ms-1"><?= contactFlagPills($person, false) ?></span>
<?php if ($person['contact_title']) { ?><div class="small text-body-secondary text-truncate"><?= escapeHtml($person['contact_title']) ?></div><?php } ?>
<div class="small d-flex flex-wrap column-gap-3">
<?php if ($person_phone) { ?><a class="text-reset text-decoration-none text-nowrap" href="tel:<?= escapeHtml(preg_replace('/[^0-9+]/', '', (string) $person['contact_phone'])) ?>"><i class="fas fa-fw fa-phone text-body-secondary me-1" aria-hidden="true"></i><?= $person_phone ?><?= $person['contact_extension'] ? ' x' . escapeHtml($person['contact_extension']) : '' ?></a><?php } ?>

View File

@@ -154,7 +154,7 @@ $sql = mysqli_query(
clients.client_id, client_name, client_type, client_abbreviation, client_rate, client_currency_code,
client_lead, client_archived_at,
contact_id, contact_name, contact_phone, contact_phone_country_code, contact_extension,
contact_mobile, contact_mobile_country_code, contact_email,
contact_mobile, contact_mobile_country_code, contact_email, contact_photo,
location_id, location_address, location_city, location_state, location_zip, location_country
FROM clients
LEFT JOIN contacts ON contact_id = (
@@ -524,7 +524,7 @@ $total_leads = intval($row['leads']);
<td class="d-none d-md-table-cell">
<?php if ($contact_id) { ?>
<a class="ajax-modal text-reset" href="#" data-modal-url="modals/contact/contact.php?client_id=<?= $client_id ?>&id=<?= $contact_id ?>" data-modal-size="lg"><?= $contact_name ?: 'Unnamed contact' ?></a>
<?= contactLink($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], ['class' => 'text-reset']) ?>
<div class="d-flex align-items-center gap-2 small text-body-secondary mt-1">
<?php if ($contact_phone) { ?>
<a class="text-reset text-decoration-none text-nowrap" href="tel:<?= escapeHtml($contact_phone_digits) ?>"><i class="fas fa-fw fa-phone me-1" aria-hidden="true"></i><?= $contact_phone ?><?php if ($contact_extension) { echo " x$contact_extension"; } ?></a>
@@ -541,7 +541,7 @@ $total_leads = intval($row['leads']);
<?php } ?>
</div>
<?php } elseif ($can_edit) { ?>
<a class="ajax-modal small text-body-secondary" href="#" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1">
<a class="ajax-modal small text-body-secondary" href="#" data-modal-size="lg" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1">
<i class="fas fa-fw fa-plus me-1" aria-hidden="true"></i>Add primary contact
</a>
<?php } else { ?>

File diff suppressed because it is too large Load Diff

View File

@@ -1,5 +1,15 @@
<?php
/*
* Contacts - everyone at a client (or across all clients).
*
* Each row is the person (picture or initials, their flags, title and
* department), how to reach them (phone, mobile, email - each one a click to
* call, mail or copy), where they are (changed in place, js/quick_pick.js)
* and what is linked to them. Tabs across the top narrow it to the roles an
* MSP reaches for: important people, billing, technical, portal users.
*/
// Default Column Sortby Filter
$sort = "contact_name";
$order = "ASC";
@@ -34,73 +44,154 @@ if (isset($_GET['client_id'])) {
// Perms
enforceUserPermission('module_client');
$can_edit = lookupUserPermission('module_client') >= 2;
$can_delete = lookupUserPermission('module_client') >= 3;
$can_credentials = lookupUserPermission('module_credential') >= 1;
$can_support = lookupUserPermission('module_support') >= 1;
// The roles an MSP reaches for
$contact_role_tabs = [
'important' => ['label' => 'Important', 'icon' => 'fa-star', 'query' => "contact_important = 1"],
'billing' => ['label' => 'Billing', 'icon' => 'fa-file-invoice-dollar', 'query' => "contact_billing = 1"],
'technical' => ['label' => 'Technical', 'icon' => 'fa-tools', 'query' => "contact_technical = 1"],
'portal' => ['label' => 'Portal', 'icon' => 'fa-user-circle', 'query' => "contact_user_id > 0 AND COALESCE(user_auth_method, '') != ''"],
];
$role_filter = (isset($_GET['role']) && isset($contact_role_tabs[$_GET['role']])) ? $_GET['role'] : '';
$_GET['role'] = $role_filter;
$role_query = $role_filter ? $contact_role_tabs[$role_filter]['query'] : "1 = 1";
// Tags Filter
if (isset($_GET['tags']) && is_array($_GET['tags']) && !empty($_GET['tags'])) {
// Sanitize each element of the tags array
$sanitizedTags = array_map('intval', $_GET['tags']);
// Convert the sanitized tags into a comma-separated string
$tag_filter = implode(",", $sanitizedTags);
$tag_query = "AND tags.tag_id IN ($tag_filter)";
$tag_filter = implode(",", array_map('intval', $_GET['tags']));
$tag_query = "AND contacts.contact_id IN (SELECT contact_tags.contact_id FROM contact_tags WHERE contact_tags.tag_id IN ($tag_filter))";
} else {
$tag_filter = 0;
$tag_query = '';
}
$client = '';
if (!$client_url) {
// Client Filter
if (isset($_GET['client']) & !empty($_GET['client'])) {
$client_query = 'AND (contact_client_id = ' . intval($_GET['client']) . ')';
if (!empty($_GET['client'])) {
$client = intval($_GET['client']);
} else {
// Default - any
$client_query = '';
$client = '';
$client_query = "AND contact_client_id = $client";
}
}
if ($client_url && isset($_GET['location']) && !empty($_GET['location'])) {
if ($client_url && !empty($_GET['location'])) {
// Location Filter
$location_query = 'AND (contact_location_id = ' . intval($_GET['location']) . ')';
$location_filter = intval($_GET['location']);
$location_query = "AND contact_location_id = $location_filter";
} else {
// Default - any
$location_query = '';
$location_filter = 0;
}
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.*, clients.*, locations.*, users.*, GROUP_CONCAT(tags.tag_name) FROM contacts
// Only these sort - filter_header.php will hand through any lowercase word, and
// an unknown column takes the page down with a mysqli exception
$sortable_columns = ['contact_name', 'contact_title', 'contact_department', 'contact_email', 'location_name', 'client_name', 'contact_created_at'];
if (!in_array($sort, $sortable_columns, true)) {
$sort = 'contact_name';
}
// Tab counts - within the client, location, tag and archive scope, before the search narrows it
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "
SELECT
COUNT(*) AS all_count,
SUM(contact_important = 1) AS important_count,
SUM(contact_billing = 1) AS billing_count,
SUM(contact_technical = 1) AS technical_count,
SUM(contact_user_id > 0 AND COALESCE(user_auth_method, '') != '') AS portal_count
FROM contacts
LEFT JOIN clients ON client_id = contact_client_id
LEFT JOIN locations ON location_id = contact_location_id
LEFT JOIN users ON user_id = contact_user_id
LEFT JOIN contact_tags ON contact_tags.contact_id = contacts.contact_id
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 '%$phone_query%' OR contact_extension LIKE '%$q%' OR contact_mobile LIKE '%$phone_query%' OR tag_name LIKE '%$q%' OR client_name LIKE '%$q%')
" . clientScopeSql('contact_client_id') . "
$client_query
$location_query
GROUP BY contact_id
"));
$tab_counts = ['' => intval($row['all_count'])];
foreach (array_keys($contact_role_tabs) as $tab_key) {
$tab_counts[$tab_key] = intval($row[$tab_key . '_count']);
}
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS contacts.contact_id, contact_archived_at, contact_billing, contact_client_id,
contact_department, contact_email, 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
LEFT JOIN clients ON client_id = contact_client_id
LEFT JOIN locations ON location_id = contact_location_id
LEFT JOIN users ON user_id = contact_user_id
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%'
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') . "
$client_query
$location_query
ORDER BY contact_primary DESC, contact_important DESC, $sort $order LIMIT $record_from, $record_to"
);
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$contacts = [];
while ($row = mysqli_fetch_assoc($sql)) {
$contacts[intval($row['contact_id'])] = $row;
}
// Tags and what is linked to each contact, for the whole page in a handful of
// queries rather than five per row
$contacts_tags = tagsForRecords('contact', array_keys($contacts));
$linked = ['assets' => [], 'credentials' => [], 'licenses' => [], 'tickets' => [], 'open_tickets' => []];
if ($contacts) {
$ids = implode(',', array_keys($contacts));
$sql_linked = mysqli_query($mysqli, "SELECT asset_contact_id AS id, COUNT(*) AS n FROM assets WHERE asset_contact_id IN ($ids) AND asset_archived_at IS NULL GROUP BY asset_contact_id");
while ($row = mysqli_fetch_assoc($sql_linked)) {
$linked['assets'][intval($row['id'])] = intval($row['n']);
}
if ($can_credentials) {
$sql_linked = mysqli_query($mysqli, "SELECT credential_contact_id AS id, COUNT(*) AS n FROM credentials WHERE credential_contact_id IN ($ids) AND credential_archived_at IS NULL GROUP BY credential_contact_id");
while ($row = mysqli_fetch_assoc($sql_linked)) {
$linked['credentials'][intval($row['id'])] = intval($row['n']);
}
}
$sql_linked = mysqli_query($mysqli, "SELECT software_contacts.contact_id AS id, COUNT(*) AS n FROM software_contacts
JOIN software ON software.software_id = software_contacts.software_id
WHERE software_contacts.contact_id IN ($ids) AND software_archived_at IS NULL GROUP BY software_contacts.contact_id");
while ($row = mysqli_fetch_assoc($sql_linked)) {
$linked['licenses'][intval($row['id'])] = intval($row['n']);
}
if ($can_support) {
$sql_linked = mysqli_query($mysqli, "SELECT ticket_contact_id AS id, COUNT(*) AS n, SUM(ticket_resolved_at IS NULL AND ticket_closed_at IS NULL) AS open_n
FROM tickets WHERE ticket_contact_id IN ($ids) AND ticket_archived_at IS NULL GROUP BY ticket_contact_id");
while ($row = mysqli_fetch_assoc($sql_linked)) {
$linked['tickets'][intval($row['id'])] = intval($row['n']);
$linked['open_tickets'][intval($row['id'])] = intval($row['open_n']);
}
}
}
$search_noun = $role_filter ? strtolower($contact_role_tabs[$role_filter]['label']) . ' contacts' : 'contacts';
?>
<div class="card">
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fa fa-fw fa-address-book me-2"></i>Contacts</h3>
<div class="card-tools">
<?php if ($can_edit) { ?>
<div class="btn-group">
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>">
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/contact/contact_add.php?<?= $client_url ?>">
<i class="fas fa-plus me-2"></i>New Contact
</button>
<button type="button" class="btn btn-primary dropdown-toggle dropdown-toggle-split" data-bs-toggle="dropdown"></button>
<div class="dropdown-menu">
<div class="dropdown-menu dropdown-menu-end">
<?php if ($client_url) { ?>
<!-- <a class="dropdown-item text-dark" href="#" data-bs-toggle="modal" data-bs-target="#contactInviteModal"><i class="fas fa-fw fa-paper-plane me-2"></i>Invite</a>-->
<!-- <div class="dropdown-divider"></div>-->
<a class="dropdown-item text-dark ajax-modal" href="#"
data-modal-url="modals/contact/contact_import.php?<?= $client_url ?>">
<i class="fa fa-fw fa-upload me-2"></i>Import
@@ -113,141 +204,140 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
</a>
</div>
</div>
<?php } ?>
</div>
</div>
<?php if ($tab_counts['']) { ?>
<!-- Roles -->
<div class="card-header py-2 itflow-asset-tabs">
<nav class="nav nav-pills flex-nowrap overflow-auto">
<a class="nav-link text-nowrap <?= $role_filter === '' ? 'active' : '' ?>" href="?<?= $url_query_strings_sort ?>&role=">
All <span class="badge rounded-pill ms-1"><?= $tab_counts[''] ?></span>
</a>
<?php foreach ($contact_role_tabs as $tab_key => $tab) {
if (!$tab_counts[$tab_key] && $role_filter !== $tab_key) {
continue;
} ?>
<a class="nav-link text-nowrap <?= $role_filter === $tab_key ? 'active' : '' ?>" href="?<?= $url_query_strings_sort ?>&role=<?= $tab_key ?>">
<i class="fas fa-fw <?= $tab['icon'] ?> me-1"></i><?= $tab['label'] ?> <span class="badge rounded-pill ms-1"><?= $tab_counts[$tab_key] ?></span>
</a>
<?php } ?>
</nav>
</div>
<?php } ?>
<div class="card-header py-3">
<form autocomplete="off">
<?php if ($client_url) { ?>
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<?php } ?>
<input type="hidden" name="role" value="<?= $role_filter ?>">
<input type="hidden" name="archived" value="<?= $archived ?>">
<div class="row g-2 align-items-center">
<div class="col-md-4">
<div class="col-lg-4 col-md-6">
<div class="input-group">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search Contacts">
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
</div>
</div>
<div class="col-md-3">
<div class="input-group">
<select onchange="this.form.submit()" class="form-select select2" name="tags[]" data-placeholder="- Select Tags -" multiple>
<?php
$sql_tags_filter = mysqli_query($mysqli, "
SELECT tags.tag_id, tags.tag_name, MAX(tags.tag_color) AS tag_color, MAX(tags.tag_icon) AS tag_icon
FROM tags
LEFT JOIN contact_tags ON contact_tags.tag_id = tags.tag_id
LEFT JOIN contacts ON contact_tags.contact_id = contacts.contact_id
WHERE tag_type = 3
$client_query OR tags.tag_id IN ($tag_filter)
GROUP BY tags.tag_id
HAVING COUNT(contact_tags.contact_id) > 0 OR tags.tag_id IN ($tag_filter)
");
while ($row = mysqli_fetch_assoc($sql_tags_filter)) {
$tag_id = intval($row['tag_id']);
$tag_name = escapeHtml($row['tag_name']); ?>
<option value="<?= $tag_id ?>" <?php if (isset($_GET['tags']) && in_array($tag_id, $_GET['tags'])) { echo 'selected'; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>> <?= $tag_name ?> </option>
<?php } ?>
</select>
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search <?= $search_noun ?>, phones, emails...">
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
</div>
</div>
<?php if ($client_url) { ?>
<div class="col-md-2">
<div class="input-group">
<select class="form-select select2" name="location" onchange="this.form.submit()">
<option value="">- All Locations -</option>
<?php
$sql_locations_filter = mysqli_query($mysqli, "
SELECT DISTINCT location_id, location_name
FROM locations
WHERE location_client_id = $client_id
AND ( EXISTS (SELECT 1 FROM contacts WHERE contact_location_id = location_id AND $archive_query) OR location_id = $location_filter)
ORDER BY location_name ASC
");
while ($row = mysqli_fetch_assoc($sql_locations_filter)) {
$location_id = intval($row['location_id']);
$location_name = escapeHtml($row['location_name']);
?>
<option <?php if ($location_filter == $location_id) { echo "selected"; } ?> value="<?= $location_id ?>"><?= $location_name ?></option>
<?php
}
?>
</select>
</div>
<div class="col-lg-3 col-md-6">
<select class="form-select select2" name="location" onchange="this.form.submit()">
<option value="">- All Locations -</option>
<?php
$sql_locations_filter = mysqli_query($mysqli, "
SELECT location_id, location_name
FROM locations
WHERE location_client_id = $client_id
AND (EXISTS (SELECT 1 FROM contacts WHERE contact_location_id = location_id AND $archive_query) OR location_id = $location_filter)
ORDER BY location_name ASC
");
while ($row = mysqli_fetch_assoc($sql_locations_filter)) {
$location_id = intval($row['location_id']); ?>
<option <?php if ($location_filter == $location_id) { echo "selected"; } ?> value="<?= $location_id ?>"><?= escapeHtml($row['location_name']) ?></option>
<?php } ?>
</select>
</div>
<?php } else { ?>
<div class="col-md-2">
<div class="input-group">
<select class="form-select select2" name="client" onchange="this.form.submit()">
<option value="" <?php if ($client == "") { echo "selected"; } ?>>- All Clients -</option>
<?php
$sql_clients_filter = mysqli_query($mysqli, "
SELECT DISTINCT client_id, client_name, client_abbreviation
FROM clients
JOIN contacts ON contact_client_id = client_id
WHERE $archive_query
" . clientScopeSql('clients.client_id') . "
ORDER BY client_name ASC
");
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
$client_id = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']);
?>
<option <?php if ($client == $client_id) { echo "selected"; } ?> value="<?= $client_id ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= $client_name ?></option>
<?php
}
?>
</select>
</div>
<div class="col-lg-3 col-md-6">
<select class="form-select select2" name="client" onchange="this.form.submit()">
<option value="" <?php if ($client == "") { echo "selected"; } ?>>- All Clients -</option>
<?php
$sql_clients_filter = mysqli_query($mysqli, "
SELECT DISTINCT client_id, client_name, client_abbreviation
FROM clients
JOIN contacts ON contact_client_id = client_id
WHERE $archive_query
" . clientScopeSql('clients.client_id') . "
ORDER BY client_name ASC
");
while ($row = mysqli_fetch_assoc($sql_clients_filter)) {
$client_id_filter = intval($row['client_id']); ?>
<option <?php if ($client == $client_id_filter) { echo "selected"; } ?> value="<?= $client_id_filter ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= escapeHtml($row['client_name']) ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<div class="col-md-3">
<div class="btn-group float-end">
<a href="?<?= $client_url ?>archived=<?php if($archived == 1){ echo 0; } else { echo 1; } ?>"
class="btn btn-<?php if($archived == 1){ echo"primary"; } else { echo "default"; } ?>">
<i class="fa fa-fw fa-archive me-2"></i>Archived
<div class="col-lg-3 col-md-6">
<select onchange="this.form.submit()" class="form-select select2" name="tags[]" data-placeholder="- Tags -" multiple>
<?php
// Tags in use on contacts in this scope, plus any already picked
$sql_tags_filter = mysqli_query($mysqli, "
SELECT tag_id, tag_name, tag_color, tag_icon
FROM tags
WHERE tag_type = 3
AND (
EXISTS (SELECT 1 FROM contact_tags JOIN contacts ON contacts.contact_id = contact_tags.contact_id
WHERE contact_tags.tag_id = tags.tag_id " . clientScopeSql('contact_client_id') . " $client_query)
OR tag_id IN ($tag_filter)
)
ORDER BY tag_name ASC
");
while ($row = mysqli_fetch_assoc($sql_tags_filter)) {
$tag_id = intval($row['tag_id']); ?>
<option value="<?= $tag_id ?>" <?php if (isset($_GET['tags']) && in_array($tag_id, $_GET['tags'])) { echo 'selected'; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= escapeHtml($row['tag_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="col-lg-2 col-md-6">
<div class="d-flex justify-content-end gap-2">
<a href="?<?= $client_url ?>archived=<?= $archived ? 0 : 1 ?>"
class="btn <?= $archived ? 'btn-dark' : 'btn-outline-dark' ?>" title="<?= $archived ? 'Back to active contacts' : 'Show archived contacts' ?>">
<i class="fa fa-fw fa-archive"></i><span class="d-xl-none ms-2">Archived</span>
</a>
<div class="dropdown ms-2" id="bulkActionButton" hidden>
<?php if ($can_edit) { ?>
<div class="dropdown" id="bulkActionButton" hidden>
<button class="btn btn-secondary dropdown-toggle" type="button" data-bs-toggle="dropdown">
<i class="fas fa-fw fa-layer-group me-2"></i>Bulk Action (<span id="selectedCount">0</span>)
</button>
<div class="dropdown-menu">
<div class="dropdown-menu dropdown-menu-end">
<?php if ($client_url) { ?>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/contact/contact_bulk_assign_location.php?<?= $client_url ?>"
data-bulk="true">
<i class="fas fa-fw fa-map-marker-alt me-2"></i>Assign Location
</a>
<div class="dropdown-divider"></div>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/contact/contact_bulk_edit_phone.php"
data-bulk="true">
<i class="fas fa-fw fa-phone-alt me-2"></i>Set Phone Number
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/contact/contact_bulk_edit_department.php"
data-bulk="true">
<i class="fas fa-fw fa-users me-2"></i>Set Department
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/contact/contact_bulk_edit_role.php"
data-bulk="true">
<i class="fas fa-fw fa-user-shield me-2"></i>Set Roles
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item" href="#" data-tag-picker data-tag-entity="contact" data-tag-bulk data-csrf="<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-tags me-2"></i>Tags
</a>
@@ -258,26 +348,27 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
data-bulk="true">
<i class="fas fa-fw fa-paper-plane me-2"></i>Send Email
</a>
<div class="dropdown-divider"></div>
<?php if ($archived) { ?>
<div class="dropdown-divider"></div>
<button class="dropdown-item text-info"
type="submit" form="bulkActions" name="bulk_restore_contacts">
<i class="fas fa-fw fa-redo me-2"></i>Restore
</button>
<div class="dropdown-divider"></div>
<button class="dropdown-item text-danger text-bold"
type="submit" form="bulkActions" name="bulk_delete_contacts">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</button>
<button class="dropdown-item text-info"
type="submit" form="bulkActions" name="bulk_restore_contacts">
<i class="fas fa-fw fa-redo me-2"></i>Restore
</button>
<?php if ($can_delete) { ?>
<button class="dropdown-item text-danger text-bold confirm-link"
type="submit" form="bulkActions" name="bulk_delete_contacts">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</button>
<?php } ?>
<?php } else { ?>
<div class="dropdown-divider"></div>
<button class="dropdown-item text-danger confirm-link"
type="submit" form="bulkActions" name="bulk_archive_contacts">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</button>
<button class="dropdown-item text-danger confirm-link"
type="submit" form="bulkActions" name="bulk_archive_contacts">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</button>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</div>
@@ -288,249 +379,175 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="table-responsive">
<table class="table border mb-0">
<thead class="table-light <?php if (!$num_rows[0]) { echo "d-none"; } ?>">
<table class="table table-hover align-middle mb-0 itflow-contact-table">
<thead class="<?php if (!$num_rows[0]) { echo "d-none"; } ?> text-nowrap table-light">
<tr>
<td class="checkbox-column border-end">
<th class="checkbox-column border-end">
<div class="form-check">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)" title="Select all on this page">
</div>
</td>
</th>
<th>
<a class="text-secondary ms-3" href="?<?= $url_query_strings_sort ?>&sort=contact_name&order=<?= $disp ?>">
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=contact_name&order=<?= $disp ?>">
Name <?php if ($sort == 'contact_name') { echo $order_icon; } ?>
</a>
</th>
<th>
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=contact_department&order=<?= $disp ?>">
Department <?php if ($sort == 'contact_department') { echo $order_icon; } ?>
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=contact_email&order=<?= $disp ?>">
Reach <?php if ($sort == 'contact_email') { echo $order_icon; } ?>
</a>
</th>
<th>Contact</th>
<th>
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=location_name&order=<?= $disp ?>">
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=location_name&order=<?= $disp ?>">
Location <?php if ($sort == 'location_name') { echo $order_icon; } ?>
</a>
</th>
<th></th>
<th class="d-none d-lg-table-cell">Linked</th>
<?php if (!$client_url) { ?>
<th>
<a class="text-secondary" href="?<?= $url_query_strings_sort ?>&sort=client_name&order=<?= $disp ?>">
<a class="text-reset text-decoration-none" href="?<?= $url_query_strings_sort ?>&sort=client_name&order=<?= $disp ?>">
Client <?php if ($sort == 'client_name') { echo $order_icon; } ?>
</a>
</th>
<?php } ?>
<th class="text-center">Action</th>
<th class="position-relative"><span class="visually-hidden">Actions</span></th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($sql)) {
foreach ($contacts as $contact_id => $row) {
$client_id = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']);
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
$contact_title = escapeHtml($row['contact_title']);
if (empty($contact_title)) {
$contact_title_display = "";
} else {
$contact_title_display = "<small class='text-secondary'>$contact_title</small>";
}
$contact_department = escapeHtml($row['contact_department']) ?: '-';
$contact_extension = escapeHtml($row['contact_extension']);
if (empty($contact_extension)) {
$contact_extension_display = "";
} else {
$contact_extension_display = "<small class='text-secondary ms-1'>x$contact_extension</small>";
}
$contact_phone_country_code = escapeHtml($row['contact_phone_country_code']);
$contact_phone = escapeHtml(formatPhoneNumber($row['contact_phone'], $contact_phone_country_code));
if (empty($contact_phone)) {
$contact_phone_display = "";
} else {
$contact_phone_display = "<div><i class='fas fa-fw fa-phone me-2'></i><a href='tel:$contact_phone'>$contact_phone$contact_extension_display</a></div>";
}
$contact_mobile_country_code = escapeHtml($row['contact_mobile_country_code']);
$contact_mobile = escapeHtml(formatPhoneNumber($row['contact_mobile'], $contact_mobile_country_code));
if (empty($contact_mobile)) {
$contact_mobile_display = "";
} else {
$contact_mobile_display = "<div class='mt-2'><i class='fas fa-fw fa-mobile-alt me-2'></i><a href='tel:$contact_mobile'>$contact_mobile</a></div>";
}
$contact_department = escapeHtml($row['contact_department']);
$contact_email = escapeHtml($row['contact_email']);
if (empty($contact_email)) {
$contact_email_display = "";
} else {
$contact_email_display = "<div class='mt-1'><i class='fas fa-fw fa-envelope me-2'></i><a 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></div>";
}
$contact_info_display = "$contact_phone_display $contact_mobile_display $contact_email_display";
if (empty($contact_info_display)) {
$contact_info_display = "-";
}
$contact_pin = escapeHtml($row['contact_pin']);
$contact_photo = escapeHtml($row['contact_photo']);
$contact_initials = initials($contact_name);
$contact_notes = escapeHtml($row['contact_notes']);
$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']);
$contact_important = intval($row['contact_important']);
$contact_billing = intval($row['contact_billing']);
$contact_technical = intval($row['contact_technical']);
$contact_created_at = escapeHtml($row['contact_created_at']);
$contact_archived_at = escapeHtml($row['contact_archived_at']);
if ($contact_primary == 1) {
$contact_primary_display = "<small class='text-success'>Primary Contact</small>";
} else {
$contact_primary_display = false;
}
$contact_location_id = intval($row['contact_location_id']);
$location_name = escapeHtml($row['location_name']);
if (empty($location_name)) {
$location_name = "<span class='text-muted'>N/A</span>";
}
$location_archived_at = escapeHtml($row['location_archived_at']);
if ($location_archived_at) {
$location_name_display = "<div class='text-danger' title='Archived'><s>$location_name</s></div>";
} else {
$location_name_display = $location_name;
}
$auth_method = escapeHtml($row['user_auth_method']);
$contact_user_id = intval($row['contact_user_id']);
if ($contact_user_id) {
$user_exists_display = "<span class='badge rounded-pill bg-dark p-1' title='User: $auth_method'><i class='fas fa-fw fa-user'></i></span>";
} else {
$user_exists_display = "";
}
$contact_archived_at = $row['contact_archived_at'];
$contact_role_line = implode(' &middot; ', array_filter([$contact_title, $contact_department]));
$contact_tags = $contacts_tags[$contact_id] ?? [];
$contact_url = "contact.php?client_id=$client_id&contact_id=$contact_id";
// Counts
// Asset Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets WHERE asset_contact_id = $contact_id AND asset_archived_at IS NULL"));
$asset_count = $row['num'];
if ($asset_count) {
$asset_count_display = "<a href='contact.php?client_id=$client_id&contact_id=$contact_id#assets' class='me-2 mb-1 badge rounded-pill bg-dark p-2' title='Assets ($asset_count)'><i class='fas fa-fw fa-desktop me-2'></i>$asset_count</a>";
} else {
$asset_count_display = '';
}
// Credential Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('credential_id') AS num FROM credentials WHERE credential_contact_id = $contact_id AND credential_archived_at IS NULL"));
$credential_count = $row['num'];
if ($credential_count) {
$credential_count_display = "<a href='contact.php?client_id=$client_id&contact_id=$contact_id#credentials' class='me-2 mb-1 badge rounded-pill bg-secondary p-2' title='Credentials ($credential_count)'><i class='fas fa-fw fa-key me-2'></i>$credential_count</a>";
} else {
$credential_count_display = '';
}
// Software Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('software_id') AS num FROM software, software_contacts WHERE software.software_id = software_contacts.software_id AND software_contacts.contact_id = $contact_id AND software_archived_at IS NULL"));
$software_count = $row['num'];
if ($software_count) {
$software_count_display = "<a href='contact.php?client_id=$client_id&contact_id=$contact_id#software' class='me-2 mb-1 badge rounded-pill bg-secondary p-2' title='Licenses ($software_count)'><i class='fas fa-fw fa-cube me-2'></i>$software_count</a>";
} else {
$software_count_display = '';
}
// Ticket Count
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('ticket_id') AS num FROM tickets WHERE ticket_contact_id = $contact_id AND ticket_archived_at IS NULL"));
$ticket_count = $row['num'];
if ($ticket_count) {
$ticket_count_display = "<a href='contact.php?client_id=$client_id&contact_id=$contact_id#tickets' class='me-2 mb-1 badge rounded-pill bg-secondary p-2' title='Tickets ($ticket_count)'><i class='fas fa-fw fa-life-ring me-2'></i>$ticket_count</a>";
} else {
$ticket_count_display = '';
}
// Tags
$contact_tags = tagsForRecord('contact', $contact_id);
$assets_n = $linked['assets'][$contact_id] ?? 0;
$credentials_n = $linked['credentials'][$contact_id] ?? 0;
$licenses_n = $linked['licenses'][$contact_id] ?? 0;
$tickets_n = $linked['tickets'][$contact_id] ?? 0;
$open_tickets_n = $linked['open_tickets'][$contact_id] ?? 0;
?>
<tr>
<td class="checkbox-column bg-light border-end">
<div class="form-check">
<input class="form-check-input bulk-select" type="checkbox" name="contact_ids[]" value="<?= $contact_id ?>">
<input class="form-check-input bulk-select" type="checkbox" name="contact_ids[]" value="<?= $contact_id ?>" aria-label="Select <?= $contact_name ?>">
</div>
</td>
<!-- The whole cell opens the contact (stretched-link); the tag pills sit above it -->
<td class="position-relative">
<div class="d-flex">
<?php if ($contact_photo) { ?>
<span class="fa-stack fa-2x me-3 text-center">
<img class="img-size-50 rounded-circle" src="<?= "../uploads/clients/$client_id/$contact_photo" ?>">
</span>
<?php } else { ?>
<span class="fa-stack fa-2x me-3">
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
<span class="fa fa-stack-1x text-white"><?= $contact_initials ?></span>
</span>
<?php } ?>
<div class="flex-grow-1">
<a class="text-dark stretched-link <?php if($contact_important) { echo "text-bold"; } ?>" href="contact.php?client_id=<?= $client_id ?>&contact_id=<?= $contact_id ?>"><?= $contact_name ?> <?= $user_exists_display ?></a>
<?= $contact_title_display ?>
<div><?= $contact_primary_display ?></div>
<?php if ($contact_tags || lookupUserPermission('module_client') >= 2) { ?>
<div class="mt-1"><?= tagPills('contact', $contact_id, $contact_tags, "contacts.php?$client_url") ?></div>
<td class="position-relative itflow-contact-name-cell">
<div class="d-flex align-items-center gap-3">
<?= contactAvatar($client_id, $contact_id, $row['contact_name'], $row['contact_photo']) ?>
<div class="min-w-0">
<div class="d-flex flex-wrap align-items-center column-gap-2">
<a class="fw-semibold text-body stretched-link" href="<?= $contact_url ?>"><?= $contact_name ?></a>
<?= contactFlagPills($row) ?>
<?php if ($contact_archived_at) { ?><span class="badge rounded-pill text-bg-secondary fw-normal">Archived</span><?php } ?>
</div>
<?php if ($contact_role_line) { ?>
<div class="small text-body-secondary text-truncate itflow-contact-role"><?= $contact_role_line ?></div>
<?php } ?>
<?php if ($contact_tags || $can_edit) { ?>
<div class="mt-1 itflow-above-stretch"><?= tagPills('contact', $contact_id, $contact_tags, "contacts.php?$client_url") ?></div>
<?php } ?>
</div>
</div>
</td>
<td><?= $contact_department ?></td>
<td><?= $contact_info_display ?></td>
<td><?= $location_name_display ?></td>
<td class="small itflow-contact-reach">
<?php if ($contact_phone_link) { ?>
<div class="text-nowrap"><i class="fas fa-fw fa-phone text-body-secondary me-1" title="Phone"></i><?= $contact_phone_link ?></div>
<?php } ?>
<?php if ($contact_mobile_link) { ?>
<div class="text-nowrap"><i class="fas fa-fw fa-mobile-alt text-body-secondary me-1" title="Mobile"></i><?= $contact_mobile_link ?></div>
<?php } ?>
<?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></div>
<?php } ?>
<?php if (!$contact_phone_link && !$contact_mobile_link && !$contact_email) { ?>
<span class="text-body-secondary">-</span>
<?php } ?>
</td>
<td>
<?= "$asset_count_display$credential_count_display$software_count_display$ticket_count_display" ?>
<?php if ($can_edit && !$contact_archived_at) { ?>
<?= quickPick('contact_location', $contact_id, (string) intval($row['contact_location_id']), contactLocationHtml($row), 'list', 0, $client_id) ?>
<?php } elseif ($row['location_name']) { ?>
<span class="<?= $row['location_archived_at'] ? 'text-danger text-decoration-line-through' : '' ?>"><?= escapeHtml($row['location_name']) ?></span>
<?php } else { ?>
<span class="text-body-secondary">-</span>
<?php } ?>
</td>
<td class="d-none d-lg-table-cell">
<div class="d-flex flex-wrap gap-1">
<?php if ($assets_n) { ?>
<a class="itflow-contact-chip" href="<?= $contact_url ?>#assets" title="<?= $assets_n ?> asset<?= $assets_n === 1 ? '' : 's' ?>"><i class="fas fa-desktop"></i><?= $assets_n ?></a>
<?php } ?>
<?php if ($credentials_n) { ?>
<a class="itflow-contact-chip" href="<?= $contact_url ?>#credentials" title="<?= $credentials_n ?> credential<?= $credentials_n === 1 ? '' : 's' ?>"><i class="fas fa-key"></i><?= $credentials_n ?></a>
<?php } ?>
<?php if ($licenses_n) { ?>
<a class="itflow-contact-chip" href="<?= $contact_url ?>#licenses" title="<?= $licenses_n ?> license<?= $licenses_n === 1 ? '' : 's' ?>"><i class="fas fa-cube"></i><?= $licenses_n ?></a>
<?php } ?>
<?php if ($tickets_n) { ?>
<a class="itflow-contact-chip <?= $open_tickets_n ? 'is-alert' : '' ?>" href="<?= $contact_url ?>#tickets" title="<?= $tickets_n ?> ticket<?= $tickets_n === 1 ? '' : 's' ?><?= $open_tickets_n ? ", $open_tickets_n open" : '' ?>"><i class="fas fa-life-ring"></i><?= $open_tickets_n ? "$open_tickets_n open" : $tickets_n ?></a>
<?php } ?>
<?php if (!$assets_n && !$credentials_n && !$licenses_n && !$tickets_n) { ?>
<span class="text-body-secondary">-</span>
<?php } ?>
</div>
</td>
<?php if (!$client_url) { ?>
<td><a href="contacts.php?client_id=<?= $client_id ?>"><?= $client_name ?></a></td>
<?php } ?>
<td>
<div class="dropdown dropstart text-center">
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<a class="dropdown-item" href="contact.php?<?= $client_url ?>contact_id=<?= $contact_id ?>">
<i class="fas fa-fw fa-eye me-2"></i>Details
</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_note_add.php?id=<?= $contact_id ?>">
<i class="fas fa-fw fa-sticky-note me-2"></i>Make Note
</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_edit.php?id=<?= $contact_id ?>">
<i class="fas fa-fw fa-edit me-2"></i>Edit
</a>
<?php if ($session_user_role == 3 && $contact_primary == 0) { ?>
<?php if ($contact_archived_at) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-info confirm-link" href="post.php?restore_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-redo me-2"></i>Restore
<td class="text-end">
<?php if ($can_edit) { ?>
<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>
<div class="dropdown-menu">
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/contact/contact_edit.php?id=<?= $contact_id ?>">
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
</a>
<?php } else { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger confirm-link" href="post.php?anonymize_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-user-secret me-2"></i>Anonymize & Archive
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_note_add.php?id=<?= $contact_id ?>">
<i class="fas fa-fw fa-sticky-note text-secondary me-2"></i>Add Note
</a>
<?php if (!$contact_primary) { ?>
<div class="dropdown-divider"></div>
<?php if ($contact_archived_at) { ?>
<a class="dropdown-item confirm-link" href="post.php?restore_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
</a>
<?php } else { ?>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</a>
<?php if ($can_delete) { ?>
<a class="dropdown-item text-danger confirm-link" href="post.php?anonymize_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-user-secret me-2"></i>Anonymize &amp; Archive
</a>
<?php } ?>
<?php } ?>
<?php if ($can_delete && $config_destructive_deletes_enable) { ?>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
<?php } ?>
<?php } ?>
<?php if ($config_destructive_deletes_enable) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_contact=<?= $contact_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
<?php } ?>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
</td>
</tr>
<?php
}
?>
<?php } ?>
</tbody>
</table>

View File

@@ -346,10 +346,11 @@ $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$credential_tags = tagsForRecord('credential', $credential_id);
if ($credential_contact_id) {
$credential_contact_display = "<a href='#' class='me-2 mb-1 badge rounded-pill bg-dark p-2 ajax-modal' title='$contact_name'
// Their avatar, the size of the asset pill beside it
$credential_contact_display = "<a href='#' class='me-2 mb-1 d-inline-flex align-middle ajax-modal' title='$contact_name'
data-modal-size='lg'
data-modal-url='modals/contact/contact.php?id=$credential_contact_id'>
<i class='fas fa-fw fa-user'></i></a>";
data-modal-url='modals/contact/contact.php?id=$credential_contact_id'>"
. contactAvatar($row['credential_client_id'], $credential_contact_id, $row['contact_name'], $row['contact_photo'], 'md') . "</a>";
} else {
$credential_contact_display = '';
}

View File

@@ -244,7 +244,7 @@ $page_title = $row['document_name'];
</button>
</h6>
<?php
$sql_contacts = mysqli_query($mysqli, "SELECT contacts.contact_id, contact_name FROM contacts, contact_documents
$sql_contacts = mysqli_query($mysqli, "SELECT contacts.contact_id, contact_client_id, contact_name, contact_photo FROM contacts, contact_documents
WHERE contacts.contact_id = contact_documents.contact_id
AND contact_documents.document_id = $document_id
ORDER BY contact_name ASC"
@@ -254,17 +254,13 @@ $page_title = $row['document_name'];
while ($row = mysqli_fetch_assoc($sql_contacts)) {
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
$linked_contacts[] = $contact_id;
?>
<div class="ms-2">
<a class="ajax-modal" href="#"
data-modal-size="lg"
data-modal-url="modals/contact/contact.php?id=<?= $contact_id ?>">
<?= $contact_name ?></a>
<a class="confirm-link float-end" href="post.php?unlink_contact_from_document&contact_id=<?= $contact_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<div class="ms-2 mb-1 d-flex align-items-center">
<span class="flex-grow-1 min-w-0"><?= contactLink($row['contact_client_id'], $contact_id, $row['contact_name'], $row['contact_photo']) ?></span>
<a class="confirm-link ms-2" href="post.php?unlink_contact_from_document&contact_id=<?= $contact_id ?>&document_id=<?= $document_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-unlink text-secondary" title="Unlink Contact"></i>
</a>
</div>

View File

@@ -163,6 +163,15 @@ function searchResultBadge($badge) {
$item_url = escapeHtml($item['url']);
?>
<div class="list-group-item d-flex align-items-center gap-3 py-2">
<?php if (!empty($item['avatar'])) {
// A contact - their avatar, as everywhere else they appear
$avatar = $item['avatar'];
if (!empty($avatar['image'])) { ?>
<img class="itflow-contact-avatar itflow-contact-avatar-sm" src="<?= escapeHtml($avatar['image']) ?>" alt="" loading="lazy">
<?php } else { ?>
<span class="itflow-contact-avatar itflow-contact-avatar-sm bg-<?= escapeHtml($avatar['tone']) ?>-subtle text-<?= escapeHtml($avatar['tone']) ?>-emphasis" aria-hidden="true"><?= escapeHtml($avatar['initials']) ?></span>
<?php }
} ?>
<div class="flex-grow-1 text-truncate">
<a href="<?= $item_url ?>">
<?php if (!empty($item['ref'])) { ?>

View File

@@ -15,7 +15,7 @@ $location_map_query = rawurlencode(html_entity_decode(trim("$location_address $l
<div class="col-md-4">
<div class="itflow-ov-label">Primary contact</div>
<?php if ($contact_id) { ?>
<a class="ajax-modal fw-semibold" href="#" data-modal-url="modals/contact/contact.php?client_id=<?= $client_id ?>&id=<?= $contact_id ?>" data-modal-size="lg"><?= $contact_name ?: 'Unnamed contact' ?></a>
<?= contactLink($client_id, $contact_id, $contact_name, $contact_photo, ['class' => 'fw-semibold']) ?>
<?php if ($contact_title) { ?><span class="text-body-secondary small ms-1"><?= $contact_title ?></span><?php } ?>
<div class="small mt-1 d-flex flex-column gap-1">
<?php if ($contact_phone) { ?>
@@ -32,7 +32,7 @@ $location_map_query = rawurlencode(html_entity_decode(trim("$location_address $l
<?php } ?>
</div>
<?php } elseif ($client_details_edit) { ?>
<a class="ajax-modal small" href="#" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1"><i class="fas fa-fw fa-plus me-1"></i>Add primary contact</a>
<a class="ajax-modal small" href="#" data-modal-size="lg" data-modal-url="modals/contact/contact_add.php?client_id=<?= $client_id ?>&primary=1"><i class="fas fa-fw fa-plus me-1"></i>Add primary contact</a>
<?php } else { ?>
<span class="text-body-tertiary">None</span>
<?php } ?>

View File

@@ -22,7 +22,7 @@ if (isset($_GET['client_id'])) {
client_lead, client_name, client_net_terms, client_notes, client_rate, client_referral,
client_tax_id_number, client_type, client_website, contact_email, contact_extension,
contact_id, contact_mobile, contact_mobile_country_code, contact_name, contact_phone,
contact_phone_country_code, contact_primary, contact_title, location_address,
contact_phone_country_code, contact_photo, contact_primary, contact_title, location_address,
location_city, location_country, location_id, location_name, location_phone,
location_phone_country_code, location_primary, location_state, location_zip FROM clients
LEFT JOIN locations ON client_id = location_client_id AND location_primary = 1
@@ -55,6 +55,7 @@ if (isset($_GET['client_id'])) {
$client_archived_at = escapeHtml($row['client_archived_at']);
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
$contact_photo = escapeHtml($row['contact_photo']);
$contact_title = escapeHtml($row['contact_title']);
$contact_email = escapeHtml($row['contact_email']);
$contact_phone_country_code = escapeHtml($row['contact_phone_country_code']);

View File

@@ -34,10 +34,20 @@ itflowReady(function () {
contactSelect.appendChild(new Option('Select a contact', ''));
response.contacts.forEach(function (contact) {
// new Option() sets text content, so contact names are
// never parsed as markup
contactSelect.appendChild(
new Option(contact.contact_name, contact.contact_id)
);
// never parsed as markup. The picker draws their avatar
// from the data-* extras, as on every other contact field.
const option = new Option(contact.contact_name, contact.contact_id);
// Title, then Primary or Technical - contactOptionDescription() server side
const role = contact.contact_primary == '1' ? 'Primary' : (contact.contact_technical == '1' ? 'Technical' : '');
option.dataset.description = [contact.contact_title, role].filter(Boolean).join(' · ');
option.dataset.initials = contact.contact_initials || '';
option.dataset.shape = 'circle';
option.dataset.tone = contact.contact_tone || 'secondary';
option.dataset.soft = '1';
if (contact.contact_photo_url) {
option.dataset.image = contact.contact_photo_url;
}
contactSelect.appendChild(option);
});
} else {
contactSelect.appendChild(new Option('No contacts found', ''));

View File

@@ -189,10 +189,11 @@
if (contactSelectDropdown) {
const option = new Option(contact.contact_name, contact.contact_id);
option.dataset.description = details.join(', ');
option.dataset.description = details.join(' · ');
option.dataset.initials = contact.contact_initials;
option.dataset.shape = 'circle';
option.dataset.tone = 'secondary';
option.dataset.tone = contact.contact_tone || 'secondary';
option.dataset.soft = '1';
if (contact.contact_photo_url) {
option.dataset.image = contact.contact_photo_url;
}

View File

@@ -38,7 +38,7 @@ ob_start();
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
?>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= $contact_name ?></option>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name ?></option>
<?php } ?>

View File

@@ -23,8 +23,10 @@ $status_options = [];
$sql_status_select = mysqli_query($mysqli, "SELECT category_name, category_color, category_icon FROM categories
WHERE category_type = 'asset_status' AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC");
$status_colors = [];
while ($row = mysqli_fetch_assoc($sql_status_select)) {
$status_options[escapeHtml($row['category_name'])] = selectOptionColor($row['category_color'] ?? '', $row['category_icon'] ?? '');
$status_colors[$row['category_name']] = assetStatusColor($row['category_name'], $row['category_color'] ?? '');
}
if ($asset_status !== '' && !isset($status_options[$asset_status])) {
$status_options[$asset_status] = '';
@@ -76,6 +78,18 @@ $sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, ta
$asset_ip_is_dhcp = $asset_ip === 'DHCP';
// Leading icons that follow what is picked or typed: the status in its
// colour, the OS brand and the kind of link - the same as the assets list
// shows them (functions/asset.php). Type needs none, its picker already shows
// the type's icon. These are the starting ones; the script at the end keeps
// them in step.
$asset_form_icons = [
'status' => escapeHtml($status_colors[html_entity_decode($asset_status)] ?? 'var(--bs-secondary-color)'),
'os' => assetOsIcon(html_entity_decode($asset_os)),
'uri' => $asset_uri !== '' ? assetLinkIcon(html_entity_decode($asset_uri)) : 'fas fa-link',
'uri_2' => $asset_uri_2 !== '' ? assetLinkIcon(html_entity_decode($asset_uri_2)) : 'fas fa-link',
];
?>
<!-- Tabs, like the other add / edit modals - Login on a new asset, History on an existing one -->
@@ -115,27 +129,34 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<?php if (!$client_id) { ?>
<div class="col-12">
<label class="form-label">Client <strong class="text-danger">*</strong></label>
<select class="form-select select2" name="client_id" required>
<option value="">- Select Client -</option>
<?php foreach ($client_options as $client_option) { ?>
<option value="<?= intval($client_option['client_id']) ?>"<?= selectOptionClient($client_option['client_id'], $client_option['client_name'], $client_option['client_abbreviation'] ?? '') ?>><?= escapeHtml($client_option['client_name']) ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<select class="form-select select2" name="client_id" required>
<option value="">- Select Client -</option>
<?php foreach ($client_options as $client_option) { ?>
<option value="<?= intval($client_option['client_id']) ?>"<?= selectOptionClient($client_option['client_id'], $client_option['client_name'], $client_option['client_abbreviation'] ?? '') ?>><?= escapeHtml($client_option['client_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">Pick the asset's location, contact, network and vendor once it's saved.</div>
</div>
<?php } ?>
<div class="col-md-4">
<label class="form-label">Type <strong class="text-danger">*</strong></label>
<select class="form-select select2" name="type" required>
<option value="">- Select Type -</option>
<?php foreach ($asset_types_array as $asset_type_select => $asset_icon_select) { ?>
<option <?php if ($asset_type_select === html_entity_decode($asset_type)) { echo "selected"; } ?><?= selectOptionData(['icon' => "fas $asset_icon_select"]) ?>><?= $asset_type_select ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-layer-group fa-fw"></i></span>
<select class="form-select select2" name="type" required>
<option value="">- Select Type -</option>
<?php foreach ($asset_types_array as $asset_type_select => $asset_icon_select) { ?>
<option <?php if ($asset_type_select === html_entity_decode($asset_type)) { echo "selected"; } ?><?= selectOptionData(['icon' => "fas $asset_icon_select"]) ?>><?= $asset_type_select ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-5">
<div class="col-md-4">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-id-badge fa-fw"></i></span>
<input type="text" class="form-control" name="name" placeholder="SRV-DC01" maxlength="200" value="<?= $asset_name ?>" required <?= $asset_form_mode === 'edit' ? '' : 'autofocus' ?>>
<div class="input-group-text">
<label class="star-toggle mb-0" title="Favorite - pinned to the client overview">
@@ -144,22 +165,29 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
</div>
</div>
</div>
<div class="col-md-3">
<div class="col-md-4">
<label class="form-label">Status</label>
<select class="form-select select2" name="status">
<option value="">- Status -</option>
<?php foreach ($status_options as $status_option => $status_option_data) { ?>
<option <?php if ($status_option === $asset_status) { echo "selected"; } ?><?= $status_option_data ?>><?= $status_option ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-circle fa-fw" data-asset-form-icon="status" style="color: <?= $asset_form_icons['status'] ?>"></i></span>
<select class="form-select select2" name="status">
<option value="">- Status -</option>
<?php foreach ($status_options as $status_option => $status_option_data) { ?>
<option <?php if ($status_option === $asset_status) { echo "selected"; } ?><?= $status_option_data ?>><?= $status_option ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-7">
<label class="form-label">Description</label>
<input type="text" class="form-control" name="description" placeholder="Domain controller for HQ" maxlength="255" value="<?= $asset_description ?>">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-align-left"></i></span>
<input type="text" class="form-control" name="description" placeholder="Domain controller for HQ" maxlength="255" value="<?= $asset_description ?>">
</div>
</div>
<div class="col-md-5">
<label class="form-label">Tags</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
<select class="form-select select2" name="tags[]" data-placeholder="Add some tags" multiple>
<?php while ($row = mysqli_fetch_assoc($sql_tags_select)) {
$tag_id_select = intval($row['tag_id']); ?>
@@ -177,20 +205,29 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<div class="row g-3">
<div class="col-md-3">
<label class="form-label">Make</label>
<input type="text" class="form-control" name="make" placeholder="Dell" maxlength="200" value="<?= $asset_make ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-industry fa-fw"></i></span>
<input type="text" class="form-control" name="make" placeholder="Dell" maxlength="200" value="<?= $asset_make ?>">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Model</label>
<input type="text" class="form-control" name="model" placeholder="PowerEdge R650" maxlength="200" value="<?= $asset_model ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-box fa-fw"></i></span>
<input type="text" class="form-control" name="model" placeholder="PowerEdge R650" maxlength="200" value="<?= $asset_model ?>">
</div>
</div>
<div class="col-md-5">
<label class="form-label">Serial number</label>
<input type="text" class="form-control font-monospace" name="serial" placeholder="ABC1234XYZ" maxlength="200" value="<?= $asset_serial ?>">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-barcode"></i></span>
<input type="text" class="form-control font-monospace" name="serial" placeholder="ABC1234XYZ" maxlength="200" value="<?= $asset_serial ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Operating system / firmware</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-laptop-code"></i></span>
<span class="input-group-text"><i class="<?= $asset_form_icons['os'] ?> fa-fw" data-asset-form-icon="os"></i></span>
<input type="text" class="form-control" name="os" id="assetFormOs" placeholder="Windows 11 Pro 24H2, Ubuntu 24.04, UniFi firmware 7.0" maxlength="200" value="<?= $asset_os ?>">
</div>
</div>
@@ -207,34 +244,46 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Location</label>
<select class="form-select select2" name="location">
<option value="">- Select Location -</option>
<?php foreach ($location_options as $location_option) {
$location_option_id = intval($location_option['location_id']); ?>
<option value="<?= $location_option_id ?>" <?php if ($asset_location_id === $location_option_id) { echo "selected"; } ?>><?= escapeHtml($location_option['location_name']) ?><?= $location_option['location_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-map-marker-alt fa-fw"></i></span>
<select class="form-select select2" name="location">
<option value="">- Select Location -</option>
<?php foreach ($location_options as $location_option) {
$location_option_id = intval($location_option['location_id']); ?>
<option value="<?= $location_option_id ?>" <?php if ($asset_location_id === $location_option_id) { echo "selected"; } ?>><?= escapeHtml($location_option['location_name']) ?><?= $location_option['location_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Where in the building</label>
<input type="text" class="form-control" name="physical_location" placeholder="Floor 2, comms closet B" maxlength="200" value="<?= $asset_physical_location ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-door-open fa-fw"></i></span>
<input type="text" class="form-control" name="physical_location" placeholder="Floor 2, comms closet B" maxlength="200" value="<?= $asset_physical_location ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Assigned to</label>
<select class="form-select select2" name="contact">
<option value="">- Nobody -</option>
<?php foreach ($contact_options as $contact_option) {
$contact_option_id = intval($contact_option['contact_id']); ?>
<option value="<?= $contact_option_id ?>" <?php if ($asset_contact_id === $contact_option_id) { echo "selected"; } ?><?= selectOptionContact($contact_option['contact_client_id'] ?? 0, $contact_option['contact_name'], $contact_option['contact_photo'] ?? '', $contact_option['contact_title'] ?? '') ?>><?= escapeHtml($contact_option['contact_name']) ?><?= $contact_option['contact_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-user fa-fw"></i></span>
<select class="form-select select2" name="contact">
<option value="">- Nobody -</option>
<?php foreach ($contact_options as $contact_option) {
$contact_option_id = intval($contact_option['contact_id']); ?>
<option value="<?= $contact_option_id ?>" <?php if ($asset_contact_id === $contact_option_id) { echo "selected"; } ?><?= selectOptionContact($contact_option['contact_client_id'] ?? 0, $contact_option['contact_name'], $contact_option['contact_photo'] ?? '', $contact_option['contact_title'] ?? '', $contact_option['contact_id'] ?? 0) ?>><?= escapeHtml($contact_option['contact_name']) ?><?= $contact_option['contact_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<?php } else { ?>
<div class="row g-3">
<div class="col-12">
<label class="form-label">Where in the building</label>
<input type="text" class="form-control" name="physical_location" placeholder="Floor 2, comms closet B" maxlength="200" value="<?= $asset_physical_location ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-door-open fa-fw"></i></span>
<input type="text" class="form-control" name="physical_location" placeholder="Floor 2, comms closet B" maxlength="200" value="<?= $asset_physical_location ?>">
</div>
<div class="form-text">The location and who it's assigned to come from the client - pick them once it's saved.</div>
</div>
</div>
@@ -248,18 +297,22 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<?php if ($client_id) { ?>
<div class="col-md-6">
<label class="form-label">Network</label>
<select class="form-select select2" name="network">
<option value="">- Select Network -</option>
<?php foreach ($network_options as $network_option) {
$network_option_id = intval($network_option['network_id']); ?>
<option value="<?= $network_option_id ?>" <?php if ($asset_network_id === $network_option_id) { echo "selected"; } ?><?= selectOptionData(['description' => $network_option['network']]) ?>><?= escapeHtml($network_option['network_name']) ?><?= $network_option['network_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-network-wired"></i></span>
<select class="form-select select2" name="network">
<option value="">- Select Network -</option>
<?php foreach ($network_options as $network_option) {
$network_option_id = intval($network_option['network_id']); ?>
<option value="<?= $network_option_id ?>" <?php if ($asset_network_id === $network_option_id) { echo "selected"; } ?><?= selectOptionData(['description' => $network_option['network']]) ?>><?= escapeHtml($network_option['network_name']) ?><?= $network_option['network_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="col-md-6">
<label class="form-label">IPv4 address</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-globe fa-fw"></i></span>
<input type="text" class="form-control font-monospace" name="ip" id="assetFormIp" placeholder="192.168.1.10" maxlength="200" value="<?= $asset_ip_is_dhcp ? '' : $asset_ip ?>" data-inputmask="'alias': 'ip'" data-mask <?= $asset_ip_is_dhcp ? 'disabled' : '' ?>>
<div class="input-group-text">
<div class="form-check mb-0">
@@ -271,15 +324,24 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
</div>
<div class="col-md-6">
<label class="form-label">MAC address</label>
<input type="text" class="form-control font-monospace" name="mac" placeholder="00:1A:2B:3C:4D:5E" maxlength="200" value="<?= $asset_mac ?>" data-inputmask="'alias': 'mac'" data-mask>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-ethernet"></i></span>
<input type="text" class="form-control font-monospace" name="mac" placeholder="00:1A:2B:3C:4D:5E" maxlength="200" value="<?= $asset_mac ?>" data-inputmask="'alias': 'mac'" data-mask>
</div>
</div>
<div class="col-md-6">
<label class="form-label">NAT address</label>
<input type="text" class="form-control font-monospace" name="nat_ip" placeholder="203.0.113.10" maxlength="200" value="<?= $asset_nat_ip ?>" data-inputmask="'alias': 'ip'" data-mask>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-exchange-alt"></i></span>
<input type="text" class="form-control font-monospace" name="nat_ip" placeholder="203.0.113.10" maxlength="200" value="<?= $asset_nat_ip ?>" data-inputmask="'alias': 'ip'" data-mask>
</div>
</div>
<div class="col-12">
<label class="form-label">IPv6 address</label>
<input type="text" class="form-control font-monospace" name="ipv6" placeholder="2001:db8::1" maxlength="200" value="<?= $asset_ipv6 ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-globe fa-fw"></i></span>
<input type="text" class="form-control font-monospace" name="ipv6" placeholder="2001:db8::1" maxlength="200" value="<?= $asset_ipv6 ?>">
</div>
</div>
</div>
@@ -287,15 +349,24 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Link</label>
<input type="text" class="form-control" name="uri" placeholder="https://, ssh://, rdp://" maxlength="500" value="<?= $asset_uri ?>">
<div class="input-group">
<span class="input-group-text"><i class="<?= $asset_form_icons['uri'] ?> fa-fw" data-asset-form-icon="link"></i></span>
<input type="text" class="form-control" name="uri" placeholder="https://, ssh://, rdp://" maxlength="500" value="<?= $asset_uri ?>">
</div>
</div>
<div class="col-md-6">
<label class="form-label">Second link</label>
<input type="text" class="form-control" name="uri_2" placeholder="https://, ssh://, rdp://" maxlength="500" value="<?= $asset_uri_2 ?>">
<div class="input-group">
<span class="input-group-text"><i class="<?= $asset_form_icons['uri_2'] ?> fa-fw" data-asset-form-icon="link"></i></span>
<input type="text" class="form-control" name="uri_2" placeholder="https://, ssh://, rdp://" maxlength="500" value="<?= $asset_uri_2 ?>">
</div>
</div>
<div class="col-12">
<label class="form-label">Client link</label>
<input type="text" class="form-control" name="uri_client" placeholder="https://" maxlength="500" value="<?= $asset_uri_client ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-share-square fa-fw"></i></span>
<input type="text" class="form-control" name="uri_client" placeholder="https://" maxlength="500" value="<?= $asset_uri_client ?>">
</div>
<div class="form-text">Shown to the client in their portal.</div>
</div>
</div>
@@ -307,30 +378,45 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<?php if ($client_id) { ?>
<div class="col-md-6">
<label class="form-label">Vendor</label>
<select class="form-select select2" name="vendor">
<option value="">- Select Vendor -</option>
<?php foreach ($vendor_options as $vendor_option) {
$vendor_option_id = intval($vendor_option['vendor_id']); ?>
<option value="<?= $vendor_option_id ?>" <?php if ($asset_vendor_id === $vendor_option_id) { echo "selected"; } ?>><?= escapeHtml($vendor_option['vendor_name']) ?><?= $vendor_option['vendor_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-building"></i></span>
<select class="form-select select2" name="vendor">
<option value="">- Select Vendor -</option>
<?php foreach ($vendor_options as $vendor_option) {
$vendor_option_id = intval($vendor_option['vendor_id']); ?>
<option value="<?= $vendor_option_id ?>" <?php if ($asset_vendor_id === $vendor_option_id) { echo "selected"; } ?>><?= escapeHtml($vendor_option['vendor_name']) ?><?= $vendor_option['vendor_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="col-md-6">
<label class="form-label">Order / invoice reference</label>
<input type="text" class="form-control" name="purchase_reference" placeholder="INV-1045, PO-7782" maxlength="200" value="<?= $asset_purchase_reference ?>">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-receipt"></i></span>
<input type="text" class="form-control" name="purchase_reference" placeholder="INV-1045, PO-7782" maxlength="200" value="<?= $asset_purchase_reference ?>">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Purchased</label>
<input type="date" class="form-control" name="purchase_date" max="2999-12-31" value="<?= $asset_purchase_date ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-shopping-cart fa-fw"></i></span>
<input type="date" class="form-control" name="purchase_date" max="2999-12-31" value="<?= $asset_purchase_date ?>">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Installed</label>
<input type="date" class="form-control" name="install_date" max="2999-12-31" value="<?= $asset_install_date ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-tools fa-fw"></i></span>
<input type="date" class="form-control" name="install_date" max="2999-12-31" value="<?= $asset_install_date ?>">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Warranty expires</label>
<input type="date" class="form-control" name="warranty_expire" max="2999-12-31" value="<?= $asset_warranty_expire ?>">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-shield-alt fa-fw"></i></span>
<input type="date" class="form-control" name="warranty_expire" max="2999-12-31" value="<?= $asset_warranty_expire ?>">
</div>
</div>
</div>
</div>
@@ -342,11 +428,17 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<div class="row g-3">
<div class="col-md-6">
<label class="form-label">Username</label>
<input type="text" class="form-control" name="username" placeholder="admin" maxlength="350" autocomplete="off">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="username" placeholder="admin" maxlength="350" autocomplete="off">
</div>
</div>
<div class="col-md-6">
<label class="form-label">Password</label>
<input type="text" class="form-control" name="password" placeholder="Leave empty to skip" maxlength="350" autocomplete="off">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
<input type="text" class="form-control" name="password" placeholder="Leave empty to skip" maxlength="350" autocomplete="off">
</div>
</div>
</div>
</div>
@@ -364,7 +456,10 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
<?php if ($asset_photo) { ?>
<div class="mb-2"><img class="img-thumbnail" style="max-height: 7rem" alt="Current photo" src="<?= "../uploads/clients/$client_id/$asset_photo" ?>"></div>
<?php } ?>
<input type="file" class="form-control" name="file" accept="image/jpeg,image/png,image/gif,image/webp">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-camera fa-fw"></i></span>
<input type="file" class="form-control" name="file" accept="image/jpeg,image/png,image/gif,image/webp">
</div>
<?php if ($asset_photo) { ?>
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" name="remove_photo" value="1" id="assetFormRemovePhoto">
@@ -429,6 +524,45 @@ $asset_ip_is_dhcp = $asset_ip === 'DHCP';
bootstrap.Tab.getOrCreateInstance(tab).show();
}, true);
// Leading icons that follow the field: the status colour, the OS
// brand, the kind of link
var icons = {
status: <?= json_encode($status_colors, JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>,
os: <?= json_encode(assetOsIconMap(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>,
link: <?= json_encode(assetLinkIconMap(), JSON_HEX_TAG | JSON_HEX_AMP | JSON_HEX_APOS | JSON_HEX_QUOT) ?>
};
function setIcon(icon, classes) {
icon.className = classes + ' fa-fw';
}
function follow(field, kind, update) {
var group = field.closest('.input-group');
var icon = group && group.querySelector('[data-asset-form-icon="' + kind + '"]');
if (!icon) {
return;
}
['input', 'change'].forEach(function (type) {
field.addEventListener(type, function () {
update(icon, field.value);
});
});
}
follow(form.querySelector('[name="status"]'), 'status', function (icon, value) {
icon.style.color = icons.status[value] || 'var(--bs-secondary-color)';
});
follow(osInput, 'os', function (icon, value) {
var os = value.toLowerCase();
var match = Object.keys(icons.os).find(function (needle) {
return os.indexOf(needle) !== -1;
});
setIcon(icon, match ? icons.os[match] : 'fas fa-compact-disc');
});
form.querySelectorAll('[name="uri"], [name="uri_2"]').forEach(function (field) {
follow(field, 'link', function (icon, value) {
var scheme = (value.match(/^([a-z][a-z0-9+.-]*):/i) || [])[1];
setIcon(icon, value.trim() === '' ? 'fas fa-link' : (icons.link[(scheme || '').toLowerCase()] || 'fas fa-external-link-alt'));
});
});
// DHCP means no fixed address to type
var dhcp = form.querySelector('#assetFormDhcp');
var ip = form.querySelector('#assetFormIp');

View File

@@ -38,7 +38,7 @@ $outstanding_balance = floatval($row['balance']);
// document, so the same people who would get the invoice get the statement.
$sql_contacts = mysqli_query(
$mysqli,
"SELECT contact_billing, contact_email, contact_id, contact_name, contact_primary, contact_title
"SELECT contact_billing, contact_email, contact_id, contact_photo, contact_name, contact_primary, contact_title
FROM contacts
WHERE contact_client_id = $client_id
AND contact_archived_at IS NULL
@@ -140,29 +140,24 @@ ob_start();
$contact_name = escapeHtml($row['contact_name']);
$contact_email = escapeHtml($row['contact_email']);
$contact_title = escapeHtml($row['contact_title']);
$contact_primary = intval($row['contact_primary']);
$contact_billing = intval($row['contact_billing']);
$contact_checked = in_array($contact_id, $default_contact_ids, true);
?>
<label class="list-group-item" for="statementContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input me-2" name="contacts[]"
<label class="list-group-item d-flex align-items-center gap-2" for="statementContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input flex-shrink-0 m-0" name="contacts[]"
id="statementContact<?= $contact_id ?>" value="<?= $contact_id ?>"
<?php if ($contact_checked) { echo "checked"; } ?>>
<strong><?= $contact_name ?></strong>
<?php if ($contact_primary == 1) { ?>
<span class="badge text-bg-primary ms-1">Primary</span>
<?php } ?>
<?php if ($contact_billing == 1) { ?>
<span class="badge text-bg-success ms-1">Billing</span>
<?php } ?>
<?php if (!empty($contact_title)) { ?>
<span class="text-muted ms-1"><?= $contact_title ?></span>
<?php } ?>
<br>
<span class="text-muted ms-4"><?= $contact_email ?></span>
<?= contactAvatar($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], 'sm') ?>
<span class="min-w-0">
<span class="d-flex flex-wrap align-items-center column-gap-1">
<strong><?= $contact_name ?></strong>
<?= contactFlagPills($row, false) ?>
<?php if ($contact_title) { ?><span class="text-body-secondary small"><?= $contact_title ?></span><?php } ?>
</span>
<span class="d-block small text-body-secondary text-truncate"><?= $contact_email ?></span>
</span>
</label>
<?php

File diff suppressed because it is too large Load Diff

View File

@@ -2,33 +2,37 @@
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_client', 2);
$client_id = intval($_GET['client_id'] ?? 0);
// Opened from an "Add Primary Contact" link, so the box below starts ticked.
// A default, not a lock - it is still a normal checkbox.
$contact_primary_default = !empty($_GET['primary']);
if ($client_id) {
$sql_location_select = mysqli_query($mysqli, "SELECT location_id, location_name FROM locations WHERE location_archived_at IS NULL AND location_client_id = $client_id ORDER BY location_name ASC");
} else {
$sql_client_select = mysqli_query($mysqli, "SELECT client_id, client_name FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
enforceClientAccess();
}
$sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name FROM tags WHERE tag_type = 3 ORDER BY tag_name ASC");
// Opened from an "Add Primary Contact" link, so the Primary switch starts on.
// A default, not a lock - it is still a normal switch.
$contact_primary_default = !empty($_GET['primary']);
// A contact's phone belongs to the CLIENT's country, not the company's. The
// client's country lives on its primary location; falls through to the
// company default when the client has none.
$client_phone_iso2 = '';
if ($client_id) {
$sql_client_country = mysqli_query($mysqli, "SELECT location_country FROM locations
WHERE location_client_id = $client_id AND location_primary = 1 LIMIT 1");
$row_client_country = mysqli_fetch_assoc($sql_client_country);
$row_client_country = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT location_country FROM locations
WHERE location_client_id = $client_id AND location_primary = 1 LIMIT 1"));
if ($row_client_country) {
$client_phone_iso2 = $country_iso2_array[$row_client_country['location_country']] ?? '';
}
}
$contact_form_mode = 'add';
$contact_id = 0;
$contact_name = $contact_title = $contact_department = $contact_email = $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;
$contact_location_id = 0;
$auth_method = '';
$contact_tag_id_array = [];
ob_start();
@@ -41,316 +45,18 @@ ob_start();
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off"
data-itflow-phone-country="<?= escapeHtml($client_phone_iso2) ?>">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php if ($client_id) { ?>
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<?php } ?>
<div class="modal-body">
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-details"><i class="fas fa-fw fa-user me-2"></i>Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-photo"><i class="fas fa-fw fa-image me-2"></i>Photo</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-access"><i class="fas fa-fw fa-lock me-2"></i>Access</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-notes"><i class="fas fa-fw fa-edit me-2"></i>Notes</a>
</li>
</ul>
<hr>
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-details">
<?php if ($client_id) { ?>
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<?php } else { ?>
<div class="mb-3">
<label>Client <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<select class="form-select select2" name="client_id" required>
<option value="">- Select Client -</option>
<?php
while ($row = mysqli_fetch_assoc($sql_client_select)) {
$client_id_select = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']); ?>
<option <?php if ($client_id_select == $client_id) { echo "selected"; } ?> value="<?= $client_id_select ?>"><?= $client_name ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong> / <span class="text-secondary">Primary Contact</span></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="name" placeholder="Full Name" maxlength="200" required autofocus>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="contact_primary" value="1"<?= $contact_primary_default ? ' checked' : '' ?>>
</div>
</div>
</div>
<div class="mb-3">
<label>Title</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-badge"></i></span>
<input type="text" class="form-control" name="title" placeholder="Job Title" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Department / Group</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
<input type="text" class="form-control" name="department" placeholder="Department or group" maxlength="200">
</div>
</div>
<label>Phone / <span class="text-secondary">Extension</span></label>
<div class="row g-2">
<div class="col-9">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-phone"></i></span>
<input type="hidden" name="phone_country_code">
<input type="tel" class="form-control" name="phone" placeholder="Phone Number" maxlength="200" data-itflow-phone="phone_country_code">
</div>
</div>
</div>
<div class="col-3">
<div class="mb-3">
<input type="text" class="form-control" name="extension" placeholder="ext." maxlength="200">
</div>
</div>
</div>
<label>Mobile</label>
<div class="row g-2">
<div class="col-9">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-mobile-alt"></i></span>
<input type="hidden" name="mobile_country_code">
<input type="tel" class="form-control" name="mobile" placeholder="Mobile Phone Number" maxlength="200" data-itflow-phone="mobile_country_code">
</div>
</div>
</div>
</div>
<div class="mb-3">
<label>Email</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
<input type="email" class="form-control" name="email" id="contact_email" placeholder="Email Address" maxlength="200" onfocusout="checkContactEmail()">
</div>
<div class="mt-2">
<span class="text-info" id="contact_check_info"></span>
</div>
</div>
<?php if($client_id) { ?>
<div class="mb-3">
<label>Location</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-map-marker-alt"></i></span>
<select class="form-select select2" name="location">
<option value="">- Select Location -</option>
<?php
while ($row = mysqli_fetch_assoc($sql_location_select)) {
$location_id = intval($row['location_id']);
$location_name = escapeHtml($row['location_name']);
?>
<option value="<?= $location_id ?>"><?= $location_name ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
</div>
<div class="tab-pane fade" id="pills-photo">
<div class="mb-3">
<label>Upload Photo</label>
<input type="file" class="form-control" name="file" accept="image/*">
</div>
</div>
<div class="tab-pane fade" id="pills-access">
<div class="mb-3">
<label>Pin</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<input type="text" class="form-control" name="pin" placeholder="Security code or pin" maxlength="255">
</div>
</div>
<?php if ($config_client_portal_enable == 1) { ?>
<div class="authForm">
<div class="mb-3">
<label>Client Portal</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user-circle"></i></span>
<select class="form-select select2 authMethod" name="auth_method">
<option value="">- No Access -</option>
<option value="local">Using Set Password</option>
<option value="azure">Using Azure Credentials</option>
</select>
</div>
</div>
<div class="mb-3 passwordGroup" style="display: none;">
<label>Password</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
<input type="password" class="form-control" data-toggle="password" id="password" name="contact_password" placeholder="Password" autocomplete="new-password">
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
<button type="button" class="btn btn-default" title="Generate password" onclick="generatePassword()">
<i class="fa fa-fw fa-question"></i>
</button>
</div>
</div>
</div>
<?php } ?>
<label>Roles:</label>
<div class="row g-2">
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactImportantCheckbox" name="contact_important" value="1">
<label class="form-check-label" for="contactImportantCheckbox">Important</label>
<p class="text-secondary"><small>Pin Top</small></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactBillingCheckbox" name="contact_billing" value="1">
<label class="form-check-label" for="contactBillingCheckbox">Billing</label>
<p class="text-secondary"><small>Receives Invoices</small></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactTechnicalCheckbox" name="contact_technical" value="1">
<label class="form-check-label" for="contactTechnicalCheckbox">Technical</label>
<p class="text-secondary"><small>Access </small></p>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-notes">
<div class="mb-3">
<textarea class="form-control" rows="8" name="notes" placeholder="Enter some notes"></textarea>
</div>
<div class="mb-3">
<label>Tags</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
<select class="form-select select2" name="tags[]" data-placeholder="Add some tags" multiple>
<?php
while ($row = mysqli_fetch_assoc($sql_tags_select)) {
$tag_id = intval($row['tag_id']);
$tag_name = escapeHtml($row['tag_name']);
?>
<option value="<?= $tag_id ?>"><?= $tag_name ?></option>
<?php } ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New tag" type="button"
data-modal-url="../admin/modals/tag/tag_add.php?type=3">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
</div>
</div>
<?php require 'contact_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="add_contact" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Create</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<!-- JavaScript to Show/Hide Password Form Group -->
<script>
function generatePassword() {
itflowGet(
"ajax.php", {
get_readable_pass: 'true'
},
function(data) {
const password = JSON.parse(data);
document.getElementById("password").value = password;
}
);
}
itflowReady(function () {
function syncAuthForm(select) {
var form = select.closest('.authForm');
if (!form) {
return;
}
form.querySelectorAll('.passwordGroup').forEach(function (group) {
group.style.display = select.value === 'local' ? '' : 'none';
});
}
document.querySelectorAll('.authMethod').forEach(function (select) {
select.addEventListener('change', function () {
syncAuthForm(this);
});
syncAuthForm(select);
});
});
</script>
<script>
// Checks contact emails
function checkContactEmail() {
var email = document.getElementById("contact_email").value;
//Send a GET request to ajax.php as ajax.php?contact_email_check=true&email=email
itflowGet(
"ajax.php",
{contact_email_check: 'true', email: email},
function(data) {
//If we get a response from ajax.php, parse it as JSON
const contact_check_data = JSON.parse(data);
document.getElementById("contact_check_info").innerHTML = contact_check_data.message;
}
);
}
</script>
<?php

View File

@@ -4,73 +4,68 @@ require_once '../../../includes/modal_header.php';
enforceUserPermission('module_client', 2);
$contact_id = intval($_GET['id']);
$contact_id = intval($_GET['id'] ?? 0);
$sql = mysqli_query($mysqli, "SELECT contact_archived_at, contact_billing, contact_client_id, contact_created_at,
contact_department, contact_email, 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
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_billing, contact_client_id, contact_department, contact_email,
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
LEFT JOIN users ON user_id = contact_user_id
WHERE contact_id = $contact_id
LIMIT 1"
);
$row = mysqli_fetch_assoc($sql);
));
if (!$row) {
echo json_encode(['error' => 'That contact no longer exists.']);
exit;
}
$client_id = intval($row['contact_client_id']);
enforceClientAccess();
// A contact's phone belongs to the CLIENT's country, not the company's. The
// client's country lives on its primary location; falls through to the
// company default when the client has none.
$client_phone_iso2 = '';
if ($client_id) {
$sql_client_country = mysqli_query($mysqli, "SELECT location_country FROM locations
WHERE location_client_id = $client_id AND location_primary = 1 LIMIT 1");
$row_client_country = mysqli_fetch_assoc($sql_client_country);
if ($row_client_country) {
$client_phone_iso2 = $country_iso2_array[$row_client_country['location_country']] ?? '';
}
$row_client_country = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT location_country FROM locations
WHERE location_client_id = $client_id AND location_primary = 1 LIMIT 1"));
if ($row_client_country) {
$client_phone_iso2 = $country_iso2_array[$row_client_country['location_country']] ?? '';
}
$contact_form_mode = 'edit';
$contact_primary_default = false;
$contact_name = escapeHtml($row['contact_name']);
$contact_title = escapeHtml($row['contact_title']);
$contact_department = escapeHtml($row['contact_department']);
$contact_extension = escapeHtml($row['contact_extension']);
$contact_phone_country_code = escapeHtml($row['contact_phone_country_code']);
$contact_phone = escapeHtml(formatPhoneNumber($row['contact_phone'], $contact_phone_country_code, false));
$contact_phone = escapeHtml(formatPhoneNumber($row['contact_phone'], $row['contact_phone_country_code'], false));
$contact_mobile_country_code = escapeHtml($row['contact_mobile_country_code']);
$contact_mobile = escapeHtml(formatPhoneNumber($row['contact_mobile'], $contact_mobile_country_code, false));
$contact_mobile = escapeHtml(formatPhoneNumber($row['contact_mobile'], $row['contact_mobile_country_code'], false));
$contact_email = escapeHtml($row['contact_email']);
$contact_pin = escapeHtml($row['contact_pin']);
$contact_photo = escapeHtml($row['contact_photo']);
$contact_initials = initials($contact_name);
$contact_notes = escapeHtml($row['contact_notes']);
$contact_primary = intval($row['contact_primary']);
$contact_important = intval($row['contact_important']);
$contact_billing = intval($row['contact_billing']);
$contact_technical = intval($row['contact_technical']);
$contact_created_at = escapeHtml($row['contact_created_at']);
$contact_archived_at = escapeHtml($row['contact_archived_at']);
$contact_location_id = intval($row['contact_location_id']);
$auth_method = escapeHtml($row['user_auth_method']);
$contact_user_id = intval($row['contact_user_id']);
$auth_method = intval($row['contact_user_id']) ? (string) $row['user_auth_method'] : '';
// Tags
$contact_tag_id_array = array();
$contact_tag_id_array = [];
$sql_contact_tags = mysqli_query($mysqli, "SELECT tag_id FROM contact_tags WHERE contact_id = $contact_id");
while ($row = mysqli_fetch_assoc($sql_contact_tags)) {
$contact_tag_id = intval($row['tag_id']);
$contact_tag_id_array[] = $contact_tag_id;
$contact_tag_id_array[] = intval($row['tag_id']);
}
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class='fas fa-user-edit me-2'></i>Editing Contact: <strong><?= $contact_name ?></strong></h5>
<h5 class="modal-title"><i class="fas fa-fw fa-user-edit me-2"></i>Editing contact: <strong><?= $contact_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" enctype="multipart/form-data" autocomplete="off"
@@ -79,256 +74,7 @@ ob_start();
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
<div class="modal-body">
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-details<?= $contact_id ?>"><i class="fa fa-fw fa-id-badge me-2"></i>Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-photo<?= $contact_id ?>"><i class="fa fa-fw fa-image me-2"></i>Photo</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-access<?= $contact_id ?>"><i class="fa fa-fw fa-lock me-2"></i>Access</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-notes<?= $contact_id ?>"><i class="fa fa-fw fa-edit me-2"></i>Notes</a>
</li>
</ul>
<hr>
<div class="tab-content">
<div class="tab-pane fade show active" id="pills-details<?= $contact_id ?>">
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong> / <span class="text-secondary">Primary Contact</span></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user"></i></span>
<input type="text" class="form-control" name="name" placeholder="Full Name" maxlength="200" value="<?= $contact_name ?>" required>
<div class="input-group-text">
<input class="form-check-input" type="checkbox" name="contact_primary" value="1" <?php if ($contact_primary == 1) { echo "checked"; } ?>>
</div>
</div>
</div>
<div class="mb-3">
<label>Title</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-id-badge"></i></span>
<input type="text" class="form-control" name="title" placeholder="Title" maxlength="200" value="<?= $contact_title ?>">
</div>
</div>
<div class="mb-3">
<label>Department / Group</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-users"></i></span>
<input type="text" class="form-control" name="department" placeholder="Department or group" maxlength="200" value="<?= $contact_department ?>">
</div>
</div>
<label>Phone / <span class="text-secondary">Extension</span></label>
<div class="row g-2">
<div class="col-9">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-phone"></i></span>
<input type="hidden" name="phone_country_code" value="<?= "$contact_phone_country_code" ?>">
<input type="tel" class="form-control" name="phone" value="<?= $contact_phone ?>" placeholder="Phone Number" maxlength="200" data-itflow-phone="phone_country_code">
</div>
</div>
</div>
<div class="col-3">
<div class="mb-3">
<input type="text" class="form-control" name="extension" value="<?= $contact_extension ?>" placeholder="ext." maxlength="200">
</div>
</div>
</div>
<label>Mobile</label>
<div class="row g-2">
<div class="col-9">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-mobile-alt"></i></span>
<input type="hidden" name="mobile_country_code" value="<?= "$contact_mobile_country_code" ?>">
<input type="tel" class="form-control" name="mobile" value="<?= $contact_mobile ?>" placeholder="Phone Number" maxlength="200" data-itflow-phone="mobile_country_code">
</div>
</div>
</div>
</div>
<div class="mb-3">
<label>Email</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-envelope"></i></span>
<input type="email" class="form-control" name="email" placeholder="Email Address" maxlength="200" value="<?= $contact_email ?>">
</div>
</div>
<div class="mb-3">
<label>Location</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-map-marker-alt"></i></span>
<select class="form-select select2" name="location">
<option value="">- Select Location -</option>
<?php
$sql_locations = mysqli_query($mysqli, "SELECT location_archived_at, location_id, location_name FROM locations WHERE location_id = $contact_location_id OR location_archived_at IS NULL AND location_client_id = $client_id ORDER BY location_name ASC");
while ($row = mysqli_fetch_assoc($sql_locations)) {
$location_id_select = intval($row['location_id']);
$location_name_select = escapeHtml($row['location_name']);
$location_archived_at = escapeHtml($row['location_archived_at']);
if ($location_archived_at) {
$location_name_select_display = "($location_name_select) - ARCHIVED";
} else {
$location_name_select_display = $location_name_select;
}
?>
<option <?php if ($contact_location_id == $location_id_select) {
echo "selected";
} ?> value="<?= $location_id_select ?>"><?= $location_name_select_display ?></option>
<?php } ?>
</select>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-access<?= $contact_id ?>">
<div class="mb-3">
<label>Pin</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-key"></i></span>
<input type="text" class="form-control" name="pin" placeholder="Security code or pin" maxlength="255" value="<?= $contact_pin ?>">
</div>
</div>
<?php if ($config_client_portal_enable == 1) { ?>
<div class="authForm">
<div class="mb-3">
<label>Client Portal</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-user-circle"></i></span>
<select class="form-select select2 authMethod" name="auth_method">
<option value="">- No Access -</option>
<option value="local" <?php if ($auth_method == "local") { echo "selected"; } ?>>Using Set Password</option>
<option value="azure" <?php if ($auth_method == "azure") { echo "selected"; } ?>>Using Azure Credentials</option>
</select>
</div>
</div>
<div class="mb-3 passwordGroup" style="display: none;">
<label>Password <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-lock"></i></span>
<input type="password" class="form-control" data-toggle="password" id="password" name="contact_password" placeholder="Password" autocomplete="new-password">
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
<button type="button" class="btn btn-default" title="Generate password" onclick="generatePassword()">
<i class="fa fa-fw fa-question"></i>
</button>
</div>
</div>
</div>
<div class="form-check">
<input type="checkbox" class="form-check-input" name="send_email" value="1" />
<label class="form-check-label">Send user e-mail with login details?</label>
</div>
<?php } ?>
<label>Roles:</label>
<div class="row g-2">
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactImportantCheckbox<?= $contact_id ?>" name="contact_important" value="1" <?php if ($contact_important == 1) { echo "checked"; } ?>>
<label class="form-check-label" for="contactImportantCheckbox<?= $contact_id ?>">Important</label>
<p class="text-secondary"><small>Pin Top</small></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactBillingCheckbox<?= $contact_id ?>" name="contact_billing" value="1" <?php if ($contact_billing == 1) { echo "checked"; } ?>>
<label class="form-check-label" for="contactBillingCheckbox<?= $contact_id ?>">Billing</label>
<p class="text-secondary"><small>Receives Invoices</small></p>
</div>
</div>
</div>
<div class="col-md-4">
<div class="mb-3">
<div class="form-check">
<input type="checkbox" class="form-check-input" id="contactTechnicalCheckbox<?= $contact_id ?>" name="contact_technical" value="1" <?php if ($contact_technical == 1) { echo "checked"; } ?>>
<label class="form-check-label" for="contactTechnicalCheckbox<?= $contact_id ?>">Technical</label>
</div>
</div>
</div>
</div>
</div>
<div class="tab-pane fade" id="pills-photo<?= $contact_id ?>">
<div class="mb-3 text-center">
<?php if ($contact_photo) { ?>
<img class="img-fluid" alt="contact_photo" src="<?= "../uploads/clients/$client_id/$contact_photo" ?>">
<?php } else { ?>
<span class="fa-stack fa-4x">
<i class="fa fa-circle fa-stack-2x text-secondary"></i>
<span class="fa fa-stack-1x text-white"><?= $contact_initials ?></span>
</span>
<?php } ?>
</div>
<div class="mb-3">
<input type="file" class="form-control" name="file" accept="image/*">
</div>
</div>
<div class="tab-pane fade" id="pills-notes<?= $contact_id ?>">
<div class="mb-3">
<textarea class="form-control" rows="8" name="notes" placeholder="Notes, eg Personal tidbits to spark convo, temperment, etc"><?= $contact_notes ?></textarea>
</div>
<div class="mb-3">
<label>Tags</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-tags"></i></span>
<select class="form-select select2" name="tags[]" data-placeholder="Add some tags" multiple>
<?php
$sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, tag_icon FROM tags WHERE tag_type = 3 ORDER BY tag_name ASC");
while ($row = mysqli_fetch_assoc($sql_tags_select)) {
$tag_id_select = intval($row['tag_id']);
$tag_name_select = escapeHtml($row['tag_name']);
?>
<option value="<?= $tag_id_select ?>" <?php if (in_array($tag_id_select, $contact_tag_id_array)) { echo "selected"; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= $tag_name_select ?></option>
<?php } ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New tag" type="button"
data-modal-url="../admin/modals/tag/tag_add.php?type=3">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<p class="text-muted text-end">Contact ID: <?= $contact_id ?></p>
</div>
</div>
<?php require 'contact_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="edit_contact" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Save</button>
@@ -336,43 +82,6 @@ ob_start();
</div>
</form>
<!-- JavaScript to Show/Hide Password Form Group -->
<script>
function generatePassword() {
itflowGet(
"ajax.php", {
get_readable_pass: 'true'
},
function(data) {
const password = JSON.parse(data);
document.getElementById("password").value = password;
}
);
}
itflowReady(function () {
function syncAuthForm(select) {
var form = select.closest('.authForm');
if (!form) {
return;
}
form.querySelectorAll('.passwordGroup').forEach(function (group) {
group.style.display = select.value === 'local' ? '' : 'none';
});
}
document.querySelectorAll('.authMethod').forEach(function (select) {
select.addEventListener('change', function () {
syncAuthForm(this);
});
syncAuthForm(select);
});
});
</script>
<?php
require_once '../../../includes/modal_footer.php';
?>

View File

@@ -0,0 +1,335 @@
<?php
/*
* Contact form fields - shared by contact_add.php and contact_edit.php, which
* set $contact_form_mode ('add' | 'edit'), $client_id (0 = pick the client
* here) and the $contact_* values (escaped, empty for a new contact) before
* including this. Posts the field set agent/post/contact_model.php reads.
*
* Tabs like the other add / edit modals: Details (who and how to reach them),
* Roles (primary, important, billing, technical), Access (PIN and the client
* portal) and Notes (photo, notes, tags).
*
* Should not be accessed directly.
*/
isset($mysqli) || die("Direct file access is not allowed");
// The client's locations - only once the client is known
$location_options = [];
if ($client_id) {
$sql = mysqli_query($mysqli, "SELECT location_archived_at, location_id, location_name, location_primary FROM locations
WHERE location_client_id = $client_id AND (location_archived_at IS NULL OR location_id = $contact_location_id)
ORDER BY location_primary DESC, location_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$location_options[] = $row;
}
} else {
$client_options = [];
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients WHERE client_archived_at IS NULL " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$client_options[] = $row;
}
}
$sql_tags_select = mysqli_query($mysqli, "SELECT tag_id, tag_name, tag_color, tag_icon FROM tags WHERE tag_type = 3 ORDER BY tag_name ASC");
// The roles, with what each one does
$contact_roles = [
'contact_important' => ['label' => 'Important', 'icon' => 'fa-star', 'value' => $contact_important, 'help' => 'Pinned to the top of the contacts list.'],
'contact_billing' => ['label' => 'Billing', 'icon' => 'fa-file-invoice-dollar', 'value' => $contact_billing, 'help' => 'Receives invoices and quotes.'],
'contact_technical' => ['label' => 'Technical', 'icon' => 'fa-tools', 'value' => $contact_technical, 'help' => 'Who to talk to about the technical side.'],
];
?>
<!-- Tabs, like the other add / edit modals -->
<ul class="nav nav-pills nav-fill flex-nowrap overflow-auto mb-3 itflow-asset-form-tabs" role="tablist">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#contactFormDetails"><i class="fas fa-fw fa-id-badge me-2 d-none d-sm-inline"></i>Details</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#contactFormRoles"><i class="fas fa-fw fa-user-tag me-2 d-none d-sm-inline"></i>Roles</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#contactFormAccess"><i class="fas fa-fw fa-lock me-2 d-none d-sm-inline"></i>Access</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#contactFormNotes"><i class="fas fa-fw fa-sticky-note me-2 d-none d-sm-inline"></i>Notes</a>
</li>
</ul>
<div class="tab-content">
<!-- Who they are and how to reach them -->
<div class="tab-pane fade show active" id="contactFormDetails">
<div class="row g-3">
<?php if (!$client_id) { ?>
<div class="col-12">
<label class="form-label">Client <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-users fa-fw"></i></span>
<select class="form-select select2" name="client_id" required>
<option value="">- Select Client -</option>
<?php foreach ($client_options as $client_option) { ?>
<option value="<?= intval($client_option['client_id']) ?>"<?= selectOptionClient($client_option['client_id'], $client_option['client_name'], $client_option['client_abbreviation'] ?? '') ?>><?= escapeHtml($client_option['client_name']) ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">Pick their location once they're saved.</div>
</div>
<?php } ?>
<div class="col-md-6">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-user fa-fw"></i></span>
<input type="text" class="form-control" name="name" placeholder="Full name" maxlength="200" value="<?= $contact_name ?>" required <?= $contact_form_mode === 'add' ? 'autofocus' : '' ?>>
</div>
</div>
<div class="col-md-6">
<label class="form-label">Title</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-id-badge fa-fw"></i></span>
<input type="text" class="form-control" name="title" placeholder="Office Manager" maxlength="200" value="<?= $contact_title ?>">
</div>
</div>
<div class="col-md-6">
<label class="form-label">Department / group</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-sitemap fa-fw"></i></span>
<input type="text" class="form-control" name="department" placeholder="Accounting" maxlength="200" value="<?= $contact_department ?>">
</div>
</div>
<?php if ($client_id) { ?>
<div class="col-md-6">
<label class="form-label">Location</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-map-marker-alt fa-fw"></i></span>
<select class="form-select select2" name="location">
<option value="">- Select Location -</option>
<?php foreach ($location_options as $location_option) {
$location_option_id = intval($location_option['location_id']); ?>
<option value="<?= $location_option_id ?>" <?php if ($contact_location_id === $location_option_id) { echo "selected"; } ?><?= selectOptionData(['description' => $location_option['location_primary'] ? 'Primary' : '']) ?>><?= escapeHtml($location_option['location_name']) ?><?= $location_option['location_archived_at'] ? ' (archived)' : '' ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="col-12"><div class="itflow-form-section mb-0 mt-2">Reach</div></div>
<div class="col-md-8">
<label class="form-label">Phone</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-phone fa-fw"></i></span>
<input type="hidden" name="phone_country_code" value="<?= $contact_phone_country_code ?>">
<input type="tel" class="form-control" name="phone" value="<?= $contact_phone ?>" placeholder="Phone number" maxlength="200" data-itflow-phone="phone_country_code">
</div>
</div>
<div class="col-md-4">
<label class="form-label">Extension</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-hashtag fa-fw"></i></span>
<input type="text" class="form-control" name="extension" value="<?= $contact_extension ?>" placeholder="114" maxlength="200" inputmode="numeric">
</div>
</div>
<div class="col-md-8">
<label class="form-label">Mobile</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-mobile-alt fa-fw"></i></span>
<input type="hidden" name="mobile_country_code" value="<?= $contact_mobile_country_code ?>">
<input type="tel" class="form-control" name="mobile" value="<?= $contact_mobile ?>" placeholder="Mobile number" maxlength="200" data-itflow-phone="mobile_country_code">
</div>
</div>
<div class="col-12">
<label class="form-label">Email</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-envelope fa-fw"></i></span>
<input type="email" class="form-control" name="email" id="contactFormEmail" placeholder="name@example.com" maxlength="200" value="<?= $contact_email ?>">
</div>
<?php if ($contact_form_mode === 'add') { ?>
<div class="form-text text-info" id="contactFormEmailCheck"></div>
<?php } ?>
</div>
</div>
<?php if ($contact_form_mode === 'edit') { ?>
<p class="text-body-secondary small text-end mt-3 mb-0">Contact ID <span class="font-monospace"><?= $contact_id ?></span></p>
<?php } ?>
</div>
<!-- What they are to the client -->
<div class="tab-pane fade" id="contactFormRoles">
<div class="list-group">
<label class="list-group-item form-switch d-flex gap-3 align-items-start py-3 ps-3">
<input class="form-check-input flex-shrink-0 mt-1 ms-0" type="checkbox" role="switch" name="contact_primary" value="1"
<?= $contact_primary ? 'checked disabled' : ($contact_primary_default ? 'checked' : '') ?>>
<span>
<span class="fw-semibold"><i class="fas fa-fw fa-crown text-success me-1"></i>Primary contact</span>
<span class="d-block small text-body-secondary">
<?= $contact_primary
? 'The client\'s main contact. To change it, make someone else primary.'
: 'The client\'s main contact - one per client, and always important. Takes over from the current primary contact.' ?>
</span>
</span>
</label>
<?php foreach ($contact_roles as $role_name => $role) { ?>
<label class="list-group-item form-switch d-flex gap-3 align-items-start py-3 ps-3">
<input class="form-check-input flex-shrink-0 mt-1 ms-0" type="checkbox" role="switch" name="<?= $role_name ?>" value="1" <?= $role['value'] ? 'checked' : '' ?>>
<span>
<span class="fw-semibold"><i class="fas fa-fw <?= $role['icon'] ?> text-secondary me-1"></i><?= $role['label'] ?></span>
<span class="d-block small text-body-secondary"><?= $role['help'] ?></span>
</span>
</label>
<?php } ?>
</div>
</div>
<!-- How we know it's them, and the client portal -->
<div class="tab-pane fade" id="contactFormAccess">
<div class="row g-3">
<div class="col-12">
<label class="form-label">PIN</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-key fa-fw"></i></span>
<input type="text" class="form-control font-monospace" name="pin" placeholder="Security code or PIN" maxlength="255" value="<?= $contact_pin ?>" autocomplete="off">
</div>
<div class="form-text">Ask for it to verify who's calling.</div>
</div>
<?php if ($config_client_portal_enable == 1) { ?>
<div class="col-12"><div class="itflow-form-section mb-0 mt-2">Client portal</div></div>
<div class="col-12 authForm">
<label class="form-label">Login</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-user-circle fa-fw"></i></span>
<select class="form-select select2 authMethod" name="auth_method">
<option value="">- No access -</option>
<option value="local" <?php if ($auth_method === 'local') { echo "selected"; } ?>>With a password</option>
<option value="azure" <?php if ($auth_method === 'azure') { echo "selected"; } ?>>With their Microsoft (Entra ID) account</option>
</select>
</div>
<div class="mt-3 passwordGroup" style="display: none;">
<label class="form-label">Password<?= $contact_form_mode === 'add' ? '' : ' <span class="text-body-secondary fw-normal">- leave empty to keep the current one</span>' ?></label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-lock fa-fw"></i></span>
<input type="password" class="form-control" data-toggle="password" id="contactFormPassword" name="contact_password" placeholder="Password" autocomplete="new-password">
<span class="input-group-text"><i class="fa fa-fw fa-eye"></i></span>
<button type="button" class="btn btn-outline-secondary" title="Generate a password" data-contact-form-generate>
<i class="fas fa-fw fa-magic"></i>
</button>
</div>
<div class="form-text">Leave it empty and they can set their own with a password reset.</div>
</div>
<?php if ($contact_form_mode === 'edit') { ?>
<div class="form-check mt-3">
<input type="checkbox" class="form-check-input" name="send_email" value="1" id="contactFormSendEmail">
<label class="form-check-label" for="contactFormSendEmail">Email them their login details</label>
</div>
<?php } ?>
</div>
<?php } ?>
</div>
</div>
<!-- Photo, notes and tags -->
<div class="tab-pane fade" id="contactFormNotes">
<div class="row g-3">
<div class="col-12">
<label class="form-label">Notes</label>
<textarea class="form-control" rows="6" name="notes" placeholder="Personal tidbits, how they like to be contacted, anything worth knowing"><?= $contact_notes ?></textarea>
</div>
<div class="col-12">
<label class="form-label">Tags</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-tags fa-fw"></i></span>
<select class="form-select select2" name="tags[]" data-placeholder="Add some tags" multiple>
<?php while ($row = mysqli_fetch_assoc($sql_tags_select)) {
$tag_id_select = intval($row['tag_id']); ?>
<option value="<?= $tag_id_select ?>" <?php if (in_array($tag_id_select, $contact_tag_id_array)) { echo "selected"; } ?><?= selectOptionColor($row['tag_color'] ?? '', $row['tag_icon'] ?? '') ?>><?= escapeHtml($row['tag_name']) ?></option>
<?php } ?>
</select>
<button class="btn btn-secondary ajax-modal" title="New tag" type="button" data-modal-url="../admin/modals/tag/tag_add.php?type=3">
<i class="fas fa-plus"></i>
</button>
</div>
</div>
<div class="col-12">
<label class="form-label">Photo</label>
<div class="d-flex align-items-center gap-3">
<?= contactAvatar($client_id, $contact_id, html_entity_decode($contact_name), $contact_photo ? html_entity_decode($contact_photo) : '', 'lg') ?>
<div class="flex-grow-1">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-camera fa-fw"></i></span>
<input type="file" class="form-control" name="file" accept="image/jpeg,image/png,image/gif,image/webp">
</div>
<?php if ($contact_photo) { ?>
<div class="form-check mt-2">
<input class="form-check-input" type="checkbox" name="remove_photo" value="1" id="contactFormRemovePhoto">
<label class="form-check-label" for="contactFormRemovePhoto">Remove this photo</label>
</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
</div>
<script>
itflowReady(function () {
var form = document.getElementById('contactFormDetails').closest('form');
// Client portal: the password only matters for a password login
form.querySelectorAll('.authMethod').forEach(function (select) {
function sync() {
select.closest('.authForm').querySelectorAll('.passwordGroup').forEach(function (group) {
group.style.display = select.value === 'local' ? '' : 'none';
});
}
select.addEventListener('change', sync);
sync();
});
var generate = form.querySelector('[data-contact-form-generate]');
if (generate) {
generate.addEventListener('click', function () {
itflowGet('ajax.php', { get_readable_pass: 'true' }, function (data) {
form.querySelector('#contactFormPassword').value = JSON.parse(data);
});
});
}
// A new contact whose email is already on file somewhere
var emailCheck = form.querySelector('#contactFormEmailCheck');
if (emailCheck) {
form.querySelector('#contactFormEmail').addEventListener('change', function () {
var email = this.value.trim();
if (email === '') {
emailCheck.textContent = '';
return;
}
itflowGet('ajax.php', { contact_email_check: 'true', email: email }, function (data) {
emailCheck.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
var reported = false;
form.addEventListener('invalid', function (e) {
var pane = e.target.closest('.tab-pane');
var tab = pane && form.querySelector('[data-bs-toggle="pill"][href="#' + pane.id + '"]');
if (!tab || pane.classList.contains('active') || reported) {
return;
}
reported = true;
tab.addEventListener('shown.bs.tab', function () {
reported = false;
e.target.reportValidity();
}, { once: true });
bootstrap.Tab.getOrCreateInstance(tab).show();
}, true);
});
</script>

View File

@@ -146,7 +146,7 @@ ob_start();
?>
<option
<?php if ($contact_id == $contact_id_select) { echo "selected"; } ?>
value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= $contact_name ?>
value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name ?>
</option>
<?php

View File

@@ -163,7 +163,7 @@ ob_start();
$contact_id_select = intval($row['contact_id']);
$contact_name_select = escapeHtml($row['contact_name']);
?>
<option <?php if ($credential_contact_id == $contact_id_select) { echo "selected"; } ?> value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= $contact_name_select ?></option>
<option <?php if ($credential_contact_id == $contact_id_select) { echo "selected"; } ?> value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name_select ?></option>
<?php } ?>
</select>
</div>

View File

@@ -50,7 +50,7 @@ ob_start();
$contact_name = escapeHtml($row['contact_name']);
?>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= $contact_name ?></option>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name ?></option>
<?php
}
?>

View File

@@ -22,7 +22,7 @@ enforceClientAccess();
// go hunting for somebody.
$sql_contacts = mysqli_query(
$mysqli,
"SELECT contact_billing, contact_email, contact_id, contact_name, contact_primary, contact_title
"SELECT contact_billing, contact_email, contact_id, contact_photo, contact_name, contact_primary, contact_title
FROM contacts
WHERE contact_client_id = $client_id
AND contact_archived_at IS NULL
@@ -87,29 +87,24 @@ ob_start();
$contact_name = escapeHtml($row['contact_name']);
$contact_email = escapeHtml($row['contact_email']);
$contact_title = escapeHtml($row['contact_title']);
$contact_primary = intval($row['contact_primary']);
$contact_billing = intval($row['contact_billing']);
$contact_checked = in_array($contact_id, $default_contact_ids, true);
?>
<label class="list-group-item" for="invoiceEmailContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input me-2" name="contacts[]"
<label class="list-group-item d-flex align-items-center gap-2" for="invoiceEmailContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input flex-shrink-0 m-0" name="contacts[]"
id="invoiceEmailContact<?= $contact_id ?>" value="<?= $contact_id ?>"
<?php if ($contact_checked) { echo "checked"; } ?>>
<strong><?= $contact_name ?></strong>
<?php if ($contact_primary == 1) { ?>
<span class="badge text-bg-primary ms-1">Primary</span>
<?php } ?>
<?php if ($contact_billing == 1) { ?>
<span class="badge text-bg-success ms-1">Billing</span>
<?php } ?>
<?php if (!empty($contact_title)) { ?>
<span class="text-muted ms-1"><?= $contact_title ?></span>
<?php } ?>
<br>
<span class="text-muted ms-4"><?= $contact_email ?></span>
<?= contactAvatar($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], 'sm') ?>
<span class="min-w-0">
<span class="d-flex flex-wrap align-items-center column-gap-1">
<strong><?= $contact_name ?></strong>
<?= contactFlagPills($row, false) ?>
<?php if ($contact_title) { ?><span class="text-body-secondary small"><?= $contact_title ?></span><?php } ?>
</span>
<span class="d-block small text-body-secondary text-truncate"><?= $contact_email ?></span>
</span>
</label>
<?php

View File

@@ -158,7 +158,7 @@ ob_start();
$contact_id = $row['contact_id'];
$contact_name = escapeHtml($row['contact_name']);
?>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= $contact_name ?></option>
<option value="<?= $contact_id ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= $contact_name ?></option>
<?php } ?>
</select>

View File

@@ -182,7 +182,7 @@ ob_start();
}
?>
<option <?php if ($location_contact_id == $contact_id_select) { echo "selected"; } ?> value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= "$contact_archived_display$contact_name_select" ?></option>
<option <?php if ($location_contact_id == $contact_id_select) { echo "selected"; } ?> value="<?= $contact_id_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= "$contact_archived_display$contact_name_select" ?></option>
<?php } ?>
</select>

View File

@@ -20,7 +20,7 @@ enforceClientAccess();
// read by whoever scoped the work as often as by whoever signs it.
$sql_contacts = mysqli_query(
$mysqli,
"SELECT contact_billing, contact_email, contact_id, contact_important, contact_name,
"SELECT contact_billing, contact_email, contact_id, contact_photo, contact_important, contact_name,
contact_primary, contact_technical, contact_title
FROM contacts
WHERE contact_client_id = $client_id
@@ -86,37 +86,24 @@ ob_start();
$contact_name = escapeHtml($row['contact_name']);
$contact_email = escapeHtml($row['contact_email']);
$contact_title = escapeHtml($row['contact_title']);
$contact_primary = intval($row['contact_primary']);
$contact_billing = intval($row['contact_billing']);
$contact_technical = intval($row['contact_technical']);
$contact_important = intval($row['contact_important']);
$contact_checked = in_array($contact_id, $default_contact_ids, true);
?>
<label class="list-group-item" for="quoteEmailContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input me-2" name="contacts[]"
<label class="list-group-item d-flex align-items-center gap-2" for="quoteEmailContact<?= $contact_id ?>">
<input type="checkbox" class="form-check-input flex-shrink-0 m-0" name="contacts[]"
id="quoteEmailContact<?= $contact_id ?>" value="<?= $contact_id ?>"
<?php if ($contact_checked) { echo "checked"; } ?>>
<strong><?= $contact_name ?></strong>
<?php if ($contact_primary == 1) { ?>
<span class="badge text-bg-primary ms-1">Primary</span>
<?php } ?>
<?php if ($contact_billing == 1) { ?>
<span class="badge text-bg-success ms-1">Billing</span>
<?php } ?>
<?php if ($contact_technical == 1) { ?>
<span class="badge text-bg-info ms-1">Technical</span>
<?php } ?>
<?php if ($contact_important == 1) { ?>
<span class="badge text-bg-warning ms-1">Important</span>
<?php } ?>
<?php if (!empty($contact_title)) { ?>
<span class="text-muted ms-1"><?= $contact_title ?></span>
<?php } ?>
<br>
<span class="text-muted ms-4"><?= $contact_email ?></span>
<?= contactAvatar($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], 'sm') ?>
<span class="min-w-0">
<span class="d-flex flex-wrap align-items-center column-gap-1">
<strong><?= $contact_name ?></strong>
<?= contactFlagPills($row, false) ?>
<?php if ($contact_title) { ?><span class="text-body-secondary small"><?= $contact_title ?></span><?php } ?>
</span>
<span class="d-block small text-body-secondary text-truncate"><?= $contact_email ?></span>
</span>
</label>
<?php

View File

@@ -203,27 +203,9 @@ ob_start();
while ($row = mysqli_fetch_assoc($sql_client_contacts_select)) {
$contact_id_select = intval($row['contact_id']);
$contact_name_select = escapeHtml($row['contact_name']);
$contact_primary_select = intval($row['contact_primary']);
if($contact_primary_select == 1) {
$contact_primary_display_select = " (Primary)";
} else {
$contact_primary_display_select = "";
}
$contact_technical_select = intval($row['contact_technical']);
if($contact_technical_select == 1) {
$contact_technical_display_select = " (Technical)";
} else {
$contact_technical_display_select = "";
}
$contact_title_select = escapeHtml($row['contact_title']);
if(!empty($contact_title_select)) {
$contact_title_display_select = " - $contact_title_select";
} else {
$contact_title_display_select = "";
}
?>
<option value="<?= $contact_id_select ?>" <?php if ($contact_id_select == $recurring_ticket_contact_id) { echo "selected"; } ?><?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= "$contact_name_select$contact_title_display_select$contact_primary_display_select$contact_technical_display_select" ?></option>
<option value="<?= $contact_id_select ?>" <?php if ($contact_id_select == $recurring_ticket_contact_id) { echo "selected"; } ?><?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', contactOptionDescription($row), $row['contact_id'] ?? 0) ?>><?= $contact_name_select ?></option>
<?php } ?>
</select>
</div>

View File

@@ -81,7 +81,7 @@ $sql_vendors = mysqli_query(
// Associated Contacts
$sql_contacts = mysqli_query(
$mysqli,
"SELECT service_contacts.contact_id, contact_name FROM service_contacts
"SELECT service_contacts.contact_id, contact_client_id, contact_name, contact_photo FROM service_contacts
LEFT JOIN contacts ON service_contacts.contact_id = contacts.contact_id
WHERE service_id = $service_id"
);
@@ -234,12 +234,11 @@ ob_start();
<!-- Contacts -->
<?php
if (mysqli_num_rows($sql_contacts) > 0) {
echo "<h5><i class='fas fa-fw fa-users me-2'></i>Contacts</h5><ul>";
// No bullets - each contact leads with their avatar instead
echo "<h5><i class='fas fa-fw fa-users me-2'></i>Contacts</h5><ul class='list-unstyled ms-1'>";
mysqli_data_seek($sql_contacts, 0);
while ($row = mysqli_fetch_assoc($sql_contacts)) {
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
echo "<li><a href='#' class='ajax-modal' data-modal-size='lg' data-modal-url='modals/contact/contact.php?id=$contact_id'>$contact_name</a></li>";
echo '<li class="mb-1">' . contactLink($row['contact_client_id'], $row['contact_id'], $row['contact_name'], $row['contact_photo']) . '</li>';
}
echo "</ul>";
}

View File

@@ -128,7 +128,7 @@ ob_start();
while ($row = mysqli_fetch_assoc($sql)) {
$contact_id = intval($row['contact_id']);
$contact_name = escapeHtml($row['contact_name']);
echo "<option value=\"$contact_id\"" . selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') . ">$contact_name</option>";
echo "<option value=\"$contact_id\"" . selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) . ">$contact_name</option>";
}
?>
</select>

View File

@@ -189,12 +189,8 @@ ob_start();
$contact_id = intval($row_all['contact_id']);
$contact_name = escapeHtml($row_all['contact_name']);
if (in_array($contact_id, $selected_ids)) {
echo "<option value=\"$contact_id\" selected" . selectOptionContact($row_all['contact_client_id'] ?? 0, $row_all['contact_name'], $row_all['contact_photo'] ?? '', $row_all['contact_title'] ?? '') . ">$contact_name</option>";
}
else{
echo "<option value=\"$contact_id\">$contact_name</option>";
}
$contact_selected = in_array($contact_id, $selected_ids) ? ' selected' : '';
echo "<option value=\"$contact_id\"$contact_selected" . selectOptionContact($row_all['contact_client_id'] ?? 0, $row_all['contact_name'], $row_all['contact_photo'] ?? '', $row_all['contact_title'] ?? '', $row_all['contact_id'] ?? 0) . ">$contact_name</option>";
}
?>
</select>
@@ -263,12 +259,8 @@ ob_start();
$asset_id = intval($row_all['asset_id']);
$asset_name = escapeHtml($row_all['asset_name']);
if (in_array($asset_id, $selected_ids)) {
echo "<option value=\"$asset_id\" selected" . selectOptionAsset($row_all['asset_type'] ?? '', trim(($row_all['asset_make'] ?? '') . ' ' . ($row_all['asset_model'] ?? ''))) . ">$asset_name</option>";
}
else{
echo "<option value=\"$asset_id\">$asset_name</option>";
}
$asset_selected = in_array($asset_id, $selected_ids) ? ' selected' : '';
echo "<option value=\"$asset_id\"$asset_selected" . selectOptionAsset($row_all['asset_type'] ?? '', trim(($row_all['asset_make'] ?? '') . ' ' . ($row_all['asset_model'] ?? ''))) . ">$asset_name</option>";
}
?>
</select>

View File

@@ -30,7 +30,7 @@
$contact_name_select = escapeHtml($row['contact_name']);
$contact_email_select = escapeHtml($row['contact_email']);
?>
<option value="<?= $contact_email_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= "$contact_name_select - $contact_email_select" ?></option>
<option value="<?= $contact_email_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= "$contact_name_select - $contact_email_select" ?></option>
<?php
}

View File

@@ -258,7 +258,7 @@ ob_start();
</li>
<?php
$sql_contacts_select = mysqli_query($mysqli, "SELECT contact_email, contact_id, contact_name FROM contacts WHERE contact_archived_at IS NULL AND contact_client_id = $client_id ORDER BY contact_name ASC");
$sql_contacts_select = mysqli_query($mysqli, "SELECT contact_email, contact_id, contact_name, contact_photo FROM contacts WHERE contact_archived_at IS NULL AND contact_client_id = $client_id ORDER BY contact_name ASC");
while ($row = mysqli_fetch_assoc($sql_contacts_select)) {
$contact_id_select = intval($row['contact_id']);
@@ -268,8 +268,11 @@ ob_start();
?>
<li class="list-group-item">
<div class="form-check">
<input type="checkbox" class="form-check-input user-checkbox" name="contacts[]" value="<?= $contact_id_select ?>">
<label class="form-check-label ms-2"><?= "$contact_name_select - $contact_email_select" ?></label>
<input type="checkbox" class="form-check-input user-checkbox" name="contacts[]" id="softwareAddContact<?= $contact_id_select ?>" value="<?= $contact_id_select ?>">
<label class="form-check-label ms-2 d-inline-flex align-items-center gap-2" for="softwareAddContact<?= $contact_id_select ?>">
<?= contactAvatar($client_id, $contact_id_select, $row['contact_name'], $row['contact_photo'], 'xs') ?>
<span><?= $contact_name_select ?><?php if ($contact_email_select) { ?> <span class="small text-body-secondary"><?= $contact_email_select ?></span><?php } ?></span>
</label>
</div>
</li>

View File

@@ -277,7 +277,7 @@ ob_start();
</li>
<?php
$sql_contacts_select = mysqli_query($mysqli, "SELECT contact_archived_at, contact_email, contact_id, contact_name FROM contacts WHERE (contact_archived_at > '$software_created_at' OR contact_archived_at IS NULL) AND contact_client_id = $client_id ORDER BY contact_archived_at ASC, contact_name ASC");
$sql_contacts_select = mysqli_query($mysqli, "SELECT contact_archived_at, contact_email, contact_id, contact_name, contact_photo FROM contacts WHERE (contact_archived_at > '$software_created_at' OR contact_archived_at IS NULL) AND contact_client_id = $client_id ORDER BY contact_archived_at ASC, contact_name ASC");
while ($row = mysqli_fetch_assoc($sql_contacts_select)) {
$contact_id_select = intval($row['contact_id']);
@@ -293,8 +293,11 @@ ob_start();
?>
<li class="list-group-item">
<div class="form-check">
<input type="checkbox" class="form-check-input user-checkbox" name="contacts[]" value="<?= $contact_id_select ?>" <?php if (in_array("$contact_id_select", $contact_licenses_array)) { echo "checked"; } ?>>
<label class="form-check-label ms-2"><?= "$contact_archived_display$contact_name_select - $contact_email_select" ?></label>
<input type="checkbox" class="form-check-input user-checkbox" name="contacts[]" id="softwareEditContact<?= $contact_id_select ?>" value="<?= $contact_id_select ?>" <?php if (in_array("$contact_id_select", $contact_licenses_array)) { echo "checked"; } ?>>
<label class="form-check-label ms-2 d-inline-flex align-items-center gap-2" for="softwareEditContact<?= $contact_id_select ?>">
<?= contactAvatar($client_id, $contact_id_select, $row['contact_name'], $row['contact_photo'], 'xs') ?>
<span><?= "$contact_archived_display$contact_name_select" ?><?php if ($contact_email_select) { ?> <span class="small text-body-secondary"><?= $contact_email_select ?></span><?php } ?></span>
</label>
</div>
</li>

View File

@@ -40,7 +40,7 @@ ob_start();
$contact_name_select = escapeHtml($row['contact_name']);
$contact_email_select = escapeHtml($row['contact_email']);
?>
<option value="<?= $contact_email_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= "$contact_name_select - $contact_email_select" ?></option>
<option value="<?= $contact_email_select ?>"<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '', $row['contact_id'] ?? 0) ?>><?= "$contact_name_select - $contact_email_select" ?></option>
<?php
}

View File

@@ -45,31 +45,13 @@ ob_start();
while ($row = mysqli_fetch_assoc($sql_client_contacts_select)) {
$contact_id_select = intval($row['contact_id']);
$contact_name_select = escapeHtml($row['contact_name']);
$contact_primary_select = intval($row['contact_primary']);
if($contact_primary_select == 1) {
$contact_primary_display_select = " (Primary)";
} else {
$contact_primary_display_select = "";
}
$contact_technical_select = intval($row['contact_technical']);
if($contact_technical_select == 1) {
$contact_technical_display_select = " (Technical)";
} else {
$contact_technical_display_select = "";
}
$contact_title_select = escapeHtml($row['contact_title']);
if(!empty($contact_title_select)) {
$contact_title_display_select = " - $contact_title_select";
} else {
$contact_title_display_select = "";
}
?>
<option
value="<?= $contact_id_select ?>"
<?php if ($contact_id_select == $contact_id) { echo "selected"; } ?>
<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>>
<?= "$contact_name_select$contact_title_display_select$contact_primary_display_select$contact_technical_display_select" ?>
<?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', contactOptionDescription($row), $row['contact_id'] ?? 0) ?>>
<?= $contact_name_select ?>
</option>
<?php } ?>
</select>

View File

@@ -203,27 +203,9 @@ ob_start();
while ($row = mysqli_fetch_assoc($sql_client_contacts_select)) {
$contact_id_select = intval($row['contact_id']);
$contact_name_select = escapeHtml($row['contact_name']);
$contact_primary_select = intval($row['contact_primary']);
if($contact_primary_select == 1) {
$contact_primary_display_select = " (Primary)";
} else {
$contact_primary_display_select = "";
}
$contact_technical_select = intval($row['contact_technical']);
if($contact_technical_select == 1) {
$contact_technical_display_select = " (Technical)";
} else {
$contact_technical_display_select = "";
}
$contact_title_select = escapeHtml($row['contact_title']);
if(!empty($contact_title_select)) {
$contact_title_display_select = " - $contact_title_select";
} else {
$contact_title_display_select = "";
}
?>
<option value="<?= $contact_id_select ?>" <?php if ($contact_id_select == $contact_id) { echo "selected"; } ?><?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', $row['contact_title'] ?? '') ?>><?= "$contact_name_select$contact_title_display_select$contact_primary_display_select$contact_technical_display_select" ?></option>
<option value="<?= $contact_id_select ?>" <?php if ($contact_id_select == $contact_id) { echo "selected"; } ?><?= selectOptionContact($row['contact_client_id'] ?? 0, $row['contact_name'], $row['contact_photo'] ?? '', contactOptionDescription($row), $row['contact_id'] ?? 0) ?>><?= $contact_name_select ?></option>
<?php } ?>
</select>
</div>

View File

@@ -14,17 +14,20 @@ if (isset($_POST['add_contact'])) {
require_once 'contact_model.php';
$client_id = intval($_POST['client_id']);
$client_id = intval($_POST['client_id'] ?? 0);
enforceClientAccess($client_id);
// Only one of the client's own locations
$location_id = assetClientOwnedId('location', $location_id, $client_id);
// Create User Account
$user_id = 0;
if ($name && $email && $auth_method) {
// Set password
if (!empty($_POST['contact_password'])) {
$password_hash = password_hash(trim($_POST['contact_password']), PASSWORD_DEFAULT);
if ($contact_password !== '') {
$password_hash = password_hash($contact_password, PASSWORD_DEFAULT);
} else {
// Set a random password
$password_hash = password_hash(randomString(), PASSWORD_DEFAULT);
@@ -54,14 +57,14 @@ if (isset($_POST['add_contact'])) {
}
// Check for and process image/photo
if (isset($_FILES['file']['tmp_name'])) {
if (!empty($_FILES['file']['tmp_name'])) {
if ($new_file_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'webp'))) {
$file_tmp_path = $_FILES['file']['tmp_name'];
// directory in which the uploaded file will be moved
if (!file_exists("../uploads/clients/$client_id")) {
mkdir("../uploads/clients/$client_id");
mkdir("../uploads/clients/$client_id", 0755, true);
}
$upload_file_dir = "../uploads/clients/$client_id/";
$dest_path = $upload_file_dir . $new_file_name;
@@ -96,31 +99,41 @@ if (isset($_POST['edit_contact'])) {
// Get Contact Info
$sql = mysqli_query($mysqli,"SELECT contact_photo, contact_user_id, contact_client_id FROM contacts WHERE contact_id = $contact_id");
$row = mysqli_fetch_assoc($sql);
$existing_file_name = escapeSql($row['contact_photo']);
if (!$row) {
flashAlert("That contact no longer exists", 'error');
redirect();
}
$existing_file_name = basename((string) $row['contact_photo']);
$contact_user_id = intval($row['contact_user_id']);
$client_id = intval($row['contact_client_id']);
enforceClientAccess();
// Only one of the client's own locations
$location_id = assetClientOwnedId('location', $location_id, $client_id);
if (!file_exists("../uploads/clients/$client_id")) {
mkdir("../uploads/clients/$client_id");
mkdir("../uploads/clients/$client_id", 0755, true);
}
// Update Existing User
// Update Existing User - their portal access only when the form had it
if ($contact_user_id > 0) {
mysqli_query($mysqli, "UPDATE users SET user_name = '$name', user_email = '$email', user_auth_method = '$auth_method' WHERE user_id = $contact_user_id");
mysqli_query($mysqli, "UPDATE users SET user_name = '$name', user_email = '$email' WHERE user_id = $contact_user_id");
if ($auth_method_posted) {
mysqli_query($mysqli, "UPDATE users SET user_auth_method = '$auth_method' WHERE user_id = $contact_user_id");
}
// Set password
if ($_POST['contact_password']) {
$password_hash = password_hash(trim($_POST['contact_password']), PASSWORD_DEFAULT);
if ($contact_password !== '') {
$password_hash = password_hash($contact_password, PASSWORD_DEFAULT);
mysqli_query($mysqli, "UPDATE users SET user_password = '$password_hash' WHERE user_id = $contact_user_id");
}
// Create New User
} elseif ($contact_user_id == 0 && $name && $email && $auth_method) {
// Set password
if ($_POST['contact_password']) {
$password_hash = password_hash(trim($_POST['contact_password']), PASSWORD_DEFAULT);
if ($contact_password !== '') {
$password_hash = password_hash($contact_password, PASSWORD_DEFAULT);
} else {
// Set a random password
$password_hash = password_hash(randomString(), PASSWORD_DEFAULT);
@@ -134,8 +147,9 @@ 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");
// Upload Photo
if (isset($_FILES['file']['tmp_name'])) {
// Upload Photo - replacing the old one, if there was one
$old_photo_path = $existing_file_name !== '' ? "../uploads/clients/$client_id/$existing_file_name" : '';
if (!empty($_FILES['file']['tmp_name'])) {
if ($new_file_name = checkFileUpload($_FILES['file'], array('jpg', 'jpeg', 'gif', 'png', 'webp'))) {
// Set directory in which the uploaded file will be moved
@@ -145,12 +159,19 @@ if (isset($_POST['edit_contact'])) {
move_uploaded_file($file_tmp_path, $dest_path);
//Delete old file
unlink("../uploads/clients/$client_id/$existing_file_name");
// Delete old file
if ($old_photo_path && is_file($old_photo_path)) {
unlink($old_photo_path);
}
mysqli_query($mysqli,"UPDATE contacts SET contact_photo = '$new_file_name' WHERE contact_id = $contact_id");
}
} elseif (!empty($_POST['remove_photo'])) {
if ($old_photo_path && is_file($old_photo_path)) {
unlink($old_photo_path);
}
mysqli_query($mysqli,"UPDATE contacts SET contact_photo = NULL WHERE contact_id = $contact_id");
}
// Tags
@@ -191,10 +212,10 @@ if (isset($_POST['edit_contact'])) {
if ($auth_method == 'azure') {
$password_info = "Login with your Microsoft (Azure AD) account.";
} elseif (empty($_POST['contact_password'])) {
} elseif ($contact_password === '') {
$password_info = "Request a password reset at https://$config_base_url/client/login_reset.php";
} else {
$password_info = mysqli_real_escape_string($mysqli, $_POST['contact_password'] . " -- Please change on first login");
$password_info = mysqli_real_escape_string($mysqli, $contact_password . " -- Please change on first login");
}
$subject = "Your new $company_name portal account";
@@ -353,24 +374,28 @@ if (isset($_POST['bulk_assign_contact_location'])) {
// Get Location name for logging and Notification
$sql = mysqli_query($mysqli,"SELECT location_name, location_client_id FROM locations WHERE location_id = $location_id");
$row = mysqli_fetch_assoc($sql);
$location_name = escapeSql($row['location_name']);
$client_id = intval($row['location_client_id']);
$location_name = escapeSql($row['location_name'] ?? '');
$client_id = intval($row['location_client_id'] ?? 0);
enforceClientAccess();
// Assign Location to Selected Contacts
if (isset($_POST['contact_ids'])) {
// Get Selected Contacts Count
$contact_count = count($_POST['contact_ids']);
// Only the contacts of the location's client are moved
$contact_count = 0;
foreach($_POST['contact_ids'] as $contact_id) {
$contact_id = intval($contact_id);
// Get Contact Details for Logging
$sql = mysqli_query($mysqli,"SELECT contact_name FROM contacts WHERE contact_id = $contact_id");
$sql = mysqli_query($mysqli,"SELECT contact_name, contact_client_id FROM contacts WHERE contact_id = $contact_id");
$row = mysqli_fetch_assoc($sql);
if (!$row || intval($row['contact_client_id']) !== $client_id) {
continue;
}
$contact_name = escapeSql($row['contact_name']);
$contact_count++;
mysqli_query($mysqli,"UPDATE contacts SET contact_location_id = $location_id WHERE contact_id = $contact_id");

View File

@@ -1,20 +1,24 @@
<?php
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
$name = escapeSql($_POST['name']);
$title = escapeSql($_POST['title']);
$department = escapeSql($_POST['department']);
$phone_country_code = preg_replace("/[^0-9]/", '', $_POST['phone_country_code']);
$phone = preg_replace("/[^0-9]/", '', $_POST['phone']);
$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']);
$notes = escapeSql($_POST['notes']);
$name = escapeSql($_POST['name'] ?? '');
$title = escapeSql($_POST['title'] ?? '');
$department = escapeSql($_POST['department'] ?? '');
$phone_country_code = preg_replace("/[^0-9]/", '', $_POST['phone_country_code'] ?? '');
$phone = preg_replace("/[^0-9]/", '', $_POST['phone'] ?? '');
$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'] ?? '');
$notes = escapeSql($_POST['notes'] ?? '');
$contact_primary = intval($_POST['contact_primary'] ?? 0);
$contact_important = intval($_POST['contact_important'] ?? 0);
$contact_billing = intval($_POST['contact_billing'] ?? 0);
$contact_technical = intval($_POST['contact_technical'] ?? 0);
$location_id = intval($_POST['location'] ?? 0);
$pin = escapeSql($_POST['pin']);
$auth_method = escapeSql($_POST['auth_method']);
$pin = escapeSql($_POST['pin'] ?? '');
// The portal login is only on the form when the client portal is on - when it
// isn't posted, leave whatever access the contact has alone
$auth_method_posted = isset($_POST['auth_method']);
$auth_method = in_array($_POST['auth_method'] ?? '', ['local', 'azure'], true) ? $_POST['auth_method'] : '';
$contact_password = trim((string) ($_POST['contact_password'] ?? ''));

View File

@@ -137,7 +137,9 @@ if (isset($_GET['ticket_id'])) {
$tab_title = "{$ticket['ticket_prefix']}{$ticket['ticket_number']}";
$contact_id = intval($ticket['contact_id']);
$contact_client_id = intval($ticket['contact_client_id']);
$contact_name = escapeHtml($ticket['contact_name']);
$contact_photo = escapeHtml($ticket['contact_photo']);
$contact_title = escapeHtml($ticket['contact_title']);
$contact_email = escapeHtml($ticket['contact_email']);
$contact_phone_country_code = escapeHtml($ticket['contact_phone_country_code']);
@@ -259,7 +261,7 @@ if (isset($_GET['ticket_id'])) {
))['user_names']);
// Get ticket replies
$sql_ticket_replies = mysqli_query($mysqli, "SELECT contact_name, contact_photo, ticket_reply, ticket_reply_created_at, ticket_reply_id,
$sql_ticket_replies = mysqli_query($mysqli, "SELECT contact_name, contact_photo, ticket_reply, ticket_reply_by, ticket_reply_created_at, ticket_reply_id,
ticket_reply_time_worked, ticket_reply_type, ticket_reply_updated_at, user_avatar, user_id,
user_name FROM ticket_replies
LEFT JOIN users ON ticket_reply_by = user_id
@@ -492,7 +494,7 @@ if (isset($_GET['ticket_id'])) {
No client
<?php } ?>
<?php if ($contact_id) { ?>
<i class="fas fa-fw fa-angle-right"></i><a href="#" class="ajax-modal" data-modal-size="lg" data-modal-url="modals/contact/contact.php?id=<?= $contact_id ?>"><?= $contact_name ?></a>
<i class="fas fa-fw fa-angle-right"></i><?= contactLink($contact_client_id, $contact_id, $contact_name, $contact_photo) ?>
<?php } ?>
</div>
@@ -824,11 +826,12 @@ if (isset($_GET['ticket_id'])) {
$ticket_reply_updated_at = escapeHtml($reply_row['ticket_reply_updated_at']);
$ticket_reply_time_worked = '';
// A client's reply wears their contact avatar - their own colour,
// the same as everywhere else they appear
$reply_contact_avatar = '';
if ($ticket_reply_type == "Client") {
$ticket_reply_by_display = escapeHtml($reply_row['contact_name']);
$user_initials = initials($reply_row['contact_name']);
$user_avatar = escapeHtml($reply_row['contact_photo']);
$avatar_link = "../uploads/clients/$client_id/$user_avatar";
$reply_contact_avatar = contactAvatar($client_id, $reply_row['ticket_reply_by'], $reply_row['contact_name'], $reply_row['contact_photo'], 'md');
} else {
$ticket_reply_by_display = escapeHtml($reply_row['user_name']);
$user_id = intval($reply_row['user_id']);
@@ -862,7 +865,9 @@ if (isset($_GET['ticket_id'])) {
<div class="d-flex justify-content-between align-items-start w-100">
<div class="d-flex align-items-center">
<?php if (!empty($user_avatar)) { ?>
<?php if ($reply_contact_avatar) { ?>
<span class="me-2 d-inline-flex"><?= $reply_contact_avatar ?></span>
<?php } elseif (!empty($user_avatar)) { ?>
<img src="<?= $avatar_link ?>" alt="" class="img-size-32 me-2 rounded-circle">
<?php } else { ?>
<span class="fa-stack me-2">
@@ -1138,9 +1143,12 @@ if (isset($_GET['ticket_id'])) {
<div class="text-muted small">No contact on this ticket yet.</div>
<?php } else { ?>
<div>
<a href="#" class="ajax-modal" data-modal-size="lg" data-modal-url="modals/contact/contact.php?id=<?= $contact_id ?>"><strong><?= $contact_name ?></strong></a>
<?php if ($contact_title) { ?><div class="text-muted small"><?= $contact_title ?></div><?php } ?>
<div class="d-flex align-items-center gap-2">
<?= contactAvatar($contact_client_id, $contact_id, $contact_name, $contact_photo) ?>
<div class="min-w-0">
<a href="#" class="ajax-modal fw-bold text-break" data-modal-size="lg" data-modal-url="modals/contact/contact.php?id=<?= $contact_id ?>"><?= $contact_name ?></a>
<?php if ($contact_title) { ?><div class="text-muted small text-truncate"><?= $contact_title ?></div><?php } ?>
</div>
</div>
<?php if (!empty($contact_phone)) { ?>

View File

@@ -173,13 +173,16 @@ $kanban = array_values($statuses);
<div class="kanban-card-client">
<?php
// The contact with their avatar, as everywhere else they appear
$item_contact = empty($item['contact_name']) ? ''
: '<span class="itflow-contact-ref">' . contactAvatar($item['ticket_client_id'], $item['contact_id'], $item['contact_name'], $item['contact_photo'] ?? '', 'xs') . '<span class="text-truncate">' . escapeHtml($item['contact_name']) . '</span></span>';
if (!$client_url) {
echo escapeHtml($item['client_name']);
if (!empty($item['contact_name'])) {
echo ' <span class="text-secondary">&middot; ' . escapeHtml($item['contact_name']) . '</span>';
if ($item_contact) {
echo ' <span class="text-secondary">&middot; ' . $item_contact . '</span>';
}
} else {
echo escapeHtml($item['contact_name']);
echo $item_contact;
}
?>
</div>

View File

@@ -301,7 +301,7 @@ if ($tickets) {
if (empty($contact_name)) {
$contact_display = "<span class='text-muted'>-</span>";
} else {
$contact_display = "<a href='contact.php?client_id=$client_id&contact_id=$contact_id'>$contact_name</a>";
$contact_display = contactLink($client_id, $contact_id, $row['contact_name'], $row['contact_photo'], ['page' => true]);
}
$ticket_invoice_id = intval($row['ticket_invoice_id']);

View File

@@ -266,7 +266,7 @@ $ticket_select_columns =
ticket_response_sla_met, ticket_resolution_sla_met,
ticket_response_sla_alert_stage, ticket_resolution_sla_alert_stage,
ticket_status_id, ticket_status_name, ticket_status_color, ticket_status_pauses_sla,
client_name, contact_id, contact_name, contact_email,
client_name, contact_id, contact_name, contact_email, contact_photo,
user_name, user_avatar, asset_name, category_name";
$ticket_joins =

View File

@@ -3132,17 +3132,6 @@ button.itflow-client-nav-identity:focus-visible {
font-size: .8rem;
color: var(--bs-secondary-color);
}
.itflow-ov-person {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
justify-content: center;
width: 2.25rem;
height: 2.25rem;
font-size: .8rem;
font-weight: 600;
object-fit: cover;
}
.itflow-ov-notes {
min-height: 12rem;
resize: vertical;
@@ -3777,19 +3766,6 @@ tr:hover .itflow-copy,
color: var(--bs-secondary-color);
background: transparent;
}
.itflow-asset-avatar {
display: inline-flex;
flex-shrink: 0;
align-items: center;
justify-content: center;
width: 20px;
height: 20px;
border-radius: 50%;
font-size: .6rem;
font-weight: 600;
color: #fff;
background-color: var(--bs-secondary);
}
/* In the Where & who card, and the quick look's glance lines, the picker is
the whole line: it lights up on hover with a chevron, like the ticket
page's properties. The negative margin keeps its text in line with the
@@ -3885,7 +3861,8 @@ tr:hover .itflow-copy,
.itflow-glance-item .font-monospace {
font-size: .82rem;
}
.itflow-asset-quicknote {
.itflow-asset-quicknote,
.itflow-contact-quicknote {
min-height: 2.6rem;
max-height: 12rem;
field-sizing: content;
@@ -3893,7 +3870,8 @@ tr:hover .itflow-copy,
background-color: var(--bs-tertiary-bg);
resize: vertical;
}
.itflow-asset-quicknote:focus {
.itflow-asset-quicknote:focus,
.itflow-contact-quicknote:focus {
background-color: var(--bs-body-bg);
}
.itflow-asset-quick-related {
@@ -3922,3 +3900,94 @@ tr:hover .itflow-copy,
.itflow-asset-quick-related .itflow-asset-pills .nav-link {
padding: .25rem .55rem;
}
/* Contacts - functions/contact.php contactAvatar(): a photo, or initials on a
soft colour that stays the same for the person (like the client avatars) */
.itflow-contact-avatar {
display: inline-flex;
flex: 0 0 auto;
align-items: center;
justify-content: center;
width: 2.5rem;
height: 2.5rem;
border-radius: 50%;
font-size: .8rem;
font-weight: 600;
letter-spacing: .02em;
}
img.itflow-contact-avatar {
object-fit: cover;
}
/* contactLink(): the avatar, then the name - in a table cell, a card or a line of text */
.itflow-contact-ref {
display: inline-flex;
align-items: center;
gap: .4rem;
min-width: 0;
max-width: 100%;
vertical-align: middle;
}
.itflow-contact-avatar-xs {
width: 1.25rem;
height: 1.25rem;
font-size: .5rem;
letter-spacing: 0;
}
.itflow-contact-avatar-sm {
width: 1.75rem;
height: 1.75rem;
font-size: .65rem;
}
.itflow-contact-avatar-md {
width: 2rem;
height: 2rem;
font-size: .7rem;
}
.itflow-contact-avatar-lg {
width: 3.5rem;
height: 3.5rem;
font-size: 1.1rem;
}
/* Contacts list */
.itflow-contact-table td {
padding-top: .6rem;
padding-bottom: .6rem;
}
.itflow-contact-name-cell {
min-width: 16rem;
}
.itflow-contact-role {
max-width: 20rem;
}
.itflow-contact-reach > div + div {
margin-top: .15rem;
}
/* What is linked to a contact - a small count that opens that tab on their page */
.itflow-contact-chip {
display: inline-flex;
align-items: center;
gap: .3rem;
padding: .1rem .5rem;
border-radius: 2rem;
font-size: .75rem;
color: var(--bs-body-color);
background-color: var(--bs-secondary-bg);
text-decoration: none;
white-space: nowrap;
}
.itflow-contact-chip i {
color: var(--bs-secondary-color);
font-size: .7rem;
}
.itflow-contact-chip:hover {
color: var(--bs-emphasis-color);
background-color: var(--bs-tertiary-bg);
box-shadow: inset 0 0 0 1px var(--bs-border-color);
}
.itflow-contact-chip.is-alert {
color: var(--bs-danger-text-emphasis);
background-color: var(--bs-danger-bg-subtle);
}
.itflow-contact-chip.is-alert i {
color: inherit;
}

View File

@@ -20,6 +20,7 @@ require_once __DIR__ . '/functions/domain.php';
require_once __DIR__ . '/functions/network.php';
require_once __DIR__ . '/functions/rack.php';
require_once __DIR__ . '/functions/asset.php';
require_once __DIR__ . '/functions/contact.php';
require_once __DIR__ . '/functions/auth.php';
require_once __DIR__ . '/functions/logging.php';
require_once __DIR__ . '/functions/app.php';

View File

@@ -70,6 +70,12 @@ function assetStatusColors() {
return $colors;
}
/** The colour a status is drawn in, as a CSS value - the same as its badge. */
function assetStatusColor($status, $category_color = '') {
$badge = assetStatusBadge($status, $category_color);
return $badge['style'] ? trim(substr($badge['style'], strlen('background-color:'))) : "var(--bs-{$badge['class']})";
}
/** The status badge, ready to echo. */
function assetStatusPill($status) {
$status = (string) $status;
@@ -82,10 +88,9 @@ function assetStatusPill($status) {
return "<span class=\"badge rounded-pill fw-normal $class\"$style>" . escapeHtml($status) . "</span>";
}
/** A brand icon for the operating system, where one is recognisable (Font Awesome 5 class). */
function assetOsIcon($os) {
$os = strtolower((string) $os);
$icons = [
/** OS name fragments and their brand icons (Font Awesome 5), first match wins. Also drives the asset form's OS icon. */
function assetOsIconMap() {
return [
'windows' => 'fab fa-windows',
'macos' => 'fab fa-apple',
'mac os' => 'fab fa-apple',
@@ -111,7 +116,12 @@ function assetOsIcon($os) {
'firmware' => 'fas fa-microchip',
'routeros' => 'fas fa-microchip',
];
foreach ($icons as $needle => $icon) {
}
/** A brand icon for the operating system, where one is recognisable (Font Awesome 5 class). */
function assetOsIcon($os) {
$os = strtolower((string) $os);
foreach (assetOsIconMap() as $needle => $icon) {
if (strpos($os, $needle) !== false) {
return $icon;
}
@@ -199,10 +209,9 @@ function assetLinkLabel($url) {
return $labels[$scheme] ?? ($scheme !== '' ? strtoupper($scheme) : 'Link');
}
/** Icon for a link by its scheme. */
function assetLinkIcon($url) {
$scheme = strtolower((string) parse_url((string) $url, PHP_URL_SCHEME));
$icons = [
/** Link schemes and their icons. Also drives the asset form's link icons. */
function assetLinkIconMap() {
return [
'ssh' => 'fas fa-terminal',
'telnet' => 'fas fa-terminal',
'rdp' => 'fas fa-desktop',
@@ -213,7 +222,12 @@ function assetLinkIcon($url) {
'http' => 'fas fa-globe',
'https' => 'fas fa-globe',
];
return $icons[$scheme] ?? 'fas fa-external-link-alt';
}
/** Icon for a link by its scheme. */
function assetLinkIcon($url) {
$scheme = strtolower((string) parse_url((string) $url, PHP_URL_SCHEME));
return assetLinkIconMap()[$scheme] ?? 'fas fa-external-link-alt';
}
/**
@@ -263,15 +277,6 @@ function assetQuickRow($asset_id) {
WHERE asset_id = " . intval($asset_id))) ?: null;
}
/** A contact's picture, or their initials in a circle. 20px, for pills and the picker button. */
function assetContactAvatar($client_id, $contact_name, $contact_photo) {
$contact_photo = (string) $contact_photo;
if ($contact_photo !== '') {
return '<img src="/uploads/clients/' . intval($client_id) . '/' . escapeHtml(rawurlencode($contact_photo)) . '" alt="" width="20" height="20" class="rounded-circle object-fit-cover flex-shrink-0">';
}
return '<span class="itflow-asset-avatar" aria-hidden="true">' . escapeHtml(personInitials($contact_name)) . '</span>';
}
/**
* What a picker shows for the value it holds now. $style is 'list' (a pill,
* on the assets list and in the asset page header) or 'detail' (a line in the
@@ -306,7 +311,7 @@ function assetQuickHtml($field, $row, $style = 'list') {
: "<span class=\"$empty\"><i class=\"fas fa-user-slash\"></i>Nobody</span>";
}
$archived = !empty($row['contact_archived_at']);
$avatar = assetContactAvatar($client_id, $row['contact_name'], $row['contact_photo'] ?? '');
$avatar = contactAvatar($client_id, $row['asset_contact_id'], $row['contact_name'], $row['contact_photo'] ?? '', 'xs');
$name = '<span class="text-truncate' . ($archived ? ' text-decoration-line-through' : '') . '"' . ($archived ? ' title="Archived contact"' : '') . '>' . escapeHtml($row['contact_name']) . '</span>';
return $style === 'detail'
? "<span class=\"d-inline-flex align-items-center gap-2 min-w-0\">$avatar$name</span>"
@@ -357,9 +362,7 @@ function assetQuickOptions($field, $client_id) {
WHERE category_type = 'asset_status' AND category_archived_at IS NULL
ORDER BY category_order ASC, category_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$badge = assetStatusBadge($row['category_name'], $row['category_color']);
$color = $badge['style'] ? trim(substr($badge['style'], strlen('background-color:'))) : "var(--bs-{$badge['class']})";
$options[] = ['value' => $row['category_name'], 'label' => $row['category_name'], 'color' => $color];
$options[] = ['value' => $row['category_name'], 'label' => $row['category_name'], 'color' => assetStatusColor($row['category_name'], $row['category_color'])];
}
return $options;
}
@@ -387,13 +390,8 @@ function assetQuickOptions($field, $client_id) {
WHERE contact_client_id = $client_id AND contact_archived_at IS NULL
ORDER BY contact_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$option = ['value' => (string) intval($row['contact_id']), 'label' => $row['contact_name'], 'description' => (string) $row['contact_title']];
if ($row['contact_photo']) {
$option['image'] = "/uploads/clients/$client_id/" . rawurlencode($row['contact_photo']);
} else {
$option['initials'] = personInitials($row['contact_name']);
}
$options[] = $option;
$options[] = ['value' => (string) intval($row['contact_id']), 'label' => $row['contact_name'], 'description' => (string) $row['contact_title']]
+ contactAvatarData($client_id, $row['contact_id'], $row['contact_name'], $row['contact_photo']);
}
return $options;
}

View File

@@ -489,12 +489,3 @@ function clientOverviewMonthly($client_id) {
];
}
/** Up to two initials for a person's name, for a contact without a photo. */
function clientOverviewPersonInitials($name) {
$words = preg_split('/\s+/u', trim((string) $name), -1, PREG_SPLIT_NO_EMPTY);
$initials = '';
foreach (array_slice($words, 0, 2) as $word) {
$initials .= mb_strtoupper(mb_substr($word, 0, 1));
}
return $initials ?: '?';
}

190
functions/contact.php Normal file
View File

@@ -0,0 +1,190 @@
<?php
/*
* Contacts - how a contact is shown: their picture or initials, their flags
* (Primary, Important, Billing, Technical, portal access), their phone
* numbers, and the quick picker for their location. The contacts list, the
* contact page and the quick look are built from these, and so is every
* other place a contact turns up - a ticket, an asset, a client, the pickers
* (selectOptionContact() in functions/format.php) and the search - so a
* person looks the same everywhere.
*
* Everything here takes raw values from the database and escapes what it
* prints.
*/
/** The colour behind a contact's initials - picked by id, so it is the same on every page and in every picker. */
function contactAvatarTone($contact_id) {
return clientInitialsTone($contact_id);
}
/**
* Their photo, or their initials on a soft colour that stays the same for
* them (like the client avatars on the clients list). $size is '' (2.5rem),
* 'xs' (in front of a name in a line of text or a pill), 'sm', 'md' (beside
* a ticket reply, the size of the agents' pictures there) or 'lg'.
* Takes values raw or already escaped.
*/
function contactAvatar($client_id, $contact_id, $name, $photo, $size = '') {
$class = 'itflow-contact-avatar' . ($size ? " itflow-contact-avatar-$size" : '');
$photo = html_entity_decode((string) $photo, ENT_QUOTES, 'UTF-8');
if ($photo !== '') {
return '<img class="' . $class . '" src="../uploads/clients/' . intval($client_id) . '/' . escapeHtml(rawurlencode($photo)) . '" alt="" loading="lazy">';
}
$tone = contactAvatarTone($contact_id);
return '<span class="' . $class . ' bg-' . $tone . '-subtle text-' . $tone . '-emphasis" aria-hidden="true">' . escapeHtml(personInitials($name) ?: '?') . '</span>';
}
/**
* A contact wherever a page mentions one: their avatar, then their name,
* linked to their quick look - or to their page with 'page' => true.
* Other options: 'size' of the avatar ('xs' unless given), 'class' on the
* link, 'archived' to strike the name through.
* Takes values raw or already escaped.
*/
function contactLink($client_id, $contact_id, $name, $photo = '', $options = []) {
$client_id = intval($client_id);
$contact_id = intval($contact_id);
$name = html_entity_decode((string) $name, ENT_QUOTES, 'UTF-8');
$label = escapeHtml($name !== '' ? $name : 'Unnamed contact');
$archived = !empty($options['archived']);
$class = trim('text-truncate ' . ($options['class'] ?? '') . ($archived ? ' text-decoration-line-through text-body-secondary' : ''));
$title = $archived ? ' title="Archived contact"' : '';
$link = !empty($options['page'])
? "<a class=\"$class\" href=\"contact.php?client_id=$client_id&amp;contact_id=$contact_id\"$title>$label</a>"
: "<a class=\"ajax-modal $class\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/contact/contact.php?id=$contact_id\"$title>$label</a>";
return '<span class="itflow-contact-ref">' . contactAvatar($client_id, $contact_id, $name, $photo, $options['size'] ?? 'xs') . $link . '</span>';
}
/** The quieter line under a contact in a picker: their title, and Primary or Technical. */
function contactOptionDescription($row) {
$role = !empty($row['contact_primary']) ? 'Primary' : (!empty($row['contact_technical']) ? 'Technical' : '');
return implode(' · ', array_filter([trim(html_entity_decode((string) ($row['contact_title'] ?? ''), ENT_QUOTES, 'UTF-8')), $role]));
}
/** For JSON (pickers, search): what contactAvatar() draws - the photo's URL, or their initials and colour. */
function contactAvatarData($client_id, $contact_id, $name, $photo) {
$photo = html_entity_decode((string) $photo, ENT_QUOTES, 'UTF-8');
if ($photo !== '') {
return ['image' => '/uploads/clients/' . intval($client_id) . '/' . rawurlencode($photo)];
}
return ['initials' => personInitials($name) ?: '?', 'tone' => contactAvatarTone($contact_id)];
}
/**
* How they log in to the client portal, or '' with no access: 'Password'
* or 'Microsoft'.
*/
function contactPortalAccess($contact_user_id, $auth_method) {
if (!intval($contact_user_id) || (string) $auth_method === '') {
return '';
}
return $auth_method === 'azure' ? 'Microsoft' : 'Password';
}
/**
* Their flags as pills: Primary (or Important when not primary - a primary
* contact is always important), Billing, Technical, and Portal when they can
* log in to the client portal.
*/
function contactFlagPills($row, $with_portal = true) {
$pills = [];
if (!empty($row['contact_primary'])) {
$pills[] = ['Primary', 'text-bg-success', 'The client\'s main contact'];
} elseif (!empty($row['contact_important'])) {
$pills[] = ['Important', 'bg-warning-subtle text-warning-emphasis', 'Pinned to the top of the list'];
}
if (!empty($row['contact_billing'])) {
$pills[] = ['Billing', 'bg-secondary-subtle text-secondary-emphasis', 'Receives invoices'];
}
if (!empty($row['contact_technical'])) {
$pills[] = ['Technical', 'bg-secondary-subtle text-secondary-emphasis', 'Technical contact'];
}
if ($with_portal) {
$portal = contactPortalAccess($row['contact_user_id'] ?? 0, $row['user_auth_method'] ?? '');
if ($portal) {
$pills[] = ['Portal', 'bg-info-subtle text-info-emphasis', "Client portal login ($portal)"];
}
}
$html = '';
foreach ($pills as [$label, $class, $title]) {
$html .= '<span class="badge rounded-pill fw-normal ' . $class . '" title="' . escapeHtml($title) . '">' . $label . '</span> ';
}
return rtrim($html);
}
/** A phone number as a tel: link, with its extension. '' when there is no number. */
function contactPhoneLink($phone, $country_code, $extension = '', $class = '') {
$phone = (string) $phone;
if ($phone === '') {
return '';
}
$display = escapeHtml(formatPhoneNumber($phone, $country_code));
$country_digits = preg_replace('/[^0-9]/', '', (string) $country_code);
$dial = escapeHtml(($country_digits !== '' ? "+$country_digits" : '') . preg_replace('/[^0-9]/', '', $phone));
$extension = escapeHtml($extension);
return '<a class="' . $class . '" href="tel:' . $dial . ($extension ? ",$extension" : '') . '">' . $display . '</a>'
. ($extension ? ' <span class="text-body-secondary">x' . $extension . '</span>' : '');
}
/*
* Quick picker (js/quick_pick.js) for a contact's location - the same picker
* the assets use, with the contact's client as the scope.
*/
/** The contact and their location, by id. */
function contactQuickRow($contact_id) {
global $mysqli;
return mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_client_id, contact_location_id,
location_name, location_archived_at
FROM contacts
LEFT JOIN locations ON location_id = contact_location_id
WHERE contact_id = " . intval($contact_id))) ?: null;
}
/** What the location picker shows - the asset location pill, fed the contact's row. */
function contactLocationHtml($row, $style = 'list') {
return assetQuickHtml('asset_location', [
'asset_client_id' => $row['contact_client_id'] ?? 0,
'asset_location_id' => $row['contact_location_id'] ?? 0,
'location_name' => $row['location_name'] ?? '',
'location_archived_at' => $row['location_archived_at'] ?? null,
], $style);
}
/** Move a contact to one of their client's locations (0 for none), as Edit Contact would. Returns [ok, plain-text message]. */
function contactQuickSetLocation($contact_id, $value) {
global $mysqli, $session_name;
$row = contactQuickRow($contact_id);
if (!$row) {
return [false, 'That contact no longer exists.'];
}
$contact_id = intval($row['contact_id']);
$client_id = intval($row['contact_client_id']);
$location_id = assetClientOwnedId('location', $value, $client_id);
if (intval($value) && !$location_id) {
return [false, 'That location is not one of this client\'s.'];
}
if ($location_id === intval($row['contact_location_id'])) {
return [true, ''];
}
$location_name = $location_id ? (string) mysqli_fetch_row(mysqli_query($mysqli, "SELECT location_name FROM locations WHERE location_id = $location_id"))[0] : '';
mysqli_query($mysqli, "UPDATE contacts SET contact_location_id = $location_id WHERE contact_id = $contact_id");
$contact_name = escapeSql($row['contact_name']);
logAudit("Contact", "Edit", $location_id
? "$session_name set the location of contact $contact_name to " . escapeSql($location_name)
: "$session_name removed the location of contact $contact_name", $client_id, $contact_id);
return [true, $location_id ? "Moved to $location_name" : 'Location removed'];
}
/** What quick_pick.js redraws after a change. */
function contactQuickRecord($contact_id) {
$row = contactQuickRow($contact_id);
return [
'current' => (string) intval($row['contact_location_id']),
'html' => ['list' => contactLocationHtml($row, 'list'), 'detail' => contactLocationHtml($row, 'detail')],
];
}

View File

@@ -394,12 +394,16 @@ function selectOptionUser($user_id, $user_name, $user_avatar = '') {
return selectOptionData(['initials' => personInitials($user_name), 'shape' => 'circle', 'tone' => 'secondary']);
}
/** A contact - their photo or initials, with their title underneath. */
function selectOptionContact($client_id, $contact_name, $contact_photo = '', $contact_title = '') {
/**
* A contact - their photo, or their initials on the same soft colour as their
* avatar everywhere else (contactAvatar() in functions/contact.php), with
* their title underneath. Without $contact_id the initials are grey.
*/
function selectOptionContact($client_id, $contact_name, $contact_photo = '', $contact_title = '', $contact_id = 0) {
$contact_photo = html_entity_decode((string) $contact_photo, ENT_QUOTES, 'UTF-8');
$data = $contact_photo !== ''
? ['image' => '/uploads/clients/' . intval($client_id) . '/' . rawurlencode($contact_photo)]
: ['initials' => personInitials($contact_name), 'shape' => 'circle', 'tone' => 'secondary'];
: ['initials' => personInitials($contact_name), 'shape' => 'circle', 'tone' => intval($contact_id) ? contactAvatarTone($contact_id) : 'secondary', 'soft' => '1'];
$data['description'] = $contact_title;
return selectOptionData($data);
}

View File

@@ -162,7 +162,7 @@ function globalSearchGroups($terms, $deep) {
: '';
$groups[] = [
'key' => 'contacts', 'label' => 'Contacts', 'icon' => 'address-book', 'module' => 'module_client',
'select' => 'contact_id, contact_name, contact_title, contact_email, contact_client_id, client_name',
'select' => 'contact_id, contact_name, contact_title, contact_email, contact_photo, contact_client_id, client_name',
'from' => 'contacts LEFT JOIN clients ON contact_client_id = client_id',
'where' => "contact_archived_at IS NULL
AND (contact_name LIKE '%$like%' OR contact_email LIKE '%$like%' OR contact_title LIKE '%$like%' $contact_phone_match)",
@@ -175,6 +175,8 @@ function globalSearchGroups($terms, $deep) {
'subtitle' => implode(' · ', array_filter([$row['contact_title'], $row['contact_email']])),
'context' => $row['client_name'],
'url' => globalSearchClientUrl('contact.php', $row['contact_client_id'], ['contact_id' => intval($row['contact_id'])]),
// Drawn in place of the group icon - the person's avatar, as everywhere else
'avatar' => contactAvatarData($row['contact_client_id'], $row['contact_id'], $row['contact_name'], $row['contact_photo']),
];
},
];

View File

@@ -277,7 +277,8 @@ function quickPick($field, $id, $current, $inner, $style = 'list', $status_id =
$labels = [
'priority' => 'Change priority', 'assignee' => 'Change who it is assigned to', 'billable' => 'Change billing', 'status' => 'Change status',
'project_manager' => 'Change the project manager', 'recurring_assignee' => 'Change who it is assigned to',
'asset_status' => 'Change status', 'asset_location' => 'Change location', 'asset_contact' => 'Change who it is assigned to'
'asset_status' => 'Change status', 'asset_location' => 'Change location', 'asset_contact' => 'Change who it is assigned to',
'contact_location' => 'Change location'
];
// On the ticket page it looks like the other editable properties there (agent/css/ticket.css)
$class = 'itflow-quick-pick itflow-quick-pick-' . $style . ($style === 'detail' ? ' ticket-prop-edit' : '');

View File

@@ -35,6 +35,7 @@
const MIN_LENGTH = 2;
const CACHE_SIZE = 50;
const BADGE_VARIANTS = ['primary', 'secondary', 'success', 'danger', 'warning', 'info', 'light', 'dark'];
const AVATAR_TONES = ['primary', 'success', 'info', 'warning', 'secondary'];
const MOD_KEY = /Mac|iPhone|iPad/.test(navigator.platform || navigator.userAgent || '') ? '⌘' : 'Ctrl';
let modalEl = null;
@@ -116,6 +117,27 @@
return frag;
}
// A contact's picture, or their initials on their colour - contactAvatar() in
// functions/contact.php draws the same thing server side
function avatar(spec) {
if (!spec) {
return null;
}
let node;
if (spec.image) {
node = el('img', 'itflow-contact-avatar itflow-contact-avatar-xs');
node.src = safeUrl(spec.image);
node.alt = '';
} else if (spec.initials) {
const tone = AVATAR_TONES.indexOf(spec.tone) !== -1 ? spec.tone : 'secondary';
node = el('span', 'itflow-contact-avatar itflow-contact-avatar-xs bg-' + tone + '-subtle text-' + tone + '-emphasis', spec.initials);
} else {
return null;
}
node.setAttribute('aria-hidden', 'true');
return node;
}
function badge(spec) {
if (!spec || !spec.text) {
return null;
@@ -156,7 +178,7 @@
body.append(sub);
}
link.append(icon(iconName, 'itflow-search-item-icon'), body);
link.append(avatar(parts.avatar) || icon(iconName, 'itflow-search-item-icon'), body);
const status = badge(parts.badge);
if (status || parts.context) {

View File

@@ -34,7 +34,9 @@
*
* data-image="/uploads/.." round picture (users, contacts)
* data-initials="RDG" initials tile; data-tone="primary" colours it,
* data-shape="circle" makes it round (people)
* data-shape="circle" makes it round (people),
* data-soft="1" puts it on the soft shade of
* that colour (contacts - their avatar's look)
* data-color="#e74c3c" colour dot (tags, categories, statuses)
* data-icon="fas fa-laptop" icon; with data-color it sits on that colour
* data-description=".." second, quieter line under the label
@@ -143,6 +145,7 @@
initials: data.initials || '',
tone: data.tone || '',
shape: data.shape || '',
soft: data.soft === '1',
disabled: option.disabled || !!(group && group.disabled),
group: group ? group.label : ''
};
@@ -157,14 +160,15 @@
/* The picture, tile, dot or icon in front of a label - or nothing. */
function lead(item) {
var node;
var node, tone;
if (item.image) {
node = make('img', 'itflow-select-avatar');
node.src = item.image;
node.alt = '';
node.loading = 'lazy';
} else if (item.initials) {
node = make('span', 'itflow-select-avatar text-bg-' + (TONES.indexOf(item.tone) === -1 ? 'secondary' : item.tone) + (item.shape === 'circle' ? '' : ' is-tile'), item.initials);
tone = TONES.indexOf(item.tone) === -1 ? 'secondary' : item.tone;
node = make('span', 'itflow-select-avatar ' + (item.soft ? 'bg-' + tone + '-subtle text-' + tone + '-emphasis' : 'text-bg-' + tone) + (item.shape === 'circle' ? '' : ' is-tile'), item.initials);
} else if (item.icon && item.color) {
node = make('span', 'itflow-select-badge');
node.style.setProperty('--itflow-select-color', item.color);

View File

@@ -1,13 +1,15 @@
/*
* Quick pickers - a ticket's status, priority, assignee and billable, a
* project's manager, a recurring ticket's assignee and an asset's status,
* location and contact, changed where you see them (ticket list and page,
* projects and project page, recurring tickets, assets list and asset page)
* instead of in a modal.
* project's manager, a recurring ticket's assignee, an asset's status,
* location and contact, and a contact's location, changed where you see them
* (ticket list and page, projects and project page, recurring tickets, the
* assets and contacts lists and their pages and quick looks) instead of in a modal.
*
* Click the value and a small menu opens under it (a sheet from the bottom
* on a phone): statuses and priorities with their colours, agents with their
* pictures and a search box, or Billable / Not billable. Pick one and it saves straight
* on a phone): statuses and priorities with their colours, agents and
* contacts with their pictures (contacts' initials on their own colour, as
* contactAvatar() draws them) and a search box, or Billable / Not billable.
* Pick one and it saves straight
* away through agent/ajax.php, which runs the same code as the old modals
* (functions/ticket_fields.php - history, audit log, SLA, notifications) and
* sends back the redrawn value. Assigning a New ticket opens it, so the
@@ -34,12 +36,13 @@
var finePointer = window.matchMedia('(pointer: fine)');
var titles = {
priority: 'Priority', assignee: 'Assign to', billable: 'Billing', status: 'Status', project_manager: 'Project manager', recurring_assignee: 'Assign to',
asset_status: 'Status', asset_location: 'Location', asset_contact: 'Assign to'
asset_status: 'Status', asset_location: 'Location', asset_contact: 'Assign to', contact_location: 'Location'
};
// People and places get a wider menu
var wideFields = ['assignee', 'project_manager', 'recurring_assignee', 'asset_location', 'asset_contact'];
var wideFields = ['assignee', 'project_manager', 'recurring_assignee', 'asset_location', 'asset_contact', 'contact_location'];
var cache = {};
var open = null;
var tones = ['primary', 'success', 'info', 'warning', 'secondary'];
function make(tag, className, text) {
var node = document.createElement(tag);
@@ -63,7 +66,8 @@
node.src = option.image;
node.alt = '';
} else if (option.initials) {
node = make('span', 'itflow-select-avatar text-bg-secondary', option.initials);
// A contact carries their own colour, on its soft shade like their avatar
node = make('span', 'itflow-select-avatar ' + (tones.indexOf(option.tone) !== -1 ? 'bg-' + option.tone + '-subtle text-' + option.tone + '-emphasis' : 'text-bg-secondary'), option.initials);
} else if (option.color) {
node = make('span', 'itflow-select-dot');
node.style.setProperty('--itflow-select-color', option.color);