From ade9d5aac3c900d9b7c2b2f19d41aa872d2efde8 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 15 Oct 2026 17:32:09 -0400 Subject: [PATCH] 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) --- admin/database_updates/2.8.7.php | 59 ++ admin/post/demo_data_model.php | 12 +- agent/ajax.php | 43 +- agent/asset.php | 51 +- agent/calendar.php | 14 + agent/client_overview.php | 42 +- agent/contact.php | 41 +- agent/includes/client_overview_side_nav.php | 2 +- agent/includes/inc_all_client.php | 2 +- agent/modals/asset/asset.php | 12 + agent/modals/asset/asset_link_service.php | 71 +- agent/modals/certificate/certificate.php | 27 +- agent/modals/contact/contact_link_service.php | 70 +- agent/modals/credential/credential.php | 6 +- agent/modals/document/document_add.php | 5 +- agent/modals/domain/domain.php | 27 +- agent/modals/link/link.php | 32 +- agent/modals/service/service.php | 409 ++++------ agent/modals/service/service_add.php | 235 +----- agent/modals/service/service_bulk_edit.php | 74 ++ agent/modals/service/service_edit.php | 323 +------- agent/modals/service/service_export.php | 97 +++ agent/modals/service/service_form.php | 179 +++++ agent/modals/service/service_link_ticket.php | 63 ++ agent/modals/service/service_review.php | 86 ++ agent/modals/ticket/ticket_add.php | 41 +- agent/modals/ticket/ticket_link_service.php | 76 ++ agent/post/asset.php | 60 -- agent/post/client.php | 51 ++ agent/post/contact.php | 60 -- agent/post/document.php | 10 +- agent/post/link.php | 6 +- agent/post/service.php | 620 +++++++++++---- agent/post/ticket.php | 9 + agent/service.php | 716 +++++++++++++++++ agent/services.php | 535 +++++++++---- agent/ticket.php | 29 +- agent/vendor.php | 32 +- api/v1/enforce_api_rbac.php | 1 + api/v1/services/read.php | 30 + cron/nightly_tasks.php | 12 + css/itflow_custom.css | 67 ++ db.sql | 44 +- functions.php | 1 + functions/certificate.php | 13 - functions/client_overview.php | 48 +- functions/credential.php | 6 +- functions/dashboard.php | 13 + functions/domain.php | 13 - functions/export.php | 21 + functions/links.php | 83 +- functions/notifications.php | 3 +- functions/search.php | 23 + functions/service.php | 734 ++++++++++++++++++ functions/ticket_fields.php | 2 +- functions/vendor.php | 2 +- 56 files changed, 3750 insertions(+), 1593 deletions(-) create mode 100644 admin/database_updates/2.8.7.php create mode 100644 agent/modals/service/service_bulk_edit.php create mode 100644 agent/modals/service/service_export.php create mode 100644 agent/modals/service/service_form.php create mode 100644 agent/modals/service/service_link_ticket.php create mode 100644 agent/modals/service/service_review.php create mode 100644 agent/modals/ticket/ticket_link_service.php create mode 100644 agent/service.php create mode 100644 api/v1/services/read.php create mode 100644 functions/service.php diff --git a/admin/database_updates/2.8.7.php b/admin/database_updates/2.8.7.php new file mode 100644 index 000000000..3f4807c35 --- /dev/null +++ b/admin/database_updates/2.8.7.php @@ -0,0 +1,59 @@ + '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`)"); diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index ca966f739..64f0825ac 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -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), diff --git a/agent/ajax.php b/agent/ajax.php index 08cdc0316..acb1e3c5f 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -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') { diff --git a/agent/asset.php b/agent/asset.php index 7276a5f57..b55dcdeb8 100644 --- a/agent/asset.php +++ b/agent/asset.php @@ -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 that depend on this asset. + Services that run on it - when it is down, so are they.
-
- - - - - - - - - - - - - - - - - - - -
ServiceCategoryImportance
- -
-
- - - -
-
+
Not part of any service.
diff --git a/agent/calendar.php b/agent/calendar.php index f41fec130..b3e7f9f67 100644 --- a/agent/calendar.php +++ b/agent/calendar.php @@ -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)) { diff --git a/agent/client_overview.php b/agent/client_overview.php index 34c74f5f1..99cacc4c4 100644 --- a/agent/client_overview.php +++ b/agent/client_overview.php @@ -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, - + @@ -316,6 +318,38 @@ $money_format = function ($amount) use ($currency_format, $client_currency_code,
+ +
+
+ +
+ $service) { + $service_issues = $client_services['issues'][$service_id]; + $service_review = serviceReview($service); + $service_danger = in_array('danger', array_column($service_issues, 'tone'), true); ?> + + + + + + + + + + + + + + + +
+
+
+ +
diff --git a/agent/contact.php b/agent/contact.php index e00a51b07..d46419410 100644 --- a/agent/contact.php +++ b/agent/contact.php @@ -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) { License - - Service - + + + Service + + Document @@ -722,30 +720,17 @@ if (!$can_support) {
- Services they are a contact for. - + Services they own or are the contact for at the client. +
-
- -
- -
- -
-
- - - - -
- -
+
Not a contact for any service.
diff --git a/agent/includes/client_overview_side_nav.php b/agent/includes/client_overview_side_nav.php index 868611b08..4872205ce 100644 --- a/agent/includes/client_overview_side_nav.php +++ b/agent/includes/client_overview_side_nav.php @@ -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') . "")); diff --git a/agent/includes/inc_all_client.php b/agent/includes/inc_all_client.php index e0f22e319..aac10a3f7 100644 --- a/agent/includes/inc_all_client.php +++ b/agent/includes/inc_all_client.php @@ -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")); diff --git a/agent/modals/asset/asset.php b/agent/modals/asset/asset.php index 90369188a..00b4d2652 100644 --- a/agent/modals/asset/asset.php +++ b/agent/modals/asset/asset.php @@ -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();
+ +
+ + +
+ +
diff --git a/agent/modals/asset/asset_link_service.php b/agent/modals/asset/asset_link_service.php index 43b81f3ae..dfef804ae 100644 --- a/agent/modals/asset/asset_link_service.php +++ b/agent/modals/asset/asset_link_service.php @@ -1,67 +1,12 @@ - - -
- - - - -
- -
- -
Services that use it
- +
+ + + +

No service is linked to it.

+ diff --git a/agent/modals/contact/contact_link_service.php b/agent/modals/contact/contact_link_service.php index 0958bd6ce..3d2f89975 100644 --- a/agent/modals/contact/contact_link_service.php +++ b/agent/modals/contact/contact_link_service.php @@ -1,66 +1,12 @@ - - -
- - - - -
- - For - Link a vendor or license + Link a vendor, license or service