<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
echo "PHP version: " . PHP_VERSION . "\n";
require_once __DIR__ . '/config.php';
echo "config.php: OK\n";

echo "\n-- getallheaders --\n";
if (function_exists('getallheaders')) {
    foreach (getallheaders() as $k => $v) {
        echo "$k: $v\n";
    }
}
echo "HTTP_AUTHORIZATION: " . (isset($_SERVER['HTTP_AUTHORIZATION']) ? $_SERVER['HTTP_AUTHORIZATION'] : '-') . "\n";
echo "REDIRECT_HTTP_AUTHORIZATION: " . (isset($_SERVER['REDIRECT_HTTP_AUTHORIZATION']) ? $_SERVER['REDIRECT_HTTP_AUTHORIZATION'] : '-') . "\n";

echo "\n-- checkAuth --\n";
$u = checkAuth();
if ($u) { echo "AUTH OK: " . $u['email'] . " (role " . $u['role'] . ")\n"; }
else { echo "AUTH GAGAL\n"; }

echo "\n-- users di DB --\n";
try {
    $db = getDB();
    foreach ($db->query('SELECT email, role FROM users')->fetchAll() as $r) {
        echo $r['email'] . " / " . $r['role'] . "\n";
    }
    echo "Jumlah produk: " . $db->query('SELECT COUNT(*) FROM products')->fetchColumn() . "\n";
} catch (Throwable $e) {
    echo "DB ERROR: " . $e->getMessage() . "\n";
}