WebOrbiton
v1.0.0.1

StocketBase

87 lines · 3.5 KB
  1. <?php
  2. ​
  3. declare(strict_types=1);
  4. ​
  5. if (count(get_included_files()) === 1) {
  6. http_response_code(403);
  7. exit;
  8. }
  9. ​
  10. require_once __DIR__ . '/../includes/currency.php';
  11. ​
  12. if (!Auth::hasRoleAtLeast(Auth::ROLE_STORE_MANAGER)) {
  13. echo '<p>You don\'t have access to customers.</p>';
  14. return;
  15. }
  16. ​
  17. $usersDb = Database::users();
  18. $customerId = (int) ($_GET['id'] ?? 0);
  19. ​
  20. $statement = $usersDb->prepare('SELECT * FROM user_accounts WHERE id = :id LIMIT 1');
  21. $statement->execute(['id' => $customerId]);
  22. $customer = $statement->fetch();
  23. ​
  24. if (!$customer) {
  25. echo '<p>We couldn\'t find this customer.</p>';
  26. return;
  27. }
  28. ​
  29. $ordersStatement = $usersDb->prepare('SELECT * FROM orders WHERE user_account_id = :id ORDER BY created_at DESC');
  30. $ordersStatement->execute(['id' => $customerId]);
  31. $orders = $ordersStatement->fetchAll();
  32. ​
  33. $subscriptionsStatement = $usersDb->prepare('SELECT * FROM subscriptions WHERE user_account_id = :id ORDER BY created_at DESC');
  34. $subscriptionsStatement->execute(['id' => $customerId]);
  35. $subscriptions = $subscriptionsStatement->fetchAll();
  36. ​
  37. $storeCurrency = SiteFront::settings()['store_currency'] ?? 'USD';
  38. ​
  39. ?>
  40. <div class="dash-header-row">
  41. <h1 class="dash-title"><?= Icons::icon("users", "icon icon-lg") ?><?= htmlspecialchars((string) ($customer['display_name'] ?? $customer['email'])) ?></h1>
  42. <a href="dashboard.php?view=customers" class="dash-btn"><?= Icons::icon('users', 'icon icon-sm') ?>Back to customers</a>
  43. </div>
  44. ​
  45. <div class="sidebar-box" style="max-width:480px;">
  46. <p>Email: <?= htmlspecialchars($customer['email']) ?><br>
  47. Status: <span class="status-pill status-<?= $customer['status'] === 'active' ? 'published' : 'rejected' ?>"><?= htmlspecialchars(StatusLabel::get((string) $customer['status'])) ?></span><br>
  48. Joined: <?= htmlspecialchars($customer['created_at']) ?><br>
  49. Last seen: <?= htmlspecialchars((string) ($customer['last_login_at'] ?? 'Never')) ?></p>
  50. </div>
  51. ​
  52. <?php if (!empty($subscriptions)): ?>
  53. <h2 class="dash-subtitle"><?= Icons::icon('credit-card', 'icon icon-sm') ?>Subscriptions</h2>
  54. <table class="dash-table">
  55. <thead><tr><th>Paid with</th><th>Plan</th><th>Status</th><th>Renews or ends on</th></tr></thead>
  56. <tbody>
  57. <?php foreach ($subscriptions as $subscription): ?>
  58. <tr>
  59. <td><?= htmlspecialchars($subscription['provider']) ?></td>
  60. <td><?= htmlspecialchars((string) ($subscription['plan_code'] ?? 'Unknown')) ?></td>
  61. <td><span class="status-pill status-<?= htmlspecialchars($subscription['status']) ?>"><?= htmlspecialchars(StatusLabel::get((string) $subscription['status'])) ?></span></td>
  62. <td><?= htmlspecialchars((string) ($subscription['current_period_end'] ?? 'No end date')) ?></td>
  63. </tr>
  64. <?php endforeach; ?>
  65. </tbody>
  66. </table>
  67. <?php endif; ?>
  68. ​
  69. <h2 class="dash-subtitle"><?= Icons::icon('checklist', 'icon icon-sm') ?>Orders</h2>
  70. <table class="dash-table">
  71. <thead><tr><th>Order</th><th>Total</th><th>Status</th><th>Date</th><th></th></tr></thead>
  72. <tbody>
  73. <?php foreach ($orders as $order): ?>
  74. <tr>
  75. <td><?= htmlspecialchars($order['order_number']) ?></td>
  76. <td><?= htmlspecialchars(Currency::format((int) $order['total_cents'], $order['currency'])) ?></td>
  77. <td><span class="status-pill status-<?= htmlspecialchars($order['status']) ?>"><?= htmlspecialchars(StatusLabel::get((string) $order['status'])) ?></span></td>
  78. <td><?= htmlspecialchars($order['created_at']) ?></td>
  79. <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>
  80. </tr>
  81. <?php endforeach; ?>
  82. <?php if (empty($orders)): ?>
  83. <tr><td colspan="5">No orders yet.</td></tr>
  84. <?php endif; ?>
  85. </tbody>
  86. </table>
  87. ​