mirror of
https://github.com/itflow-org/itflow
synced 2026-12-04 01:59:00 +00:00
Undo in Admin after archiving tags and categories (one or several), canned responses, ticket, project, document, vendor, license and contract templates, roles, payment methods with any default they were, SLAs, custom links, portal announcements and agent banners, and after archiving a tax or switching off a ticket status when nothing was moved; payment methods archive without asking first and the SLA archive message names the SLA
This commit is contained in:
@@ -210,8 +210,8 @@ $csrf = $_SESSION['csrf_token'];
|
||||
<i class="fas fa-fw fa-box-open text-secondary me-2"></i>Restore
|
||||
</a>
|
||||
<?php } else { ?>
|
||||
<a class="dropdown-item text-danger confirm-link" href="post.php?archive_payment_method=<?= $payment_method_id ?>&csrf_token=<?= $csrf ?>"
|
||||
data-confirm-title="Archive <?= $name ?>?" data-confirm-text="It can't be picked any more<?= $is_default ? ', and stops being a default' : '' ?>. The records that used it keep it." data-confirm-button="Archive">
|
||||
<a class="dropdown-item text-danger" href="post.php?archive_payment_method=<?= $payment_method_id ?>&csrf_token=<?= $csrf ?>"
|
||||
title="It can't be picked any more<?= $is_default ? ', and stops being a default' : '' ?> - the records that used it keep it">
|
||||
<i class="fas fa-fw fa-archive me-2"></i>Archive
|
||||
</a>
|
||||
<?php } ?>
|
||||
|
||||
@@ -76,11 +76,15 @@ if (isset($_GET['archive_canned_response']) || isset($_GET['restore_canned_respo
|
||||
$name = escapeSql($row['canned_response_name']);
|
||||
|
||||
// Archived, it isn't offered on tickets; restoring it is all it takes to offer it again
|
||||
$undo = $archive ? undoArchivedBefore('canned_responses', 'canned_response_id', [$canned_response_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE canned_responses SET canned_response_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE canned_response_id = $canned_response_id");
|
||||
|
||||
logAudit("Canned Response", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " canned response $name", 0, $canned_response_id);
|
||||
|
||||
flashAlert("Canned response <strong>" . escapeHtml($row['canned_response_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['canned_response_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -93,11 +93,13 @@ if (isset($_GET['archive_category'])) {
|
||||
|
||||
$row = categoryRow(intval($_GET['archive_category']));
|
||||
if ($row && !$row['category_archived_at']) {
|
||||
$undo = undoArchivedBefore('categories', 'category_id', [$row['category_id']]);
|
||||
categoryArchive($row['category_id']);
|
||||
$used = categoryUsageFor($row['category_id']);
|
||||
logAudit("Category", "Archive", "$session_name archived " . $category_kind_word($row) . " " . escapeSql($row['category_name']), 0, intval($row['category_id']));
|
||||
flashAlert(ucfirst($category_kind_word($row)) . " <strong>" . escapeHtml($row['category_name']) . "</strong> archived - "
|
||||
. ($used['all'] ? "it stays on the " . escapeHtml(categoryUsageText($row, $used)) . " that have it, but isn't offered for new ones" : "it isn't offered for new ones"));
|
||||
undoOfferArchived($undo, 'categor', $row['category_name'], [], 'y|ies');
|
||||
}
|
||||
|
||||
redirect();
|
||||
@@ -244,6 +246,7 @@ if (isset($_POST['bulk_archive_categories']) || isset($_POST['bulk_restore_categ
|
||||
validateCSRFToken();
|
||||
|
||||
$archive = isset($_POST['bulk_archive_categories']);
|
||||
$undo = $archive ? undoArchivedBefore('categories', 'category_id', $_POST['category_ids'] ?? []) : null;
|
||||
$count = 0;
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['category_ids'] ?? []))) as $category_id) {
|
||||
$row = categoryRow($category_id);
|
||||
@@ -260,6 +263,9 @@ if (isset($_POST['bulk_archive_categories']) || isset($_POST['bulk_restore_categ
|
||||
}
|
||||
|
||||
flashAlert(($archive ? "Archived " : "Restored ") . $count . ($count === 1 ? " category" : " categories") . ($archive && $count ? " - they stay on their records, but aren't offered for new ones" : ''));
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, 'categor', '', [], 'y|ies');
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -88,10 +88,14 @@ if (isset($_GET['archive_contract_template']) || isset($_GET['restore_contract_t
|
||||
$contract_template_id = intval($row['contract_template_id']);
|
||||
|
||||
// Archived, it isn't offered on a new contract; contracts started from it are unchanged
|
||||
$undo = $archive ? undoArchivedBefore('contract_templates', 'contract_template_id', [$contract_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE contract_templates SET contract_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE contract_template_id = $contract_template_id");
|
||||
|
||||
logAudit("Contract Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " contract template " . escapeSql($row['contract_template_name']), 0, $contract_template_id);
|
||||
flashAlert("Contract template <strong>" . escapeHtml($row['contract_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['contract_template_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -68,6 +68,7 @@ if (isset($_GET['archive_custom_link']) || isset($_GET['restore_custom_link']))
|
||||
$row = customLinkRow($archive ? $_GET['archive_custom_link'] : $_GET['restore_custom_link']);
|
||||
if ($row) {
|
||||
$custom_link_id = intval($row['custom_link_id']);
|
||||
$undo = $archive ? undoArchivedBefore('custom_links', 'custom_link_id', [$custom_link_id]) : null;
|
||||
if ($archive) {
|
||||
mysqli_query($mysqli, "UPDATE custom_links SET custom_link_archived_at = NOW() WHERE custom_link_id = $custom_link_id");
|
||||
} else {
|
||||
@@ -76,6 +77,9 @@ if (isset($_GET['archive_custom_link']) || isset($_GET['restore_custom_link']))
|
||||
}
|
||||
logAudit("Custom Link", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " custom link " . escapeSql($row['custom_link_name']), 0, $custom_link_id);
|
||||
flashAlert("Link <strong>" . escapeHtml($row['custom_link_name']) . "</strong> " . ($archive ? 'archived - it no longer shows in its menu' : 'restored'));
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['custom_link_name']);
|
||||
}
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -72,11 +72,15 @@ if (isset($_GET['archive_document_template']) || isset($_GET['restore_document_t
|
||||
$document_template_id = intval($row['document_template_id']);
|
||||
|
||||
// Archived, it isn't offered for new documents; the ones made from it stay
|
||||
$undo = $archive ? undoArchivedBefore('document_templates', 'document_template_id', [$document_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE document_templates SET document_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE document_template_id = $document_template_id");
|
||||
|
||||
logAudit("Document Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " document template " . escapeSql($row['document_template_name']), 0, $document_template_id);
|
||||
|
||||
flashAlert("Document template <strong>" . escapeHtml($row['document_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['document_template_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -71,10 +71,15 @@ if (isset($_GET['archive_payment_method']) || isset($_GET['restore_payment_metho
|
||||
$archive = isset($_GET['archive_payment_method']);
|
||||
$row = paymentMethodRow($archive ? $_GET['archive_payment_method'] : $_GET['restore_payment_method']);
|
||||
if ($row) {
|
||||
$undo = $archive ? undoArchivedBefore('payment_methods', 'payment_method_id', [$row['payment_method_id']]) : null;
|
||||
$defaults = $archive ? undoSnapshot('settings', 'company_id', [1], ['config_default_payment_method', 'config_default_expense_payment_method']) : null;
|
||||
$cleared = paymentMethodSetArchived($row, $archive);
|
||||
$no_longer = $cleared ? ' - no longer the default for ' . implode(' or ', array_map(function ($way) { return $way === 'in' ? 'payments' : 'expenses'; }, $cleared)) : '';
|
||||
logAudit("Payment Method", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " payment method " . escapeSql($row['payment_method_name']) . $no_longer, 0, intval($row['payment_method_id']));
|
||||
flashAlert("Payment method <strong>" . escapeHtml($row['payment_method_name']) . "</strong> " . ($archive ? "archived - it isn't offered any more$no_longer" : 'restored'));
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['payment_method_name'], [$defaults]);
|
||||
}
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
@@ -62,12 +62,16 @@ if (isset($_GET['archive_portal_announcement']) || isset($_GET['restore_portal_a
|
||||
redirect();
|
||||
}
|
||||
|
||||
$undo = $archive ? undoArchivedBefore('portal_announcements', 'announcement_id', [$announcement_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE portal_announcements SET announcement_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE announcement_id = $announcement_id");
|
||||
$title = escapeSql($row['announcement_title']);
|
||||
|
||||
logAudit("Announcement", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " the client portal announcement $title", intval($row['announcement_client_id']), $announcement_id);
|
||||
|
||||
flashAlert("Announcement <strong>" . escapeHtml($row['announcement_title']) . "</strong> " . ($archive ? 'archived - the portal no longer shows it' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['announcement_title']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -140,11 +140,15 @@ if (isset($_GET['archive_project_template']) || isset($_GET['restore_project_tem
|
||||
$project_template_id = intval($archive ? $_GET['archive_project_template'] : $_GET['restore_project_template']);
|
||||
$name = projectTemplateName($project_template_id);
|
||||
|
||||
$undo = $archive ? undoArchivedBefore('project_templates', 'project_template_id', [$project_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE project_templates SET project_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE project_template_id = $project_template_id");
|
||||
|
||||
logAudit("Project Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " project template " . escapeSql($name), 0, $project_template_id);
|
||||
|
||||
flashAlert("Project template <strong>" . escapeHtml($name) . "</strong> " . ($archive ? 'archived - it is no longer offered on New Project' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $name);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -78,11 +78,13 @@ if (isset($_GET['archive_role'])) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
$undo = undoArchivedBefore('user_roles', 'role_id', [$row['role_id']]);
|
||||
roleSetArchived($row['role_id'], true);
|
||||
|
||||
logAudit("User Role", "Archive", "$session_name archived role " . escapeSql($row['role_name']), 0, $row['role_id']);
|
||||
|
||||
flashAlert("Role <strong>" . escapeHtml($row['role_name']) . "</strong> archived");
|
||||
undoOfferArchived($undo, '', $row['role_name']);
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -86,6 +86,8 @@ if (isset($_GET['archive_sla'])) {
|
||||
validateCSRFToken();
|
||||
|
||||
$sla_id = intval($_GET['archive_sla']);
|
||||
$sla_name = (string) getFieldById('slas', $sla_id, 'sla_name');
|
||||
$undo = undoArchivedBefore('slas', 'sla_id', [$sla_id]);
|
||||
|
||||
mysqli_query($mysqli, "UPDATE slas SET sla_archived_at = NOW() WHERE sla_id = $sla_id");
|
||||
|
||||
@@ -94,7 +96,8 @@ if (isset($_GET['archive_sla'])) {
|
||||
|
||||
logAudit("SLA", "Archive", "$session_name archived SLA ID $sla_id");
|
||||
|
||||
flashAlert("SLA archived");
|
||||
flashAlert($sla_name !== '' ? "SLA <strong>" . escapeHtml($sla_name) . "</strong> archived" : "SLA archived");
|
||||
undoOfferArchived($undo, 'SLA', $sla_name);
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -224,12 +224,16 @@ if (isset($_GET['archive_software_template']) || isset($_GET['restore_software_t
|
||||
$software_template_id = intval($row['software_template_id']);
|
||||
|
||||
// Archived, it isn't offered for new licenses; the ones made from it stay
|
||||
$undo = $archive ? undoArchivedBefore('software_templates', 'software_template_id', [$software_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE software_templates SET software_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . ", software_template_updated_at = software_template_updated_at
|
||||
WHERE software_template_id = $software_template_id");
|
||||
|
||||
logAudit("Software Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " license template " . escapeSql($row['software_template_name']), 0, $software_template_id);
|
||||
|
||||
flashAlert("License template <strong>" . escapeHtml($row['software_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['software_template_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -77,11 +77,13 @@ if (isset($_GET['archive_tag'])) {
|
||||
|
||||
$row = tagRow(intval($_GET['archive_tag']));
|
||||
if ($row && !$row['tag_archived_at']) {
|
||||
$undo = undoArchivedBefore('tags', 'tag_id', [$row['tag_id']]);
|
||||
tagArchive($row['tag_id']);
|
||||
$used = tagUsage($row['tag_id']);
|
||||
logAudit("Tag", "Archive", "$session_name archived " . $tag_kind_word($row) . " tag " . escapeSql($row['tag_name']), 0, intval($row['tag_id']));
|
||||
flashAlert("Tag <strong>" . escapeHtml($row['tag_name']) . "</strong> archived - "
|
||||
. ($used ? "it stays on its " . $tag_records_text($used, $row['tag_type']) . ", but isn't offered for tagging" : "it isn't offered for tagging"));
|
||||
undoOfferArchived($undo, 'tag', $row['tag_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
@@ -171,6 +173,7 @@ if (isset($_POST['bulk_archive_tags']) || isset($_POST['bulk_restore_tags'])) {
|
||||
validateCSRFToken();
|
||||
|
||||
$archive = isset($_POST['bulk_archive_tags']);
|
||||
$undo = $archive ? undoArchivedBefore('tags', 'tag_id', $_POST['tag_ids'] ?? []) : null;
|
||||
$count = 0;
|
||||
foreach (array_unique(array_map('intval', (array) ($_POST['tag_ids'] ?? []))) as $tag_id) {
|
||||
$row = tagRow($tag_id);
|
||||
@@ -187,6 +190,9 @@ if (isset($_POST['bulk_archive_tags']) || isset($_POST['bulk_restore_tags'])) {
|
||||
}
|
||||
|
||||
flashAlert(($archive ? "Archived " : "Restored ") . $count . ($count === 1 ? " tag" : " tags") . ($archive && $count ? " - they stay on their records, but aren't offered for tagging" : ''));
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, 'tag');
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -81,6 +81,8 @@ if (isset($_POST['archive_tax'])) {
|
||||
}
|
||||
|
||||
$move_to = intval($_POST['move_to'] ?? 0);
|
||||
$undo = undoArchivedBefore('taxes', 'tax_id', [$tax_id]);
|
||||
$default = undoSnapshot('settings', 'company_id', [1], ['config_tax_default_id']);
|
||||
$done = taxArchive($tax_id, $move_to);
|
||||
$label = taxLabel($row);
|
||||
$moved = taxMovedText($done['moved']);
|
||||
@@ -91,6 +93,10 @@ if (isset($_POST['archive_tax'])) {
|
||||
flashAlert("Tax <strong>" . escapeHtml($label) . "</strong> archived"
|
||||
. ($moved !== '' ? " - $moved moved to " . escapeHtml($to) : '')
|
||||
. ($done['was_default'] ? ". There is no default rate now" : ''), 'error');
|
||||
// What was moved to another rate isn't put back - with nothing moved, Undo is all it takes
|
||||
if (!$done['moved']) {
|
||||
undoOfferArchived($undo, '', $label, [$default]);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -123,6 +123,7 @@ if (isset($_POST['switch_off_ticket_status'])) {
|
||||
redirect();
|
||||
}
|
||||
|
||||
$undo = undoSnapshot('ticket_statuses', 'ticket_status_id', [$row['ticket_status_id']], ['ticket_status_active']);
|
||||
[$ok, $moved] = ticketStatusSetActive($row, false, $move_to);
|
||||
if (!$ok) {
|
||||
flashAlert("ITFlow's own statuses can't be switched off.", 'error');
|
||||
@@ -132,6 +133,10 @@ if (isset($_POST['switch_off_ticket_status'])) {
|
||||
$to_name = $moved ? ticketStatusesAll()[$move_to]['ticket_status_name'] : '';
|
||||
logAudit("Ticket Status", "Edit", "$session_name switched off ticket status " . escapeSql($name) . ($moved ? ", moving $moved tickets to " . escapeSql($to_name) : ''), 0, intval($row['ticket_status_id']));
|
||||
flashAlert("Status <strong>" . escapeHtml($name) . "</strong> switched off" . ($moved ? " - $moved " . ($moved === 1 ? 'ticket' : 'tickets') . " moved to <strong>" . escapeHtml($to_name) . "</strong>" : ''));
|
||||
// Tickets moved to another status stay there - with none moved, Undo switches it back on
|
||||
if (!$moved) {
|
||||
undoOfferChanges($undo, '<strong>' . escapeHtml($name) . '</strong> is switched on again', 'admin', 3);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -81,11 +81,15 @@ if (isset($_GET['archive_ticket_template']) || isset($_GET['restore_ticket_templ
|
||||
$name = escapeSql($row['ticket_template_name']);
|
||||
|
||||
// Archived, it isn't offered for new tickets - recurring tickets and project templates that use it keep it, so restoring it is all it takes
|
||||
$undo = $archive ? undoArchivedBefore('ticket_templates', 'ticket_template_id', [$ticket_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE ticket_templates SET ticket_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . " WHERE ticket_template_id = $ticket_template_id");
|
||||
|
||||
logAudit("Ticket Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " ticket template $name", 0, $ticket_template_id);
|
||||
|
||||
flashAlert("Ticket template <strong>" . escapeHtml($row['ticket_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['ticket_template_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
@@ -98,12 +98,16 @@ if (isset($_GET['archive_vendor_template']) || isset($_GET['restore_vendor_templ
|
||||
$vendor_template_id = intval($row['vendor_template_id']);
|
||||
|
||||
// Archived, it isn't offered for new vendors; the ones made from it stay
|
||||
$undo = $archive ? undoArchivedBefore('vendor_templates', 'vendor_template_id', [$vendor_template_id]) : null;
|
||||
mysqli_query($mysqli, "UPDATE vendor_templates SET vendor_template_archived_at = " . ($archive ? 'NOW()' : 'NULL') . ", vendor_template_updated_at = vendor_template_updated_at
|
||||
WHERE vendor_template_id = $vendor_template_id");
|
||||
|
||||
logAudit("Vendor Template", $archive ? "Archive" : "Restore", "$session_name " . ($archive ? 'archived' : 'restored') . " vendor template " . escapeSql($row['vendor_template_name']), 0, $vendor_template_id);
|
||||
|
||||
flashAlert("Vendor template <strong>" . escapeHtml($row['vendor_template_name']) . "</strong> " . ($archive ? 'archived' : 'restored'), $archive ? 'error' : 'success');
|
||||
if ($undo) {
|
||||
undoOfferArchived($undo, '', $row['vendor_template_name']);
|
||||
}
|
||||
|
||||
redirect();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user