Print a ticket as a work order and an asset as a spec sheet: Print Work Order in the ticket menu, or the browser print, gives the letterhead, who and where with access notes, the job details, assets, description, client-visible fill-ins, tasks as boxes to tick, public replies oldest first and a sign-off with times, work done lines and signatures, never internal notes; the asset print button beside Copy Details gives its hardware, network, location and assignee, interfaces, devices in it, licenses, services and quick notes with a QR code that opens it, never credentials or license keys; both print black on white in either theme and the ticket menu now shows for every agent; 26.12.3 changelog entries

This commit is contained in:
johnnyq
2026-11-29 22:36:50 -05:00
parent fffa5680db
commit 52e340b85c
7 changed files with 668 additions and 3 deletions

View File

@@ -34,6 +34,8 @@ Update from Maintenance > Update as usual - this release has four database chang
- An identity provider can be required: the accounts on its email domains then can't sign in with a password, and the sign-in page says which button to use. Passkeys still work, and an agent with an administrator role keeps their password, to get back in if the provider is down.
- An agent who signs in with an identity provider or their mail password finds their credentials locked, as after some passkeys: the first username or password they open asks for their ITFlow password, once, until they sign out.
- Admin > Settings > Single Sign-on is gone: the client portal's Microsoft 365 sign-in is now a Microsoft 365 identity provider. A contact's Login of Only with an identity provider (once called With their Microsoft account) signs in only that way, with no password, and is offered when a provider is on for client contacts.
- Printing a ticket prints a work order instead of the page as it looks on screen: your letterhead, the client and contact, the site with its access notes, the job's details, its assets, the description, the fill-ins the client can see, the tasks as boxes to tick, the public replies oldest first, and a sign-off with arrival and departure times, lines for the work done and signatures. Internal notes never print. It's Print Work Order in the ticket's menu, or the browser's own print.
- Printing an asset prints a spec sheet: its hardware, network, where it is and who has it, its interfaces, the devices in it, its licenses and services and its quick notes, with a QR code that opens it in ITFlow. Credentials and license keys never print. The new print button sits beside Copy Details.
### Bug Fixes
@@ -68,6 +70,7 @@ Update from Maintenance > Update as usual - this release has four database chang
- functions/identity_provider.php: the kinds, who a provider covers (identityProviderCovers(), identityProviderFor(), identityProviderRequiredFor(), identityProviderImapFor()), the OpenID Connect code flow with PKCE S256 (identityProviderEndpoints() - Microsoft and Google fixed, Nextcloud from its discovery document; identityProviderAuthorizeUrl(), identityProviderIdentity()) and the IMAP check (identityProviderImapCheck(), DirectoryTree ImapEngine, certificate checked). Microsoft's address is Graph /me userPrincipalName (guests refused), Google's needs email_verified.
- login_provider.php starts a sign-in (?provider=N, a single-use state in the session, ten minutes) and takes the code back, then hands the account to login.php as ?provider_login= with $_SESSION['pending_provider_login'], which signs in through its usual success path - role choice included - with $_SESSION['signed_in_with'] = 'provider' (left out of MFA enforcement as a passkey is) and signed_in_via the provider's name. client/login_microsoft.php serves it for the migrated app's redirect address. IMAP is checked in login.php's password step ('imap'); an administrator's own password still works there.
- Admin: admin/identity_providers.php (list), admin/modals/identity_provider/identity_provider_edit.php (Add and Edit), admin/post/identity_provider.php (save_identity_provider, turn_identity_provider_on / off, delete_identity_provider - locked in the demo). The identity settings page and edit_identity_provider are gone. portalSignInMethods() and identityProviderContactsWording() take an email, to offer only the providers that sign it in; vaultLockedReason() says why the vault is locked.
- functions/print_sheet.php draws the work order (ticketWorkOrderHtml()) and spec sheet (assetSpecSheetHtml()) into their pages, hidden on screen; css .itflow-print-sheet hides the rest of the page when printing (the .container-fluid:has() rule). [data-print-page] buttons call window.print() (js/app.js). The ticket's actions bar and menu now show for every agent.
## [26.12.2]

View File

