<?php
// admin/_notice_diag.php
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);
header('Content-Type: text/plain; charset=utf-8');

try {
  require_once __DIR__ . '/../config.php';
  echo "[OK] config.php loaded\n";
} catch (Throwable $e) {
  echo "[ERR] config.php: " . $e->getMessage() . "\n";
  exit;
}
if (!isset($pdo)) {
  echo "[ERR] \$pdo not set\n"; exit;
}

try {
  $stmt = $pdo->query("SELECT COUNT(*) AS c FROM subcategories");
  $c = $stmt->fetch(PDO::FETCH_ASSOC)['c'] ?? 'n/a';
  echo "[OK] subcategories count = " . $c . "\n";
} catch (Throwable $e) {
  echo "[ERR] query subcategories: " . $e->getMessage() . "\n";
}

try {
  $res = $pdo->query("SHOW COLUMNS FROM subcategories LIKE 'notice_text'");
  echo $res->rowCount() ? "[OK] notice_text exists\n" : "[WARN] notice_text missing\n";
  $res = $pdo->query("SHOW COLUMNS FROM subcategories LIKE 'notice_enabled'");
  echo $res->rowCount() ? "[OK] notice_enabled exists\n" : "[WARN] notice_enabled missing\n";
} catch (Throwable $e) {
  echo "[ERR] SHOW COLUMNS: " . $e->getMessage() . "\n";
}
