Categories stage 1: Admin > Categories rebuilt with the ten kinds in a side nav with counts and what each is for, each category shown as it looks on records (icon or dot in its color, asset statuses as their badge) with its description and what uses it linked to the filtered lists, search, sort by name, most used or order, Current and Archived tabs, Edit, Merge into, Archive, Restore and Delete only while unused, bulk merge, archive, restore and delete, drag or Move up and Move down ordering for the ordered kinds, names in use that are not categories listed with Add, one shared category window with live preview, color swatches or none and searchable icons or none, names unique per kind and held to their column length, renaming a kind kept by name carries the new name onto its records, merge moves every reference including budget months folded per month, payment provider fees and the mileage setting, all without touching record updated_at, database 3.1.5 normalizing category colors to #rrggbb and icons to fa-name, seed data in hex, new functions/categories.php, agent + window handler routed through the same validation, note-type icons fixed in pickers, Settings > Defaults payment methods read from Payment Methods, changelog updated

This commit is contained in:
johnnyq
2026-10-17 15:22:59 -04:00
parent 95dd3ef9c5
commit 8a992039fb
18 changed files with 1812 additions and 398 deletions

View File

@@ -1,225 +1,319 @@
<?php
// Default Column Sortby Filter
$sort = "category_name";
$order = "ASC";
/*
* Admin > Categories - the categories of each kind: expense, income,
* referral and ticket, and the interface, asset status, software, rack and
* note types.
*
* Each shows as it looks on records, with its description and what uses it
* (opening the list of them, where there is one). A category can be
* changed, merged into another of its kind, archived - it stays on its
* records but isn't offered for new ones - or, while nothing uses it,
* deleted. The kinds pickers list in an order set here are dragged into it.
* The work is in functions/categories.php; the handlers are
* admin/post/category.php.
*/
require_once "includes/inc_all_admin.php";
$kinds = categoryKinds();
$kind = isset($kinds[$_GET['category'] ?? '']) ? (string) $_GET['category'] : 'Expense';
$config = categoryKind($kind);
$show_archived = isset($_GET['archived']);
$search = trim((string) ($_GET['q'] ?? ''));
if (isset($_GET['category'])) {
$category = escapeSql($_GET['category']);
} else {
$category = "Expense";
// How the list is sorted - the order pickers use first, for the kinds that keep one
$sorts = ($config['ordered'] ? ['order' => ['Order', 'fa-sort-numeric-down', 'The order they are offered in']] : [])
+ ['name' => ['Name', 'fa-sort-alpha-down', 'A to Z'], 'use' => ['Most used', 'fa-sort-amount-down', 'The ones on the most records first']];
$sort_by = isset($sorts[$_GET['sort'] ?? '']) ? (string) $_GET['sort'] : array_key_first($sorts);
$default_sort = array_key_first($sorts);
$usage = categoryUsage($kind);
$empty_use = ['all' => 0, 'archived' => 0, 'uses' => []];
$categories = [];
foreach (categoryRows($kind) as $category_id => $row) {
if ((bool) $row['category_archived_at'] !== $show_archived) {
continue;
}
if ($search !== '' && mb_stripos($row['category_name'], $search) === false && mb_stripos((string) $row['category_description'], $search) === false) {
continue;
}
$row['used'] = $usage[$category_id] ?? $empty_use;
$categories[$category_id] = $row;
}
if ($sort_by === 'name') {
uasort($categories, function ($a, $b) {
return strnatcasecmp($a['category_name'], $b['category_name']);
});
} elseif ($sort_by === 'use') {
uasort($categories, function ($a, $b) {
return $b['used']['all'] <=> $a['used']['all'] ?: strnatcasecmp($a['category_name'], $b['category_name']);
});
}
$sql = mysqli_query(
$mysqli,
"SELECT SQL_CALC_FOUND_ROWS category_color, category_description, category_id, category_name FROM categories
WHERE category_name LIKE '%$q%'
AND category_type = '$category'
AND category_$archive_query
ORDER BY $sort $order LIMIT $record_from, $record_to"
);
$num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()"));
// Names records have that aren't categories - a kind held by name, in the plain current view
$loose = !$show_archived && $search === '' ? categoryLooseNames($kind) : [];
// Category types shown in the left nav
$category_types = [
'Expense' => ['label' => 'Expense', 'icon' => 'fa-shopping-cart'],
'Income' => ['label' => 'Income', 'icon' => 'fa-hand-holding-usd'],
'Referral' => ['label' => 'Referral', 'icon' => 'fa-share-alt'],
'Ticket' => ['label' => 'Ticket', 'icon' => 'fa-life-ring'],
'network_interface' => ['label' => 'Network Interface', 'icon' => 'fa-ethernet'],
'asset_status' => ['label' => 'Asset Status', 'icon' => 'fa-heartbeat'],
'software_type' => ['label' => 'Software Type', 'icon' => 'fa-cube'],
'rack_type' => ['label' => 'Rack Type', 'icon' => 'fa-server'],
'contact_note_type' => ['label' => 'Contact Note Type', 'icon' => 'fa-address-book'],
'asset_note_type' => ['label' => 'Asset Note Type', 'icon' => 'fa-desktop'],
];
// Dragged into order - in the order view, with the whole current list showing
$can_reorder = $config['ordered'] && $sort_by === 'order' && !$show_archived && $search === '' && count($categories) > 1;
// Label for the selected type, falling back for anything not in the map
$category_label = $category_types[$category]['label'] ?? ucwords(str_replace('_', ' ', $category));
// Row count per type for the nav badges, respecting the archived view
$category_type_counts = [];
$sql_category_type_counts = mysqli_query(
$mysqli,
"SELECT category_type, COUNT(category_id) AS category_type_count FROM categories
WHERE category_$archive_query
GROUP BY category_type"
);
while ($row = mysqli_fetch_assoc($sql_category_type_counts)) {
$category_type_counts[$row['category_type']] = intval($row['category_type_count']);
// Current categories of each kind for the nav, and this kind's archived ones for the tab
$kind_counts = [];
$archived_count = 0;
$sql = mysqli_query($mysqli, "SELECT category_type, SUM(category_archived_at IS NULL), SUM(category_archived_at IS NOT NULL) FROM categories GROUP BY category_type");
while ($row = mysqli_fetch_row($sql)) {
$kind_counts[$row[0]] = intval($row[1]);
if ($row[0] === $kind) {
$archived_count = intval($row[2]);
}
}
// Archived nav item toggles the view while holding the selected type/search
$archive_toggle_query = $_GET;
unset($archive_toggle_query['page']);
$archive_toggle_query['category'] = $category;
if ($archived) {
unset($archive_toggle_query['archived']);
} else {
$archive_toggle_query['archived'] = 1;
}
$archive_toggle_url = '?' . http_build_query($archive_toggle_query);
// This page with some of its query changed - null drops a key
$page_url = function (array $change = []) use ($kind, $show_archived, $sort_by, $default_sort, $search) {
$query = array_merge(['category' => $kind, 'q' => $search !== '' ? $search : null, 'sort' => $sort_by !== $default_sort ? $sort_by : null, 'archived' => $show_archived ? 1 : null], $change);
return 'categories.php?' . http_build_query(array_filter($query, function ($v) {
return $v !== null;
}));
};
$new_label = 'New ' . ucwords($config['one']);
$add_url = 'modals/category/category_add.php?category=' . urlencode($kind);
$csrf = $_SESSION['csrf_token'];
?>
<div class="card card-dark">
<div class="card-header py-2">
<h3 class="card-title mt-2"><i class="fa fa-fw fa-list-ul me-2"></i>
<?= escapeHtml($category_label) ?> Categories
</h3>
<?php
if (!isset($_GET['archived'])) {
?>
<div class="card">
<div class="card-header bg-dark py-2">
<h3 class="card-title mt-2"><i class="fas fa-fw fa-list-ul me-2"></i>Categories</h3>
<div class="card-tools">
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="modals/category/category_add.php?category=<?= escapeHtml($category) ?>"><i
class="fas fa-plus me-2"></i>New <?= escapeHtml($category_label) ?> Category</button>
<button type="button" class="btn btn-primary ajax-modal" data-modal-url="<?= escapeHtml($add_url) ?>"><i class="fas fa-plus me-2"></i><?= escapeHtml($new_label) ?></button>
</div>
<?php
}
?>
</div>
<div class="card-body">
<div class="row">
<!-- Category types -->
<div class="col-md-3 border-end mb-3">
<ul class="nav nav-pills flex-column bg-light">
<?php foreach ($category_types as $category_type => $category_type_details) { ?>
<li class="nav-item">
<a class="nav-link<?php if ($category == $category_type) {
echo ' active';
} ?>" href="?category=<?= urlencode($category_type) ?>">
<i class="fa fa-fw <?= $category_type_details['icon'] ?> me-2"></i><?= escapeHtml($category_type_details['label']) ?>
<span class="badge rounded-pill bg-dark float-end mt-1"><?= $category_type_counts[$category_type] ?? 0 ?></span>
</a>
</li>
<?php } ?>
</ul>
</div>
<div class="row g-0">
<!-- Kinds -->
<div class="col-md-4 col-lg-3 border-end">
<nav class="nav nav-pills flex-nowrap flex-md-column overflow-auto p-2 gap-1 itflow-category-kinds" aria-label="Kinds of category">
<?php foreach ($kinds as $kind_key => $kind_config) { ?>
<a class="nav-link d-flex align-items-center gap-2 text-nowrap<?= $kind_key === $kind ? ' active' : '' ?>" href="categories.php?category=<?= urlencode($kind_key) ?>"<?= $kind_key === $kind ? ' aria-current="page"' : '' ?>>
<i class="fas fa-fw <?= $kind_config['icon'] ?>"></i><span class="text-truncate"><?= escapeHtml($kind_config['label']) ?></span>
<span class="badge rounded-pill ms-auto <?= $kind_key === $kind ? 'text-bg-light' : 'text-bg-secondary' ?>"><?= $kind_counts[$kind_key] ?? 0 ?></span>
</a>
<?php } ?>
</nav>
</div>
<!-- Categories -->
<div class="col-md-9">
<form autocomplete="off">
<input type="hidden" name="category" value="<?= escapeHtml($category) ?>">
<?php if ($archived) { ?>
<input type="hidden" name="archived" value="1">
<?php } ?>
<div class="row">
<div class="col-sm-6 mb-2">
<div class="input-group">
<input type="search" class="form-control" name="q"
value="<?php if (isset($q)) {
echo stripslashes(escapeHtml($q));
} ?>"
placeholder="Search <?= escapeHtml($category_label) ?> Categories ">
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
</div>
</div>
<div class="col-sm-6 mb-2">
<a href="<?= $archive_toggle_url ?>"
class="btn float-end <?php if ($archived) {
echo 'btn-primary';
} else {
echo 'btn-default';
} ?>"><i
class="fas fa-fw fa-archive me-2"></i>Archived</a>
<!-- This kind's categories -->
<div class="col-md-8 col-lg-9">
<div class="p-2 border-bottom">
<p class="small text-secondary mb-2"><?= escapeHtml($config['about']) ?></p>
<form autocomplete="off" class="d-flex flex-wrap align-items-center gap-2">
<input type="hidden" name="category" value="<?= escapeHtml($kind) ?>">
<?php if ($show_archived) { ?><input type="hidden" name="archived" value="1"><?php } ?>
<?php if ($sort_by !== $default_sort) { ?><input type="hidden" name="sort" value="<?= escapeHtml($sort_by) ?>"><?php } ?>
<div class="input-group input-group-sm w-auto">
<input type="search" class="form-control" name="q" value="<?= escapeHtml($search) ?>" placeholder="Search <?= escapeHtml($config['many']) ?>">
<button class="btn btn-primary" title="Search"><i class="fa fa-search"></i></button>
</div>
<div class="btn-group btn-group-sm" role="group" aria-label="Sort">
<?php foreach ($sorts as $sort_key => [$sort_label, $sort_icon, $sort_title]) { ?>
<a class="btn btn-outline-secondary<?= $sort_by === $sort_key ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['sort' => $sort_key !== $default_sort ? $sort_key : null])) ?>" title="<?= $sort_title ?>"><i class="fas <?= $sort_icon ?> me-1"></i><?= $sort_label ?></a>
<?php } ?>
</div>
<div class="btn-group btn-group-sm me-auto" role="group" aria-label="Current or archived">
<a class="btn btn-outline-secondary<?= $show_archived ? '' : ' active' ?>" href="<?= escapeHtml($page_url(['archived' => null])) ?>">Current</a>
<a class="btn btn-outline-secondary<?= $show_archived ? ' active' : '' ?>" href="<?= escapeHtml($page_url(['archived' => 1])) ?>">Archived <span class="badge text-bg-secondary ms-1"><?= $archived_count ?></span></a>
</div>
<div class="dropdown" id="bulkActionButton" hidden>
<button class="btn btn-secondary btn-sm dropdown-toggle" type="button" data-bs-toggle="dropdown">
<i class="fas fa-fw fa-layer-group me-1"></i>Bulk Action (<span id="selectedCount">0</span>)
</button>
<div class="dropdown-menu dropdown-menu-end">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php" data-bulk="true">
<i class="fas fa-fw fa-compress-alt text-secondary me-2"></i>Merge into one...
</a>
<?php if ($show_archived) { ?>
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_restore_categories">
<i class="fas fa-fw fa-redo text-secondary me-2"></i>Restore
</button>
<?php } else { ?>
<button class="dropdown-item" type="submit" form="bulkActions" name="bulk_archive_categories">
<i class="fas fa-fw fa-archive text-secondary me-2"></i>Archive
</button>
<?php } ?>
<div class="dropdown-divider"></div>
<button class="dropdown-item text-danger confirm-link" type="submit" form="bulkActions" name="bulk_delete_categories"
data-confirm-title="Delete these <?= escapeHtml($config['many']) ?>?"
data-confirm-text="Only the ones nothing uses are deleted - the rest are kept, to merge into another or archive."
data-confirm-button="Delete">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</button>
</div>
</div>
</form>
<hr>
</div>
<form id="bulkActions" action="post.php" method="post">
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
<div class="table-responsive-sm">
<table class="table table-striped table-borderless table-hover mb-0">
<thead class="text-dark <?php if ($num_rows[0] == 0) { echo "d-none"; } ?>">
<table class="table table-borderless table-hover align-middle mb-0">
<?php if ($categories) { ?>
<thead class="text-dark">
<tr>
<th>
<a class="text-dark" href="?<?= $url_query_strings_sort ?>&sort=category_name&order=<?= $disp ?>">
Name <?php if ($sort == 'category_name') { echo $order_icon; } ?>
</a>
<th class="ps-3" style="width: 1%">
<div class="form-check mb-0">
<input class="form-check-input" id="selectAllCheckbox" type="checkbox" title="Select all">
</div>
</th>
<th>Color</th>
<th class="text-center">Action</th>
<?php if ($can_reorder) { ?><th style="width: 1%"><span class="visually-hidden">Order</span></th><?php } ?>
<th><?= escapeHtml(ucfirst($config['one'])) ?></th>
<th class="d-none d-sm-table-cell">Used on</th>
<th class="text-center" style="width: 1%">Action</th>
</tr>
</thead>
<tbody>
<?php
while ($row = mysqli_fetch_assoc($sql)) {
$category_id = intval($row['category_id']);
$category_name = escapeHtml($row['category_name']);
$category_description = escapeHtml($row['category_description']);
$category_color = escapeHtml($row['category_color']);
?>
<tr>
<td>
<a class="text-dark ajax-modal" href="#"
data-modal-url="modals/category/category_edit.php?id=<?= $category_id ?>">
<?= $category_name ?>
<div><small class="text-secondary"><?= $category_description ?></small></div>
</a>
</td>
<td><i class="fa fa-3x fa-circle" style="color:<?= $category_color ?>;"></i></td>
<td>
<div class="dropdown dropstart text-center">
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown">
<i class="fas fa-ellipsis-h"></i>
</button>
<div class="dropdown-menu">
<?php
if ($archived) {
?>
<a class="dropdown-item text-info confirm-link"
href="post.php?restore_category=<?= $category_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-redo me-2"></i>Restore
</a>
<a class="dropdown-item text-danger confirm-link"
href="post.php?delete_category=<?= $category_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-trash me-2"></i>Delete
</a>
<?php
} else {
?>
<a class="dropdown-item ajax-modal" href="#"
data-modal-url="modals/category/category_edit.php?id=<?= $category_id ?>">
<i class="fas fa-fw fa-edit me-2"></i>Edit
</a>
<a class="dropdown-item text-danger confirm-link"
href="post.php?archive_category=<?= $category_id ?>&csrf_token=<?= $_SESSION['csrf_token'] ?>">
<i class="fas fa-fw fa-archive me-2"></i>Archive
</a>
<?php
}
?>
</div>
</div>
</td>
</tr>
<?php
}
</thead>
<?php } ?>
<tbody<?= $can_reorder ? ' data-category-sortable data-category-kind="' . escapeHtml($kind) . '"' : '' ?>>
<?php
$positions = array_keys($categories);
foreach ($categories as $category_id => $row) {
$name = escapeHtml($row['category_name']);
$used = $row['used'];
$edit_url = "modals/category/category_edit.php?id=$category_id";
$used_html = $used['all'] ? categoryUsageHtml($row, $used) : '<span class="text-secondary">' . ($row['category_archived_at'] ? 'Nothing uses it' : 'Nothing yet') . '</span>';
$blocker = categoryDeleteBlocker($row, $used);
$position = array_search($category_id, $positions, true);
?>
<tr data-category-id="<?= $category_id ?>">
<td class="ps-3">
<div class="form-check mb-0">
<input class="form-check-input bulk-select" type="checkbox" name="category_ids[]" value="<?= $category_id ?>" aria-label="Select <?= $name ?>">
</div>
</td>
<?php if ($can_reorder) { ?>
<td class="pe-0"><span class="itflow-category-grip text-secondary" title="Drag to move" data-category-grip><i class="fas fa-grip-vertical" aria-hidden="true"></i></span></td>
<?php } ?>
<td>
<a class="ajax-modal text-decoration-none text-reset" href="#" data-modal-url="<?= $edit_url ?>" title="Edit <?= $name ?>"><?= categoryChip($row) ?></a>
<?php if (trim((string) $row['category_description']) !== '') { ?>
<div class="small text-secondary mt-1"><?= escapeHtml($row['category_description']) ?></div>
<?php } ?>
<div class="small d-sm-none mt-1"><?= $used_html ?></div>
<?php if ($row['category_archived_at']) { ?>
<div class="small text-secondary"><i class="fas fa-fw fa-archive me-1"></i>Archived <?= date('M j, Y', strtotime($row['category_archived_at'])) ?></div>
<?php } ?>
</td>
<td class="d-none d-sm-table-cell small"><?= $used_html ?></td>
<td>
<div class="dropdown dropstart text-center">
<button class="btn btn-secondary btn-sm" title="More actions" type="button" data-bs-toggle="dropdown"><i class="fas fa-ellipsis-h"></i></button>
<div class="dropdown-menu">
<a class="dropdown-item ajax-modal" href="#" data-modal-url="<?= $edit_url ?>"><i class="fas fa-fw fa-edit me-2"></i>Edit</a>
<a class="dropdown-item ajax-modal" href="#" data-modal-url="modals/category/category_merge.php?category_ids[]=<?= $category_id ?>"><i class="fas fa-fw fa-compress-alt me-2"></i>Merge into...</a>
<?php if ($can_reorder) { ?>
<?php if ($position > 0) { ?>
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=up&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-arrow-up me-2"></i>Move up</a>
<?php } ?>
<?php if ($position < count($positions) - 1) { ?>
<a class="dropdown-item" href="post.php?move_category=<?= $category_id ?>&direction=down&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-arrow-down me-2"></i>Move down</a>
<?php } ?>
<?php } ?>
<div class="dropdown-divider"></div>
<?php if ($row['category_archived_at']) { ?>
<a class="dropdown-item" href="post.php?restore_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>"><i class="fas fa-fw fa-redo me-2"></i>Restore</a>
<?php } else { ?>
<a class="dropdown-item" href="post.php?archive_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>" title="It stays on its records, but isn't offered for new ones"><i class="fas fa-fw fa-archive me-2"></i>Archive</a>
<?php } ?>
<?php if ($blocker !== '') { ?>
<span class="dropdown-item disabled" title="<?= escapeHtml($blocker) ?>"><i class="fas fa-fw fa-trash me-2"></i>Delete</span>
<?php } else { ?>
<a class="dropdown-item text-danger text-bold confirm-link" href="post.php?delete_category=<?= $category_id ?>&csrf_token=<?= $csrf ?>"
data-confirm-title="Delete <?= $name ?>?" data-confirm-text="Nothing uses it, so no record changes." data-confirm-button="Delete"><i class="fas fa-fw fa-trash me-2"></i>Delete</a>
<?php } ?>
</div>
</div>
</td>
</tr>
<?php } ?>
</tbody>
</table>
</div>
</div>
</form>
<?php if ($can_reorder) { ?>
<div class="small text-secondary px-3 py-2 border-top"><i class="fas fa-fw fa-grip-vertical me-1"></i>Drag them into the order they're offered in.</div>
<?php } elseif ($config['ordered'] && $sort_by === 'order' && !$show_archived && $search !== '') { ?>
<div class="small text-secondary px-3 py-2 border-top">Clear the search to drag them into order.</div>
<?php } ?>
<?php if (!$categories) { ?>
<?= emptyStateHtml([
'thing' => $config['many'],
'title' => $show_archived ? 'No archived ' . $config['many'] : 'No ' . $config['many'] . ' yet',
'text' => $show_archived ? 'An archived category stays on its records, but isn\'t offered for new ones.' : $config['about'],
'icon' => $config['icon'],
'filtered' => $search !== '',
'clear_url' => $page_url(['q' => null]),
'actions' => $show_archived ? [] : [['label' => $new_label, 'modal' => $add_url]],
]) ?>
<?php } ?>
<?php if ($loose) { ?>
<div class="border-top px-3 py-2 itflow-category-loose">
<div class="fw-semibold"><i class="fas fa-fw fa-question-circle text-secondary me-1"></i>In use, but not set up here</div>
<p class="small text-secondary mb-1">Records have these, but they aren't <?= escapeHtml($config['many']) ?> - so they can't be picked again, and have no color or icon. Add one to make it <?= escapeHtml(categoryKindPhrase($kind)) ?>; to fold it into another, add it, then merge it.</p>
<ul class="list-unstyled mb-0">
<?php foreach ($loose as $loose_name => $loose_used) { ?>
<li class="d-flex flex-wrap align-items-center gap-2 py-1">
<span><?= escapeHtml($loose_name) ?></span>
<span class="small"><?= categoryUsageHtml(['category_id' => 0, 'category_name' => $loose_name, 'category_type' => $kind], $loose_used) ?></span>
<form action="post.php" method="post" class="ms-auto">
<input type="hidden" name="csrf_token" value="<?= $csrf ?>">
<input type="hidden" name="type" value="<?= escapeHtml($kind) ?>">
<input type="hidden" name="name" value="<?= escapeHtml($loose_name) ?>">
<button type="submit" name="add_category" class="btn btn-sm btn-outline-secondary" title="Make it <?= escapeHtml(categoryKindPhrase($kind)) ?>"><i class="fas fa-plus me-1"></i>Add</button>
</form>
</li>
<?php } ?>
</ul>
</div>
<?php } ?>
</div>
</div>
<?php
$empty_state = [
'thing' => strtolower($category_label) . ' categories',
'icon' => 'fa-list-ul',
'views' => ['category'],
'actions' => [['label' => "New $category_label Category", 'modal' => 'modals/category/category_add.php?category=' . urlencode($category)]],
];
?>
<?php require_once "../includes/filter_footer.php"; ?>
</div>
<script src="../js/bulk_actions.js"></script>
<?php if ($can_reorder) { ?>
<script src="/libs/SortableJS/Sortable.min.js"></script>
<script>
(function () {
// Dragged into order - saved as soon as one is dropped; a failure reloads the page to show the order kept
const body = document.querySelector('[data-category-sortable]');
new Sortable(body, {
handle: '[data-category-grip]',
animation: 150,
onEnd: function (event) {
if (event.oldIndex === event.newIndex) {
return;
}
const ids = Array.from(body.querySelectorAll('tr[data-category-id]')).map(function (row) {
return row.dataset.categoryId;
});
itflowPost('post.php', { reorder_categories: 1, csrf_token: '<?= $csrf ?>', category: body.dataset.categoryKind, category_ids: ids })
.then(function (text) {
const result = JSON.parse(text);
if (!result.ok) {
throw new Error(result.error || 'Not saved');
}
itflowToast('Order saved', 'success');
})
.catch(function () {
window.location.reload();
});
}
});
})();
</script>
<?php } ?>
<?php
require_once "../includes/footer.php";