<?php
session_start();
$activePage = 'User';
if(isset($_SESSION['token'] ))
{
include("../elements/master.php");
include("../elements/login_function.php");
}
//--------------------API CALL-----------------------//
$jsonFilePath = __DIR__ . '/../urls/api_endpoints.json';
$jsonData = file_get_contents($jsonFilePath);
$endpoints = json_decode($jsonData, true);
$url = $endpoints['user_edit'];
//---------------End Here--------------------------//

$token = $_SESSION['token'];
$result = make_get_request($url, ["Authorization: $token"]);
$response = json_decode($result, true);
$_SESSION["response"] = $response;
include("../user/user_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_user.css" type="text/css">
</head>
<body>


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


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

        <?php 
          $pid=htmlspecialchars($user['pid']);;
          $password =htmlspecialchars($user['password']);;
          $firstname=htmlspecialchars($user['firstname']);;
          $lastname=htmlspecialchars($user['lastname']);;
          $email=htmlspecialchars($user['email']);;
          $designation=htmlspecialchars($user['Designation']);;
          $department=htmlspecialchars($user['Department']);;
          $phone_num=htmlspecialchars($user['work_phone']);;
          ?>


        <div>
        <div class="col-10">
        <label>PID</label>
        </div>
        <div class="col-40">
        <input type="text" name="pid" 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>firstname</label>
        </div>
        <div class="col-40">
        <input type="text" name="firstname" placeholder="Enter User Firstname" value="<?php echo $firstname?>" required />
        </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>lastname</label>
          </div>
          <div class="col-40">
          <input type="text" name="lastname" placeholder="Enter Lastname"  value="<?php echo $lastname?>"required />
          </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>Email</label>
        </div>
        <div class="col-40">
        <input type="text" name="email" placeholder="Enter Email Id"  value="<?php echo $email?>" />
        </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>Department</label>
        </div>
        <div class="col-40 ">
        <input type="text" name="department" placeholder="Enter Department" value="<?php echo $department?>" />
        </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>Designation</label>
        </div>
        <div class="col-40">
        <input type="text" name="designation" placeholder="Enter Designation" value="<?php echo $designation?>" />
        </div>
        <div class="col-10 hidden">
        <label>cust_field4</label>
        </div>
        <div class="col-40 hidden">
        <input type="text" name="cust_field4" placeholder="Enter cust_field4"  />
        </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>
