<?php  if (!defined('DASHBOARD_ROOT')) { http_response_code(403); exit; } RBAC::enforce('view.orders'); $page = max(1, (int)($_GET['page'] ?? 1)); $limit = 25; $offset = ($page - 1) * $limit; $total = (int)Database::scalar("SELECT COUNT(*) FROM orders"); $orders = Database::fetchAll("SELECT id, order_ref, user_id, subtotal, status_code, status_label, payment_method, created_at FROM orders ORDER BY created_at DESC LIMIT :l OFFSET :o", [':l' => $limit, ':o' => $offset]); $rows = []; foreach ($orders as $o) { $rows[] = [ (int)$o['id'], UI::e($o['order_ref']), (int)$o['user_id'], '$' . number_format((float)$o['subtotal'], 2), UI::e($o['status_label'] ?? ''), UI::e($o['payment_method'] ?? ''), UI::e($o['created_at']), "<a class='btn btn-sm' href='javascript:void(0)' data-action='view-order' data-id='{$o['id']}'><span>View</span></a>" ]; } UI::table(['ID', 'Ref', 'User ID', 'Total', 'Status', 'Payment', 'Date', 'Actions'], $rows); echo "<div class=\"pagination\"><span>Page {$page} of " . max(1, ceil($total / $limit)) . "</span></div>"; 