From 6a5bc6cf554ed6c91c8342ed0e96e1a5704cef67 Mon Sep 17 00:00:00 2001 From: johnnyq Date: Thu, 19 Nov 2026 23:15:07 -0500 Subject: [PATCH] Undo: the message after archiving, a move or a bulk change has Undo, which puts it back as it was unless it changed since, and archiving no longer asks first except for clients; covers archiving every kind on Archived with contact roles, document links and a client's recurring invoices, file, document, folder and rack moves, and the bulk changes that set a field on tickets, assets, contacts, clients, projects, invoices, products and IP addresses --- CHANGELOG.md | 2 + agent/asset.php | 2 +- agent/assets.php | 4 +- agent/certificates.php | 4 +- agent/contact.php | 2 +- agent/contacts.php | 4 +- agent/credentials.php | 4 +- agent/document.php | 2 +- agent/domains.php | 4 +- agent/files.php | 4 +- agent/license.php | 3 +- agent/location.php | 2 +- agent/locations.php | 4 +- agent/network.php | 3 +- agent/networks.php | 6 +- agent/post/asset.php | 12 + agent/post/certificate.php | 4 + agent/post/client.php | 13 ++ agent/post/contact.php | 12 + agent/post/credential.php | 4 + agent/post/document.php | 4 + agent/post/domain.php | 4 + agent/post/file.php | 12 + agent/post/folder.php | 3 + agent/post/invoice.php | 2 + agent/post/location.php | 4 + agent/post/network.php | 4 + agent/post/network_ip.php | 2 + agent/post/product.php | 6 + agent/post/project.php | 8 + agent/post/rack.php | 4 + agent/post/service.php | 4 + agent/post/software.php | 4 + agent/post/ticket.php | 6 + agent/post/undo.php | 19 ++ agent/post/vendor.php | 4 + agent/product.php | 3 +- agent/products.php | 5 +- agent/project.php | 2 +- agent/projects.php | 2 +- agent/rack.php | 2 +- agent/racks.php | 2 +- agent/service.php | 3 +- agent/services.php | 6 +- agent/software.php | 4 +- agent/vendor.php | 2 +- agent/vendors.php | 4 +- css/itflow_custom.css | 13 ++ functions.php | 1 + functions/request.php | 2 + functions/undo.php | 380 ++++++++++++++++++++++++++++++++ includes/inc_alert_feedback.php | 21 +- 52 files changed, 589 insertions(+), 48 deletions(-) create mode 100644 agent/post/undo.php create mode 100644 functions/undo.php diff --git a/CHANGELOG.md b/CHANGELOG.md index 8481859bb..604a4c478 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -187,6 +187,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u - Projects: a project has a Timeline - its booked tickets as bars in time, from its start to its due date, with now marked. A booking that is past and still open shows in amber, and two of the same agent's at the same time are flagged. Its open tickets with no booking are listed under it, with Book. - Pickers: long lists of clients, contacts, vendors, categories, locations, assets, technicians, projects, accounts and products start with the last five you picked in a field like it, under Recent, above All. Typing searches everything as before. - Archived: Tools > Archived lists what was archived lately - clients, contacts, locations, vendors, assets, credentials, documents, files, domains, certificates, networks, racks, services, licenses, projects and products - newest first, with who archived each one, to restore one or several at once. The last 30 days to start with, or pick another time, a kind or a client. +- Undo: archiving no longer asks "Are you sure?" - the message that says it's done has Undo instead, as do moves and changes to several records at once. The message stays up for ten seconds, or as long as the pointer is on it. Undo covers archiving one or several of every kind Archived lists, bringing back what archiving took with it - a contact's roles, a document's links, a client's recurring invoices; moving files, documents and folders, dragged or with Move; dragging kit on a rack; and the bulk changes to a ticket's priority, category or project, an asset's location, physical location, contact or status, a contact's location, department, phone number or roles, a client's industry or referral, a project's manager or due date, an invoice's or product's category, and an IP address's type. Undo works once and only for whoever made the change, and leaves anything changed again since as it is, saying how many. Archiving a client still asks first, and has no Undo when it withdrew a contract out for signing. - Client portal: one Search box in the top bar looks through the client's tickets - their subject, number and what was said on them - the documents you share with them and your Help articles at once, the first eight of each with See all. Nothing found offers Ask us, and a search with no Help article goes on the Knowledge Base's Not found list. - Client portal: a ticket says when to expect your first reply - We'll reply by and the time, from its SLA - until you reply, while it isn't on hold and the time is still ahead. New ticket says how soon you reply to each priority, beside the priority and under What happens next. Without SLAs nothing is promised. - Users: Invite several, beside New User, invites a list of people at once with one role (and office, and whether two-step sign-in is required) - one per line, as a name and email or just the email. Each gets their own invite email; anyone who already has an account is skipped and named. It needs email set up. @@ -254,6 +255,7 @@ Update from Maintenance > Update — Queue Update hands the job to cron, which u ### Developer Updates +- Undo: `functions/undo.php`. A handler that can be put back calls `undoOffer()` after its `flashAlert()` with the message for afterwards and the steps that put it back; the steps are kept in `\$_SESSION['undo']` under a random token for `UNDO_SECONDS` (600, the last `UNDO_KEEP` of them), and `\$_SESSION['alert_undo']` gives the next message an Undo button (`includes/inc_alert_feedback.php`, `.itflow-toast-undo`) linking to `agent/post.php?undo=` with the CSRF token (`agent/post/undo.php`, `undoApply()`), which checks the user, the age and the permission level again. `flashAlert()` clears `alert_undo`, so only the message it was offered on carries it. `undoSnapshot()` before a change and `undoOfferChanges()` after offer the columns back as `set` steps, each only if the row still holds what the change wrote; `undoArchiveBefore()` / `undoOfferArchive()` do the same for archiving through `archivedRestore()`, with a contact's role flags, a document's link rows and a client's running recurring invoices. Steps that need their side effects go through their own code: `ticket_priority` (`ticketChangePriority()`), `ticket_category` and `ticket_project` (ticket history), `asset_status` (asset history), `folder` (no loop) and `rack` (`rackUnitConflict()`). The archive links and bulk Archive buttons of those kinds lose `confirm-link`; clients keep theirs. - Database 3.6.7: `rmm_providers` (`rmm_provider_kind` - `tactical` for now - the name it goes by, `api_url`, `web_url`, `api_key`, `api_secret` for an RMM that signs in with an id and a secret, and how the last sync went), `rmm_clients` (each provider's clients, `rmm_client_client_id` 0 until linked, `rmm_client_removed_at` once the RMM stops listing one) and `rmm_devices` (one a device: its asset, what the RMM last said - status, last seen, signed-in user, reboot, patches, checks - and `rmm_device_synced`, JSON of what the sync last wrote to the asset). Re-runnable, like 3.6.0. - `functions/rmm.php` is what every RMM shares. A kind is an entry in `rmmProviderKinds()` and a file of its own - `functions/rmm_tactical.php` for Tactical. It names the connection fields it uses, with their labels and help (the window and its checks are built from them), hints added to errors, the device links it offers, and four functions: `clients`, `devices` (each device in the shape described above `rmmDeviceFacts()`), `dashboard` and `device_urls`. `rmmHttp()` makes the request and turns a refused key, a redirect, a 404 or an answer that isn't JSON into a sentence for the person; `rmmTacticalRequest()` adds Tactical's `X-API-KEY`. Another RMM is a file like `rmm_tactical.php`, a line in `rmmProviderKinds()` and a `require_once` in `functions.php`. - `rmmSync($provider, $only = 0, $max_seconds = 120)` asks the kind for its clients, then for each linked client's devices, longest since brought in first, and stops on time to pick up next run. `GET_LOCK('itflow_rmm_sync_')` keeps each provider to one sync at a time. Devices and clients are marked removed by what the RMM listed, never by time, and only for a client whose list came back whole. One client failing doesn't hold up the rest or mark its devices removed. `rmmDeviceSave()` matches (`rmmAssetMatch()` - serial, then a name only one asset has, among this client's unarchived assets no other device of the provider has), makes (`rmmAssetCreate()`) and follows (`rmmAssetFollow()`). The follow rule: a field is written when it is empty or still holds what `rmm_device_synced` says was last written, and a blank never writes. Values go through `rmmText()` first - what `escapeSql()` would store - so a value compares the same on both sides and isn't written again every run. CPU and storage are asset details (`asset_specs`) and are only written for a type that has them. A device two providers have is one asset with a row from each, and each follows only what it wrote. diff --git a/agent/asset.php b/agent/asset.php index ccf711900..14bbd95d7 100644 --- a/agent/asset.php +++ b/agent/asset.php @@ -403,7 +403,7 @@ if (mysqli_num_rows($sql) == 0) { - + Archive diff --git a/agent/assets.php b/agent/assets.php index bbd85a832..076b1494e 100644 --- a/agent/assets.php +++ b/agent/assets.php @@ -456,7 +456,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets' - @@ -777,7 +777,7 @@ $search_noun = $type_filter ? $asset_type_tabs[$type_filter]['label'] : 'assets' - + Archive diff --git a/agent/certificates.php b/agent/certificates.php index 23e5e5b3a..c78c519d1 100644 --- a/agent/certificates.php +++ b/agent/certificates.php @@ -238,7 +238,7 @@ $export_extra = [ - @@ -435,7 +435,7 @@ $export_extra = [ - + Archive diff --git a/agent/contact.php b/agent/contact.php index 727ba55a9..f00f87229 100644 --- a/agent/contact.php +++ b/agent/contact.php @@ -337,7 +337,7 @@ if (!$can_support) { Restore - + Archive diff --git a/agent/contacts.php b/agent/contacts.php index 66553e8a8..d4736d0fd 100644 --- a/agent/contacts.php +++ b/agent/contacts.php @@ -448,7 +448,7 @@ $search_placeholder = $invites_view ? 'Search invites by email, name or client' - @@ -710,7 +710,7 @@ $search_placeholder = $invites_view ? 'Search invites by email, name or client' Restore - + Archive diff --git a/agent/credentials.php b/agent/credentials.php index a9985d747..c8675e573 100644 --- a/agent/credentials.php +++ b/agent/credentials.php @@ -289,7 +289,7 @@ $filter_url = function ($changes) use ($client_url) { - @@ -460,7 +460,7 @@ $filter_url = function ($changes) use ($client_url) { - + Archive diff --git a/agent/document.php b/agent/document.php index a0186cb09..bfaa981cf 100644 --- a/agent/document.php +++ b/agent/document.php @@ -143,7 +143,7 @@ $page_title = $row['document_name']; Copy to Knowledge Base - Archive + Archive Restore diff --git a/agent/domains.php b/agent/domains.php index 492f95413..302cf2732 100644 --- a/agent/domains.php +++ b/agent/domains.php @@ -270,7 +270,7 @@ $bulk_vendor_options = $can_edit ? domainVendorChoices($client_url ? $client_id - @@ -425,7 +425,7 @@ $bulk_vendor_options = $can_edit ? domainVendorChoices($client_url ? $client_id - + Archive diff --git a/agent/files.php b/agent/files.php index 5168727f0..c16b29e0e 100644 --- a/agent/files.php +++ b/agent/files.php @@ -275,7 +275,7 @@ function filesItemMenu($item) { : "Delete"; } } else { - $html .= "Archive"; + $html .= "Archive"; } } return $html; @@ -447,7 +447,7 @@ $preview = []; // the grid's previewer payload Download as zip - diff --git a/agent/license.php b/agent/license.php index 62fe34500..ebbb982ce 100644 --- a/agent/license.php +++ b/agent/license.php @@ -204,8 +204,7 @@ if (!$license || ($client_url && intval($license['software_client_id']) !== intv Seats - + Archive diff --git a/agent/location.php b/agent/location.php index b9a3cb819..10ba2d9d0 100644 --- a/agent/location.php +++ b/agent/location.php @@ -276,7 +276,7 @@ if (!$location || ($client_url && intval($location['location_client_id']) !== in - + Archive diff --git a/agent/locations.php b/agent/locations.php index a5990db68..30b3fadfa 100644 --- a/agent/locations.php +++ b/agent/locations.php @@ -213,7 +213,7 @@ $locations_counts = locationCounts(array_keys($locations)); - @@ -395,7 +395,7 @@ $locations_counts = locationCounts(array_keys($locations)); - + Archive diff --git a/agent/network.php b/agent/network.php index d78491aa4..999b72e69 100644 --- a/agent/network.php +++ b/agent/network.php @@ -187,8 +187,7 @@ if (!$network || ($client_url && intval($network['network_client_id']) !== intva - + Archive diff --git a/agent/networks.php b/agent/networks.php index 9a8bea09f..02e47a906 100644 --- a/agent/networks.php +++ b/agent/networks.php @@ -261,8 +261,7 @@ $csrf = $_SESSION['csrf_token']; - @@ -429,8 +428,7 @@ $csrf = $_SESSION['csrf_token']; - + Archive diff --git a/agent/post/asset.php b/agent/post/asset.php index bcb5819bb..808deea72 100644 --- a/agent/post/asset.php +++ b/agent/post/asset.php @@ -203,6 +203,7 @@ if (isset($_GET['archive_asset'])) { enforceClientAccess(); + $undo = undoArchiveBefore('asset', $asset_id); // for Undo on the message mysqli_query($mysqli,"UPDATE assets SET asset_archived_at = NOW() WHERE asset_id = $asset_id"); // Add to History @@ -211,6 +212,7 @@ if (isset($_GET['archive_asset'])) { logAudit("Asset", "Archive", "$session_name archived asset $asset_name", $client_id, $asset_id); flashAlert("Asset " . stripslashes($asset_name) . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -438,6 +440,7 @@ if (isset($_POST['bulk_assign_asset_location'])) { enforceClientAccess(); // Assign Location to Selected Assets + $undo = undoSnapshot('assets', 'asset_id', $_POST['asset_ids'] ?? [], ['asset_location_id'], 'asset_client_id'); // for Undo on the message if (isset($_POST['asset_ids'])) { // Only the assets of the location's client are moved @@ -469,6 +472,7 @@ if (isset($_POST['bulk_assign_asset_location'])) { logAudit("Asset", "Bulk Edit", "$session_name assigned $asset_count assets to location $location_name", $location_client_id); flashAlert("$asset_count asset" . ($asset_count === 1 ? '' : 's') . " assigned to location " . stripslashes($location_name) . ""); + undoOfferChanges($undo, "Location put back on {n} asset{s}", 'module_support'); } redirect(); @@ -484,6 +488,7 @@ if (isset($_POST['bulk_assign_asset_physical_location'])) { $physical_location = escapeSql($_POST['physical_location']); // Assign Physical Location to Selected Assets + $undo = undoSnapshot('assets', 'asset_id', $_POST['asset_ids'] ?? [], ['asset_physical_location'], 'asset_client_id'); // for Undo on the message if (isset($_POST['asset_ids'])) { // Get Selected Assets Count @@ -509,6 +514,7 @@ if (isset($_POST['bulk_assign_asset_physical_location'])) { logAudit("Asset", "Bulk Edit", "$session_name set $asset_count assets to physical location $physical_location", $client_id); flashAlert("Physical location of $asset_count asset" . ($asset_count === 1 ? '' : 's') . " set to " . stripslashes($physical_location) . ""); + undoOfferChanges($undo, "Physical location put back on {n} asset{s}", 'module_support'); } redirect(); @@ -635,6 +641,7 @@ if (isset($_POST['bulk_assign_asset_contact'])) { enforceClientAccess(); // Assign Contact to Selected Assets + $undo = undoSnapshot('assets', 'asset_id', $_POST['asset_ids'] ?? [], ['asset_contact_id'], 'asset_client_id'); // for Undo on the message if (isset($_POST['asset_ids'])) { // Only the assets of the contact's client are assigned @@ -663,6 +670,7 @@ if (isset($_POST['bulk_assign_asset_contact'])) { logAudit("Asset", "Bulk Edit", "$session_name assigned $asset_count assets to contact $contact_name", $client_id); flashAlert("$asset_count asset" . ($asset_count === 1 ? '' : 's') . " assigned to " . stripslashes($contact_name) . ""); + undoOfferChanges($undo, "Contact put back on {n} asset{s}", 'module_support'); } redirect(); @@ -677,6 +685,7 @@ if (isset($_POST['bulk_edit_asset_status'])) { $status = escapeSql($_POST['bulk_status']); + $undo = undoSnapshot('assets', 'asset_id', $_POST['asset_ids'] ?? [], ['asset_status'], 'asset_client_id'); // for Undo on the message if (isset($_POST['asset_ids'])) { $asset_count = count($_POST['asset_ids']); @@ -704,6 +713,7 @@ if (isset($_POST['bulk_edit_asset_status'])) { logAudit("Asset", "Bulk Edit", "$session_name set status to $status on $asset_count assets", $client_id); flashAlert("Status set to " . stripslashes($status) . " on $asset_count asset" . ($asset_count === 1 ? '' : 's')); + undoOfferChanges($undo, "Status put back on {n} asset{s}", 'module_support', 2, 's', 'asset_status'); } redirect(); @@ -792,6 +802,7 @@ if (isset($_POST['bulk_archive_assets'])) { enforceUserPermission('module_support', 2); + $undo = undoArchiveBefore('asset', $_POST['asset_ids'] ?? []); // for Undo on the message if (isset($_POST['asset_ids'])) { $count = count($_POST['asset_ids']); @@ -820,6 +831,7 @@ if (isset($_POST['bulk_archive_assets'])) { logAudit("Asset", "Bulk Archive", "$session_name archived $count assets", $client_id); flashAlert("Archived $count asset(s)", 'error'); + undoOfferArchive($undo); } diff --git a/agent/post/certificate.php b/agent/post/certificate.php index 51cb381a2..be1b51cc9 100644 --- a/agent/post/certificate.php +++ b/agent/post/certificate.php @@ -187,11 +187,13 @@ if (isset($_GET['archive_certificate'])) { $row = certificateForRequest($_GET['archive_certificate'], 2); $certificate_id = intval($row['certificate_id']); + $undo = undoArchiveBefore('certificate', $certificate_id); // for Undo on the message mysqli_query($mysqli, "UPDATE certificates SET certificate_archived_at = NOW() WHERE certificate_id = $certificate_id"); logAudit("Certificate", "Archive", "$session_name archived certificate " . escapeSql($row['certificate_name']), $client_id, $certificate_id); flashAlert("Certificate " . escapeHtml($row['certificate_name']) . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -288,6 +290,7 @@ if (isset($_POST['bulk_archive_certificates'])) { validateCSRFToken(); + $undo = undoArchiveBefore('certificate', $_POST['certificate_ids'] ?? []); // for Undo on the message $count = 0; foreach (certificatesForBulk(2) as $certificate_id => $row) { mysqli_query($mysqli, "UPDATE certificates SET certificate_archived_at = NOW() WHERE certificate_id = $certificate_id"); @@ -296,6 +299,7 @@ if (isset($_POST['bulk_archive_certificates'])) { } flashAlert("Archived $count certificate" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/client.php b/agent/post/client.php index b2088d0bf..15952c3e1 100644 --- a/agent/post/client.php +++ b/agent/post/client.php @@ -191,6 +191,7 @@ if (isset($_GET['archive_client'])) { enforceClientAccess(); // Archived, its recurring invoices stopped and contract signing requests withdrawn (functions/client.php) + $undo = undoArchiveBefore('client', $client_id); // for Undo on the message $contracts_withdrawn = clientArchiveNow($client_id); // Get Client Name @@ -199,6 +200,9 @@ if (isset($_GET['archive_client'])) { logAudit("Client", "Archive", "$session_name archived client $client_name" . ($contracts_withdrawn ? " - $contracts_withdrawn contract signing request" . ($contracts_withdrawn === 1 ? '' : 's') . " withdrawn" : ''), $client_id, $client_id); flashAlert("Client " . stripslashes($client_name) . " archived" . ($contracts_withdrawn ? " - contract signing requests to them were withdrawn" : ''), 'error'); + if (!$contracts_withdrawn) { + undoOfferArchive($undo); // a signing request withdrawn can't be put back + } redirect(); @@ -708,6 +712,7 @@ if (isset($_POST['bulk_edit_client_industry'])) { $industry = escapeSql($_POST['bulk_industry']); + $undo = undoSnapshot('clients', 'client_id', $_POST['client_ids'] ?? [], ['client_type'], 'client_id'); // for Undo on the message if (isset($_POST['client_ids'])) { // Check every selected client before changing any of them @@ -733,6 +738,7 @@ if (isset($_POST['bulk_edit_client_industry'])) { logAudit("Client", "Bulk Edit", "$session_name set the industry $industry for $count client(s)", $client_id); flashAlert("Industry set to " . stripslashes($industry) . " on $count client" . ($count === 1 ? '' : 's')); + undoOfferChanges($undo, "Industry put back on {n} client{s}", 'module_client'); } redirect(); @@ -747,6 +753,7 @@ if (isset($_POST['bulk_edit_client_referral'])) { $referral = escapeSql($_POST['bulk_referral']); + $undo = undoSnapshot('clients', 'client_id', $_POST['client_ids'] ?? [], ['client_referral'], 'client_id'); // for Undo on the message if (isset($_POST['client_ids'])) { // Check every selected client before changing any of them @@ -772,6 +779,7 @@ if (isset($_POST['bulk_edit_client_referral'])) { logAudit("Client", "Bulk Edit", "$session_name set the referral $referral for $count client(s)", $client_id); flashAlert("Referral set to " . stripslashes($referral) . " on $count client" . ($count === 1 ? '' : 's')); + undoOfferChanges($undo, "Referral put back on {n} client{s}", 'module_client'); } redirect(); @@ -882,6 +890,7 @@ if (isset($_POST['bulk_archive_clients'])) { enforceUserPermission('module_client', 2); + $undo = undoArchiveBefore('client', $_POST['client_ids'] ?? []); // for Undo on the message if (isset($_POST['client_ids'])) { // Check every selected client before changing any of them @@ -901,6 +910,7 @@ if (isset($_POST['bulk_archive_clients'])) { mysqli_query($mysqli,"UPDATE clients SET client_archived_at = NOW() WHERE client_id = $client_id"); $contracts_withdrawn = contractSignatureWithdrawStale($client_id); + $undo_withdrawn = ($undo_withdrawn ?? 0) + $contracts_withdrawn; logAudit("Client", "Archive", "$session_name archived $client_name" . ($contracts_withdrawn ? " - $contracts_withdrawn contract signing request" . ($contracts_withdrawn === 1 ? '' : 's') . " withdrawn" : ''), $client_id); @@ -911,6 +921,9 @@ if (isset($_POST['bulk_archive_clients'])) { logAudit("Client", "Bulk Archive", "$session_name archived $count clients", $client_id); flashAlert("Archived $count client(s)", 'error'); + if (empty($undo_withdrawn)) { + undoOfferArchive($undo); // a signing request withdrawn can't be put back + } } diff --git a/agent/post/contact.php b/agent/post/contact.php index c0b0bdac3..8ce7dbae5 100644 --- a/agent/post/contact.php +++ b/agent/post/contact.php @@ -363,6 +363,7 @@ if (isset($_POST['bulk_assign_contact_location'])) { enforceClientAccess(); // Assign Location to Selected Contacts + $undo = undoSnapshot('contacts', 'contact_id', $_POST['contact_ids'] ?? [], ['contact_location_id'], 'contact_client_id'); // for Undo on the message if (isset($_POST['contact_ids'])) { // Only the contacts of the location's client are moved @@ -389,6 +390,7 @@ if (isset($_POST['bulk_assign_contact_location'])) { logAudit("Contact", "Bulk Edit", "$session_name assigned $contact_count contacts to location $location_name", $client_id); flashAlert("$contact_count contact" . ($contact_count === 1 ? '' : 's') . " assigned to location " . stripslashes($location_name) . ""); + undoOfferChanges($undo, "Location put back on {n} contact{s}", 'module_client'); } redirect(); @@ -404,6 +406,7 @@ if (isset($_POST['bulk_edit_contact_phone'])) { $phone = preg_replace("/[^0-9]/", '', $_POST['bulk_phone']); // Assign Location to Selected Contacts + $undo = undoSnapshot('contacts', 'contact_id', $_POST['contact_ids'] ?? [], ['contact_phone'], 'contact_client_id'); // for Undo on the message if (isset($_POST['contact_ids'])) { // Get Selected Contacts Count @@ -429,6 +432,7 @@ if (isset($_POST['bulk_edit_contact_phone'])) { logAudit("Contact", "Bulk Edit", "$session_name set the Phone Number $phone for $contact_count contacts", $client_id); flashAlert("Phone number set to " . formatPhoneNumber($phone) . " on $contact_count contact" . ($contact_count === 1 ? '' : 's')); + undoOfferChanges($undo, "Phone number put back on {n} contact{s}", 'module_client'); } redirect(); @@ -444,6 +448,7 @@ if (isset($_POST['bulk_edit_contact_department'])) { $department = escapeSql($_POST['bulk_department']); // Assign Location to Selected Contacts + $undo = undoSnapshot('contacts', 'contact_id', $_POST['contact_ids'] ?? [], ['contact_department'], 'contact_client_id'); // for Undo on the message if (isset($_POST['contact_ids'])) { // Get Selected Contacts Count @@ -469,6 +474,7 @@ if (isset($_POST['bulk_edit_contact_department'])) { logAudit("Contact", "Bulk Edit", "$session_name set the department $department for $contact_count contacts", $client_id); flashAlert("Department set to " . stripslashes($department) . " on $contact_count contact" . ($contact_count === 1 ? '' : 's')); + undoOfferChanges($undo, "Department put back on {n} contact{s}", 'module_client'); } redirect(); @@ -486,6 +492,7 @@ if (isset($_POST['bulk_edit_contact_role'])) { $contact_technical = intval($_POST['bulk_contact_technical']); // Assign Location to Selected Contacts + $undo = undoSnapshot('contacts', 'contact_id', $_POST['contact_ids'] ?? [], ['contact_important', 'contact_billing', 'contact_technical'], 'contact_client_id'); // for Undo on the message if (isset($_POST['contact_ids'])) { // Get Selected Contacts Count @@ -513,6 +520,7 @@ if (isset($_POST['bulk_edit_contact_role'])) { logAudit("Contact", "Bulk Edit", "$session_name edited the contact role for $contact_count contacts", $client_id); flashAlert("Roles updated on $contact_count contact" . ($contact_count === 1 ? '' : 's')); + undoOfferChanges($undo, "Roles put back on {n} contact{s}", 'module_client'); } redirect(); @@ -552,6 +560,7 @@ if (isset($_POST['bulk_archive_contacts'])) { enforceUserPermission('module_client', 2); + $undo = undoArchiveBefore('contact', $_POST['contact_ids'] ?? []); // for Undo on the message if (isset($_POST['contact_ids'])) { $count = 0; // Default 0 @@ -591,6 +600,7 @@ if (isset($_POST['bulk_archive_contacts'])) { logAudit("Contact", "Bulk Archive", "$session_name archived $count contacts", $client_id); flashAlert("Archived $count contact(s)", 'error'); + undoOfferArchive($undo); } @@ -1022,6 +1032,7 @@ if (isset($_GET['archive_contact'])) { enforceClientAccess(); + $undo = undoArchiveBefore('contact', $contact_id); // for Undo on the message // Archive Contact User if ($contact_user_id > 0) { mysqli_query($mysqli,"UPDATE users SET user_archived_at = NOW() WHERE user_id = $contact_user_id"); @@ -1032,6 +1043,7 @@ if (isset($_GET['archive_contact'])) { logAudit("Contact", "Archive", "$session_name archived contact $contact_name", $client_id, $contact_id); flashAlert("Contact " . stripslashes($contact_name) . " archived", 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/credential.php b/agent/post/credential.php index 4673dc420..9dedfd723 100644 --- a/agent/post/credential.php +++ b/agent/post/credential.php @@ -246,11 +246,13 @@ if (isset($_GET['archive_credential'])) { $row = credentialForRequest($_GET['archive_credential'], 2); $credential_id = intval($row['credential_id']); + $undo = undoArchiveBefore('credential', $credential_id); // for Undo on the message mysqli_query($mysqli, "UPDATE credentials SET credential_archived_at = NOW() WHERE credential_id = $credential_id"); logAudit("Credential", "Archive", "$session_name archived credential " . escapeSql($row['credential_name']), $client_id, $credential_id); flashAlert("Credential {$row['credential_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -311,6 +313,7 @@ if (isset($_POST['bulk_archive_credentials'])) { validateCSRFToken(); + $undo = undoArchiveBefore('credential', $_POST['credential_ids'] ?? []); // for Undo on the message $count = 0; foreach (credentialsForBulk(2) as $credential_id => $row) { mysqli_query($mysqli, "UPDATE credentials SET credential_archived_at = NOW() WHERE credential_id = $credential_id"); @@ -319,6 +322,7 @@ if (isset($_POST['bulk_archive_credentials'])) { } flashAlert("Archived $count credential" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/document.php b/agent/post/document.php index fcf9d0939..5d3bf1b52 100644 --- a/agent/post/document.php +++ b/agent/post/document.php @@ -231,11 +231,13 @@ if (isset($_POST['move_document'])) { $folder_id = folderOwnedId($_POST['folder'] ?? 0, $client_id); $folder_name = folderDisplayName($folder_id); + $undo = undoSnapshot('documents', 'document_id', [$document_id], ['document_folder_id'], 'document_client_id'); // for Undo on the message mysqli_query($mysqli, "UPDATE documents SET document_folder_id = $folder_id, document_updated_at = document_updated_at WHERE document_id = $document_id"); logAudit("Document", "Move", "$session_name moved document " . escapeSql($row['document_name']) . " to folder " . escapeSql($folder_name), $client_id, $document_id); flashAlert("Document {$row['document_name']} moved to $folder_name"); + undoOfferChanges($undo, "" . escapeHtml($row['document_name']) . " moved back", 'module_support'); redirect(); @@ -474,6 +476,7 @@ if (isset($_GET['archive_document'])) { $row = documentForHandler($_GET['archive_document']); $document_id = intval($row['document_id']); + $undo = undoArchiveBefore('document', $document_id); // for Undo on the message mysqli_query($mysqli, "UPDATE documents SET document_archived_at = NOW(), document_updated_at = document_updated_at WHERE document_id = $document_id"); // An archived document drops its links, as it always has @@ -482,6 +485,7 @@ if (isset($_GET['archive_document'])) { logAudit("Document", "Archive", "$session_name archived document " . escapeSql($row['document_name']), $client_id, $document_id); flashAlert("Document {$row['document_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/domain.php b/agent/post/domain.php index 2703e2900..529d1607c 100644 --- a/agent/post/domain.php +++ b/agent/post/domain.php @@ -236,11 +236,13 @@ if (isset($_GET['archive_domain'])) { $row = domainForRequest($_GET['archive_domain'], 2); $domain_id = intval($row['domain_id']); + $undo = undoArchiveBefore('domain', $domain_id); // for Undo on the message mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id"); logAudit("Domain", "Archive", "$session_name archived domain " . escapeSql($row['domain_name']), $client_id, $domain_id); flashAlert("Domain {$row['domain_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -360,6 +362,7 @@ if (isset($_POST['bulk_archive_domains'])) { validateCSRFToken(); + $undo = undoArchiveBefore('domain', $_POST['domain_ids'] ?? []); // for Undo on the message $count = 0; foreach (domainsForBulk(2) as $domain_id => $row) { mysqli_query($mysqli, "UPDATE domains SET domain_archived_at = NOW() WHERE domain_id = $domain_id"); @@ -368,6 +371,7 @@ if (isset($_POST['bulk_archive_domains'])) { } flashAlert("Archived $count domain" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/file.php b/agent/post/file.php index d5416f859..100c53806 100644 --- a/agent/post/file.php +++ b/agent/post/file.php @@ -264,11 +264,13 @@ if (isset($_POST['move_file'])) { $folder_id = folderOwnedId($_POST['folder_id'] ?? 0, $client_id); $folder_name = folderDisplayName($folder_id); + $undo = undoSnapshot('files', 'file_id', [$file_id], ['file_folder_id'], 'file_client_id'); // for Undo on the message mysqli_query($mysqli, "UPDATE files SET file_folder_id = $folder_id WHERE file_id = $file_id"); logAudit("File", "Move", "$session_name moved file $file_name to " . escapeSql($folder_name), $client_id, $file_id); flashAlert("File {$row['file_name']} moved to $folder_name"); + undoOfferChanges($undo, "" . escapeHtml($row['file_name']) . " moved back", 'module_support'); redirect(); @@ -291,11 +293,13 @@ if (isset($_GET['archive_file'])) { enforceClientAccess(); + $undo = undoArchiveBefore('file', $file_id); // for Undo on the message mysqli_query($mysqli, "UPDATE files SET file_archived_at = NOW() WHERE file_id = $file_id"); logAudit("File", "Archive", "$session_name archived file " . escapeSql($row['file_name']), $client_id, $file_id); flashAlert("File {$row['file_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -361,6 +365,8 @@ if (isset($_POST['bulk_archive_files'])) { $file_count = 0; $document_count = 0; + $undo = undoArchiveBefore('file', $_POST['file_ids'] ?? []); // for Undo on the message + $undo_documents = undoArchiveBefore('document', $_POST['document_ids'] ?? []); foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) { $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT file_client_id, file_name FROM files WHERE file_id = $file_id AND file_archived_at IS NULL")); if (!$row) { @@ -386,6 +392,7 @@ if (isset($_POST['bulk_archive_files'])) { } flashAlert("Archived " . filesCountPhrase($document_count, $file_count), 'error'); + undoOfferArchive($undo, $undo_documents); redirect(); @@ -475,6 +482,10 @@ if (isset($_POST['bulk_move_files'])) { $file_count = 0; $document_count = 0; + // For Undo on the message - each back to the folder it came from + $undo = undoSnapshot('files', 'file_id', $_POST['file_ids'] ?? [], ['file_folder_id'], 'file_client_id'); + $undo_documents = undoSnapshot('documents', 'document_id', $_POST['document_ids'] ?? [], ['document_folder_id'], 'document_client_id'); + // Each item only moves into a folder of its own client - one of another // client's folders would take it out of sight of both. One already there is left alone. foreach (array_map('intval', (array) ($_POST['file_ids'] ?? [])) as $file_id) { @@ -508,6 +519,7 @@ if (isset($_POST['bulk_move_files'])) { } flashAlert("Moved " . filesCountPhrase($document_count, $file_count) . " to $folder_name"); + undoOffer('{n} item{s} moved back', array_merge(undoChangedSteps($undo), undoChangedSteps($undo_documents)), 'module_support'); redirect(); diff --git a/agent/post/folder.php b/agent/post/folder.php index 49fa4aa16..90f439325 100644 --- a/agent/post/folder.php +++ b/agent/post/folder.php @@ -132,6 +132,9 @@ if (isset($_POST['move_folder'])) { logAudit("Folder", "Move", "$session_name moved folder " . escapeSql($folder_name) . " into " . escapeSql($parent_name), $client_id, $folder_id); flashAlert("Folder $folder_name moved into $parent_name"); + $parent_before = intval($tree[$folder_id]['parent_folder'] ?? 0); + undoOffer("Folder " . escapeHtml($folder_name) . " is back in " . escapeHtml(folderDisplayName($parent_before)) . "", + [['folder', $folder_id, $parent_before, $parent_folder, $client_id]], 'module_support'); redirect(); diff --git a/agent/post/invoice.php b/agent/post/invoice.php index 7e9655d21..e9eeb11e3 100644 --- a/agent/post/invoice.php +++ b/agent/post/invoice.php @@ -814,6 +814,7 @@ if (isset($_POST['bulk_edit_invoice_category'])) { $category_name = escapeSql(getFieldById('categories', $category_id, 'category_name')); // Assign Income category to Selected Invoices + $undo = undoSnapshot('invoices', 'invoice_id', $_POST['invoice_ids'] ?? [], ['invoice_category_id'], 'invoice_client_id'); // for Undo on the message if (isset($_POST['invoice_ids'])) { // Get Selected Count @@ -841,6 +842,7 @@ if (isset($_POST['bulk_edit_invoice_category'])) { logAudit("Invoice", "Bulk Edit", "$session_name assigned $count invoices to category $category_name"); flashAlert("Assigned income category $category_name to $count invoice(s)"); + undoOfferChanges($undo, "Income category put back on {n} invoice{s}", 'module_sales'); } redirect(); diff --git a/agent/post/location.php b/agent/post/location.php index a9b8e202b..c94ede0f2 100644 --- a/agent/post/location.php +++ b/agent/post/location.php @@ -213,11 +213,13 @@ if (isset($_GET['archive_location'])) { redirect(); } + $undo = undoArchiveBefore('location', $location_id); // for Undo on the message mysqli_query($mysqli, "UPDATE locations SET location_archived_at = NOW() WHERE location_id = $location_id"); logAudit("Location", "Archive", "$session_name archived location " . escapeSql($row['location_name']), $client_id, $location_id); flashAlert("Location {$row['location_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -275,6 +277,7 @@ if (isset($_POST['bulk_archive_locations'])) { enforceUserPermission('module_client', 2); + $undo = undoArchiveBefore('location', $_POST['location_ids'] ?? []); // for Undo on the message $count = 0; $skipped = []; foreach (array_unique(array_map('intval', (array) ($_POST['location_ids'] ?? []))) as $location_id) { @@ -294,6 +297,7 @@ if (isset($_POST['bulk_archive_locations'])) { } flashAlert("Archived $count location" . ($count === 1 ? '' : 's') . ($skipped ? ' - kept ' . implode(', ', $skipped) . ', the primary location' : ''), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/network.php b/agent/post/network.php index 6871426dd..98b89dd39 100644 --- a/agent/post/network.php +++ b/agent/post/network.php @@ -140,9 +140,11 @@ if (isset($_GET['archive_network'])) { $row = networkForRequest($_GET['archive_network'], 2); + $undo = undoArchiveBefore('network', $row['network_id']); // for Undo on the message networkArchive($row); flashAlert("Network " . $row['network_name'] . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -249,6 +251,7 @@ if (isset($_POST['bulk_archive_networks'])) { validateCSRFToken(); + $undo = undoArchiveBefore('network', $_POST['network_ids'] ?? []); // for Undo on the message $count = 0; foreach (networksForBulk(2) as $row) { if (!$row['network_archived_at']) { @@ -258,6 +261,7 @@ if (isset($_POST['bulk_archive_networks'])) { } flashAlert("Archived $count network" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/network_ip.php b/agent/post/network_ip.php index d8843983f..e45c9e79f 100644 --- a/agent/post/network_ip.php +++ b/agent/post/network_ip.php @@ -156,6 +156,7 @@ if (isset($_POST['bulk_ip_type'])) { redirect(); } + $undo = undoSnapshot('network_ips', 'ip_id', $_POST['network_ip_ids'] ?? [], ['ip_type'], ''); // for Undo on the message $count = 0; foreach (networkIpsForBulk(2) as $ip_id => $row) { mysqli_query($mysqli, "UPDATE network_ips SET ip_type = '$type' WHERE ip_id = $ip_id"); @@ -164,6 +165,7 @@ if (isset($_POST['bulk_ip_type'])) { } flashAlert("Made $count address" . ($count === 1 ? '' : 'es') . " " . strtolower(NETWORK_IP_TYPES[$type][3]) . ""); + undoOfferChanges($undo, "Type put back on {n} address{s}", 'module_support', 2, 'es', ''); redirect(); diff --git a/agent/post/product.php b/agent/post/product.php index 2aed41365..668a057da 100644 --- a/agent/post/product.php +++ b/agent/post/product.php @@ -128,11 +128,13 @@ if (isset($_GET['archive_product'])) { $product_name = escapeSql(getFieldById('products', $product_id, 'product_name')); + $undo = undoArchiveBefore('product', $product_id); // for Undo on the message mysqli_query($mysqli,"UPDATE products SET product_archived_at = NOW() WHERE product_id = $product_id"); logAudit("Product", "Archive", "$session_name archived product $product_name", 0, $product_id); flashAlert("Product " . escapeHtml(stripslashes($product_name)) . " archived - it is no longer offered on new lines", 'error'); + undoOfferArchive($undo); redirect(); @@ -191,6 +193,7 @@ if (isset($_POST['bulk_edit_product_category'])) { $category_name = escapeSql(getFieldById('categories', $category_id, 'category_name')); // Assign category to Selected Products + $undo = undoSnapshot('products', 'product_id', $_POST['product_ids'] ?? [], ['product_category_id'], ''); // for Undo on the message if (isset($_POST['product_ids'])) { // Get Count @@ -211,6 +214,7 @@ if (isset($_POST['bulk_edit_product_category'])) { logAudit("Product", "Edit", "$session_name assigned category $category_name to $count product(s)"); flashAlert("Assigned category " . escapeHtml(stripslashes($category_name)) . " to $count product(s)"); + undoOfferChanges($undo, "Category put back on {n} product{s}", 'module_sales'); } redirect(); @@ -223,6 +227,7 @@ if (isset($_POST['bulk_archive_products'])) { enforceUserPermission('module_sales', 2); + $undo = undoArchiveBefore('product', $_POST['product_ids'] ?? []); // for Undo on the message if (isset($_POST['product_ids'])) { $count = count($_POST['product_ids']); @@ -242,6 +247,7 @@ if (isset($_POST['bulk_archive_products'])) { logAudit("Product", "Bulk Archive", "$session_name archived $count product(s)"); flashAlert("Archived $count product(s)", 'error'); + undoOfferArchive($undo); } diff --git a/agent/post/project.php b/agent/post/project.php index ce73f3d1c..f39e3f08b 100644 --- a/agent/post/project.php +++ b/agent/post/project.php @@ -164,9 +164,11 @@ if (isset($_GET['archive_project'])) { $row = projectForRequest($_GET['archive_project'], 2); + $undo = undoArchiveBefore('project', $row['project_id']); // for Undo on the message projectArchive($row); flashAlert("Project " . escapeHtml(projectReference($row) . ' - ' . $row['project_name']) . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -377,6 +379,7 @@ if (isset($_POST['bulk_archive_projects'])) { validateCSRFToken(); $done = 0; + $undo = undoArchiveBefore('project', $_POST['project_ids'] ?? []); // for Undo on the message foreach (projectsForBulk(2) as $row) { if (!empty($row['project_archived_at'])) { continue; @@ -386,6 +389,7 @@ if (isset($_POST['bulk_archive_projects'])) { } flashAlert("$done project" . ($done === 1 ? '' : 's') . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -434,6 +438,7 @@ if (isset($_POST['bulk_edit_project_manager'])) { $manager_name = $manager_id ? escapeSql((string) getFieldById('users', $manager_id, 'user_name')) : 'No One'; $done = 0; + $undo = undoSnapshot('projects', 'project_id', $_POST['project_ids'] ?? [], ['project_manager'], 'project_client_id'); // for Undo on the message foreach (projectsForBulk(2) as $row) { if (!projectIsOpen($row) || intval($row['project_manager']) === $manager_id) { continue; @@ -445,6 +450,7 @@ if (isset($_POST['bulk_edit_project_manager'])) { } flashAlert("Manager of $done project" . ($done === 1 ? '' : 's') . " set to " . escapeHtml(stripslashes($manager_name)) . ""); + undoOfferChanges($undo, "Manager put back on {n} project{s}", 'module_support'); redirect(); @@ -458,6 +464,7 @@ if (isset($_POST['bulk_edit_project_due'])) { $done = 0; $skipped = 0; + $undo = undoSnapshot('projects', 'project_id', $_POST['project_ids'] ?? [], ['project_due'], 'project_client_id'); // for Undo on the message foreach (projectsForBulk(2) as $row) { if (!projectIsOpen($row)) { continue; @@ -474,6 +481,7 @@ if (isset($_POST['bulk_edit_project_due'])) { flashAlert("Due date of $done project" . ($done === 1 ? '' : 's') . ($due === 'NULL' ? ' cleared' : ' set to ' . escapeHtml(date('M j, Y', strtotime(trim($due, "'")))) . '') . ($skipped ? ", $skipped skipped - they start after it" : '')); + undoOfferChanges($undo, "Due date put back on {n} project{s}", 'module_support'); redirect(); diff --git a/agent/post/rack.php b/agent/post/rack.php index ff72df602..a23b082b9 100644 --- a/agent/post/rack.php +++ b/agent/post/rack.php @@ -132,9 +132,11 @@ if (isset($_GET['archive_rack']) || isset($_GET['restore_rack'])) { enforceClientAccess(); if ($is_archive) { + $undo = undoArchiveBefore('rack', $rack_id); // for Undo on the message mysqli_query($mysqli, "UPDATE racks SET rack_archived_at = NOW() WHERE rack_id = $rack_id"); logAudit("Rack", "Archive", "$session_name archived rack $rack_name", $client_id, $rack_id); flashAlert("Rack $rack_name_display archived", 'error'); + undoOfferArchive($undo); } else { mysqli_query($mysqli, "UPDATE racks SET rack_archived_at = NULL WHERE rack_id = $rack_id"); logAudit("Rack", "Restore", "$session_name restored rack $rack_name", $client_id, $rack_id); @@ -351,6 +353,8 @@ if (isset($_POST['move_rack_unit'])) { logAudit("Rack", "Edit", "$session_name moved " . escapeSql($item_name) . " to $position ($face) in rack $rack_name", $client_id, $rack_id); flashAlert("" . strip_tags($item_name) . " moved to $position" . ($face !== $row['unit_face'] ? " on the $face" : '')); + undoOffer("" . escapeHtml(strip_tags($item_name)) . " is back at " . rackPositionLabel($row['unit_start_number'], $row['unit_end_number']) . " on the {$row['unit_face']}", + [['rack', $unit_id, intval($row['unit_start_number']), intval($row['unit_end_number']), $row['unit_face'], $start, $face]], 'module_support'); redirect(); diff --git a/agent/post/service.php b/agent/post/service.php index e88f52ddd..88768a746 100644 --- a/agent/post/service.php +++ b/agent/post/service.php @@ -149,9 +149,11 @@ if (isset($_GET['archive_service'])) { $row = serviceForRequest($_GET['archive_service'], 2); + $undo = undoArchiveBefore('service', $row['service_id']); // for Undo on the message serviceArchive($row); flashAlert("Service " . escapeHtml($row['service_name']) . " archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -362,6 +364,7 @@ if (isset($_POST['bulk_archive_services'])) { validateCSRFToken(); + $undo = undoArchiveBefore('service', $_POST['service_ids'] ?? []); // for Undo on the message $count = 0; foreach (servicesForBulk(2) as $row) { if (!$row['service_archived_at']) { @@ -371,6 +374,7 @@ if (isset($_POST['bulk_archive_services'])) { } flashAlert("Archived $count service" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/software.php b/agent/post/software.php index bac6ab3e4..d444f2184 100644 --- a/agent/post/software.php +++ b/agent/post/software.php @@ -336,11 +336,13 @@ if (isset($_GET['archive_software'])) { // Seats stay put - an archived license drops off every device and user // anyway, and comes back with them if it is restored + $undo = undoArchiveBefore('software', $software_id); // for Undo on the message mysqli_query($mysqli, "UPDATE software SET software_archived_at = NOW() WHERE software_id = $software_id"); logAudit("Software", "Archive", "$session_name archived license " . escapeSql($row['software_name']), $client_id, $software_id); flashAlert("License {$row['software_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -395,6 +397,7 @@ if (isset($_POST['bulk_archive_software'])) { enforceUserPermission('module_support', 2); + $undo = undoArchiveBefore('software', $_POST['software_ids'] ?? []); // for Undo on the message $rows = softwareBulkRows($_POST['software_ids'] ?? []); foreach ($rows as $software_id => $row) { $client_id = intval($row['software_client_id']); @@ -403,6 +406,7 @@ if (isset($_POST['bulk_archive_software'])) { } flashAlert("Archived " . count($rows) . " license" . (count($rows) === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/post/ticket.php b/agent/post/ticket.php index 87166f28e..8b8939515 100644 --- a/agent/post/ticket.php +++ b/agent/post/ticket.php @@ -747,6 +747,7 @@ if (isset($_POST['bulk_edit_ticket_priority'])) { } // The same change the priority picker makes - history, SLA, audit and the custom action + $undo = undoSnapshot('tickets', 'ticket_id', $_POST['ticket_ids'] ?? [], ['ticket_priority'], 'ticket_client_id'); // for Undo on the message $count = 0; foreach (ticketsForBulk(2) as $ticket_id => $row) { [$ok] = ticketChangePriority($ticket_id, $priority); @@ -756,6 +757,7 @@ if (isset($_POST['bulk_edit_ticket_priority'])) { logAudit("Ticket", "Bulk Edit", "$session_name set the priority of $count ticket(s) to $priority"); flashAlert("Priority set to $priority on $count ticket" . ($count === 1 ? '' : 's')); + undoOfferChanges($undo, "Priority put back on {n} ticket{s}", 'module_support', 2, 's', 'ticket_priority'); redirect(); @@ -768,6 +770,7 @@ if (isset($_POST['bulk_edit_ticket_category'])) { $category_id = ticketCategoryId($_POST['bulk_category'] ?? 0); $category_name = $category_id ? (string) getFieldById('categories', $category_id, 'category_name') : 'Not categorized'; + $undo = undoSnapshot('tickets', 'ticket_id', $_POST['ticket_ids'] ?? [], ['ticket_category'], 'ticket_client_id'); // for Undo on the message $count = 0; foreach (ticketsForBulk(2) as $ticket_id => $row) { $previous = intval($row['ticket_category']) ? (string) getFieldById('categories', intval($row['ticket_category']), 'category_name') : 'Not categorized'; @@ -786,6 +789,7 @@ if (isset($_POST['bulk_edit_ticket_category'])) { logAudit("Ticket", "Bulk Edit", "$session_name set the category of $count ticket(s) to " . escapeSql($category_name)); flashAlert("Category set to " . escapeHtml($category_name) . " on $count ticket" . ($count === 1 ? '' : 's')); + undoOfferChanges($undo, "Category put back on {n} ticket{s}", 'module_support', 2, 's', 'ticket_category'); redirect(); @@ -970,6 +974,7 @@ if (isset($_POST['bulk_add_ticket_project'])) { $project_name = $project_input ? (string) getFieldById('projects', $project_input, 'project_name') : ''; $count = $skipped = 0; + $undo = undoSnapshot('tickets', 'ticket_id', $_POST['ticket_ids'] ?? [], ['ticket_project_id'], 'ticket_client_id'); // for Undo on the message foreach (ticketsForBulk(2) as $ticket_id => $row) { // The project has to be the ticket's client's, or an internal one $project_id = ticketClientOwnedId('project', $project_input, $row['ticket_client_id']); @@ -987,6 +992,7 @@ if (isset($_POST['bulk_add_ticket_project'])) { // The project is named once a ticket went into it - one that fits none of them may be a client this agent can't see flashAlert(($project_input ? "$count ticket" . ($count === 1 ? '' : 's') . " added to " . ($count ? "project " . escapeHtml($project_name) . "" : 'the project') : "$count ticket" . ($count === 1 ? '' : 's') . " taken out of their project") . ($skipped ? ", $skipped skipped - the project is another client's" : '')); + undoOfferChanges($undo, "Project put back on {n} ticket{s}", 'module_support', 2, 's', 'ticket_project'); redirect(); diff --git a/agent/post/undo.php b/agent/post/undo.php new file mode 100644 index 000000000..fbcb8b002 --- /dev/null +++ b/agent/post/undo.php @@ -0,0 +1,19 @@ +{$row['vendor_name']} archived", 'error'); + undoOfferArchive($undo); redirect(); @@ -337,6 +339,7 @@ if (isset($_POST['bulk_archive_vendors'])) { validateCSRFToken(); + $undo = undoArchiveBefore('vendor', $_POST['vendor_ids'] ?? []); // for Undo on the message $count = 0; foreach (array_unique(array_map('intval', (array) ($_POST['vendor_ids'] ?? []))) as $vendor_id) { $row = vendorRow($vendor_id); @@ -351,6 +354,7 @@ if (isset($_POST['bulk_archive_vendors'])) { } flashAlert("Archived $count vendor" . ($count === 1 ? '' : 's'), 'error'); + undoOfferArchive($undo); redirect(); diff --git a/agent/product.php b/agent/product.php index 6a87cc354..3ebf0392e 100644 --- a/agent/product.php +++ b/agent/product.php @@ -171,8 +171,7 @@ if (!$product) { - + Archive diff --git a/agent/products.php b/agent/products.php index c2c0d7f6c..e321892da 100644 --- a/agent/products.php +++ b/agent/products.php @@ -286,7 +286,7 @@ $add_type = in_array($view, ['product', 'hardware', 'stocked', 'reorder'], true) - @@ -433,8 +433,7 @@ $add_type = in_array($view, ['product', 'hardware', 'stocked', 'reorder'], true) - + Archive diff --git a/agent/project.php b/agent/project.php index 170f4f5e8..662dd2f10 100644 --- a/agent/project.php +++ b/agent/project.php @@ -233,7 +233,7 @@ echo agentBannersHtml($project_client_id); Restore - + Archive diff --git a/agent/projects.php b/agent/projects.php index 1d501abfe..b88b65b40 100644 --- a/agent/projects.php +++ b/agent/projects.php @@ -445,7 +445,7 @@ $hidden_filter_count = $date_filter_active ? 1 : 0; Restore - + Archive diff --git a/agent/rack.php b/agent/rack.php index 55c7f97af..4ecb72394 100644 --- a/agent/rack.php +++ b/agent/rack.php @@ -149,7 +149,7 @@ if (mysqli_num_rows($sql) == 0) { Restore - + Archive diff --git a/agent/racks.php b/agent/racks.php index 379353841..09148ec80 100644 --- a/agent/racks.php +++ b/agent/racks.php @@ -273,7 +273,7 @@ foreach ($racks as $rack_id => $row) { Restore - + Archive diff --git a/agent/service.php b/agent/service.php index 40b2ea78f..2ed990dad 100644 --- a/agent/service.php +++ b/agent/service.php @@ -235,8 +235,7 @@ if (!$service || ($client_url && intval($service['service_client_id']) !== intva - + Archive diff --git a/agent/services.php b/agent/services.php index a95d665d1..f568e9e6b 100644 --- a/agent/services.php +++ b/agent/services.php @@ -241,8 +241,7 @@ $link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['f - @@ -418,8 +417,7 @@ $link_icons = ['asset' => ['fa-desktop', 'asset', 'assets'], 'credential' => ['f - + Archive diff --git a/agent/software.php b/agent/software.php index 71325d73c..10c3df2da 100644 --- a/agent/software.php +++ b/agent/software.php @@ -348,7 +348,7 @@ while ($license_type_row = mysqli_fetch_row($sql_license_types)) { Tags - @@ -556,7 +556,7 @@ while ($license_type_row = mysqli_fetch_row($sql_license_types)) { Renew - + Archive diff --git a/agent/vendor.php b/agent/vendor.php index 7b90856a9..ce0421a45 100644 --- a/agent/vendor.php +++ b/agent/vendor.php @@ -361,7 +361,7 @@ if (!$vendor || (isset($_GET['client_id']) && $vendor_client_id !== intval($clie - + Archive diff --git a/agent/vendors.php b/agent/vendors.php index ec54e14bb..0a8db94f5 100644 --- a/agent/vendors.php +++ b/agent/vendors.php @@ -251,7 +251,7 @@ $missing_templates = $view === 'client' && !$archived ? vendorTemplatesMissingFo - @@ -453,7 +453,7 @@ $missing_templates = $view === 'client' && !$archived ? vendorTemplatesMissingFo - + Archive diff --git a/css/itflow_custom.css b/css/itflow_custom.css index 5b17d49dc..ef2a7f008 100644 --- a/css/itflow_custom.css +++ b/css/itflow_custom.css @@ -638,6 +638,19 @@ a:focus { animation: itflow-toast-progress 5s linear both; } +/* With Undo on it (functions/undo.php), twice as long to reach the button */ +.itflow-toast.itflow-toast-undo { + animation: + itflow-toast-in 300ms ease-out both, + itflow-toast-out 1s ease-in 10s both; +} +.itflow-toast-undo .itflow-toast-progress { + animation-duration: 10s; +} +.itflow-toast.itflow-toast-undo:hover { + animation-play-state: paused; +} + @keyframes itflow-toast-in { from { opacity: 0; diff --git a/functions.php b/functions.php index 1b51d0fa5..ad3fdcdc1 100644 --- a/functions.php +++ b/functions.php @@ -29,6 +29,7 @@ require_once __DIR__ . '/functions/rack.php'; require_once __DIR__ . '/functions/asset.php'; require_once __DIR__ . '/functions/asset_type.php'; require_once __DIR__ . '/functions/archived.php'; +require_once __DIR__ . '/functions/undo.php'; require_once __DIR__ . '/functions/contact.php'; require_once __DIR__ . '/functions/contact_bounce.php'; require_once __DIR__ . '/functions/software.php'; diff --git a/functions/request.php b/functions/request.php index 2b76de0c9..3a73c529c 100644 --- a/functions/request.php +++ b/functions/request.php @@ -123,4 +123,6 @@ function redirect($url = null, $permanent = false) { function flashAlert(string $message, string $type = 'success'): void { $_SESSION['alert_type'] = $type; $_SESSION['alert_message'] = $message; + // A new message carries no Undo until undoOffer() gives it one (functions/undo.php) + unset($_SESSION['alert_undo']); } diff --git a/functions/undo.php b/functions/undo.php new file mode 100644 index 000000000..58cf22017 --- /dev/null +++ b/functions/undo.php @@ -0,0 +1,380 @@ + $done, + 'plural' => $plural, + 'steps' => array_values($steps), + 'module' => $module, + 'level' => $level, + 'user' => intval($session_user_id), + 'at' => time(), + ]; + $_SESSION['undo'] = array_slice($offers, -UNDO_KEEP, null, true); + $_SESSION['alert_undo'] = $token; + return $token; +} + +/** The offer the next message carries - its token, or '' (includes/inc_alert_feedback.php). */ +function undoTokenForAlert(): string { + $token = (string) ($_SESSION['alert_undo'] ?? ''); + $offer = $_SESSION['undo'][$token] ?? null; + return $offer && time() - intval($offer['at']) < UNDO_SECONDS ? $token : ''; +} + +/* + * These rows' columns as they are now, before a change - for undoChangedSteps() after it. $ids + * as posted (made whole numbers here); $client_column says whose each row is, '' for none. + */ +function undoSnapshot(string $table, string $id_column, $ids, array $columns, string $client_column = ''): array { + global $mysqli; + $ids = array_values(array_unique(array_filter(array_map('intval', (array) $ids)))); + $snapshot = ['table' => $table, 'id' => $id_column, 'columns' => $columns, 'client' => $client_column, 'rows' => []]; + if (!$ids) { + return $snapshot; + } + $select = implode(', ', array_merge([$id_column], $columns, $client_column !== '' ? [$client_column] : [])); + $sql = mysqli_query($mysqli, "SELECT $select FROM $table WHERE $id_column IN (" . implode(',', $ids) . ")"); + while ($row = mysqli_fetch_assoc($sql)) { + $snapshot['rows'][intval($row[$id_column])] = $row; + } + return $snapshot; +} + +/** After the change: a 'set' step for each row of the snapshot that it changed. */ +function undoChangedSteps(array $snapshot): array { + global $mysqli; + if (!$snapshot['rows']) { + return []; + } + $after = undoSnapshot($snapshot['table'], $snapshot['id'], array_keys($snapshot['rows']), $snapshot['columns'], $snapshot['client'])['rows']; + $steps = []; + foreach ($snapshot['rows'] as $id => $row) { + if (!isset($after[$id])) { + continue; + } + $before = []; + $now = []; + foreach ($snapshot['columns'] as $column) { + if ($row[$column] !== $after[$id][$column]) { + $before[$column] = $row[$column]; + $now[$column] = $after[$id][$column]; + } + } + if ($before) { + $client_id = $snapshot['client'] !== '' ? intval($row[$snapshot['client']]) : 0; + $steps[] = ['set', $snapshot['table'], $snapshot['id'], $id, $before, $now, $client_id]; + } + } + return $steps; +} + +/* + * undoChangedSteps() and undoOffer() in one - for a bulk change of columns and nothing else. + * $as runs each row back through a step of its own (undoStepsAs()) rather than a plain 'set'. + */ +function undoOfferChanges(array $snapshot, string $done, string $module, int $level = 2, string $plural = 's', string $as = ''): string { + $steps = undoChangedSteps($snapshot); + if ($as !== '') { + $steps = undoStepsAs($as, $steps); + } + return undoOffer($done, $steps, $module, $level, $plural); +} + +/** 'set' steps of one column as steps of $type - [type, id, before, after] - for a change that goes back through its own function. */ +function undoStepsAs(string $type, array $steps): array { + return array_map(function ($step) use ($type) { + $column = array_key_first($step[4]); + return [$type, $step[3], $step[4][$column], $step[5][$column]]; + }, $steps); +} + +/* + * Before archiving $ids of a kind on Archived (functions/archived.php): which of them aren't + * archived yet, and what the archive also takes away - a contact's roles, a document's links, + * a client's running recurring invoices. Hand it to undoOfferArchive() after. + */ +function undoArchiveBefore(string $kind_key, $ids): array { + global $mysqli; + $kind = archivedKinds()[$kind_key] ?? null; + $ids = array_values(array_unique(array_filter(array_map('intval', (array) $ids)))); + $before = ['kind' => $kind_key, 'ids' => [], 'snapshot' => null, 'rows' => [], 'recurring' => []]; + if (!$kind || !$ids) { + return $before; + } + $sql = mysqli_query($mysqli, "SELECT {$kind['id']} FROM {$kind['table']} WHERE {$kind['id']} IN (" . implode(',', $ids) . ") AND {$kind['archived']} IS NULL"); + $ids = array_map('intval', array_column(mysqli_fetch_all($sql), 0)); + $before['ids'] = $ids; + if (!$ids) { + return $before; + } + if ($kind_key === 'contact') { + $before['snapshot'] = undoSnapshot('contacts', 'contact_id', $ids, ['contact_important', 'contact_billing', 'contact_technical'], 'contact_client_id'); + } + if ($kind_key === 'document') { + foreach (LINK_RELATIONS as $pair => $relation) { + if (in_array('document', explode('|', $pair), true)) { + $sql = mysqli_query($mysqli, "SELECT * FROM {$relation['table']} WHERE document_id IN (" . implode(',', $ids) . ")"); + $rows = mysqli_fetch_all($sql, MYSQLI_ASSOC); + if ($rows) { + $before['rows'][$relation['table']] = $rows; + } + } + } + } + if ($kind_key === 'client') { + $sql = mysqli_query($mysqli, "SELECT recurring_invoice_id FROM recurring_invoices WHERE recurring_invoice_client_id IN (" . implode(',', $ids) . ") AND recurring_invoice_status = 1"); + $before['recurring'] = array_map('intval', array_column(mysqli_fetch_all($sql), 0)); + } + return $before; +} + +/* + * After archiving: offer back what undoArchiveBefore() saw, as far as it is archived now. One + * offer for any number of kinds (the files list archives files and documents together). The + * message after: "Name is back", or "3 assets are back". + */ +function undoOfferArchive(array ...$befores): string { + global $mysqli; + $kinds = archivedKinds(); + $steps = []; + $names = []; + $labels = []; + $module = ''; + foreach ($befores as $before) { + $kind = $kinds[$before['kind']] ?? null; + if (!$kind || !$before['ids']) { + continue; + } + $sql = mysqli_query($mysqli, "SELECT {$kind['id']} AS id, {$kind['name']} AS name FROM {$kind['table']} WHERE {$kind['id']} IN (" . implode(',', $before['ids']) . ") AND {$kind['archived']} IS NOT NULL"); + $archived = []; + while ($row = mysqli_fetch_assoc($sql)) { + $archived[intval($row['id'])] = $row['name']; + } + if (!$archived) { + continue; + } + foreach (array_keys($archived) as $id) { + $steps[] = ['restore', $before['kind'], $id]; + } + if ($before['snapshot']) { + $before['snapshot']['rows'] = array_intersect_key($before['snapshot']['rows'], $archived); + $steps = array_merge($steps, undoChangedSteps($before['snapshot'])); + } + foreach ($before['rows'] as $table => $rows) { + $rows = array_values(array_filter($rows, function ($row) use ($archived) { + return isset($archived[intval($row['document_id'])]); + })); + if ($rows) { + $steps[] = ['rows', $table, $rows]; + } + } + foreach ($before['recurring'] as $recurring_invoice_id) { + $steps[] = ['recurring_on', $recurring_invoice_id]; + } + $names = array_merge($names, array_values($archived)); + $labels[] = strtolower($kind['label']); + $module = $module ?: $kind['module']; + } + if (!$names) { + return ''; + } + $done = count($names) === 1 + ? '' . escapeHtml($names[0]) . ' is back' + : '{n} ' . (count(array_unique($labels)) === 1 ? $labels[0] : 'item') . '{s} {are} back'; + return undoOffer($done, $steps, $module); +} + +/** A value as SQL - NULL stays NULL. Values come from the database, never from the request. */ +function undoSqlValue($value): string { + global $mysqli; + return $value === null ? 'NULL' : "'" . mysqli_real_escape_string($mysqli, (string) $value) . "'"; +} + +/* + * Put an offer back. [ok, message] - ok false when there was nothing it could do: gone, too late, + * someone else's, or the permission is no longer there. + */ +function undoApply(string $token): array { + global $mysqli, $session_user_id, $session_name; + + $offer = $_SESSION['undo'][$token] ?? null; + unset($_SESSION['undo'][$token]); + if (!is_array($offer) || intval($offer['user']) !== intval($session_user_id)) { + return [false, 'That can no longer be undone.']; + } + if (time() - intval($offer['at']) >= UNDO_SECONDS) { + return [false, 'That can no longer be undone - Undo works for ' . intval(UNDO_SECONDS / 60) . ' minutes.']; + } + if (lookupUserPermission($offer['module']) < intval($offer['level'])) { + return [false, 'You no longer have the permission to undo that.']; + } + + $done = 0; + $missed = 0; + foreach ($offer['steps'] as $step) { + $ok = undoStep($step); + if ($ok === null) { + continue; // a step that goes with another, not counted on its own + } + $ok ? $done++ : $missed++; + } + + if (!$done && $missed) { + return [false, 'Nothing was put back - it has changed since.']; + } + $message = str_replace(['{n}', '{s}', '{are}'], [$done, $done === 1 ? '' : ($offer['plural'] ?? 's'), $done === 1 ? 'is' : 'are'], $offer['done']); + logAudit('Undo', 'Undo', "$session_name undid a change: " . html_entity_decode(strip_tags($message), ENT_QUOTES)); + return [true, 'Undone - ' . $message . ($missed ? " - $missed had changed since, and " . ($missed === 1 ? 'was left as it is' : 'were left as they are') : '')]; +} + +/** One step: true put back, false not (changed since, or not theirs), null not counted. */ +function undoStep(array $step) { + global $mysqli, $session_name; + + switch ($step[0]) { + case 'restore': + return archivedRestore($step[1], $step[2]) !== null; + + case 'set': + [, $table, $id_column, $id, $before, $after, $client_id] = $step; + if ($client_id && !hasClientAccess($client_id)) { + return false; + } + $sets = []; + $still = []; + foreach ($before as $column => $value) { + $sets[] = "$column = " . undoSqlValue($value); + $still[] = "$column <=> " . undoSqlValue($after[$column]); + } + if ($table === 'documents') { + $sets[] = 'document_updated_at = document_updated_at'; // a move isn't an edit + } + mysqli_query($mysqli, "UPDATE $table SET " . implode(', ', $sets) . " WHERE $id_column = " . intval($id) . " AND " . implode(' AND ', $still)); + return mysqli_affected_rows($mysqli) > 0; + + case 'rows': + [, $table, $rows] = $step; + foreach ($rows as $row) { + $values = array_map('undoSqlValue', array_values($row)); + mysqli_query($mysqli, "INSERT IGNORE INTO $table (" . implode(', ', array_keys($row)) . ") VALUES (" . implode(', ', $values) . ")"); + } + return null; + + case 'recurring_on': + $recurring_invoice_id = intval($step[1]); + // Only once its client is back + mysqli_query($mysqli, "UPDATE recurring_invoices JOIN clients ON client_id = recurring_invoice_client_id SET recurring_invoice_status = 1 + WHERE recurring_invoice_id = $recurring_invoice_id AND recurring_invoice_status = 0 AND client_archived_at IS NULL"); + if (mysqli_affected_rows($mysqli) > 0) { + mysqli_query($mysqli, "INSERT INTO history SET history_status = 'Active', history_description = 'Recurring Invoice active again - its client is back', history_recurring_invoice_id = $recurring_invoice_id"); + } + return null; + + case 'folder': + [, $folder_id, $parent, $parent_after, $client_id] = $step; + if (!hasClientAccess($client_id)) { + return false; + } + $tree = folderTree($client_id); + if (!isset($tree[$folder_id]) || intval($tree[$folder_id]['parent_folder']) !== intval($parent_after) + || folderOwnedId($parent, $client_id) !== intval($parent) || in_array(intval($parent), folderSubtree($tree, $folder_id), true)) { + return false; + } + mysqli_query($mysqli, "UPDATE folders SET parent_folder = " . intval($parent) . " WHERE folder_id = " . intval($folder_id)); + logAudit("Folder", "Move", "$session_name moved folder " . escapeSql($tree[$folder_id]['folder_name'] ?? '') . " back into " . escapeSql(folderDisplayName($parent)), $client_id, $folder_id); + return true; + + case 'rack': + [, $unit_id, $start, $end, $face, $start_after, $face_after] = $step; + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT unit_rack_id, unit_start_number, unit_face, unit_full_depth, rack_client_id, rack_archived_at FROM rack_units + JOIN racks ON rack_id = unit_rack_id WHERE unit_id = " . intval($unit_id))); + if (!$row || $row['rack_archived_at'] || !hasClientAccess($row['rack_client_id']) + || intval($row['unit_start_number']) !== intval($start_after) || $row['unit_face'] !== $face_after + || rackUnitConflict(intval($row['unit_rack_id']), $start, $end, $face, intval($row['unit_full_depth']), $unit_id)) { + return false; + } + mysqli_query($mysqli, "UPDATE rack_units SET unit_start_number = " . intval($start) . ", unit_end_number = " . intval($end) . ", unit_face = " . undoSqlValue($face) . " WHERE unit_id = " . intval($unit_id)); + logAudit("Rack", "Edit", "$session_name moved an item back to " . html_entity_decode(rackPositionLabel($start, $end)) . " ($face)", intval($row['rack_client_id']), intval($row['unit_rack_id'])); + return true; + + case 'ticket_priority': + [, $ticket_id, $before, $after] = $step; + $row = ticketFieldsRow($ticket_id); + if (!$row || !hasClientAccess($row['ticket_client_id']) || $row['ticket_priority'] !== $after) { + return false; + } + return ticketChangePriority($ticket_id, $before)[0]; + + case 'ticket_category': + case 'ticket_project': + [, $ticket_id, $before, $after] = $step; + $column = $step[0] === 'ticket_category' ? 'ticket_category' : 'ticket_project_id'; + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT ticket_client_id, ticket_prefix, ticket_number FROM tickets WHERE ticket_id = " . intval($ticket_id) . " AND $column = " . intval($after))); + if (!$row || !hasClientAccess($row['ticket_client_id'])) { + return false; + } + mysqli_query($mysqli, "UPDATE tickets SET $column = " . intval($before) . " WHERE ticket_id = " . intval($ticket_id)); + if ($column === 'ticket_category') { + $name = intval($before) ? (string) getFieldById('categories', intval($before), 'category_name') : 'Not categorized'; + logTicketHistory($ticket_id, "$session_name put the category back to " . escapeSql($name)); + } else { + $name = intval($before) ? (string) getFieldById('projects', intval($before), 'project_name') : ''; + logTicketHistory($ticket_id, $name !== '' ? "$session_name put the ticket back in project " . escapeSql($name) : "$session_name took the ticket back out of its project"); + } + logAudit("Ticket", "Edit", "$session_name undid a bulk change on ticket " . escapeSql(ticketReference($row)), intval($row['ticket_client_id']), $ticket_id); + triggerCustomAction('ticket_update', $ticket_id); + return true; + + case 'asset_status': + [, $asset_id, $before, $after] = $step; + $row = mysqli_fetch_assoc(mysqli_query($mysqli, "SELECT asset_name, asset_client_id FROM assets WHERE asset_id = " . intval($asset_id) . " AND asset_status <=> " . undoSqlValue($after))); + if (!$row || !hasClientAccess($row['asset_client_id'])) { + return false; + } + mysqli_query($mysqli, "UPDATE assets SET asset_status = " . undoSqlValue($before) . " WHERE asset_id = " . intval($asset_id)); + mysqli_query($mysqli, "INSERT INTO asset_history SET asset_history_status = " . undoSqlValue((string) $before) . ", asset_history_description = '" . escapeSql("$session_name put the status back on " . $row['asset_name']) . "', asset_history_asset_id = " . intval($asset_id)); + return true; + } + return false; +} diff --git a/includes/inc_alert_feedback.php b/includes/inc_alert_feedback.php index f8aab0161..11325a0ab 100644 --- a/includes/inc_alert_feedback.php +++ b/includes/inc_alert_feedback.php @@ -50,6 +50,9 @@ if (!empty($_SESSION['alert_message'])) { // Escaping lives in one place now - see alertMessageHtml() in functions/sanitize.php $alert_safe_message = alertMessageHtml($_SESSION['alert_message']); + // Undo, when the change can be put back (functions/undo.php) - and the message stays up longer for it + $alert_undo_token = function_exists('undoTokenForAlert') && !empty($_SESSION['csrf_token']) ? undoTokenForAlert() : ''; + ?>