v1.0.0.0
StocketBase
- <?php
-
- declare(strict_types=1);
-
- if (count(get_included_files()) === 1) {
- http_response_code(403);
- exit;
- }
-
- require_once __DIR__ . '/../includes/currency.php';
-
- if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
- echo '<p>You do not have permission to view customers.</p>';
- return;
- }
-
- $usersDb = Database::users();
- $customerId = (int) ($_GET['id'] ?? 0);
-
- $statement = $usersDb->prepare('SELECT * FROM user_accounts WHERE id = :id LIMIT 1');
- $statement->execute(['id' => $customerId]);
- $customer = $statement->fetch();
-
- if (!$customer) {
- echo '<p>Customer not found.</p>';
- return;
- }
-
- $ordersStatement = $usersDb->prepare('SELECT * FROM orders WHERE user_account_id = :id ORDER BY created_at DESC');
- $ordersStatement->execute(['id' => $customerId]);
- $orders = $ordersStatement->fetchAll();
-
- $subscriptionsStatement = $usersDb->prepare('SELECT * FROM subscriptions WHERE user_account_id = :id ORDER BY created_at DESC');
- $subscriptionsStatement->execute(['id' => $customerId]);
- $subscriptions = $subscriptionsStatement->fetchAll();
-
- $storeCurrency = SiteFront::settings()['store_currency'] ?? 'USD';
-
- ?>
- <div class="dash-header-row">
- <h1 class="dash-title"><?= Icons::icon("users", "icon icon-lg") ?><?= htmlspecialchars((string) ($customer['display_name'] ?? $customer['email'])) ?></h1>
- <a href="dashboard.php?view=customers" class="dash-btn"><?= Icons::icon('users', 'icon icon-sm') ?>Back to customers</a>
- </div>
-
- <div class="sidebar-box" style="max-width:480px;">
- <p>Email: <?= htmlspecialchars($customer['email']) ?><br>
- Status: <span class="status-pill status-<?= $customer['status'] === 'active' ? 'published' : 'rejected' ?>"><?= htmlspecialchars($customer['status']) ?></span><br>
- Joined: <?= htmlspecialchars($customer['created_at']) ?><br>
- Last login: <?= htmlspecialchars((string) ($customer['last_login_at'] ?? '—')) ?></p>
- </div>
-
- <?php if (!empty($subscriptions)): ?>
- <h2 class="dash-subtitle"><?= Icons::icon('credit-card', 'icon icon-sm') ?>Subscriptions</h2>
- <table class="dash-table">
- <thead><tr><th>Provider</th><th>Plan</th><th>Status</th><th>Renews / ends</th></tr></thead>
- <tbody>
- <?php foreach ($subscriptions as $subscription): ?>
- <tr>
- <td><?= htmlspecialchars($subscription['provider']) ?></td>
- <td><?= htmlspecialchars((string) ($subscription['plan_code'] ?? '—')) ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($subscription['status']) ?>"><?= htmlspecialchars($subscription['status']) ?></span></td>
- <td><?= htmlspecialchars((string) ($subscription['current_period_end'] ?? '—')) ?></td>
- </tr>
- <?php endforeach; ?>
- </tbody>
- </table>
- <?php endif; ?>
-
- <h2 class="dash-subtitle"><?= Icons::icon('checklist', 'icon icon-sm') ?>Orders</h2>
- <table class="dash-table">
- <thead><tr><th>Order</th><th>Total</th><th>Status</th><th>Placed</th><th></th></tr></thead>
- <tbody>
- <?php foreach ($orders as $order): ?>
- <tr>
- <td><?= htmlspecialchars($order['order_number']) ?></td>
- <td><?= htmlspecialchars(Currency::format((int) $order['total_cents'], $order['currency'])) ?></td>
- <td><span class="status-pill status-<?= htmlspecialchars($order['status']) ?>"><?= htmlspecialchars($order['status']) ?></span></td>
- <td><?= htmlspecialchars($order['created_at']) ?></td>
- <td><a href="dashboard.php?view=order-detail&id=<?= (int) $order['id'] ?>" class="dash-btn-small"><?= Icons::icon('eye', 'icon icon-sm') ?>View</a></td>
- </tr>
- <?php endforeach; ?>
- <?php if (empty($orders)): ?>
- <tr><td colspan="5">No orders yet.</td></tr>
- <?php endif; ?>
- </tbody>
- </table>
-