<?php
session_start();
header('Content-Type: application/json');
include_once('../includes/config.php');

if (!isset($_SESSION['uid'])) {
    echo json_encode(['success' => false, 'message' => 'Unauthorized']);
    exit();
}

$query = "SELECT ID, CategoryName FROM tblcategories WHERE Status = 'Active' ORDER BY CategoryName";
$result = mysqli_query($con, $query);

$categories = [];
if ($result) {
    while ($row = mysqli_fetch_assoc($result)) {
        $categories[] = $row;
    }
}

echo json_encode([
    'success' => true,
    'data' => $categories
]);
?>
