From 95dd3ef9c55b4b2b31e1c8280174afc55bf9d1df Mon Sep 17 00:00:00 2001 From: johnnyq Date: Sat, 17 Oct 2026 15:17:14 -0400 Subject: [PATCH] Tags stage 2: tags on five more record kinds (tickets, documents, [kind], [kind], [kind]) working like the other seven with tag pills and + picker on list, page and quick look, Tags field in New and Edit, list tag filter and tag-name search, Bulk Action Tags, export tag filter and Tags column; tickets list shows + only once a ticket has a tag, Tags under More filters with its own chip, board cards show tags, tag changes written to ticket history and merging moves non-archived tags; document tag filter in client Files and at top level across all folders excluding uploads, bulk Tags only tags ticked documents, cross-client document tags open a global search; global search matches tag names, shows the matching tag on each result and adds a Tags group; API tags read, update and create endpoints plus a tags list on every record read, per-kind permission checks and tag creation limited to admin keys; Tags starter pack and demo data cover the new kinds; changelog breaking change for tag-name matching in searches and upgrade note now 2.7.9 to 3.1.4; stage 1 tag test updated for twelve kinds --- CHANGELOG.md | 27 ++- admin/database_updates/3.1.4.php | 29 +++ admin/post/demo_data_model.php | 20 ++ admin/post/starter_content_model.php | 40 +++- admin/tags.php | 2 +- agent/ajax.php | 6 + agent/document.php | 4 + agent/files.php | 39 +++- agent/global_search.php | 8 + agent/license.php | 4 + agent/modals/document/document_form.php | 7 +- agent/modals/network/network.php | 5 + agent/modals/network/network_export.php | 3 + agent/modals/network/network_form.php | 5 +- agent/modals/service/service.php | 4 + agent/modals/service/service_export.php | 3 + agent/modals/service/service_form.php | 4 + agent/modals/software/software.php | 4 + agent/modals/software/software_export.php | 3 + agent/modals/software/software_form.php | 5 +- agent/modals/ticket/ticket.php | 5 + agent/modals/ticket/ticket_add.php | 4 + agent/modals/ticket/ticket_edit.php | 4 + agent/modals/ticket/ticket_export.php | 3 + agent/network.php | 4 + agent/networks.php | 25 ++- agent/post/document.php | 7 + agent/post/network.php | 16 +- agent/post/service.php | 15 +- agent/post/software.php | 16 +- agent/post/ticket.php | 28 ++- agent/service.php | 4 + agent/services.php | 30 ++- agent/software.php | 48 +++- agent/ticket.php | 5 + agent/ticket_kanban.php | 5 + agent/ticket_list.php | 5 + agent/tickets.php | 28 ++- api/v1/assets/read.php | 1 + api/v1/clients/read.php | 1 + api/v1/contacts/read.php | 1 + api/v1/credentials/read.php | 1 + api/v1/documents/read.php | 1 + api/v1/domains/read.php | 1 + api/v1/enforce_api_rbac.php | 5 +- api/v1/locations/read.php | 1 + api/v1/networks/read.php | 1 + api/v1/read_output.php | 5 + api/v1/services/read.php | 1 + api/v1/software/read.php | 1 + api/v1/tags/create.php | 51 +++++ api/v1/tags/read.php | 96 ++++++++ api/v1/tags/tags_model.php | 46 ++++ api/v1/tags/update.php | 81 +++++++ api/v1/tickets/read.php | 1 + api/v1/vendors/read.php | 1 + css/itflow_custom.css | 30 +++ db.sql | 85 +++++++ functions/export.php | 6 +- functions/search.php | 113 ++++++++-- functions/tags.php | 261 +++++++++++++++++++++- js/global_search.js | 44 +++- js/tag_picker.js | 11 +- 63 files changed, 1236 insertions(+), 84 deletions(-) create mode 100644 admin/database_updates/3.1.4.php create mode 100644 api/v1/tags/create.php create mode 100644 api/v1/tags/read.php create mode 100644 api/v1/tags/tags_model.php create mode 100644 api/v1/tags/update.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 0fa168d91..75104570a 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,9 +6,9 @@ This file documents all notable changes made to ITFlow. ### Upgrading to 26.11 -Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.1.3) in the same pass. Nothing else is required. +Update from Maintenance > Update — Queue Update hands the job to cron, which updates the files and applies this release's database changes (2.7.9 to 3.1.4) in the same pass. Nothing else is required. -This is a big release, with thirty-four database steps in one go, so take a backup before you update. +This is a big release, with thirty-five database steps in one go, so take a backup before you update. The update also clears out data that deletes in older versions left behind, all of it pointing at something that no longer exists: @@ -33,7 +33,7 @@ Every account is given a kind - checking, savings, credit card, cash or payment Taxes keep their names and rates, now kept to four decimal places. No client has a rate of its own or is tax exempt, and there is no default rate, so new lines start untaxed as before until you pick one in Admin > Taxes. Billed time, trips and expenses stay untaxed until you switch them on there. Discounts now come off before tax on invoices and quotes that are still open, the next time they are edited (see Breaking Changes, Taxes). No expense has tax recorded on it until you add it, so Tax Collected shows no tax paid on purchases for the months before. -Tags keep their names, colors, icons and records. A color saved as a word, such as dark or primary, becomes the color it stands for, a short one such as #abc is written out in full, and a tag with no color, or one that isn't a color, turns grey, so its pills can be read (see Bug Fixes). An icon saved with `fas fa-` in front keeps just its name. A tag archived in an older version now counts as archived (see Breaking Changes, Tags). +Tags keep their names, colors, icons and records. A color saved as a word, such as dark or primary, becomes the color it stands for, a short one such as #abc is written out in full, and a tag with no color, or one that isn't a color, turns grey, so its pills can be read (see Bug Fixes). An icon saved with `fas fa-` in front keeps just its name. A tag archived in an older version now counts as archived (see Breaking Changes, Tags). Licenses, services, networks, documents and tickets can now be tagged too, and start with no tags - the Tags pack in Maintenance > Starter Content adds a few for each. If you are coming from 26.08 or earlier, the database update still has to be run from the command line one time, exactly as described under Upgrading to 26.09 below. @@ -136,6 +136,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run - A tag's name is now unique within its kind, in any case: a second client tag called VIP can't be made, though an asset tag can be. Tags already named alike keep their names. Typing a name that exists into a record form picks that tag. - A tag that a recurring invoice line counts users or devices by can't be deleted. Archive it, or merge it into another tag, which moves the line along with it. - Pills now have dark text on light colors such as yellow and light blue, where every pill had white text. + - The search box at the top, and the license, service, network, ticket and Files searches, also match tag names, so a search can bring back records whose own details don't have the words in them. In the search box and on its full results page, the tag that matched shows next to each. - Notifications now follow access too. An agent only sees notifications for clients and areas they can open, so someone without sales access no longer sees invoice and quote notifications. - Drop-downs: Tom Select is gone, replaced by ITFlow's own picker. It works the way you are used to: type to search, tick several in a multi-select, and type a new value in fields that allow it, such as ticket watchers. See Developer Updates if you have custom pages that used Tom Select. - Several small windows are gone because the change is now made where the value is shown: @@ -753,7 +754,7 @@ If you are coming from 26.08 or earlier, the database update still has to be run - API: clients take `client_default_tax_id`, `client_tax_exempt`, `client_tax_exempt_number` and `client_tax_exempt_expires`, and a new invoice line takes `tax_id` `default` for the client's usual rate. A new endpoint reads the taxes with their parts. Invoices and quotes add their subtotal, tax, tax by part and registration numbers, invoice lines name their rate, and expenses include their tax. - Demo data: both taxes have a registration number, Allegheny County Sales Tax is made of the state's 6% - named PA Sales Tax, so Tax Collected adds the two up together - and the county's 1%, each client has its rate, the church and the charter school are tax exempt, one with a certificate that has run out, and what the company buys for its own use pays sales tax. - **Tags** (rebuilt) - - Admin > Tags lists each kind's tags - clients, locations, contacts, credentials, assets, vendors and domains, down the side with how many each has. Each tag shows as it looks on a record, with its description, how many records have it (and how many of those are archived), opening that list filtered by it, and the recurring invoice lines that count users or devices by it. + - Admin > Tags lists each kind's tags - clients, locations, contacts, credentials, assets, vendors, domains, licenses, services, networks, documents and tickets, down the side with how many each has. Each tag shows as it looks on a record, with its description, how many records have it (and how many of those are archived), opening that list filtered by it, and the recurring invoice lines that count users or devices by it. - Search by name or description, sort by name or by most used, and Current and Archived tabs. - Each tag has Edit, Merge into..., a link to its records, Archive or Restore, and Delete, which asks first and says how many records lose the tag. Tick several for Merge into one, Archive or Restore, and Delete. - The tag window shows the tag as it will look while you change it: @@ -764,6 +765,15 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Merge moves every record with the merged tags onto the one you keep, once each, and the recurring invoice lines that count by them count by it. The others are deleted. - Record forms: an admin types a new tag's name into the Tags field and picks Add or presses Enter, and the tag is made, with the next color along, when the record is saved - nothing reloads and nothing typed is lost. Typing the name of an archived tag brings it back. - A recurring invoice line counting by a tag keeps it in its window once the tag is archived, or when the client no longer has anything with it, so saving the line doesn't drop it. + - Licenses, services, networks, documents and tickets take tags, like the other seven kinds: + - their lists show each one's tags with the + to change them (tickets show the + once a ticket has a tag), filter by tag and find tags by name in the search, and Bulk Action has Tags + - their pages and quick looks show the tags, with the + to change them, and their New and Edit windows have a Tags field + - their exports filter by tag and can add a Tags column + - Files: documents take tags. Filtering by a tag shows the documents with it - from every folder at the top level, like a search - and no uploads. Bulk Action > Tags tags the documents ticked and leaves uploads alone. + - Tickets: Tags is in the More filters, shown as a chip like the others, and the board's cards show their tags. Changing a ticket's tags is written in its history. Merging a ticket into another moves its tags over too, apart from archived ones. + - Search finds records by their tags: searching VIP finds the clients, assets or tickets tagged VIP, with the tag next to each. A Tags group lists the tags that match, each in its color, opening its list filtered by it - or for a document tag, the search for it, as documents are listed one client at a time. + - API: read the tags, one record's tags or the records with a tag, set a record's tags or add and take some off, and make a tag (admin keys only). Every record read now includes its tags. + - Starter Content: the Tags pack has tags for licenses, services, networks, documents and tickets - We Resell, Managed, PCI, Runbook, Escalated and so on. Demo data tags its licenses, services, documents and tickets with them. ### Bug Fixes @@ -1222,6 +1232,15 @@ If you are coming from 26.08 or earlier, the database update still has to be run - Removed: `agent/post/tag.php` and `agent/post/tag_model.php` (an older copy of `add_tag` for the window opened from agent pages), and `admin/post/tag_model.php`. - `agent/modals/billing/billing_item.php` adds a seat line's own tag to its choices when `recurringSeatOptions()` leaves it out. - CSS: `.itflow-tag` takes its text color from `--itflow-tag-text`; new `.itflow-tag-swatch`, `.itflow-tag-icons`, `.itflow-tag-icon` and `.itflow-tag-icon-custom`. +- Tags on more records (database 3.1.4): + - New link tables `software_tags`, `service_tags`, `network_tags`, `document_tags` and `ticket_tags` - the record's id and `tag_id`, keyed together and on `tag_id`, gone with the record or the tag. Tag types 8 (license - the `software` table), 9 (service), 10 (network), 11 (document) and 12 (ticket) in `tagKinds()` and `tagEntity()`; a document's `client_list` says its list (`files.php`) is one client's. + - `functions/tags.php`: `tagListUrl($entity, $tag)` (the list filtered by it, or `global_search.php?query=` for documents), `tagFilterIds()` (`?tags[]=`), `tagFilterSql($entity, $ids, $column)`, `tagSearchSql($entity, $like, $column)`, `tagFilterOptionsHtml($entity, $selected, $records_where)` (the tags on records the list can show, its client joined, plus those chosen), `tagOptionHtml($row, $selected)`, `tagFormFieldHtml($entity, $selected, $placeholder)` (with the `tags_form` marker), `tagIdsForRecord()`, `tagChangeText($before, $after)`, `tagExportFieldHtml()`, `tagNamesSql()` and `tagExportFilterSql($entity, $values, &$summary, $column)`, `tagMatchSql()` and `tagSearchSpec()` for search, and `tagApiRow()` and `tagApiAttach($rows, $entity)` for the API. `tagsForRecords()` adds `tag_type`. + - Licenses, services, networks, documents and tickets: the lists read `tags[]`; the forms post `tags[]` and `tags_form`; `add_software`, `add_service`, `add_network`, `add_document` and `add_ticket` save them with `tagSetForRecord()`, and the edits do when `tags_form` is posted. `edit_ticket` writes the change to the ticket's history, as does the picker (`agent/ajax.php` `tag_picker_set`) for a ticket. `ticketMergeInto()` copies the merged ticket's tags that aren't archived. + - Exports: `tags[]` filters, and `software_tags`, `service_tags`, `network_tags` and `ticket_tags` columns, off until ticked. + - `js/tag_picker.js`: `data-tag-bulk="document_ids[]"` takes only the ticked boxes of that name. + - Global search: a group's `tags` (`[entity, id column]`) also matches its records' tag names and hands back each item's matching `tags` (`name`, `color`, `text`, `icon`); the new `tags` group (`module` null - it checks each kind's module in its own query) gives each item its `tag`. CSS: `.itflow-search-tag-icon`, `.itflow-search-item-text` and `.itflow-search-item-tags`. + - API: `api/v1/tags/read.php` (`kind` - a kind's name, `software` or its type - `record_id`, `tag_id` with `tag_record_ids`, `tag_name`, `archived`, `limit`, `offset`), `update.php` (`kind`, `record_id`, `tags` as an array or comma-separated ids or names, `mode` `set`, `add` or `remove`, and `client_id` for a key limited to certain clients) and `create.php` (admin keys; `kind`, `name`, `description`, `color`, `icon`). `enforce_api_rbac.php` maps `tags` to `''`, so `tagApiKind()` checks the module of the kind asked for. `read_output.php` adds `tags` to each row when the endpoint sets `$api_tag_entity`, as the twelve kinds' reads now do; `credentials/read.php` adds them itself. + - Seeds: `starterContentTags()` has types 8 to 12, and demo data tags its documents, services, licenses and tickets (`demoTicketTags()`). - Empty states: every list page sets `$empty_state` before including `includes/filter_footer.php`, and `includes/inc_empty_state.php` draws it with `emptyStateHtml()` (`functions/format.php`) when the list has nothing - `thing`, `icon`, `title`, `text`, `actions` (`label`, `modal` or `href`, `size`, `icon`; the first is the main one), `archived`, `view`, `filtered`, `views`, `match_title`, `match_text` and `clear_url`. `emptyStateFiltered($views)` reads the GET string for a search or filter, leaving out paging, sorting, `client_id`, `archived` and the page's views, and `emptyStateClearUrl($views)` is the page without them. `emptyStatePill($pills, $key, $default, $good)` builds a pill's own state from the page's pill array (`label`, `icon`, `title`, `alarm`), with a tick for `alarm` pills and the keys in `$good`. Files, notifications and racks call `emptyStateHtml()` in their own layout; files and notifications set `$empty_state_skip`. A page that sets nothing still gets one, worded from `$page_title`. The pages' own empty blocks (`.itflow-asset-empty` under a list) are gone. CSS: `.itflow-empty-state` with `-icon` (a grey round tile), `-title`, `-text` and `-actions`. - Removed unused helpers and files: - `credentialLink()`, `projectLink()`, `linkCounts()`, `assetContactAvatar()`, `clientOverviewPersonInitials()`, and `getMonthlyTax()` and `getQuarterlyTax()`, which looked a tax up by name diff --git a/admin/database_updates/3.1.4.php b/admin/database_updates/3.1.4.php new file mode 100644 index 000000000..7fdbcd196 --- /dev/null +++ b/admin/database_updates/3.1.4.php @@ -0,0 +1,29 @@ + ['software_id', 'software'], + 'service_tags' => ['service_id', 'services'], + 'network_tags' => ['network_id', 'networks'], + 'document_tags' => ['document_id', 'documents'], + 'ticket_tags' => ['ticket_id', 'tickets'], + ]; + foreach ($tag_links as $tag_link_table => [$tag_link_column, $tag_link_parent]) { + mysqli_query($mysqli, "CREATE TABLE IF NOT EXISTS `$tag_link_table` ( + `$tag_link_column` int(11) NOT NULL, + `tag_id` int(11) NOT NULL, + PRIMARY KEY (`$tag_link_column`, `tag_id`), + KEY `tag_id` (`tag_id`), + CONSTRAINT `{$tag_link_table}_ibfk_1` FOREIGN KEY (`$tag_link_column`) REFERENCES `$tag_link_parent` (`$tag_link_column`) ON DELETE CASCADE, + CONSTRAINT `{$tag_link_table}_ibfk_2` FOREIGN KEY (`tag_id`) REFERENCES `tags` (`tag_id`) ON DELETE CASCADE + ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_general_ci"); + } diff --git a/admin/post/demo_data_model.php b/admin/post/demo_data_model.php index c5e777f0f..6787329ab 100644 --- a/admin/post/demo_data_model.php +++ b/admin/post/demo_data_model.php @@ -1518,6 +1518,7 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { ], ['document_content', 'document_content_raw']); $document_ids[] = $document_id; $counts['documentation']++; + demoAttachTags($mysqli, 'document_tags', 'document_id', 'tag_id', $document_id, 11, $document_index === 0 ? ['Runbook'] : ($document[3] ? ['Client-facing'] : ['Procedure'])); // The runbook has been revised at least once since it was written if ($document_index === 0 && $written_months_ago > 2) { @@ -1558,6 +1559,7 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { 'service_accessed_at' => demoDateTime($index % 12, 16, 20), ]); $counts['documentation']++; + demoAttachTags($mysqli, 'service_tags', 'service_id', 'tag_id', $service_id, 9, in_array($service[2], ['Email', 'Web'], true) ? ['Managed', 'Cloud'] : ['Managed']); // Link it to the assets whose type it runs on foreach ($assets as $asset) { @@ -1604,6 +1606,7 @@ function demoBuildClient($mysqli, $profile, $index, $context, &$counts) { $software_id = starterInsert($mysqli, 'software', $software_fields); $counts['documentation']++; + demoAttachTags($mysqli, 'software_tags', 'software_id', 'tag_id', $software_id, 8, $software[4] === 'Subscription' ? ['We Resell', 'Core Stack'] : []); // Open source software has no key to hold if ($software[4] !== 'Open Source') { @@ -2388,6 +2391,22 @@ function demoBuildProjects($mysqli, $profile, $index, $client_id, $months, &$cou // One place that writes a ticket and its trail, so every ticket in the demo // gets the same history, SLA treatment and reply handling. // ------------------------------ +/* A demo ticket's tags, from what it is about - the Tags starter pack's ticket tags. */ +function demoTicketTags($subject) { + $map = [ + 'New starter' => 'Onboarding', 'leaving' => 'Offboarding', 'Ransomware' => 'Security', 'Suspicious' => 'Security', + 'Multi factor' => 'Security', 'Drive failed' => 'Warranty Claim', 'screen cracked' => 'Warranty Claim', 'will not power on' => 'Warranty Claim', + 'internet dropping' => 'Waiting on Vendor', + ]; + $tags = []; + foreach ($map as $words => $tag) { + if (stripos((string) $subject, $words) !== false) { + $tags[] = $tag; + } + } + return array_values(array_unique($tags)); +} + function demoSeedTicket($mysqli, $fields, $trail, $context, &$counts) { global $config_ticket_prefix; @@ -2415,6 +2434,7 @@ function demoSeedTicket($mysqli, $fields, $trail, $context, &$counts) { $ticket_id = starterInsert($mysqli, 'tickets', $fields, ['ticket_details']); $counts['tickets']++; + demoAttachTags($mysqli, 'ticket_tags', 'ticket_id', 'tag_id', $ticket_id, 12, demoTicketTags($fields['ticket_subject'])); if (!empty($fields['ticket_asset_id'])) { mysqli_query($mysqli, "INSERT INTO ticket_assets SET ticket_id = $ticket_id, asset_id = {$fields['ticket_asset_id']}"); diff --git a/admin/post/starter_content_model.php b/admin/post/starter_content_model.php index 9c528ef1d..9529b52f3 100644 --- a/admin/post/starter_content_model.php +++ b/admin/post/starter_content_model.php @@ -30,7 +30,7 @@ function starterContentPacks() { 'tags' => [ 'label' => 'Tags', 'icon' => 'fa-tags', - 'description' => 'Client, location, contact, credential, asset, vendor and domain tags.', + 'description' => 'Tags for clients, locations, contacts, credentials, assets, vendors, domains, licenses, services, networks, documents and tickets.', ], 'ticket_templates' => [ 'label' => 'Ticket Templates', @@ -575,7 +575,8 @@ function starterContentCategories() { // ------------------------------ // starterContentTags -// tag_type 1 Client, 2 Location, 3 Contact, 4 Credential, 5 Asset. +// tag_type 1 Client, 2 Location, 3 Contact, 4 Credential, 5 Asset, 6 Vendor, 7 Domain, +// 8 License, 9 Service, 10 Network, 11 Document, 12 Ticket - tagKinds() in functions/tags.php. // tag_icon is stored without the fa- prefix, the views add it. // ------------------------------ function starterContentTags() { @@ -686,6 +687,41 @@ function starterContentTags() { [7, 'Parked', '#adb5bd', 'parking'], [7, 'Marketing', '#fd7e14', 'bullhorn'], [7, 'Do Not Renew', '#dc3545', 'ban'], + + // License + [8, 'We Resell', '#007bff', 'handshake'], + [8, 'Client-paid', '#6f42c1', 'user-tie'], + [8, 'Annual True-up', '#fd7e14', 'sync-alt'], + [8, 'Core Stack', '#001f3f', 'layer-group'], + [8, 'Do Not Renew', '#dc3545', 'ban'], + + // Service + [9, 'Managed', '#28a745', 'handshake'], + [9, 'Client-managed', '#6f42c1', 'user-tie'], + [9, 'Cloud', '#0dcaf0', 'cloud'], + [9, 'On-premises', '#343a40', 'server'], + [9, 'Business Hours Only', '#ffc107', 'clock'], + + // Network + [10, 'Managed', '#28a745', 'handshake'], + [10, 'Segmented', '#6610f2', 'network-wired'], + [10, 'PCI', '#dc3545', 'credit-card'], + [10, 'IoT', '#20c997', 'microchip'], + + // Document + [11, 'Procedure', '#007bff', 'list-ol'], + [11, 'Runbook', '#001f3f', 'book'], + [11, 'Policy', '#6f42c1', 'gavel'], + [11, 'Client-facing', '#20c997', 'eye'], + [11, 'Needs Review', '#fd7e14', 'exclamation-circle'], + + // Ticket + [12, 'Onboarding', '#007bff', 'user-plus'], + [12, 'Offboarding', '#dc3545', 'user-minus'], + [12, 'Escalated', '#d81b60', 'fire'], + [12, 'Warranty Claim', '#28a745', 'certificate'], + [12, 'Waiting on Vendor', '#ffc107', 'hourglass-half'], + [12, 'Security', '#343a40', 'shield-alt'], ]; return $tags; diff --git a/admin/tags.php b/admin/tags.php index bf5ec47dc..f0bc6b9af 100644 --- a/admin/tags.php +++ b/admin/tags.php @@ -165,7 +165,7 @@ $csrf = $_SESSION['csrf_token']; $used_archived = $tag['used']['archived']; $lines = $tag['lines']; $edit_url = "modals/tag/tag_edit.php?id=$tag_id"; - $list_url = '/agent/' . $kind['list'] . '?tags[]=' . $tag_id; + $list_url = tagListUrl(tagKinds()[$type], $tag); $used_html = $used ? '' . $records_text($used) . '' . ($used_archived ? ' (' . number_format($used_archived) . ' archived)' : '') diff --git a/agent/ajax.php b/agent/ajax.php index 58402e237..1a00d9ee8 100644 --- a/agent/ajax.php +++ b/agent/ajax.php @@ -215,10 +215,16 @@ if (isset($_POST['tag_picker_set']) || isset($_POST['tag_picker_create'])) { if ($on && !$has) { mysqli_query($mysqli, "INSERT INTO $link SET $link_record = $record_id, $link_tag = $tag_id"); logAudit($config['log'], "Edit", "$session_name added tag $tag_name to $record_name", $record['client_id'], $record_id); + if ($entity === 'ticket') { + logTicketHistory($record_id, "$session_name added tag $tag_name"); + } $changed++; } elseif (!$on && $has) { mysqli_query($mysqli, "DELETE FROM $link WHERE $link_record = $record_id AND $link_tag = $tag_id"); logAudit($config['log'], "Edit", "$session_name removed tag $tag_name from $record_name", $record['client_id'], $record_id); + if ($entity === 'ticket') { + logTicketHistory($record_id, "$session_name removed tag $tag_name"); + } $changed++; } } diff --git a/agent/document.php b/agent/document.php index 395747963..b23965553 100644 --- a/agent/document.php +++ b/agent/document.php @@ -53,6 +53,7 @@ while ($version = mysqli_fetch_assoc($sql_versions)) { } $csrf = $_SESSION['csrf_token']; +$document_tags_display = tagPills('document', $document_id, tagsForRecord('document', $document_id), "files.php?client_id=$client_id&", $can_edit && !$document_archived); // Tab title - used raw, the header escapes it $page_title = $row['document_name']; @@ -81,6 +82,9 @@ $page_title = $row['document_name'];
+ +
+
Updated · Created diff --git a/agent/files.php b/agent/files.php index b8102fe17..f40b33b36 100644 --- a/agent/files.php +++ b/agent/files.php @@ -9,6 +9,9 @@ * details, what they are linked to); documents open their page. Files can be * dropped straight onto the list to upload them into the folder on show. * + * Documents can be tagged; filtering by a tag shows the documents with it - + * from every folder at the top level, like a search. + * * Open to anyone with access to the client (contracts and the like live here), * changes need support write access, like the handlers behind them. */ @@ -49,6 +52,11 @@ $order = ($_GET['order'] ?? '') === 'DESC' ? 'DESC' : 'ASC'; $search = trim((string) ($_GET['q'] ?? '')); $search_everywhere = $search !== '' && $folder_id === 0; +// Tags - documents with any of them, and no uploads, which have none. At the +// top level that is in every folder, like a search +$tag_filter_ids = tagFilterIds(); +$look_everywhere = $search_everywhere || ($tag_filter_ids && $folder_id === 0); + /** This page's URL with some parameters changed - the rest (folder, type, view, search, archived) ride along. */ function filesUrl($changes = []) { $params = array_merge($_GET, $changes); @@ -74,11 +82,13 @@ foreach ([['files', 'file'], ['documents', 'document']] as [$table, $prefix]) { // ---- What is on show: files and documents, merged and sorted here ---- $search_sql = escapeSql($search); -$file_where = "file_client_id = $client_id AND file_$archive_query" . ($search_everywhere ? '' : " AND file_folder_id = $folder_id"); -$document_where = "document_client_id = $client_id AND document_$archive_query" . ($search_everywhere ? '' : " AND document_folder_id = $folder_id"); +$file_where = "file_client_id = $client_id AND file_$archive_query" . ($look_everywhere ? '' : " AND file_folder_id = $folder_id") . ($tag_filter_ids ? ' AND 0' : ''); +$document_where = "document_client_id = $client_id AND document_$archive_query" . ($look_everywhere ? '' : " AND document_folder_id = $folder_id") + . ' ' . tagFilterSql('document', $tag_filter_ids, 'documents.document_id'); if ($search !== '') { $file_where .= " AND (file_name LIKE '%$search_sql%' OR file_ext LIKE '%$search_sql%' OR file_description LIKE '%$search_sql%')"; - $document_where .= " AND (MATCH(document_content_raw) AGAINST ('$search_sql') OR document_name LIKE '%$search_sql%' OR document_description LIKE '%$search_sql%')"; + $document_where .= " AND (MATCH(document_content_raw) AGAINST ('$search_sql') OR document_name LIKE '%$search_sql%' OR document_description LIKE '%$search_sql%' + " . tagSearchSql('document', $search_sql, 'documents.document_id') . ")"; } $items = []; @@ -171,6 +181,7 @@ foreach (['file' => 'File', 'document' => 'Document'] as $kind => $share_type) { $shared[$kind][intval($row['item_related_id'])] = $row; } } +$documents_tags = tagsForRecords('document', $page_ids['document']); $link_counts = []; foreach (['file', 'document'] as $kind) { if (!$page_ids[$kind]) { @@ -294,7 +305,7 @@ function filesFolderTree($parent_id, $depth = 0) { $empty_state_skip = true; $upload_url = "modals/file/file_upload.php?client_id=$client_id&folder_id=$folder_id"; -$search_label = $search_everywhere || $folder_id === 0 ? 'all folders' : $folder_name; +$search_label = $look_everywhere || $folder_id === 0 ? 'all folders' : $folder_name; $preview = []; // the grid's previewer payload ?> @@ -355,6 +366,11 @@ $preview = []; // the grid's previewer payload
+
+ +
@@ -374,6 +390,9 @@ $preview = []; // the grid's previewer payload data-modal-url="modals/file/file_bulk_move.php?client_id=¤t_folder_id="> Move + + Tags +
diff --git a/agent/global_search.php b/agent/global_search.php index 7c2c696bf..2938f8817 100644 --- a/agent/global_search.php +++ b/agent/global_search.php @@ -166,6 +166,10 @@ function searchResultBadge($badge) { + + + + + + + +
diff --git a/agent/license.php b/agent/license.php index 1860aab7f..35834369c 100644 --- a/agent/license.php +++ b/agent/license.php @@ -58,6 +58,7 @@ if (!$license || ($client_url && intval($license['software_client_id']) !== intv $renewal = softwareRenewal($license['software_expire']); $can_edit = lookupUserPermission('module_support') >= 2 && !$software_archived_at; + $license_tags_display = tagPills('license', $software_id, tagsForRecord('license', $software_id), "software.php?client_id=$client_id&", $can_edit); $can_restore = lookupUserPermission('module_support') >= 2; $can_delete = lookupUserPermission('module_support') >= 3 && !empty($config_destructive_deletes_enable); $can_credentials = lookupUserPermission('module_credential') >= 1; @@ -139,6 +140,9 @@ if (!$license || ($client_url && intval($license['software_client_id']) !== intv + +
+
diff --git a/agent/modals/document/document_form.php b/agent/modals/document/document_form.php index f53d2db21..1abe9a169 100644 --- a/agent/modals/document/document_form.php +++ b/agent/modals/document/document_form.php @@ -7,7 +7,8 @@ * * Expects $document_form_mode ('add' or 'edit'), $client_id, and the * escaped $document_name, $document_description, $document_content, - * $document_folder_id, $document_client_visible. + * $document_folder_id, $document_client_visible - and $document_id when + * editing, for its tags. */ ?> @@ -39,6 +40,10 @@
+
+ +
+
diff --git a/agent/modals/network/network.php b/agent/modals/network/network.php index c61c696f4..ee200df0c 100644 --- a/agent/modals/network/network.php +++ b/agent/modals/network/network.php @@ -18,6 +18,7 @@ $addresses = networkAddresses([$network_id]); $plan = networkAddressPlan($network, $addresses); $usage = networkUsage([$network_id => $network], $addresses)[$network_id]; $can_edit = networkCan(2) && empty($network['network_archived_at']); +$network_tags_display = tagPills('network', $network_id, tagsForRecord('network', $network_id), 'networks.php?client_id=' . intval($network['network_client_id']) . '&', $can_edit); $dns = array_filter([$network['network_primary_dns'], $network['network_secondary_dns']]); $flagged = array_values(array_filter($plan['rows'], function ($row) { return $row['kind'] === 'address' && $row['flags']; @@ -94,6 +95,10 @@ ob_start();
About
+ +
Tags
+
+ diff --git a/agent/modals/network/network_export.php b/agent/modals/network/network_export.php index 35e938774..11ef0d09b 100644 --- a/agent/modals/network/network_export.php +++ b/agent/modals/network/network_export.php @@ -25,6 +25,7 @@ $type_filter = isset(NETWORK_TYPES[$_GET['type'] ?? '']) ? $_GET['type'] : ''; // Archived Filter $archived_filter = (isset($_GET['archived']) && $_GET['archived'] == 1) ? 1 : 0; +$tag_filter = tagFilterIds(); ob_start(); @@ -110,6 +111,8 @@ ob_start();
+ +
diff --git a/agent/modals/network/network_form.php b/agent/modals/network/network_form.php index fb6e80d60..3963cdf53 100644 --- a/agent/modals/network/network_form.php +++ b/agent/modals/network/network_form.php @@ -7,7 +7,7 @@ * (functions/network.php) reads. * * Tabs: Details (name, type, site, the provider of an internet connection, - * VLAN), Addressing (subnet, gateway, DHCP range, DNS) and Notes. The subnet + * VLAN, tags), Addressing (subnet, gateway, DHCP range, DNS) and Notes. The subnet * is read as it is typed - its size and mask, a gateway and DHCP range to * suggest, and the client's networks it overlaps (agent/js/network_form.js). */ @@ -155,6 +155,9 @@ $value = function ($key) use ($form) {
The ISP - its phone, account number and hours show on the network.
+
+ +
diff --git a/agent/modals/service/service.php b/agent/modals/service/service.php index f3390e23c..028f28d2e 100644 --- a/agent/modals/service/service.php +++ b/agent/modals/service/service.php @@ -15,6 +15,7 @@ $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_tags_display = tagPills('service', $service_id, tagsForRecord('service', $service_id), 'services.php?client_id=' . intval($service['service_client_id']) . '&', $can_edit); $counts = serviceCounts([$service_id])[$service_id]; $issues = serviceIssues([$service_id])[$service_id]; @@ -72,6 +73,9 @@ ob_start();

+ +
+
diff --git a/agent/modals/service/service_export.php b/agent/modals/service/service_export.php index ba183871e..af2332242 100644 --- a/agent/modals/service/service_export.php +++ b/agent/modals/service/service_export.php @@ -19,6 +19,7 @@ $show_filter = (string) ($_GET['show'] ?? ''); $client_filter = (string) ($_GET['client'] ?? ''); $importance_filter = (string) ($_GET['importance'] ?? ''); $category_filter = (string) ($_GET['category'] ?? ''); +$tag_filter = tagFilterIds(); $views = serviceViews(); ob_start(); @@ -74,6 +75,8 @@ ob_start();
+ +
diff --git a/agent/modals/service/service_form.php b/agent/modals/service/service_form.php index 45ccf01a7..65bf84ddb 100644 --- a/agent/modals/service/service_form.php +++ b/agent/modals/service/service_form.php @@ -80,6 +80,10 @@ $importance_styles = [
+
+ +
+
diff --git a/agent/modals/software/software.php b/agent/modals/software/software.php index bcd4aa140..d47c9383c 100644 --- a/agent/modals/software/software.php +++ b/agent/modals/software/software.php @@ -37,6 +37,7 @@ $renewal = softwareRenewal($license['software_expire']); $can_edit = lookupUserPermission('module_support') >= 2 && !$software_archived; $can_credentials = lookupUserPermission('module_credential') >= 1; +$license_tags_display = tagPills('license', $software_id, tagsForRecord('license', $software_id), "software.php?client_id=$client_id&", $can_edit); $holders = softwareSeatHolders($software_id); $keys = softwareKeys($software_id); @@ -90,6 +91,9 @@ ob_start();
+ +
+
diff --git a/agent/modals/software/software_export.php b/agent/modals/software/software_export.php index ba0648d31..dfc425b9e 100644 --- a/agent/modals/software/software_export.php +++ b/agent/modals/software/software_export.php @@ -27,6 +27,7 @@ $archived_filter = (isset($_GET['archived']) && $_GET['archived'] == 1) ? 1 : 0; $status_filters = softwareStatusFilters(); $status_filter = isset($status_filters[$_GET['status'] ?? '']) ? $_GET['status'] : ''; $license_type_filter = (string) ($_GET['license_type'] ?? ''); +$tag_filter = tagFilterIds(); ob_start(); @@ -117,6 +118,8 @@ ob_start();
+ +
diff --git a/agent/modals/software/software_form.php b/agent/modals/software/software_form.php index 26e29df68..1b8fe3218 100644 --- a/agent/modals/software/software_form.php +++ b/agent/modals/software/software_form.php @@ -7,7 +7,7 @@ * the seats, before including this. Posts what softwareFormSet() * (functions/software.php) reads. * - * Tabs: Details, License (type, seats, key, dates), Seats (the client's + * Tabs: Details (with its tags), License (type, seats, key, dates), Seats (the client's * devices and users, with a running count against the seats bought) and * Notes. A new license can start from a template, which fills in the details, * and take a batch of individual keys, one per line. @@ -193,6 +193,9 @@ $form_id = 'softwareForm' . ($software_form_mode === 'edit' ? $software_id : 'Ne
+
+ +
diff --git a/agent/modals/ticket/ticket.php b/agent/modals/ticket/ticket.php index d4ba23191..2e8bd71fe 100644 --- a/agent/modals/ticket/ticket.php +++ b/agent/modals/ticket/ticket.php @@ -51,6 +51,7 @@ $url = escapeHtml(ticketUrl($ticket_id, $client_id)); $is_open = ticketIsOpen($ticket); $is_closed = !empty($ticket['ticket_closed_at']); $can_edit = ticketCan(2) && !$is_closed; +$ticket_tags_display = tagPills('ticket', $ticket_id, tagsForRecord('ticket', $ticket_id), $client_id ? "tickets.php?client_id=$client_id&" : 'tickets.php?', $can_edit); $mine = intval($ticket['ticket_assigned_to']) === intval($session_user_id); $move = ticketWhoseMove($ticket); $sla = ticketSlaState($ticket); @@ -113,6 +114,10 @@ ob_start(); +
+ +
+
diff --git a/agent/modals/ticket/ticket_edit.php b/agent/modals/ticket/ticket_edit.php index 31ed02cb0..1885e45f0 100644 --- a/agent/modals/ticket/ticket_edit.php +++ b/agent/modals/ticket/ticket_edit.php @@ -178,6 +178,10 @@ ob_start();
+
+ +
+ = 2) { ?>
value="1" id="billableSwitch"> diff --git a/agent/modals/ticket/ticket_export.php b/agent/modals/ticket/ticket_export.php index d30c463b7..46b1ea96c 100644 --- a/agent/modals/ticket/ticket_export.php +++ b/agent/modals/ticket/ticket_export.php @@ -36,6 +36,7 @@ $sla_filter = $_GET['sla'] ?? ''; // Billing Filter $billing_filter = $_GET['billing'] ?? ''; +$tag_filter = tagFilterIds(); // Date Filter - the all-time sentinels from filter_header.php leave the fields blank $date_from_filter = (!empty($_GET['dtf']) && $_GET['dtf'] !== '1970-01-01') ? escapeHtml($_GET['dtf']) : ''; @@ -192,6 +193,8 @@ ob_start();
+ +
diff --git a/agent/network.php b/agent/network.php index 22d475b8d..077ca4c22 100644 --- a/agent/network.php +++ b/agent/network.php @@ -42,6 +42,7 @@ if (!$network || ($client_url && intval($network['network_client_id']) !== intva $is_archived = !empty($network['network_archived_at']); $is_favorite = intval($network['network_favorite']) === 1; $can_edit = networkCan(2) && !$is_archived; + $network_tags_display = tagPills('network', $network_id, tagsForRecord('network', $network_id), "networks.php?client_id=$client_id&", $can_edit); $can_restore = networkCan(2); $can_delete = networkCan(3) && !empty($config_destructive_deletes_enable); $csrf = $_SESSION['csrf_token']; @@ -115,6 +116,9 @@ if (!$network || ($client_url && intval($network['network_client_id']) !== intva
+ +
+
diff --git a/agent/networks.php b/agent/networks.php index f468c6dfd..5f430d246 100644 --- a/agent/networks.php +++ b/agent/networks.php @@ -65,12 +65,17 @@ if ($q_ip !== false) { $contains_query = $ids ? ' OR network_id IN (' . implode(',', $ids) . ')' : ''; } +// Tags - a network with any of them +$tag_filter_ids = tagFilterIds(); +$tag_query = tagFilterSql('network', $tag_filter_ids, 'networks.network_id'); + $filters = "(network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_type LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR network_dhcp_range LIKE '%$q%' OR location_name LIKE '%$q%' OR vendor_name LIKE '%$q%' OR client_name LIKE '%$q%' OR EXISTS (SELECT 1 FROM network_ips WHERE ip_network_id = network_id AND (ip_address LIKE '%$q%' OR ip_hostname LIKE '%$q%' OR ip_mac LIKE '%$q%')) + " . tagSearchSql('network', $q, 'networks.network_id') . " $contains_query) - " . clientScopeSql('network_client_id') . " $client_query $location_query"; + " . clientScopeSql('network_client_id') . " $client_query $location_query $tag_query"; $joins = "LEFT JOIN clients ON client_id = network_client_id LEFT JOIN locations ON location_id = network_location_id AND network_location_id > 0 @@ -111,6 +116,7 @@ while ($row = mysqli_fetch_assoc($sql)) { $networks[intval($row['network_id'])] = $row; } $addresses = networkAddresses(array_keys($networks)); +$networks_tags = tagsForRecords('network', array_keys($networks)); $usage = networkUsage($networks, $addresses); $problems = []; foreach ($networks as $network_id => $row) { @@ -160,7 +166,7 @@ $csrf = $_SESSION['csrf_token']; -
+
+ +
+
+ +
+
diff --git a/agent/post/document.php b/agent/post/document.php index 864f97062..c6a9792ac 100644 --- a/agent/post/document.php +++ b/agent/post/document.php @@ -104,6 +104,8 @@ if (isset($_POST['add_document'])) { logAudit("Service", "Link", "$session_name linked new document $name to service " . escapeSql($service['name']), $client_id, $service_id); } + tagSetForRecord('document', $document_id, (array) ($_POST['tags'] ?? [])); + logAudit("Document", "Create", "$session_name created document $name", $client_id, $document_id); flashAlert("Document " . trim($_POST['name']) . " created"); @@ -208,6 +210,11 @@ if (isset($_POST['edit_document'])) { $visible_sql WHERE document_id = $document_id"); + // Only a form that showed the tags changes them + if (isset($_POST['tags_form'])) { + tagSetForRecord('document', $document_id, (array) ($_POST['tags'] ?? [])); + } + logAudit("Document", "Edit", "$session_name edited document $name, previous version kept", $client_id, $document_id); flashAlert("Document " . trim($_POST['name']) . " saved - the previous version is kept"); diff --git a/agent/post/network.php b/agent/post/network.php index 270a1d5c1..63fc9c5ac 100644 --- a/agent/post/network.php +++ b/agent/post/network.php @@ -54,6 +54,8 @@ if (isset($_POST['add_network'])) { logAudit("Network", "Create", "$session_name created network " . escapeSql(trim($_POST['name'])), $client_id, $network_id); + tagSetForRecord('network', $network_id, (array) ($_POST['tags'] ?? [])); + networkSavedMessage('created', $network_id, $note); redirect(networkUrl($network_id, $client_id)); @@ -79,6 +81,11 @@ if (isset($_POST['edit_network'])) { mysqli_query($mysqli, "UPDATE networks SET $set WHERE network_id = $network_id"); + // Only a form that showed the tags changes them + if (isset($_POST['tags_form'])) { + tagSetForRecord('network', $network_id, (array) ($_POST['tags'] ?? [])); + } + logAudit("Network", "Edit", "$session_name edited network " . escapeSql(trim($_POST['name'])), $client_id, $network_id); networkSavedMessage('saved', $network_id, $note); @@ -340,6 +347,8 @@ if (isExportRequest('export_networks')) { $filter_summary['Type'] = $_POST['type']; } + $tag_query = tagExportFilterSql('network', $_POST['tags'] ?? [], $filter_summary, 'networks.network_id'); + $q = escapeSql($_POST['q'] ?? ''); if ($q !== '') { $filter_summary['Search'] = $_POST['q']; @@ -347,15 +356,17 @@ if (isExportRequest('export_networks')) { $sql = mysqli_query( $mysqli, - "SELECT networks.*, client_name, location_name, vendor_name FROM networks + "SELECT networks.*, client_name, location_name, vendor_name, " . tagNamesSql('network', 'networks.network_id') . " AS network_tags FROM networks LEFT JOIN clients ON client_id = network_client_id LEFT JOIN locations ON location_id = network_location_id AND network_location_id > 0 LEFT JOIN vendors ON vendor_id = network_vendor_id AND network_vendor_id > 0 WHERE $archive_query - AND (network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_type LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR client_name LIKE '%$q%' OR location_name LIKE '%$q%' OR vendor_name LIKE '%$q%') + AND (network_name LIKE '%$q%' OR network_description LIKE '%$q%' OR network_type LIKE '%$q%' OR network_vlan LIKE '%$q%' OR network LIKE '%$q%' OR network_gateway LIKE '%$q%' OR network_primary_dns LIKE '%$q%' OR network_secondary_dns LIKE '%$q%' OR client_name LIKE '%$q%' OR location_name LIKE '%$q%' OR vendor_name LIKE '%$q%' + " . tagSearchSql('network', $q, 'networks.network_id') . ") " . clientScopeSql('network_client_id') . " $location_query $type_query + $tag_query $client_query ORDER BY client_name ASC, network_name ASC" ); @@ -369,6 +380,7 @@ if (isExportRequest('export_networks')) { $export = beginExport('networks', $format, $file_name_prepend . 'Networks', 'Networks', summarizeExportFilters($filter_summary)); while ($row = mysqli_fetch_assoc($sql)) { + $row['network_tags'] = (string) $row['network_tags']; addExportRow($export, $row); } diff --git a/agent/post/service.php b/agent/post/service.php index 53ce6f39b..8c3d3870a 100644 --- a/agent/post/service.php +++ b/agent/post/service.php @@ -36,6 +36,8 @@ if (isset($_POST['add_service'])) { logAudit("Service", "Create", "$session_name created service $service_name", $client_id, $service_id); + tagSetForRecord('service', $service_id, (array) ($_POST['tags'] ?? [])); + // 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) { @@ -67,6 +69,11 @@ if (isset($_POST['edit_service'])) { mysqli_query($mysqli, "UPDATE services SET $set WHERE service_id = $service_id"); + // Only a form that showed the tags changes them + if (isset($_POST['tags_form'])) { + tagSetForRecord('service', $service_id, (array) ($_POST['tags'] ?? [])); + } + $service_name = escapeSql(trim($_POST['name'])); logAudit("Service", "Edit", "$session_name edited service $service_name", $client_id, $service_id); @@ -448,14 +455,17 @@ if (isExportRequest('export_services')) { $filter_summary['Category'] = $category; } + $where[] = tagExportFilterSql('service', $_POST['tags'] ?? [], $filter_summary, 'services.service_id'); + $q = escapeSql($_POST['q'] ?? ''); if ($q !== '') { $filter_summary['Search'] = $_POST['q']; } - $sql = mysqli_query($mysqli, "SELECT services.*, client_name FROM services + $sql = mysqli_query($mysqli, "SELECT services.*, client_name, " . tagNamesSql('service', 'services.service_id') . " AS service_tags 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%') + WHERE (service_name LIKE '%$q%' OR service_description LIKE '%$q%' OR service_category LIKE '%$q%' OR client_name LIKE '%$q%' + " . tagSearchSql('service', $q, 'services.service_id') . ") " . implode(' ', $where) . " ORDER BY client_name ASC, FIELD(service_importance, 'High', 'Medium', 'Low'), service_name ASC"); @@ -501,6 +511,7 @@ if (isExportRequest('export_services')) { $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'; + $row['service_tags'] = (string) $row['service_tags']; addExportRow($export, $row); } diff --git a/agent/post/software.php b/agent/post/software.php index 07bb064ab..732c0e081 100644 --- a/agent/post/software.php +++ b/agent/post/software.php @@ -66,6 +66,7 @@ if (isset($_POST['add_software'])) { $changes = softwareSyncSeats($software_id, $client_id, $_POST['assets'] ?? [], $_POST['contacts'] ?? []); $keys_added = softwareAddKeys($software_id, $_POST['keys'] ?? ''); + tagSetForRecord('license', $software_id, (array) ($_POST['tags'] ?? [])); $name = trim($_POST['name']); logAudit("Software", "Create", "$session_name created license " . escapeSql($name . softwareSeatChangeText($changes)), $client_id, $software_id); @@ -138,6 +139,10 @@ if (isset($_POST['edit_software'])) { if (isset($_POST['seats_form'])) { $changes = softwareSyncSeats($software_id, $client_id, $_POST['assets'] ?? [], $_POST['contacts'] ?? []); } + // ...and the tags + if (isset($_POST['tags_form'])) { + tagSetForRecord('license', $software_id, (array) ($_POST['tags'] ?? [])); + } $name = trim($_POST['name']); logAudit("Software", "Edit", "$session_name edited license " . escapeSql($name . softwareSeatChangeText($changes)), $client_id, $software_id); @@ -507,6 +512,9 @@ if (isExportRequest('export_software')) { $filter_summary['License Type'] = $_POST['license_type']; } + // Tags - a license with any of them + $tag_query = tagExportFilterSql('license', $_POST['tags'] ?? [], $filter_summary, 'software.software_id'); + // Search Filter $q = escapeSql($_POST['q'] ?? ''); if (!empty($q)) { @@ -525,15 +533,18 @@ if (isExportRequest('export_software')) { JOIN assets ON assets.asset_id = sa.asset_id AND asset_archived_at IS NULL WHERE sa.software_id = software.software_id) AS assigned_to_assets, (SELECT GROUP_CONCAT(contact_name ORDER BY contact_name SEPARATOR ', ') FROM software_contacts AS sc JOIN contacts ON contacts.contact_id = sc.contact_id AND contact_archived_at IS NULL WHERE sc.software_id = software.software_id) AS assigned_to_contacts, - (SELECT GROUP_CONCAT(sk.software_key ORDER BY sk.software_key_id SEPARATOR ', ') FROM software_keys AS sk WHERE sk.software_key_software_id = software.software_id) AS software_keys_list + (SELECT GROUP_CONCAT(sk.software_key ORDER BY sk.software_key_id SEPARATOR ', ') FROM software_keys AS sk WHERE sk.software_key_software_id = software.software_id) AS software_keys_list, + " . tagNamesSql('license', 'software.software_id') . " AS software_tags FROM software LEFT JOIN clients ON client_id = software_client_id LEFT JOIN vendors ON vendor_id = software_vendor_id WHERE (software_name LIKE '%$q%' OR software_type LIKE '%$q%' OR software_key LIKE '%$q%' OR client_name LIKE '%$q%' OR vendor_name LIKE '%$q%' - OR software.software_id IN (SELECT software_key_software_id FROM software_keys WHERE software_key LIKE '%$q%')) + OR software.software_id IN (SELECT software_key_software_id FROM software_keys WHERE software_key LIKE '%$q%') + " . tagSearchSql('license', $q, 'software.software_id') . ") AND $archive_query " . clientScopeSql('software_client_id') . " $client_query + $tag_query $expire_query $status_query $license_type_query @@ -552,6 +563,7 @@ if (isExportRequest('export_software')) { $row['assigned_to_assets'] = (string) $row['assigned_to_assets']; $row['assigned_to_contacts'] = (string) $row['assigned_to_contacts']; $row['software_keys_list'] = (string) $row['software_keys_list']; + $row['software_tags'] = (string) $row['software_tags']; addExportRow($export, $row); } diff --git a/agent/post/ticket.php b/agent/post/ticket.php index e3b745201..5562f62f2 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -48,7 +48,7 @@ function ticketNotifyAgent($user_id, $row, $text) { mysqli_query($mysqli, "INSERT INTO notifications SET notification_type = 'Ticket', notification = '" . escapeSql($text) . "', notification_action = '$action', notification_client_id = $client_id, notification_user_id = $user_id"); } -/** Close a merged ticket into another one - notes on both, replies moved when asked. */ +/** Close a merged ticket into another one - notes on both, its tags onto the other, replies moved when asked. */ function ticketMergeInto($child, $parent, $comment, $move_replies = false) { global $mysqli, $session_name, $session_user_id; $ticket_id = intval($child['ticket_id']); @@ -75,6 +75,11 @@ function ticketMergeInto($child, $parent, $comment, $move_replies = false) { mysqli_query($mysqli, "INSERT INTO ticket_replies SET ticket_reply = 'Ticket $child_reference was merged into this ticket with comment: $comment.

$child_subject
$child_details', ticket_reply_time_worked = '00:00:00', ticket_reply_type = 'Internal', ticket_reply_by = $session_user_id, ticket_reply_ticket_id = $parent_id"); mysqli_query($mysqli, "UPDATE tickets SET ticket_updated_at = NOW() WHERE ticket_id = $parent_id"); + // Its tags go with it - not archived ones, which aren't put on more tickets + mysqli_query($mysqli, "INSERT IGNORE INTO ticket_tags (ticket_id, tag_id) + SELECT $parent_id, ticket_tags.tag_id FROM ticket_tags JOIN tags ON tags.tag_id = ticket_tags.tag_id + WHERE ticket_tags.ticket_id = $ticket_id AND tags.tag_archived_at IS NULL"); + logTicketHistory($ticket_id, "$session_name merged this ticket into $parent_reference and closed it"); logTicketHistory($parent_id, "$session_name merged $child_reference into this ticket"); logAudit("Ticket", "Merged", "$session_name merged ticket $child_reference into $parent_reference", intval($child['ticket_client_id']), $ticket_id); @@ -164,6 +169,7 @@ if (isset($_POST['add_ticket'])) { ticketAddWatchers($ticket_id, ticketWatcherEmails($_POST['watchers'] ?? [])); ticketSetOtherAssets($ticket_id, $other_asset_ids); + tagSetForRecord('ticket', $ticket_id, (array) ($_POST['tags'] ?? [])); // 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) { @@ -278,6 +284,16 @@ if (isset($_POST['edit_ticket'])) { ticketSetOtherAssets($ticket_id, ticketClientOwnedAssetIds($_POST['additional_assets'] ?? [], $client_id, $asset_id)); } + // ...and the tags with their marker + if (isset($_POST['tags_form'])) { + $tags_before = tagIdsForRecord('ticket', $ticket_id); + $tags_after = tagSetForRecord('ticket', $ticket_id, (array) ($_POST['tags'] ?? [])); + $tags_text = tagChangeText($tags_before, $tags_after); + if ($tags_text !== '') { + logTicketHistory($ticket_id, escapeSql(stripslashes((string) $session_name) . " $tags_text")); + } + } + // The trail for what changed - the same entries the dedicated pickers write if ($row['ticket_priority'] !== $priority) { logTicketHistory($ticket_id, "$session_name changed priority from " . escapeSql($row['ticket_priority']) . " to $priority_sql"); @@ -1680,12 +1696,15 @@ if (isExportRequest('export_tickets')) { $filter_summary['Search'] = $_POST['q']; } + // Tags - a ticket with any of them + $ticket_tag_query = tagExportFilterSql('ticket', $_POST['tags'] ?? [], $filter_summary, 'tickets.ticket_id'); + // Get records from database - same shape as the tickets page list query $sql = mysqli_query( $mysqli, "SELECT category_name, client_name, contact_name, ticket_billable, ticket_closed_at, ticket_created_at, ticket_number, ticket_prefix, ticket_priority, ticket_resolved_at, - ticket_status_name, ticket_subject, user_name FROM tickets + ticket_status_name, ticket_subject, user_name, " . tagNamesSql('ticket', 'tickets.ticket_id') . " AS ticket_tags FROM tickets LEFT JOIN clients ON ticket_client_id = client_id LEFT JOIN contacts ON ticket_contact_id = contact_id LEFT JOIN users ON ticket_assigned_to = user_id @@ -1698,7 +1717,9 @@ if (isExportRequest('export_tickets')) { $ticket_assigned_query $category_query AND DATE(ticket_created_at) BETWEEN '$dtf' AND '$dtt' - AND (CONCAT(ticket_prefix,ticket_number) LIKE '%$q%' OR client_name LIKE '%$q%' OR ticket_subject LIKE '%$q%' OR ticket_status_name LIKE '%$q%' OR ticket_priority LIKE '%$q%' OR user_name LIKE '%$q%' OR contact_name LIKE '%$q%' OR asset_name LIKE '%$q%' OR vendor_name LIKE '%$q%') + AND (CONCAT(ticket_prefix,ticket_number) LIKE '%$q%' OR client_name LIKE '%$q%' OR ticket_subject LIKE '%$q%' OR ticket_status_name LIKE '%$q%' OR ticket_priority LIKE '%$q%' OR user_name LIKE '%$q%' OR contact_name LIKE '%$q%' OR asset_name LIKE '%$q%' OR vendor_name LIKE '%$q%' + " . tagSearchSql('ticket', $q, 'tickets.ticket_id') . ") + $ticket_tag_query $ticket_sla_query $ticket_billable_snippet $ticket_project_snippet @@ -1721,6 +1742,7 @@ if (isExportRequest('export_tickets')) { $row['ticket_category_name'] = $row['category_name']; $row['ticket_assigned_to'] = $row['user_name']; $row['ticket_billable'] = $row['ticket_billable'] ? 'Yes' : 'No'; + $row['ticket_tags'] = (string) $row['ticket_tags']; addExportRow($export, $row); } diff --git a/agent/service.php b/agent/service.php index c588b15da..a33be187d 100644 --- a/agent/service.php +++ b/agent/service.php @@ -48,6 +48,7 @@ if (!$service || ($client_url && intval($service['service_client_id']) !== intva $can_delete = serviceCan(3) && !empty($config_destructive_deletes_enable); $can_credentials = lookupUserPermission('module_credential') >= 1; $can_link_credentials = $can_edit && linkCanEdit('service', 'credential'); + $service_tags_display = tagPills('service', $service_id, tagsForRecord('service', $service_id), "services.php?client_id=$client_id&", $can_edit); // Override Tab Title // No Sanitizing needed as this var will only be used in the tab title $page_title = $service['service_name']; @@ -178,6 +179,9 @@ if (!$service || ($client_url && intval($service['service_client_id']) !== intva
+ +
+
diff --git a/agent/services.php b/agent/services.php index f1593a529..d0fc4bdd2 100644 --- a/agent/services.php +++ b/agent/services.php @@ -50,8 +50,13 @@ $importance_query = $importance_filter ? "AND service_importance = '$importance_ $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"; +// Tags - a service with any of them +$tag_filter_ids = tagFilterIds(); +$tag_query = tagFilterSql('service', $tag_filter_ids, 'services.service_id'); + +$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%' + " . tagSearchSql('service', $q, 'services.service_id') . ") + " . clientScopeSql('service_client_id') . " $client_query $importance_query $category_query $tag_query"; $joins = "LEFT JOIN clients ON client_id = service_client_id"; @@ -85,6 +90,7 @@ while ($row = mysqli_fetch_assoc($sql)) { $services[intval($row['service_id'])] = $row; } $counts = serviceCounts(array_keys($services)); +$services_tags = tagsForRecords('service', array_keys($services)); $issues = serviceIssues(array_keys($services)); // How many of each, for the pills @@ -135,7 +141,7 @@ $link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['f @@ -152,7 +158,7 @@ $link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['f
- +
@@ -172,6 +178,11 @@ $link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['f
+
+ +
-
+