<?php
require_once 'config/database.php';
require_once 'config/uddoktapay.php';

echo "Testing database connection and configuration loading...\n";

// Check if PDO is available
if (isset($pdo)) {
    echo "✓ PDO connection is available\n";
    
    // Test direct database query
    try {
        $stmt = $pdo->query("SELECT setting_key, setting_value FROM settings WHERE setting_key LIKE 'uddoktapay_%'");
        $results = $stmt->fetchAll();
        
        echo "Direct database query results:\n";
        foreach ($results as $row) {
            echo "  " . $row['setting_key'] . " = " . $row['setting_value'] . "\n";
        }
    } catch (Exception $e) {
        echo "✗ Direct database query failed: " . $e->getMessage() . "\n";
    }
    
    // Test configuration function
    echo "\nTesting get_uddoktapay_config() function:\n";
    $config = get_uddoktapay_config();
    foreach ($config as $key => $value) {
        echo "  " . $key . " = " . (is_bool($value) ? ($value ? 'true' : 'false') : $value) . "\n";
    }
    
    // Check if global PDO is accessible within the function
    echo "\nChecking global PDO accessibility within function:\n";
    function test_global_pdo() {
        if (isset($GLOBALS['pdo'])) {
            echo "  ✓ \$GLOBALS['pdo'] is accessible\n";
            return true;
        } else {
            echo "  ✗ \$GLOBALS['pdo'] is not accessible\n";
            return false;
        }
    }
    
    test_global_pdo();
} else {
    echo "✗ PDO connection is not available\n";
}
?>