<?php
require_once __DIR__ . '/navbar.php';
if (session_status() === PHP_SESSION_NONE) {
    session_start();
}
$db_path = __DIR__ . '/../config/db.php';
$pdo = require $db_path;
$role = $_SESSION['role'] ?? 'other';
$formats = $pdo->query('SELECT * FROM formats')->fetchAll();
?><!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>OOH Management</title>
    <link rel="icon" type="image/x-icon" href="../ooh_project/favicon.ico">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.0/dist/css/bootstrap.min.css" rel="stylesheet">
    <style>
      body, html, .container, .card, .modal-content, .table, .form-control, .btn, .modal-title, .fw-bold, .text-primary, .text-light {
        font-family: 'Arial Unicode MS', Arial, Helvetica, sans-serif !important;
      }
    </style>
</head>
<body>
<div class="container mt-5">
    <h2>Site Evaluation</h2>
    <table class="table table-bordered">
        <thead>
            <tr>
                <th>ID</th>
                <th>Supplier</th>
                <th>Type</th>
                <th>Format</th>
                <th>Score</th>
                <th>Evaluate</th>
            </tr>
        </thead>
        <tbody>
            <?php foreach ($formats as $f): ?>
            <tr>
                <td><?= $f['id'] ?></td>
                <td><?= htmlspecialchars($f['supplier']) ?></td>
                <td><?= htmlspecialchars($f['type']) ?></td>
                <td><?= htmlspecialchars($f['format']) ?></td>
                <td><?= htmlspecialchars($f['evaluate_score']) ?></td>
                <td>
                    <?php if ($role === 'admin' || $role === 'staff'): ?>
                    <form method="post" action="../handler/evaluate_site.php">
                        <input type="hidden" name="format_id" value="<?= $f['id'] ?>">
                        <input type="number" step="0.1" min="0" max="10" name="evaluate_score" value="<?= htmlspecialchars($f['evaluate_score']) ?>" required>
                        <button type="submit" class="btn btn-sm btn-warning">Update</button>
                    </form>
                    <?php endif; ?>
                </td>
            </tr>
            <?php endforeach; ?>
        </tbody>
    </table>
</div>
</body>
</html>
