<?php
session_start();

if (isset($_POST['id']))
{
if (isset($_SESSION['token'])) {
    $token = $_SESSION['token'];
    $user=$_POST['id'];
    //$pid =$_POST[]; // Replace with your actual PID or get it dynamically from your application

    // Ensure $pid is properly sanitized or validated before using in the URL
    
        //-------------------API CALL------------------------------------//

        $jsonFilePath = __DIR__ . '/../urls/api_endpoints.json';
        $jsonData = file_get_contents($jsonFilePath);
        $endpoints = json_decode($jsonData, true);
        $url = $endpoints['update_role'] . $user;
        //---------------------------ENDS HERE-----------------------------------------//


    $headers = [
        "Authorization: Bearer $token",
    ];

    $options = [
        'http' => [
            'header'  => implode("\r\n", $headers),
            'method'  => 'DELETE',
            'ignore_errors' => true
        ],
        'ssl' => [
            'verify_peer' => false,
            'verify_peer_name' => false
        ]
    ];

    $context = stream_context_create($options);
    $response = file_get_contents($url, false, $context);

    if ($response !== false) {
       echo '<script>window.location.href = "../configuration/roles.php";</script>';
       exit;
    }
 else 
 {
    $response = json_encode(['status' => 'error', 'message' => 'Failed to fetch data']);

 }

}
}
?>
