Files
itflow/client/licenses.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

115 lines
6.0 KiB
PHP

<?php
/*
* Client Portal
* Licenses - the software the company is licensed for: how many seats are in
* use of how many bought, and when each renews, with tabs for the ones
* renewing in the next 30 days and the ones that have run out. License keys
* stay on the agent side.
*
* SCOPING: primary and technical contacts (portalItGate()); keyed to
* $session_client_id.
*/
header("Content-Security-Policy: default-src 'self'");
require_once "includes/inc_all.php";
portalItGate();
$q = trim((string) ($_GET['q'] ?? ''));
$tabs = [
'all' => ['label' => 'All', 'icon' => 'fa-list', 'where' => '1 = 1'],
'soon' => ['label' => 'Renewing soon', 'icon' => 'fa-hourglass-half', 'where' => 'software_expire BETWEEN CURDATE() AND CURDATE() + INTERVAL 30 DAY'],
'expired' => ['label' => 'Expired', 'icon' => 'fa-calendar-times', 'where' => 'software_expire < CURDATE()'],
];
$where = "software_client_id = $session_client_id AND software_archived_at IS NULL";
if ($q !== '') {
$q_sql = escapeSql($q);
$where .= " AND (software_name LIKE '%$q_sql%' OR software_type LIKE '%$q_sql%' OR vendor_name LIKE '%$q_sql%')";
}
$from = "FROM software LEFT JOIN vendors ON vendor_id = software_vendor_id WHERE $where";
$count_sql = [];
foreach ($tabs as $key => $t) {
$count_sql[] = "COALESCE(SUM({$t['where']}), 0) AS `$key`";
}
$counts = array_map('intval', mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " $from")));
$tab = isset($tabs[$_GET['tab'] ?? '']) ? $_GET['tab'] : 'all';
$licenses = mysqli_query($mysqli, "SELECT software_id, software_name, software_version, software_type, software_license_type, software_seats, software_expire, vendor_name,
" . softwareSeatsUsedSql('software.software_id') . " AS seats_used
$from AND {$tabs[$tab]['where']}
ORDER BY software_name ASC");
/** This page's address with some of its settings changed. */
function licensesUrl(array $changes) {
global $tab, $q;
$params = array_merge(['tab' => $tab !== 'all' ? $tab : null, 'q' => $q !== '' ? $q : null], $changes);
$params = array_filter($params, function ($v) { return $v !== null && $v !== ''; });
return 'licenses.php' . ($params ? '?' . http_build_query($params) : '');
}
?>
<div class="itflow-portal-page-head">
<div>
<h1>Licenses</h1>
<p>The software you are licensed for, and when it renews</p>
</div>
<form method="get" class="d-flex" role="search">
<?php if ($tab !== 'all') { ?><input type="hidden" name="tab" value="<?= escapeHtml($tab) ?>"><?php } ?>
<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, kind or vendor" aria-label="Search licenses" maxlength="200">
</div>
</form>
</div>
<nav class="itflow-portal-tabs" aria-label="Licenses">
<?php foreach ($tabs as $key => $t) { ?>
<a class="<?= $key === $tab ? 'active' : '' ?><?= $key !== 'all' && $counts[$key] ? ' itflow-portal-tab-alert' : '' ?>" href="<?= escapeHtml(licensesUrl(['tab' => $key])) ?>">
<i class="fas <?= $t['icon'] ?>"></i><?= escapeHtml($t['label']) ?>
<span class="badge rounded-pill"><?= $counts[$key] ?></span>
</a>
<?php } ?>
</nav>
<section class="itflow-portal-panel">
<?php if (!mysqli_num_rows($licenses)) { ?>
<?php if ($q !== '') { ?>
<?= emptyStateHtml(['thing' => 'licenses', 'filtered' => true, 'match_text' => 'No license has &ldquo;' . escapeHtml($q) . '&rdquo; in its name, kind or vendor.', 'clear_url' => licensesUrl(['q' => null])]) ?>
<?php } elseif ($tab === 'soon') { ?>
<?= emptyStateHtml(['title' => 'Nothing renewing soon', 'text' => 'Licenses renewing in the next 30 days show here.', 'icon' => 'fa-check', 'filtered' => false]) ?>
<?php } elseif ($tab === 'expired') { ?>
<?= emptyStateHtml(['title' => 'Nothing has run out', 'text' => '', 'icon' => 'fa-check', 'filtered' => false]) ?>
<?php } else { ?>
<?= emptyStateHtml(['title' => 'No licenses yet', 'text' => 'The software we manage for you shows here.', 'icon' => 'fa-cube', 'filtered' => false]) ?>
<?php } ?>
<?php } else { ?>
<ul class="itflow-portal-list">
<?php while ($row = mysqli_fetch_assoc($licenses)) {
$seats = softwareSeats($row['seats_used'], $row['software_seats']);
$renewal = portalRenewalState(softwareRenewal($row['software_expire'])); ?>
<li class="itflow-portal-ticket">
<?= portalTile(softwareTypeStyle($row['software_type'])['icon']) ?>
<span class="itflow-portal-ticket-main">
<span class="itflow-portal-ticket-subject d-block"><?= escapeHtml(trim($row['software_name'] . ' ' . $row['software_version'])) ?></span>
<span class="itflow-portal-ticket-meta">
<?php foreach (array_filter([$row['software_type'], $row['software_license_type'], $row['vendor_name']]) as $part) { ?><span><?= escapeHtml($part) ?></span><?php } ?>
<span class="<?= $seats['state'] === 'over' ? 'text-danger-emphasis' : '' ?>" title="<?= escapeHtml($seats['title']) ?>"><i class="fas fa-users me-1"></i><?= $seats['state'] === 'unlimited' ? escapeHtml($seats['text']) : $seats['used'] . ' of ' . $seats['total'] . ' seats in use' ?></span>
</span>
</span>
<?php if ($renewal) { ?>
<span class="itflow-portal-ticket-side">
<?= portalStateBadge($renewal) ?>
<small><?= escapeHtml(date('M j, Y', strtotime($row['software_expire']))) ?></small>
</span>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
</section>
<?php
require_once "includes/footer.php";