@@ -332,6 +332,9 @@ if (mysqli_num_rows($sql) == 0) {
<button type="button" class="btn btn-outline-secondary clipboardjs" data-clipboard-text="<?= escapeHtml(assetDetailsText($asset_id)) ?>" title="Copy its make, serial, OS, address, warranty and where it is as text - for a vendor's support case or an email">
<i class="far fa-clipboard me-2"></i>Copy Details
</button>
<button type="button" class="btn btn-outline-secondary" data-print-page title="Print a spec sheet: its hardware, network, where it is, interfaces, licenses and services, with a QR code to open it here - no credentials">
<i class="fas fa-print"></i><span class="visually-hidden">Print</span>
</button>
<?php if ($can_edit) { ?>
<div class="dropdown">
<button type="button" class="btn btn-primary dropdown-toggle" data-bs-toggle="dropdown"><i class="fas fa-plus me-2"></i>New</button>
@@ -1390,6 +1393,18 @@ if (mysqli_num_rows($sql) == 0) {
</div>
<!-- What prints - the spec sheet, in place of the page (functions/print_sheet.php) -->
<?= assetSpecSheetHtml($asset_row, [
'spec_rows' => $asset_spec_rows,
'guests' => $asset_guests,
'rack' => $asset_rack,
'holds' => $asset_holds ?: [],
'interfaces' => $interfaces,
'interface_links' => $interface_links,
'software' => $held_software,
'services' => $linked_services,
]) ?>
<script>
// Interfaces as ports or as a table - remembered between visits

View File

@@ -583,9 +583,9 @@ if (isset($_GET['ticket_id'])) {
<!--
One primary action for the stage the ticket is at. Billing and
the rarer actions live in the menu; Invoice comes out of it once
the work is done, which is when it is actually wanted.
the work is done, which is when it is actually wanted. The menu is
there for everyone: it prints the work order.
-->
<?php if ($can_edit_ticket || $ai_summary_available || $show_trips || $kb_write_up_available) { ?>
<div class="ticket-actions d-flex flex-wrap align-items-center gap-2 d-print-none">
<?php if ($can_edit_ticket && $ticket_is_open) { ?>
@@ -646,6 +646,12 @@ if (isset($_GET['ticket_id'])) {
<i class="fas fa-fw fa-ellipsis-v"></i>
</button>
<div class="dropdown-menu dropdown-menu-end">
<button type="button" class="dropdown-item" data-print-page title="The ticket as a work order: who, where, the job, its tasks and public replies, and lines to sign it off">
<i class="fas fa-fw fa-print me-2"></i>Print Work Order
</button>
<?php if ($ai_summary_available || $ai_triage_available || $ai_document_available || $kb_write_up_available || $show_trips || $can_edit_ticket) { ?>
<div class="dropdown-divider"></div>
<?php } ?>
<?php if ($ai_summary_available) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket/ticket_summary.php?ticket_id=<?= $ticket_id ?>" data-modal-size="lg">
<i class="fas fa-fw fa-magic me-2"></i>Summarize with AI
@@ -722,7 +728,6 @@ if (isset($_GET['ticket_id'])) {
</div>
</div>
<?php } ?>
</div>
</div>
@@ -2114,6 +2119,9 @@ if (isset($_GET['ticket_id'])) {
</div> <!-- End ticket-layout -->
<!-- What prints - the work order, in place of the page (functions/print_sheet.php) -->
<?= ticketWorkOrderHtml($ticket, $purifier, $ticket_reply_rows) ?>
<?php
}
}

View File

@@ -11370,3 +11370,294 @@ input.itflow-filter-on {
outline-offset: -2px;
background-color: var(--bs-primary-bg-subtle);
}
/* ==========================================================================
Printed sheets - a ticket's work order and an asset's spec sheet
(functions/print_sheet.php). Hidden on screen; printing a page that has one
prints the sheet and nothing else of the page. Black on white in either
theme, sized in points so the print-wide 71% root size doesn't shrink it.
========================================================================== */
.itflow-print-sheet {
display: none;
}
@media print {
.app-content > .container-fluid:has(> .itflow-print-sheet) > :not(.itflow-print-sheet) {
display: none !important;
}
.itflow-print-sheet {
--print-rule: #b8b8b8;
--print-muted: #555;
display: block;
color: #000;
background: #fff;
font-size: 10pt;
line-height: 1.4;
}
.itflow-print-sheet a {
color: inherit;
text-decoration: none;
}
.itflow-print-head {
display: flex;
align-items: flex-start;
gap: 14pt;
padding-bottom: 8pt;
margin-bottom: 10pt;
border-bottom: 1.5pt solid #000;
}
.itflow-print-company {
display: flex;
align-items: flex-start;
gap: 8pt;
flex: 1 1 auto;
min-width: 0;
font-size: 8.5pt;
color: var(--print-muted);
}
.itflow-print-logo {
max-width: 110pt;
max-height: 40pt;
object-fit: contain;
}
.itflow-print-company-name {
font-size: 12pt;
font-weight: 700;
color: #000;
}
.itflow-print-doc {
flex: 0 0 auto;
text-align: right;
font-size: 8.5pt;
color: var(--print-muted);
}
.itflow-print-kind {
font-size: 8.5pt;
font-weight: 700;
letter-spacing: .1em;
text-transform: uppercase;
color: #000;
}
.itflow-print-ref {
font-size: 17pt;
font-weight: 700;
line-height: 1.15;
color: #000;
}
.itflow-print-qr {
flex: 0 0 auto;
}
.itflow-print-qr svg {
display: block;
width: 62pt;
height: 62pt;
}
.itflow-print-title {
margin: 0;
font-size: 15pt;
font-weight: 700;
line-height: 1.25;
}
.itflow-print-subtitle {
margin-top: 2pt;
font-size: 9.5pt;
color: var(--print-muted);
}
.itflow-print-grid {
display: flex;
gap: 8pt;
margin-top: 10pt;
}
.itflow-print-box {
flex: 1 1 0;
min-width: 0;
padding: 6pt 8pt;
border: .75pt solid var(--print-rule);
border-radius: 3pt;
font-size: 9pt;
break-inside: avoid;
overflow-wrap: anywhere;
}
.itflow-print-heading {
margin: 0 0 4pt;
font-size: 7.5pt;
font-weight: 700;
letter-spacing: .1em;
text-transform: uppercase;
color: var(--print-muted);
}
.itflow-print-section {
margin-top: 12pt;
}
.itflow-print-section > .itflow-print-heading {
padding-bottom: 2pt;
border-bottom: .75pt solid var(--print-rule);
break-after: avoid;
}
.itflow-print-strong {
font-weight: 700;
}
.itflow-print-muted {
color: var(--print-muted);
}
.itflow-print-note {
margin-top: 4pt;
padding-top: 4pt;
border-top: .75pt dotted var(--print-rule);
}
.itflow-print-fields {
display: grid;
grid-template-columns: max-content minmax(0, 1fr);
gap: 1pt 8pt;
margin: 0;
}
.itflow-print-fields dt {
font-weight: 600;
color: var(--print-muted);
}
.itflow-print-fields dd {
margin: 0;
overflow-wrap: anywhere;
}
.itflow-print-section > .itflow-print-fields {
grid-template-columns: max-content minmax(0, 1fr) max-content minmax(0, 1fr);
}
.itflow-print-table {
width: 100%;
border-collapse: collapse;
font-size: 9pt;
}
.itflow-print-table th {
padding: 2pt 6pt 2pt 0;
font-size: 7.5pt;
font-weight: 700;
text-align: left;
text-transform: uppercase;
letter-spacing: .06em;
color: var(--print-muted);
}
.itflow-print-table td {
padding: 3pt 6pt 3pt 0;
vertical-align: top;
border-top: .75pt solid var(--print-rule);
overflow-wrap: anywhere;
}
.itflow-print-table tr {
break-inside: avoid;
}
/* A table with no heads sits right under its section's rule */
.itflow-print-table > tbody:first-child > tr:first-child > td {
border-top: 0;
}
.itflow-print-prose {
overflow-wrap: anywhere;
}
.itflow-print-prose > :last-child {
margin-bottom: 0;
}
.itflow-print-prose img {
max-width: 100% !important;
height: auto !important;
}
.itflow-print-prose table {
max-width: 100%;
}
.itflow-print-tasks {
margin: 0;
padding: 0;
list-style: none;
}
.itflow-print-tasks li {
display: flex;
align-items: baseline;
gap: 6pt;
padding: 2.5pt 0;
break-inside: avoid;
}
.itflow-print-tasks li.is-done {
color: var(--print-muted);
}
.itflow-print-check {
display: inline-flex;
align-items: center;
justify-content: center;
flex: 0 0 auto;
width: 10pt;
height: 10pt;
border: .75pt solid #000;
font-size: 8pt;
line-height: 1;
color: #000;
transform: translateY(1pt);
}
.itflow-print-reply {
padding: 4pt 0 6pt 8pt;
margin-bottom: 6pt;
border-left: 1.5pt solid var(--print-rule);
}
.itflow-print-reply.is-client {
border-left-color: #000;
}
.itflow-print-reply-head {
display: flex;
flex-wrap: wrap;
justify-content: space-between;
gap: 2pt 10pt;
margin-bottom: 2pt;
font-size: 8.5pt;
color: var(--print-muted);
break-after: avoid;
}
.itflow-print-reply-head .fw-semibold {
color: #000;
}
.itflow-print-signoff {
break-inside: avoid;
}
.itflow-print-label {
margin-top: 8pt;
font-size: 8.5pt;
font-weight: 600;
color: var(--print-muted);
}
.itflow-print-times {
display: grid;
grid-template-columns: repeat(4, minmax(0, 1fr));
gap: 12pt;
margin-top: 14pt;
}
.itflow-print-sign-line {
min-height: 16pt;
border-bottom: .75pt solid #000;
}
.itflow-print-times span,
.itflow-print-sign span {
display: block;
font-size: 7.5pt;
color: var(--print-muted);
}
.itflow-print-lines > div {
height: 18pt;
border-bottom: .75pt solid var(--print-rule);
}
.itflow-print-sign {
display: grid;
grid-template-columns: repeat(2, minmax(0, 1fr));
gap: 18pt 24pt;
margin-top: 22pt;
}
.itflow-print-sign-line {
display: flex;
align-items: flex-end;
padding-bottom: 1pt;
}
.itflow-print-times span,
.itflow-print-sign span {
padding-top: 2pt;
}
.itflow-print-foot {
margin-top: 14pt;
padding-top: 4pt;
border-top: .75pt solid var(--print-rule);
font-size: 7.5pt;
color: var(--print-muted);
}
}

View File

@@ -49,6 +49,7 @@ require_once __DIR__ . '/functions/audit_log.php';
require_once __DIR__ . '/functions/sign_in.php';
require_once __DIR__ . '/functions/passkey.php';
require_once __DIR__ . '/functions/identity_provider.php';
require_once __DIR__ . '/functions/print_sheet.php';
require_once __DIR__ . '/functions/app_log.php';
require_once __DIR__ . '/functions/app.php';
require_once __DIR__ . '/functions/email.php';

333
functions/print_sheet.php Normal file
View File

@@ -0,0 +1,333 @@
<?php
/*
* Printed sheets - a ticket's work order (agent/ticket.php) and an asset's spec sheet
* (agent/asset.php). Each page draws its sheet hidden on screen; printing the page - its Print, or
* the browser's own - prints the sheet and nothing else (css .itflow-print-sheet), so what comes
* out is the same either way. Black on white in either theme, with the company's letterhead.
*
* The work order is safe to hand to the client: its public replies only, and the fill-ins the
* client can see - never internal notes. The spec sheet never shows credentials or license keys,
* as it gets left in racks and on desks; its QR code opens the asset in ITFlow, signed in.
*/
/** The letterhead: the company on the left, what this is and its reference on the right - then its title. */
function printSheetHeadHtml($kind, $reference, $title, array $subtitle = [], array $meta = [], $aside_html = '') {
$company = billingCompany();
$company_lines = array_filter([
formatAddress($company['company_address'] ?? '', $company['company_city'] ?? '', $company['company_state'] ?? '', $company['company_zip'] ?? '', '', ', '),
implode(' · ', array_filter([$company['phone_display'] ?? '', $company['company_email'] ?? '', $company['company_website'] ?? ''])),
]);
$html = '<div class="itflow-print-head">'
. '<div class="itflow-print-company">'
. (!empty($company['logo_url']) ? '<img class="itflow-print-logo" src="' . escapeHtml($company['logo_url']) . '" alt="">' : '')
. '<div><div class="itflow-print-company-name">' . escapeHtml($company['company_name'] ?? '') . '</div>'
. implode('', array_map(function ($line) {
return '<div>' . escapeHtml($line) . '</div>';
}, $company_lines))
. '</div></div>'
. '<div class="itflow-print-doc"><div class="itflow-print-kind">' . escapeHtml($kind) . '</div>'
. ($reference !== '' ? '<div class="itflow-print-ref">' . escapeHtml($reference) . '</div>' : '')
. implode('', array_map(function ($line) {
return '<div>' . escapeHtml($line) . '</div>';
}, array_filter($meta)))
. '</div>'
. ($aside_html !== '' ? '<div class="itflow-print-qr">' . $aside_html . '</div>' : '')
. '</div>';
$html .= '<h1 class="itflow-print-title">' . escapeHtml($title) . '</h1>';
$subtitle = array_filter(array_map('trim', $subtitle), 'strlen');
if ($subtitle) {
$html .= '<div class="itflow-print-subtitle">' . escapeHtml(implode(' · ', $subtitle)) . '</div>';
}
return $html;
}
/** Label and value pairs, leaving out the empty ones - [label => value HTML]. '' when none are left. */
function printSheetFieldsHtml(array $fields) {
$html = '';
foreach ($fields as $label => $value) {
if (trim(strip_tags((string) $value)) === '') {
continue;
}
$html .= '<dt>' . escapeHtml($label) . '</dt><dd>' . $value . '</dd>';
}
return $html === '' ? '' : '<dl class="itflow-print-fields">' . $html . '</dl>';
}
/** A boxed block with a small heading - '' when it has nothing in it. */
function printSheetBoxHtml($heading, $body_html) {
if (trim(strip_tags((string) $body_html, '<img>')) === '') {
return '';
}
return '<div class="itflow-print-box"><div class="itflow-print-heading">' . escapeHtml($heading) . '</div>' . $body_html . '</div>';
}
/** A section of the sheet - a heading over its body; '' when it has nothing in it. */
function printSheetSectionHtml($heading, $body_html, $attributes = '') {
if (trim(strip_tags((string) $body_html, '<img><input>')) === '') {
return '';
}
return '<section class="itflow-print-section" ' . $attributes . '><h2 class="itflow-print-heading">' . escapeHtml($heading) . '</h2>' . $body_html . '</section>';
}
/** Ruled lines to write on. */
function printSheetLinesHtml($count) {
return '<div class="itflow-print-lines">' . str_repeat('<div></div>', max(1, intval($count))) . '</div>';
}
/** Who printed it and when, for the foot of a sheet. */
function printSheetPrintedText() {
global $session_name;
return 'Printed ' . formatDateTime(date('Y-m-d H:i:s')) . (!empty($session_name) ? ' by ' . $session_name : '');
}
/** Lines of text with line breaks kept, escaped. */
function printSheetText($text) {
return nl2br(escapeHtml(trim((string) $text)));
}
/*
* A ticket's work order: who and where, the job's details, its assets, the description, the
* fill-ins the client can see, the tasks to tick, its public replies oldest first, and lines to
* sign off on-site work. $ticket is agent/ticket.php's row (the ticket with its client, contact,
* location, asset, assignee, status and category); $replies its replies, any order.
*/
function ticketWorkOrderHtml(array $ticket, $purifier, array $replies) {
global $mysqli;
$ticket_id = intval($ticket['ticket_id']);
$client_id = intval($ticket['ticket_client_id']);
// Who it's for
$contact_lines = [];
if (!empty($ticket['contact_name'])) {
$contact_lines[] = '<div class="fw-semibold">' . escapeHtml($ticket['contact_name']) . '</div>'
. (!empty($ticket['contact_title']) ? '<div>' . escapeHtml($ticket['contact_title']) . '</div>' : '');
foreach ([['contact_phone', 'contact_phone_country_code', 'Phone'], ['contact_mobile', 'contact_mobile_country_code', 'Mobile']] as [$phone, $code, $label]) {
if (!empty($ticket[$phone])) {
$contact_lines[] = '<div>' . $label . ' ' . escapeHtml(formatPhoneNumber($ticket[$phone], $ticket[$code] ?? ''))
. ($phone === 'contact_phone' && !empty($ticket['contact_extension']) ? ' x' . escapeHtml($ticket['contact_extension']) : '') . '</div>';
}
}
if (!empty($ticket['contact_email'])) {
$contact_lines[] = '<div>' . escapeHtml($ticket['contact_email']) . '</div>';
}
}
$for_html = ($client_id ? '<div class="itflow-print-strong">' . escapeHtml($ticket['client_name']) . '</div>' : '') . implode('', $contact_lines);
// Where - the site, how to get in
$site_html = '';
if (intval($ticket['location_id'] ?? 0)) {
$address = locationAddressText($ticket, true);
$site_html = '<div class="itflow-print-strong">' . escapeHtml($ticket['location_name']) . '</div>'
. ($address !== '' ? '<div>' . printSheetText($address) . '</div>' : '')
. (!empty($ticket['location_phone']) ? '<div>Phone ' . escapeHtml(formatPhoneNumber($ticket['location_phone'], $ticket['location_phone_country_code'] ?? '')) . (!empty($ticket['location_phone_extension']) ? ' x' . escapeHtml($ticket['location_phone_extension']) : '') . '</div>' : '')
. (!empty($ticket['location_hours']) ? '<div>Hours ' . escapeHtml($ticket['location_hours']) . '</div>' : '')
. (trim((string) ($ticket['location_notes'] ?? '')) !== '' ? '<div class="itflow-print-note">' . printSheetText($ticket['location_notes']) . '</div>' : '');
}
// The job
$schedule = !empty($ticket['ticket_schedule']) ? ticketScheduleShortText($ticket['ticket_schedule'], $ticket['ticket_schedule_end'] ?? null) : '';
$job_html = printSheetFieldsHtml([
'Status' => escapeHtml($ticket['ticket_status_name'] ?? ''),
'Priority' => escapeHtml($ticket['ticket_priority'] ?? ''),
'Category' => escapeHtml($ticket['category_name'] ?? ''),
'Assigned' => escapeHtml(intval($ticket['ticket_assigned_to'] ?? 0) ? ($ticket['user_name'] ?? '') : 'Not assigned'),
'Scheduled' => escapeHtml($schedule . ($schedule !== '' && intval($ticket['ticket_onsite'] ?? 0) ? ', on site' : '')),
'Opened' => escapeHtml(formatDate($ticket['ticket_created_at'])),
'Their ref' => escapeHtml($ticket['ticket_vendor_ticket_number'] ?? ''),
]);
// Its assets - the ticket's own first
$assets = [];
$asset_sql = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_make, asset_model, asset_serial, interface_ip FROM assets
LEFT JOIN asset_interfaces ON interface_asset_id = asset_id AND interface_primary = 1
WHERE asset_id = " . intval($ticket['ticket_asset_id']) . " OR asset_id IN (SELECT asset_id FROM ticket_assets WHERE ticket_id = $ticket_id)
ORDER BY asset_id = " . intval($ticket['ticket_asset_id']) . " DESC, asset_name ASC");
while ($asset = mysqli_fetch_assoc($asset_sql)) {
$assets[] = '<tr><td class="fw-semibold">' . escapeHtml($asset['asset_name']) . '</td><td>' . escapeHtml($asset['asset_type']) . '</td><td>' . escapeHtml(trim($asset['asset_make'] . ' ' . $asset['asset_model'])) . '</td>'
. '<td class="font-monospace">' . escapeHtml($asset['asset_serial']) . '</td><td class="font-monospace">' . escapeHtml($asset['interface_ip']) . '</td></tr>';
}
$assets_html = $assets ? '<table class="itflow-print-table"><thead><tr><th>Asset</th><th>Type</th><th>Model</th><th>Serial</th><th>IP</th></tr></thead><tbody>' . implode('', $assets) . '</tbody></table>' : '';
// The fill-ins the client can see
$fill_ins = [];
foreach (ticketFillInsStored('ticket', $ticket_id) as $answer) {
if ($answer['client']) {
$fill_ins[$answer['name']] = printSheetText(ticketFillInText($answer)) ?: '<span class="itflow-print-muted">Not answered</span>';
}
}
// The tasks, to tick
$tasks = [];
$task_sql = mysqli_query($mysqli, "SELECT task_name, task_completed_at FROM tasks WHERE task_ticket_id = $ticket_id ORDER BY task_order ASC, task_id ASC");
while ($task = mysqli_fetch_assoc($task_sql)) {
$done = !empty($task['task_completed_at']);
$tasks[] = '<li class="' . ($done ? 'is-done' : '') . '"><span class="itflow-print-check" aria-hidden="true">' . ($done ? '&#10003;' : '') . '</span>' . escapeHtml($task['task_name']) . '</li>';
}
$tasks_html = $tasks ? '<ul class="itflow-print-tasks">' . implode('', $tasks) . '</ul>' : '';
// The replies the client saw - oldest first, as it happened
$public = array_values(array_filter($replies, function ($reply) {
return ($reply['ticket_reply_type'] ?? '') !== 'Internal';
}));
usort($public, function ($a, $b) {
return intval($a['ticket_reply_id']) <=> intval($b['ticket_reply_id']);
});
$replies_html = '';
foreach ($public as $reply) {
$from_client = $reply['ticket_reply_type'] === 'Client';
$who = $from_client ? ($reply['contact_name'] ?: 'The client') : ($reply['user_name'] ?: 'Your team');
$replies_html .= '<div class="itflow-print-reply' . ($from_client ? ' is-client' : '') . '">'
. '<div class="itflow-print-reply-head"><span class="fw-semibold">' . escapeHtml($who) . '</span>'
. '<span>' . ($from_client ? 'From the client' : 'Reply') . ' &middot; ' . escapeHtml(formatDateTime($reply['ticket_reply_created_at'])) . '</span></div>'
. '<div class="itflow-print-prose">' . $purifier->purify($reply['ticket_reply']) . '</div></div>';
}
// Signing off the work, on site
$assignee = intval($ticket['ticket_assigned_to'] ?? 0) ? (string) ($ticket['user_name'] ?? '') : '';
$sign_html = '<div class="itflow-print-times">'
. implode('', array_map(function ($label) {
return '<div><div class="itflow-print-sign-line"></div><span>' . $label . '</span></div>';
}, ['Date', 'Arrived', 'Left', 'Time on site'])) . '</div>'
. '<div class="itflow-print-label">Work done</div>' . printSheetLinesHtml(5)
. '<div class="itflow-print-sign">'
. '<div><div class="itflow-print-sign-line">' . escapeHtml($assignee) . '</div><span>Technician</span></div>'
. '<div><div class="itflow-print-sign-line"></div><span>Signature</span></div>'
. '<div><div class="itflow-print-sign-line">' . (!empty($ticket['contact_name']) ? escapeHtml($ticket['contact_name']) : '') . '</div><span>Client name</span></div>'
. '<div><div class="itflow-print-sign-line"></div><span>Client signature</span></div>'
. '</div>';
$reference = ticketReference($ticket);
$html = '<div class="itflow-print-sheet" data-print-sheet="work-order">'
. printSheetHeadHtml('Work order', $reference, (string) $ticket['ticket_subject'], [], ['Opened ' . formatDate($ticket['ticket_created_at'])])
. '<div class="itflow-print-grid">'
. printSheetBoxHtml('For', $for_html)
. printSheetBoxHtml('Site', $site_html)
. printSheetBoxHtml('Job', $job_html)
. '</div>'
. printSheetSectionHtml('Assets', $assets_html)
. printSheetSectionHtml('Description', '<div class="itflow-print-prose">' . $purifier->purify($ticket['ticket_details']) . '</div>')
. printSheetSectionHtml('Details', printSheetFieldsHtml($fill_ins))
. printSheetSectionHtml('Tasks', $tasks_html, 'data-print-tasks')
. printSheetSectionHtml('Conversation', $replies_html, 'data-print-replies')
. '<section class="itflow-print-section itflow-print-signoff" data-print-signoff><h2 class="itflow-print-heading">Sign-off</h2>' . $sign_html . '</section>'
. '<div class="itflow-print-foot">' . escapeHtml($reference . ' · ' . printSheetPrintedText()) . '</div>'
. '</div>';
return $html;
}
/*
* An asset's spec sheet: what it is, its hardware and network, where it is and who has it, its
* interfaces, what is in it, the licenses and services it is part of, and its quick notes - with
* a QR code that opens it in ITFlow. $row is agent/asset.php's row; $more what the page worked
* out for its tabs (interfaces and their links, licenses, services, rack, guests, holds, specs).
*/
function assetSpecSheetHtml(array $row, array $more) {
global $config_base_url;
$asset_id = intval($row['asset_id']);
$client_id = intval($row['client_id']);
// Hardware
$hardware = [
'Type' => escapeHtml($row['asset_type']),
'Model' => escapeHtml(trim($row['asset_make'] . ' ' . $row['asset_model'])),
'Serial' => '<span class="font-monospace">' . escapeHtml($row['asset_serial']) . '</span>',
(assetTypeOsLabel($row['asset_type']) === 'Firmware' ? 'Firmware' : 'OS') => escapeHtml($row['asset_os']),
];
// Its type's details - dates as dates, as "in 23 days" goes stale on paper
foreach ($more['spec_rows'] ?? [] as $spec_row) {
$hardware[$spec_row['label']] = escapeHtml($spec_row['flag']
? formatDate($spec_row['flag']['date']) . ($spec_row['flag']['tone'] === 'danger' ? ' - overdue' : '')
: $spec_row['text']);
}
if (!empty($more['guests'])) {
$hardware['Runs'] = escapeHtml(implode(', ', $more['guests']));
}
$warranty = assetWarranty($row['asset_warranty_expire'] ?? '');
$hardware['Warranty'] = $warranty ? escapeHtml(($warranty['tone'] === 'danger' ? 'Ended ' : 'Until ') . formatDate($warranty['date'])) : '';
$hardware['Purchased'] = escapeHtml(formatDate($row['asset_purchase_date']));
$hardware['Installed'] = escapeHtml(formatDate($row['asset_install_date']));
$hardware['Vendor'] = escapeHtml($row['vendor_name']);
$hardware['Order ref'] = escapeHtml($row['asset_purchase_reference']);
// Network - its primary address, and its links
$network = [
'IP' => '<span class="font-monospace">' . escapeHtml($row['interface_ip']) . '</span>',
'NAT' => '<span class="font-monospace">' . escapeHtml($row['interface_nat_ip']) . '</span>',
'IPv6' => '<span class="font-monospace">' . escapeHtml($row['interface_ipv6']) . '</span>',
'MAC' => '<span class="font-monospace">' . escapeHtml($row['interface_mac']) . '</span>',
'Network' => escapeHtml($row['network_name']),
];
foreach (assetLinks($row['asset_uri'], $row['asset_uri_2'], $row['asset_uri_client']) as [$label, $url]) {
$network[$label === 'Client link' ? 'Client link' : 'Link'] = ($network[$label === 'Client link' ? 'Client link' : 'Link'] ?? '') . '<div class="text-break">' . escapeHtml($url) . '</div>';
}
// Where it is, and who has it
$rack = $more['rack'] ?? null;
$where = [
'Client' => escapeHtml($row['client_name']),
'Location' => escapeHtml($row['location_name']) . (trim((string) $row['asset_physical_location']) !== '' ? '<div>' . escapeHtml($row['asset_physical_location']) . '</div>' : ''),
'Rack' => $rack ? escapeHtml($rack['rack_name']) . '<div>' . rackPositionLabel($rack['unit_start_number'], $rack['unit_end_number']) . ', ' . ($rack['unit_face'] === 'rear' ? 'rear' : 'front')
. (trim((string) ($rack['holder_name'] ?? '')) !== '' ? escapeHtml(' - slot ' . intval($rack['unit_position']) . ' in ' . $rack['holder_name']) : '') . '</div>' : '',
'Assigned' => !empty($row['contact_name']) ? escapeHtml($row['contact_name'])
. (!empty($row['contact_phone']) ? '<div>' . escapeHtml(formatPhoneNumber($row['contact_phone'], $row['contact_phone_country_code']) . (!empty($row['contact_extension']) ? ' x' . $row['contact_extension'] : '')) . '</div>' : '')
. (!empty($row['contact_email']) ? '<div>' . escapeHtml($row['contact_email']) . '</div>' : '') : '',
];
// Interfaces
$interface_rows = '';
foreach ($more['interfaces'] ?? [] as $interface_id => $interface) {
$link = $more['interface_links'][$interface_id] ?? null;
$details = implode(' · ', array_filter([$interface['interface_type'], $interface['interface_description']]));
$interface_rows .= '<tr><td><span class="fw-semibold">' . escapeHtml($interface['interface_name']) . '</span>' . (intval($interface['interface_primary']) ? ' (primary)' : '')
. ($details !== '' ? '<div class="itflow-print-muted">' . escapeHtml($details) . '</div>' : '') . '</td>'
. '<td>' . escapeHtml($interface['network_name']) . ($interface['interface_vlans'] ? '<div class="itflow-print-muted">VLAN ' . escapeHtml($interface['interface_vlans']) . '</div>' : '') . '</td>'
. '<td class="font-monospace">' . escapeHtml($interface['interface_ip']) . ($interface['interface_ipv6'] ? '<div>' . escapeHtml($interface['interface_ipv6']) . '</div>' : '') . '</td>'
. '<td class="font-monospace">' . escapeHtml($interface['interface_mac']) . '</td>'
. '<td>' . ($link ? escapeHtml($link['asset_name'] . ' ' . $link['interface_name']) : '') . '</td></tr>';
}
$interfaces_html = $interface_rows !== '' ? '<table class="itflow-print-table"><thead><tr><th>Interface</th><th>Network</th><th>Address</th><th>MAC</th><th>Connected to</th></tr></thead><tbody>' . $interface_rows . '</tbody></table>' : '';
// What is in it - a chassis and its nodes
$holds_rows = '';
foreach ($more['holds'] ?? [] as $held) {
// rackUnitView() items come escaped
$holds_rows .= '<tr><td>Slot ' . intval($held['slot']) . '</td><td class="fw-semibold">' . $held['name'] . '</td><td>' . ($held['make_model'] ?: $held['type_label']) . '</td></tr>';
}
$holds_html = $holds_rows !== '' ? '<table class="itflow-print-table"><tbody>' . $holds_rows . '</tbody></table>' : '';
// Licenses - names, never their keys
$license_rows = '';
foreach ($more['software'] ?? [] as $software) {
$license_rows .= '<tr><td class="fw-semibold">' . escapeHtml(trim($software['software_name'] . ' ' . $software['software_version'])) . '</td><td>' . escapeHtml($software['software_type']) . '</td>'
. '<td>' . escapeHtml($software['software_license_type']) . '</td><td>' . (!empty($software['software_expire']) ? 'Expires ' . escapeHtml(formatDate($software['software_expire'])) : '') . '</td></tr>';
}
$licenses_html = $license_rows !== '' ? '<table class="itflow-print-table"><tbody>' . $license_rows . '</tbody></table>' : '';
// Services it is part of
$service_rows = '';
foreach ($more['services'] ?? [] as $service) {
$service_rows .= '<tr><td class="fw-semibold">' . escapeHtml($service['service_name']) . '</td><td>' . escapeHtml($service['service_importance']) . ' importance</td><td>' . escapeHtml($service['service_description']) . '</td></tr>';
}
$services_html = $service_rows !== '' ? '<table class="itflow-print-table"><tbody>' . $service_rows . '</tbody></table>' : '';
$url = "https://$config_base_url/agent/asset.php?client_id=$client_id&asset_id=$asset_id";
$qr = qrCodeSvg($url, 'role="img" aria-label="QR code that opens this asset in ITFlow"');
return '<div class="itflow-print-sheet" data-print-sheet="spec-sheet">'
. printSheetHeadHtml('Spec sheet', '', (string) $row['asset_name'],
[(string) $row['asset_type'], trim($row['asset_make'] . ' ' . $row['asset_model']), (string) $row['asset_status'], (string) $row['asset_description']],
[(string) $row['client_name']], $qr)
. '<div class="itflow-print-grid">'
. printSheetBoxHtml('Hardware', printSheetFieldsHtml($hardware))
. printSheetBoxHtml('Network', printSheetFieldsHtml($network))
. printSheetBoxHtml('Where and who', printSheetFieldsHtml($where))
. '</div>'
. printSheetSectionHtml('Interfaces', $interfaces_html)
. printSheetSectionHtml('Devices in it', $holds_html)
. printSheetSectionHtml('Licenses', $licenses_html)
. printSheetSectionHtml('Services', $services_html)
. printSheetSectionHtml('Notes', trim((string) $row['asset_notes']) !== '' ? '<div>' . printSheetText($row['asset_notes']) . '</div>' : '')
. '<div class="itflow-print-foot">' . escapeHtml(printSheetPrintedText() . ' · Scan the code to open it in ITFlow') . '</div>'
. '</div>';
}

View File

@@ -1684,3 +1684,17 @@ document.addEventListener('click', function (event) {
});
more.closest('li').hidden = true;
});
// Print - a page with a printed sheet prints just that (functions/print_sheet.php)
document.addEventListener('click', function (event) {
if (!event.target.closest('[data-print-page]')) {
return;
}
event.preventDefault();
if (document.activeElement) {
document.activeElement.blur();
}
setTimeout(function () {
window.print();
}, 50);
});