<?php
// public/admin/dashboard_district.php
session_start();
require_once __DIR__ . '/../../config/admin.php';
require_admin_role('DISTRICT_ADMIN');
require_once __DIR__ . '/../../config/db.php';
$district_id = $_SESSION['admin_district_id'];
// Blocks in district
$blocks = $pdo->prepare('SELECT id, name FROM blocks WHERE district_id=? ORDER BY name');
$blocks->execute([$district_id]);
$blocks = $blocks->fetchAll();
// Panchayats in district
$panchayats = $pdo->prepare('SELECT id, name FROM gps WHERE block_id IN (SELECT id FROM blocks WHERE district_id=?)');
$panchayats->execute([$district_id]);
$panchayats = $panchayats->fetchAll();
// Participants in district
$participants = $pdo->prepare('SELECT COUNT(*) FROM participants WHERE district_id=?');
$participants->execute([$district_id]);
$total_participants = $participants->fetchColumn();
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>District Admin Dashboard</title>
    <link rel="stylesheet" href="/school-crm/public/assets/bootstrap.min.css">
</head>
<body>
<div class="container py-4">
    <h2>District Admin Dashboard</h2>
    <div class="row mb-4">
        <div class="col-md-4">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Blocks</h5>
                    <h2><?= count($blocks) ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Panchayats</h5>
                    <h2><?= count($panchayats) ?></h2>
                </div>
            </div>
        </div>
        <div class="col-md-4">
            <div class="card text-center">
                <div class="card-body">
                    <h5>Total Participants</h5>
                    <h2><?= $total_participants ?></h2>
                </div>
            </div>
        </div>
    </div>
    <h5>Blocks in District</h5>
    <ul class="list-group mb-4">
        <?php foreach ($blocks as $b): ?>
            <li class="list-group-item"> <?= htmlspecialchars($b['name']) ?> </li>
        <?php endforeach; ?>
    </ul>
    <a href="/school-crm/public/admin/admin_logout.php" class="btn btn-secondary">Logout</a>
</div>
</body>
</html>
