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

echo "=== TABLES ===\n";
$tables = fetchAll("SHOW TABLES");
foreach ($tables as $row) {
    $tableName = array_values($row)[0];
    echo "- $tableName\n";
}

echo "\n=== EMPLOYEES SCHEMA ===\n";
$cols = fetchAll("DESCRIBE employees");
foreach ($cols as $col) {
    echo "  {$col['Field']} - {$col['Type']} - Null: {$col['Null']} - Key: {$col['Key']}\n";
}

echo "\n=== SYSTEM MODULES OR RELATED TABLES ===\n";
foreach (['system_modules', 'company_modules', 'modules'] as $t) {
    try {
        $check = fetch("SHOW TABLES LIKE '$t'");
        if ($check) {
            echo "Table $t exists! Structure:\n";
            $mCols = fetchAll("DESCRIBE $t");
            foreach ($mCols as $col) {
                echo "  {$col['Field']} - {$col['Type']}\n";
            }
            echo "Sample Data for $t:\n";
            $data = fetchAll("SELECT * FROM $t LIMIT 10");
            print_r($data);
        } else {
            echo "Table $t does not exist.\n";
        }
    } catch (Exception $e) {
        echo "Error checking table $t: " . $e->getMessage() . "\n";
    }
}
