diff --git a/admin/categories.php b/admin/categories.php index d9bb8a01..ca549e0a 100644 --- a/admin/categories.php +++ b/admin/categories.php @@ -23,193 +23,195 @@ $sql = mysqli_query( ); $num_rows = mysqli_fetch_row(mysqli_query($mysqli, "SELECT FOUND_ROWS()")); +// 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'], +]; + +// 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']); +} + +// 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); + ?>