<?php
require_once 'config/database.php';

echo "<!DOCTYPE html>
<html>
<head>
    <title>Management Board Images Test</title>
    <link href='https://cdn.jsdelivr.net/npm/bootstrap@5.1.3/dist/css/bootstrap.min.css' rel='stylesheet'>
    <link href='assets/css/style.css' rel='stylesheet'>
</head>
<body>
<div class='container mt-4'>
    <h2>Management Board Images Test</h2>
    <div class='table-responsive'>
        <table class='table table-bordered'>
            <thead>
                <tr>
                    <th>ID</th>
                    <th>Name</th>
                    <th>Photo Path</th>
                    <th>File Status</th>
                    <th>Display Test</th>
                </tr>
            </thead>
            <tbody>";

$stmt = $pdo->query('SELECT id, name, photo FROM management_board_members ORDER BY id');
while ($row = $stmt->fetch()) {
    $photoPath = $row['photo'];
    $fullPath = __DIR__ . '/' . $photoPath;
    $fileExists = $photoPath && file_exists($fullPath) ? 'YES' : 'NO';
    $webPath = $photoPath ? '../' . $photoPath : '';
    
    echo "<tr>
            <td>{$row['id']}</td>
            <td>" . htmlspecialchars($row['name']) . "</td>
            <td>" . htmlspecialchars($photoPath) . "</td>
            <td>{$fileExists}</td>
            <td>";
    
    if ($photoPath && file_exists($fullPath)) {
        echo "<img src='{$webPath}' alt='Profile Photo' class='profile-img-small'>";
    } else {
        echo "<span class='text-muted'>No Image</span>";
    }
    
    echo "</td></tr>";
}

echo "      </tbody>
        </table>
    </div>
    <div class='mt-4'>
        <h4>Direct Links to Images:</h4>";
        
$stmt = $pdo->query('SELECT id, name, photo FROM management_board_members WHERE photo IS NOT NULL AND photo != ""');
while ($row = $stmt->fetch()) {
    $webPath = '../' . $row['photo'];
    echo "<p><a href='{$webPath}' target='_blank'>" . htmlspecialchars($row['name']) . " - " . htmlspecialchars($row['photo']) . "</a></p>";
}

echo "    </div>
</div>
</body>
</html>";
?>