<?php
// debug_images.php - Letakkan di admin folder
require_once '../includes/auth.php';

if (!isAdmin()) {
    redirect('../login.php');
}

// Ambil semua station dan check content gambar
$stmt = $pdo->query("SELECT id, nama_station, deskripsi, instruksi_peserta, instruksi_penguji FROM stations ORDER BY id DESC");
$stations = $stmt->fetchAll();

echo "<h1>Debug Images in Database</h1>";

foreach ($stations as $station) {
    echo "<h2>Station: {$station['nama_station']} (ID: {$station['id']})</h2>";
    
    $fields = [
        'deskripsi' => $station['deskripsi'],
        'instruksi_peserta' => $station['instruksi_peserta'],
        'instruksi_penguji' => $station['instruksi_penguji']
    ];
    
    foreach ($fields as $field => $content) {
        echo "<h3>Field: {$field}</h3>";
        if (strpos($content, '<img') !== false) {
            echo "<div style='color: green;'>✓ Gambar ditemukan</div>";
            // Extract image src
            preg_match_all('/<img[^>]+src="([^">]+)"/', $content, $matches);
            foreach ($matches[1] as $src) {
                echo "<div>Image URL: {$src}</div>";
                echo "<div>Image Preview: <img src='{$src}' style='max-width: 200px; border: 1px solid #ccc;'></div>";
            }
        } else {
            echo "<div style='color: red;'>✗ Tidak ada gambar</div>";
        }
        echo "<hr>";
    }
}
?>