' . '
' . (!empty($company['logo_url']) ? '' : '') . '
' . escapeHtml($company['company_name'] ?? '') . '
' . implode('', array_map(function ($line) { return '
' . escapeHtml($line) . '
'; }, $company_lines)) . '
' . '
' . escapeHtml($kind) . '
' . ($reference !== '' ? '
' . escapeHtml($reference) . '
' : '') . implode('', array_map(function ($line) { return '
' . escapeHtml($line) . '
'; }, array_filter($meta))) . '
' . ($aside_html !== '' ? '
' . $aside_html . '
' : '') . ''; $html .= '

' . escapeHtml($title) . '

'; $subtitle = array_filter(array_map('trim', $subtitle), 'strlen'); if ($subtitle) { $html .= '
' . escapeHtml(implode(' · ', $subtitle)) . '
'; } 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 .= '
' . escapeHtml($label) . '
' . $value . '
'; } return $html === '' ? '' : '
' . $html . '
'; } /** 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, '')) === '') { return ''; } return '
' . escapeHtml($heading) . '
' . $body_html . '
'; } /** 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, '')) === '') { return ''; } return '

' . escapeHtml($heading) . '

' . $body_html . '
'; } /** Ruled lines to write on. */ function printSheetLinesHtml($count) { return '
' . str_repeat('
', max(1, intval($count))) . '
'; } /** 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[] = '
' . escapeHtml($ticket['contact_name']) . '
' . (!empty($ticket['contact_title']) ? '
' . escapeHtml($ticket['contact_title']) . '
' : ''); 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[] = '
' . $label . ' ' . escapeHtml(formatPhoneNumber($ticket[$phone], $ticket[$code] ?? '')) . ($phone === 'contact_phone' && !empty($ticket['contact_extension']) ? ' x' . escapeHtml($ticket['contact_extension']) : '') . '
'; } } if (!empty($ticket['contact_email'])) { $contact_lines[] = '
' . escapeHtml($ticket['contact_email']) . '
'; } } $for_html = ($client_id ? '
' . escapeHtml($ticket['client_name']) . '
' : '') . implode('', $contact_lines); // Where - the site, how to get in $site_html = ''; if (intval($ticket['location_id'] ?? 0)) { $address = locationAddressText($ticket, true); $site_html = '
' . escapeHtml($ticket['location_name']) . '
' . ($address !== '' ? '
' . printSheetText($address) . '
' : '') . (!empty($ticket['location_phone']) ? '
Phone ' . escapeHtml(formatPhoneNumber($ticket['location_phone'], $ticket['location_phone_country_code'] ?? '')) . (!empty($ticket['location_phone_extension']) ? ' x' . escapeHtml($ticket['location_phone_extension']) : '') . '
' : '') . (!empty($ticket['location_hours']) ? '
Hours ' . escapeHtml($ticket['location_hours']) . '
' : '') . (trim((string) ($ticket['location_notes'] ?? '')) !== '' ? '
' . printSheetText($ticket['location_notes']) . '
' : ''); } // 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[] = '' . escapeHtml($asset['asset_name']) . '' . escapeHtml($asset['asset_type']) . '' . escapeHtml(trim($asset['asset_make'] . ' ' . $asset['asset_model'])) . '' . '' . escapeHtml($asset['asset_serial']) . '' . escapeHtml($asset['interface_ip']) . ''; } $assets_html = $assets ? '' . implode('', $assets) . '
AssetTypeModelSerialIP
' : ''; // 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)) ?: 'Not answered'; } } // 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[] = '
  • ' . escapeHtml($task['task_name']) . '
  • '; } $tasks_html = $tasks ? '' : ''; // 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 .= '
    ' . '
    ' . escapeHtml($who) . '' . '' . ($from_client ? 'From the client' : 'Reply') . ' · ' . escapeHtml(formatDateTime($reply['ticket_reply_created_at'])) . '
    ' . '
    ' . ticketHtmlForAgents($purifier, $reply['ticket_reply']) . '
    '; } // Signing off the work, on site $assignee = intval($ticket['ticket_assigned_to'] ?? 0) ? (string) ($ticket['user_name'] ?? '') : ''; $sign_html = '
    ' . implode('', array_map(function ($label) { return '
    ' . $label . '
    '; }, ['Date', 'Arrived', 'Left', 'Time on site'])) . '
    ' . '
    Work done
    ' . printSheetLinesHtml(5) . '
    ' . '
    ' . escapeHtml($assignee) . '
    Technician
    ' . '
    Signature
    ' . '
    ' . (!empty($ticket['contact_name']) ? escapeHtml($ticket['contact_name']) : '') . '
    Client name
    ' . '
    Client signature
    ' . '
    '; $reference = ticketReference($ticket); $html = '
    ' . printSheetHeadHtml('Work order', $reference, (string) $ticket['ticket_subject'], [], ['Opened ' . formatDate($ticket['ticket_created_at'])]) . '
    ' . printSheetBoxHtml('For', $for_html) . printSheetBoxHtml('Site', $site_html) . printSheetBoxHtml('Job', $job_html) . '
    ' . printSheetSectionHtml('Assets', $assets_html) . printSheetSectionHtml('Description', '
    ' . ticketHtmlForAgents($purifier, $ticket['ticket_details']) . '
    ') . printSheetSectionHtml('Details', printSheetFieldsHtml($fill_ins)) . printSheetSectionHtml('Tasks', $tasks_html, 'data-print-tasks') . printSheetSectionHtml('Conversation', $replies_html, 'data-print-replies') . '

    Sign-off

    ' . $sign_html . '
    ' . '
    ' . escapeHtml($reference . ' · ' . printSheetPrintedText()) . '
    ' . '
    '; 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' => '' . escapeHtml($row['asset_serial']) . '', (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' => '' . escapeHtml($row['interface_ip']) . '', 'NAT' => '' . escapeHtml($row['interface_nat_ip']) . '', 'IPv6' => '' . escapeHtml($row['interface_ipv6']) . '', 'MAC' => '' . escapeHtml($row['interface_mac']) . '', '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'] ?? '') . '
    ' . escapeHtml($url) . '
    '; } // 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']) !== '' ? '
    ' . escapeHtml($row['asset_physical_location']) . '
    ' : ''), 'Rack' => $rack ? escapeHtml($rack['rack_name']) . '
    ' . 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']) : '') . '
    ' : '', 'Assigned' => !empty($row['contact_name']) ? escapeHtml($row['contact_name']) . (!empty($row['contact_phone']) ? '
    ' . escapeHtml(formatPhoneNumber($row['contact_phone'], $row['contact_phone_country_code']) . (!empty($row['contact_extension']) ? ' x' . $row['contact_extension'] : '')) . '
    ' : '') . (!empty($row['contact_email']) ? '
    ' . escapeHtml($row['contact_email']) . '
    ' : '') : '', ]; // 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 .= '' . escapeHtml($interface['interface_name']) . '' . (intval($interface['interface_primary']) ? ' (primary)' : '') . ($details !== '' ? '
    ' . escapeHtml($details) . '
    ' : '') . '' . '' . escapeHtml($interface['network_name']) . ($interface['interface_vlans'] ? '
    VLAN ' . escapeHtml($interface['interface_vlans']) . '
    ' : '') . '' . '' . escapeHtml($interface['interface_ip']) . ($interface['interface_ipv6'] ? '
    ' . escapeHtml($interface['interface_ipv6']) . '
    ' : '') . '' . '' . escapeHtml($interface['interface_mac']) . '' . '' . ($link ? escapeHtml($link['asset_name'] . ' ' . $link['interface_name']) : '') . ''; } $interfaces_html = $interface_rows !== '' ? '' . $interface_rows . '
    InterfaceNetworkAddressMACConnected to
    ' : ''; // What is in it - a chassis and its nodes $holds_rows = ''; foreach ($more['holds'] ?? [] as $held) { // rackUnitView() items come escaped $holds_rows .= 'Slot ' . intval($held['slot']) . '' . $held['name'] . '' . ($held['make_model'] ?: $held['type_label']) . ''; } $holds_html = $holds_rows !== '' ? '' . $holds_rows . '
    ' : ''; // Licenses - names, never their keys $license_rows = ''; foreach ($more['software'] ?? [] as $software) { $license_rows .= '' . escapeHtml(trim($software['software_name'] . ' ' . $software['software_version'])) . '' . escapeHtml($software['software_type']) . '' . '' . escapeHtml($software['software_license_type']) . '' . (!empty($software['software_expire']) ? 'Expires ' . escapeHtml(formatDate($software['software_expire'])) : '') . ''; } $licenses_html = $license_rows !== '' ? '' . $license_rows . '
    ' : ''; // Services it is part of $service_rows = ''; foreach ($more['services'] ?? [] as $service) { $service_rows .= '' . escapeHtml($service['service_name']) . '' . escapeHtml($service['service_importance']) . ' importance' . escapeHtml($service['service_description']) . ''; } $services_html = $service_rows !== '' ? '' . $service_rows . '
    ' : ''; $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 '
    ' . 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) . '
    ' . printSheetBoxHtml('Hardware', printSheetFieldsHtml($hardware)) . printSheetBoxHtml('Network', printSheetFieldsHtml($network)) . printSheetBoxHtml('Where and who', printSheetFieldsHtml($where)) . '
    ' . 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']) !== '' ? '
    ' . printSheetText($row['asset_notes']) . '
    ' : '') . '
    ' . escapeHtml(printSheetPrintedText() . ' · Scan the code to open it in ITFlow') . '
    ' . '
    '; }