# WBMCZ — Premium Admin Sidebar Release

**Date:** 10 August 2026
**Scope:** New checklist-based admin sidebar + Activity Log + Payout & Earning + category-wise Order Management

---

## 1. Upload order (important)

Upload in this exact order so the site is never in a broken state:

1. All **NEW FILES** (section 2)
2. All **MODIFIED FILES** (section 3)
3. Open `https://yourdomain.com/ccpsimigration.php` in the browser
4. **Delete `ccpsimigration.php` from the server** once the green report shows

---

## 2. NEW FILES (6)

| File | What it does |
|---|---|
| `admin/includes/sidebar.php` | The whole premium sidebar. One file now drives every admin page. |
| `admin/includes/role_filter.php` | Turns `?role=free\|pro\|seller\|employee\|admin` into SQL, labels and filter pills. |
| `admin/activity_log.php` | **New page** — full admin audit trail with filters, timeline, CSV export, purge. |
| `admin/payouts.php` | **New page** — Payout & Earning Management, audience-wise. |
| `includes/activity.php` | Activity logging engine (`activity_log()` + `activity_autolog()`). |
| `ccpsimigration.php` | **Database migration.** Run once, then delete. |

> `admin/_sbbackup/` is a local rollback copy of the old files. **Do not upload it.**

---

## 3. MODIFIED FILES (27)

### 3a. Core (2)

| File | Change |
|---|---|
| `db.php` | Added 6 lines at the bottom — loads `includes/activity.php` and calls `activity_autolog($db)`. Wrapped in try/catch, cannot break a page. |
| `includes/shares.php` | Added `shares_service_category()` — resolves a service's category id. |

### 3b. Front-end (1)

| File | Change |
|---|---|
| `category.php` | Both `INSERT INTO orders` statements now also store `category_id`, so new orders are category-tagged automatically. |

### 3c. Admin — sidebar swap only (19)

The old inline `<aside>…</aside>` block (≈14 KB in each file) was deleted and replaced with a single line:

```php
<?php include __DIR__ . '/includes/sidebar.php'; ?>
```

Files: `index.php`, `kyc_pending.php`, `notifications.php`, `pending_services.php`,
`product_management.php`, `profile.php`, `refer.php`, `reports.php`, `roles.php`,
`sellers.php`, `services.php`, `settings.php`, `staff.php`, `transactions.php`,
`upgrade_requests.php`, `user_list.php`\*, `users.php`, `wallet_history.php`, `withdrawals.php`

### 3d. Admin — sidebar swap **+ extra logic** (5)

| File | Extra change |
|---|---|
| `user_list.php` | Reads `?role=` and maps it onto the existing sticky filters (`types` + `sub`). |
| `wallet.php` | New **audience panel** (`#role_view`) with credit/debit totals, opened by `wallet.php?role=…`. |
| `tickets.php` | New **audience panel** (`#role_view`) listing every ticket from that audience. |
| `commissions.php` | `?role=` decides which commission tab opens; audience pills added. |
| `orders.php` | **Category-wise filtering** — `?cat_id=N`, chip row with per-category counts, self-healing column check. |

### 3e. Admin — layout rebuilt (1)

| File | Change |
|---|---|
| `website_requests.php` | Had a standalone layout with no sidebar. Rewrapped into the standard admin shell so it now matches every other page. |

---

## 4. DATABASE CHANGES — run `ccpsimigration.php`

### New table: `activity_logs`

| Column | Type |
|---|---|
| `id` | BIGINT AUTO_INCREMENT PK |
| `user_id` | INT NULL |
| `user_name` | VARCHAR(150) NULL |
| `user_role` | VARCHAR(20) NULL |
| `action` | VARCHAR(60) NOT NULL DEFAULT 'view' |
| `module` | VARCHAR(80) NULL |
| `description` | VARCHAR(500) NULL |
| `reference_type` | VARCHAR(40) NULL |
| `reference_id` | INT NULL |
| `method` | VARCHAR(10) NULL |
| `url` | VARCHAR(255) NULL |
| `ip_address` | VARCHAR(45) NULL |
| `user_agent` | VARCHAR(255) NULL |
| `meta` | TEXT NULL |
| `created_at` | TIMESTAMP DEFAULT CURRENT_TIMESTAMP |

