<?php
/**
 * TEMPORARY DIAGNOSTIC SCRIPT - delete this file after use.
 * Drop this in the SAME folder as your other api/erp/*.php files, then visit:
 * https://kussiya.mjpos.live/api/erp/debug.php
 *
 * This shows exactly where things are so we can fix the require path
 * without more guessing.
 */

header('Content-Type: text/plain');
error_reporting(E_ALL);
ini_set('display_errors', '1');

echo "=== MJ ERP Diagnostic ===\n\n";

echo "1. This file's directory (__DIR__):\n";
echo __DIR__ . "\n\n";

echo "2. Checking common config.php locations:\n";
$candidates = [
    __DIR__ . '/../../config/config.php',
    __DIR__ . '/../../../config/config.php',
    __DIR__ . '/../config/config.php',
    __DIR__ . '/../../config.php',
];
foreach ($candidates as $path) {
    $real = realpath($path);
    echo "   " . $path . "\n";
    echo "     -> " . ($real ? "FOUND at $real" : "NOT FOUND") . "\n";
}

echo "\n3. Listing directories going upward from here:\n";
$dir = __DIR__;
for ($i = 0; $i < 5; $i++) {
    echo "   [$i level(s) up] $dir\n";
    if (is_dir($dir)) {
        $items = @scandir($dir);
        if ($items) {
            $filtered = array_diff($items, ['.', '..']);
            echo "       contains: " . implode(', ', $filtered) . "\n";
        }
    }
    $parent = dirname($dir);
    if ($parent === $dir) break;
    $dir = $parent;
}

echo "\n4. PHP extensions check:\n";
echo "   pdo_mysql loaded: " . (extension_loaded('pdo_mysql') ? 'YES' : 'NO - THIS WOULD CAUSE 500') . "\n";

echo "\n5. Can we write to error log path?\n";
echo "   error_log setting: " . ini_get('error_log') . "\n";

echo "\n=== End Diagnostic - DELETE this file now ===\n";
