First Commit
This commit is contained in:
1 parent
5eb9dd037d
commit
2e62c0e60b
11877 files changed
+2035312
No files matched your search
@@ -0,0 +1,730 @@
|
||||
<?php
|
||||
session_name('pp_admin');
|
||||
session_start();
|
||||
|
||||
$ADMIN_USER = 'admin';
|
||||
$ADMIN_PASS = 'admin';
|
||||
$dataDir = __DIR__ . '/data';
|
||||
$error = '';
|
||||
|
||||
// ── Diagnostic endpoint ──────────────────────────────────────────────────
|
||||
// Visit dashboard.php?debug=1 to see which data path the dashboard READS from.
|
||||
// Compare its realpath against onboard.php?debug=1 — if they differ, the
|
||||
// onboarding writes and the dashboard reads are two different files.
|
||||
if (isset($_GET['debug'])) {
|
||||
header('Content-Type: text/plain');
|
||||
$merchantsFile = $dataDir . '/school_merchants.json';
|
||||
echo "=== dashboard.php diagnostics ===\n";
|
||||
echo "__DIR__ : " . __DIR__ . "\n";
|
||||
echo "realpath(__DIR__) : " . realpath(__DIR__) . "\n";
|
||||
echo "dataDir realpath : " . (realpath($dataDir) ?: '(does not exist)') . "\n";
|
||||
echo "merchants file : $merchantsFile\n";
|
||||
echo "merchants realpath : " . (realpath($merchantsFile) ?: '(MISSING)') . "\n";
|
||||
echo "\n--- school_merchants.json (" . (file_exists($merchantsFile) ? filesize($merchantsFile) . ' bytes' : 'MISSING') . ") ---\n";
|
||||
echo file_exists($merchantsFile) ? file_get_contents($merchantsFile) : '(none)';
|
||||
exit();
|
||||
}
|
||||
|
||||
// ── Logout ─────────────────────────────────────────────────────────────────
|
||||
if (isset($_GET['logout'])) {
|
||||
$_SESSION = [];
|
||||
session_destroy();
|
||||
header('Location: dashboard.php');
|
||||
exit();
|
||||
}
|
||||
|
||||
// ── Login POST ──────────────────────────────────────────────────────────────
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['_login'])) {
|
||||
if (($_POST['username'] ?? '') === $ADMIN_USER && ($_POST['password'] ?? '') === $ADMIN_PASS) {
|
||||
$_SESSION['admin'] = true;
|
||||
header('Location: dashboard.php');
|
||||
exit();
|
||||
}
|
||||
$error = 'Invalid username or password.';
|
||||
}
|
||||
|
||||
// ── AJAX actions (must be logged in) ───────────────────────────────────────
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'POST' && isset($_POST['action']) && ($_SESSION['admin'] ?? false)) {
|
||||
header('Content-Type: application/json');
|
||||
$config = require __DIR__ . '/config.php';
|
||||
require_once __DIR__ . '/lib/PayPalClient.php';
|
||||
|
||||
try {
|
||||
$client = new PayPalClient($config);
|
||||
$merchantsFile = $dataDir . '/school_merchants.json';
|
||||
$merchants = file_exists($merchantsFile) ? (json_decode(file_get_contents($merchantsFile), true) ?: []) : [];
|
||||
|
||||
if ($_POST['action'] === 'check_status') {
|
||||
$school = trim($_POST['school_name'] ?? '');
|
||||
$merchantId = $merchants[$school]['merchant_id'] ?? null;
|
||||
if (!$merchantId) {
|
||||
echo json_encode(['success' => false, 'error' => 'School not found or not connected']);
|
||||
exit();
|
||||
}
|
||||
$s = $client->getSellerStatus($config['partner_merchant_id'], $merchantId);
|
||||
$merchants[$school] = array_merge($merchants[$school], [
|
||||
'paypal_ready' => $s['paypal_ready'],
|
||||
'email_confirmed' => $s['email_confirmed'],
|
||||
'payments_receivable' => $s['payments_receivable'],
|
||||
'oauth_ok' => $s['oauth_ok'],
|
||||
'seller_email' => $s['seller_email'],
|
||||
'status_issues' => $s['issues'],
|
||||
'status_checked_at' => time(),
|
||||
]);
|
||||
file_put_contents($merchantsFile, json_encode($merchants, JSON_PRETTY_PRINT));
|
||||
echo json_encode(array_merge(['success' => true], $s));
|
||||
exit();
|
||||
}
|
||||
|
||||
if ($_POST['action'] === 'check_all') {
|
||||
$refreshed = 0;
|
||||
foreach ($merchants as $school => &$data) {
|
||||
$mid = $data['merchant_id'] ?? null;
|
||||
if (!$mid) continue;
|
||||
$s = $client->getSellerStatus($config['partner_merchant_id'], $mid);
|
||||
$data = array_merge($data, [
|
||||
'paypal_ready' => $s['paypal_ready'],
|
||||
'email_confirmed' => $s['email_confirmed'],
|
||||
'payments_receivable' => $s['payments_receivable'],
|
||||
'oauth_ok' => $s['oauth_ok'],
|
||||
'seller_email' => $s['seller_email'],
|
||||
'status_issues' => $s['issues'],
|
||||
'status_checked_at' => time(),
|
||||
]);
|
||||
$refreshed++;
|
||||
}
|
||||
unset($data);
|
||||
file_put_contents($merchantsFile, json_encode($merchants, JSON_PRETTY_PRINT));
|
||||
echo json_encode(['success' => true, 'refreshed' => $refreshed]);
|
||||
exit();
|
||||
}
|
||||
|
||||
} catch (Exception $e) {
|
||||
echo json_encode(['success' => false, 'error' => $e->getMessage()]);
|
||||
}
|
||||
exit();
|
||||
}
|
||||
|
||||
// ── Load data (only needed for authenticated view) ─────────────────────────
|
||||
$merchants = [];
|
||||
$pending = [];
|
||||
$total = 0;
|
||||
$ready = 0;
|
||||
$withIssues = 0;
|
||||
$pendingCount = 0;
|
||||
|
||||
if ($_SESSION['admin'] ?? false) {
|
||||
$merchantsFile = $dataDir . '/school_merchants.json';
|
||||
if (file_exists($merchantsFile)) {
|
||||
$merchants = json_decode(file_get_contents($merchantsFile), true) ?: [];
|
||||
}
|
||||
|
||||
$pendingFile = $dataDir . '/pending_onboarding.json';
|
||||
if (file_exists($pendingFile)) {
|
||||
$pending = json_decode(file_get_contents($pendingFile), true) ?: [];
|
||||
}
|
||||
|
||||
$total = count($merchants);
|
||||
foreach ($merchants as $m) {
|
||||
if ($m['paypal_ready'] ?? false) $ready++;
|
||||
if (!empty($m['status_issues'])) $withIssues++;
|
||||
}
|
||||
foreach ($pending as $p) {
|
||||
if (in_array($p['status'] ?? '', ['pending', 'waiting_for_paypal', 'incomplete_onboarding'])) {
|
||||
$pendingCount++;
|
||||
}
|
||||
}
|
||||
}
|
||||
?>
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>PayPal Admin Dashboard</title>
|
||||
<style>
|
||||
/* ── Reset & base ── */
|
||||
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
|
||||
:root {
|
||||
--pp-blue: #003087;
|
||||
--pp-sky: #009cde;
|
||||
--pp-gold: #ffc439;
|
||||
--success: #28a745;
|
||||
--warning: #fd7e14;
|
||||
--danger: #dc3545;
|
||||
--bg: #f0f4f8;
|
||||
--card: #ffffff;
|
||||
--border: #e2e8f0;
|
||||
--text: #1a202c;
|
||||
--muted: #718096;
|
||||
--radius: 10px;
|
||||
--shadow: 0 2px 12px rgba(0,0,0,.08);
|
||||
--shadow-lg: 0 8px 32px rgba(0,0,0,.14);
|
||||
}
|
||||
body {
|
||||
font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
|
||||
background: var(--bg);
|
||||
color: var(--text);
|
||||
min-height: 100vh;
|
||||
}
|
||||
|
||||
/* ── Login page ── */
|
||||
.login-wrap {
|
||||
min-height: 100vh;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
background: linear-gradient(135deg, var(--pp-blue) 0%, var(--pp-sky) 100%);
|
||||
padding: 20px;
|
||||
}
|
||||
.login-card {
|
||||
background: var(--card);
|
||||
border-radius: 16px;
|
||||
box-shadow: var(--shadow-lg);
|
||||
padding: 48px 40px;
|
||||
width: 100%;
|
||||
max-width: 400px;
|
||||
}
|
||||
.login-logo {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 10px;
|
||||
margin-bottom: 32px;
|
||||
}
|
||||
.login-logo svg { width: 36px; height: 36px; }
|
||||
.login-logo span { font-size: 22px; font-weight: 700; color: var(--pp-blue); }
|
||||
.login-card h2 { font-size: 20px; color: var(--text); margin-bottom: 6px; }
|
||||
.login-card p { font-size: 14px; color: var(--muted); margin-bottom: 28px; }
|
||||
.field { margin-bottom: 18px; }
|
||||
.field label { display: block; font-size: 13px; font-weight: 600; color: var(--text); margin-bottom: 6px; }
|
||||
.field input {
|
||||
width: 100%; padding: 11px 14px;
|
||||
border: 1.5px solid var(--border); border-radius: 8px;
|
||||
font-size: 15px; transition: border-color .2s;
|
||||
}
|
||||
.field input:focus { outline: none; border-color: var(--pp-sky); }
|
||||
.btn-primary {
|
||||
width: 100%; padding: 13px;
|
||||
background: var(--pp-blue); color: #fff;
|
||||
border: none; border-radius: 8px;
|
||||
font-size: 15px; font-weight: 600; cursor: pointer;
|
||||
transition: background .2s, transform .1s;
|
||||
}
|
||||
.btn-primary:hover { background: #002070; transform: translateY(-1px); }
|
||||
.alert-err {
|
||||
background: #fff5f5; border: 1px solid #feb2b2;
|
||||
color: #c53030; border-radius: 8px;
|
||||
padding: 11px 14px; font-size: 13px; margin-bottom: 20px;
|
||||
}
|
||||
|
||||
/* ── Dashboard layout ── */
|
||||
.topbar {
|
||||
background: var(--pp-blue);
|
||||
padding: 0 28px;
|
||||
height: 60px;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
justify-content: space-between;
|
||||
box-shadow: 0 2px 8px rgba(0,0,0,.18);
|
||||
}
|
||||
.topbar-brand {
|
||||
display: flex; align-items: center; gap: 10px;
|
||||
color: #fff; font-size: 17px; font-weight: 700;
|
||||
}
|
||||
.topbar-brand svg { width: 28px; height: 28px; }
|
||||
.topbar-right { display: flex; align-items: center; gap: 14px; }
|
||||
.topbar-env {
|
||||
background: rgba(255,255,255,.15);
|
||||
color: #fff; font-size: 11px; font-weight: 700;
|
||||
padding: 3px 10px; border-radius: 20px; letter-spacing: .5px; text-transform: uppercase;
|
||||
}
|
||||
.topbar-user {
|
||||
color: rgba(255,255,255,.85); font-size: 13px;
|
||||
}
|
||||
.btn-logout {
|
||||
background: rgba(255,255,255,.12); color: #fff;
|
||||
border: 1px solid rgba(255,255,255,.3); border-radius: 7px;
|
||||
padding: 6px 14px; font-size: 13px; cursor: pointer;
|
||||
text-decoration: none; transition: background .2s;
|
||||
}
|
||||
.btn-logout:hover { background: rgba(255,255,255,.22); }
|
||||
|
||||
.main { padding: 28px; max-width: 1300px; margin: 0 auto; }
|
||||
|
||||
/* ── Stat cards ── */
|
||||
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px,1fr)); gap: 18px; margin-bottom: 28px; }
|
||||
.stat-card {
|
||||
background: var(--card); border-radius: var(--radius);
|
||||
box-shadow: var(--shadow); padding: 22px 24px;
|
||||
display: flex; align-items: center; gap: 16px;
|
||||
}
|
||||
.stat-icon {
|
||||
width: 46px; height: 46px; border-radius: 12px;
|
||||
display: flex; align-items: center; justify-content: center;
|
||||
font-size: 20px; flex-shrink: 0;
|
||||
}
|
||||
.stat-icon.blue { background: #ebf4ff; }
|
||||
.stat-icon.green { background: #f0fff4; }
|
||||
.stat-icon.red { background: #fff5f5; }
|
||||
.stat-icon.orange { background: #fffaf0; }
|
||||
.stat-label { font-size: 12px; color: var(--muted); font-weight: 600; text-transform: uppercase; letter-spacing: .4px; }
|
||||
.stat-value { font-size: 28px; font-weight: 700; color: var(--text); line-height: 1.1; margin-top: 2px; }
|
||||
|
||||
/* ── Section header ── */
|
||||
.section-header {
|
||||
display: flex; align-items: center; justify-content: space-between;
|
||||
margin-bottom: 16px; flex-wrap: wrap; gap: 10px;
|
||||
}
|
||||
.section-title { font-size: 17px; font-weight: 700; color: var(--text); }
|
||||
.section-sub { font-size: 13px; color: var(--muted); margin-top: 2px; }
|
||||
|
||||
.btn-action {
|
||||
padding: 9px 18px; border-radius: 8px; font-size: 13px; font-weight: 600;
|
||||
border: none; cursor: pointer; transition: all .2s; white-space: nowrap;
|
||||
}
|
||||
.btn-action.blue { background: var(--pp-sky); color: #fff; }
|
||||
.btn-action.blue:hover { background: #0089c7; }
|
||||
.btn-action.green { background: var(--success); color: #fff; }
|
||||
.btn-action.green:hover { background: #218838; }
|
||||
.btn-action.ghost { background: var(--card); color: var(--pp-blue); border: 1.5px solid var(--pp-sky); }
|
||||
.btn-action.ghost:hover { background: #ebf8ff; }
|
||||
.btn-action:disabled { opacity: .55; cursor: not-allowed; }
|
||||
|
||||
/* ── Table ── */
|
||||
.table-wrap {
|
||||
background: var(--card); border-radius: var(--radius);
|
||||
box-shadow: var(--shadow); overflow: hidden;
|
||||
}
|
||||
.table-scroll { overflow-x: auto; }
|
||||
table { width: 100%; border-collapse: collapse; font-size: 14px; }
|
||||
thead tr { background: #f7fafc; }
|
||||
thead th {
|
||||
padding: 13px 16px; text-align: left;
|
||||
font-size: 11px; font-weight: 700; text-transform: uppercase;
|
||||
letter-spacing: .5px; color: var(--muted);
|
||||
border-bottom: 1px solid var(--border); white-space: nowrap;
|
||||
}
|
||||
tbody tr { border-bottom: 1px solid var(--border); transition: background .15s; }
|
||||
tbody tr:last-child { border-bottom: none; }
|
||||
tbody tr:hover { background: #f7fafc; }
|
||||
td { padding: 14px 16px; vertical-align: middle; }
|
||||
|
||||
.school-name { font-weight: 600; color: var(--text); }
|
||||
.merchant-id { font-size: 11px; color: var(--muted); font-family: monospace; margin-top: 2px; }
|
||||
|
||||
.email-cell { color: var(--pp-blue); font-weight: 500; }
|
||||
.email-none { color: var(--muted); font-style: italic; }
|
||||
|
||||
/* badges */
|
||||
.badge {
|
||||
display: inline-flex; align-items: center; gap: 5px;
|
||||
padding: 4px 10px; border-radius: 20px;
|
||||
font-size: 12px; font-weight: 600; white-space: nowrap;
|
||||
}
|
||||
.badge-green { background: #f0fff4; color: #276749; }
|
||||
.badge-red { background: #fff5f5; color: #9b2c2c; }
|
||||
.badge-orange { background: #fffaf0; color: #9c4221; }
|
||||
|
||||
/* flag icons */
|
||||
.flag { display: inline-block; width: 20px; height: 20px; border-radius: 50%; text-align: center; line-height: 20px; font-size: 11px; font-weight: 700; }
|
||||
.flag-ok { background: #c6f6d5; color: #276749; }
|
||||
.flag-no { background: #fed7d7; color: #9b2c2c; }
|
||||
.flag-unk { background: #e2e8f0; color: #718096; }
|
||||
|
||||
.flags-row { display: flex; gap: 6px; align-items: center; }
|
||||
|
||||
.date-cell { color: var(--muted); font-size: 12px; white-space: nowrap; }
|
||||
|
||||
/* issues tooltip area */
|
||||
.issues-list {
|
||||
margin-top: 6px; font-size: 12px; color: #c53030;
|
||||
list-style: none; padding: 0;
|
||||
}
|
||||
.issues-list li::before { content: '⚠ '; }
|
||||
|
||||
/* ── Pending section ── */
|
||||
.pending-wrap {
|
||||
background: var(--card); border-radius: var(--radius);
|
||||
box-shadow: var(--shadow); margin-top: 24px;
|
||||
}
|
||||
.pending-header {
|
||||
padding: 16px 20px; border-bottom: 1px solid var(--border);
|
||||
display: flex; align-items: center; gap: 8px;
|
||||
font-size: 15px; font-weight: 700;
|
||||
}
|
||||
.pending-row {
|
||||
padding: 14px 20px; border-bottom: 1px solid var(--border);
|
||||
display: flex; align-items: center; justify-content: space-between; flex-wrap: wrap; gap: 8px;
|
||||
}
|
||||
.pending-row:last-child { border-bottom: none; }
|
||||
.pending-school { font-weight: 600; }
|
||||
.pending-meta { font-size: 12px; color: var(--muted); margin-top: 2px; }
|
||||
|
||||
/* ── Empty state ── */
|
||||
.empty-state {
|
||||
text-align: center; padding: 60px 20px; color: var(--muted);
|
||||
}
|
||||
.empty-state .empty-icon { font-size: 48px; margin-bottom: 12px; }
|
||||
.empty-state p { font-size: 15px; }
|
||||
|
||||
/* ── Toast ── */
|
||||
#toast {
|
||||
position: fixed; bottom: 24px; right: 24px;
|
||||
background: #1a202c; color: #fff;
|
||||
padding: 12px 20px; border-radius: 9px;
|
||||
font-size: 14px; box-shadow: var(--shadow-lg);
|
||||
display: none; z-index: 9999;
|
||||
animation: fadeIn .2s ease;
|
||||
}
|
||||
#toast.show { display: block; }
|
||||
#toast.success { background: #276749; }
|
||||
#toast.error { background: #9b2c2c; }
|
||||
@keyframes fadeIn { from { opacity:0; transform:translateY(10px); } to { opacity:1; transform:translateY(0); } }
|
||||
|
||||
@media (max-width: 640px) {
|
||||
.main { padding: 16px; }
|
||||
.topbar { padding: 0 16px; }
|
||||
.login-card { padding: 32px 24px; }
|
||||
}
|
||||
</style>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<?php if (!($_SESSION['admin'] ?? false)): ?>
|
||||
<!-- ════════════════════ LOGIN PAGE ════════════════════ -->
|
||||
<div class="login-wrap">
|
||||
<div class="login-card">
|
||||
<div class="login-logo">
|
||||
<!-- PayPal P icon -->
|
||||
<svg viewBox="0 0 24 24" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||
<path d="M7.5 21H4.5L7 3H14C17.5 3 19.5 5 19 8C18.5 11.5 15.5 13 12.5 13H9.5L8.5 18H11L10.5 21H7.5Z" fill="#003087"/>
|
||||
<path d="M9 17H6L8.5 3H15.5C19 3 21 5 20.5 8.5C20 12 17 13.5 14 13.5H11L10 18H12.5L12 21H9Z" fill="#009cde" opacity=".7"/>
|
||||
</svg>
|
||||
<span>PayPal Admin</span>
|
||||
</div>
|
||||
<h2>Welcome back</h2>
|
||||
<p>Sign in to manage your PayPal merchant connections.</p>
|
||||
|
||||
<?php if ($error): ?>
|
||||
<div class="alert-err"><?= htmlspecialchars($error) ?></div>
|
||||
<?php endif; ?>
|
||||
|
||||
<form method="POST">
|
||||
<input type="hidden" name="_login" value="1">
|
||||
<div class="field">
|
||||
<label for="u">Username</label>
|
||||
<input type="text" id="u" name="username" autocomplete="username" placeholder="admin" required>
|
||||
</div>
|
||||
<div class="field">
|
||||
<label for="p">Password</label>
|
||||
<input type="password" id="p" name="password" autocomplete="current-password" placeholder="••••••" required>
|
||||
</div>
|
||||
<button type="submit" class="btn-primary">Sign in</button>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<?php else: ?>
|
||||
<!-- ════════════════════ DASHBOARD ════════════════════ -->
|
||||
|
||||
<div id="toast"></div>
|
||||
|
||||
<!-- Top bar -->
|
||||
<nav class="topbar">
|
||||
<div class="topbar-brand">
|
||||
<svg viewBox="0 0 24 24" fill="none">
|
||||
<path d="M7.5 21H4.5L7 3H14C17.5 3 19.5 5 19 8C18.5 11.5 15.5 13 12.5 13H9.5L8.5 18H11L10.5 21H7.5Z" fill="#fff"/>
|
||||
<path d="M9 17H6L8.5 3H15.5C19 3 21 5 20.5 8.5C20 12 17 13.5 14 13.5H11L10 18H12.5L12 21H9Z" fill="#ffc439" opacity=".85"/>
|
||||
</svg>
|
||||
<span>PayPal Admin Dashboard</span>
|
||||
</div>
|
||||
<div class="topbar-right">
|
||||
<?php
|
||||
$config = require __DIR__ . '/config.php';
|
||||
$envLabel = ($config['env'] ?? 'sandbox') === 'live' ? 'Live' : 'Sandbox';
|
||||
?>
|
||||
<span class="topbar-env"><?= htmlspecialchars($envLabel) ?></span>
|
||||
<span class="topbar-user">admin</span>
|
||||
<a href="?logout=1" class="btn-logout">Sign out</a>
|
||||
</div>
|
||||
</nav>
|
||||
|
||||
<main class="main">
|
||||
|
||||
<!-- Stat cards -->
|
||||
<div class="stats">
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon blue">🏫</div>
|
||||
<div>
|
||||
<div class="stat-label">Total Schools</div>
|
||||
<div class="stat-value"><?= $total ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon green">✅</div>
|
||||
<div>
|
||||
<div class="stat-label">PayPal Ready</div>
|
||||
<div class="stat-value"><?= $ready ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon red">⚠️</div>
|
||||
<div>
|
||||
<div class="stat-label">With Issues</div>
|
||||
<div class="stat-value"><?= $withIssues ?></div>
|
||||
</div>
|
||||
</div>
|
||||
<div class="stat-card">
|
||||
<div class="stat-icon orange">⏳</div>
|
||||
<div>
|
||||
<div class="stat-label">Pending</div>
|
||||
<div class="stat-value"><?= $pendingCount ?></div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Connected merchants table -->
|
||||
<div class="section-header">
|
||||
<div>
|
||||
<div class="section-title">Connected Schools</div>
|
||||
<div class="section-sub">Schools that have completed PayPal onboarding</div>
|
||||
</div>
|
||||
<button class="btn-action blue" id="checkAllBtn" <?= $total === 0 ? 'disabled' : '' ?>>
|
||||
🔄 Refresh All Statuses
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div class="table-wrap">
|
||||
<?php if (empty($merchants)): ?>
|
||||
<div class="empty-state">
|
||||
<div class="empty-icon">🏫</div>
|
||||
<p>No schools connected yet. Use the onboarding page to connect a school.</p>
|
||||
</div>
|
||||
<?php else: ?>
|
||||
<div class="table-scroll">
|
||||
<table>
|
||||
<thead>
|
||||
<tr>
|
||||
<th>School</th>
|
||||
<th>PayPal Email</th>
|
||||
<th>Status</th>
|
||||
<th title="Email Confirmed / Payments Receivable / OAuth OK">Flags</th>
|
||||
<th>Connected</th>
|
||||
<th>Last Checked</th>
|
||||
<th>Actions</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody id="merchantsTbody">
|
||||
<?php foreach ($merchants as $schoolName => $m):
|
||||
$ready = $m['paypal_ready'] ?? null;
|
||||
$emailConf = $m['email_confirmed'] ?? null;
|
||||
$paymentsRecv = $m['payments_receivable'] ?? null;
|
||||
$oauthOk = $m['oauth_ok'] ?? null;
|
||||
$sellerEmail = $m['seller_email'] ?? null;
|
||||
$issues = $m['status_issues'] ?? [];
|
||||
$connectedAt = isset($m['connected_at']) ? date('M j, Y', $m['connected_at']) : '—';
|
||||
$checkedAt = isset($m['status_checked_at']) ? date('M j, Y g:i a', $m['status_checked_at']) : 'Never';
|
||||
|
||||
$statusBadge = $ready === null
|
||||
? '<span class="badge badge-orange">⚪ Unknown</span>'
|
||||
: ($ready
|
||||
? '<span class="badge badge-green">✔ Ready</span>'
|
||||
: '<span class="badge badge-red">✖ Issues</span>');
|
||||
|
||||
$flag = fn($v) => $v === null
|
||||
? '<span class="flag flag-unk" title="Not checked">?</span>'
|
||||
: ($v ? '<span class="flag flag-ok" title="OK">✓</span>' : '<span class="flag flag-no" title="Failing">✗</span>');
|
||||
?>
|
||||
<tr id="row-<?= htmlspecialchars(base64_encode($schoolName)) ?>">
|
||||
<td>
|
||||
<div class="school-name"><?= htmlspecialchars($schoolName) ?></div>
|
||||
<div class="merchant-id"><?= htmlspecialchars($m['merchant_id'] ?? '—') ?></div>
|
||||
</td>
|
||||
<td>
|
||||
<?php if ($sellerEmail): ?>
|
||||
<span class="email-cell"><?= htmlspecialchars($sellerEmail) ?></span>
|
||||
<?php else: ?>
|
||||
<span class="email-none">Not checked yet</span>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<?= $statusBadge ?>
|
||||
<?php if (!empty($issues)): ?>
|
||||
<ul class="issues-list">
|
||||
<?php foreach ($issues as $iss): ?>
|
||||
<li><?= htmlspecialchars($iss) ?></li>
|
||||
<?php endforeach; ?>
|
||||
</ul>
|
||||
<?php endif; ?>
|
||||
</td>
|
||||
<td>
|
||||
<div class="flags-row" title="Email Confirmed / Payments Receivable / OAuth OK">
|
||||
<?= $flag($emailConf) ?>
|
||||
<?= $flag($paymentsRecv) ?>
|
||||
<?= $flag($oauthOk) ?>
|
||||
</div>
|
||||
<div style="font-size:10px;color:var(--muted);margin-top:4px;">Email / Pay / OAuth</div>
|
||||
</td>
|
||||
<td class="date-cell"><?= htmlspecialchars($connectedAt) ?></td>
|
||||
<td class="date-cell" id="checked-<?= htmlspecialchars(base64_encode($schoolName)) ?>"><?= htmlspecialchars($checkedAt) ?></td>
|
||||
<td>
|
||||
<button class="btn-action ghost refresh-btn"
|
||||
data-school="<?= htmlspecialchars($schoolName) ?>">
|
||||
Refresh
|
||||
</button>
|
||||
</td>
|
||||
</tr>
|
||||
<?php endforeach; ?>
|
||||
</tbody>
|
||||
</table>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
</div>
|
||||
|
||||
<!-- Pending schools -->
|
||||
<?php
|
||||
$pendingRows = array_filter($pending, fn($p) => in_array($p['status'] ?? '', ['pending','waiting_for_paypal','incomplete_onboarding']));
|
||||
?>
|
||||
<?php if (!empty($pendingRows)): ?>
|
||||
<div class="pending-wrap" style="margin-top:24px;">
|
||||
<div class="pending-header">
|
||||
⏳ Pending Onboarding
|
||||
<span style="font-size:12px;color:var(--muted);font-weight:400;margin-left:4px;">(<?= count($pendingRows) ?> school<?= count($pendingRows) > 1 ? 's' : '' ?>)</span>
|
||||
</div>
|
||||
<?php foreach ($pendingRows as $tid => $p): ?>
|
||||
<div class="pending-row">
|
||||
<div>
|
||||
<div class="pending-school"><?= htmlspecialchars($p['school'] ?? $tid) ?></div>
|
||||
<div class="pending-meta">
|
||||
Status: <strong><?= htmlspecialchars($p['status']) ?></strong>
|
||||
· Started: <?= isset($p['created_at']) ? date('M j, Y', $p['created_at']) : '—' ?>
|
||||
</div>
|
||||
</div>
|
||||
<span class="badge badge-orange">⏳ <?= htmlspecialchars(ucfirst(str_replace('_', ' ', $p['status']))) ?></span>
|
||||
</div>
|
||||
<?php endforeach; ?>
|
||||
</div>
|
||||
<?php endif; ?>
|
||||
|
||||
</main>
|
||||
<?php endif; ?>
|
||||
|
||||
<script>
|
||||
function showToast(msg, type = 'success') {
|
||||
const t = document.getElementById('toast');
|
||||
if (!t) return;
|
||||
t.textContent = msg;
|
||||
t.className = 'show ' + type;
|
||||
setTimeout(() => { t.className = ''; }, 3500);
|
||||
}
|
||||
|
||||
function flagHtml(val, title) {
|
||||
if (val === null || val === undefined) return `<span class="flag flag-unk" title="${title} — not checked">?</span>`;
|
||||
return val
|
||||
? `<span class="flag flag-ok" title="${title} — OK">✓</span>`
|
||||
: `<span class="flag flag-no" title="${title} — Failing">✗</span>`;
|
||||
}
|
||||
|
||||
function statusBadge(ready) {
|
||||
if (ready === null || ready === undefined) return '<span class="badge badge-orange">⚪ Unknown</span>';
|
||||
return ready
|
||||
? '<span class="badge badge-green">✔ Ready</span>'
|
||||
: '<span class="badge badge-red">✖ Issues</span>';
|
||||
}
|
||||
|
||||
function updateRow(schoolName, data) {
|
||||
const key = btoa(unescape(encodeURIComponent(schoolName)));
|
||||
const row = document.getElementById('row-' + key);
|
||||
if (!row) return;
|
||||
|
||||
const cells = row.querySelectorAll('td');
|
||||
|
||||
// email
|
||||
cells[1].innerHTML = data.seller_email
|
||||
? `<span class="email-cell">${escHtml(data.seller_email)}</span>`
|
||||
: `<span class="email-none">Not available</span>`;
|
||||
|
||||
// status + issues
|
||||
let statusHtml = statusBadge(data.paypal_ready);
|
||||
if (data.issues && data.issues.length) {
|
||||
statusHtml += '<ul class="issues-list">' + data.issues.map(i => `<li>${escHtml(i)}</li>`).join('') + '</ul>';
|
||||
}
|
||||
cells[2].innerHTML = statusHtml;
|
||||
|
||||
// flags
|
||||
cells[3].innerHTML =
|
||||
`<div class="flags-row" title="Email Confirmed / Payments Receivable / OAuth OK">
|
||||
${flagHtml(data.email_confirmed, 'Email Confirmed')}
|
||||
${flagHtml(data.payments_receivable, 'Payments Receivable')}
|
||||
${flagHtml(data.oauth_ok, 'OAuth OK')}
|
||||
</div>
|
||||
<div style="font-size:10px;color:var(--muted);margin-top:4px;">Email / Pay / OAuth</div>`;
|
||||
|
||||
// last checked
|
||||
const checkedCell = document.getElementById('checked-' + key);
|
||||
if (checkedCell) checkedCell.textContent = new Date().toLocaleString('en-US', {month:'short',day:'numeric',year:'numeric',hour:'numeric',minute:'2-digit'});
|
||||
}
|
||||
|
||||
function escHtml(str) {
|
||||
return String(str).replace(/&/g,'&').replace(/</g,'<').replace(/>/g,'>').replace(/"/g,'"');
|
||||
}
|
||||
|
||||
// Per-row refresh buttons
|
||||
document.querySelectorAll('.refresh-btn').forEach(btn => {
|
||||
btn.addEventListener('click', function () {
|
||||
const school = this.dataset.school;
|
||||
this.disabled = true;
|
||||
this.textContent = '…';
|
||||
|
||||
fetch('dashboard.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: 'action=check_status&school_name=' + encodeURIComponent(school)
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
updateRow(school, data);
|
||||
showToast('Status refreshed for ' + school, 'success');
|
||||
} else {
|
||||
showToast('Error: ' + (data.error || 'Unknown error'), 'error');
|
||||
}
|
||||
})
|
||||
.catch(err => showToast('Request failed: ' + err.message, 'error'))
|
||||
.finally(() => { this.disabled = false; this.textContent = 'Refresh'; });
|
||||
});
|
||||
});
|
||||
|
||||
// Refresh all
|
||||
const checkAllBtn = document.getElementById('checkAllBtn');
|
||||
if (checkAllBtn) {
|
||||
checkAllBtn.addEventListener('click', function () {
|
||||
this.disabled = true;
|
||||
this.textContent = '⏳ Refreshing…';
|
||||
|
||||
fetch('dashboard.php', {
|
||||
method: 'POST',
|
||||
headers: { 'Content-Type': 'application/x-www-form-urlencoded' },
|
||||
body: 'action=check_all'
|
||||
})
|
||||
.then(r => r.json())
|
||||
.then(data => {
|
||||
if (data.success) {
|
||||
showToast('Refreshed ' + data.refreshed + ' school(s). Reloading…', 'success');
|
||||
setTimeout(() => location.reload(), 1200);
|
||||
} else {
|
||||
showToast('Error: ' + (data.error || 'Unknown error'), 'error');
|
||||
this.disabled = false;
|
||||
this.textContent = '🔄 Refresh All Statuses';
|
||||
}
|
||||
})
|
||||
.catch(err => {
|
||||
showToast('Request failed: ' + err.message, 'error');
|
||||
this.disabled = false;
|
||||
this.textContent = '🔄 Refresh All Statuses';
|
||||
});
|
||||
});
|
||||
}
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
Reference in new issue
Block a user