Indexes: `idx_al_user (user_id, created_at)`, `idx_al_action`, `idx_al_module`, `idx_al_created`

### New column: `orders.category_id`

```sql
ALTER TABLE orders ADD COLUMN `category_id` INT NULL DEFAULT NULL AFTER `service_name`;
ALTER TABLE orders ADD INDEX idx_orders_cat (category_id);
```

The migration also **back-fills** `category_id` for old orders by matching
`orders.service_name` against `seller_services.title` and `agency_services.title`.
Orders whose service no longer exists stay `NULL` and simply appear under **All Orders**.

**No other table or column was changed. Nothing was dropped or renamed.**

---

## 5. The new menu (matches the WBMCZ checklist)

```
Overview
  Dashboard
  Profile          → My Profile / Edit / KYC / Password / ID Card
  Activity Log                                              ← NEW

Management
  User Management       → All · Free · Pro · Seller · Employees
                          + KYC Pending · Upgrade Requests · Staff Accounts
                          · Custom Roles · Customer Console · Notifications
  Wallet Management     → All · Free · Pro · Seller · Employees · Admin
                          + Full Wallet History · Transactions
  Service Management    → All Service + all 12 categories (live from DB)
                          + Product Management · Main / Sub Categories
  Order Management      → All Orders + all 12 categories               ← NEW
  Website Settings      → All · Free · Pro · Seller · Employees · Admin
  Payout & Earning      → All · Free · Pro · Seller · Employees · Admin  ← NEW
                          + Bank Requests · Earning Reports
  Commission Management → All · Free · Pro · Seller · Employees · Admin
  Helpdesk Management   → All · Free · Pro · Seller · Employees · Admin

More
  Sellers · Website Requests · Refer & Earn
  Logout
```

### How the audiences are defined

| Audience | SQL |
|---|---|
| Free User | `user_type='customer' AND is_subscribed = 0` |
| Pro User | `user_type='customer' AND is_subscribed = 1` |
| Seller | `user_type='seller'` |
| Employees | `user_type='admin' AND role_id IS NOT NULL` |
| Admin | `user_type='admin' AND role_id IS NULL` |

---

## 6. Premium polish included

- Layered dark shell — emerald/sky radial glow over a slate gradient, edge glow shadow
- Gradient brand wordmark, animated hairline under the header
- Active item: emerald gradient wash + glowing left accent bar + gradient icon chip
- Hover: soft lift, background fade, icon chip brighten
- Sub-menus: vertical guide rail with dot markers that light up on hover/active
- Live badge counts (KYC pending, upgrade requests, pending orders, payouts, tickets)
- **Live menu search** — type to filter the whole menu, groups auto-expand
- Collapsed icon-rail mode with tooltips, remembered open groups (localStorage)
- Section headings, full keyboard/`aria` support, `prefers-reduced-motion` respected

---

## 7. Quick test after upload

1. `admin/index.php` — sidebar renders, Dashboard highlighted
2. Collapse/expand with the ☰ button — icon rail mode works
3. Type `pro` in the menu search — only Pro User rows remain
4. **User Management → Pro User** — list shows subscribed customers only
5. **Order Management → Government Portals** — chip active, count matches
6. **Payout & Earning → Seller** — totals and member table load
7. **Activity Log** — your own page visits appear within seconds
8. `admin/website_requests.php` — now has the sidebar

---

## 8. Rollback

Every change is additive. To roll back, restore the 27 modified files from
`admin/_sbbackup/` (admin pages) plus your own backup of `db.php`,
`category.php` and `includes/shares.php`. The new tables/columns can stay —
they are unused by the old code and harmless.
