<?php
// public/admin/dashboard_block.php
session_start();
require_once __DIR__ . '/../../config/admin.php';
require_admin_role('BLOCK_ADMIN');
require_once __DIR__ . '/../../config/db.php';
$block_id = $_SESSION['admin_block_id'];
// Panchayats in block
$panchayats = $pdo->prepare('SELECT id, name FROM gps WHERE block_id=? ORDER BY name');
$panchayats->execute([$block_id]);
$panchayats = $panchayats->fetchAll();
// Participants in block
$participants = $pdo->prepare('SELECT * FROM participants WHERE block_id=?');
$participants->execute([$block_id]);
$participants = $participants->fetchAll();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Block Admin Dashboard</title>
    <link rel="stylesheet" href="/school-crm/public/assets/bootstrap.min.css">
</head>
<body>
<div class="container py-4">
    <h2>Block Admin Dashboard</h2>
    <div class="row mb-4">
        <div class="col-md-6">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Panchayats</h5>
                    <h2><?= count($panchayats) ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-6">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Participants</h5>
                    <h2><?= count($participants) ?></h2>
                </div>
            </div>
        </div>
    </div>
    <h5>Panchayats in Block</h5>
    <ul class="list-group mb-4">
        <?php foreach ($panchayats as $g): ?>
            <li class="list-group-item"> <?= htmlspecialchars($g['name']) ?> </li>
        <?php endforeach; ?>
    </ul>
    <h5>Participants</h5>
    <table class="table table-bordered table-sm">
        <thead><tr><th>Name</th><th>Age</th><th>Gender</th><th>Category</th></tr></thead>
        <tbody>
        <?php foreach ($participants as $p): ?>
            <tr>
                <td><?= htmlspecialchars($p['full_name']) ?></td>
                <td><?= htmlspecialchars($p['age']) ?></td>
                <td><?= htmlspecialchars($p['gender']) ?></td>
                <td><?= htmlspecialchars($p['category']) ?></td>
            </tr>
        <?php endforeach; ?>
        </tbody>
    </table>
    <a href="/school-crm/public/admin/admin_logout.php" class="btn btn-secondary">Logout</a>
</div>
</body>
</html>
