Services modernization: new services list with Needs attention, Review due, High importance, No review set, Starred and Archived views, dependency chips, in-place importance, bulk importance/category/review schedule, mark reviewed, star, archive/restore/delete and CSV/PDF export; new service page with service facts, backup and recovery, who to call (vendor and client contact details), auto-saving notes and tabs for the assets it runs on, logins, domains and certificates, documents, tickets and history; compact quick look; shared add/edit form with importance, category suggestions, a review schedule and dependency pickers on add; review modal with checklist and history note; attention flags for expiring or expired domains and certificates, certificate check problems, infrastructure out of warranty or out of action, and archived records still linked; Report a problem opens a prefilled ticket linked to the service, plus a service_tickets table, ticket page services list and link/unlink from both sides; services, domains and certificates added to the generic link system, legacy service link actions routed through it with same-client checks; services shown on the asset, contact and vendor pages, the asset/domain/certificate/credential quick looks, the document Linked card, the client overview (card, attention items, upcoming reviews), the dashboard, calendar, global search, client PDF pack and nightly review notifications; archived services left out of nav counts and lookups; services read endpoint in the API; demo data review schedules; database update 2.8.7 (archive and review columns, wider category and backup, link table dedupe with primary keys, service_domains foreign keys, service_tickets)

This commit is contained in:
johnnyq
2026-10-15 17:32:09 -04:00
parent bbb2456f0b
commit ade9d5aac3
56 changed files with 3750 additions and 1593 deletions

View File

