<?php
require_once "config/Conexion.php";

echo "--- Checking Database Records ---\n";
$sql = "SELECT * FROM certificados_medicos";
$rs = ejecutarConsulta($sql);

if ($rs) {
    while ($row = $rs->fetch_assoc()) {
        echo "ID: " . $row['idcertificado'] . " | Emp: " . $row['idempleado'] . " | Estado: " . $row['estado'] . "\n";
        echo "Path: " . $row['ruta_certificado'] . "\n";
        
        // Resolve path
        // DB path is like '../files/certificados_encriptados/...' relative to ajax/
        // So from SISTEMA/ root, it should be 'files/certificados_encriptados/...'
        $path = str_replace('../', '', $row['ruta_certificado']);
        $fullPath = __DIR__ . '/' . $path;
        
        echo "Resolved Full Path: " . $fullPath . "\n";
        if (file_exists($fullPath)) {
            echo "[OK] File exists.\n";
        } else {
            echo "[ERROR] File NOT found!\n";
        }
        echo "--------------------------------\n";
    }
} else {
    echo "No records found or query error.\n";
}
?>
