<?php
require_once 'includes/db.php';

echo "=== COMPANIES SCHEMA ===\n";
$cols = fetchAll("DESCRIBE companies");
foreach ($cols as $col) {
    echo "  {$col['Field']} - {$col['Type']}\n";
}

echo "\n=== COMPANIES DATA ===\n";
$companies = fetchAll("SELECT * FROM companies");
print_r($companies);

echo "\n=== SYSTEM MODULES DATA ===\n";
$modules = fetchAll("SELECT * FROM system_modules");
print_r($modules);

echo "\n=== SEARCH FOR SYSTEM_MODULES IN CODEBASE ===\n";
function search_in_files($dir) {
    $files = scandir($dir);
    foreach ($files as $file) {
        if ($file === '.' || $file === '..' || $file === '.git' || $file === '.gemini') continue;
        $path = $dir . '/' . $file;
        if (is_dir($path)) {
            search_in_files($path);
        } else {
            if (pathinfo($path, PATHINFO_EXTENSION) === 'php') {
                $content = file_get_contents($path);
                if (stripos($content, 'system_modules') !== false || stripos($content, 'modules') !== false) {
                    echo "Found reference in: $path\n";
                }
            }
        }
    }
}
search_in_files('.');
