Sindbad~EG File Manager

Current Path : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/administration/
Upload File :
Current File : /home/copmadinaarea/thecopmadinaarea.org/portal/modules/administration/get-districts.php

<?php
/**
 * API Endpoint: Get Districts by Area
 * Returns districts filtered by area_id for cascading dropdown
 */

require_once '../../config/config.php';
checkLogin();

header('Content-Type: application/json');

$db = Database::getInstance()->getConnection();

if (isset($_GET['area_id']) && !empty($_GET['area_id'])) {
    $areaId = (int)$_GET['area_id'];
    
    try {
        $stmt = $db->prepare("
            SELECT id, district_name, district_code, area_id 
            FROM districts 
            WHERE area_id = :area_id AND is_active = 1 
            ORDER BY district_name ASC
        ");
        $stmt->execute(['area_id' => $areaId]);
        $districts = $stmt->fetchAll(PDO::FETCH_ASSOC);
        
        echo json_encode([
            'success' => true,
            'districts' => $districts
        ]);
    } catch (Exception $e) {
        echo json_encode([
            'success' => false,
            'error' => $e->getMessage()
        ]);
    }
} else {
    echo json_encode([
        'success' => false,
        'error' => 'Area ID is required'
    ]);
}

Sindbad File Manager Version 1.0, Coded By Sindbad EG ~ The Terrorists