<?php
// Include database connection
include '../layouts/dbconn.php';

// Check if role_id is provided
if (!isset($_GET['role_id'])) {
    echo json_encode([]);
    exit;
}

$roleId = (int)$_GET['role_id'];

// Fetch permissions for the role
$query = "SELECT permission_id FROM role_permissions WHERE role_id = $roleId";
$result = $conn->query($query);

$permissions = [];
if ($result && $result->num_rows > 0) {
    while ($row = $result->fetch_assoc()) {
        $permissions[] = (int)$row['permission_id'];
    }
}

// Return permissions as JSON
header('Content-Type: application/json');
echo json_encode($permissions);
?>