@@ -0,0 +1,59 @@
<?php
/*
* ITFlow - Database update to version 2.8.7 (from 2.8.6)
* Included by admin/database_updates.php - do not access directly
*/
defined('FROM_DB_UPDATER') || die("Direct file access is not allowed");
// Services: retired ones are archived rather than deleted, and each can have a
// review cadence - when it was last reviewed, and every how many months
mysqli_query($mysqli, "ALTER TABLE `services` ADD COLUMN `service_archived_at` datetime DEFAULT NULL AFTER `service_accessed_at`");
mysqli_query($mysqli, "ALTER TABLE `services` ADD COLUMN `service_reviewed_at` datetime DEFAULT NULL AFTER `service_review_due`");
mysqli_query($mysqli, "ALTER TABLE `services` ADD COLUMN `service_review_interval` int(11) NOT NULL DEFAULT 0 AFTER `service_reviewed_at`");
// Room for categories like "Line of business", and for how it is backed up and brought back; description, category and notes may be left empty
mysqli_query($mysqli, "ALTER TABLE `services` MODIFY `service_backup` varchar(500) DEFAULT NULL");
mysqli_query($mysqli, "ALTER TABLE `services` MODIFY `service_category` varchar(50) NOT NULL DEFAULT ''");
mysqli_query($mysqli, "ALTER TABLE `services` MODIFY `service_description` varchar(200) NOT NULL DEFAULT ''");
mysqli_query($mysqli, "ALTER TABLE `services` MODIFY `service_importance` varchar(10) NOT NULL DEFAULT 'Medium'");
mysqli_query($mysqli, "ALTER TABLE `services` MODIFY `service_notes` mediumtext DEFAULT NULL");
// A service's links to domains had no foreign keys - clear out what points at nothing first
mysqli_query($mysqli, "DELETE `service_domains` FROM `service_domains` LEFT JOIN `services` ON `services`.`service_id` = `service_domains`.`service_id`
LEFT JOIN `domains` ON `domains`.`domain_id` = `service_domains`.`domain_id` WHERE `services`.`service_id` IS NULL OR `domains`.`domain_id` IS NULL");
// The service link tables let the same pair in twice - keep one of each, then make the pair the key
$service_link_tables = [
'service_assets' => 'asset_id',
'service_certificates' => 'certificate_id',
'service_contacts' => 'contact_id',
'service_credentials' => 'credential_id',
'service_documents' => 'document_id',
'service_domains' => 'domain_id',
'service_vendors' => 'vendor_id',
];
foreach ($service_link_tables as $table => $column) {
mysqli_query($mysqli, "CREATE TEMPORARY TABLE `{$table}_once` SELECT DISTINCT `service_id`, `$column` FROM `$table`");
mysqli_query($mysqli, "DELETE FROM `$table`");
mysqli_query($mysqli, "INSERT INTO `$table` (`service_id`, `$column`) SELECT `service_id`, `$column` FROM `{$table}_once`");
mysqli_query($mysqli, "DROP TEMPORARY TABLE `{$table}_once`");
mysqli_query($mysqli, "ALTER TABLE `$table` ADD PRIMARY KEY (`service_id`, `$column`)");
}
mysqli_query($mysqli, "ALTER TABLE `service_domains` ADD CONSTRAINT `service_domains_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE");
mysqli_query($mysqli, "ALTER TABLE `service_domains` ADD CONSTRAINT `service_domains_ibfk_2` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`domain_id`) ON DELETE CASCADE");
// Tickets raised about a service - an outage, a change - whether or not they name one of its assets
mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `service_tickets` (
`service_id` int(11) NOT NULL,
`ticket_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`, `ticket_id`),
KEY `ticket_id` (`ticket_id`),
CONSTRAINT `service_tickets_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
CONSTRAINT `service_tickets_ibfk_2` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`ticket_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci");
// The review date was there all along but nothing used it - the lists filter and sort by it now
mysqli_query($mysqli, "ALTER TABLE `services` ADD INDEX `service_review_due` (`service_review_due`)");

View File

@@ -1423,9 +1423,13 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) {
// The site runbook belongs to the main site too
demoLink($mysqli, 'location_documents', 'location_id', $primary_location_id, 'document_id', $runbook_id);
// Services, linked to the kit and credentials that actually run them
foreach ($profile['services'] as $service) {
// Services, linked to the kit and credentials that actually run them. The
// important ones are reviewed every six months, the rest yearly - last
// reviewed at different times, so a few are due and one or two are late
foreach ($profile['services'] as $service_index => $service) {
$review_months = $service[3] === 'High' ? 6 : 12;
$reviewed_days_ago = 20 + (($index * 37 + $service_index * 71) % ($review_months * 30));
$service_id = starterInsert($mysqli, 'services', [
'service_name' => $service[0],
'service_description' => $service[1],
@@ -1433,7 +1437,9 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) {
'service_importance' => $service[3],
'service_backup' => $service[4],
'service_notes' => $service[5],
'service_review_due' => demoDate(-1 * (90 + ($index * 5))),
'service_review_interval' => $review_months,
'service_reviewed_at' => demoDateTime($reviewed_days_ago, 14, 30),
'service_review_due' => demoDate($reviewed_days_ago - $review_months * 30),
'service_client_id' => $client_id,
'service_created_at' => demoMonthDateTime($months, 9, 10, 30),
'service_accessed_at' => demoDateTime($index % 12, 16, 20),

View File

@@ -222,8 +222,8 @@ if (isset($_POST['tag_picker_set']) || isset($_POST['tag_picker_create'])) {
/*
* Quick pickers (js/quick_pick.js) - 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 in place instead of through a modal. GET lists the choices; POST makes the change through the same
* and billable, a project's manager, a recurring ticket's assignee, a
* service's importance and an asset's status, location and contact, changed in place instead of through a modal. GET lists the choices; POST makes the change through the same
* functions the post.php handlers use (functions/ticket_fields.php) and sends
* back the redrawn values.
*/
@@ -252,6 +252,12 @@ if (isset($_GET['quick_pick_options'])) {
$options = quickPickAgents();
} elseif ($field === 'project_manager') {
$options = quickPickAgents('No manager');
} elseif ($field === 'service_importance') {
$colors = ['High' => 'var(--bs-danger)', 'Medium' => 'var(--bs-warning)', 'Low' => 'var(--bs-secondary)'];
$descriptions = ['High' => 'Down means the client cannot work', 'Medium' => 'Down hurts, but there is a way round it', 'Low' => 'Down is an inconvenience'];
foreach (SERVICE_IMPORTANCE as $importance) {
$options[] = ['value' => $importance, 'label' => $importance, 'color' => $colors[$importance], 'description' => $descriptions[$importance]];
}
} 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));
@@ -348,6 +354,39 @@ if (isset($_POST['quick_pick_set'])) {
exit();
}
// A service's importance - services of clients this agent can reach, not archived, like Edit Service
if ($field === 'service_importance') {
$service_ids = $ticket_ids;
$allowed = serviceCan(2) && $service_ids && in_array($value, SERVICE_IMPORTANCE, true);
$rows = [];
foreach ($allowed ? $service_ids : [] as $id) {
$row = serviceRow($id);
if (!$row || $row['service_archived_at'] || !hasClientAccess($row['service_client_id'])) {
$allowed = false;
break;
}
$rows[$id] = $row;
}
if (!$allowed) {
http_response_code(403);
echo json_encode(['error' => 'You cannot change that on these services.']);
exit();
}
$response = ['records' => []];
foreach ($rows as $id => $row) {
mysqli_query($mysqli, "UPDATE services SET service_importance = '$value' WHERE service_id = $id");
if ($row['service_importance'] !== $value) {
logAudit("Service", "Edit", "$session_name changed the importance of service " . escapeSql($row['service_name']) . " from {$row['service_importance']} to $value", intval($row['service_client_id']), $id);
}
$html = serviceImportancePill($value);
$response['records'][$id] = ['current' => $value, 'html' => ['list' => $html, 'detail' => $html]];
}
$response['message'] = count($rows) === 1 ? 'Importance set to ' . $value : 'Updated ' . count($rows) . ' services';
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') {

View File

@@ -201,14 +201,9 @@ if (mysqli_num_rows($sql) == 0) {
$held_software = softwareHeldBy('asset', $asset_id);
$software_count = count($held_software);
// Linked services
$sql_linked_services = mysqli_query($mysqli, "SELECT service_category, service_description, service_assets.service_id, service_importance,
service_name FROM service_assets, services
WHERE service_assets.asset_id = $asset_id
AND service_assets.service_id = services.service_id
ORDER BY service_name ASC"
);
$service_count = mysqli_num_rows($sql_linked_services);
// The services it is part of - most important first
$linked_services = servicesFor('asset', $asset_id);
$service_count = count($linked_services);
// Notes - 1 to many relationship
$sql_related_notes = mysqli_query($mysqli, "SELECT asset_note, asset_note_created_at, asset_note_id, asset_note_type, user_name FROM asset_notes
@@ -965,7 +960,7 @@ if (mysqli_num_rows($sql) == 0) {
<!-- Services -->
<div class="tab-pane fade" id="asset-pane-services" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Services that depend on this asset.</span>
<span class="text-body-secondary small">Services that run on it - when it is down, so are they.</span>
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="modals/asset/asset_link_service.php?id=<?= $asset_id ?>">
<i class="fas fa-link me-2"></i>Link Service
@@ -973,41 +968,9 @@ if (mysqli_num_rows($sql) == 0) {
<?php } ?>
</div>
<?php if ($service_count) { ?>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="text-nowrap table-light">
<tr>
<th>Service</th>
<th>Category</th>
<th>Importance</th>
<th></th>
</tr>
</thead>
<tbody>
<?php while ($row = mysqli_fetch_assoc($sql_linked_services)) {
$service_id = intval($row['service_id']);
$service_name = escapeHtml($row['service_name']);
$service_description = escapeHtml($row['service_description']);
$service_category = escapeHtml($row['service_category']);
$service_importance = escapeHtml($row['service_importance']);
?>
<tr>
<td>
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= $service_id ?>"><?= $service_name ?></a>
<?php if ($service_description) { ?><div class="small text-body-secondary"><?= $service_description ?></div><?php } ?>
</td>
<td><?= $service_category ?></td>
<td><?= $service_importance ?></td>
<td class="text-end">
<?php if ($can_edit) { ?>
<a href="post.php?unlink_service_from_asset&asset_id=<?= $asset_id ?>&service_id=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" class="btn btn-sm btn-light" title="Unlink"><i class="fas fa-fw fa-unlink"></i></a>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?= serviceRowsHtml($linked_services, $can_edit ? function ($row) use ($asset_id) {
return "post.php?unlink_item&from=asset&id=$asset_id&to=service&other=" . intval($row['service_id']) . "&csrf_token=" . $_SESSION['csrf_token'];
} : null) ?>
<?php } else { ?>
<div class="itflow-asset-empty">Not part of any service.</div>
<?php } ?>

View File

@@ -483,6 +483,20 @@ while ($row = mysqli_fetch_assoc($sql)) {
}
}
// Services due for review - the day it falls due
if (lookupUserPermission('module_support') >= 1) {
$sql = mysqli_query($mysqli, "SELECT service_id, service_name, service_review_due, service_client_id FROM services
JOIN clients ON client_id = service_client_id
WHERE service_archived_at IS NULL AND client_archived_at IS NULL AND service_review_due IS NOT NULL
" . (isset($_GET['client_id']) ? "AND service_client_id = " . intval($_GET['client_id']) : '') . " " . clientScopeSql('service_client_id'));
while ($row = mysqli_fetch_assoc($sql)) {
$event_title = json_encode("Review - " . $row['service_name']);
$event_start = json_encode($row['service_review_due']);
$event_url = json_encode(serviceUrl($row['service_id'], $row['service_client_id']));
echo "{ title: $event_title, start: $event_start, allDay: true, color: 'slategray', url: $event_url },";
}
}
// Vendors Added Created
$sql = mysqli_query($mysqli, "SELECT client_id, vendor_created_at, vendor_id, vendor_name FROM clients LEFT JOIN vendors ON client_id = vendor_client_id $client_query " . clientScopeSql('clients.client_id') . "");
while ($row = mysqli_fetch_assoc($sql)) {

View File

@@ -4,9 +4,10 @@
* Client overview.
*
* Who the client is and how to reach them, what needs attention, then the
* technical side (tickets, notes, contacts, favourites, schedule, renewals,
* assets) and the financial side (balance, payments, recurring, unbilled
* work, open invoices). Each part shows to agents whose role can read it.
* technical side (tickets, notes, contacts, favourites, schedule, projects,
* services, renewals, assets) and the financial side (balance, payments,
* recurring, unbilled work, open invoices). Each part shows to agents whose
* role can read it.
*
* The figures come from functions/client_overview.php; the chart is drawn by
* js/client_overview.js, which also saves the quick notes.
@@ -22,6 +23,7 @@ $renewals = $access['docs'] ? clientOverviewRenewals($client_id) : null;
$attention = clientOverviewAttention($client_id, $access, $renewals);
$open_tickets = $access['tickets'] ? clientOverviewOpenTickets($client_id) : null;
$open_projects = $access['tickets'] ? clientOverviewProjects($client_id) : null;
$client_services = $access['docs'] ? clientOverviewServices($client_id) : null;
$overview_contacts = clientOverviewContacts($client_id);
$favorites = clientOverviewFavorites($client_id, $access);
$upcoming = clientOverviewUpcoming($client_id, $access);
@@ -281,7 +283,7 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
<?php } ?>
<a class="itflow-dash-schedule-item" href="<?= escapeHtml($item['url']) ?>">
<span class="itflow-dash-schedule-time"><?= $item['all_day'] ? 'All day' : escapeHtml(date('g:i A', strtotime($item['when']))) ?></span>
<span class="itflow-dash-schedule-mark bg-<?= ['ticket' => 'primary', 'recurring' => 'info', 'event' => 'success', 'project' => 'warning'][$item['kind']] ?>"></span>
<span class="itflow-dash-schedule-mark bg-<?= ['ticket' => 'primary', 'recurring' => 'info', 'event' => 'success', 'project' => 'warning', 'service' => 'secondary'][$item['kind']] ?>"></span>
<span class="flex-grow-1 overflow-hidden">
<span class="d-block text-truncate"><?php if ($item['ref']) { ?><span class="small text-body-secondary me-2"><?= escapeHtml($item['ref']) ?></span><?php } ?><?= escapeHtml($item['title']) ?></span>
<?php if ($item['detail']) { ?><span class="d-block small text-body-secondary text-truncate"><?= escapeHtml($item['detail']) ?></span><?php } ?>
@@ -316,6 +318,38 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
</div>
<?php } ?>
<?php if ($client_services && $client_services['total']) { ?>
<div class="col-md-6 col-xl-4">
<div class="card h-100 mb-0">
<div class="card-header d-flex align-items-center">
<h3 class="card-title mb-0 me-auto">Services</h3>
<a class="small" href="services.php?client_id=<?= $client_id ?>">View all <?= $client_services['total'] ?></a>
</div>
<div class="list-group list-group-flush">
<?php foreach ($client_services['services'] as $service_id => $service) {
$service_issues = $client_services['issues'][$service_id];
$service_review = serviceReview($service);
$service_danger = in_array('danger', array_column($service_issues, 'tone'), true); ?>
<a href="<?= escapeHtml(serviceUrl($service_id, $client_id)) ?>" class="list-group-item list-group-item-action d-flex align-items-center gap-2 py-2">
<?= serviceTile($service['service_category'], 'sm') ?>
<span class="flex-grow-1 overflow-hidden">
<span class="d-block text-truncate"><?= escapeHtml($service['service_name']) ?></span>
<span class="d-block small text-truncate <?= $service_issues ? ($service_danger ? 'text-danger-emphasis' : 'text-warning-emphasis') : 'text-body-secondary' ?>">
<?php if ($service_issues) { ?>
<i class="fas fa-exclamation-triangle me-1"></i><?= escapeHtml($service_issues[0]['text']) ?>
<?php } else { ?>
<?= escapeHtml($service['service_category'] ?: $service['service_importance'] . ' importance') ?><?= in_array($service_review['state'], ['overdue', 'soon'], true) ? ' · ' . escapeHtml(lcfirst($service_review['text'])) : '' ?>
<?php } ?>
</span>
</span>
<?php if ($service['service_importance'] === 'High') { ?><?= serviceImportancePill('High') ?><?php } ?>
</a>
<?php } ?>
</div>
</div>
</div>
<?php } ?>
<?php if ($renewals !== null) { ?>
<div class="col-md-6 col-xl-4" id="clientRenewals">
<div class="card h-100 mb-0">

View File

@@ -145,13 +145,9 @@ $sql_linked_files = mysqli_query($mysqli, "SELECT files.file_id, file_name, file
$file_count = mysqli_num_rows($sql_linked_files);
// Services
$sql_linked_services = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_description, service_category, service_importance
FROM service_contacts
JOIN services ON services.service_id = service_contacts.service_id
WHERE service_contacts.contact_id = $contact_id
ORDER BY service_name ASC"
);
$service_count = mysqli_num_rows($sql_linked_services);
// The services they are a contact for - most important first
$linked_services = servicesFor('contact', $contact_id);
$service_count = count($linked_services);
// Notes
$sql_related_notes = mysqli_query($mysqli, "SELECT contact_note, contact_note_created_at, contact_note_id, contact_note_type, user_name
@@ -293,9 +289,11 @@ if (!$can_support) {
<i class="fa fa-fw fa-cube text-secondary me-2"></i>License
</a>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_link_service.php?id=<?= $contact_id ?>">
<i class="fa fa-fw fa-stream text-secondary me-2"></i>Service
</a>
<?php if ($can_support_edit) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_link_service.php?id=<?= $contact_id ?>">
<i class="fa fa-fw fa-stream text-secondary me-2"></i>Service
</a>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/contact/contact_link_document.php?id=<?= $contact_id ?>">
<i class="fa fa-fw fa-file-alt text-secondary me-2"></i>Document
</a>
@@ -722,30 +720,17 @@ if (!$can_support) {
<!-- Services -->
<div class="tab-pane fade" id="contact-pane-services" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Services they are a contact for.</span>
<?php if ($can_edit) { ?>
<span class="text-body-secondary small">Services they own or are the contact for at the client.</span>
<?php if ($can_support_edit) { ?>
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="modals/contact/contact_link_service.php?id=<?= $contact_id ?>">
<i class="fas fa-link me-2"></i>Link Service
</button>
<?php } ?>
</div>
<?php if ($service_count) { ?>
<div class="list-group list-group-flush">
<?php while ($row = mysqli_fetch_assoc($sql_linked_services)) {
$service_id = intval($row['service_id']); ?>
<div class="list-group-item d-flex align-items-center gap-3 py-2">
<i class="fas fa-fw fa-stream text-secondary"></i>
<div class="flex-grow-1 min-w-0">
<a class="fw-semibold ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= $service_id ?>"><?= escapeHtml($row['service_name']) ?></a>
<?php if ($row['service_description']) { ?><div class="small text-body-secondary text-truncate"><?= escapeHtml($row['service_description']) ?></div><?php } ?>
</div>
<span class="small text-body-secondary text-nowrap"><?= escapeHtml(implode(' · ', array_filter([$row['service_category'], $row['service_importance']]))) ?></span>
<?php if ($can_edit) { ?>
<a class="btn btn-sm btn-light" title="Unlink" href="post.php?unlink_service_from_contact&contact_id=<?= $contact_id ?>&service_id=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"><i class="fas fa-fw fa-unlink"></i></a>
<?php } ?>
</div>
<?php } ?>
</div>
<?= serviceRowsHtml($linked_services, $can_support_edit ? function ($row) use ($contact_id) {
return "post.php?unlink_item&from=contact&id=$contact_id&to=service&other=" . intval($row['service_id']) . "&csrf_token=" . $_SESSION['csrf_token'];
} : null) ?>
<?php } else { ?>
<div class="itflow-asset-empty">Not a contact for any service.</div>
<?php } ?>

View File

@@ -10,7 +10,7 @@ $num_locations = $row['num'];
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('asset_id') AS num FROM assets LEFT JOIN clients ON asset_client_id = client_id WHERE asset_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('asset_client_id') . ""));
$num_assets = $row['num'];
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services LEFT JOIN clients ON service_client_id = client_id WHERE client_archived_at IS NULL " . clientScopeSql('service_client_id') . ""));
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('service_id') AS num FROM services LEFT JOIN clients ON service_client_id = client_id WHERE client_archived_at IS NULL AND service_archived_at IS NULL " . clientScopeSql('service_client_id') . ""));
$num_services = $row['num'];
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT('credential_id') AS num FROM credentials LEFT JOIN clients ON credential_client_id = client_id WHERE credential_archived_at IS NULL AND client_archived_at IS NULL " . clientScopeSql('credential_client_id') . ""));

View File

@@ -234,7 +234,7 @@ if (isset($_GET['client_id'])) {
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(project_id) AS num FROM projects WHERE project_archived_at IS NULL AND project_completed_at IS NULL AND project_client_id = $client_id"));
$num_active_projects = intval($row['num']);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(service_id) AS num FROM services WHERE service_client_id = $client_id"));
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(service_id) AS num FROM services WHERE service_client_id = $client_id AND service_archived_at IS NULL"));
$num_services = intval($row['num']);
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT COUNT(vendor_id) AS num FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id"));

View File

@@ -116,6 +116,10 @@ $recurring_ticket_count = mysqli_num_rows($sql_related_recurring_tickets);
$held_software = softwareHeldBy('asset', $asset_id);
$software_count = count($held_software);
// The services it runs - what goes down with it
$asset_services = servicesFor('asset', $asset_id);
$service_count = count($asset_services);
// Documents
$linked_documents = linkedRecords('asset', $asset_id, 'document');
$document_count = count($linked_documents);
@@ -145,6 +149,7 @@ $quick_tabs = array_filter([
'tickets' => ['label' => 'Tickets', 'count' => $ticket_count, 'badge' => $ticket_open_count],
'recurring' => ['label' => 'Recurring', 'count' => $recurring_ticket_count],
'licenses' => ['label' => 'Licenses', 'count' => $software_count],
'services' => ['label' => 'Services', 'count' => $service_count],
'documents' => ['label' => 'Documents', 'count' => $document_count],
'files' => ['label' => 'Files', 'count' => $file_count],
'notes' => ['label' => 'Notes', 'count' => $note_count],
@@ -369,6 +374,13 @@ ob_start();
</div>
<?php } ?>
<?php if ($service_count) { ?>
<div class="tab-pane fade <?= $first_tab === 'services' ? 'show active' : '' ?>" id="asset-quick-<?= $asset_id ?>-services" role="tabpanel">
<!-- What goes down with it - most important first -->
<?= serviceRowsHtml($asset_services) ?>
</div>
<?php } ?>
<?php if ($document_count) { ?>
<div class="tab-pane fade <?= $first_tab === 'documents' ? 'show active' : '' ?>" id="asset-quick-<?= $asset_id ?>-documents" role="tabpanel">
<!-- The same rows as a document's Linked card - tile, name, when it changed -->

View File

@@ -1,67 +1,12 @@
<?php
require_once '../../../includes/modal_header.php';
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Services tab.
*/
$asset_id = intval($_GET['id']);
$_GET['from'] = 'asset';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'service';
$sql = mysqli_query($mysqli, "SELECT asset_client_id, asset_name FROM assets
WHERE asset_id = $asset_id
LIMIT 1
");
$row = mysqli_fetch_assoc($sql);
$asset_name = escapeHtml($row['asset_name']);
$client_id = intval($row['asset_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-stream me-2"></i>Link Service to <strong><?= $asset_name ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="asset_id" value="<?= $asset_id ?>">
<div class="modal-body">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-stream"></i></span>
<select class="form-select select2" name="service_id">
<option value="">- Select a Service -</option>
<?php
$sql_services_select = mysqli_query($mysqli, "
SELECT services.service_id, services.service_name
FROM services
LEFT JOIN service_assets
ON services.service_id = service_assets.service_id
AND service_assets.asset_id = $asset_id
WHERE services.service_client_id = $client_id
AND service_assets.asset_id IS NULL
ORDER BY services.service_name ASC
");
while ($row = mysqli_fetch_assoc($sql_services_select)) {
$service_id = intval($row['service_id']);
$service_name = escapeHtml($row['service_name']);
?>
<option value="<?= $service_id ?>"><?= $service_name ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_service_to_asset" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';
require __DIR__ . '/../link/link.php';

View File

@@ -32,7 +32,7 @@ $host = certificateHost($certificate['certificate_domain']);
$expiry = certificateExpiry($certificate);
$parsed = certificateParse($certificate['certificate_public_key']);
$names = certificateNames($certificate);
$services = certificateServices($certificate_id);
$services = servicesFor('certificate', $certificate_id);
$history = certificateHistory($certificate_id, 15);
$pem = $parsed ? $parsed['pem'] : '';
$fingerprint = trim((string) $certificate['certificate_fingerprint']);
@@ -172,19 +172,20 @@ ob_start();
</div>
</div>
<?php if ($services) { ?>
<div class="small text-body-secondary fw-semibold text-uppercase mt-1 mb-1">Services that use it</div>
<ul class="list-unstyled mb-0 itflow-links">
<?php foreach ($services as $service) { ?>
<li class="itflow-link-row">
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-stream"></i></span>
<div class="min-w-0 flex-grow-1">
<div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= intval($service['service_id']) ?>"><?= escapeHtml($service['service_name']) ?></a></div>
<div class="small text-body-secondary"><?= escapeHtml($service['service_importance']) ?> importance</div>
</div>
</li>
<?php if ($services || $can_edit) { ?>
<div class="d-flex align-items-center mt-1 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">Services that use it</span>
<?php if ($can_edit) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=certificate&id=<?= $certificate_id ?>&to=service"><i class="fas fa-link me-1"></i>Link a service</a>
<?php } ?>
</ul>
</div>
<?php if ($services) { ?>
<?= serviceRowsHtml($services, $can_edit ? function ($row) use ($certificate_id) {
return "post.php?unlink_item&from=certificate&id=$certificate_id&to=service&other=" . intval($row['service_id']) . "&csrf_token=" . $_SESSION['csrf_token'];
} : null) ?>
<?php } else { ?>
<p class="small text-body-secondary mb-0">No service is linked to it.</p>
<?php } ?>
<?php } ?>
<?php if (trim((string) $certificate['certificate_notes']) !== '') { ?>

View File

@@ -1,66 +1,12 @@
<?php
require_once '../../../includes/modal_header.php';
/*
* Kept so existing links keep working. Every pair is linked in
* agent/modals/link/link.php, here opened on its Services tab.
*/
$contact_id = intval($_GET['id']);
$_GET['from'] = 'contact';
$_GET['id'] = intval($_GET['id'] ?? 0);
$_GET['to'] = 'service';
$sql = mysqli_query($mysqli, "SELECT contact_client_id, contact_name FROM contacts
WHERE contact_id = $contact_id
LIMIT 1
");
$row = mysqli_fetch_assoc($sql);
$contact_name = escapeHtml($row['contact_name']);
$client_id = intval($row['contact_client_id']);
enforceClientAccess();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fa fa-fw fa-stream me-2"></i>Link Service to <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" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="contact_id" value="<?= $contact_id ?>">
<div class="modal-body">
<div class="mb-3">
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-stream"></i></span>
<select class="form-select select2" name="service_id">
<option value="">- Select a Service -</option>
<?php
$sql_services_select = mysqli_query($mysqli, "
SELECT services.service_id, services.service_name
FROM services
LEFT JOIN service_contacts
ON services.service_id = service_contacts.service_id
AND service_contacts.contact_id = $contact_id
WHERE services.service_client_id = $client_id
AND service_contacts.contact_id IS NULL
ORDER BY services.service_name ASC
");
while ($row = mysqli_fetch_assoc($sql_services_select)) {
$service_id = intval($row['service_id']);
$service_name = escapeHtml($row['service_name']);
?>
<option value="<?= $service_id ?>"><?= $service_name ?></option>
<?php
}
?>
</select>
</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="link_service_to_contact" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Link</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';
require __DIR__ . '/../link/link.php';

View File

@@ -93,7 +93,7 @@ ob_start();
<div class="d-flex align-items-center mt-3 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">For</span>
<?php if ($can_edit && $link_types) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=credential&id=<?= $credential_id ?>&to=vendor"><i class="fas fa-link me-1"></i>Link a vendor or license</a>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=credential&id=<?= $credential_id ?>&to=vendor"><i class="fas fa-link me-1"></i>Link a vendor, license or service</a>
<?php } ?>
</div>
<ul class="list-unstyled mb-0 itflow-links">
@@ -119,9 +119,9 @@ ob_start();
<div class="min-w-0 flex-grow-1"><div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/software/software.php?id=<?= $id ?>"><?= escapeHtml($name) ?></a></div><div class="small text-body-secondary">License</div></div>
<?php } else { ?>
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-stream"></i></span>
<div class="min-w-0 flex-grow-1"><div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= $id ?>"><?= escapeHtml($name) ?></a></div><div class="small text-body-secondary">Service</div></div>
<div class="min-w-0 flex-grow-1"><div class="d-flex"><a class="text-truncate" href="<?= escapeHtml(serviceUrl($id, $client_id)) ?>"><?= escapeHtml($name) ?></a></div><div class="small text-body-secondary">Service</div></div>
<?php } ?>
<?php if ($can_edit && $type !== 'service') { ?>
<?php if ($can_edit) { ?>
<a class="itflow-link-remove" href="post.php?unlink_item&from=credential&id=<?= $credential_id ?>&to=<?= $type ?>&other=<?= $id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" title="Unlink"><i class="fas fa-unlink"></i></a>
<?php } ?>
</li>

View File

@@ -19,7 +19,9 @@ $software = linkRecord('software', $_GET['software_id'] ?? 0);
$software_id = $software && intval($software['client_id']) === $client_id ? intval($software['id']) : 0;
$location_id = assetClientOwnedId('location', $_GET['location_id'] ?? 0, $client_id);
$vendor_id = assetClientOwnedId('vendor', $_GET['vendor_id'] ?? 0, $client_id);
$link_name = $asset_id ? $asset['name'] : ($contact_id ? getFieldById('contacts', $contact_id, 'contact_name') : ($software_id ? $software['name'] : ($location_id ? getFieldById('locations', $location_id, 'location_name') : ($vendor_id ? getFieldById('vendors', $vendor_id, 'vendor_name') : ''))));
$service = linkRecord('service', $_GET['service_id'] ?? 0);
$service_id = $service && intval($service['client_id']) === $client_id && !$service['archived_at'] ? intval($service['id']) : 0;
$link_name = $asset_id ? $asset['name'] : ($contact_id ? getFieldById('contacts', $contact_id, 'contact_name') : ($software_id ? $software['name'] : ($location_id ? getFieldById('locations', $location_id, 'location_name') : ($vendor_id ? getFieldById('vendors', $vendor_id, 'vendor_name') : ($service_id ? $service['name'] : '')))));
$document_form_mode = 'add';
$document_name = $document_description = $document_content = '';
@@ -41,6 +43,7 @@ ob_start();
<input type="hidden" name="software" value="<?= $software_id ?>">
<input type="hidden" name="location" value="<?= $location_id ?>">
<input type="hidden" name="vendor" value="<?= $vendor_id ?>">
<input type="hidden" name="service" value="<?= $service_id ?>">
<div class="modal-body">
<?php require 'document_form.php'; ?>
</div>

View File

@@ -32,7 +32,7 @@ $expiry = domainExpiry($domain['domain_expire'], $domain['domain_auto_renew']);
$facts = domainRegistrationFacts($domain['domain_raw_whois']);
$mail_checks = domainMailChecks($domain);
$certificates = domainCertificates($domain);
$services = domainServices($domain_id);
$services = servicesFor('domain', $domain_id);
$logins = domainLogins($domain);
$history = domainHistory($domain_id, 15);
$tags = tagsForRecord('domain', $domain_id);
@@ -161,19 +161,20 @@ ob_start();
<?php } ?>
<?php } ?>
<?php if ($services) { ?>
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Services that use it</div>
<ul class="list-unstyled mb-0 itflow-links">
<?php foreach ($services as $service) { ?>
<li class="itflow-link-row">
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-stream"></i></span>
<div class="min-w-0 flex-grow-1">
<div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= intval($service['service_id']) ?>"><?= escapeHtml($service['service_name']) ?></a></div>
<div class="small text-body-secondary"><?= escapeHtml($service['service_importance']) ?> importance</div>
</div>
</li>
<?php if ($services || $can_edit) { ?>
<div class="d-flex align-items-center mt-3 mb-1">
<span class="small text-body-secondary fw-semibold text-uppercase me-auto">Services that use it</span>
<?php if ($can_edit) { ?>
<a class="small ajax-modal" href="#" data-modal-url="modals/link/link.php?from=domain&id=<?= $domain_id ?>&to=service"><i class="fas fa-link me-1"></i>Link a service</a>
<?php } ?>
</ul>
</div>
<?php if ($services) { ?>
<?= serviceRowsHtml($services, $can_edit ? function ($row) use ($domain_id) {
return "post.php?unlink_item&from=domain&id=$domain_id&to=service&other=" . intval($row['service_id']) . "&csrf_token=" . $_SESSION['csrf_token'];
} : null) ?>
<?php } else { ?>
<p class="small text-body-secondary mb-0">No service is linked to it.</p>
<?php } ?>
<?php } ?>
<?php if ($logins) { ?>

View File

@@ -2,7 +2,8 @@
/*
* Link things to a document or a file - or a document or file to an asset or
* contact, devices, users and credentials to a license. One modal for every
* contact, devices, users and credentials to a license, what a service
* depends on to the service. One modal for every
* pair in LINK_RELATIONS (functions/links.php):
* ?from=document&id=81&to=asset opens on Assets; the pills along the top
* switch to anything else this record can be linked to. Pick as many as you
@@ -38,35 +39,6 @@ $link_to = in_array($_GET['to'] ?? '', $link_types, true) ? $_GET['to'] : $link_
$from_entity = LINK_ENTITIES[$link_from];
$link_name = escapeHtml($link_source['name']);
/** The option extras for one candidate - its icon or avatar, and a line under it. */
function linkOptionData($to, $row, $client_id) {
switch ($to) {
case 'asset':
return selectOptionAsset($row['asset_type'], trim($row['asset_make'] . ' ' . $row['asset_model']));
case 'contact':
return selectOptionContact($row['contact_client_id'], $row['name'], $row['contact_photo'], $row['contact_title'], $row['id']);
case 'file':
$info = fileTypeInfo($row['file_ext']);
return selectOptionData(['icon' => 'fas fa-' . $info['icon'], 'description' => ($row['folder_name'] ?: 'Top level') . ' · ' . formatBytes(intval($row['file_size'])), 'keywords' => $row['file_description']]);
case 'document':
return selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row['document_description'] ?: 'Updated ' . timeAgo($row['document_updated_at'] ?: $row['document_created_at'])]);
case 'software':
// How many seats are left, so a full license is seen before it is picked
$seats = softwareSeats($row['seats_used'], $row['software_seats']);
$seat_text = $seats['state'] === 'unlimited' ? '' : ($seats['state'] === 'over' || $seats['state'] === 'full'
? 'Full - ' . $seats['used'] . ' of ' . $seats['total'] . ' seats'
: $seats['free'] . ' of ' . $seats['total'] . ' seats free');
return selectOptionData(['icon' => 'fas ' . softwareTypeStyle($row['software_type'])['icon'], 'description' => implode(' · ', array_filter([$row['software_license_type'], $seat_text, $row['software_version']]))]);
case 'credential':
return selectOptionCredential(['credential_name' => $row['name'], 'credential_description' => $row['credential_description'], 'credential_uri' => $row['credential_uri']], $row['credential_description'] ?: $row['credential_uri']);
case 'location':
return selectOptionData(['icon' => 'fas fa-' . (intval($row['location_primary']) ? 'building' : 'map-marker-alt'), 'description' => implode(' · ', array_filter([intval($row['location_primary']) ? 'Primary' : '', locationAddressText($row)]))]);
case 'vendor':
return selectOptionVendor($row['name'], $row['vendor_description']);
}
return '';
}
$panes = [];
foreach ($link_types as $to) {
$panes[$to] = [

View File

@@ -1,296 +1,149 @@
<?php
/*
* Service quick look - opened from the services list, and from the assets,
* contacts, vendors, domains, certificates and credentials it depends on.
* What it is and how important, anything it depends on that needs
* attention, what it runs on, who to call and how it comes back - and the
* way to its page, where all of it is linked and unlinked.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support');
$service = serviceForModal($_GET['id'] ?? 0, 1);
$service_id = intval($service['service_id']);
$service_archived = !empty($service['service_archived_at']);
$can_edit = serviceCan(2) && !$service_archived;
$can_credentials = lookupUserPermission('module_credential') >= 1;
$service_id = intval($_GET['id']);
$counts = serviceCounts([$service_id])[$service_id];
$issues = serviceIssues([$service_id])[$service_id];
$review = serviceReview($service);
$active = function ($row) {
return !$row['archived_at'];
};
$assets = array_values(array_filter(serviceLinked($service_id, 'asset'), $active));
$contacts = array_values(array_filter(serviceLinked($service_id, 'contact'), $active));
$vendors = array_values(array_filter(serviceLinked($service_id, 'vendor'), $active));
$urls = serviceUrls($service_id, $can_credentials);
$page_url = escapeHtml(serviceUrl($service_id, $client_id));
$sql = mysqli_query($mysqli, "SELECT service_backup, service_category, service_client_id, service_created_at,
service_description, service_importance, service_name, service_notes, service_review_due,
service_updated_at FROM services WHERE service_id = $service_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$service_name = escapeHtml($row['service_name']);
$service_description = escapeHtml($row['service_description']);
$service_category = escapeHtml($row['service_category']);
$service_importance = escapeHtml($row['service_importance']);
$service_backup = escapeHtml($row['service_backup']);
$service_notes = escapeHtml($row['service_notes']);
$service_created_at = escapeHtml($row['service_created_at']);
$service_updated_at = escapeHtml($row['service_updated_at']);
$service_review_due = escapeHtml($row['service_review_due']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Service Importance
if ($service_importance == "High") {
$service_importance_display = "<span class='p-2 badge bg-danger'>$service_importance</span>";
} elseif ($service_importance == "Medium") {
$service_importance_display = "<span class='p-2 badge bg-warning text-dark'>$service_importance</span>";
} elseif ($service_importance == "Low") {
$service_importance_display = "<span class='p-2 badge bg-info text-dark'>$service_importance</span>";
} else {
$service_importance_display = "-";
// The rest it depends on, counted - each opening its tab on the page
$also = [];
foreach (['credential' => ['fa-key', 'login', 'logins', 'logins'], 'domain' => ['fa-globe', 'domain', 'domains', 'web'],
'certificate' => ['fa-lock', 'certificate', 'certificates', 'web'], 'document' => ['fa-file-alt', 'document', 'documents', 'documents']] as $type => [$icon, $one, $many, $tab]) {
if ($counts[$type]) {
$also[] = '<a class="itflow-contact-chip" href="' . $page_url . '#' . $tab . '"><i class="fas ' . $icon . '"></i>' . $counts[$type] . ' ' . ($counts[$type] === 1 ? $one : $many) . '</a>';
}
}
// Associated Assets (and their networks/locations) - one row each, their credentials come below
$sql_assets = mysqli_query(
$mysqli,
"SELECT * FROM service_assets
LEFT JOIN assets ON service_assets.asset_id = assets.asset_id
LEFT JOIN asset_interfaces ON interface_asset_id = assets.asset_id AND interface_primary = 1
LEFT JOIN networks ON interface_network_id = networks.network_id
LEFT JOIN locations ON assets.asset_location_id = locations.location_id
WHERE service_id = $service_id"
);
// Its credentials - the ones linked to it and the ones on its assets - for those who may see credentials
$service_credentials = lookupUserPermission('module_credential') >= 1
? credentialRows("credential_client_id = $client_id AND (credential_id IN (SELECT credential_id FROM service_credentials WHERE service_id = $service_id)
OR credential_asset_id IN (SELECT asset_id FROM service_assets WHERE service_id = $service_id))")
: [];
// Associated Domains
$sql_domains = mysqli_query(
$mysqli,
"SELECT domains.domain_id, domain_name, domain_expire, domain_auto_renew, domain_archived_at FROM service_domains
JOIN domains ON service_domains.domain_id = domains.domain_id
WHERE service_id = $service_id
ORDER BY domain_name"
);
// Associated Certificates
$sql_certificates = mysqli_query(
$mysqli,
"SELECT certificates.certificate_id, certificate_domain, certificate_name, certificate_issued_at, certificate_expire, certificate_check_status,
certificate_checked_at, certificate_archived_at FROM service_certificates
JOIN certificates ON service_certificates.certificate_id = certificates.certificate_id
WHERE service_id = $service_id
ORDER BY certificate_name"
);
// Associated Vendors
$sql_vendors = mysqli_query(
$mysqli,
"SELECT vendors.vendor_id, vendor_name FROM service_vendors
LEFT JOIN vendors ON service_vendors.vendor_id = vendors.vendor_id
WHERE service_id = $service_id"
);
// Associated Contacts
$sql_contacts = mysqli_query(
$mysqli,
"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"
);
// Associated Documents
$sql_docs = mysqli_query(
$mysqli,
"SELECT documents.document_id AS id, document_name AS name, document_description, document_created_at, document_updated_at
FROM service_documents
JOIN documents ON service_documents.document_id = documents.document_id
WHERE service_id = $service_id AND document_archived_at IS NULL
ORDER BY document_name ASC"
);
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-white"><i class="fa fa-fw fa-stream me-2"></i><?= $service_name ?></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<div class="modal-body">
<div class="row">
<!-- Main/Left side -->
<div class="col-8 border-end">
<div class="col-12">
<h4>Service Overview: <?= "$service_name $service_importance_display" ?></h4>
<b>Description:</b> <?= $service_description ?> <br>
<b>Backup Info:</b> <?= $service_backup ?> <br><br>
<h5><i class="fas fa-fw fa-sticky-note me-2"></i>Notes</h5>
<div style="white-space: pre-line"><?= $service_notes ?></div>
<hr>
<!-- Assets -->
<?php
if (mysqli_num_rows($sql_assets) > 0) {
echo "<h5><i class='fas fa-fw fa-desktop me-2'></i>Assets</h5><ul>";
mysqli_data_seek($sql_assets, 0);
while ($row = mysqli_fetch_assoc($sql_assets)) {
$asset_id = intval($row['asset_id']);
$asset_name = escapeHtml($row['asset_name']);
$ip = !empty($row['interface_ip']) ? '(' . escapeHtml($row['interface_ip']) . ')' : '';
echo "<li><a class='ajax-modal' href='#' data-modal-size='lg' data-modal-url='modals/asset/asset.php?id=$asset_id'>$asset_name</a>$ip</li>";
}
echo "</ul>";
}
?>
<!-- Networks -->
<?php
$networks = [];
if ($sql_assets) {
mysqli_data_seek($sql_assets, 0);
while ($row = mysqli_fetch_assoc($sql_assets)) {
if (!empty($row['network_name'])) {
$network_data = escapeHtml($row["network_name"]) . ':' . escapeHtml($row["network_vlan"]);
$networks[] = $network_data;
}
}
$networks = array_unique($networks);
if (!empty($networks)) {
echo "<h5><i class='fas fa-fw fa-network-wired me-2'></i>Networks</h5><ul>";
foreach ($networks as $network) {
$network_parts = explode(":", $network);
$network_name = $network_parts[0];
$network_vlan = $network_parts[1] ?? '';
echo "<li><a href='networks.php?client_id=$client_id&q=$network_name'>$network_name</a> (VLAN <span class='font-monospace'>$network_vlan</span>)</li>";
}
echo "</ul>";
}
}
?>
<!-- Locations -->
<?php
$location_names = [];
if ($sql_assets) {
mysqli_data_seek($sql_assets, 0);
while ($row = mysqli_fetch_assoc($sql_assets)) {
if (!empty($row['location_name'])) {
$location_names[] = escapeHtml($row['location_name']);
}
}
$location_names = array_unique($location_names);
if (!empty($location_names)) {
echo "<h5><i class='fas fa-fw fa-map-marker-alt me-2'></i>Locations</h5><ul>";
foreach ($location_names as $location) {
echo "<li><a href='locations.php?client_id=$client_id&q=$location'>$location</a></li>";
}
echo "</ul>";
}
}
?>
<!-- Domains -->
<?php
if (mysqli_num_rows($sql_domains) > 0) {
echo "<h5><i class='fas fa-fw fa-globe me-2'></i>Domains</h5><ul class='list-unstyled ms-1'>";
mysqli_data_seek($sql_domains, 0);
while ($row = mysqli_fetch_assoc($sql_domains)) {
// Each opens its quick look, with when it expires
echo '<li class="mb-1 d-flex align-items-center gap-2">' . domainLink($row['domain_id'], $row['domain_name'], ['archived' => !empty($row['domain_archived_at'])])
. domainExpiryPill(domainExpiry($row['domain_expire'], $row['domain_auto_renew']), true) . '</li>';
}
echo "</ul>";
}
?>
<!-- Certificates -->
<?php
if (mysqli_num_rows($sql_certificates) > 0) {
echo "<h5><i class='fas fa-fw fa-lock me-2'></i>Certificates</h5><ul class='list-unstyled ms-1'>";
mysqli_data_seek($sql_certificates, 0);
while ($row = mysqli_fetch_assoc($sql_certificates)) {
// Each opens its quick look, with when it expires and anything the last check found wrong
$certificate_problem = !in_array($row['certificate_check_status'], [null, '', 'ok'], true);
echo '<li class="mb-1 d-flex flex-wrap align-items-center gap-2">' . certificateLink($row['certificate_id'], $row['certificate_name'], ['archived' => !empty($row['certificate_archived_at'])])
. ($certificate_problem ? certificateStatusPill($row) : '') . certificateExpiryPill(certificateExpiry($row)) . '</li>';
}
echo "</ul>";
}
?>
</div>
</div>
<!-- Right side -->
<div class="col-4">
<div class="col-12">
<h4>Additional Related Items</h4>
<br>
<!-- Vendors -->
<?php
if (mysqli_num_rows($sql_vendors) > 0) {
echo "<h5><i class='fas fa-fw fa-building me-2'></i>Vendors</h5><ul>";
mysqli_data_seek($sql_vendors, 0);
while ($row = mysqli_fetch_assoc($sql_vendors)) {
$vendor_id = intval($row['vendor_id']);
$vendor_name = escapeHtml($row['vendor_name']);
echo "<li class='mb-1'>" . vendorLink($vendor_id, $row['vendor_name']) . "</li>";
}
echo "</ul>";
}
?>
<!-- Contacts -->
<?php
if (mysqli_num_rows($sql_contacts) > 0) {
// 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)) {
echo '<li class="mb-1">' . contactLink($row['contact_client_id'], $row['contact_id'], $row['contact_name'], $row['contact_photo']) . '</li>';
}
echo "</ul>";
}
?>
<!-- Credentials -->
<?php if ($service_credentials) { ?>
<h5><i class="fas fa-fw fa-key me-2"></i>Credentials</h5>
<div class="mb-3"><?= credentialListHtml($service_credentials) ?></div>
<?php } ?>
<!-- URLs -->
<?php
$urls = [];
foreach ($service_credentials as $row) {
if (!empty($row['credential_uri'])) {
$urls[] = escapeUrl($row['credential_uri']);
}
}
mysqli_data_seek($sql_assets, 0);
while ($row = mysqli_fetch_assoc($sql_assets)) {
if (!empty($row['asset_uri'])) {
$urls[] = escapeUrl($row['asset_uri']);
}
}
$urls = array_unique($urls);
if (!empty($urls)) {
echo "<h5><i class='fas fa-fw fa-link me-2'></i>URLs</h5><ul>";
foreach ($urls as $url) {
$label = htmlspecialchars(parse_url($url, PHP_URL_HOST) ?: $url);
echo "<li><a href='$url' target='_blank'>$label</a></li>";
}
echo "</ul>";
}
?>
<!-- Documents -->
<?php
if (mysqli_num_rows($sql_docs) > 0) {
// The same rows as a document's Linked card
echo "<h5><i class='fas fa-fw fa-file-alt me-2'></i>Documents</h5><ul class='list-unstyled itflow-links'>";
mysqli_data_seek($sql_docs, 0);
while ($row = mysqli_fetch_assoc($sql_docs)) {
echo '<li class="itflow-link-row">' . linkRowHtml('document', $row, $client_id) . '</li>';
}
echo "</ul>";
}
?>
<div class="modal-header bg-dark" data-bs-theme="dark">
<div class="d-flex align-items-center gap-3 min-w-0">
<?= serviceTile($service['service_category']) ?>
<div class="min-w-0">
<h5 class="modal-title d-flex flex-wrap align-items-center column-gap-2 row-gap-1">
<span class="fw-semibold text-break"><?= escapeHtml($service['service_name']) ?></span>
<?php if (intval($service['service_favorite'])) { ?><i class="fas fa-star text-warning small" title="Starred"></i><?php } ?>
<?php if ($service_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
</h5>
<div class="small text-body-secondary d-flex flex-wrap column-gap-3 mt-1">
<span><?= escapeHtml($service['client_name']) ?></span>
<?php if ($service['service_category']) { ?><span><?= escapeHtml($service['service_category']) ?></span><?php } ?>
</div>
</div>
</div>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal" aria-label="Close"></button>
</div>
<div class="modal-body">
<div class="d-flex flex-wrap align-items-center gap-2 mb-3">
<?= serviceImportancePill($service['service_importance'], true) ?>
<?= serviceReviewPill($review, true) ?>
<?php if ($counts['open_tickets']) { ?>
<a class="badge rounded-pill bg-primary-subtle text-primary-emphasis border border-primary-subtle fw-normal text-decoration-none" href="<?= $page_url ?>#tickets"><i class="fas fa-life-ring me-1"></i><?= $counts['open_tickets'] ?> open ticket<?= $counts['open_tickets'] === 1 ? '' : 's' ?></a>
<?php } ?>
</div>
<?php if ($service['service_description']) { ?>
<p class="mb-3"><?= escapeHtml($service['service_description']) ?></p>
<?php } ?>
<?php if ($issues) { ?>
<div class="alert alert-<?= in_array('danger', array_column($issues, 'tone'), true) ? 'danger' : 'warning' ?> py-2 small mb-3">
<div class="fw-semibold mb-1">Needs attention</div>
<?= serviceIssuesHtml($issues, 5) ?>
</div>
<?php } ?>
<dl class="itflow-asset-dl mb-0">
<dt>Runs on</dt>
<dd class="min-w-0">
<?php if ($assets) { ?>
<div class="d-flex flex-wrap gap-1">
<?php foreach (array_slice($assets, 0, 6) as $asset) { ?>
<a class="itflow-contact-chip ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/asset/asset.php?id=<?= intval($asset['id']) ?>"><i class="fas fa-fw fa-<?= getAssetIcon($asset['asset_type']) ?> text-secondary"></i><?= escapeHtml($asset['name']) ?></a>
<?php } ?>
<?php if (count($assets) > 6) { ?><a class="small align-self-center" href="<?= $page_url ?>#assets">+<?= count($assets) - 6 ?> more</a><?php } ?>
</div>
<?php } else { ?>
<span class="text-body-secondary">Nothing linked</span>
<?php } ?>
</dd>
<?php if ($contacts) { ?>
<dt>People</dt>
<dd class="d-flex flex-wrap column-gap-3 row-gap-1">
<?php foreach ($contacts as $contact) { ?>
<?= contactLink($contact['contact_client_id'], $contact['id'], $contact['name'], $contact['contact_photo']) ?>
<?php } ?>
</dd>
<?php } ?>
<?php if ($vendors) { ?>
<dt>Call</dt>
<dd>
<?php foreach ($vendors as $vendor) {
$phone = contactPhoneLink($vendor['vendor_phone'], $vendor['vendor_phone_country_code'], $vendor['vendor_extension']); ?>
<div class="d-flex flex-wrap align-items-center column-gap-2"><?= vendorLink($vendor['id'], $vendor['name']) ?><?php if ($phone) { ?><span class="small"><?= $phone ?></span><?php } ?></div>
<?php } ?>
</dd>
<?php } ?>
<?php if ($urls) { ?>
<dt>Opens at</dt>
<dd class="min-w-0">
<?php foreach (array_slice($urls, 0, 4) as $url) { ?>
<div class="text-truncate"><a href="<?= escapeHtml($url['url']) ?>" target="_blank" rel="noopener noreferrer"><i class="fas fa-fw <?= $url['icon'] ?> text-secondary me-1"></i><?= escapeHtml($url['label']) ?></a></div>
<?php } ?>
</dd>
<?php } ?>
<?php if (trim((string) $service['service_backup']) !== '') { ?>
<dt>Recovery</dt>
<dd class="itflow-service-text"><?= escapeHtml($service['service_backup']) ?></dd>
<?php } ?>
<?php if ($also) { ?>
<dt>Also</dt>
<dd class="d-flex flex-wrap gap-1"><?= implode('', $also) ?></dd>
<?php } ?>
</dl>
<?php if (trim((string) $service['service_notes']) !== '') { ?>
<div class="small text-body-secondary fw-semibold text-uppercase mt-3 mb-1">Notes</div>
<div class="small itflow-service-text itflow-service-notes-peek"><?= escapeHtml($service['service_notes']) ?></div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($can_edit) { ?>
<a class="btn btn-outline-secondary ajax-modal me-auto" href="#" data-modal-size="lg" data-modal-url="<?= escapeHtml('modals/ticket/ticket_add.php?' . http_build_query(['client_id' => $client_id, 'service_id' => $service_id])) ?>">
<i class="fas fa-life-ring me-2"></i>Report a problem
</a>
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="lg" data-modal-url="modals/service/service_edit.php?id=<?= $service_id ?>"><i class="fas fa-edit me-2"></i>Edit</button>
<?php } ?>
<a class="btn btn-primary" href="<?= $page_url ?>"><i class="fas fa-arrow-right me-2"></i>Open service</a>
</div>
<?php

View File

@@ -1,241 +1,40 @@
<?php
/*
* New Service - for a client (opened inside one, or picked here). Opened
* inside a client it can link what the service depends on as it is made.
*/
require_once '../../../includes/modal_header.php';
$client_id = intval($_GET['client_id'] ?? 0);
enforceUserPermission('module_support', 2);
$form_client_id = intval($_GET['client_id'] ?? 0);
if ($form_client_id) {
$client_id = $form_client_id;
enforceClientAccess();
}
$form = ['service_importance' => 'Medium', 'service_review_interval' => 12, 'service_review_due' => serviceNextReview(12)];
$is_new = true;
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-white"><i class="fa fa-fw fa-stream me-2"></i>New Service</h5>
<h5 class="modal-title"><i class="fas fa-fw fa-stream me-2"></i>New Service<?php if ($form_client_id) { ?> <small class="ms-1 opacity-75"><?= escapeHtml((string) getFieldById('clients', $form_client_id, 'client_name')) ?></small><?php } ?></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="modal-body">
<?php if ($client_id) { ?>
<ul class="nav nav-pills nav-justified mb-3">
<li class="nav-item">
<a class="nav-link active" data-bs-toggle="pill" href="#pills-overview">Overview</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-general">General</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-assets">Assets</a>
</li>
</ul>
<hr>
<?php } ?>
<div class="tab-content">
<!-- //TODO: The multiple selects won't play nicely with the icons or just general formatting. I've just added blank <p> tags to format it better for now -->
<div class="tab-pane fade show active" id="pills-overview">
<?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
$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_id = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']); ?>
<option <?php if ($client_id == isset($_GET['client'])) { echo "selected"; } ?> value="<?= $client_id ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= $client_name ?></option>
<?php } ?>
</select>
</div>
</div>
<?php } ?>
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-stream"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name of Service" maxlength="200" required>
</div>
</div>
<div class="mb-3">
<label>Description <strong class="text-danger">*</strong></label>
<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="Description of Service" maxlength="200" required>
</div>
</div>
<!-- //TODO: Integrate with company wide categories: /categories.php -->
<div class="mb-3">
<label>Category</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-info"></i></span>
<input type="text" class="form-control" name="category" placeholder="Category" maxlength="20">
</div>
</div>
<div class="mb-3">
<label>Importance</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<select class="form-select select2" name="importance" required>
<option>Low</option>
<option>Medium</option>
<option>High</option>
</select>
</div>
</div>
<div class="mb-3">
<label>Backup</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-hdd"></i></span>
<input type="text" class="form-control" name="backup" placeholder="Backup strategy" maxlength="200">
</div>
</div>
<div class="mb-3">
<label>Notes</label>
<textarea class="form-control" rows="3" placeholder="Enter some notes" name="note"></textarea>
</div>
</div>
<?php if ($client_id) { ?>
<div class="tab-pane fade" id="pills-general">
<div class="mb-3">
<label for="contacts">Select related Contacts</label>
<select class="form-select select2" id="contacts" name="contacts[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_client_id, contact_photo, contact_title FROM contacts WHERE contact_archived_at IS NULL AND contact_client_id = $client_id");
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'] ?? '', $row['contact_id'] ?? 0) . ">$contact_name</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="vendors">Select related vendors</label>
<select class="form-select select2" id="vendors" name="vendors[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE vendor_archived_at IS NULL AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$vendor_id = intval($row['vendor_id']);
$vendor_name = escapeHtml($row['vendor_name']);
echo "<option value=\"$vendor_id\"" . selectOptionVendor($row['vendor_name'], $row['vendor_description']) . ">$vendor_name</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="documents">Select related documents</label>
<select class="form-select select2" id="documents" name="documents[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT document_id, document_name, document_description FROM documents WHERE document_archived_at IS NULL AND document_client_id = $client_id ORDER BY document_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$document_id = intval($row['document_id']);
$document_name = escapeHtml($row['document_name']);
echo "<option value=\"$document_id\"" . selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row['document_description']]) . ">$document_name</option>";
}
?>
</select>
</div>
<!-- TODO: Services related to other services -->
</div>
<div class="tab-pane fade" id="pills-assets">
<div class="mb-3">
<label for="assets">Select related assets</label>
<select class="form-select select2" id="assets" name="assets[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_make, asset_model FROM assets WHERE asset_archived_at IS NULL AND asset_client_id = $client_id");
while ($row = mysqli_fetch_assoc($sql)) {
$asset_id = intval($row['asset_id']);
$asset_name = escapeHtml($row['asset_name']);
echo "<option value=\"$asset_id\"" . selectOptionAsset($row['asset_type'] ?? '', trim(($row['asset_make'] ?? '') . ' ' . ($row['asset_model'] ?? ''))) . ">$asset_name</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="credentials">Select related Credentials</label>
<select class="form-select select2" id="credentials" name="credentials[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT credential_id, credential_name FROM credentials WHERE credential_archived_at IS NULL AND credential_client_id = $client_id");
while ($row = mysqli_fetch_assoc($sql)) {
$credential_id = intval($row['credential_id']);
$credential_name = escapeHtml($row['credential_name']);
echo "<option value=\"$credential_id\">$credential_name</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="domains">Select related domains</label>
<select class="form-select select2" id="domains" name="domains[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains WHERE domain_archived_at IS NULL AND domain_client_id = $client_id");
while ($row = mysqli_fetch_assoc($sql)) {
$domain_id = intval($row['domain_id']);
$domain_name = escapeHtml($row['domain_name']);
echo "<option value=\"$domain_id\">$domain_name</option>";
}
?>
</select>
</div>
<div class="mb-3">
<label for="certificates">Select related certificates</label>
<select class="form-select select2" id="certificates" name="certificates[]" multiple>
<?php
$sql = mysqli_query($mysqli, "SELECT certificate_domain, certificate_id, certificate_name, certificate_issued_at, certificate_expire FROM certificates
WHERE certificate_archived_at IS NULL AND certificate_client_id = $client_id ORDER BY certificate_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$cert_id = intval($row['certificate_id']);
$cert_name = escapeHtml($row['certificate_name']);
echo "<option value=\"$cert_id\"" . selectOptionCertificate($row) . ">$cert_name</option>";
}
?>
</select>
</div>
</div>
<?php } ?>
</div>
<?php require 'service_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="add_service" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Create</button>
<button type="submit" name="add_service" 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>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,74 @@
<?php
/*
* Bulk - the importance, category and review schedule of the services
* ticked on the services list. Each field left on "No change" stays as it is.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$service_ids = array_values(array_unique(array_filter(array_map('intval', (array) ($_GET['service_ids'] ?? [])))));
$count = count($service_ids);
$categories = SERVICE_CATEGORY_SUGGESTIONS;
$sql = mysqli_query($mysqli, "SELECT DISTINCT service_category FROM services WHERE service_category <> '' " . clientScopeSql('service_client_id') . " ORDER BY service_category LIMIT 50");
while ($row = mysqli_fetch_row($sql)) {
if (!in_array($row[0], $categories, true)) {
$categories[] = $row[0];
}
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-edit me-2"></i>Change <strong><?= $count ?></strong> service<?= $count === 1 ? '' : 's' ?></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<?php foreach ($service_ids as $service_id) { ?><input type="hidden" name="service_ids[]" value="<?= $service_id ?>"><?php } ?>
<div class="modal-body">
<div class="mb-3">
<label class="form-label">Importance</label>
<select class="form-select select2" name="importance">
<option value="">- No change -</option>
<?php foreach (SERVICE_IMPORTANCE as $importance) { ?>
<option value="<?= $importance ?>"><?= $importance ?></option>
<?php } ?>
</select>
</div>
<div class="mb-3">
<label class="form-label">Category</label>
<input type="text" class="form-control" name="category" list="serviceBulkCategories" maxlength="50" placeholder="- No change -">
<datalist id="serviceBulkCategories">
<?php foreach ($categories as $category) { ?>
<option value="<?= escapeHtml($category) ?>"></option>
<?php } ?>
</datalist>
</div>
<div class="mb-0">
<label class="form-label">Review</label>
<select class="form-select select2" name="review_interval">
<option value="">- No change -</option>
<?php foreach (SERVICE_REVIEW_INTERVALS as $months => $label) { ?>
<option value="<?= $months ?>"><?= $label ?></option>
<?php } ?>
</select>
<div class="form-text">A schedule sets each one's next review that long after its last one - or from today if that has passed.</div>
</div>
</div>
<div class="modal-footer">
<button type="submit" name="bulk_edit_services" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Change</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -1,331 +1,34 @@
<?php
/*
* Edit Service - what it is, how important, how it comes back, when it is
* next reviewed. What it depends on is linked and unlinked on its page.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
$service_id = intval($_GET['id']);
$sql = mysqli_query($mysqli, "SELECT service_backup, service_category, service_client_id, service_created_at,
service_description, service_importance, service_name, service_notes, service_review_due,
service_updated_at FROM services WHERE service_id = $service_id LIMIT 1");
$row = mysqli_fetch_assoc($sql);
$service_name = escapeHtml($row['service_name']);
$service_description = escapeHtml($row['service_description']);
$service_category = escapeHtml($row['service_category']);
$service_importance = escapeHtml($row['service_importance']);
$service_backup = escapeHtml($row['service_backup']);
$service_notes = escapeHtml($row['service_notes']);
$service_created_at = escapeHtml($row['service_created_at']);
$service_updated_at = escapeHtml($row['service_updated_at']);
$service_review_due = escapeHtml($row['service_review_due']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Associated Assets (and their credentials/networks/locations)
$sql_assets = mysqli_query(
$mysqli,
"SELECT * FROM service_assets
LEFT JOIN assets ON service_assets.asset_id = assets.asset_id
LEFT JOIN asset_interfaces ON interface_asset_id = assets.asset_id AND interface_primary = 1
LEFT JOIN credentials ON service_assets.asset_id = credentials.credential_asset_id
LEFT JOIN networks ON interface_network_id = networks.network_id
LEFT JOIN locations ON assets.asset_location_id = locations.location_id
WHERE service_id = $service_id"
);
// Associated credentials
$sql_credentials = mysqli_query(
$mysqli,
"SELECT * FROM service_credentials
LEFT JOIN credentials ON service_credentials.credential_id = credentials.credential_id
WHERE service_id = $service_id"
);
// Associated Domains
$sql_domains = mysqli_query(
$mysqli,
"SELECT * FROM service_domains
LEFT JOIN domains ON service_domains.domain_id = domains.domain_id
WHERE service_id = $service_id"
);
// Associated Certificates
$sql_certificates = mysqli_query(
$mysqli,
"SELECT * FROM service_certificates
LEFT JOIN certificates ON service_certificates.certificate_id = certificates.certificate_id
WHERE service_id = $service_id"
);
// Associated URLs ---- REMOVED for now
//$sql_urls = mysqli_query($mysqli, "SELECT * FROM service_urls
//WHERE service_id = '$service_id'");
// Associated Vendors
$sql_vendors = mysqli_query(
$mysqli,
"SELECT * FROM service_vendors
LEFT JOIN vendors ON service_vendors.vendor_id = vendors.vendor_id
WHERE service_id = $service_id"
);
// Associated Contacts
$sql_contacts = mysqli_query(
$mysqli,
"SELECT * FROM service_contacts
LEFT JOIN contacts ON service_contacts.contact_id = contacts.contact_id
WHERE service_id = $service_id"
);
// Associated Documents
$sql_docs = mysqli_query(
$mysqli,
"SELECT * FROM service_documents
LEFT JOIN documents ON service_documents.document_id = documents.document_id
WHERE service_id = $service_id"
);
$form = serviceForModal($_GET['id'] ?? 0, 2, true);
$service_id = intval($form['service_id']);
$form_client_id = intval($form['service_client_id']);
$is_new = false;
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-white"><i class="fa fa-fw fa-stream me-2"></i>Editing service: <strong><?= $service_name ?></strong></h5>
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-stream me-2"></i>Edit <strong><?= escapeHtml($form['service_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="service_id" value="<?= $service_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-overview<?= $service_id ?>">Overview</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-general<?= $service_id ?>">General</a>
</li>
<li class="nav-item">
<a class="nav-link" data-bs-toggle="pill" href="#pills-assets<?= $service_id ?>">Assets</a>
</li>
</ul>
<hr>
<div class="tab-content" <?php if (lookupUserPermission('module_support') <= 1) { echo 'inert'; } ?>>
<div class="tab-pane fade show active" id="pills-overview<?= $service_id ?>">
<div class="mb-3">
<label>Name <strong class="text-danger">*</strong></label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-stream"></i></span>
<input type="text" class="form-control" name="name" placeholder="Name of Service" maxlength="200" value="<?= $service_name ?>" required>
</div>
</div>
<div class="mb-3">
<label>Description <strong class="text-danger">*</strong></label>
<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="Description of Service" maxlength="200" value="<?= $service_description ?>" required>
</div>
</div>
<!-- //TODO: Integrate with company wide categories: /categories.php -->
<div class="mb-3">
<label>Category</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-info"></i></span>
<input type="text" class="form-control" name="category" placeholder="Category" maxlength="20" value="<?= $service_category ?>">
</div>
</div>
<div class="mb-3">
<label>Importance</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-thermometer-half"></i></span>
<select class="form-select select2" name="importance" required>
<option <?php if ($service_importance == 'Low') { echo "selected"; } ?> >Low</option>
<option <?php if ($service_importance == 'Medium') { echo "selected"; } ?> >Medium</option>
<option <?php if ($service_importance == 'High') { echo "selected"; } ?> >High</option>
</select>
</div>
</div>
<div class="mb-3">
<label>Backup</label>
<div class="input-group">
<span class="input-group-text"><i class="fa fa-fw fa-hdd"></i></span>
<input type="text" class="form-control" name="backup" placeholder="Backup strategy" maxlength="200" value="<?= $service_backup ?>">
</div>
</div>
<div class="mb-3">
<label>Notes</label>
<textarea class="form-control" rows="3" placeholder="Enter some notes" name="note"><?= $service_notes ?></textarea>
</div>
</div>
<div class="tab-pane fade" id="pills-general<?= $service_id ?>">
<div class="mb-3">
<label for="contacts">Contacts</label>
<select multiple class="form-select select2" id="contacts" name="contacts[]">
<?php
// Get just the currently selected contact IDs
$selected_ids = array_column(mysqli_fetch_all($sql_contacts, MYSQLI_ASSOC), "contact_id");
// Get all contacts
// NOTE: These are called $sql_all and $row_all for a reason - anything overwriting $sql or $row will break the current while loop we are in from client_services.php
$sql_all = mysqli_query($mysqli, "SELECT contact_id, contact_name, contact_client_id, contact_photo, contact_title FROM contacts WHERE (contact_archived_at > '$service_created_at' OR contact_archived_at IS NULL) AND contact_client_id = $client_id");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$contact_id = intval($row_all['contact_id']);
$contact_name = escapeHtml($row_all['contact_name']);
$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>
</div>
<div class="mb-3">
<label for="vendors">Vendors</label>
<select multiple class="form-select select2" id="vendors" name="vendors[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_vendors, MYSQLI_ASSOC), "vendor_id");
$sql_all = mysqli_query($mysqli, "SELECT vendor_id, vendor_name, vendor_description FROM vendors WHERE (vendor_archived_at > '$service_created_at' OR vendor_archived_at IS NULL) AND vendor_client_id = $client_id ORDER BY vendor_favorite DESC, vendor_name ASC");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$vendor_id = intval($row_all['vendor_id']);
$vendor_name = escapeHtml($row_all['vendor_name']);
if (in_array($vendor_id, $selected_ids)) {
echo "<option value=\"$vendor_id\" selected" . selectOptionVendor($row_all['vendor_name'], $row_all['vendor_description']) . ">$vendor_name</option>";
}
else{
echo "<option value=\"$vendor_id\"" . selectOptionVendor($row_all['vendor_name'], $row_all['vendor_description']) . ">$vendor_name</option>";
}
}
?>
</select>
</div>
<div class="mb-3">
<label for="documents">Documents</label>
<select multiple class="form-select select2" id="documents" name="documents[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_docs, MYSQLI_ASSOC), "document_id");
$sql_all = mysqli_query($mysqli, "SELECT document_id, document_name, document_description FROM documents WHERE document_archived_at IS NULL AND document_client_id = $client_id ORDER BY document_name ASC");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$document_id = intval($row_all['document_id']);
$document_name = escapeHtml($row_all['document_name']);
$document_selected = in_array($document_id, $selected_ids) ? ' selected' : '';
echo "<option value=\"$document_id\"$document_selected" . selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row_all['document_description']]) . ">$document_name</option>";
}
?>
</select>
</div>
<!-- TODO: Services related to other services -->
</div>
<div class="tab-pane fade" id="pills-assets<?= $service_id ?>">
<div class="mb-3">
<label for="assets">Assets</label>
<select multiple class="form-select select2" id="assets" name="assets[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_assets, MYSQLI_ASSOC), "asset_id");
$sql_all = mysqli_query($mysqli, "SELECT asset_id, asset_name, asset_type, asset_make, asset_model FROM assets WHERE (asset_archived_at > '$service_created_at' OR asset_archived_at IS NULL) AND asset_client_id = $client_id");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$asset_id = intval($row_all['asset_id']);
$asset_name = escapeHtml($row_all['asset_name']);
$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>
</div>
<div class="mb-3">
<label for="credentials">Credentials</label>
<select multiple class="form-select select2" id="credentials" name="credentials[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_credentials, MYSQLI_ASSOC), "credential_id");
$sql_all = mysqli_query($mysqli, "SELECT credential_id, credential_name FROM credentials WHERE (credential_archived_at > '$service_created_at' OR credential_archived_at IS NULL) AND credential_client_id = $client_id");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$credential_id = intval($row_all['credential_id']);
$credential_name = escapeHtml($row_all['credential_name']);
if (in_array($credential_id, $selected_ids)) {
echo "<option value=\"$credential_id\" selected>$credential_name</option>";
}
else{
echo "<option value=\"$credential_id\">$credential_name</option>";
}
}
?>
</select>
</div>
<div class="mb-3">
<label for="domains">Domains</label>
<select multiple class="form-select select2" id="domains" name="domains[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_domains, MYSQLI_ASSOC), "domain_id");
$sql_all = mysqli_query($mysqli, "SELECT domain_id, domain_name FROM domains WHERE (domain_archived_at > '$service_created_at' OR domain_archived_at IS NULL) AND domain_client_id = $client_id");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$domain_id = intval($row_all['domain_id']);
$domain_name = escapeHtml($row_all['domain_name']);
if (in_array($domain_id, $selected_ids)) {
echo "<option value=\"$domain_id\" selected>$domain_name</option>";
}
else{
echo "<option value=\"$domain_id\">$domain_name</option>";
}
}
?>
</select>
</div>
<div class="mb-3">
<label for="certificates">Certificates</label>
<select multiple class="form-select select2" id="certificates" name="certificates[]">
<?php
$selected_ids = array_column(mysqli_fetch_all($sql_certificates, MYSQLI_ASSOC), "certificate_id");
$sql_all = mysqli_query($mysqli, "SELECT certificate_id, certificate_name, certificate_domain, certificate_issued_at, certificate_expire FROM certificates
WHERE (certificate_archived_at > '$service_created_at' OR certificate_archived_at IS NULL) AND certificate_client_id = $client_id ORDER BY certificate_name ASC");
while ($row_all = mysqli_fetch_assoc($sql_all)) {
$cert_id = intval($row_all['certificate_id']);
$cert_name = escapeHtml($row_all['certificate_name']);
echo "<option value=\"$cert_id\"" . (in_array($cert_id, $selected_ids) ? ' selected' : '') . selectOptionCertificate($row_all) . ">$cert_name</option>";
}
?>
</select>
</div>
</div>
</div>
<?php require 'service_form.php'; ?>
</div>
<div class="modal-footer">
<button type="submit" name="edit_service" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Save</button>
<a class="me-auto small" href="<?= escapeHtml(serviceUrl($service_id, $form_client_id)) ?>"><i class="fas fa-link me-1"></i>Link what it depends on from its page</a>
<button type="submit" name="edit_service" class="btn btn-primary text-bold"><i class="fas fa-check me-2"></i>Save</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>

View File

@@ -0,0 +1,97 @@
<?php
/*
* Export services - pre-filled from the services list's view and filters.
* Everything here is editable; the export runs whatever this form posts.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support');
$client_id = intval($_GET['client_id'] ?? 0);
if ($client_id) {
enforceClientAccess();
}
$q_filter = $_GET['q'] ?? '';
$show_filter = (string) ($_GET['show'] ?? '');
$client_filter = (string) ($_GET['client'] ?? '');
$importance_filter = (string) ($_GET['importance'] ?? '');
$category_filter = (string) ($_GET['category'] ?? '');
$views = serviceViews();
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-download me-2"></i>Export Services</h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<?php exportTabsNav(); ?>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<div class="modal-body">
<?php exportTabsFiltersOpen(); ?>
<div class="mb-3">
<label class="form-label">Which</label>
<select class="form-select select2" name="show">
<?php foreach ($views as $key => $view) { ?>
<option value="<?= escapeHtml($key) ?>" <?= $show_filter === $key ? 'selected' : '' ?>><?= escapeHtml($view['label']) ?></option>
<?php } ?>
</select>
</div>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label class="form-label">Importance</label>
<select class="form-select select2" name="importance">
<option value="">- Any importance -</option>
<?php foreach (SERVICE_IMPORTANCE as $importance) { ?>
<option value="<?= $importance ?>" <?= $importance_filter === $importance ? 'selected' : '' ?>><?= $importance ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Category</label>
<input type="text" class="form-control" name="category" value="<?= escapeHtml($category_filter) ?>" placeholder="Any category">
</div>
</div>
<div class="mb-3">
<label class="form-label">Search</label>
<input type="text" class="form-control" name="q" value="<?= stripslashes(escapeHtml($q_filter)) ?>" placeholder="Name, description, category, client">
</div>
<?php if (!$client_id) { ?>
<div class="mb-3">
<label class="form-label">Client</label>
<select class="form-select select2" name="client">
<option value="">- All Clients -</option>
<?php
$sql = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients
WHERE client_archived_at IS NULL AND EXISTS (SELECT 1 FROM services WHERE service_client_id = client_id) " . clientScopeSql('clients.client_id') . " ORDER BY client_name ASC");
while ($row = mysqli_fetch_assoc($sql)) { ?>
<option value="<?= intval($row['client_id']) ?>" <?= $client_filter === (string) intval($row['client_id']) ? 'selected' : '' ?><?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= escapeHtml($row['client_name']) ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
<?php exportTabsColumns('services'); ?>
</div>
<div class="modal-footer">
<?php renderExportButtons('export_services'); ?>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,179 @@
<?php
/*
* The fields of New Service and Edit Service - included by service_add.php
* and service_edit.php, which set $form (the values, raw), $form_client_id
* (the service's client, 0 when not picked yet) and $is_new. A new service
* picks its client here when opened outside one; opened inside one it can
* link what it depends on straight away. Afterwards that is done from the
* service page.
*/
isset($mysqli) || die("Direct file access is not allowed");
$form_importance = in_array($form['service_importance'] ?? '', SERVICE_IMPORTANCE, true) ? $form['service_importance'] : 'Medium';
$form_interval = intval($form['service_review_interval'] ?? 0);
// Categories to suggest - the usual ones and whatever this client (or anyone) already uses
$category_suggestions = SERVICE_CATEGORY_SUGGESTIONS;
$sql = mysqli_query($mysqli, "SELECT DISTINCT service_category FROM services WHERE service_category <> ''" . ($form_client_id ? " AND service_client_id = $form_client_id" : '') . " ORDER BY service_category LIMIT 50");
while ($row = mysqli_fetch_row($sql)) {
if (!in_array($row[0], $category_suggestions, true)) {
$category_suggestions[] = $row[0];
}
}
$importance_styles = [
'High' => ['danger', 'fa-thermometer-full', 'The client cannot work without it'],
'Medium' => ['warning', 'fa-thermometer-half', 'It hurts, but there is a way round it'],
'Low' => ['secondary', 'fa-thermometer-quarter', 'An inconvenience'],
];
?>
<?php if ($is_new && !$form_client_id) { ?>
<div class="mb-3">
<label class="form-label">Client <strong class="text-danger">*</strong></label>
<select class="form-select select2" name="client_id" required>
<option value="">- Pick a client -</option>
<?php
$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)) { ?>
<option value="<?= intval($row['client_id']) ?>"<?= selectOptionClient($row['client_id'], $row['client_name'], $row['client_abbreviation'] ?? '') ?>><?= escapeHtml($row['client_name']) ?></option>
<?php } ?>
</select>
</div>
<?php } elseif ($is_new) { ?>
<input type="hidden" name="client_id" value="<?= $form_client_id ?>">
<?php } ?>
<div class="row g-3 mb-3">
<div class="col-md-7">
<label class="form-label">Name <strong class="text-danger">*</strong></label>
<input type="text" class="form-control" name="name" placeholder="Email, Backup, Practice management, Phones..." maxlength="200" value="<?= escapeHtml($form['service_name'] ?? '') ?>" required autofocus>
</div>
<div class="col-md-5">
<label class="form-label">Category</label>
<input type="text" class="form-control" name="category" list="serviceCategorySuggestions" placeholder="Email, Backup, Network..." maxlength="50" value="<?= escapeHtml($form['service_category'] ?? '') ?>">
<datalist id="serviceCategorySuggestions">
<?php foreach ($category_suggestions as $suggestion) { ?>
<option value="<?= escapeHtml($suggestion) ?>"></option>
<?php } ?>
</datalist>
</div>
</div>
<div class="mb-3">
<label class="form-label">Description</label>
<input type="text" class="form-control" name="description" placeholder="Microsoft 365 mail for all staff, Veeam to the NAS and offsite..." maxlength="200" value="<?= escapeHtml($form['service_description'] ?? '') ?>">
</div>
<div class="mb-3">
<label class="form-label d-block">Importance <span class="text-body-secondary small fw-normal">- how bad is it when it is down?</span></label>
<div class="btn-group w-100 itflow-service-importance" role="group">
<?php foreach ($importance_styles as $importance => [$tone, $icon, $hint]) { ?>
<input type="radio" class="btn-check" name="importance" id="serviceImportance<?= $importance ?>" value="<?= $importance ?>" <?= $form_importance === $importance ? 'checked' : '' ?> autocomplete="off">
<label class="btn btn-outline-<?= $tone ?> text-start" for="serviceImportance<?= $importance ?>">
<i class="fas <?= $icon ?> me-1"></i><span class="fw-semibold"><?= $importance ?></span>
<span class="d-none d-md-block small opacity-75"><?= $hint ?></span>
</label>
<?php } ?>
</div>
</div>
<div class="mb-3">
<label class="form-label">Backup and recovery</label>
<textarea class="form-control" name="backup" rows="2" maxlength="500" placeholder="How it is backed up, where to, and how it comes back - and how long that takes"><?= escapeHtml($form['service_backup'] ?? '') ?></textarea>
</div>
<div class="mb-3">
<label class="form-label">Notes</label>
<textarea class="form-control" name="notes" rows="4" placeholder="How it fits together, the known quirks, what to check first when it breaks"><?= escapeHtml($form['service_notes'] ?? '') ?></textarea>
</div>
<div class="row g-3 <?= $is_new && $form_client_id ? 'mb-3' : 'mb-0' ?>">
<div class="col-md-6">
<label class="form-label">Review it</label>
<select class="form-select select2" name="review_interval" id="serviceReviewInterval">
<?php foreach (SERVICE_REVIEW_INTERVALS as $months => $label) { ?>
<option value="<?= $months ?>" <?= $form_interval === $months ? 'selected' : '' ?> data-icon="far <?= $months ? 'fa-calendar-check' : 'fa-calendar' ?>"><?= $label ?></option>
<?php } ?>
</select>
<div class="form-text">Check it still matches what is out there - a QBR is a good time.</div>
</div>
<div class="col-md-6">
<label class="form-label">Next review</label>
<input type="date" class="form-control" name="review_due" id="serviceReviewDue" value="<?= escapeHtml($form['service_review_due'] ?? '') ?>">
<?php if (!empty($form['service_reviewed_at'])) { ?>
<div class="form-text">Last reviewed <?= escapeHtml(date('M j, Y', strtotime($form['service_reviewed_at']))) ?>.</div>
<?php } else { ?>
<div class="form-text">Left empty, it follows the schedule.</div>
<?php } ?>
</div>
</div>
<?php if ($is_new && $form_client_id) {
// What it depends on - the client's own, unarchived records, the kinds this agent may link
$pickers = [];
foreach (SERVICE_LINK_TYPES as $type) {
if (!linkCanEdit('service', $type)) {
continue;
}
$candidates = linkCandidates('service', 0, $type, $form_client_id);
if ($candidates) {
$pickers[$type] = $candidates;
}
}
$picker_hints = ['asset' => 'The servers, firewalls, NAS it runs on', 'credential' => 'Admin consoles, portals', 'domain' => 'Its mail or web domains',
'certificate' => 'What keeps it on https', 'contact' => 'Who owns it at the client, who to tell', 'vendor' => 'Who to call when it breaks', 'document' => 'Runbooks, diagrams'];
if ($pickers) { ?>
<div class="border-top pt-3">
<div class="small text-body-secondary fw-semibold text-uppercase mb-2">What it depends on</div>
<div class="row g-3">
<?php foreach ($pickers as $type => $candidates) {
$entity = LINK_ENTITIES[$type]; ?>
<div class="col-md-6">
<label class="form-label small mb-1"><i class="fas fa-fw <?= $entity['icon'] ?> text-secondary me-1"></i><?= $type === 'credential' ? 'Logins' : ($type === 'contact' ? 'People' : $entity['plural']) ?></label>
<select class="form-select select2" name="<?= $entity['table'] ?>[]" multiple data-placeholder="<?= escapeHtml($picker_hints[$type]) ?>">
<?php foreach ($candidates as $candidate) { ?>
<option value="<?= intval($candidate['id']) ?>"<?= linkOptionData($type, $candidate, $form_client_id) ?>><?= escapeHtml($candidate['name']) ?></option>
<?php } ?>
</select>
</div>
<?php } ?>
</div>
</div>
<?php }
} ?>
<script>
(function () {
// A schedule picked with no date - the date it falls on, from today
var interval = document.getElementById('serviceReviewInterval');
var due = document.getElementById('serviceReviewDue');
if (!interval || !due || interval.dataset.wired) {
return;
}
interval.dataset.wired = '1';
interval.addEventListener('change', function () {
var months = parseInt(interval.value, 10) || 0;
if (!months) {
return;
}
var date = new Date();
var day = date.getDate();
date.setDate(1);
date.setMonth(date.getMonth() + months);
var last = new Date(date.getFullYear(), date.getMonth() + 1, 0).getDate();
date.setDate(Math.min(day, last));
var pad = function (n) { return (n < 10 ? '0' : '') + n; };
if (!due.value || due.dataset.auto) {
due.value = date.getFullYear() + '-' + pad(date.getMonth() + 1) + '-' + pad(date.getDate());
due.dataset.auto = '1';
}
});
due.addEventListener('input', function () {
delete due.dataset.auto;
});
})();
</script>

View File

@@ -0,0 +1,63 @@
<?php
/*
* Link tickets already raised to a service - the outage reported before
* anyone said which service it was. The client's tickets from the last year,
* open ones first, not already on the service.
*/
require_once '../../../includes/modal_header.php';
$service = serviceForModal($_GET['id'] ?? 0, 2, true);
$service_id = intval($service['service_id']);
$sql = mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_subject, ticket_created_at, ticket_resolved_at, ticket_closed_at FROM tickets
WHERE ticket_client_id = $client_id AND ticket_archived_at IS NULL
AND ticket_id NOT IN (SELECT ticket_id FROM service_tickets WHERE service_id = $service_id)
AND (" . TICKET_OPEN_SQL . " OR ticket_created_at > NOW() - INTERVAL 1 YEAR)
ORDER BY " . TICKET_OPEN_SQL . " DESC, ticket_number DESC LIMIT 300");
$candidates = [];
while ($row = mysqli_fetch_assoc($sql)) {
$candidates[] = $row;
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-life-ring me-2"></i>Tickets about <strong><?= escapeHtml($service['service_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="service_id" value="<?= $service_id ?>">
<div class="modal-body">
<?php if ($candidates) { ?>
<label class="form-label">Which tickets?</label>
<select class="form-select select2" name="ticket_ids[]" multiple required data-placeholder="Search by number or subject">
<?php foreach ($candidates as $row) {
$is_open = ticketIsOpen($row); ?>
<option value="<?= intval($row['ticket_id']) ?>" data-icon="fas fa-<?= $is_open ? 'life-ring' : 'check-circle' ?>"
data-description="<?= escapeHtml($row['ticket_prefix'] . $row['ticket_number'] . ' · ' . ($is_open ? 'Open' : 'Closed') . ' · ' . date('M j, Y', strtotime($row['ticket_created_at']))) ?>"
data-keywords="<?= escapeHtml($row['ticket_prefix'] . $row['ticket_number']) ?>"><?= escapeHtml($row['ticket_subject']) ?></option>
<?php } ?>
</select>
<div class="form-text">Tickets on its assets show on the service already - this is for the rest.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas fa-life-ring fa-2x mb-2"></i>
<div>No other tickets for this client in the last year.</div>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($candidates) { ?>
<button type="submit" name="link_service_tickets" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -0,0 +1,86 @@
<?php
/*
* Mark a service reviewed - after checking it still matches what is out
* there: what needs attention now, what it is linked to, who to call. The
* next review falls due on its schedule (or a date picked here), and the
* note goes in its history, so the review can be shown at the next QBR.
*/
require_once '../../../includes/modal_header.php';
$service = serviceForModal($_GET['id'] ?? 0, 2, true);
$service_id = intval($service['service_id']);
$interval = intval($service['service_review_interval']);
$counts = serviceCounts([$service_id])[$service_id];
$issues = serviceIssues([$service_id])[$service_id];
$review = serviceReview($service);
$next = serviceNextReview($interval ?: 12);
$checks = [
['fa-desktop', $counts['asset'] ? "The {$counts['asset']} asset" . ($counts['asset'] === 1 ? ' it runs on is' : 's it runs on are') . ' still the ones in service' : 'Nothing is linked as what it runs on - link the assets'],
['fa-building', $counts['vendor'] ? 'The vendor' . ($counts['vendor'] === 1 ? '' : 's') . ' and their support numbers are current' : 'No vendor is linked - who gets called when it breaks?'],
['fa-user', $counts['contact'] ? 'The people at the client who own it are still there' : 'Nobody at the client is linked as its owner'],
['fa-history', trim((string) $service['service_backup']) !== '' ? 'The backup is running, and the recovery steps still work' : 'No backup or recovery is written down'],
];
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title text-truncate"><i class="fas fa-fw fa-clipboard-check me-2"></i>Review <strong><?= escapeHtml($service['service_name']) ?></strong></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="service_id" value="<?= $service_id ?>">
<div class="modal-body">
<div class="small text-body-secondary mb-2"><?= escapeHtml($review['text']) ?><?= $service['service_reviewed_at'] ? ' - last reviewed ' . escapeHtml(date('M j, Y', strtotime($service['service_reviewed_at']))) : '' ?>.</div>
<?php if ($issues) { ?>
<div class="alert alert-<?= in_array('danger', array_column($issues, 'tone'), true) ? 'danger' : 'warning' ?> py-2 small mb-3">
<div class="fw-semibold mb-1">Needs attention now</div>
<?= serviceIssuesHtml($issues, 6) ?>
</div>
<?php } ?>
<div class="small text-body-secondary fw-semibold text-uppercase mb-1">Check</div>
<ul class="list-unstyled small mb-3 itflow-service-checks">
<?php foreach ($checks as [$icon, $text]) { ?>
<li class="py-1"><i class="fas fa-fw <?= $icon ?> text-secondary me-2"></i><?= escapeHtml($text) ?></li>
<?php } ?>
</ul>
<div class="row g-3 mb-3">
<div class="col-md-6">
<label class="form-label">Review it</label>
<select class="form-select select2" name="review_interval">
<?php foreach (SERVICE_REVIEW_INTERVALS as $months => $label) { ?>
<option value="<?= $months ?>" <?= $interval === $months ? 'selected' : '' ?>><?= $label ?></option>
<?php } ?>
</select>
</div>
<div class="col-md-6">
<label class="form-label">Next review</label>
<input type="date" class="form-control" name="review_due" value="<?= $interval ? escapeHtml($next) : '' ?>">
</div>
</div>
<label class="form-label">Note <span class="text-body-secondary small fw-normal">- goes in its history</span></label>
<textarea class="form-control" name="note" rows="2" maxlength="400" placeholder="Walked through it with the client, swapped the backup target, all good..."></textarea>
</div>
<div class="modal-footer">
<a class="me-auto small" href="<?= escapeHtml(serviceUrl($service_id, $client_id)) ?>">Open the service</a>
<button type="submit" name="review_service" class="btn btn-primary text-bold"><i class="fa fa-check me-2"></i>Mark reviewed</button>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -4,9 +4,9 @@ require_once '../../../includes/modal_header.php';
/*
* New Ticket - who it is for and what it is about, what it is related to,
* and its tasks. Opened from a client, contact, asset, site, vendor or
* project, it starts with that filled in; picking an asset fills in the
* person it is assigned to and its site. When the person or the asset
* and its tasks. Opened from a client, contact, asset, site, vendor,
* project or service, it starts with that filled in; picking an asset fills
* in the person it is assigned to and its site. When the person or the asset
* already has open tickets, they show under the contact - so a second ticket
* for the same problem gets noticed before it is raised.
*/
@@ -30,6 +30,28 @@ if ($client_id) {
enforceClientAccess();
}
// Raised about a service (its page's Report a problem) - one of this client's that is not archived
$service = intval($_GET['service_id'] ?? 0) ? serviceRow($_GET['service_id']) : null;
if ($service && (!$client_id || intval($service['service_client_id']) !== $client_id || $service['service_archived_at'])) {
$service = null;
}
// ...and starts with what whoever picks it up needs: what it runs on, who to call, how it comes back
if ($service) {
if ($prefill_subject === '') {
$prefill_subject = $service['service_name'] . ': ';
}
$service_assets = serviceLinked($service['service_id'], 'asset');
if ($prefill_details === '') {
$prefill_details = serviceTicketDetails($service, $service_assets, serviceLinked($service['service_id'], 'vendor'));
$prefill_details_html = '<p>' . nl2br(escapeHtml($prefill_details)) . '</p>';
}
// Runs on one thing - that is the asset
$service_assets = array_values(array_filter($service_assets, function ($row) { return !$row['archived_at']; }));
if (!$asset_id && count($service_assets) === 1) {
$asset_id = intval($service_assets[0]['id']);
}
}
ob_start();
?>
@@ -66,6 +88,19 @@ ob_start();
<!-- Ticket details -->
<div class="tab-pane fade show active" id="pills-add-details">
<?php if ($service) { ?>
<!-- What it is about - it shows on the service's page -->
<div class="d-flex align-items-center gap-2 border rounded px-2 py-2 mb-3 itflow-ticket-service">
<input type="hidden" name="service_ids[]" value="<?= intval($service['service_id']) ?>">
<?= serviceTile($service['service_category'], 'sm') ?>
<div class="min-w-0 flex-grow-1">
<div class="small text-body-secondary">About the service</div>
<div class="fw-semibold text-truncate"><?= escapeHtml($service['service_name']) ?></div>
</div>
<?= serviceImportancePill($service['service_importance'], true) ?>
</div>
<?php } ?>
<!-- Ticket client/contact -->
<div class="row">
<div class="col">

View File

@@ -0,0 +1,76 @@
<?php
/*
* Link a service to a ticket - an outage of email, a change to the backups.
* The ticket then shows on the service's page with the tickets on its assets.
*/
require_once '../../../includes/modal_header.php';
enforceUserPermission('module_support', 2);
// The ticket, after the module and client checks - or the modal's error
$row = ticketForModal($_GET['id'] ?? 0, 2, true);
$ticket_id = intval($row['ticket_id']);
$client_id = intval($row['ticket_client_id']);
$reference = escapeHtml($row['ticket_prefix'] . $row['ticket_number']);
if (!$client_id) {
echo json_encode(['error' => 'A ticket with no client has no services to link.']);
exit;
}
$linked = ticketServices($ticket_id);
$sql = mysqli_query($mysqli, "SELECT service_id, service_name, service_description, service_category, service_importance FROM services
WHERE service_client_id = $client_id AND service_archived_at IS NULL
AND service_id NOT IN (SELECT service_id FROM service_tickets WHERE ticket_id = $ticket_id)
ORDER BY FIELD(service_importance, 'High', 'Medium', 'Low'), service_name");
$candidates = [];
while ($candidate = mysqli_fetch_assoc($sql)) {
$candidates[] = $candidate;
}
ob_start();
?>
<div class="modal-header bg-dark">
<h5 class="modal-title"><i class="fas fa-fw fa-stream me-2"></i>Link a service <small class="ms-1 opacity-75"><?= $reference ?></small></h5>
<button type="button" class="btn-close btn-close-white" data-bs-dismiss="modal"></button>
</div>
<form action="post.php" method="post" autocomplete="off">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<input type="hidden" name="ticket_id" value="<?= $ticket_id ?>">
<div class="modal-body">
<?php if ($candidates) { ?>
<label class="form-label">Which service is this ticket about?</label>
<div class="input-group">
<span class="input-group-text"><i class="fas fa-fw fa-stream"></i></span>
<select class="form-select select2" name="service_ids[]" multiple required data-placeholder="Pick one or more services">
<?php foreach ($candidates as $candidate) {
$via_asset = isset($linked[intval($candidate['service_id'])]); ?>
<option value="<?= intval($candidate['service_id']) ?>"<?= selectOptionService($candidate) ?>><?= escapeHtml($candidate['service_name']) ?><?= $via_asset ? ' (through its asset)' : '' ?></option>
<?php } ?>
</select>
</div>
<div class="form-text">The ticket shows on the service's page, in its Tickets tab.</div>
<?php } else { ?>
<div class="itflow-asset-empty py-4">
<i class="fas fa-stream fa-2x mb-2"></i>
<div><?= $linked ? 'Every service this client has is already linked.' : 'This client has no services yet.' ?></div>
</div>
<?php } ?>
</div>
<div class="modal-footer">
<?php if ($candidates) { ?>
<button type="submit" name="link_ticket_services" class="btn btn-primary text-bold"><i class="fas fa-link me-2"></i>Link</button>
<?php } ?>
<button type="button" class="btn btn-light" data-bs-dismiss="modal"><i class="fa fa-times me-2"></i>Cancel</button>
</div>
</form>
<?php
require_once '../../../includes/modal_footer.php';

View File

@@ -946,66 +946,6 @@ if (isset($_GET['unlink_credential_from_asset'])) {
}
if (isset($_POST['link_service_to_asset'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$service_id = intval($_POST['service_id']);
$asset_id = intval($_POST['asset_id']);
// Get service Name and Client ID for logging
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
$row = mysqli_fetch_assoc($sql_service);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Get Asset Name for logging
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
mysqli_query($mysqli,"INSERT INTO service_assets SET asset_id = $asset_id, service_id = $service_id");
logAudit("Service", "Link", "$session_name linked asset $asset_name to service $service_name", $client_id, $service_id);
flashAlert("Service <strong>$service_name</strong> linked with asset <strong>$asset_name</strong>");
redirect();
}
if (isset($_GET['unlink_service_from_asset'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$asset_id = intval($_GET['asset_id']);
$service_id = intval($_GET['service_id']);
// Get service Name and Client ID for logging
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
$row = mysqli_fetch_assoc($sql_service);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Get Asset Name for logging
$asset_name = escapeSql(getFieldById('assets', $asset_id, 'asset_name'));
mysqli_query($mysqli,"DELETE FROM service_assets WHERE asset_id = $asset_id AND service_id = $service_id");
logAudit("Service", "Unlink", "$session_name unlinked asset $asset_name from service $service_name", $client_id, $service_id);
flashAlert("Asset <strong>$asset_name</strong> unlinked from service <strong>$service_name</strong>", 'error');
redirect();
}
// END LINKING
if (isset($_POST["import_assets_csv"])) {

View File

@@ -1222,6 +1222,17 @@ if (isset($_POST["export_client_pdf"])) {
$sql_contacts = $pack['contacts'] ? mysqli_query($mysqli, "SELECT * FROM contacts WHERE contact_client_id = $client_id AND contact_archived_at IS NULL ORDER BY contact_name ASC") : false;
$sql_locations = $pack['locations'] ? mysqli_query($mysqli, "SELECT * FROM locations WHERE location_client_id = $client_id AND location_archived_at IS NULL ORDER BY location_name ASC") : false;
$sql_vendors = $pack['vendors'] ? mysqli_query($mysqli, "SELECT * FROM vendors WHERE vendor_client_id = $client_id AND vendor_archived_at IS NULL ORDER BY vendor_name ASC") : false;
// Services, most important first, with what each runs on and who supports it
$pack_services = [];
if ($pack['services']) {
$sql = mysqli_query($mysqli, "SELECT * FROM services WHERE service_client_id = $client_id AND service_archived_at IS NULL
ORDER BY FIELD(service_importance, 'High', 'Medium', 'Low'), service_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$row['runs_on'] = implode(', ', array_column(array_filter(serviceLinked($row['service_id'], 'asset'), function ($a) { return !$a['archived_at']; }), 'name'));
$row['supported_by'] = implode(', ', array_column(array_filter(serviceLinked($row['service_id'], 'vendor'), function ($v) { return !$v['archived_at']; }), 'name'));
$pack_services[] = $row;
}
}
$sql_credentials = $pack['credentials'] ? mysqli_query($mysqli, "SELECT * FROM credentials WHERE credential_client_id = $client_id ORDER BY credential_name ASC") : false;
$sql_assets = $pack['assets'] ? mysqli_query($mysqli, "SELECT 1 FROM assets
LEFT JOIN contacts ON asset_contact_id = contact_id
@@ -1520,6 +1531,46 @@ if (isset($_POST["export_client_pdf"])) {
</table>";
}
// Services Section
if ($pack['services'] == 1 && $pack_services) {
$pdf->Bookmark("Services", 0, 0, "", "B", array(0,0,0));
$html .= "
<h2 class='section-title'>Services</h2>
<table>
<thead>
<tr>
<th>Service</th>
<th>Importance</th>
<th>Runs On</th>
<th>Vendors</th>
<th>Backup and Recovery</th>
<th>Next Review</th>
</tr>
</thead>
<tbody>";
foreach ($pack_services as $row) {
$service_name = escapeHtml($row['service_name']);
$service_detail = escapeHtml(implode(' - ', array_filter([$row['service_category'], $row['service_description']])));
$service_importance = escapeHtml($row['service_importance']);
$service_runs_on = escapeHtml($row['runs_on']);
$service_vendors = escapeHtml($row['supported_by']);
$service_backup = nl2br(escapeHtml($row['service_backup']));
$service_review = escapeHtml((string) $row['service_review_due']);
$html .= "
<tr style='page-break-inside: avoid;'>
<td><strong>$service_name</strong><br>$service_detail</td>
<td>$service_importance</td>
<td>$service_runs_on</td>
<td>$service_vendors</td>
<td>$service_backup</td>
<td>$service_review</td>
</tr>";
}
$html .= "
</tbody>
</table>";
}
// Credentials Section
if ($pack['credentials'] == 1 && mysqli_num_rows($sql_credentials) > 0) {
$pdf->Bookmark("Credentials", 0, 0, "", "B", array(0,0,0));

View File

@@ -1070,66 +1070,6 @@ if (isset($_GET['unlink_credential_from_contact'])) {
}
if (isset($_POST['link_service_to_contact'])) {
validateCSRFToken();
enforceUserPermission('module_client', 2);
$service_id = intval($_POST['service_id']);
$contact_id = intval($_POST['contact_id']);
// Get service Name and Client ID for logging
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
$row = mysqli_fetch_assoc($sql_service);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Get Contact Name for logging
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
mysqli_query($mysqli,"INSERT INTO service_contacts SET contact_id = $contact_id, service_id = $service_id");
logAudit("Service", "Link", "$session_name linked contact $contact_name to service $service_name", $client_id, $service_id);
flashAlert("service <strong>$service_name</strong> linked with contact <strong>$contact_name</strong>");
redirect();
}
if (isset($_GET['unlink_service_from_contact'])) {
validateCSRFToken();
enforceUserPermission('module_client', 2);
$contact_id = intval($_GET['contact_id']);
$service_id = intval($_GET['service_id']);
// Get service Name and Client ID for logging
$sql_service = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
$row = mysqli_fetch_assoc($sql_service);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['service_client_id']);
enforceClientAccess();
// Get Contact Name for logging
$contact_name = escapeSql(getFieldById('contacts', $contact_id, 'contact_name'));
mysqli_query($mysqli,"DELETE FROM service_contacts WHERE contact_id = $contact_id AND service_id = $service_id");
logAudit("service", "Unlink", "$session_name unlinked contact $contact_name from service $service_name", $client_id, $service_id);
flashAlert("Contact <strong>$contact_name</strong> unlinked from service <strong>$service_name</strong>", 'error');
redirect();
}
if (isExportRequest('export_contacts')) {
validateCSRFToken();

View File

@@ -61,6 +61,8 @@ if (isset($_POST['add_document'])) {
$software_id = $software && intval($software['client_id']) === $client_id ? intval($software['id']) : 0;
$location_id = assetClientOwnedId('location', $_POST['location'] ?? 0, $client_id);
$vendor_id = assetClientOwnedId('vendor', $_POST['vendor'] ?? 0, $client_id);
$service = linkRecord('service', $_POST['service'] ?? 0);
$service_id = $service && intval($service['client_id']) === $client_id && !$service['archived_at'] ? intval($service['id']) : 0;
$client_visible = intval($_POST['client_visible'] ?? 0) ? 1 : 0;
if ($name === '') {
@@ -97,13 +99,17 @@ if (isset($_POST['add_document'])) {
if ($vendor_id) {
mysqli_query($mysqli, "INSERT IGNORE INTO vendor_documents SET vendor_id = $vendor_id, document_id = $document_id");
}
if ($service_id) {
mysqli_query($mysqli, "INSERT IGNORE INTO service_documents SET service_id = $service_id, document_id = $document_id");
logAudit("Service", "Link", "$session_name linked new document $name to service " . escapeSql($service['name']), $client_id, $service_id);
}
logAudit("Document", "Create", "$session_name created document $name", $client_id, $document_id);
flashAlert("Document <strong>" . trim($_POST['name']) . "</strong> created");
// From an asset, a contact, a license, a location or a vendor, back to it; otherwise to the new document
redirect(($contact_id || $asset_id || $software_id || $location_id || $vendor_id) ? null : "document.php?client_id=$client_id&document_id=$document_id");
// From an asset, a contact, a license, a location, a vendor or a service, back to it; otherwise to the new document
redirect(($contact_id || $asset_id || $software_id || $location_id || $vendor_id || $service_id) ? null : "document.php?client_id=$client_id&document_id=$document_id");
}

View File

@@ -2,8 +2,8 @@
/*
* ITFlow - links between documents, files and what they are about, the
* devices, users, credentials and files on a license, and the documents and
* files about a location.
* devices, users, credentials and files on a license, the documents and
* files about a location, and what a service depends on.
*
* One handler for every pair LINK_RELATIONS knows (functions/links.php):
* link_items links any number of records at once, unlink_item drops one.
@@ -83,6 +83,8 @@ $legacy_links = [
'contact_to_file' => ['file', 'file_id', 'contact', 'contact_id'],
'software_to_asset' => ['asset', 'asset_id', 'software', 'software_id'],
'software_to_contact' => ['contact', 'contact_id', 'software', 'software_id'],
'service_to_asset' => ['asset', 'asset_id', 'service', 'service_id'],
'service_to_contact' => ['contact', 'contact_id', 'service', 'service_id'],
];
foreach ($legacy_links as $legacy => [$from, $from_field, $to, $to_field]) {
if (isset($_POST["link_$legacy"])) {

View File

@@ -1,7 +1,11 @@
<?php
/*
* ITFlow - GET/POST request handler for client service info
* ITFlow - GET/POST request handler for client services
*
* A service and the things it depends on (functions/service.php). Links to
* those things go through the generic link handler (agent/post/link.php) -
* only Add Service links them here, from the pickers on its form.
*/
defined('FROM_POST_HANDLER') || die("Direct file access is not allowed");
@@ -12,80 +16,38 @@ if (isset($_POST['add_service'])) {
enforceUserPermission('module_support', 2);
$client_id = intval($_POST['client_id']);
$service_name = escapeSql($_POST['name']);
$service_description = escapeSql($_POST['description']);
$service_category = escapeSql($_POST['category']); //TODO: Needs integration with company categories
$service_importance = escapeSql($_POST['importance']);
$service_backup = escapeSql($_POST['backup']);
$service_notes = escapeSql($_POST['note']);
$client_id = intval($_POST['client_id'] ?? 0);
enforceClientAccess();
if (!$client_id || !mysqli_num_rows(mysqli_query($mysqli, "SELECT 1 FROM clients WHERE client_id = $client_id AND client_archived_at IS NULL"))) {
flashAlert('Pick the client the service is for.', 'error');
redirect();
}
// Create Service
mysqli_query($mysqli, "INSERT INTO services SET service_name = '$service_name', service_description = '$service_description', service_category = '$service_category', service_importance = '$service_importance', service_backup = '$service_backup', service_notes = '$service_notes', service_client_id = $client_id");
// Create links to assets
$error = '';
$set = serviceFormSet($_POST, $error);
if ($set === '') {
flashAlert($error, 'error');
redirect();
}
mysqli_query($mysqli, "INSERT INTO services SET $set, service_client_id = $client_id");
$service_id = mysqli_insert_id($mysqli);
if (isset($_POST['contacts'])) {
foreach($_POST['contacts'] as $contact_id) {
$contact_id = intval($contact_id);
mysqli_query($mysqli, "INSERT INTO service_contacts SET service_id = $service_id, contact_id = $contact_id");
}
}
if (isset($_POST['vendors'])) {
foreach($_POST['vendors'] as $vendor_id) {
$vendor_id = intval($vendor_id);
mysqli_query($mysqli, "INSERT INTO service_vendors SET service_id = $service_id, vendor_id = $vendor_id");
}
}
if (isset($_POST['documents'])) {
foreach($_POST['documents'] as $document_id) {
$document_id = intval($document_id);
mysqli_query($mysqli, "INSERT INTO service_documents SET service_id = $service_id, document_id = $document_id");
}
}
if (isset($_POST['assets'])) {
foreach($_POST['assets'] as $asset_id) {
$asset_id = intval($asset_id);
mysqli_query($mysqli, "INSERT INTO service_assets SET service_id = $service_id, asset_id = $asset_id");
}
}
if (isset($_POST['credentials'])) {
foreach($_POST['credentials'] as $credential_id) {
$credential_id = intval($credential_id);
// Only the client's own credentials
mysqli_query($mysqli, "INSERT INTO service_credentials (service_id, credential_id) SELECT $service_id, credential_id FROM credentials WHERE credential_id = $credential_id AND credential_client_id = $client_id");
}
}
if (isset($_POST['domains'])) {
foreach($_POST['domains'] as $domain_id) {
$domain_id = intval($domain_id);
// Only the client's own domains
mysqli_query($mysqli, "INSERT INTO service_domains (service_id, domain_id) SELECT $service_id, domain_id FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id");
}
}
if (isset($_POST['certificates'])) {
foreach($_POST['certificates'] as $cert_id) {
$cert_id = intval($cert_id);
// Only the client's own certificates
mysqli_query($mysqli, "INSERT INTO service_certificates (service_id, certificate_id) SELECT $service_id, certificate_id FROM certificates WHERE certificate_id = $cert_id AND certificate_client_id = $client_id");
}
}
$service_name = escapeSql(trim($_POST['name']));
logAudit("Service", "Create", "$session_name created service $service_name", $client_id, $service_id);
flashAlert("Service <strong>$service_name</strong> created");
// What it depends on, from the form's pickers - the client's own, unarchived records only (linkAdd checks)
$linked = 0;
foreach (SERVICE_LINK_TYPES as $type) {
$ids = $_POST[LINK_ENTITIES[$type]['table']] ?? [];
if ($ids && linkCanEdit('service', $type)) {
$linked += count(linkAdd('service', $service_id, $type, (array) $ids));
}
}
redirect();
flashAlert("Service <strong>" . escapeHtml(trim($_POST['name'])) . "</strong> created" . ($linked ? " with <strong>$linked</strong> linked" : ' - link what it runs on and depends on below'));
redirect(serviceUrl($service_id, $client_id));
}
@@ -93,88 +55,110 @@ if (isset($_POST['edit_service'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$row = serviceForRequest($_POST['service_id'] ?? 0, 2);
$service_id = intval($row['service_id']);
$service_id = intval($_POST['service_id']);
$service_name = escapeSql($_POST['name']);
$service_description = escapeSql($_POST['description']);
$service_category = escapeSql($_POST['category']); //TODO: Needs integration with company categories
$service_importance = escapeSql($_POST['importance']);
$service_backup = escapeSql($_POST['backup']);
$service_notes = escapeSql($_POST['note']);
$client_id = intval(getFieldById('services', $service_id, 'service_client_id'));
enforceClientAccess();
// Update main service details
mysqli_query($mysqli, "UPDATE services SET service_name = '$service_name', service_description = '$service_description', service_category = '$service_category', service_importance = '$service_importance', service_backup = '$service_backup', service_notes = '$service_notes' WHERE service_id = $service_id");
// Unlink existing relations/assets
mysqli_query($mysqli, "DELETE FROM service_contacts WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_vendors WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_documents WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_assets WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_credentials WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_domains WHERE service_id = $service_id");
mysqli_query($mysqli, "DELETE FROM service_certificates WHERE service_id = $service_id");
// Relink
if (isset($_POST['contacts'])) {
foreach($_POST['contacts'] as $contact_id) {
$contact_id = intval($contact_id);
mysqli_query($mysqli, "INSERT INTO service_contacts SET service_id = $service_id, contact_id = $contact_id");
}
$error = '';
$set = serviceFormSet($_POST, $error, $row);
if ($set === '') {
flashAlert($error, 'error');
redirect();
}
if (isset($_POST['vendors'])) {
foreach($_POST['vendors'] as $vendor_id) {
$vendor_id = intval($vendor_id);
mysqli_query($mysqli, "INSERT INTO service_vendors SET service_id = $service_id, vendor_id = $vendor_id");
}
}
if (isset($_POST['documents'])) {
foreach($_POST['documents'] as $document_id) {
$document_id = intval($document_id);
mysqli_query($mysqli, "INSERT INTO service_documents SET service_id = $service_id, document_id = $document_id");
}
}
if (isset($_POST['assets'])) {
foreach($_POST['assets'] as $asset_id) {
$asset_id = intval($asset_id);
mysqli_query($mysqli, "INSERT INTO service_assets SET service_id = $service_id, asset_id = $asset_id");
}
}
if (isset($_POST['credentials'])) {
foreach($_POST['credentials'] as $credential_id) {
$credential_id = intval($credential_id);
// Only the client's own credentials
mysqli_query($mysqli, "INSERT INTO service_credentials (service_id, credential_id) SELECT $service_id, credential_id FROM credentials WHERE credential_id = $credential_id AND credential_client_id = $client_id");
}
}
if (isset($_POST['domains'])) {
foreach($_POST['domains'] as $domain_id) {
$domain_id = intval($domain_id);
// Only the client's own domains
mysqli_query($mysqli, "INSERT INTO service_domains (service_id, domain_id) SELECT $service_id, domain_id FROM domains WHERE domain_id = $domain_id AND domain_client_id = $client_id");
}
}
if (isset($_POST['certificates'])) {
foreach($_POST['certificates'] as $cert_id) {
$cert_id = intval($cert_id);
// Only the client's own certificates
mysqli_query($mysqli, "INSERT INTO service_certificates (service_id, certificate_id) SELECT $service_id, certificate_id FROM certificates WHERE certificate_id = $cert_id AND certificate_client_id = $client_id");
}
}
mysqli_query($mysqli, "UPDATE services SET $set WHERE service_id = $service_id");
$service_name = escapeSql(trim($_POST['name']));
logAudit("Service", "Edit", "$session_name edited service $service_name", $client_id, $service_id);
flashAlert("Service <strong>$service_name</strong> edited");
flashAlert("Service <strong>" . escapeHtml(trim($_POST['name'])) . "</strong> saved");
redirect();
}
// Notes save from the service page when you click away
if (isset($_POST['service_set_notes'])) {
validateCSRFToken();
$row = serviceForRequest($_POST['service_id'] ?? 0, 2);
$notes = escapeSql((string) ($_POST['notes'] ?? ''));
mysqli_query($mysqli, "UPDATE services SET service_notes = '$notes' WHERE service_id = " . intval($row['service_id']));
logAudit("Service", "Edit", "$session_name updated the notes of service " . escapeSql($row['service_name']), $client_id, intval($row['service_id']));
if (!empty($_POST['ajax'])) {
header('Content-Type: application/json');
echo json_encode(['ok' => true]);
exit;
}
flashAlert("Notes saved");
redirect();
}
if (isset($_POST['review_service'])) {
validateCSRFToken();
$row = serviceForRequest($_POST['service_id'] ?? 0, 2);
// A new schedule can be set at the same time
if (isset($_POST['review_interval']) && isset(SERVICE_REVIEW_INTERVALS[intval($_POST['review_interval'])])) {
$row['service_review_interval'] = intval($_POST['review_interval']);
mysqli_query($mysqli, "UPDATE services SET service_review_interval = {$row['service_review_interval']} WHERE service_id = " . intval($row['service_id']));
}
$next = serviceMarkReviewed($row, trim((string) ($_POST['review_due'] ?? '')), (string) ($_POST['note'] ?? ''));
flashAlert("Service <strong>" . escapeHtml($row['service_name']) . "</strong> marked reviewed" . ($next ? " - next review " . date('M j, Y', strtotime($next)) : ''));
redirect();
}
if (isset($_GET['favorite_service']) || isset($_GET['unfavorite_service'])) {
validateCSRFToken();
$favorite = isset($_GET['favorite_service']) ? 1 : 0;
$row = serviceForRequest($favorite ? $_GET['favorite_service'] : $_GET['unfavorite_service'], 2);
mysqli_query($mysqli, "UPDATE services SET service_favorite = $favorite WHERE service_id = " . intval($row['service_id']));
logAudit("Service", "Edit", "$session_name " . ($favorite ? 'starred' : 'unstarred') . " service " . escapeSql($row['service_name']), $client_id, intval($row['service_id']));
flashAlert("Service <strong>" . escapeHtml($row['service_name']) . "</strong> " . ($favorite ? 'starred' : 'unstarred'));
redirect();
}
if (isset($_GET['archive_service'])) {
validateCSRFToken();
$row = serviceForRequest($_GET['archive_service'], 2);
serviceArchive($row);
flashAlert("Service <strong>" . escapeHtml($row['service_name']) . "</strong> archived", 'error');
redirect();
}
if (isset($_GET['restore_service'])) {
validateCSRFToken();
$row = serviceForRequest($_GET['restore_service'], 2);
serviceRestore($row);
flashAlert("Service <strong>" . escapeHtml($row['service_name']) . "</strong> restored");
redirect();
@@ -184,24 +168,350 @@ if (isset($_GET['delete_service'])) {
validateCSRFToken();
enforceUserPermission('module_support', 3);
$row = serviceForRequest($_GET['delete_service'], 3);
$service_id = intval($_GET['delete_service']);
serviceDelete($row);
// Get Service Details
$sql = mysqli_query($mysqli,"SELECT service_name, service_client_id FROM services WHERE service_id = $service_id");
$row = mysqli_fetch_assoc($sql);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['service_client_id']);
flashAlert("Service <strong>" . escapeHtml($row['service_name']) . "</strong> deleted", 'error');
enforceClientAccess();
// Not back to the page of a service that is gone
$referer = $_SERVER['HTTP_REFERER'] ?? '';
redirect(strpos($referer, 'service.php') !== false ? 'services.php?client_id=' . intval($row['service_client_id']) : null);
// Delete service
mysqli_query($mysqli, "DELETE FROM services WHERE service_id = $service_id");
}
logAudit("Service", "Delete", "$session_name deleted service $service_name", $client_id);
// Tickets raised about a service - from its page, or from the ticket
if (isset($_POST['link_service_tickets'])) {
flashAlert("Service <strong>$service_name</strong> deleted", 'error');
validateCSRFToken();
$row = serviceForRequest($_POST['service_id'] ?? 0, 2);
$added = serviceLinkTickets($row['service_id'], $client_id, (array) ($_POST['ticket_ids'] ?? []));
if ($added) {
logAudit("Service", "Link", "$session_name linked $added ticket(s) to service " . escapeSql($row['service_name']), $client_id, intval($row['service_id']));
flashAlert("Linked <strong>$added</strong> ticket" . ($added === 1 ? '' : 's') . " to <strong>" . escapeHtml($row['service_name']) . "</strong>");
} else {
flashAlert("Nothing new to link to <strong>" . escapeHtml($row['service_name']) . "</strong>.", 'warning');
}
redirect();
}
if (isset($_POST['link_ticket_services'])) {
validateCSRFToken();
enforceUserPermission('module_support', 2);
$ticket_id = intval($_POST['ticket_id'] ?? 0);
$ticket = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_id, ticket_prefix, ticket_number, ticket_client_id FROM tickets WHERE ticket_id = $ticket_id"));
if (!$ticket || !intval($ticket['ticket_client_id'])) {
flashAlert('That ticket no longer exists.', 'error');
redirect();
}
$client_id = intval($ticket['ticket_client_id']);
enforceClientAccess();
$names = [];
foreach (array_unique(array_map('intval', (array) ($_POST['service_ids'] ?? []))) as $service_id) {
$row = serviceRow($service_id);
if (!$row || intval($row['service_client_id']) !== $client_id || $row['service_archived_at']) {
continue;
}
if (serviceLinkTickets($service_id, $client_id, [$ticket_id])) {
$names[] = $row['service_name'];
logAudit("Service", "Link", "$session_name linked ticket " . escapeSql($ticket['ticket_prefix'] . $ticket['ticket_number']) . " to service " . escapeSql($row['service_name']), $client_id, $service_id);
}
}
if ($names) {
flashAlert("Ticket linked to <strong>" . escapeHtml(implode(', ', $names)) . "</strong>");
} else {
flashAlert('Nothing new to link.', 'warning');
}
redirect();
}
if (isset($_GET['unlink_service_ticket'])) {
validateCSRFToken();
$row = serviceForRequest($_GET['service_id'] ?? 0, 2);
$ticket_id = intval($_GET['unlink_service_ticket']);
mysqli_query($mysqli, "DELETE FROM service_tickets WHERE service_id = " . intval($row['service_id']) . " AND ticket_id = $ticket_id");
if (mysqli_affected_rows($mysqli) > 0) {
$ticket = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_prefix, ticket_number FROM tickets WHERE ticket_id = $ticket_id"));
$reference = $ticket ? $ticket['ticket_prefix'] . $ticket['ticket_number'] : "#$ticket_id";
logAudit("Service", "Unlink", "$session_name unlinked ticket " . escapeSql($reference) . " from service " . escapeSql($row['service_name']), $client_id, intval($row['service_id']));
flashAlert("Ticket <strong>" . escapeHtml($reference) . "</strong> unlinked from <strong>" . escapeHtml($row['service_name']) . "</strong>", 'error');
}
redirect();
}
/*
* Bulk actions from the services list
*/
if (isset($_POST['bulk_edit_services'])) {
validateCSRFToken();
$rows = servicesForBulk(2);
// Each field only when one was picked - blank leaves it as it is
$sets = [];
$changes = [];
if (in_array($_POST['importance'] ?? '', SERVICE_IMPORTANCE, true)) {
$sets[] = "service_importance = '{$_POST['importance']}'";
$changes[] = 'importance ' . $_POST['importance'];
}
$category = trim((string) ($_POST['category'] ?? ''));
if ($category !== '') {
$category = mb_substr($category, 0, 50);
$sets[] = "service_category = '" . escapeSql($category) . "'";
$changes[] = 'category ' . $category;
}
$interval = (string) ($_POST['review_interval'] ?? '');
$set_interval = $interval !== '' && isset(SERVICE_REVIEW_INTERVALS[intval($interval)]);
if (!$sets && !$set_interval) {
flashAlert('Nothing picked to change.', 'warning');
redirect();
}
$count = 0;
foreach ($rows as $service_id => $row) {
$row_sets = $sets;
if ($set_interval) {
$months = intval($interval);
$row_sets[] = "service_review_interval = $months";
// A schedule needs a next date: from the last review, never in the past - and none without a schedule
if ($months) {
$due = max(serviceNextReview($months, $row['service_reviewed_at'] ?: null), date('Y-m-d'));
$row_sets[] = "service_review_due = '$due'";
} else {
$row_sets[] = "service_review_due = NULL";
}
}
mysqli_query($mysqli, "UPDATE services SET " . implode(', ', $row_sets) . " WHERE service_id = $service_id");
$what = $changes;
if ($set_interval) {
$what[] = 'reviews ' . strtolower(SERVICE_REVIEW_INTERVALS[intval($interval)]);
}
logAudit("Service", "Edit", "$session_name set " . escapeSql(implode(', ', $what)) . " on service " . escapeSql($row['service_name']), intval($row['service_client_id']), $service_id);
$count++;
}
flashAlert("Updated <strong>$count</strong> service" . ($count === 1 ? '' : 's'));
redirect();
}
if (isset($_POST['bulk_review_services'])) {
validateCSRFToken();
$count = 0;
foreach (servicesForBulk(2) as $row) {
if ($row['service_archived_at']) {
continue;
}
serviceMarkReviewed($row);
$count++;
}
flashAlert("Marked <strong>$count</strong> service" . ($count === 1 ? '' : 's') . " reviewed");
redirect();
}
if (isset($_POST['bulk_favorite_services']) || isset($_POST['bulk_unfavorite_services'])) {
validateCSRFToken();
$favorite = isset($_POST['bulk_favorite_services']) ? 1 : 0;
$count = 0;
foreach (servicesForBulk(2) as $service_id => $row) {
mysqli_query($mysqli, "UPDATE services SET service_favorite = $favorite WHERE service_id = $service_id");
$count++;
}
flashAlert(($favorite ? 'Starred' : 'Unstarred') . " <strong>$count</strong> service" . ($count === 1 ? '' : 's'));
redirect();
}
if (isset($_POST['bulk_archive_services'])) {
validateCSRFToken();
$count = 0;
foreach (servicesForBulk(2) as $row) {
if (!$row['service_archived_at']) {
serviceArchive($row);
$count++;
}
}
flashAlert("Archived <strong>$count</strong> service" . ($count === 1 ? '' : 's'), 'error');
redirect();
}
if (isset($_POST['bulk_restore_services'])) {
validateCSRFToken();
$count = 0;
foreach (servicesForBulk(2) as $row) {
if ($row['service_archived_at']) {
serviceRestore($row);
$count++;
}
}
flashAlert("Restored <strong>$count</strong> service" . ($count === 1 ? '' : 's'));
redirect();
}
if (isset($_POST['bulk_delete_services'])) {
validateCSRFToken();
$count = 0;
foreach (servicesForBulk(3) as $row) {
serviceDelete($row);
$count++;
}
flashAlert("Deleted <strong>$count</strong> service" . ($count === 1 ? '' : 's'), 'error');
redirect();
}
if (isExportRequest('export_services')) {
validateCSRFToken();
enforceUserPermission('module_support');
$format = resolveExportFormat($_POST['export_services']);
$filter_summary = [];
$client_id = intval($_POST['client_id'] ?? 0);
$where = [clientScopeSql('service_client_id')];
if ($client_id) {
enforceClientAccess();
$where[] = "AND service_client_id = $client_id";
$file_name_prepend = getFieldById('clients', $client_id, 'client_name') . '-';
$filter_summary['Client'] = getFieldById('clients', $client_id, 'client_name');
} else {
$file_name_prepend = "$session_company_name-";
$where[] = 'AND clients.client_archived_at IS NULL';
if (intval($_POST['client'] ?? 0)) {
$where[] = 'AND service_client_id = ' . intval($_POST['client']);
$filter_summary['Client'] = getFieldById('clients', intval($_POST['client']), 'client_name');
}
}
$views = serviceViews();
$show = (string) ($_POST['show'] ?? '');
if (!isset($views[$show])) {
$show = '';
}
if ($views[$show]['where'] !== '') {
$where[] = 'AND ' . $views[$show]['where'];
}
$filter_summary['Showing'] = $views[$show]['label'];
if (in_array($_POST['importance'] ?? '', SERVICE_IMPORTANCE, true)) {
$where[] = "AND service_importance = '{$_POST['importance']}'";
$filter_summary['Importance'] = $_POST['importance'];
}
$category = trim((string) ($_POST['category'] ?? ''));
if ($category !== '') {
$where[] = "AND service_category = '" . escapeSql($category) . "'";
$filter_summary['Category'] = $category;
}
$q = escapeSql($_POST['q'] ?? '');
if ($q !== '') {
$filter_summary['Search'] = $_POST['q'];
}
$sql = mysqli_query($mysqli, "SELECT services.*, client_name FROM services
LEFT JOIN clients ON client_id = service_client_id
WHERE (service_name LIKE '%$q%' OR service_description LIKE '%$q%' OR service_category LIKE '%$q%' OR client_name LIKE '%$q%')
" . implode(' ', $where) . "
ORDER BY client_name ASC, FIELD(service_importance, 'High', 'Medium', 'Low'), service_name ASC");
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$rows[intval($row['service_id'])] = $row;
}
$num_rows = count($rows);
if ($num_rows > 0) {
guardExportPdfRowCount($format, $num_rows);
$ids = array_keys($rows);
$in = implode(',', $ids);
$counts = serviceCounts($ids);
$issues = serviceIssues($ids);
// The names of what each one depends on, for the columns that list them
$names = [];
foreach (['asset', 'vendor', 'contact', 'domain'] as $type) {
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type];
$sql = mysqli_query($mysqli, "SELECT l.service_id, t.{$entity['name']} FROM {$relation['table']} l
JOIN {$entity['table']} t ON t.{$entity['id']} = l.{$entity['id']} AND t.{$entity['archived']} IS NULL
WHERE l.service_id IN ($in) ORDER BY t.{$entity['name']}");
while ($name_row = mysqli_fetch_row($sql)) {
$names[intval($name_row[0])][$type][] = $name_row[1];
}
}
$export = beginExport('services', $format, $file_name_prepend . 'Services', 'Services', summarizeExportFilters($filter_summary));
foreach ($rows as $service_id => $row) {
$review = serviceReview($row);
$row['service_assets'] = implode(', ', $names[$service_id]['asset'] ?? []);
$row['service_vendors'] = implode(', ', $names[$service_id]['vendor'] ?? []);
$row['service_contacts'] = implode(', ', $names[$service_id]['contact'] ?? []);
$row['service_domains'] = implode(', ', $names[$service_id]['domain'] ?? []);
$row['service_attention'] = implode('; ', array_column($issues[$service_id], 'text'));
$row['service_review'] = $review['date'] ? $review['date'] . ($review['state'] === 'overdue' ? ' (overdue)' : '') : '';
$row['service_reviewed'] = $row['service_reviewed_at'] ? substr($row['service_reviewed_at'], 0, 10) : '';
$row['service_review_every'] = intval($row['service_review_interval']) ? (SERVICE_REVIEW_INTERVALS[intval($row['service_review_interval'])] ?? '') : '';
$row['open_tickets'] = $counts[$service_id]['open_tickets'];
$row['service_state'] = $row['service_archived_at'] ? 'Archived' : 'Active';
addExportRow($export, $row);
}
finishExport($export);
logAudit("Service", "Export", "$session_name exported $num_rows service(s) to a " . strtoupper($format) . " file", $client_id);
exit;
}
flashAlert('No services match - nothing to export.', 'error');
redirect();

View File

@@ -163,6 +163,15 @@ if (isset($_POST['add_ticket'])) {
ticketAddWatchers($ticket_id, ticketWatcherEmails($_POST['watchers'] ?? []));
ticketSetOtherAssets($ticket_id, $other_asset_ids);
// Raised about a service - from the service page's "Report a problem"
foreach (array_unique(array_map('intval', (array) ($_POST['service_ids'] ?? []))) as $service_id) {
$service = serviceRow($service_id);
if ($service && intval($service['service_client_id']) === $client_id && !$service['service_archived_at']) {
serviceLinkTickets($service_id, $client_id, [$ticket_id]);
logAudit("Service", "Link", "$session_name raised ticket $ticket_prefix$ticket_number about service " . escapeSql($service['service_name']), $client_id, $service_id);
}
}
// E-mail the client and the watchers
if (intval($config_ticket_client_general_notifications) === 1) {
ticketMailCreated($ticket_id, 'Ticket Created', $emailable_attachments['send']);

716
agent/service.php Normal file
View File

@@ -0,0 +1,716 @@
<?php
/*
* Service - one service a client relies on: email, backup, the line of
* business app, the phones.
*
* What an agent wants when it breaks, in one place: how important it is,
* anything it depends on that needs attention now (header), who to call
* and how it comes back, the notes, and then everything it depends on in
* tabs with counts - the assets it runs on (with their addresses, networks
* and warranties), the logins, the domains and certificates, the documents,
* the tickets raised about it or its assets, and its history from the audit
* log. Report a problem starts a ticket that already says all that. The
* open tab follows the URL hash (#logins) and is remembered between visits.
*/
// If client_id is in URI then show client Side Bar and client header
if (isset($_GET['client_id'])) {
require_once "includes/inc_all_client.php";
$client_url = "client_id=$client_id&";
} else {
require_once "includes/inc_client_overview_all.php";
$client_url = '';
}
// Perms
enforceUserPermission('module_support');
$service_id = intval($_GET['service_id'] ?? 0);
$service = serviceRow($service_id);
if (!$service || ($client_url && intval($service['service_client_id']) !== intval($client_id))) {
echo "<center><h1 class='text-secondary mt-5'>Nothing to see here</h1><a class='btn btn-lg btn-secondary mt-3' href='javascript:history.back()'><i class='fa fa-fw fa-arrow-left'></i> Go Back</a></center>";
} else {
$client_id = intval($service['service_client_id']);
enforceClientAccess();
$client_url = "client_id=$client_id&";
$service_name = escapeHtml($service['service_name']);
$service_archived = !empty($service['service_archived_at']);
$is_favorite = intval($service['service_favorite']) === 1;
$can_edit = serviceCan(2) && !$service_archived;
$can_restore = serviceCan(2);
$can_delete = serviceCan(3) && !empty($config_destructive_deletes_enable);
$can_credentials = lookupUserPermission('module_credential') >= 1;
$can_link_credentials = $can_edit && linkCanEdit('service', 'credential');
// Override Tab Title // No Sanitizing needed as this var will only be used in the tab title
$page_title = $service['service_name'];
$counts = serviceCounts([$service_id])[$service_id];
$issues = serviceIssues([$service_id])[$service_id];
$review = serviceReview($service);
$urls = serviceUrls($service_id, $can_credentials);
// What it runs on - each with its address, network, site and warranty
$assets = [];
$sql = mysqli_query($mysqli, "SELECT assets.asset_id, asset_name, asset_type, asset_make, asset_model, asset_status, asset_warranty_expire, asset_archived_at,
asset_contact_id, asset_location_id, interface_ip, network_name, network_vlan, location_name, contact_name, contact_photo
FROM service_assets
JOIN assets ON assets.asset_id = service_assets.asset_id
LEFT JOIN asset_interfaces ON interface_asset_id = assets.asset_id AND interface_primary = 1
LEFT JOIN networks ON network_id = interface_network_id
LEFT JOIN locations ON location_id = asset_location_id
LEFT JOIN contacts ON contact_id = asset_contact_id
WHERE service_assets.service_id = $service_id
ORDER BY asset_archived_at IS NOT NULL, asset_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$assets[] = $row;
}
$networks = array_unique(array_filter(array_column(array_filter($assets, function ($a) { return !$a['asset_archived_at']; }), 'network_name')));
$sites = array_unique(array_filter(array_column(array_filter($assets, function ($a) { return !$a['asset_archived_at']; }), 'location_name')));
// Its logins, and the ones on the assets it runs on
$credentials = $can_credentials ? credentialRows("credential_id IN (SELECT credential_id FROM service_credentials WHERE service_id = $service_id)") : [];
$asset_credentials = $can_credentials ? credentialRows("credential_client_id = $client_id AND credential_asset_id IN (SELECT asset_id FROM service_assets WHERE service_id = $service_id)
AND credential_id NOT IN (SELECT credential_id FROM service_credentials WHERE service_id = $service_id)") : [];
$domains = serviceLinked($service_id, 'domain');
$certificates = serviceLinked($service_id, 'certificate');
$documents = serviceLinked($service_id, 'document');
$contacts = serviceLinked($service_id, 'contact');
$vendors = serviceLinked($service_id, 'vendor');
$archived_credentials = $can_credentials ? array_values(array_filter(serviceLinked($service_id, 'credential'), function ($row) { return $row['archived_at']; })) : [];
// Who to call - the vendors' and people's details for the call
$vendor_details = [];
if ($vendors) {
$sql = mysqli_query($mysqli, "SELECT vendor_id, vendor_account_number, vendor_code, vendor_email, vendor_website, vendor_hours, vendor_sla FROM vendors
WHERE vendor_id IN (" . implode(',', array_map('intval', array_column($vendors, 'id'))) . ")");
while ($row = mysqli_fetch_assoc($sql)) {
$vendor_details[intval($row['vendor_id'])] = $row;
}
}
$contact_details = [];
if ($contacts) {
$sql = mysqli_query($mysqli, "SELECT contact_id, contact_email, contact_phone, contact_phone_country_code, contact_extension, contact_mobile, contact_mobile_country_code FROM contacts
WHERE contact_id IN (" . implode(',', array_map('intval', array_column($contacts, 'id'))) . ")");
while ($row = mysqli_fetch_assoc($sql)) {
$contact_details[intval($row['contact_id'])] = $row;
}
}
$tickets = ticketRows(serviceTicketsSql($service_id), 100);
$linked_ticket_ids = [];
$sql = mysqli_query($mysqli, "SELECT ticket_id FROM service_tickets WHERE service_id = $service_id");
while ($row = mysqli_fetch_row($sql)) {
$linked_ticket_ids[intval($row[0])] = true;
}
$open_tickets = count(array_filter($tickets, 'ticketIsOpen'));
$history = serviceHistory($service_id, 100);
$service_tabs = [
'assets' => ['label' => 'Runs on', 'icon' => 'fa-desktop', 'count' => count($assets)],
'logins' => ['label' => 'Logins', 'icon' => 'fa-key', 'count' => count($credentials) + count($asset_credentials) + count($archived_credentials)],
'web' => ['label' => 'Domains &amp; SSL', 'icon' => 'fa-globe', 'count' => count($domains) + count($certificates)],
'documents' => ['label' => 'Documents', 'icon' => 'fa-file-alt', 'count' => count($documents)],
'tickets' => ['label' => 'Tickets', 'icon' => 'fa-life-ring', 'count' => count($tickets), 'alarm' => $open_tickets],
'history' => ['label' => 'History', 'icon' => 'fa-history', 'count' => count($history)],
];
if (!$can_credentials) {
unset($service_tabs['logins']);
}
$link_url = "modals/link/link.php?from=service&id=$service_id&to=";
$unlink_url = function ($to, $other_id) use ($service_id) {
return "post.php?unlink_item&from=service&id=$service_id&to=$to&other=" . intval($other_id) . "&csrf_token=" . $_SESSION['csrf_token'];
};
$report_url = 'modals/ticket/ticket_add.php?' . http_build_query(['client_id' => $client_id, 'service_id' => $service_id]);
$has_danger = in_array('danger', array_column($issues, 'tone'), true);
/** An archived record still linked - struck through, with a way to unlink it. */
$archived_row = function ($to, $row) use ($can_edit, $unlink_url) {
$entity = LINK_ENTITIES[$to];
return '<li class="itflow-link-row"><span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw ' . $entity['icon'] . '"></i></span>'
. '<div class="min-w-0 flex-grow-1"><div class="text-truncate text-decoration-line-through text-body-secondary">' . escapeHtml($row['name']) . '</div>'
. '<div class="small text-warning-emphasis">Archived - unlink it, or link what replaced it</div></div>'
. ($can_edit ? '<a class="btn btn-sm btn-light" href="' . escapeHtml($unlink_url($to, $row['id'])) . '" title="Unlink"><i class="fas fa-fw fa-unlink"></i></a>' : '')
. '</li>';
};
?>
<ol class="breadcrumb d-print-none">
<li class="breadcrumb-item">
<a href="client_overview.php?client_id=<?= $client_id ?>"><?= escapeHtml($service['client_name']) ?></a>
</li>
<li class="breadcrumb-item">
<a href="services.php?client_id=<?= $client_id ?>">Services</a>
</li>
<li class="breadcrumb-item active"><?= $service_name ?></li>
</ol>
<!-- What it is, how much it matters, when it is next checked -->
<div class="card mb-3">
<div class="card-body d-flex flex-wrap align-items-center gap-3">
<?= serviceTile($service['service_category'], 'lg') ?>
<div class="flex-grow-1 min-w-0">
<h1 class="h4 fw-semibold mb-1 d-flex flex-wrap align-items-center gap-2">
<span><?= $service_name ?></span>
<?php if ($is_favorite) { ?><i class="fas fa-star text-warning fs-6" title="Starred"></i><?php } ?>
<?php if ($service_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal fs-6">Archived</span><?php } ?>
<span class="fs-6"><?= serviceImportancePill($service['service_importance'], true) ?></span>
<span class="fs-6"><?= serviceReviewPill($review, true) ?></span>
</h1>
<div class="text-body-secondary small d-flex flex-wrap column-gap-3 row-gap-1">
<?php if ($service['service_category']) { ?><span><i class="fas fa-fw <?= serviceStyle($service['service_category'])['icon'] ?> me-1"></i><?= escapeHtml($service['service_category']) ?></span><?php } ?>
<?php if ($service['service_description']) { ?><span><?= escapeHtml($service['service_description']) ?></span><?php } ?>
</div>
</div>
<div class="d-flex flex-wrap gap-2 d-print-none">
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-outline-danger ajax-modal" data-modal-size="lg" data-modal-url="<?= escapeHtml($report_url) ?>">
<i class="fas fa-life-ring me-2"></i>Report a problem
</button>
<div class="dropdown">
<button type="button" class="btn btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"><i class="fas fa-link me-2"></i>Link</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>asset"><i class="fa fa-fw fa-desktop text-secondary me-2"></i>Asset it runs on</a>
<?php if ($can_link_credentials) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>credential"><i class="fa fa-fw fa-key text-secondary me-2"></i>Login</a>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>domain"><i class="fa fa-fw fa-globe text-secondary me-2"></i>Domain</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>certificate"><i class="fa fa-fw fa-lock text-secondary me-2"></i>Certificate</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>contact"><i class="fa fa-fw fa-user text-secondary me-2"></i>Person</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>vendor"><i class="fa fa-fw fa-building text-secondary me-2"></i>Vendor</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>document"><i class="fa fa-fw fa-file-alt text-secondary me-2"></i>Document</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/service/service_link_ticket.php?id=<?= $service_id ?>"><i class="fa fa-fw fa-life-ring text-secondary me-2"></i>Ticket</a>
</div>
</div>
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-url="modals/service/service_review.php?id=<?= $service_id ?>">
<i class="fas fa-clipboard-check me-2"></i>Mark reviewed
</button>
<button type="button" class="btn btn-outline-secondary ajax-modal" data-modal-size="lg" data-modal-url="modals/service/service_edit.php?id=<?= $service_id ?>">
<i class="fas fa-edit me-2"></i>Edit
</button>
<?php } ?>
<?php if ($can_restore) { ?>
<div class="dropdown dropstart">
<button class="btn btn-outline-secondary" title="More actions" type="button" data-bs-toggle="dropdown">
<i class="fas fa-fw fa-ellipsis-v"></i>
</button>
<div class="dropdown-menu">
<?php if ($service_archived) { ?>
<a class="dropdown-item" href="post.php?restore_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
</a>
<?php if ($can_delete) { ?>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
data-confirm-text="<?= $service_name ?> goes for good. What it linked to - assets, logins, documents - stays.">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
<?php } ?>
<?php } else { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-size="xl" data-modal-url="modals/document/document_add.php?client_id=<?= $client_id ?>&service_id=<?= $service_id ?>">
<i class="fas fa-fw fa-file-alt text-secondary me-2"></i>New runbook document
</a>
<a class="dropdown-item" href="post.php?<?= $is_favorite ? 'unfavorite_service' : 'favorite_service' ?>=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="<?= $is_favorite ? 'far' : 'fas' ?> fa-fw fa-star text-secondary me-2"></i><?= $is_favorite ? 'Unstar' : 'Star' ?>
</a>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
data-confirm-text="<?= $service_name ?> moves to Archived, off the lists and counts, until restored.">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</a>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
<?php if ($issues && !$service_archived) { ?>
<!-- What it depends on that needs attention now -->
<div class="alert alert-<?= $has_danger ? 'danger' : 'warning' ?> d-flex gap-3 mb-3 itflow-service-alert">
<i class="fas fa-exclamation-triangle mt-1"></i>
<div class="min-w-0">
<div class="fw-semibold mb-1"><?= count($issues) ?> thing<?= count($issues) === 1 ? '' : 's' ?> it depends on need<?= count($issues) === 1 ? 's' : '' ?> attention</div>
<?= serviceIssuesHtml($issues) ?>
</div>
</div>
<?php } ?>
<div class="row g-3">
<!-- The facts, who to call, how it comes back, the notes -->
<div class="col-xl-4 col-lg-5">
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title mb-0"><i class="fas fa-fw fa-stream text-secondary me-2"></i>Service</h3>
</div>
<div class="card-body">
<dl class="itflow-asset-dl mb-0">
<dt>Importance</dt>
<dd><?= $can_edit ? quickPick('service_importance', $service_id, $service['service_importance'], serviceImportancePill($service['service_importance'])) : serviceImportancePill($service['service_importance']) ?></dd>
<dt>Review</dt>
<dd>
<?php if ($review['date']) { ?>
<?= escapeHtml(date('M j, Y', strtotime($review['date']))) ?>
<div class="small text-<?= $review['tone'] === 'success' ? 'body-secondary' : $review['tone'] . '-emphasis' ?>"><?= escapeHtml($review['state'] === 'scheduled' ? ucfirst(timeAgo($review['date'])) : $review['text']) ?></div>
<?php } else { ?>
<span class="text-body-secondary">Not scheduled</span>
<?php } ?>
<div class="small text-body-secondary">
<?= escapeHtml(SERVICE_REVIEW_INTERVALS[intval($service['service_review_interval'])] ?? '') ?><?= $service['service_reviewed_at'] ? ' · last ' . escapeHtml(date('M j, Y', strtotime($service['service_reviewed_at']))) : ' · never reviewed' ?>
</div>
</dd>
<?php if ($urls) { ?>
<dt>Opens at</dt>
<dd class="min-w-0">
<?php foreach ($urls as $url) { ?>
<div class="text-truncate"><a href="<?= escapeHtml($url['url']) ?>" target="_blank" rel="noopener noreferrer" title="<?= escapeHtml($url['url']) ?>"><i class="fas fa-fw <?= $url['icon'] ?> text-secondary me-1"></i><?= escapeHtml($url['label']) ?></a></div>
<?php } ?>
</dd>
<?php } ?>
<?php if ($networks || $sites) { ?>
<dt>Where</dt>
<dd>
<?php if ($sites) { ?><div><i class="fas fa-fw fa-map-marker-alt text-secondary me-1"></i><?= escapeHtml(implode(', ', $sites)) ?></div><?php } ?>
<?php if ($networks) { ?><div><i class="fas fa-fw fa-network-wired text-secondary me-1"></i><?= escapeHtml(implode(', ', $networks)) ?></div><?php } ?>
</dd>
<?php } ?>
<dt>Added</dt><dd title="<?= escapeHtml($service['service_created_at']) ?>"><?= timeAgo($service['service_created_at']) ?></dd>
<?php if ($service['service_updated_at']) { ?>
<dt>Updated</dt><dd title="<?= escapeHtml($service['service_updated_at']) ?>"><?= timeAgo($service['service_updated_at']) ?></dd>
<?php } ?>
</dl>
</div>
</div>
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title mb-0"><i class="fas fa-fw fa-history text-secondary me-2"></i>Backup and recovery</h3>
</div>
<div class="card-body">
<?php if (trim((string) $service['service_backup']) !== '') { ?>
<div class="itflow-service-text"><?= escapeHtml($service['service_backup']) ?></div>
<?php } else { ?>
<div class="small text-body-secondary">
How it is backed up and how it comes back is not written down.
<?php if ($can_edit) { ?><a class="ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/service/service_edit.php?id=<?= $service_id ?>">Add it</a><?php } ?>
</div>
<?php } ?>
</div>
</div>
<!-- Who to call - the vendors and the people at the client -->
<div class="card mb-3">
<div class="card-header d-flex align-items-center">
<h3 class="card-title mb-0 me-auto"><i class="fas fa-fw fa-phone text-secondary me-2"></i>Who to call</h3>
<?php if ($can_edit) { ?>
<div class="dropdown">
<button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"><i class="fas fa-link me-1"></i>Link</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>vendor"><i class="fa fa-fw fa-building text-secondary me-2"></i>Vendor</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>contact"><i class="fa fa-fw fa-user text-secondary me-2"></i>Person at the client</a>
</div>
</div>
<?php } ?>
</div>
<?php if ($vendors || $contacts) { ?>
<ul class="list-group list-group-flush itflow-service-callees">
<?php foreach ($vendors as $vendor) {
if ($vendor['archived_at']) {
echo '<li class="list-group-item p-0"><ul class="list-unstyled mb-0 itflow-links">' . $archived_row('vendor', $vendor) . '</ul></li>';
continue;
}
$vendor_id = intval($vendor['id']);
$details = $vendor_details[$vendor_id] ?? [];
$phone = contactPhoneLink($vendor['vendor_phone'], $vendor['vendor_phone_country_code'], $vendor['vendor_extension']);
$account = escapeHtml($details['vendor_account_number'] ?? '');
$pin = vendorSecretHtml($details['vendor_code'] ?? '');
$when = escapeHtml(implode(' · ', array_filter([$details['vendor_hours'] ?? '', $details['vendor_sla'] ?? '']))); ?>
<li class="list-group-item itflow-service-callee">
<div class="d-flex align-items-center gap-2 min-w-0">
<?= vendorLink($vendor_id, $vendor['name'], ['page' => true, 'client_id' => $client_id, 'class' => 'fw-semibold']) ?>
<span class="small text-body-secondary ms-1">Vendor</span>
<?php if ($can_edit) { ?>
<a class="itflow-link-remove ms-auto confirm-link" href="<?= escapeHtml($unlink_url('vendor', $vendor_id)) ?>" title="Unlink vendor" data-confirm-text="<?= escapeHtml($vendor['name']) ?> is no longer listed on this service."><i class="fas fa-unlink"></i></a>
<?php } ?>
</div>
<?php if ($vendor['vendor_description']) { ?><div class="small text-body-secondary text-truncate"><?= escapeHtml($vendor['vendor_description']) ?></div><?php } ?>
<div class="small d-flex flex-wrap column-gap-3 row-gap-1 mt-1">
<?php if ($phone) { ?><span><i class="fas fa-fw fa-phone text-secondary me-1"></i><?= $phone ?></span><?php } ?>
<?php if (!empty($details['vendor_email'])) { ?><span class="text-truncate"><i class="fas fa-fw fa-envelope text-secondary me-1"></i><a href="mailto:<?= escapeHtml($details['vendor_email']) ?>"><?= escapeHtml($details['vendor_email']) ?></a></span><?php } ?>
<?php if ($account) { ?><span title="Account number"><i class="fas fa-fw fa-fingerprint text-secondary me-1"></i><span class="font-monospace"><?= $account ?></span><button type="button" class="itflow-copy clipboardjs" title="Copy account number" data-clipboard-text="<?= $account ?>"><i class="far fa-copy"></i></button></span><?php } ?>
<?php if ($pin) { ?><span><span class="text-body-secondary">PIN</span> <?= $pin ?></span><?php } ?>
<?php if ($when) { ?><span class="text-body-secondary"><i class="fas fa-fw fa-clock me-1"></i><?= $when ?></span><?php } ?>
</div>
</li>
<?php } ?>
<?php foreach ($contacts as $contact) {
if ($contact['archived_at']) {
echo '<li class="list-group-item p-0"><ul class="list-unstyled mb-0 itflow-links">' . $archived_row('contact', $contact) . '</ul></li>';
continue;
}
$contact_id = intval($contact['id']);
$details = $contact_details[$contact_id] ?? [];
$phone = contactPhoneLink($details['contact_phone'] ?? '', $details['contact_phone_country_code'] ?? '', $details['contact_extension'] ?? '');
$mobile = contactPhoneLink($details['contact_mobile'] ?? '', $details['contact_mobile_country_code'] ?? ''); ?>
<li class="list-group-item itflow-service-callee">
<div class="d-flex align-items-center gap-2 min-w-0">
<?= contactLink($client_id, $contact_id, $contact['name'], $contact['contact_photo'], ['class' => 'fw-semibold']) ?>
<span class="small text-body-secondary ms-1 text-truncate"><?= escapeHtml($contact['contact_title'] ?: 'At the client') ?></span>
<?php if ($can_edit) { ?>
<a class="itflow-link-remove ms-auto confirm-link" href="<?= escapeHtml($unlink_url('contact', $contact_id)) ?>" title="Unlink person" data-confirm-text="<?= escapeHtml($contact['name']) ?> is no longer listed on this service."><i class="fas fa-unlink"></i></a>
<?php } ?>
</div>
<div class="small d-flex flex-wrap column-gap-3 row-gap-1 mt-1">
<?php if ($phone) { ?><span><i class="fas fa-fw fa-phone text-secondary me-1"></i><?= $phone ?></span><?php } ?>
<?php if ($mobile) { ?><span><i class="fas fa-fw fa-mobile-alt text-secondary me-1"></i><?= $mobile ?></span><?php } ?>
<?php if (!empty($details['contact_email'])) { ?><span class="text-truncate"><i class="fas fa-fw fa-envelope text-secondary me-1"></i><a href="mailto:<?= escapeHtml($details['contact_email']) ?>"><?= escapeHtml($details['contact_email']) ?></a></span><?php } ?>
</div>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="card-body small text-body-secondary">No vendor or person linked - who gets the call when it breaks?</div>
<?php } ?>
</div>
<div class="card mb-3">
<div class="card-header">
<h3 class="card-title mb-0"><i class="fas fa-fw fa-pen text-secondary me-2"></i>Notes</h3>
</div>
<textarea class="form-control border-0 rounded-0 rounded-bottom itflow-service-notes" rows="7" placeholder="How it fits together, the quirks, what to check first when it breaks - saves when you click away"
data-service-id="<?= $service_id ?>" data-csrf="<?= escapeHtml($_SESSION['csrf_token']) ?>" <?= $can_edit ? '' : 'readonly' ?>><?= escapeHtml($service['service_notes']) ?></textarea>
</div>
</div>
<!-- Everything it depends on -->
<div class="col-xl-8 col-lg-7">
<div class="card mb-3 itflow-asset-related">
<div class="card-header py-2">
<ul class="nav nav-pills itflow-asset-pills" role="tablist">
<?php foreach ($service_tabs as $tab_key => $tab) { ?>
<li class="nav-item" role="presentation">
<button class="nav-link text-nowrap <?= $tab['count'] ? '' : 'is-empty' ?>" id="service-tab-<?= $tab_key ?>" data-bs-toggle="pill" data-bs-target="#service-pane-<?= $tab_key ?>" data-service-tab="<?= $tab_key ?>" type="button" role="tab">
<?= $tab['label'] ?>
<span class="badge rounded-pill ms-1 <?= !empty($tab['alarm']) ? 'text-bg-primary' : '' ?>" <?= !empty($tab['alarm']) ? 'title="' . $tab['alarm'] . ' open"' : '' ?>><?= !empty($tab['alarm']) ? $tab['alarm'] . ' open' : $tab['count'] ?></span>
</button>
</li>
<?php } ?>
</ul>
</div>
<div class="tab-content">
<!-- What it runs on -->
<div class="tab-pane fade" id="service-pane-assets" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">The servers, firewalls, NAS and other kit it runs on - when one is down, so is the service.</span>
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="<?= $link_url ?>asset">
<i class="fas fa-link me-2"></i>Link
</button>
<?php } ?>
</div>
<?php if ($assets) { ?>
<div class="table-responsive">
<table class="table table-hover align-middle mb-0">
<thead class="text-nowrap table-light">
<tr><th>Asset</th><th>Address</th><th>Site</th><th>Status</th><th></th></tr>
</thead>
<tbody>
<?php foreach ($assets as $asset) {
$asset_id = intval($asset['asset_id']);
$asset_archived = !empty($asset['asset_archived_at']);
$warranty = assetWarranty($asset['asset_warranty_expire']); ?>
<tr class="<?= $asset_archived ? 'text-body-secondary' : '' ?>">
<td>
<div class="d-flex align-items-center gap-2">
<span class="itflow-asset-icon itflow-asset-icon-sm itflow-asset-tone-<?= assetTypeTone($asset['asset_type']) ?>" aria-hidden="true"><i class="fas fa-fw fa-<?= getAssetIcon($asset['asset_type']) ?>"></i></span>
<div class="min-w-0">
<a class="fw-semibold ajax-modal <?= $asset_archived ? 'text-decoration-line-through text-body-secondary' : '' ?>" href="#" data-modal-size="lg" data-modal-url="modals/asset/asset.php?id=<?= $asset_id ?>"><?= escapeHtml($asset['asset_name']) ?></a>
<div class="small text-body-secondary text-truncate"><?= escapeHtml(implode(' · ', array_filter([$asset['asset_type'], trim($asset['asset_make'] . ' ' . $asset['asset_model'])]))) ?></div>
</div>
</div>
</td>
<td class="small text-nowrap">
<?php if ($asset['interface_ip']) { ?>
<span class="font-monospace"><?= escapeHtml($asset['interface_ip']) ?></span><button type="button" class="itflow-copy clipboardjs" title="Copy address" data-clipboard-text="<?= escapeHtml($asset['interface_ip']) ?>"><i class="far fa-copy"></i></button>
<?php } ?>
<?php if ($asset['network_name']) { ?><div class="text-body-secondary"><?= escapeHtml($asset['network_name']) ?><?= $asset['network_vlan'] ? ' · VLAN ' . escapeHtml($asset['network_vlan']) : '' ?></div><?php } ?>
<?php if (!$asset['interface_ip'] && !$asset['network_name']) { ?><span class="text-body-secondary">-</span><?php } ?>
</td>
<td class="small"><?= $asset['location_name'] ? escapeHtml($asset['location_name']) : '<span class="text-body-secondary">-</span>' ?></td>
<td class="small">
<?php if ($asset_archived) { ?>
<span class="badge rounded-pill text-bg-secondary fw-normal">Archived</span>
<?php } else { ?>
<?= assetStatusPill($asset['asset_status']) ?>
<?php if ($warranty && $warranty['tone'] !== 'success') { ?>
<div class="text-<?= $warranty['tone'] ?>-emphasis mt-1 text-nowrap" title="Warranty"><i class="fas fa-shield-alt me-1"></i><?= escapeHtml($warranty['short']) ?></div>
<?php } ?>
<?php } ?>
</td>
<td class="text-end text-nowrap">
<?php if ($can_edit) { ?>
<a href="<?= escapeHtml($unlink_url('asset', $asset_id)) ?>" class="btn btn-sm btn-light confirm-link" title="Unlink" data-confirm-text="<?= escapeHtml($asset['asset_name']) ?> is no longer listed as something it runs on."><i class="fas fa-fw fa-unlink"></i></a>
<?php } ?>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
<?php } else { ?>
<div class="itflow-asset-empty">
<div>Nothing linked as what it runs on.</div>
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-sm btn-outline-primary mt-3 ajax-modal" data-modal-url="<?= $link_url ?>asset"><i class="fas fa-link me-2"></i>Link assets</button>
<?php } ?>
</div>
<?php } ?>
</div>
<?php if ($can_credentials) { ?>
<!-- Logins: its own, then the ones on its assets -->
<div class="tab-pane fade" id="service-pane-logins" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Admin consoles, portals and service accounts. Passwords are fetched only when you ask.</span>
<?php if ($can_link_credentials) { ?>
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="<?= $link_url ?>credential">
<i class="fas fa-link me-2"></i>Link
</button>
<?php } ?>
</div>
<?php if ($credentials) { ?>
<?= credentialTableHtml($credentials, [
'for' => true,
'unlink' => function ($row) use ($unlink_url, $can_link_credentials) {
return $can_link_credentials ? $unlink_url('credential', $row['credential_id']) : '';
},
]) ?>
<?php } ?>
<?php if ($archived_credentials) { ?>
<ul class="list-unstyled mb-0 itflow-links border-top">
<?php foreach ($archived_credentials as $row) { echo $archived_row('credential', $row); } ?>
</ul>
<?php } ?>
<?php if ($asset_credentials) { ?>
<div class="itflow-license-section"><i class="fas fa-fw fa-desktop me-1"></i>On the assets it runs on <span class="badge rounded-pill ms-1"><?= count($asset_credentials) ?></span></div>
<?= credentialTableHtml($asset_credentials, ['for' => true]) ?>
<?php } ?>
<?php if (!$credentials && !$asset_credentials && !$archived_credentials) { ?>
<div class="itflow-asset-empty">No logins linked, and none on the assets it runs on.</div>
<?php } ?>
</div>
<?php } ?>
<!-- Domains and certificates -->
<div class="tab-pane fade" id="service-pane-web" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">The domains its mail or web run on and the certificates that keep it on https - expiring ones show at the top of the page.</span>
<?php if ($can_edit) { ?>
<div class="dropdown">
<button type="button" class="btn btn-sm btn-outline-secondary dropdown-toggle" data-bs-toggle="dropdown"><i class="fas fa-link me-2"></i>Link</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>domain"><i class="fa fa-fw fa-globe text-secondary me-2"></i>Domain</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $link_url ?>certificate"><i class="fa fa-fw fa-lock text-secondary me-2"></i>Certificate</a>
</div>
</div>
<?php } ?>
</div>
<?php foreach (['domain' => [$domains, 'Domains', 'fa-globe'], 'certificate' => [$certificates, 'Certificates', 'fa-lock']] as $to => [$linked, $label, $icon]) {
if (!$linked) {
continue;
} ?>
<div class="itflow-license-section"><i class="fas fa-fw <?= $icon ?> me-1"></i><?= $label ?> <span class="badge rounded-pill ms-1"><?= count($linked) ?></span></div>
<ul class="list-unstyled mb-0 itflow-links itflow-license-links">
<?php foreach ($linked as $linked_row) {
if ($linked_row['archived_at']) {
echo $archived_row($to, $linked_row);
continue;
} ?>
<li class="itflow-link-row">
<?= linkRowHtml($to, $linked_row, $client_id) ?>
<?php if ($can_edit) { ?>
<a class="itflow-link-remove" href="<?= escapeHtml($unlink_url($to, $linked_row['id'])) ?>" title="Unlink <?= $to ?>"><i class="fas fa-unlink"></i></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } ?>
<?php if (!$domains && !$certificates) { ?>
<div class="itflow-asset-empty">No domains or certificates linked.</div>
<?php } ?>
</div>
<!-- Documents -->
<div class="tab-pane fade" id="service-pane-documents" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Runbooks, diagrams, the restore procedure, the vendor contract.</span>
<?php if ($can_edit) { ?>
<div class="d-flex gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="<?= $link_url ?>document">
<i class="fas fa-link me-2"></i>Link
</button>
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="xl" data-modal-url="modals/document/document_add.php?client_id=<?= $client_id ?>&service_id=<?= $service_id ?>">
<i class="fas fa-plus me-2"></i>New Document
</button>
</div>
<?php } ?>
</div>
<?php if ($documents) { ?>
<ul class="list-unstyled mb-0 itflow-links itflow-license-links">
<?php foreach ($documents as $linked_row) {
if ($linked_row['archived_at']) {
echo $archived_row('document', $linked_row);
continue;
} ?>
<li class="itflow-link-row">
<?= linkRowHtml('document', $linked_row, $client_id) ?>
<?php if ($can_edit) { ?>
<a class="itflow-link-remove" href="<?= escapeHtml($unlink_url('document', $linked_row['id'])) ?>" title="Unlink document"><i class="fas fa-unlink"></i></a>
<?php } ?>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="itflow-asset-empty">No documents linked.</div>
<?php } ?>
</div>
<!-- Tickets about it, or about what it runs on -->
<div class="tab-pane fade" id="service-pane-tickets" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Raised about it, or about what it runs on - open ones first.</span>
<?php if ($can_edit) { ?>
<div class="d-flex gap-2">
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="modals/service/service_link_ticket.php?id=<?= $service_id ?>">
<i class="fas fa-link me-2"></i>Link
</button>
<button type="button" class="btn btn-sm btn-primary ajax-modal" data-modal-size="lg" data-modal-url="<?= escapeHtml($report_url) ?>">
<i class="fas fa-plus me-2"></i>Report a problem
</button>
</div>
<?php } ?>
</div>
<?php if ($tickets) { ?>
<?= ticketTableHtml($tickets) ?>
<?php
$linked_tickets = array_values(array_filter($tickets, function ($row) use ($linked_ticket_ids) { return isset($linked_ticket_ids[intval($row['ticket_id'])]); }));
if ($linked_tickets && $can_edit) { ?>
<div class="small text-body-secondary px-3 py-2 border-top d-flex flex-wrap align-items-center gap-2">
<span>Raised about the service:</span>
<?php foreach ($linked_tickets as $row) { ?>
<span class="itflow-contact-chip"><?= escapeHtml(ticketReference($row)) ?>
<a class="text-body-secondary ms-1" href="post.php?unlink_service_ticket=<?= intval($row['ticket_id']) ?>&service_id=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" title="Not about this service"><i class="fas fa-times"></i></a>
</span>
<?php } ?>
</div>
<?php } ?>
<?php } else { ?>
<div class="itflow-asset-empty">No tickets about it or what it runs on.</div>
<?php } ?>
</div>
<!-- History, from the audit log -->
<div class="tab-pane fade" id="service-pane-history" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">Reviews, links, edits - newest first.</span>
</div>
<?php if ($history) {
$history_icons = ['Create' => 'fa-plus', 'Edit' => 'fa-edit', 'Review' => 'fa-clipboard-check', 'Link' => 'fa-link', 'Unlink' => 'fa-unlink',
'Archive' => 'fa-archive', 'Restore' => 'fa-redo', 'Export' => 'fa-download']; ?>
<ul class="list-group list-group-flush">
<?php foreach ($history as $entry) { ?>
<li class="list-group-item d-flex gap-3 py-2">
<span class="itflow-asset-icon itflow-asset-icon-sm itflow-asset-tone-<?= $entry['log_action'] === 'Review' ? 'network' : 'other' ?>" title="<?= escapeHtml($entry['log_action']) ?>"><i class="fas fa-fw <?= $history_icons[$entry['log_action']] ?? 'fa-circle' ?>"></i></span>
<div class="flex-grow-1 min-w-0">
<div class="text-break"><?= escapeHtml($entry['log_description']) ?></div>
<div class="small text-body-secondary"><?= escapeHtml($entry['user_name'] ?: 'System') ?> &middot; <span title="<?= escapeHtml($entry['log_created_at']) ?>"><?= timeAgo($entry['log_created_at']) ?></span></div>
</div>
</li>
<?php } ?>
</ul>
<?php } else { ?>
<div class="itflow-asset-empty">Nothing logged yet.</div>
<?php } ?>
</div>
</div>
</div>
</div>
</div>
<script>
// Notes save when you click away
document.querySelectorAll('.itflow-service-notes').forEach(function (notes) {
var saved = notes.value;
notes.addEventListener('blur', function () {
if (notes.readOnly || notes.value === saved) {
return;
}
saved = notes.value;
itflowPost('post.php', {
service_set_notes: 'TRUE',
ajax: 1,
csrf_token: notes.dataset.csrf,
service_id: notes.dataset.serviceId,
notes: notes.value
});
});
});
/*
* Which tab is open: the URL hash wins (#tickets), then the tab last
* used on any service, then the first with something in it (history
* aside - a new service has that, and wants linking first).
* Choosing a tab updates the hash without a history entry, so the
* redirect back from a save lands on the same tab. Bootstrap loads
* in the footer, so this waits for it.
*/
document.addEventListener('DOMContentLoaded', function () {
var key = 'itflow.serviceTab';
var tabs = document.querySelectorAll('[data-service-tab]');
if (!tabs.length) {
return;
}
function byName(name) {
return document.querySelector('[data-service-tab="' + name + '"]');
}
// A remembered tab that is empty here gives way to the first one with something in it
var remembered = '';
try { remembered = localStorage.getItem(key) || ''; } catch (e) {}
var kept = byName(remembered);
var start = byName(location.hash.replace('#', ''))
|| (kept && !kept.classList.contains('is-empty') ? kept : null)
|| document.querySelector('[data-service-tab]:not(.is-empty):not([data-service-tab="history"])') || tabs[0];
bootstrap.Tab.getOrCreateInstance(start).show();
tabs.forEach(function (tab) {
tab.addEventListener('shown.bs.tab', function () {
var name = tab.getAttribute('data-service-tab');
try { localStorage.setItem(key, name); } catch (e) {}
history.replaceState(null, '', location.pathname + location.search + '#' + name);
});
});
});
</script>
<?php
}
require_once "../includes/footer.php";

View File

@@ -1,7 +1,18 @@
<?php
// Default Column Sortby Filter
$sort = "service_name";
/*
* Services - one client's, or every service the agent can see from All
* Client Docs. What a client runs on, most important first: each row says
* what it depends on (assets, logins, domains, certificates, people,
* vendors, documents), whether any of that needs attention, any open
* tickets about it, and when it is next due for review - with a red or
* amber edge when something it depends on is expired, out of action or
* archived. The pills along the top are the ones to look at: needs
* attention, review due, high importance.
*/
// Default Column Sortby Filter - most important first
$sort = "service_importance";
$order = "ASC";
// If client_id is in URI then show client Side Bar and client header
@@ -11,212 +22,402 @@ if (isset($_GET['client_id'])) {
$client_url = "client_id=$client_id&";
} else {
require_once "includes/inc_client_overview_all.php";
$client_query = '';
$client_query = 'AND clients.client_archived_at IS NULL';
$client_url = '';
}
// Perms
enforceUserPermission('module_support');
if (!$client_url) {
// Client Filter
if (isset($_GET['client']) & !empty($_GET['client'])) {
$client_query = 'AND (service_client_id = ' . intval($_GET['client']) . ')';
$client = intval($_GET['client']);
} else {
// Default - any
$client_query = '';
$client = '';
}
// filter_header.php fills in canned_date=custom when no range was asked for - not a filter here, so not carried into links
if (($_GET['canned_date'] ?? '') === 'custom' && empty($_GET['dtf'])) {
unset($_GET['canned_date']);
}
// Overview SQL query
$sql = mysqli_query(
$mysqli,
"SELECT SQL_CALC_FOUND_ROWS client_id, client_name, service_backup, service_category, service_created_at,
service_description, service_id, service_importance, service_name, service_notes,
service_review_due, service_updated_at FROM services
LEFT JOIN clients ON client_id = service_client_id
WHERE (service_name LIKE '%$q%' OR service_description LIKE '%$q%' OR service_category LIKE '%$q%' OR client_name LIKE '%$q%')
AND client_archived_at IS NULL
" . clientScopeSql('service_client_id') . "
$client_query
ORDER BY $sort $order LIMIT $record_from, $record_to"
);
$can_edit = serviceCan(2);
$can_delete = serviceCan(3) && !empty($config_destructive_deletes_enable);
// Client (all clients)
$client_filter = 0;
if (!$client_url && !empty($_GET['client'])) {
$client_filter = intval($_GET['client']);
$client_query .= " AND service_client_id = $client_filter";
}
// Importance and category
$importance_filter = in_array($_GET['importance'] ?? '', SERVICE_IMPORTANCE, true) ? $_GET['importance'] : '';
$importance_query = $importance_filter ? "AND service_importance = '$importance_filter'" : '';
$category_filter = trim((string) ($_GET['category'] ?? ''));
$category_query = $category_filter !== '' ? "AND service_category = '" . escapeSql($category_filter) . "'" : '';
$filters = "(service_name LIKE '%$q%' OR service_description LIKE '%$q%' OR service_category LIKE '%$q%' OR service_notes LIKE '%$q%' OR client_name LIKE '%$q%')
" . clientScopeSql('service_client_id') . " $client_query $importance_query $category_query";
$joins = "LEFT JOIN clients ON client_id = service_client_id";
// The views - counted over what the filters leave
$shows = serviceViews();
$show = isset($shows[$_GET['show'] ?? '']) ? ($_GET['show'] ?? '') : '';
$show_query = $shows[$show]['where'] ? 'AND ' . $shows[$show]['where'] : '';
// Only these sort - an unknown column would take the page down
$sortable_columns = [
'service_importance' => "FIELD(service_importance, 'High', 'Medium', 'Low') $order, service_name ASC",
'service_name' => "service_name $order",
'service_category' => "service_category = '' $order, service_category $order, service_name ASC",
'client_name' => "client_name $order, service_name ASC",
'service_review_due' => "service_review_due IS NULL, service_review_due $order, service_name ASC",
'service_updated_at' => "COALESCE(service_updated_at, service_created_at) $order",
];
if (!isset($sortable_columns[$sort])) {
$sort = 'service_importance';
}
$sql = mysqli_query($mysqli, "SELECT SQL_CALC_FOUND_ROWS services.*, client_name FROM services $joins
WHERE $filters $show_query
ORDER BY services.service_favorite DESC, {$sortable_columns[$sort]}, service_id DESC
LIMIT $record_from, $record_to");
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
$services = [];
while ($row = mysqli_fetch_assoc($sql)) {
$services[intval($row['service_id'])] = $row;
}
$counts = serviceCounts(array_keys($services));
$issues = serviceIssues(array_keys($services));
// How many of each, for the pills
$count_sql = [];
foreach ($shows as $key => $s) {
$count_sql[] = $s['where'] === '' ? 'COUNT(*)' : "COALESCE(SUM({$s['where']}), 0)";
}
$row = mysqli_fetch_row(mysqli_query($mysqli, "SELECT " . implode(', ', $count_sql) . " FROM services $joins WHERE $filters"));
$view_counts = [];
foreach (array_keys($shows) as $i => $key) {
$view_counts[$key] = intval($row[$i]);
}
// Categories in use in this scope, for the filter
$categories = [];
$sql_categories = mysqli_query($mysqli, "SELECT DISTINCT service_category FROM services $joins
WHERE service_category <> '' " . clientScopeSql('service_client_id') . ($client_url ? " AND service_client_id = $client_id" : '') . " ORDER BY service_category");
while ($row = mysqli_fetch_row($sql_categories)) {
$categories[] = $row[0];
}
$filter_url = function ($changes) {
$params = array_merge($_GET, $changes);
unset($params['page']);
return '?' . http_build_query(array_filter($params, function ($v) { return $v !== '' && $v !== null; }));
};
$sort_link = function ($column, $label) use ($url_query_strings_sort, $sort, $disp, $order_icon) {
return '<a class="text-reset text-decoration-none" href="?' . escapeHtml($url_query_strings_sort) . '&amp;sort=' . $column . '&amp;order=' . $disp . '">'
. $label . ($sort === $column ? " $order_icon" : '') . '</a>';
};
$link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['fa-key', 'login', 'logins'], 'domain' => ['fa-globe', 'domain', 'domains'],
'certificate' => ['fa-lock', 'certificate', 'certificates'], 'contact' => ['fa-user', 'person', 'people'], 'vendor' => ['fa-building', 'vendor', 'vendors'],
'document' => ['fa-file-alt', 'document', 'documents']];
?>
<div class="card">
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fa fa-fw fa-stream me-2"></i>Services</h3>
<div class="card-tools">
<?php if (lookupUserPermission("module_support") >= 2) { ?>
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/service/service_add.php?<?= $client_url ?>"><i class="fas fa-plus me-2"></i>New Service</button>
<div class="card">
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-stream me-2"></i>Services</h3>
<div class="card-tools">
<div class="btn-group">
<?php if ($can_edit) { ?>
<button type="button" class="btn btn-primary ajax-modal" data-modal-size="lg" data-modal-url="modals/service/service_add.php?<?= $client_url ?>">
<i class="fas fa-plus"></i><span class="d-none d-lg-inline ms-2">New Service</span>
</button>
<?php } ?>
<button type="button" class="btn btn-primary dropdown-toggle <?= $can_edit ? 'dropdown-toggle-split' : '' ?>" data-bs-toggle="dropdown"><?= $can_edit ? '' : '<i class="fas fa-ellipsis-h"></i>' ?></button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item text-dark ajax-modal" href="#" data-modal-url="<?= buildExportModalUrl('modals/service/service_export.php', ['client_id', 'client', 'show', 'importance', 'category', 'q']) ?>">
<i class="fa fa-fw fa-download me-2"></i>Export
</a>
</div>
</div>
</div>
</div>
<div class="card-header py-3">
<form autocomplete="off">
<?php if ($client_url) { ?>
<div class="card-header py-3">
<form autocomplete="off">
<?php if ($client_url) { ?>
<input type="hidden" name="client_id" value="<?= $client_id ?>">
<?php } ?>
<div class="row g-2 align-items-center">
<div class="col-md-4">
<div class="input-group">
<input type="search" class="form-control" name="q" value="<?php if (isset($q)) { echo stripslashes(escapeHtml($q)); } ?>" placeholder="Search Services">
<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>
<?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 services ON service_client_id = client_id
WHERE client_archived_at IS NULL
" . 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>
<?php } ?>
<div class="col-md-6">
<div class="float-end">
</div>
<?php } ?>
<input type="hidden" name="show" value="<?= escapeHtml($show) ?>">
<div class="row g-2 align-items-center">
<div class="<?= $client_url ? 'col-lg-4' : 'col-lg-3' ?> 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 services..." title="Name, description, category, notes, client">
<button class="btn btn-dark" title="Search"><i class="fa fa-search"></i></button>
</div>
</div>
</form>
</div>
<div class="col-lg-2 col-md-6">
<select class="form-select select2" name="category" onchange="this.form.submit()">
<option value="">- Any category -</option>
<?php foreach ($categories as $category) { ?>
<option value="<?= escapeHtml($category) ?>" <?= $category_filter === $category ? 'selected' : '' ?> data-icon="fas <?= serviceStyle($category)['icon'] ?>"><?= escapeHtml($category) ?></option>
<?php } ?>
</select>
</div>
<div class="col-lg-2 col-md-6">
<select class="form-select select2" name="importance" onchange="this.form.submit()">
<option value="">- Any importance -</option>
<?php foreach (SERVICE_IMPORTANCE as $importance) { ?>
<option value="<?= $importance ?>" <?= $importance_filter === $importance ? 'selected' : '' ?>><?= $importance ?></option>
<?php } ?>
</select>
</div>
<?php if (!$client_url) { ?>
<div class="col-lg-2 col-md-6">
<select class="form-select select2" name="client" onchange="this.form.submit()">
<option value="">- All Clients -</option>
<?php
$sql_clients_filter = mysqli_query($mysqli, "SELECT client_id, client_name, client_abbreviation FROM clients
WHERE client_archived_at IS NULL AND (EXISTS (SELECT 1 FROM services WHERE service_client_id = client_id) OR client_id = $client_filter)
" . 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 <?= $client_filter === $client_id_filter ? '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="<?= $client_url ? 'col-lg-4' : 'col-lg-3' ?> col-md-6">
<div class="d-flex justify-content-end gap-2">
<?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 dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/service/service_bulk_edit.php" data-bulk="true">
<i class="fas fa-fw fa-edit me-2"></i>Importance, category, review
</a>
<button class="dropdown-item confirm-link" type="submit" form="bulkActions" name="bulk_review_services"
data-confirm-text="Each one is marked reviewed today, and its next review set from its schedule.">
<i class="fas fa-fw fa-clipboard-check me-2"></i>Mark reviewed
</button>
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_favorite_services">
<i class="fas fa-fw fa-star text-warning me-2"></i>Star
</button>
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_unfavorite_services">
<i class="far fa-fw fa-star me-2"></i>Unstar
</button>
<div class="dropdown-divider"></div>
<?php if ($show === 'archived') { ?>
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_services">
<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_services"
data-confirm-text="The services go for good. What they linked to - assets, logins, documents - stays.">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</button>
<?php } ?>
<?php } else { ?>
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_archive_services"
data-confirm-text="They move to Archived, off the lists and counts, until restored.">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</button>
<?php } ?>
</div>
</div>
<?php } ?>
</div>
</div>
</div>
</form>
<!-- The views - counted over what the filters above leave -->
<nav class="nav nav-pills itflow-asset-tabs mt-2 flex-nowrap overflow-auto">
<?php foreach ($shows as $key => $s) {
$alarm = $view_counts[$key] && !empty($s['alarm']) && $show !== $key ? $s['alarm'] : ''; ?>
<?php if ($key === 'archived') { ?><span class="vr mx-1 my-1"></span><?php } ?>
<a class="nav-link text-nowrap <?= $show === $key ? 'active' : '' ?>" href="<?= escapeHtml($filter_url(['show' => $key, 'sort' => null, 'order' => null])) ?>"<?= !empty($s['title']) ? ' title="' . escapeHtml($s['title']) . '"' : '' ?>>
<?php if (!empty($s['icon'])) { ?><i class="fas fa-fw <?= $s['icon'] ?> me-1"></i><?php } ?><?= $s['label'] ?>
<span class="badge rounded-pill ms-1 <?= $alarm ? "text-bg-$alarm" : '' ?>"><?= $view_counts[$key] ?></span>
</a>
<?php } ?>
</nav>
</div>
<form id="bulkActions" action="post.php" method="post">
<input type="hidden" name="csrf_token" value="<?= $_SESSION['csrf_token'] ?>">
<div class="table-responsive">
<table class="table table-striped table-borderless table-hover mb-0">
<thead class="<?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
<table class="table table-hover align-middle mb-0 itflow-asset-table itflow-ticket-list itflow-service-list">
<thead class="<?php if (!$services) { echo "d-none"; } ?> text-nowrap table-light">
<tr>
<th class="ps-3">
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=service_name&order=<?= $disp ?>">
Name <?php if ($sort == 'service_name') { echo $order_icon; } ?>
</a>
</th>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=service_category&order=<?= $disp ?>">
Category <?php if ($sort == 'service_category') { echo $order_icon; } ?>
</a>
</th>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=service_importance&order=<?= $disp ?>">
Importance <?php if ($sort == 'service_importance') { echo $order_icon; } ?>
</a>
</th>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=service_updated_at&order=<?= $disp ?>">
Updated <?php if ($sort == 'service_updated_at') { echo $order_icon; } ?>
</a>
</th>
<?php if (!$client_url) { ?>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=client_name&order=<?= $disp ?>">
Client <?php if ($sort == 'client_name') { echo $order_icon; } ?>
</a>
</th>
<?php if ($can_edit) { ?>
<th class="checkbox-column border-end">
<div class="form-check">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" onclick="checkAll(this)" title="Select all on this page">
</div>
</th>
<?php } ?>
<th class="text-center">Action</th>
<th><?= $sort_link('service_name', 'Service') ?></th>
<?php if (!$client_url) { ?><th><?= $sort_link('client_name', 'Client') ?></th><?php } ?>
<th><?= $sort_link('service_importance', 'Importance') ?></th>
<th class="d-none d-xxl-table-cell">Depends on</th>
<th>Attention</th>
<th><?= $sort_link('service_review_due', 'Review') ?></th>
<th></th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($sql)) {
$client_id = intval($row['client_id']);
$client_name = escapeHtml($row['client_name']);
$service_id = intval($row['service_id']);
$service_name = escapeHtml($row['service_name']);
$service_description = escapeHtml($row['service_description']);
$service_category = escapeHtml($row['service_category']);
$service_importance = escapeHtml($row['service_importance']);
$service_backup = escapeHtml($row['service_backup']);
$service_notes = escapeHtml($row['service_notes']);
$service_created_at = escapeHtml($row['service_created_at']);
$service_updated_at = escapeHtml($row['service_updated_at']);
$service_review_due = escapeHtml($row['service_review_due']);
<?php foreach ($services as $service_id => $row) {
$row_client_id = intval($row['service_client_id']);
$c = $counts[$service_id];
$row_issues = $issues[$service_id];
$review = serviceReview($row);
$is_archived = !empty($row['service_archived_at']);
$is_favorite = intval($row['service_favorite']) === 1;
$has_danger = in_array('danger', array_column($row_issues, 'tone'), true);
$edge = $is_archived ? '' : ($has_danger ? 'danger' : ($row_issues || $review['state'] === 'overdue' ? 'warning' : ''));
$url = escapeHtml(serviceUrl($service_id, $row_client_id));
$quick_url = "modals/service/service.php?id=$service_id";
$name = escapeHtml($row['service_name']);
$detail = implode(' · ', array_filter([$row['service_category'], $row['service_description']]));
$chips = '';
foreach ($link_icons as $type => [$icon, $one, $many]) {
if ($c[$type]) {
$chips .= '<span class="itflow-contact-chip" title="' . $c[$type] . ' ' . ($c[$type] === 1 ? $one : $many) . '"><i class="fas ' . $icon . '"></i>' . $c[$type] . '</span>';
}
}
?>
<tr>
<!-- Name/Category/Updated/Importance from DB -->
<td class="ps-3">
<a class="text-dark ajax-modal" href="#"
data-modal-size="xl"
data-modal-url="modals/service/service.php?id=<?= $service_id ?>">
<div class="d-flex">
<i class="fa fa-fw fa-2x fa-stream me-3"></i>
<div class="flex-grow-1">
<div><?= $service_name ?></div>
<div><small class="text-secondary"><?= $service_description ?></small></div>
</div>
<tr class="itflow-ticket-row <?= $edge ? "is-$edge" : '' ?> <?= $is_archived ? 'is-done' : '' ?>">
<?php if ($can_edit) { ?>
<td class="checkbox-column bg-light border-end">
<div class="form-check">
<input class="form-check-input bulk-select" type="checkbox" name="service_ids[]" value="<?= $service_id ?>" aria-label="Select <?= $name ?>">
</div>
</a>
</td>
<td><?= $service_category ?></td>
<td><?= $service_importance ?></td>
<td><?= $service_updated_at ?></td>
<?php if (!$client_url) { ?>
<td><a href="services.php?client_id=<?= $client_id ?>"><?= $client_name ?></a></td>
</td>
<?php } ?>
<!-- Action -->
<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>
<!-- What it is -->
<td class="itflow-ticket-main itflow-service-main">
<div class="d-flex align-items-center gap-3">
<?= serviceTile($row['service_category']) ?>
<div class="min-w-0">
<a class="<?= $is_archived ? 'text-body-secondary' : 'fw-semibold text-body' ?>" href="<?= $url ?>"><?= $name ?></a>
<?php if ($is_favorite) { ?><i class="fas fa-star text-warning small ms-1" title="Starred"></i><?php } ?>
<?php if ($is_archived) { ?><span class="badge rounded-pill text-bg-secondary fw-normal ms-1">Archived</span><?php } ?>
<?php if ($detail !== '') { ?>
<div class="small text-body-secondary text-truncate itflow-service-desc" title="<?= escapeHtml($detail) ?>"><?= escapeHtml($detail) ?></div>
<?php } ?>
<!-- Narrower screens drop the Depends on column - the chips come along -->
<?php if ($chips) { ?><div class="d-none d-md-flex d-xxl-none flex-wrap gap-1 mt-1"><?= $chips ?></div><?php } ?>
<!-- On a phone the other columns are off to the side - the essentials come along -->
<div class="d-md-none d-flex flex-wrap align-items-center gap-2 mt-1 small">
<?= serviceImportancePill($row['service_importance']) ?>
<?php if ($row_issues) { ?><span class="text-<?= $has_danger ? 'danger' : 'warning' ?>-emphasis"><i class="fas fa-exclamation-triangle me-1"></i><?= count($row_issues) ?> to look at</span><?php } ?>
<?php if (!$client_url) { ?><span class="text-body-secondary text-truncate"><?= escapeHtml($row['client_name']) ?></span><?php } ?>
</div>
</div>
</div>
</td>
<?php if (!$client_url) { ?>
<td class="itflow-ticket-who-cell"><a class="d-block text-truncate text-body fw-semibold small" href="services.php?client_id=<?= $row_client_id ?>"><?= escapeHtml($row['client_name']) ?></a></td>
<?php } ?>
<td class="text-nowrap">
<?= $can_edit && !$is_archived ? quickPick('service_importance', $service_id, $row['service_importance'], serviceImportancePill($row['service_importance'])) : serviceImportancePill($row['service_importance']) ?>
</td>
<td class="itflow-service-chips-cell d-none d-xxl-table-cell">
<?php if ($chips) { ?>
<a class="d-flex flex-wrap gap-1 text-decoration-none itflow-service-chips" href="<?= $url ?>"><?= $chips ?></a>
<?php } else { ?>
<span class="small text-body-secondary" title="Link the assets, logins and vendors it depends on from its page">Nothing linked</span>
<?php } ?>
</td>
<td class="small itflow-service-attention">
<?php if ($row_issues) {
$first = $row_issues[0]; ?>
<div class="text-<?= $first['tone'] ?>-emphasis text-truncate" title="<?= escapeHtml(implode("\n", array_column($row_issues, 'text'))) ?>">
<i class="fas fa-fw fa-exclamation-<?= $first['tone'] === 'danger' ? 'circle' : 'triangle' ?> me-1"></i><?= escapeHtml($first['text']) ?>
</div>
<?php if (count($row_issues) > 1) { ?><div class="text-body-secondary">and <?= count($row_issues) - 1 ?> more</div><?php } ?>
<?php } ?>
<?php if ($c['open_tickets']) { ?>
<a class="text-reset text-nowrap" href="<?= $url ?>#tickets"><i class="fas fa-fw fa-life-ring text-body-secondary me-1"></i><?= $c['open_tickets'] ?> open ticket<?= $c['open_tickets'] === 1 ? '' : 's' ?></a>
<?php } ?>
<?php if (!$row_issues && !$c['open_tickets']) { ?>
<span class="text-body-secondary">-</span>
<?php } ?>
</td>
<td class="text-nowrap"><?= serviceReviewPill($review) ?></td>
<td class="text-end">
<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-url="modals/service/service_edit.php?id=<?= $service_id ?>">
<i class="fas fa-fw fa-edit me-2"></i>Edit
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= $quick_url ?>">
<i class="fas fa-fw fa-eye text-secondary me-2"></i>Quick look
</a>
<?php if (lookupUserPermission("module_support") >= 3) { ?>
<div class="dropdown-divider"></div>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-trash me-2"></i>Delete
<a class="dropdown-item" href="<?= $url ?>" target="_blank">
<i class="fas fa-fw fa-external-link-alt text-secondary me-2"></i>Open in a new tab
</a>
<?php if ($can_edit && !$is_archived) { ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="<?= escapeHtml('modals/ticket/ticket_add.php?' . http_build_query(['client_id' => $row_client_id, 'service_id' => $service_id])) ?>">
<i class="fas fa-fw fa-life-ring text-secondary me-2"></i>Report a problem
</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-size="lg" data-modal-url="modals/service/service_edit.php?id=<?= $service_id ?>">
<i class="fas fa-fw fa-edit text-secondary me-2"></i>Edit
</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/service/service_review.php?id=<?= $service_id ?>">
<i class="fas fa-fw fa-clipboard-check text-secondary me-2"></i>Mark reviewed
</a>
<a class="dropdown-item" href="post.php?<?= $is_favorite ? 'unfavorite_service' : 'favorite_service' ?>=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="<?= $is_favorite ? 'far' : 'fas' ?> fa-fw fa-star text-secondary me-2"></i><?= $is_favorite ? 'Unstar' : 'Star' ?>
</a>
<?php } ?>
<?php if ($can_edit) { ?>
<div class="dropdown-divider"></div>
<?php if ($is_archived) { ?>
<a class="dropdown-item" href="post.php?restore_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
</a>
<?php if ($can_delete) { ?>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
data-confirm-text="<?= $name ?> goes for good. What it linked to - assets, logins, documents - stays.">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
<?php } ?>
<?php } else { ?>
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_service=<?= $service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>"
data-confirm-text="<?= $name ?> moves to Archived, off the lists and counts, until restored.">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</a>
<?php } ?>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php
}
?>
<?php } ?>
</tbody>
</table>
</div>
<?php require_once "../includes/filter_footer.php";
?>
</div>
</form>
<?php if (!$services) { ?>
<div class="itflow-asset-empty">
<i class="fas fa-stream fa-2x mb-2 opacity-50"></i>
<div><?= $q !== '' || $show || $importance_filter || $category_filter !== '' || $client_filter ? 'No services match.' : 'No services yet - start with what the client cannot work without: email, backup, their line of business app.' ?></div>
</div>
<?php } ?>
<?php require_once "../includes/filter_footer.php"; ?>
</div>
<script src="../js/bulk_actions.js"></script>
<?php
require_once "../includes/footer.php";

View File

@@ -1396,7 +1396,9 @@ if (isset($_GET['ticket_id'])) {
-->
<?php
$can_link = $can_edit_ticket && !$ticket_is_closed;
$has_links = $asset_id || $vendor_id || $project_id || $watcher_count;
// The services it is about - raised for them, or through its assets
$ticket_services = $client_id ? ticketServices($ticket_id) : [];
$has_links = $asset_id || $vendor_id || $project_id || $watcher_count || $ticket_services;
if ($has_links || $can_link) { ?>
<div class="card mb-3">
<div class="card-header px-3 py-2">
@@ -1418,6 +1420,9 @@ if (isset($_GET['ticket_id'])) {
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket/ticket_edit_project.php?id=<?= $ticket_id ?>">
<i class="fas fa-fw fa-project-diagram me-2"></i><?= $project_id ? 'Change project' : 'Add to a project' ?>
</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket/ticket_link_service.php?id=<?= $ticket_id ?>">
<i class="fas fa-fw fa-stream me-2"></i>Link a service
</a>
<div class="dropdown-divider"></div>
<?php } ?>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/ticket/ticket_add_watcher.php?ticket_id=<?= $ticket_id ?>">
@@ -1434,7 +1439,7 @@ if (isset($_GET['ticket_id'])) {
<div class="card-body p-3">
<?php if (!$has_links) { ?>
<div class="text-muted small">Nothing linked yet. Use <i class="fas fa-fw fa-plus"></i> to add an asset, vendor, project or watcher.</div>
<div class="text-muted small">Nothing linked yet. Use <i class="fas fa-fw fa-plus"></i> to add an asset, vendor, project, service or watcher.</div>
<?php } ?>
<?php if ($asset_id) { ?>
@@ -1512,8 +1517,26 @@ if (isset($_GET['ticket_id'])) {
<?php } ?>
<?php } ?>
<?php if ($ticket_services) { ?>
<div class="ticket-link-heading <?= ($asset_id || $vendor_id || $project_id) ? 'mt-3 pt-2 border-top' : '' ?>">Services</div>
<?php foreach ($ticket_services as $ticket_service) {
$ticket_service_id = intval($ticket_service['service_id']); ?>
<div class="mt-1 d-flex align-items-center gap-1 min-w-0">
<span class="d-flex min-w-0 flex-grow-1"><?= serviceLink($ticket_service_id, $ticket_service['service_name'], $client_id, ['category' => $ticket_service['service_category']]) ?></span>
<?php if ($ticket_service['service_importance'] === 'High') { ?><?= serviceImportancePill('High') ?><?php } ?>
<?php if (!$ticket_service['linked']) { ?>
<span class="small text-muted text-nowrap" title="One of its assets is on this ticket">via asset</span>
<?php } elseif ($can_link) { ?>
<a class="confirm-link ms-1" href="post.php?unlink_service_ticket=<?= $ticket_id ?>&service_id=<?= $ticket_service_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>" title="Not about this service">
<i class="fas fa-fw fa-times text-secondary"></i>
</a>
<?php } ?>
</div>
<?php } ?>
<?php } ?>
<?php if ($watcher_count) { ?>
<div class="ticket-link-heading <?= ($asset_id || $vendor_id || $project_id) ? 'mt-3 pt-2 border-top' : '' ?>">
<div class="ticket-link-heading <?= ($asset_id || $vendor_id || $project_id || $ticket_services) ? 'mt-3 pt-2 border-top' : '' ?>">
Watchers <span class="text-muted text-lowercase fw-normal">&middot; copied on emailed replies</span>
</div>
<?php while ($watcher_row = mysqli_fetch_assoc($sql_ticket_watchers)) {

View File

@@ -68,6 +68,8 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
$can_credentials_edit = lookupUserPermission('module_credential') >= 2;
$can_financial = lookupUserPermission('module_financial') >= 1;
$can_financial_edit = lookupUserPermission('module_financial') >= 2;
// A client's vendor can be linked to that client's services
$can_link_services = !$is_ours && $can_support_edit && !$vendor_archived_at;
// Override Tab Title // No Sanitizing needed as this var will only be used in the tab title
$page_title = $vendor['vendor_name'];
@@ -99,13 +101,7 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
while ($row = mysqli_fetch_assoc($sql)) {
$assets[] = $row;
}
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_description, service_category, service_importance
FROM service_vendors JOIN services ON services.service_id = service_vendors.service_id
WHERE service_vendors.vendor_id = $vendor_id AND service_client_id = $client_id
ORDER BY service_name ASC");
while ($row = mysqli_fetch_assoc($sql)) {
$services[] = $row;
}
$services = servicesFor('vendor', $vendor_id);
$documents = linkedRecords('vendor', $vendor_id, 'document');
$files = linkedRecords('vendor', $vendor_id, 'file');
}
@@ -584,21 +580,17 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie
<!-- Services they are part of -->
<div class="tab-pane fade" id="vendor-pane-services" role="tabpanel">
<div class="itflow-asset-pane-bar">
<span class="text-body-secondary small">The client's services that depend on them.</span>
<span class="text-body-secondary small">The client's services that depend on them - who gets the call when one breaks.</span>
<?php if ($can_link_services) { ?>
<button type="button" class="btn btn-sm btn-outline-secondary ajax-modal" data-modal-url="modals/link/link.php?from=vendor&id=<?= $vendor_id ?>&to=service">
<i class="fas fa-link me-2"></i>Link
</button>
<?php } ?>
</div>
<?php if ($services) { ?>
<ul class="list-unstyled mb-0 itflow-links itflow-license-links">
<?php foreach ($services as $service) { ?>
<li class="itflow-link-row">
<span class="itflow-link-icon" aria-hidden="true"><i class="fas fa-fw fa-stream"></i></span>
<div class="min-w-0 flex-grow-1">
<div class="d-flex"><a class="ajax-modal text-truncate" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=<?= intval($service['service_id']) ?>"><?= escapeHtml($service['service_name']) ?></a></div>
<div class="small text-body-secondary text-truncate"><?= escapeHtml(implode(' · ', array_filter([$service['service_category'], $service['service_description']]))) ?></div>
</div>
<?php if ($service['service_importance']) { ?><span class="badge rounded-pill bg-<?= $service['service_importance'] === 'High' ? 'danger' : ($service['service_importance'] === 'Medium' ? 'warning' : 'secondary') ?>-subtle text-body fw-normal"><?= escapeHtml($service['service_importance']) ?></span><?php } ?>
</li>
<?php } ?>
</ul>
<?= serviceRowsHtml($services, $can_link_services ? function ($row) use ($vendor_id) {
return "post.php?unlink_item&from=vendor&id=$vendor_id&to=service&other=" . intval($row['service_id']) . "&csrf_token=" . $_SESSION['csrf_token'];
} : null) ?>
<?php } else { ?>
<div class="itflow-asset-empty">No services depend on them.</div>
<?php } ?>

View File

@@ -133,6 +133,7 @@ $resource_module = [
'documents' => 'module_support',
'domains' => 'module_support',
'networks' => 'module_support',
'services' => 'module_support',
'software' => 'module_support',
'tickets' => 'module_support',
'ticket_replies' => 'module_support',

30
api/v1/services/read.php Normal file
View File

@@ -0,0 +1,30 @@
<?php
require_once '../validate_api_key.php';
require_once '../require_get_method.php';
// Archived ones only when asked for (?archived=1)
$archived_query = intval($_GET['archived'] ?? 0) === 1 ? '' : 'AND service_archived_at IS NULL';
if (isset($_GET['service_id'])) {
// Specific service via ID (single)
$id = intval($_GET['service_id']);
$sql = mysqli_query($mysqli, "SELECT * FROM services WHERE service_id = $id " . apiClientScopeSql('service_client_id'));
} elseif (isset($_GET['service_name'])) {
// Service by name
$name = mysqli_real_escape_string($mysqli, $_GET['service_name']);
$sql = mysqli_query($mysqli, "SELECT * FROM services WHERE service_name = '$name' $archived_query " . apiClientScopeSql('service_client_id') . " ORDER BY service_id LIMIT $limit OFFSET $offset");
} elseif (isset($_GET['review_due'])) {
// Due for review in the next 30 days, or overdue
$sql = mysqli_query($mysqli, "SELECT * FROM services WHERE " . serviceReviewDueSql() . " AND service_archived_at IS NULL " . apiClientScopeSql('service_client_id') . " ORDER BY service_review_due LIMIT $limit OFFSET $offset");
} else {
// All services (by client ID or all in general if key permits)
$sql = mysqli_query($mysqli, "SELECT * FROM services WHERE 1=1 $archived_query " . apiClientScopeSql('service_client_id') . " ORDER BY service_id LIMIT $limit OFFSET $offset");
}
// Output
require_once "../read_output.php";

View File

@@ -326,6 +326,18 @@ foreach ($warranty_alert_array as $day) {
// Logging
// logAudit("Cron", "Task", "Cron created notifications for asset warranties expiring");
// Services due for review - said once, the day it falls due
$sql = mysqli_query($mysqli, "SELECT service_id, service_name, service_importance, client_id, client_name FROM services
JOIN clients ON service_client_id = client_id
WHERE service_review_due = CURDATE() AND service_archived_at IS NULL AND client_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql)) {
$service_id = intval($row['service_id']);
$service_name = escapeSql($row['service_name']);
$client_id = intval($row['client_id']);
$client_name = escapeSql($row['client_name']);
appNotify("Service Review", "Service $service_name for $client_name (" . escapeSql($row['service_importance']) . " importance) is due for review today", "/agent/" . serviceUrl($service_id, $client_id), $client_id);
}
// Notify of New Tickets
// Get Ticket Pending Assignment
$sql_tickets_pending_assignment = mysqli_query($mysqli,"SELECT ticket_id FROM tickets WHERE ticket_status = 1");

View File

@@ -4938,3 +4938,70 @@ img.itflow-contact-avatar {
.itflow-project-tasks li {
padding: .2rem 0;
}
/* Services - agent/services.php, agent/service.php and the service quick
look (functions/service.php). Each row says what it depends on as small
count chips, and the first thing that needs attention. */
.itflow-service-main {
max-width: 20rem;
}
.itflow-service-desc {
max-width: 16rem;
}
.itflow-service-attention,
.itflow-service-attention > div {
max-width: 15rem;
}
.itflow-service-list .itflow-ticket-who-cell > * {
max-width: 10rem;
}
.itflow-service-chips-cell {
min-width: 11rem;
}
@media (max-width: 1599.98px) {
.itflow-service-main {
max-width: 16rem;
}
.itflow-service-desc {
max-width: 12rem;
}
.itflow-service-attention,
.itflow-service-attention > div {
max-width: 12rem;
}
}
.itflow-service-chips {
max-width: 15.5rem;
}
.itflow-service-text {
white-space: pre-line;
overflow-wrap: anywhere;
}
.itflow-service-issues li {
padding: .1rem 0;
overflow-wrap: anywhere;
}
.itflow-service-notes-peek {
max-height: 9rem;
overflow: hidden;
-webkit-mask-image: linear-gradient(to bottom, #000 70%, transparent);
mask-image: linear-gradient(to bottom, #000 70%, transparent);
}
.itflow-service-importance .btn {
line-height: 1.25;
}
.itflow-service-callee .itflow-link-remove {
opacity: 0;
}
.itflow-service-callee:hover .itflow-link-remove,
.itflow-service-callee .itflow-link-remove:focus-visible {
opacity: 1;
}
@media (hover: none) {
.itflow-service-callee .itflow-link-remove {
opacity: 1;
}
}
.itflow-service-alert ul {
font-size: .9rem;
}

44
db.sql
View File

@@ -2229,6 +2229,7 @@ DROP TABLE IF EXISTS `service_assets`;
CREATE TABLE `service_assets` (
`service_id` int(11) NOT NULL,
`asset_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`asset_id`),
KEY `service_id` (`service_id`),
KEY `asset_id` (`asset_id`),
CONSTRAINT `service_assets_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2246,6 +2247,7 @@ DROP TABLE IF EXISTS `service_certificates`;
CREATE TABLE `service_certificates` (
`service_id` int(11) NOT NULL,
`certificate_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`certificate_id`),
KEY `service_id` (`service_id`),
KEY `certificate_id` (`certificate_id`),
CONSTRAINT `service_certificates_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2263,6 +2265,7 @@ DROP TABLE IF EXISTS `service_contacts`;
CREATE TABLE `service_contacts` (
`service_id` int(11) NOT NULL,
`contact_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`contact_id`),
KEY `service_id` (`service_id`),
KEY `contact_id` (`contact_id`),
CONSTRAINT `service_contacts_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2280,6 +2283,7 @@ DROP TABLE IF EXISTS `service_credentials`;
CREATE TABLE `service_credentials` (
`service_id` int(11) NOT NULL,
`credential_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`credential_id`),
KEY `service_id` (`service_id`),
KEY `credential_id` (`credential_id`),
CONSTRAINT `service_credentials_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2297,6 +2301,7 @@ DROP TABLE IF EXISTS `service_documents`;
CREATE TABLE `service_documents` (
`service_id` int(11) NOT NULL,
`document_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`document_id`),
KEY `service_id` (`service_id`),
KEY `document_id` (`document_id`),
CONSTRAINT `service_documents_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2314,8 +2319,28 @@ DROP TABLE IF EXISTS `service_domains`;
CREATE TABLE `service_domains` (
`service_id` int(11) NOT NULL,
`domain_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`domain_id`),
KEY `service_id` (`service_id`),
KEY `domain_id` (`domain_id`)
KEY `domain_id` (`domain_id`),
CONSTRAINT `service_domains_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
CONSTRAINT `service_domains_ibfk_2` FOREIGN KEY (`domain_id`) REFERENCES `domains` (`domain_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
--
-- Table structure for table `service_tickets`
--
DROP TABLE IF EXISTS `service_tickets`;
/*!40101 SET @saved_cs_client = @@character_set_client */;
/*!40101 SET character_set_client = utf8mb4 */;
CREATE TABLE `service_tickets` (
`service_id` int(11) NOT NULL,
`ticket_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`ticket_id`),
KEY `ticket_id` (`ticket_id`),
CONSTRAINT `service_tickets_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
CONSTRAINT `service_tickets_ibfk_2` FOREIGN KEY (`ticket_id`) REFERENCES `tickets` (`ticket_id`) ON DELETE CASCADE
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;
@@ -2329,6 +2354,7 @@ DROP TABLE IF EXISTS `service_vendors`;
CREATE TABLE `service_vendors` (
`service_id` int(11) NOT NULL,
`vendor_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`,`vendor_id`),
KEY `service_id` (`service_id`),
KEY `vendor_id` (`vendor_id`),
CONSTRAINT `service_vendors_ibfk_1` FOREIGN KEY (`service_id`) REFERENCES `services` (`service_id`) ON DELETE CASCADE,
@@ -2346,19 +2372,23 @@ DROP TABLE IF EXISTS `services`;
CREATE TABLE `services` (
`service_id` int(11) NOT NULL AUTO_INCREMENT,
`service_name` varchar(200) NOT NULL,
`service_description` varchar(200) NOT NULL,
`service_category` varchar(20) NOT NULL,
`service_importance` varchar(10) NOT NULL,
`service_backup` varchar(200) DEFAULT NULL,
`service_notes` mediumtext NOT NULL,
`service_description` varchar(200) NOT NULL DEFAULT '',
`service_category` varchar(50) NOT NULL DEFAULT '',
`service_importance` varchar(10) NOT NULL DEFAULT 'Medium',
`service_backup` varchar(500) DEFAULT NULL,
`service_notes` mediumtext DEFAULT NULL,
`service_favorite` tinyint(1) NOT NULL DEFAULT 0,
`service_created_at` datetime NOT NULL DEFAULT current_timestamp(),
`service_updated_at` datetime DEFAULT NULL ON UPDATE current_timestamp(),
`service_accessed_at` datetime DEFAULT NULL,
`service_archived_at` datetime DEFAULT NULL,
`service_review_due` date DEFAULT NULL,
`service_reviewed_at` datetime DEFAULT NULL,
`service_review_interval` int(11) NOT NULL DEFAULT 0,
`service_client_id` int(11) NOT NULL,
PRIMARY KEY (`service_id`),
KEY `service_client_id` (`service_client_id`)
KEY `service_client_id` (`service_client_id`),
KEY `service_review_due` (`service_review_due`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci;
/*!40101 SET character_set_client = @saved_cs_client */;

View File

@@ -44,3 +44,4 @@ require_once __DIR__ . '/functions/tags.php';
require_once __DIR__ . '/functions/ticket_fields.php';
require_once __DIR__ . '/functions/ticket.php';
require_once __DIR__ . '/functions/project.php';
require_once __DIR__ . '/functions/service.php';

View File

@@ -527,19 +527,6 @@ function certificateHistory($certificate_id, $limit = 25) {
return $rows;
}
/** The services that use a certificate. */
function certificateServices($certificate_id) {
global $mysqli;
$certificate_id = intval($certificate_id);
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_importance FROM service_certificates
JOIN services ON services.service_id = service_certificates.service_id WHERE service_certificates.certificate_id = $certificate_id ORDER BY service_name");
$rows = [];
while ($service = mysqli_fetch_assoc($sql)) {
$rows[] = $service;
}
return $rows;
}
/** The SQL for "expiring soon" - inside CERTIFICATE_SOON_DAYS, or 20 days for a short-lived one (see certificateExpiry()). */
function certificateSoonSql($alias = 'certificates') {
return "$alias.certificate_expire BETWEEN CURDATE() AND CURDATE() + INTERVAL IF($alias.certificate_issued_at IS NOT NULL

View File

@@ -103,6 +103,20 @@ function clientOverviewAttention($client_id, $access, $renewals) {
'detail' => 'Name mismatch, untrusted, expired or unreachable',
'url' => "/agent/certificates.php?client_id=$client_id&show=problems",
];
// Something a service depends on is expiring, out of action or archived - the same rule as services.php?show=attention
$service_views = serviceViews();
$items[] = [
'count' => dashboardCount("SELECT COUNT(service_id) FROM services WHERE service_client_id = $client_id AND " . $service_views['attention']['where']),
'label' => 'Services needing attention', 'icon' => 'stream', 'tone' => 'danger',
'detail' => 'What they run on needs a look',
'url' => "/agent/services.php?client_id=$client_id&show=attention",
];
$items[] = [
'count' => dashboardCount("SELECT COUNT(service_id) FROM services WHERE service_client_id = $client_id AND " . $service_views['review']['where']),
'label' => 'Service reviews due', 'icon' => 'clipboard-check', 'tone' => 'warning',
'detail' => 'Next ' . SERVICE_REVIEW_SOON_DAYS . ' days or overdue',
'url' => "/agent/services.php?client_id=$client_id&show=review",
];
}
if ($access['credentials']) {
@@ -218,6 +232,23 @@ function clientOverviewFavorites($client_id, $access) {
return $favorites;
}
/**
* What the client runs on, most important first and the ones needing a look
* before the rest - [services, issues per service, total].
*/
function clientOverviewServices($client_id, $limit = 6) {
global $mysqli;
$client_id = intval($client_id);
$where = "service_client_id = $client_id AND services.service_archived_at IS NULL";
$sql = mysqli_query($mysqli, "SELECT services.* FROM services WHERE $where
ORDER BY " . serviceAttentionSql() . " DESC, FIELD(service_importance, 'High', 'Medium', 'Low'), service_name LIMIT " . intval($limit));
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$rows[intval($row['service_id'])] = $row;
}
return ['services' => $rows, 'issues' => serviceIssues(array_keys($rows)), 'total' => dashboardCount("SELECT COUNT(service_id) FROM services WHERE $where")];
}
/**
* The client's open projects, the ones needing a look first (overdue, then
* soonest due), with their numbers - [rows, stats, total].
@@ -238,7 +269,8 @@ function clientOverviewProjects($client_id, $limit = 5) {
/**
* The next $days days for this client: scheduled tickets, calendar events
* (repeating ones expanded the way the calendar does it), recurring
* tickets due to be raised, and projects starting or due. Soonest first.
* tickets due to be raised, projects starting or due, and services due for
* review. Soonest first.
*/
function clientOverviewUpcoming($client_id, $access, $days = 14) {
global $mysqli;
@@ -292,6 +324,20 @@ function clientOverviewUpcoming($client_id, $access, $days = 14) {
}
}
// Services due for review - all day
if ($access['docs']) {
$sql = mysqli_query($mysqli, "SELECT service_id, service_name, service_review_due FROM services
WHERE service_client_id = $client_id AND service_archived_at IS NULL
AND service_review_due BETWEEN '" . substr($from, 0, 10) . "' AND '" . substr($to, 0, 10) . "'");
while ($row = mysqli_fetch_assoc($sql)) {
$items[] = [
'when' => $row['service_review_due'] . ' 00:00:00', 'all_day' => true, 'kind' => 'service',
'title' => $row['service_name'], 'ref' => '', 'detail' => 'Service review due',
'url' => '/agent/' . serviceUrl($row['service_id'], $client_id),
];
}
}
$sql = mysqli_query($mysqli, "SELECT event_id, event_title, event_start, event_end, event_all_day, event_repeat, event_location
FROM calendar_events
WHERE event_client_id = $client_id AND event_archived_at IS NULL AND event_start <= '$to'

View File

@@ -12,8 +12,8 @@
* carries the credential id, never the secret.
*
* A credential belongs to one asset and/or one contact (columns on the
* credential), and is linked to vendors and licenses through link tables
* (functions/links.php) and to services (service_credentials).
* credential), and is linked to vendors, licenses and services through link
* tables (functions/links.php).
*/
/** How long a password can go unchanged before it is called stale - the same 90 days the rotation report uses. */
@@ -431,7 +431,7 @@ function credentialLinks(array $credential_ids) {
$sources = [
'vendor' => "SELECT l.credential_id, v.vendor_id, v.vendor_name FROM vendor_credentials l JOIN vendors v ON v.vendor_id = l.vendor_id AND v.vendor_archived_at IS NULL WHERE l.credential_id IN ($in) ORDER BY v.vendor_name",
'software' => "SELECT l.credential_id, s.software_id, s.software_name FROM software_credentials l JOIN software s ON s.software_id = l.software_id AND s.software_archived_at IS NULL WHERE l.credential_id IN ($in) ORDER BY s.software_name",
'service' => "SELECT l.credential_id, s.service_id, s.service_name FROM service_credentials l JOIN services s ON s.service_id = l.service_id WHERE l.credential_id IN ($in) ORDER BY s.service_name",
'service' => "SELECT l.credential_id, s.service_id, s.service_name FROM service_credentials l JOIN services s ON s.service_id = l.service_id AND s.service_archived_at IS NULL WHERE l.credential_id IN ($in) ORDER BY s.service_name",
];
foreach ($sources as $type => $query) {
$sql = mysqli_query($mysqli, $query);

View File

@@ -295,6 +295,19 @@ function dashboardAttention($access) {
'label' => 'Warranties expiring', 'icon' => 'shield-alt', 'tone' => 'warning', 'detail' => 'Next 30 days',
'url' => '/agent/assets.php?expire_days=30&sort=asset_warranty_expire&order=ASC&show_column[]=Warranty_Expire',
];
// The same rules as services.php?show=attention and ?show=review
$service_views = serviceViews();
$service_scope = "FROM services JOIN clients ON client_id = service_client_id WHERE client_archived_at IS NULL " . clientScopeSql('service_client_id');
$items[] = [
'count' => dashboardCount("SELECT COUNT(service_id) $service_scope AND " . $service_views['attention']['where']),
'label' => 'Services needing attention', 'icon' => 'stream', 'tone' => 'danger', 'detail' => 'What they depend on',
'url' => '/agent/services.php?show=attention',
];
$items[] = [
'count' => dashboardCount("SELECT COUNT(service_id) $service_scope AND " . $service_views['review']['where']),
'label' => 'Service reviews due', 'icon' => 'clipboard-check', 'tone' => 'warning', 'detail' => 'Next ' . SERVICE_REVIEW_SOON_DAYS . ' days',
'url' => '/agent/services.php?show=review&sort=service_review_due&order=ASC',
];
}
return array_values(array_filter($items, function ($item) {

View File

@@ -910,19 +910,6 @@ function domainCertificates($row) {
return $rows;
}
/** The services that use a domain. */
function domainServices($domain_id) {
global $mysqli;
$domain_id = intval($domain_id);
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_importance FROM service_domains
JOIN services ON services.service_id = service_domains.service_id WHERE service_domains.domain_id = $domain_id ORDER BY service_name");
$rows = [];
while ($service = mysqli_fetch_assoc($sql)) {
$rows[] = $service;
}
return $rows;
}
/** The client's logins for the domain's registrar and hosts - linked to those vendors - for those who may see credentials. */
function domainLogins($row) {
$vendor_ids = array_keys(domainVendors($row));

View File

@@ -283,6 +283,26 @@ function getExportColumns($export_type) {
'project_description' => ['label' => 'Scope', 'weight' => 3, 'default' => false],
],
// Services - the counts, attention and review columns are built by the handler
'services' => [
'service_name' => ['label' => 'Service', 'weight' => 2],
'client_name' => ['label' => 'Client', 'weight' => 2],
'service_category' => ['label' => 'Category'],
'service_importance' => ['label' => 'Importance'],
'service_description' => ['label' => 'Description', 'weight' => 3],
'service_assets' => ['label' => 'Runs On', 'weight' => 3],
'service_vendors' => ['label' => 'Vendors', 'weight' => 2],
'service_contacts' => ['label' => 'People', 'weight' => 2, 'default' => false],
'service_domains' => ['label' => 'Domains', 'weight' => 2, 'default' => false],
'service_backup' => ['label' => 'Backup and Recovery', 'weight' => 3],
'service_attention' => ['label' => 'Needs Attention', 'weight' => 3],
'service_review' => ['label' => 'Next Review'],
'service_reviewed' => ['label' => 'Last Reviewed', 'default' => false],
'service_review_every' => ['label' => 'Review Every', 'default' => false],
'open_tickets' => ['label' => 'Open Tickets', 'format' => 'number', 'default' => false],
'service_state' => ['label' => 'State', 'default' => false],
],
// invoice_number_display is prefix . number, built by the handler
'invoices' => [
'invoice_number_display' => ['label' => 'Invoice Number'],
@@ -914,6 +934,7 @@ function getClientPackSections() {
'contacts' => ['label' => 'Contacts', 'icon' => 'fa-users', 'module' => 'module_client', 'default' => true],
'locations' => ['label' => 'Locations', 'icon' => 'fa-map-marker-alt', 'module' => 'module_client', 'default' => true],
'vendors' => ['label' => 'Vendors', 'icon' => 'fa-building', 'module' => 'module_client', 'default' => true],
'services' => ['label' => 'Services', 'icon' => 'fa-stream', 'module' => 'module_support', 'default' => true],
'credentials' => ['label' => 'Credentials', 'icon' => 'fa-key', 'module' => 'module_credential', 'default' => false],
'assets' => ['label' => 'Assets', 'icon' => 'fa-desktop', 'module' => 'module_support', 'default' => true],
'software' => ['label' => 'Software / Licenses', 'icon' => 'fa-cube', 'module' => 'module_support', 'default' => true],

View File

@@ -7,7 +7,8 @@
* license (the devices and users on it) and the credentials and files that
* go with it, the documents and files about a location (a floor plan, a
* site runbook), and a vendor's portal logins, documents and files (the
* contract, the escalation sheet).
* contract, the escalation sheet), and what a service depends on - its
* assets, logins, domains, certificates, people, vendors and documents.
*
* Every link is a row in a two-column table (asset_documents, document_files,
* contact_files...) and they all work the same way, so they are described once
@@ -33,6 +34,9 @@ const LINK_ENTITIES = [
'location' => ['table' => 'locations', 'id' => 'location_id', 'name' => 'location_name', 'client' => 'location_client_id', 'archived' => 'location_archived_at', 'label' => 'location', 'plural' => 'Locations', 'icon' => 'fa-map-marker-alt', 'view' => 'module_client'],
'credential' => ['table' => 'credentials', 'id' => 'credential_id', 'name' => 'credential_name', 'client' => 'credential_client_id', 'archived' => 'credential_archived_at', 'label' => 'credential', 'plural' => 'Credentials', 'icon' => 'fa-key', 'view' => 'module_credential'],
'vendor' => ['table' => 'vendors', 'id' => 'vendor_id', 'name' => 'vendor_name', 'client' => 'vendor_client_id', 'archived' => 'vendor_archived_at', 'label' => 'vendor', 'plural' => 'Vendors', 'icon' => 'fa-building'],
'service' => ['table' => 'services', 'id' => 'service_id', 'name' => 'service_name', 'client' => 'service_client_id', 'archived' => 'service_archived_at', 'label' => 'service', 'plural' => 'Services', 'icon' => 'fa-stream'],
'domain' => ['table' => 'domains', 'id' => 'domain_id', 'name' => 'domain_name', 'client' => 'domain_client_id', 'archived' => 'domain_archived_at', 'label' => 'domain', 'plural' => 'Domains', 'icon' => 'fa-globe'],
'certificate' => ['table' => 'certificates', 'id' => 'certificate_id', 'name' => 'certificate_name', 'client' => 'certificate_client_id', 'archived' => 'certificate_archived_at', 'label' => 'certificate', 'plural' => 'Certificates', 'icon' => 'fa-lock'],
];
/**
@@ -58,6 +62,14 @@ const LINK_RELATIONS = [
'file|location' => ['table' => 'location_files', 'module' => 'module_support'],
'credential|vendor' => ['table' => 'vendor_credentials', 'module' => 'module_credential'],
'file|vendor' => ['table' => 'vendor_files', 'module' => 'module_support'],
// What a service depends on - support documentation, its logins a credentials permission
'asset|service' => ['table' => 'service_assets', 'module' => 'module_support'],
'certificate|service' => ['table' => 'service_certificates', 'module' => 'module_support'],
'contact|service' => ['table' => 'service_contacts', 'module' => 'module_support'],
'credential|service' => ['table' => 'service_credentials', 'module' => 'module_credential'],
'document|service' => ['table' => 'service_documents', 'module' => 'module_support'],
'domain|service' => ['table' => 'service_domains', 'module' => 'module_support'],
'service|vendor' => ['table' => 'service_vendors', 'module' => 'module_support'],
];
/** The relation between two types, or null when they cannot be linked. */
@@ -75,9 +87,11 @@ function linkTypesFor($from) {
$orders = [
'software' => ['asset', 'contact', 'credential', 'document', 'file'],
// A vendor's portal logins first - what is wanted on the phone to them
'vendor' => ['credential', 'document', 'file'],
'vendor' => ['credential', 'document', 'file', 'service'],
// What it runs on first, then what it needs to work, then who to call
'service' => SERVICE_LINK_TYPES,
];
$order = $orders[$from] ?? ['file', 'document', 'asset', 'contact', 'location', 'software', 'credential', 'vendor'];
$order = $orders[$from] ?? ['file', 'document', 'asset', 'contact', 'location', 'software', 'credential', 'vendor', 'service'];
return array_values(array_filter($order, function ($to) use ($from) {
$view = LINK_ENTITIES[$to]['view'] ?? null;
return $to !== $from && linkRelation($from, $to) && (!$view || lookupUserPermission($view) >= 1);
@@ -115,6 +129,9 @@ function linkDisplayColumns($type) {
'credential' => 'credential_description, credential_uri, credential_username, credential_otp_secret, credential_favorite, credential_password_changed_at',
'vendor' => 'vendor_description, vendor_account_number, vendor_phone, vendor_phone_country_code, vendor_extension',
'location' => 'location_address, location_city, location_state, location_zip, location_primary, location_photo, location_client_id',
'service' => 'service_description, service_category, service_importance, service_client_id',
'domain' => 'domain_description, domain_expire, domain_auto_renew',
'certificate' => 'certificate_domain, certificate_expire, certificate_issued_at, certificate_check_status, certificate_checked_at',
][$type] ?? '';
}
@@ -182,9 +199,9 @@ function linkCounts($from, $id) {
return $counts;
}
/** The audit log entry a link change is filed under - the document, file or license side of it. */
/** The audit log entry a link change is filed under - the service, document, file or license side of it. */
function linkLogSide($from, $id, $to, $other_id) {
foreach (['document', 'file', 'software'] as $side) {
foreach (['service', 'document', 'file', 'software'] as $side) {
if ($from === $side) {
return [ucfirst($side), $id];
}
@@ -276,9 +293,42 @@ function linkRemoveAll($type, $id) {
mysqli_query($mysqli, "DELETE FROM {$relation['table']} WHERE {$entity['id']} = $id");
}
}
if ($type === 'document') {
mysqli_query($mysqli, "DELETE FROM service_documents WHERE document_id = $id");
}
/** A candidate as an option in a picker (itflow_select.js) - its icon or avatar, and a line under it. Rows as linkCandidates() gives them. */
function linkOptionData($to, $row, $client_id) {
switch ($to) {
case 'asset':
return selectOptionAsset($row['asset_type'], trim($row['asset_make'] . ' ' . $row['asset_model']));
case 'contact':
return selectOptionContact($row['contact_client_id'], $row['name'], $row['contact_photo'], $row['contact_title'], $row['id']);
case 'file':
$info = fileTypeInfo($row['file_ext']);
return selectOptionData(['icon' => 'fas fa-' . $info['icon'], 'description' => ($row['folder_name'] ?: 'Top level') . ' · ' . formatBytes(intval($row['file_size'])), 'keywords' => $row['file_description']]);
case 'document':
return selectOptionData(['icon' => 'fas fa-file-alt', 'description' => $row['document_description'] ?: 'Updated ' . timeAgo($row['document_updated_at'] ?: $row['document_created_at'])]);
case 'software':
// How many seats are left, so a full license is seen before it is picked
$seats = softwareSeats($row['seats_used'], $row['software_seats']);
$seat_text = $seats['state'] === 'unlimited' ? '' : ($seats['state'] === 'over' || $seats['state'] === 'full'
? 'Full - ' . $seats['used'] . ' of ' . $seats['total'] . ' seats'
: $seats['free'] . ' of ' . $seats['total'] . ' seats free');
return selectOptionData(['icon' => 'fas ' . softwareTypeStyle($row['software_type'])['icon'], 'description' => implode(' · ', array_filter([$row['software_license_type'], $seat_text, $row['software_version']]))]);
case 'credential':
return selectOptionCredential(['credential_name' => $row['name'], 'credential_description' => $row['credential_description'], 'credential_uri' => $row['credential_uri']], $row['credential_description'] ?: $row['credential_uri']);
case 'location':
return selectOptionData(['icon' => 'fas fa-' . (intval($row['location_primary']) ? 'building' : 'map-marker-alt'), 'description' => implode(' · ', array_filter([intval($row['location_primary']) ? 'Primary' : '', locationAddressText($row)]))]);
case 'vendor':
return selectOptionVendor($row['name'], $row['vendor_description']);
case 'service':
return selectOptionService($row);
case 'domain':
$expiry = domainExpiry($row['domain_expire'], $row['domain_auto_renew']);
return selectOptionData(['icon' => 'fas fa-globe', 'description' => implode(' · ', array_filter([$row['domain_description'], $expiry ? $expiry['text'] : '']))]);
case 'certificate':
return selectOptionCertificate(['certificate_name' => $row['name']] + $row);
}
return '';
}
/**
@@ -344,6 +394,25 @@ function linkRowHtml($to, $row, $client_id) {
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/vendor/vendor.php?id=$id\">$name</a>";
$detail = implode(' · ', array_filter([$row['vendor_description'], $row['vendor_phone'] ? formatPhoneNumber($row['vendor_phone'], $row['vendor_phone_country_code']) : '']));
break;
case 'service':
$lead = serviceTile($row['service_category'] ?? '', 'sm');
$link = '<a class="text-truncate" href="' . escapeHtml(serviceUrl($id, $row['service_client_id'] ?? $client_id)) . "\">$name</a>";
$detail = implode(' · ', array_filter([$row['service_category'] ?? '', ($row['service_importance'] ?? '') ? $row['service_importance'] . ' importance' : '']));
break;
case 'domain':
$lead = domainTile('sm');
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/domain/domain.php?id=$id\">$name</a>";
$expiry = domainExpiry($row['domain_expire'] ?? '', $row['domain_auto_renew'] ?? 0);
$detail = '';
$extra = '<div class="mt-1">' . domainExpiryPill($expiry, true) . '</div>';
break;
case 'certificate':
$lead = certificateTile('sm');
$link = "<a class=\"ajax-modal text-truncate\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/certificate/certificate.php?id=$id\">$name</a>";
$detail = ($row['certificate_domain'] ?? '') !== $row['name'] ? ($row['certificate_domain'] ?? '') : '';
$problem = !in_array($row['certificate_check_status'] ?? '', [null, '', 'ok'], true);
$extra = '<div class="mt-1 d-flex flex-wrap gap-1">' . certificateExpiryPill(certificateExpiry($row), true) . ($problem ? certificateStatusPill($row) : '') . '</div>';
break;
default:
return '';
}

View File

@@ -32,7 +32,7 @@ function notificationTypeModules() {
'module_financial' => ['Expense', 'Expense Created'],
'module_support' => [
'Ticket', 'Ticket SLA', 'Pending Tickets', 'Feedback', 'Recurring Ticket', 'Project',
'Domain Expiring', 'Certificate Expiring', 'Asset Warranty Expiring',
'Domain Expiring', 'Certificate Expiring', 'Asset Warranty Expiring', 'Service Review',
],
'module_client' => ['Share Viewed'],
];
@@ -76,6 +76,7 @@ function notificationTypeStyle($type) {
[['expense'], 'receipt', 'secondary'],
[['ticket'], 'life-ring', 'primary'],
[['project'], 'project-diagram', 'primary'],
[['service'], 'clipboard-check', 'info'],
[['mail'], 'envelope', 'danger'],
[['backup'], 'database', 'secondary'],
[['master key'], 'key', 'warning'],

View File

@@ -285,6 +285,28 @@ function globalSearchGroups($terms, $deep) {
},
];
// What a client runs on - by name, category and description, and its notes in a deep search
$service_deep_match = $deep ? "OR service_notes LIKE '%$like%' OR service_backup LIKE '%$like%'" : '';
$groups[] = [
'key' => 'services', 'label' => 'Services', 'icon' => 'stream', 'module' => 'module_support',
'select' => 'service_id, service_name, service_description, service_category, service_importance, service_client_id, client_name',
'from' => 'services LEFT JOIN clients ON service_client_id = client_id',
'where' => "service_archived_at IS NULL
AND (service_name LIKE '%$like%' OR service_description LIKE '%$like%' OR service_category LIKE '%$like%' $service_deep_match)",
'scope' => 'service_client_id',
'order' => "(service_name = '$eq') DESC, (service_name LIKE '$like%') DESC, FIELD(service_importance, 'High', 'Medium', 'Low'), service_name",
'list_url' => '/agent/services.php?' . http_build_query(['q' => $q]),
'item' => function ($row) {
return [
'title' => $row['service_name'],
'subtitle' => implode(' · ', array_filter([$row['service_category'], $row['service_description']])),
'context' => $row['client_name'],
'badge' => $row['service_importance'] === 'High' ? ['text' => 'High', 'variant' => 'danger'] : null,
'url' => '/agent/' . serviceUrl($row['service_id'], $row['service_client_id']),
];
},
];
// Name and description only. Usernames and passwords are encrypted at rest,
// and the results page reveals passwords through the audited endpoint, never
// in the markup.
@@ -669,6 +691,7 @@ function globalSearchPages($raw_query) {
['Dashboard', '/agent/dashboard.php', true],
['Clients', '/agent/clients.php', $client],
['All Client Docs', '/agent/contacts.php', $client],
['Services', '/agent/services.php', $support],
['Vendors', '/agent/vendors.php', true],
['Calendar', '/agent/calendar.php', true],
['Tickets', '/agent/tickets.php', $support && $ticketing],

734
functions/service.php Normal file
View File

@@ -0,0 +1,734 @@
<?php
/*
* Services - what a client actually runs on: email, backup, the line of
* business app, the phones, the website, remote access. A service is the
* map an agent wants when something breaks or someone asks what a change
* will touch: the assets it runs on, the logins, domains and certificates it
* needs, the people who own or use it, the vendors to call, the documents
* that explain it, and the tickets raised about it.
*
* Importance is how bad an outage is. A review keeps the map honest - every
* so many months someone checks it still matches what is out there, and the
* next review falls due that many months later.
*
* Something it depends on that needs attention - a domain or certificate
* expiring, a server or network device out of warranty or out for repair, a
* linked record that has since been archived - shows on the service, the
* list and the client overview rather than only on that record's own page.
*
* A service that is retired is archived: it drops off the lists and counts
* and comes back when restored.
*/
/** How bad an outage is, most first. */
const SERVICE_IMPORTANCE = ['High', 'Medium', 'Low'];
/** "Review due" - within this many days. */
const SERVICE_REVIEW_SOON_DAYS = 30;
/** How often a service is reviewed, in months. */
const SERVICE_REVIEW_INTERVALS = [
0 => 'Not on a schedule',
1 => 'Every month',
3 => 'Every 3 months',
6 => 'Every 6 months',
12 => 'Every year',
24 => 'Every 2 years',
];
/** Categories the form suggests - anything else can be typed. */
const SERVICE_CATEGORY_SUGGESTIONS = ['Email', 'Backup', 'Network', 'Internet', 'Security', 'Web', 'Cloud', 'Phones', 'Line of business',
'Identity', 'Remote access', 'File storage', 'Printing', 'Hosting', 'Monitoring'];
/** What a service can depend on, in the order the page lists them. */
const SERVICE_LINK_TYPES = ['asset', 'credential', 'domain', 'certificate', 'contact', 'vendor', 'document'];
/** Asset statuses that mean it is not doing its job. */
const SERVICE_ASSET_DOWN_STATUSES = ['Out for Repair', 'Lost', 'Stolen', 'Retired'];
/**
* One person's device - a service on many of them (endpoint protection) does
* not hinge on any one, so their warranties and repairs are not the service's
* problem. Servers, network kit, printers and the rest are.
*/
const SERVICE_USER_DEVICE_TYPES = ['Laptop', 'Desktop', 'Mobile Phone', 'Tablet'];
/** May this agent do this with services? They are support documentation: 1 to see, 2 to change, 3 to delete. */
function serviceCan($level) {
return lookupUserPermission('module_support') >= $level;
}
/** One service by id, with its client - raw, or null. */
function serviceRow($service_id) {
global $mysqli;
$service_id = intval($service_id);
if (!$service_id) {
return null;
}
$row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT services.*, client_name, client_archived_at FROM services
LEFT JOIN clients ON client_id = service_client_id
WHERE service_id = $service_id LIMIT 1"));
return $row ?: null;
}
/**
* For post handlers: the service a request names, after the module and
* client checks - or back with an error if it is gone. Sets the global $client_id.
*/
function serviceForRequest($service_id, $level) {
global $client_id;
enforceUserPermission('module_support', $level);
$row = serviceRow($service_id);
if (!$row) {
flashAlert('That service no longer exists.', 'error');
redirect();
}
$client_id = intval($row['service_client_id']);
enforceClientAccess();
return $row;
}
/**
* For modals: the service a modal is opened for, after the same checks - or
* the modal's error, and nothing more. $active_only refuses an archived one.
* Sets the global $client_id.
*/
function serviceForModal($service_id, $level = 1, $active_only = false) {
global $client_id;
enforceUserPermission('module_support', $level);
$row = serviceRow($service_id);
if (!$row) {
echo json_encode(['error' => 'That service no longer exists.']);
exit;
}
$client_id = intval($row['service_client_id']);
enforceClientAccess();
if ($active_only && !empty($row['service_archived_at'])) {
echo json_encode(['error' => escapeHtml($row['service_name']) . ' is archived - restore it first.']);
exit;
}
return $row;
}
/** For post handlers: the services a bulk action names (service_ids[]) that this agent may act on - [id => row]. */
function servicesForBulk($level) {
global $client_id;
enforceUserPermission('module_support', $level);
$rows = [];
foreach (array_unique(array_map('intval', (array) ($_POST['service_ids'] ?? []))) as $service_id) {
$row = serviceRow($service_id);
if (!$row) {
continue;
}
$client_id = intval($row['service_client_id']);
enforceClientAccess();
$rows[$service_id] = $row;
}
return $rows;
}
/** Where the service page is. */
function serviceUrl($service_id, $client_id) {
return 'service.php?client_id=' . intval($client_id) . '&service_id=' . intval($service_id);
}
/** Its icon and colour, from what its category says it is - an envelope for email, a shield for security. */
function serviceStyle($category) {
$category = mb_strtolower(trim(html_entity_decode((string) $category, ENT_QUOTES, 'UTF-8')));
$styles = [
['mail|exchange|smtp', 'fa-envelope', 'wireless'],
['backup|recovery|disaster|continuity', 'fa-history', 'virtual'],
['phone|voip|voice|telephon|pbx|fax|call', 'fa-phone', 'phone'],
['secur|antivirus|anti-virus|edr|xdr|firewall|mfa|soc\b|siem|filter', 'fa-shield-alt', 'firewall'],
['remote|vpn|rds|citrix|terminal', 'fa-plug', 'wireless'],
['network|internet|wan\b|lan\b|wifi|wi-fi|wireless|isp|circuit|broadband|fibre|fiber', 'fa-network-wired', 'network'],
['web|site|dns', 'fa-globe', 'location'],
['hosting|server|virtual|hypervisor|infrastructure|datacent', 'fa-server', 'server'],
['identity|directory|sso|entra|ldap|login|auth', 'fa-id-badge', 'virtual'],
['file|storage|share|nas\b|sharepoint|onedrive|drive|document', 'fa-folder-open', 'peripheral'],
['print|scan|copier', 'fa-print', 'peripheral'],
['monitor|rmm|alert|patch', 'fa-heartbeat', 'network'],
['cloud|saas|365|workspace|azure|aws|tenant', 'fa-cloud', 'workstation'],
['line of business|lob\b|erp|crm|accounting|payroll|app|database|sql|software|pos\b|point of sale|ehr|emr|practice', 'fa-briefcase', 'server'],
];
foreach ($styles as [$pattern, $icon, $tone]) {
if ($category !== '' && preg_match("/($pattern)/u", $category)) {
return ['icon' => $icon, 'tone' => $tone];
}
}
return ['icon' => 'fa-stream', 'tone' => 'other'];
}
/** A service's tile - its category's icon in the same rounded square as the other tiles. $size 'xs' | 'sm' | '' | 'lg'. */
function serviceTile($category, $size = '') {
$style = serviceStyle($category);
$size_class = in_array($size, ['xs', 'sm', 'lg'], true) ? " itflow-asset-icon-$size" . ($size === 'xs' ? ' itflow-vendor-tile-xs' : '') : '';
return '<span class="itflow-asset-icon' . $size_class . ' itflow-asset-tone-' . $style['tone'] . '" aria-hidden="true"><i class="fas fa-fw ' . $style['icon'] . '"></i></span>';
}
/**
* A service wherever a page mentions one: its tile and its name, opening
* its page - or its quick look with 'quick' => true. 'archived' strikes it
* through; 'class' goes on the link. Takes the name raw or already escaped.
*/
function serviceLink($service_id, $name, $client_id, $options = []) {
$service_id = intval($service_id);
$label = escapeHtml(html_entity_decode((string) $name, ENT_QUOTES, 'UTF-8'));
$archived = !empty($options['archived']);
$class = trim('text-truncate ' . ($options['class'] ?? '') . ($archived ? ' text-decoration-line-through text-body-secondary' : ''));
$title = $archived ? ' title="Archived service"' : '';
if (!empty($options['quick'])) {
$link = "<a class=\"ajax-modal $class\" href=\"#\" data-modal-size=\"lg\" data-modal-url=\"modals/service/service.php?id=$service_id\"$title>$label</a>";
} else {
$link = '<a class="' . $class . '" href="' . escapeHtml(serviceUrl($service_id, $client_id)) . "\"$title>$label</a>";
}
return '<span class="itflow-contact-ref">' . serviceTile($options['category'] ?? '', 'xs') . $link . '</span>';
}
/** A service in a picker (itflow_select.js) - its icon, and its category and importance underneath. */
function selectOptionService($row) {
return selectOptionData(['icon' => 'fas ' . serviceStyle($row['service_category'] ?? '')['icon'],
'description' => implode(' · ', array_filter([$row['service_category'] ?? '', ($row['service_importance'] ?? '') ? $row['service_importance'] . ' importance' : ''])),
'keywords' => $row['service_description'] ?? '']);
}
/** Importance as a soft pill - red High, amber Medium, grey Low. $use_text says "High importance". */
function serviceImportancePill($importance, $use_text = false) {
$importance = in_array($importance, SERVICE_IMPORTANCE, true) ? $importance : 'Medium';
$styles = [
'High' => ['danger', 'fa-thermometer-full', 'Down means the client cannot work'],
'Medium' => ['warning', 'fa-thermometer-half', 'Down hurts, but there is a way round it'],
'Low' => ['secondary', 'fa-thermometer-quarter', 'Down is an inconvenience'],
];
[$tone, $icon, $title] = $styles[$importance];
return '<span class="badge rounded-pill bg-' . $tone . '-subtle text-' . $tone . '-emphasis border border-' . $tone . '-subtle fw-normal" title="' . $title . '">'
. '<i class="fas ' . $icon . ' me-1"></i>' . $importance . ($use_text ? ' importance' : '') . '</span>';
}
/** Whole days from today to a date: negative is past. */
function serviceDaysFromToday($date) {
$today = new DateTime(date('Y-m-d'));
$then = new DateTime(substr((string) $date, 0, 10));
return intval($today->diff($then)->format('%r%a'));
}
/** The date a review is next due: $months after $from (today by default). '' for no schedule. */
function serviceNextReview($months, $from = null) {
$months = intval($months);
if ($months <= 0) {
return '';
}
$date = new DateTime($from ? substr((string) $from, 0, 10) : date('Y-m-d'));
// The 31st plus a month is the end of next month, not the start of the one after
$day = intval($date->format('j'));
$date->modify('first day of this month')->modify("+$months months");
$date->setDate(intval($date->format('Y')), intval($date->format('n')), min($day, intval($date->format('t'))));
return $date->format('Y-m-d');
}
/**
* Where its review stands: ['state' => overdue | soon | scheduled | none,
* 'tone', 'short' (for the list), 'text', 'date', 'days'].
*/
function serviceReview($row) {
$due = $row['service_review_due'] ?? null;
$reviewed = $row['service_reviewed_at'] ?? null;
if (!$due || strpos((string) $due, '0000-00-00') === 0) {
return ['state' => 'none', 'tone' => 'secondary', 'short' => 'Not scheduled', 'date' => '', 'days' => null, 'reviewed' => $reviewed,
'text' => $reviewed ? 'Last reviewed ' . timeAgo($reviewed) . ' - no next review set' : 'No review scheduled'];
}
$days = serviceDaysFromToday($due);
$date = date('M j, Y', strtotime($due));
if ($days < 0) {
return ['state' => 'overdue', 'tone' => 'danger', 'short' => 'Overdue', 'date' => $due, 'days' => $days, 'reviewed' => $reviewed,
'text' => 'Review was due ' . $date . ' (' . abs($days) . ' day' . (abs($days) === 1 ? '' : 's') . ' ago)'];
}
if ($days <= SERVICE_REVIEW_SOON_DAYS) {
$when = $days === 0 ? 'today' : ($days === 1 ? 'tomorrow' : "in $days days");
return ['state' => 'soon', 'tone' => 'warning', 'short' => $days === 0 ? 'Today' : ($days === 1 ? 'Tomorrow' : "$days days"), 'date' => $due, 'days' => $days, 'reviewed' => $reviewed,
'text' => "Review due $when ($date)"];
}
return ['state' => 'scheduled', 'tone' => 'success', 'short' => date('M j, Y', strtotime($due)), 'date' => $due, 'days' => $days, 'reviewed' => $reviewed, 'text' => "Next review $date"];
}
/** The review as a soft pill. */
function serviceReviewPill($review, $use_text = false) {
$icons = ['overdue' => 'far fa-calendar-times', 'soon' => 'fas fa-hourglass-half', 'scheduled' => 'far fa-calendar-check', 'none' => 'far fa-calendar'];
$tone = $review['tone'];
$title = $review['text'] . (!empty($review['reviewed']) && $review['state'] !== 'none' ? ' - last reviewed ' . date('M j, Y', strtotime($review['reviewed'])) : '');
return '<span class="badge rounded-pill bg-' . $tone . '-subtle text-' . $tone . '-emphasis border border-' . $tone . '-subtle fw-normal" title="' . escapeHtml($title) . '">'
. '<i class="' . $icons[$review['state']] . ' me-1"></i>' . escapeHtml($use_text ? $review['text'] : $review['short']) . '</span>';
}
/** The views along the top of the list, and what each one shows. On the services table. */
function serviceViews() {
$active = 'services.service_archived_at IS NULL';
return [
'' => ['label' => 'Active', 'icon' => 'fa-stream', 'where' => $active, 'title' => 'Not archived'],
'attention' => ['label' => 'Needs attention', 'icon' => 'fa-exclamation-triangle', 'where' => "$active AND " . serviceAttentionSql(),
'title' => 'Something it depends on is expiring, out of warranty, out of action or archived', 'alarm' => 'danger'],
'review' => ['label' => 'Review due', 'icon' => 'fa-clipboard-check', 'where' => "$active AND " . serviceReviewDueSql(),
'title' => 'Due for review in the next ' . SERVICE_REVIEW_SOON_DAYS . ' days, or overdue', 'alarm' => 'warning'],
'high' => ['label' => 'High importance', 'icon' => 'fa-thermometer-full', 'where' => "$active AND services.service_importance = 'High'", 'title' => 'Down means the client cannot work'],
'unreviewed' => ['label' => 'No review set', 'icon' => 'fa-calendar', 'where' => "$active AND services.service_review_due IS NULL", 'title' => 'No next review date'],
'starred' => ['label' => 'Starred', 'icon' => 'fa-star', 'where' => "$active AND services.service_favorite = 1"],
'archived' => ['label' => 'Archived', 'icon' => 'fa-archive', 'where' => 'services.service_archived_at IS NOT NULL'],
'all' => ['label' => 'All', 'where' => ''],
];
}
/** SQL: its review is due within SERVICE_REVIEW_SOON_DAYS, or overdue. */
function serviceReviewDueSql($alias = 'services') {
return "($alias.service_review_due IS NOT NULL AND $alias.service_review_due <= CURDATE() + INTERVAL " . SERVICE_REVIEW_SOON_DAYS . " DAY)";
}
/**
* SQL: something it depends on needs attention - the same things
* serviceIssues() lists. On the services table as $alias.
*/
function serviceAttentionSql($alias = 'services') {
$id = "$alias.service_id";
$soon = DOMAIN_SOON_DAYS;
$down = "'" . implode("', '", SERVICE_ASSET_DOWN_STATUSES) . "'";
$user_devices = "'" . implode("', '", SERVICE_USER_DEVICE_TYPES) . "'";
$archived = [];
foreach (['credential', 'contact', 'vendor', 'document', 'domain', 'certificate'] as $type) {
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type];
$archived[] = "EXISTS (SELECT 1 FROM {$relation['table']} l JOIN {$entity['table']} t ON t.{$entity['id']} = l.{$entity['id']}
WHERE l.service_id = $id AND t.{$entity['archived']} IS NOT NULL)";
}
return "(EXISTS (SELECT 1 FROM service_domains sd JOIN domains d ON d.domain_id = sd.domain_id
WHERE sd.service_id = $id AND d.domain_archived_at IS NULL
AND (d.domain_expire < CURDATE() OR (d.domain_auto_renew = 0 AND d.domain_expire <= CURDATE() + INTERVAL $soon DAY)))
OR EXISTS (SELECT 1 FROM service_certificates sc JOIN certificates c ON c.certificate_id = sc.certificate_id
WHERE sc.service_id = $id AND c.certificate_archived_at IS NULL
AND (c.certificate_expire < CURDATE() OR " . certificateSoonSql('c') . " OR " . certificateProblemSql('c') . "))
OR EXISTS (SELECT 1 FROM service_assets sa JOIN assets a ON a.asset_id = sa.asset_id
WHERE sa.service_id = $id AND (a.asset_archived_at IS NOT NULL OR (a.asset_type NOT IN ($user_devices) AND (a.asset_status IN ($down)
OR (a.asset_warranty_expire > '1000-01-01' AND a.asset_warranty_expire < CURDATE())))))
OR " . implode("\n OR ", $archived) . ")";
}
/** SQL for ticketRows(): the tickets raised about a service, and those on any of its assets. */
function serviceTicketsSql($service_id) {
$service_id = intval($service_id);
return "tickets.ticket_id IN (SELECT st.ticket_id FROM service_tickets st WHERE st.service_id = $service_id)
OR tickets.ticket_asset_id IN (SELECT sa.asset_id FROM service_assets sa WHERE sa.service_id = $service_id)
OR tickets.ticket_id IN (SELECT ta.ticket_id FROM ticket_assets ta JOIN service_assets sa ON sa.asset_id = ta.asset_id WHERE sa.service_id = $service_id)";
}
/**
* How much hangs off each service, for the whole page at once:
* [service_id => [asset, credential, domain, certificate, contact, vendor,
* document => count of active ones, 'archived' => linked ones since archived,
* 'open_tickets' => open tickets about it or its assets]]. Credentials only
* count for those who may see them.
*/
function serviceCounts(array $service_ids) {
global $mysqli;
$service_ids = array_values(array_unique(array_filter(array_map('intval', $service_ids))));
$blank = array_fill_keys(SERVICE_LINK_TYPES, 0) + ['archived' => 0, 'open_tickets' => 0];
$counts = array_fill_keys($service_ids, $blank);
if (!$service_ids) {
return $counts;
}
$in = implode(',', $service_ids);
$can_credentials = lookupUserPermission('module_credential') >= 1;
foreach (SERVICE_LINK_TYPES as $type) {
if ($type === 'credential' && !$can_credentials) {
continue;
}
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type];
$sql = mysqli_query($mysqli, "SELECT l.service_id, COALESCE(SUM(t.{$entity['archived']} IS NULL), 0), COALESCE(SUM(t.{$entity['archived']} IS NOT NULL), 0)
FROM {$relation['table']} l JOIN {$entity['table']} t ON t.{$entity['id']} = l.{$entity['id']}
WHERE l.service_id IN ($in) GROUP BY l.service_id");
while ($row = mysqli_fetch_row($sql)) {
$counts[intval($row[0])][$type] = intval($row[1]);
$counts[intval($row[0])]['archived'] += intval($row[2]);
}
}
$sql = mysqli_query($mysqli, "SELECT x.service_id, COUNT(DISTINCT x.ticket_id) FROM (
SELECT st.service_id, st.ticket_id FROM service_tickets st WHERE st.service_id IN ($in)
UNION SELECT sa.service_id, tk.ticket_id FROM service_assets sa JOIN tickets tk ON tk.ticket_asset_id = sa.asset_id WHERE sa.service_id IN ($in)
UNION SELECT sa.service_id, ta.ticket_id FROM service_assets sa JOIN ticket_assets ta ON ta.asset_id = sa.asset_id WHERE sa.service_id IN ($in)
) x JOIN tickets ON tickets.ticket_id = x.ticket_id
WHERE " . TICKET_OPEN_SQL . " AND tickets.ticket_archived_at IS NULL
GROUP BY x.service_id");
while ($row = mysqli_fetch_row($sql)) {
$counts[intval($row[0])]['open_tickets'] = intval($row[1]);
}
return $counts;
}
/**
* What needs attention in what each service depends on, worst first, for
* the whole page at once: [service_id => [['tone' => danger | warning,
* 'icon', 'text', 'type', 'id', 'name'], ...]]. The same things
* serviceAttentionSql() finds.
*/
function serviceIssues(array $service_ids) {
global $mysqli;
$service_ids = array_values(array_unique(array_filter(array_map('intval', $service_ids))));
$issues = array_fill_keys($service_ids, []);
if (!$service_ids) {
return $issues;
}
$in = implode(',', $service_ids);
$soon = DOMAIN_SOON_DAYS;
$sql = mysqli_query($mysqli, "SELECT sd.service_id, d.domain_id, d.domain_name, d.domain_expire, d.domain_auto_renew FROM service_domains sd
JOIN domains d ON d.domain_id = sd.domain_id
WHERE sd.service_id IN ($in) AND d.domain_archived_at IS NULL
AND (d.domain_expire < CURDATE() OR (d.domain_auto_renew = 0 AND d.domain_expire <= CURDATE() + INTERVAL $soon DAY))
ORDER BY d.domain_expire");
while ($row = mysqli_fetch_assoc($sql)) {
$expiry = domainExpiry($row['domain_expire'], $row['domain_auto_renew']);
$issues[intval($row['service_id'])][] = ['tone' => $expiry['state'] === 'expired' ? 'danger' : 'warning', 'icon' => 'fa-globe',
'text' => $row['domain_name'] . ': ' . lcfirst($expiry['text']), 'type' => 'domain', 'id' => intval($row['domain_id']), 'name' => $row['domain_name']];
}
$sql = mysqli_query($mysqli, "SELECT sc.service_id, c.certificate_id, c.certificate_name, c.certificate_domain, c.certificate_expire, c.certificate_issued_at,
c.certificate_check_status, c.certificate_checked_at FROM service_certificates sc
JOIN certificates c ON c.certificate_id = sc.certificate_id
WHERE sc.service_id IN ($in) AND c.certificate_archived_at IS NULL
AND (c.certificate_expire < CURDATE() OR " . certificateSoonSql('c') . " OR " . certificateProblemSql('c') . ")
ORDER BY c.certificate_expire");
while ($row = mysqli_fetch_assoc($sql)) {
$expiry = certificateExpiry($row);
$status = CERTIFICATE_CHECK_STATES[(string) $row['certificate_check_status']] ?? null;
if ($expiry && $expiry['state'] !== 'active') {
$text = lcfirst($expiry['text']);
$tone = $expiry['state'] === 'expired' ? 'danger' : 'warning';
} else {
$text = $status ? lcfirst($status['label']) . ' - ' . lcfirst($status['text']) : 'the last check found a problem';
$tone = $status && $status['tone'] === 'danger' ? 'danger' : 'warning';
}
$issues[intval($row['service_id'])][] = ['tone' => $tone, 'icon' => 'fa-lock', 'text' => $row['certificate_name'] . ': ' . $text,
'type' => 'certificate', 'id' => intval($row['certificate_id']), 'name' => $row['certificate_name']];
}
$down = "'" . implode("', '", SERVICE_ASSET_DOWN_STATUSES) . "'";
$user_devices = "'" . implode("', '", SERVICE_USER_DEVICE_TYPES) . "'";
$sql = mysqli_query($mysqli, "SELECT sa.service_id, a.asset_id, a.asset_name, a.asset_status, a.asset_warranty_expire, a.asset_archived_at FROM service_assets sa
JOIN assets a ON a.asset_id = sa.asset_id
WHERE sa.service_id IN ($in) AND (a.asset_archived_at IS NOT NULL OR (a.asset_type NOT IN ($user_devices) AND (a.asset_status IN ($down)
OR (a.asset_warranty_expire > '1000-01-01' AND a.asset_warranty_expire < CURDATE()))))
ORDER BY a.asset_name");
while ($row = mysqli_fetch_assoc($sql)) {
$service_id = intval($row['service_id']);
$base = ['type' => 'asset', 'id' => intval($row['asset_id']), 'name' => $row['asset_name'], 'icon' => 'fa-desktop'];
if ($row['asset_archived_at']) {
$issues[$service_id][] = $base + ['tone' => 'warning', 'text' => $row['asset_name'] . ': archived, but still listed - unlink it or link what replaced it', 'archived' => true];
} elseif (in_array($row['asset_status'], SERVICE_ASSET_DOWN_STATUSES, true)) {
$issues[$service_id][] = $base + ['tone' => $row['asset_status'] === 'Out for Repair' ? 'warning' : 'danger', 'text' => $row['asset_name'] . ': ' . strtolower($row['asset_status'])];
} else {
$warranty = assetWarranty($row['asset_warranty_expire']);
$issues[$service_id][] = $base + ['tone' => 'warning', 'text' => $row['asset_name'] . ': warranty ' . lcfirst($warranty['text'])];
}
}
// Anything else linked that has since been archived - the map no longer matches
foreach (['credential', 'contact', 'vendor', 'document', 'domain', 'certificate'] as $type) {
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type];
$sql = mysqli_query($mysqli, "SELECT l.service_id, t.{$entity['id']}, t.{$entity['name']} FROM {$relation['table']} l
JOIN {$entity['table']} t ON t.{$entity['id']} = l.{$entity['id']}
WHERE l.service_id IN ($in) AND t.{$entity['archived']} IS NOT NULL ORDER BY t.{$entity['name']}");
while ($row = mysqli_fetch_row($sql)) {
$issues[intval($row[0])][] = ['tone' => 'warning', 'icon' => $entity['icon'], 'text' => $row[2] . ': ' . $entity['label'] . ' archived, but still listed - unlink it or link what replaced it',
'type' => $type, 'id' => intval($row[1]), 'name' => $row[2], 'archived' => true];
}
}
foreach ($issues as &$list) {
usort($list, function ($a, $b) {
return ($a['tone'] === 'danger' ? 0 : 1) <=> ($b['tone'] === 'danger' ? 0 : 1);
});
}
unset($list);
return $issues;
}
/** The issues as a list of soft lines - on the service page and its quick look. */
function serviceIssuesHtml(array $issues, $limit = 0) {
if (!$issues) {
return '';
}
$shown = $limit ? array_slice($issues, 0, $limit) : $issues;
$html = '<ul class="list-unstyled mb-0 itflow-service-issues">';
foreach ($shown as $issue) {
$html .= '<li class="text-' . $issue['tone'] . '-emphasis"><i class="fas fa-fw ' . ($issue['tone'] === 'danger' ? 'fa-exclamation-circle' : 'fa-exclamation-triangle') . ' me-1"></i>'
. '<i class="fas fa-fw ' . $issue['icon'] . ' text-body-secondary me-1"></i>' . escapeHtml($issue['text']) . '</li>';
}
if ($limit && count($issues) > $limit) {
$html .= '<li class="text-body-secondary small">and ' . (count($issues) - $limit) . ' more</li>';
}
return $html . '</ul>';
}
/**
* Everything of one type linked to a service, archived ones included (they
* are flagged) - the service page's tabs. Rows as linkedRecords() gives them,
* plus 'archived_at'.
*/
function serviceLinked($service_id, $type) {
global $mysqli;
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type] ?? null;
if (!$relation || !$entity) {
return [];
}
$service_id = intval($service_id);
$extra = linkDisplayColumns($type);
$sql = mysqli_query($mysqli, "SELECT t.{$entity['id']} AS id, t.{$entity['name']} AS name, t.{$entity['archived']} AS archived_at" . ($extra ? ", $extra" : '') . "
FROM {$relation['table']} l
JOIN {$entity['table']} t ON t.{$entity['id']} = l.{$entity['id']}
WHERE l.service_id = $service_id
ORDER BY t.{$entity['archived']} IS NOT NULL, t.{$entity['name']} ASC");
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$rows[] = $row;
}
return $rows;
}
/**
* The services an asset, contact, vendor, domain, certificate, credential or
* document is part of - active ones, for the "Services" sections around
* the app. Raw rows.
*/
function servicesFor($type, $id) {
global $mysqli;
$relation = linkRelation('service', $type);
$entity = LINK_ENTITIES[$type] ?? null;
if (!$relation || !$entity) {
return [];
}
$id = intval($id);
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_description, service_category, service_importance,
service_review_due, service_reviewed_at, service_client_id
FROM {$relation['table']} l JOIN services ON services.service_id = l.service_id
WHERE l.{$entity['id']} = $id AND service_archived_at IS NULL
ORDER BY FIELD(service_importance, 'High', 'Medium', 'Low'), service_name");
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$rows[] = $row;
}
return $rows;
}
/**
* Services as rows - tile, name opening the page, category and description,
* importance - for the Services tabs on the asset, contact and vendor pages
* and the domain and certificate quick looks. $unlink($row) gives the unlink
* URL for a row, or '' for none.
*/
function serviceRowsHtml(array $rows, $unlink = null) {
if (!$rows) {
return '';
}
$html = '<ul class="list-unstyled mb-0 itflow-links">';
foreach ($rows as $row) {
$service_id = intval($row['service_id']);
$detail = implode(' · ', array_filter([$row['service_category'], $row['service_description']]));
$remove = $unlink ? $unlink($row) : '';
$html .= '<li class="itflow-link-row">' . serviceTile($row['service_category'], 'sm')
. '<div class="min-w-0 flex-grow-1"><div class="d-flex align-items-center gap-2 min-w-0"><a class="text-truncate fw-semibold" href="' . escapeHtml(serviceUrl($service_id, $row['service_client_id'])) . '">' . escapeHtml($row['service_name']) . '</a>'
. '<a class="ajax-modal text-body-secondary small" href="#" data-modal-size="lg" data-modal-url="modals/service/service.php?id=' . $service_id . '" title="Quick look"><i class="fas fa-eye"></i></a></div>'
. ($detail !== '' ? '<div class="small text-body-secondary text-truncate">' . escapeHtml($detail) . '</div>' : '') . '</div>'
. '<span class="ms-2 text-nowrap">' . serviceImportancePill($row['service_importance']) . '</span>'
. ($remove ? '<a class="itflow-link-remove confirm-link" href="' . escapeHtml($remove) . '" title="Unlink service" data-confirm-text="' . escapeHtml($row['service_name']) . ' stops listing it."><i class="fas fa-unlink"></i></a>' : '')
. '</li>';
}
return $html . '</ul>';
}
/** Web links to it - the logins' and its assets' URLs, each once: [['url', 'label', 'icon'], ...]. Raw. */
function serviceUrls($service_id, $with_credentials) {
global $mysqli;
$service_id = intval($service_id);
$urls = [];
$sql = mysqli_query($mysqli, "SELECT asset_uri, asset_uri_2 FROM service_assets JOIN assets ON assets.asset_id = service_assets.asset_id
WHERE service_id = $service_id AND asset_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql)) {
foreach ([$row['asset_uri'], $row['asset_uri_2']] as $uri) {
$urls[] = $uri;
}
}
if ($with_credentials) {
$sql = mysqli_query($mysqli, "SELECT credential_uri, credential_uri_2 FROM service_credentials JOIN credentials ON credentials.credential_id = service_credentials.credential_id
WHERE service_id = $service_id AND credential_archived_at IS NULL");
while ($row = mysqli_fetch_assoc($sql)) {
foreach ([$row['credential_uri'], $row['credential_uri_2']] as $uri) {
$urls[] = $uri;
}
}
}
$out = [];
foreach ($urls as $uri) {
$uri = trim(html_entity_decode((string) $uri, ENT_QUOTES, 'UTF-8'));
if ($uri === '' || isset($out[$uri])) {
continue;
}
$scheme = strtolower((string) parse_url($uri, PHP_URL_SCHEME));
if ($scheme === '' && preg_match('/^[a-z0-9.-]+\.[a-z]{2,}(\/|$)/i', $uri)) {
$uri = "https://$uri";
} elseif (!in_array($scheme, ['http', 'https'], true)) {
// rdp://, ssh:// and the rest open from the asset or login itself
continue;
}
$host = preg_replace('/^www\./i', '', (string) parse_url($uri, PHP_URL_HOST));
$out[$uri] = ['url' => $uri, 'label' => $host !== '' ? $host . rtrim((string) parse_url($uri, PHP_URL_PATH), '/') : assetLinkLabel($uri), 'icon' => assetLinkIcon($uri)];
}
return array_values($out);
}
/** Its history from the audit log, newest first. */
function serviceHistory($service_id, $limit = 50) {
global $mysqli;
$service_id = intval($service_id);
$limit = max(1, intval($limit));
$sql = mysqli_query($mysqli, "SELECT log_action, log_description, log_created_at, user_name, user_avatar, user_id FROM logs
LEFT JOIN users ON user_id = log_user_id
WHERE log_type = 'Service' AND log_entity_id = $service_id
ORDER BY log_id DESC LIMIT $limit");
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$rows[] = $row;
}
return $rows;
}
/**
* The fields of the add and edit forms, checked, as a SET clause - or ''
* with $error. Notes are plain text. $current is the row being edited.
*/
function serviceFormSet($post, &$error = '', $current = null) {
$name = trim((string) ($post['name'] ?? ''));
if ($name === '') {
$error = 'A service needs a name.';
return '';
}
$importance = in_array($post['importance'] ?? '', SERVICE_IMPORTANCE, true) ? $post['importance'] : 'Medium';
$interval = intval($post['review_interval'] ?? 0);
if (!isset(SERVICE_REVIEW_INTERVALS[$interval])) {
$interval = 0;
}
// The next review: the date given, or the schedule from the last review (or today)
$review_due = trim((string) ($post['review_due'] ?? ''));
if ($review_due !== '' && !DateTime::createFromFormat('!Y-m-d', $review_due)) {
$review_due = '';
}
if ($review_due === '' && $interval) {
$review_due = serviceNextReview($interval, $current['service_reviewed_at'] ?? null);
if ($review_due < date('Y-m-d')) {
$review_due = date('Y-m-d');
}
}
return "service_name = '" . escapeSql(mb_substr($name, 0, 200)) . "',
service_description = '" . escapeSql(mb_substr(trim((string) ($post['description'] ?? '')), 0, 200)) . "',
service_category = '" . escapeSql(mb_substr(trim((string) ($post['category'] ?? '')), 0, 50)) . "',
service_importance = '$importance',
service_backup = '" . escapeSql(mb_substr(trim((string) ($post['backup'] ?? '')), 0, 500)) . "',
service_notes = '" . escapeSql((string) ($post['notes'] ?? $post['note'] ?? '')) . "',
service_review_interval = $interval,
service_review_due = " . ($review_due !== '' ? "'$review_due'" : 'NULL');
}
/** Mark it reviewed now: the next review falls due on $next_due, or after its interval. Logged with $note. */
function serviceMarkReviewed($row, $next_due = '', $note = '') {
global $mysqli, $session_name;
$service_id = intval($row['service_id']);
if ($next_due === '' || !DateTime::createFromFormat('!Y-m-d', $next_due)) {
$next_due = serviceNextReview($row['service_review_interval']);
}
mysqli_query($mysqli, "UPDATE services SET service_reviewed_at = NOW(), service_review_due = " . ($next_due ? "'$next_due'" : 'NULL') . " WHERE service_id = $service_id");
$note = trim(preg_replace('/\s+/', ' ', strip_tags((string) $note)));
logAudit("Service", "Review", "$session_name reviewed service " . escapeSql($row['service_name'])
. ($next_due ? ' - next review ' . $next_due : '') . ($note !== '' ? ': ' . escapeSql(mb_substr($note, 0, 400)) : ''), intval($row['service_client_id']), $service_id);
return $next_due;
}
function serviceArchive($row) {
global $mysqli, $session_name;
$service_id = intval($row['service_id']);
mysqli_query($mysqli, "UPDATE services SET service_archived_at = NOW() WHERE service_id = $service_id");
logAudit("Service", "Archive", "$session_name archived service " . escapeSql($row['service_name']), intval($row['service_client_id']), $service_id);
}
function serviceRestore($row) {
global $mysqli, $session_name;
$service_id = intval($row['service_id']);
mysqli_query($mysqli, "UPDATE services SET service_archived_at = NULL WHERE service_id = $service_id");
logAudit("Service", "Restore", "$session_name restored service " . escapeSql($row['service_name']), intval($row['service_client_id']), $service_id);
}
/** Delete for good - its links and ticket links go with it (ON DELETE CASCADE); the records it linked to stay. */
function serviceDelete($row) {
global $mysqli, $session_name;
$service_id = intval($row['service_id']);
mysqli_query($mysqli, "DELETE FROM services WHERE service_id = $service_id");
logAudit("Service", "Delete", "$session_name deleted service " . escapeSql($row['service_name']), intval($row['service_client_id']), $service_id);
}
/** Link tickets to a service - the client's own only. Returns how many were new. */
function serviceLinkTickets($service_id, $client_id, array $ticket_ids) {
global $mysqli;
$service_id = intval($service_id);
$client_id = intval($client_id);
$added = 0;
foreach (array_unique(array_filter(array_map('intval', $ticket_ids))) as $ticket_id) {
mysqli_query($mysqli, "INSERT IGNORE INTO service_tickets (service_id, ticket_id)
SELECT $service_id, ticket_id FROM tickets WHERE ticket_id = $ticket_id AND ticket_client_id = $client_id");
$added += max(0, mysqli_affected_rows($mysqli));
}
return $added;
}
/**
* The services a ticket is about: the ones it was raised for (linked) and
* the ones its assets are part of - [service_id => row + 'linked' => bool].
*/
function ticketServices($ticket_id) {
global $mysqli;
$ticket_id = intval($ticket_id);
$sql = mysqli_query($mysqli, "SELECT services.service_id, service_name, service_category, service_importance, service_client_id,
MAX(x.linked) AS linked
FROM (
SELECT st.service_id, 1 AS linked FROM service_tickets st WHERE st.ticket_id = $ticket_id
UNION ALL SELECT sa.service_id, 0 FROM service_assets sa JOIN tickets t ON t.ticket_asset_id = sa.asset_id WHERE t.ticket_id = $ticket_id
UNION ALL SELECT sa.service_id, 0 FROM service_assets sa JOIN ticket_assets ta ON ta.asset_id = sa.asset_id WHERE ta.ticket_id = $ticket_id
) x JOIN services ON services.service_id = x.service_id
WHERE service_archived_at IS NULL
GROUP BY services.service_id
ORDER BY FIELD(service_importance, 'High', 'Medium', 'Low'), service_name");
$rows = [];
while ($row = mysqli_fetch_assoc($sql)) {
$row['linked'] = (bool) intval($row['linked']);
$rows[intval($row['service_id'])] = $row;
}
return $rows;
}
/**
* The details a ticket about the service starts with - what it is, what it
* runs on, who to call, how it comes back - plain text, one fact a line.
*/
function serviceTicketDetails($row, $assets, $vendors) {
$lines = ['Service: ' . $row['service_name'] . ' (' . $row['service_importance'] . ' importance)'];
if ($assets) {
$lines[] = 'Runs on: ' . implode(', ', array_column(array_filter($assets, function ($a) { return !$a['archived_at']; }), 'name'));
}
if ($vendors) {
$lines[] = 'Vendors: ' . implode(', ', array_column(array_filter($vendors, function ($v) { return !$v['archived_at']; }), 'name'));
}
if (trim((string) $row['service_backup']) !== '') {
$lines[] = 'Backup and recovery: ' . $row['service_backup'];
}
$lines[] = '';
$lines[] = 'What is happening:';
return implode("\n", $lines);
}

View File

@@ -278,7 +278,7 @@ function quickPick($field, $id, $current, $inner, $style = 'list', $status_id =
'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',
'contact_location' => 'Change location'
'contact_location' => 'Change location', 'service_importance' => 'Change importance'
];
// 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

@@ -319,7 +319,7 @@ function vendorCounts($vendors) {
}
}
$joins = [
'service' => ['service_vendors', 'services', 'service_id', 'service_client_id IN (' . $client_in . ')'],
'service' => ['service_vendors', 'services', 'service_id', 'service_client_id IN (' . $client_in . ') AND service_archived_at IS NULL'],
'credential' => ['vendor_credentials', 'credentials', 'credential_id', 'credential_archived_at IS NULL'],
'document' => ['vendor_documents', 'documents', 'document_id', 'document_archived_at IS NULL'],
'file' => ['vendor_files', 'files', 'file_id', 'file_archived_at IS NULL'],