Files
itflow/client/contacts.php
johnnyq 5e77edb077 Client portal stage 3: Your IT - Devices with tabs by kind (Computers, Servers, Network, Phones and tablets, Other) with counts, an Everyone's or Mine filter, search and warranty badges when expired or expiring; a device page with make and model, serial, OS, user, location, purchase date and age, warranty, status, open tickets and licenses on it, Report a problem opening a new ticket with the device picked and plain contacts reaching their own devices from home; Licenses with All, Renewing soon and Expired tabs showing seats in use and renewal state without license keys; Domains and certificates on one page with registrar, DNS, website and email vendors, expiry and auto-renew, and a certificates tab with short-lived certificates shown as renewing themselves, the old certificates page redirecting there; Documents as a help library of client-visible documents with folder tabs and full-text search, a document page keeping its own tables and colours under a widened style policy, files to open or download with the first PDF or image shown inline, Print and Ask us about it, and new documents written in the editor or uploaded as a file with an agent notification; Contacts listing everyone primary first with roles and search, and the primary contact alone adding and editing contacts, giving portal access with an emailed set-password or Microsoft 365 invite, resending it, turning access off and marking someone as left, which turns off access and opens an offboarding ticket, all audited and notified; home renewals and devices linking to their pages; fixes a technical contact being able to change the primary contact's login email, revoked contacts staying signed in, portal documents recording the contact id as author, the upload stub going in unescaped and gated pages leaving a bare header; check_login ends sessions without a sign-in method, header.php buffers output so gates redirect properly, enforceContactCan sends contacts home with a message instead of logging them out, add_contact and edit_contact replaced by portal_contact_save, portal_contact_access and portal_contact_left, new Your IT helpers in client/functions.php and portal tile, roles, PDF and document styles; changelog updated
2026-10-17 02:40:59 -04:00

93 lines
5.2 KiB
PHP

<?php
/*
* Client Portal
* Contacts - the people at the company, with how to reach them and their
* roles, searchable. The primary contact also sees who can sign in to the
* portal, and adds and manages people from here (contact.php).
*
* SCOPING: primary and technical contacts see the list
* (contactCan('contacts')); keyed to $session_client_id.
*/
header("Content-Security-Policy: default-src 'self'");
require_once "includes/inc_all.php";
enforceContactCan('contacts');
$manage = contactCan('contacts_manage');
$q = trim((string) ($_GET['q'] ?? ''));
$where = "contact_client_id = $session_client_id AND contact_archived_at IS NULL";
if ($q !== '') {
$q_sql = escapeSql($q);
$q_digits = preg_replace('/\D/', '', $q);
$where .= " AND (contact_name LIKE '%$q_sql%' OR contact_email LIKE '%$q_sql%' OR contact_title LIKE '%$q_sql%' OR contact_department LIKE '%$q_sql%'"
. ($q_digits !== '' ? " OR contact_phone LIKE '%$q_digits%' OR contact_mobile LIKE '%$q_digits%'" : '') . ")";
}
$contacts = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_title, contact_email, contact_phone, contact_phone_country_code, contact_extension,
contact_mobile, contact_mobile_country_code, contact_photo, contact_primary, contact_billing, contact_technical, contact_department,
user_id, user_auth_method, user_status, user_archived_at
FROM contacts LEFT JOIN users ON user_id = contact_user_id
WHERE $where
ORDER BY contact_primary DESC, contact_name ASC");
?>
<div class="itflow-portal-page-head">
<div>
<h1>Contacts</h1>
<p>The people at <?= escapeHtml($session_client_name) ?><?= $manage ? ', and who can sign in here' : '' ?></p>
</div>
<div class="d-flex flex-wrap align-items-center gap-2">
<form method="get" class="d-flex" role="search">
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-search"></i></span>
<input type="search" class="form-control" name="q" value="<?= escapeHtml($q) ?>" placeholder="Name, email, title or phone" aria-label="Search contacts" maxlength="200">
</div>
</form>
<?php if ($manage) { ?>
<a class="btn btn-primary" href="contact.php?new=1"><i class="fas fa-user-plus me-2"></i>Add a person</a>
<?php } ?>
</div>
</div>
<section class="itflow-portal-panel">
<?php if (!mysqli_num_rows($contacts)) { ?>
<?php if ($q !== '') { ?>
<?= emptyStateHtml(['thing' => 'people', 'filtered' => true, 'match_text' => 'Nobody here matches &ldquo;' . escapeHtml($q) . '&rdquo;.', 'clear_url' => 'contacts.php']) ?>
<?php } else { ?>
<?= emptyStateHtml(['title' => 'No contacts yet', 'text' => '', 'icon' => 'fa-address-book', 'filtered' => false]) ?>
<?php } ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php while ($row = mysqli_fetch_assoc($contacts)) {
$id = intval($row['contact_id']);
$phone = !empty($row['contact_phone']) ? formatPhoneNumber($row['contact_phone'], $row['contact_phone_country_code']) . (!empty($row['contact_extension']) ? ' x' . $row['contact_extension'] : '')
: (!empty($row['contact_mobile']) ? formatPhoneNumber($row['contact_mobile'], $row['contact_mobile_country_code']) : '');
$access = portalContactAccess($row); ?>
<li>
<a class="itflow-portal-ticket" href="contact.php?id=<?= $id ?>">
<?= portalAvatarHtml((string) $row['contact_name'], !empty($row['contact_photo']) ? "/uploads/clients/$session_client_id/" . rawurlencode(basename($row['contact_photo'])) : '') ?>
<span class="itflow-portal-ticket-main">
<span class="itflow-portal-ticket-subject d-block"><?= escapeHtml($row['contact_name']) ?><?= $id === $session_contact_id ? '<span class="fw-normal text-body-secondary"> (you)</span>' : '' ?></span>
<span class="itflow-portal-ticket-meta">
<?php foreach (array_filter([$row['contact_title'], $row['contact_department']]) as $part) { ?><span><?= escapeHtml($part) ?></span><?php } ?>
<?php if (!empty($row['contact_email'])) { ?><span><i class="fas fa-envelope me-1"></i><?= escapeHtml($row['contact_email']) ?></span><?php } ?>
<?php if ($phone !== '') { ?><span><i class="fas fa-phone me-1"></i><?= escapeHtml($phone) ?></span><?php } ?>
</span>
</span>
<span class="itflow-portal-ticket-side">
<?php if ($roles = portalContactRoles($row)) { ?>
<span class="itflow-portal-roles"><?php foreach ($roles as $role) { ?><span><?= escapeHtml($role) ?></span><?php } ?></span>
<?php } ?>
<?php if ($manage) { ?><?= portalStateBadge($access) ?><?php } ?>
</span>
</a>
</li>
<?php } ?>
</ul>
<?php } ?>
</section>
<?php
require_once "includes/footer.php";