Files
2026-10-19 15:22:52 -07:00

117 lines
4.7 KiB
PHP

<?php
/**
* square_check.php — TEMPORARY diagnostic: one school's Square row + the latest
* onboarding attempts, shown whether or not the school is connected.
*
* Read-only. NEVER displays access/refresh tokens — only whether one is present.
*
* ⚠️ DELETE THIS FILE FROM THE SERVER when you're done. It is gated by a key
* below to avoid casual exposure, but it is not part of the real app.
*
* Usage: https://dev.hotlunches.net/square/square_check.php?key=sq-check-4b9e2d
* (optional) &school=Other%20School%20Name
*/
ini_set('display_errors', 0);
// ── Simple access gate ───────────────────────────────────────────────────────
$ACCESS_KEY = 'sq-check-4b9e2d';
if (($_GET['key'] ?? '') !== $ACCESS_KEY) {
http_response_code(403);
header('Content-Type: text/plain; charset=utf-8');
echo "Forbidden. Append ?key=YOUR_KEY (see the top of square_check.php).";
exit;
}
// ── Bootstrap the DB layer (MerchantStore loads the host include/database.php) ─
require_once __DIR__ . '/lib/MerchantStore.php';
$config = require __DIR__ . '/config.php';
$store = new MerchantStore($config); // constructor bootstraps the db_* layer
header('Content-Type: text/html; charset=utf-8');
function h($v) { return htmlspecialchars((string)$v, ENT_QUOTES, 'UTF-8'); }
/** Run a query and print its rows as a table (NULL shown as NULL). */
function showQuery(string $title, string $sql, array $truncate = []): void {
echo '<h2>' . h($title) . '</h2><pre class="sql">' . h($sql) . '</pre>';
$r = db_query($sql);
if (!$r) {
echo '<p class="err">Query failed' . (function_exists('db_error') ? ': ' . h(db_error()) : '') . '</p>';
return;
}
$rows = [];
while ($row = db_fetch_assoc($r)) {
$rows[] = $row;
}
if (!$rows) {
echo '<p class="err">No rows.</p>';
return;
}
echo '<table><thead><tr>';
foreach (array_keys($rows[0]) as $col) {
echo '<th>' . h($col) . '</th>';
}
echo '</tr></thead><tbody>';
foreach ($rows as $row) {
echo '<tr>';
foreach ($row as $col => $val) {
if ($val === null) {
echo '<td class="muted">NULL</td>';
} elseif (in_array($col, $truncate, true)) {
echo '<td>' . h(substr((string)$val, 0, 12)) . '…</td>';
} else {
echo '<td>' . nl2br(h($val)) . '</td>';
}
}
echo '</tr>';
}
echo '</tbody></table>';
}
$school = trim((string)($_GET['school'] ?? 'Development School'));
?>
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Square — Check</title>
<style>
body { font-family: system-ui, -apple-system, Segoe UI, Arial, sans-serif; margin: 0; background: #f7fafc; color: #1a202c; }
.wrap { max-width: 1200px; margin: 0 auto; padding: 28px 20px 60px; }
h1 { font-size: 22px; margin: 0 0 20px; }
h2 { font-size: 16px; margin: 28px 0 8px; }
.warn { background: #fffaf0; border: 1px solid #fbd38d; color: #7b341e; padding: 10px 14px; border-radius: 8px; font-size: 13px; }
.err { color: #c53030; font-size: 13px; }
pre.sql { background: #f1f5f9; padding: 10px 12px; border-radius: 6px; font-size: 12px; white-space: pre-wrap; margin: 0 0 10px; }
table { width: 100%; border-collapse: collapse; background: #fff; border: 1px solid #e2e8f0; font-size: 13px; }
th, td { text-align: left; padding: 8px 10px; border-bottom: 1px solid #edf2f7; vertical-align: top; }
th { background: #f1f5f9; font-weight: 600; color: #475569; white-space: nowrap; }
.muted { color: #a0aec0; }
</style>
</head>
<body>
<div class="wrap">
<h1>Square — Check</h1>
<div class="warn">⚠️ Temporary diagnostic page — delete <code>square_check.php</code> from the server when finished.</div>
<?php
if (!function_exists('db_query')) {
echo '<p class="err">Host database layer (db_query) is not available — cannot read.</p>';
} else {
$s = db_escape_string($school);
showQuery('School row', "SELECT record_num, school_name, square_merchant_id,
square_access_token IS NOT NULL AS has_token,
square_ready, square_location_id,
square_authorization_revoked, square_status_issues
FROM schools WHERE school_name = '$s'");
showQuery('Latest onboarding attempts', "SELECT state, school_num, status, merchant_id,
FROM_UNIXTIME(created_at) AS created, FROM_UNIXTIME(last_callback) AS callback
FROM square_pending_onboarding ORDER BY created_at DESC LIMIT 5", ['state']);
}
?>
</div>
</body>
</html>