<?php
session_start();
$activePage = 'configuration';
$activeSubPage = 'roles';
if(isset($_SESSION['token'] ))
{
include("../elements/master.php");
include("../configuration/role_list.php");

}  


//-------------------API CALL------------------------------------//

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


$token = $_SESSION['token'];
$result = make_get_request($url, ["Authorization: $token"]);
$response = json_decode($result, true);
$_SESSION["response"] = $response;

include("../configuration/role_details_function.php")
  
?>

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Create User</title>
    <link rel="stylesheet" href="../css/style.css" type="text/css">
    <link rel="stylesheet" href="../css/create_role.css" type="text/css">
    <script>
         
    </script>
</head>
<body>


<div class="user_container">
<maincontent>
<div class="usertable">
      <h3>Edit Role</h3>


  <div class="userdetails">
     <form action="role_update.php" class="form" id="createUserForm" method="POST">
  
     <!-- edited portion -->
      <?php foreach ($user_details_fetch as $user): ?>

        <?php 
          $pid=htmlspecialchars($user['id']);;
          $parent_role=htmlspecialchars($user['parent_id']);;
          $description=htmlspecialchars($user['notes']);;
          $max_nodes=htmlspecialchars($user['max_nodes_per_pid']);;
          ?>


        <div>
        <div class="col-10">
        <label>Name</label>
        </div>
        <div class="col-40">
        <input type="text" name="id" placeholder="Enter User PID" value="<?php echo $pid; ?>"   disabled />
        </div>

        <div class="col-10 hidden">
        <label>cust_field9</label>
        </div>
        <div class="col-40 hidden">
        <input type="text" name="cust_field9" placeholder="Enter cust_field9" />
        </div>
        </div>

        <div>
        <div class="col-10">
        <label>Parent Role</label>
        </div>
        <div class="col-40">
        <input type="text" name="parent_id" placeholder="Enter User Firstname" value="<?php echo $parent_role?>" disabled />
        </div>
        <div class="col-10 hidden">
        <label>cust_field9</label>
        </div>
        <div class="col-40 hidden">
        <input type="text" name="cust_field9" placeholder="Enter cust_field9" />
        </div>
        </div>

        <div>
          <div class="col-10">
          <label>Description</label>
          </div>
          <div class="col-40">
          <input type="text" name="notes" placeholder="Enter description"  value="<?php echo $description?>" />
          </div>
          <div class="col-10 hidden">
          <label>cust_field9</label>
          </div>
          <div class="col-40 hidden">
          <input type="text" name="cust_field9" placeholder="Enter cust_field9" />
          </div>
        </div>



        <div>
        <div class="col-10">
        <label>Max Nodes Per User</label>
        </div>
        <div class="col-40">
        <input type="text" name="max_nodes_per_pid" placeholder="Enter Max Nodes Per User"  value="<?php echo $max_nodes?>" />
        </div>

        <div class="col-10 hidden">
        <label>cust_field9</label>
        </div>
        <div class="col-40 hidden">
        <input type="text" name="cust_field9" placeholder="Enter cust_field9" />
        </div>
        </div>
        <div>
        <div class="col-10-submit">
        <input type="submit" name="submit" id="submit" value="submit" />
        </div>    
        </div>
        </div>
        <!--- FOR EACH ENDED-->
        <?php endforeach; ?>
      </form>

      </div>

</div>
    </maincontent>
</div>
<script src="../js/redirect_page.js"></script>
</body>
</html>
