<!DOCTYPE html>
<?php 
include ('includes/header.php');?>
<html>
<head>
    <meta charset="utf-8">
    <title>PHP JSON File CRUD (Create Read Update and Delete)</title>
    <link rel="stylesheet" type="text/css" href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css">
</head>
<body>
<?php
 
    //get json data
    $data = file_get_contents('api/RTXUpdate.json');
    $data_array = json_decode($data);
 
    //assign the data to selected index
    $row = $data_array->RTX_MODE[0];
 
    if(isset($_POST['save'])){
        $input = array(
            'AppVerion' => $_POST['AppVerion'],
            'APKUrl' => $_POST['APKUrl'],
            'Change' => $_POST['Change']
        );
 
        //update the selected index
        $data_array->RTX_MODE[0] = $input;
 
        //encode back to json
        $data = json_encode($data_array, JSON_PRETTY_PRINT);
        file_put_contents('api/RTXUpdate.json', $data);
        $index = "";
        //header('location: appsetting.php');
        echo "<script>window.location.href='appupdate.php';</script>";
        exit;
    }
?>
<div class="login-box">
  <h2>App Update 🆕</h2>
  <form method="post">
    <div class="user-box">
      <input type="text" name="AppVerion" value="<?php echo $row->AppVerion; ?>">
      <label>New AppVerion [Integers only]</label>
    </div>
    <div class="user-box">
      <input type="text" name="APKUrl" value="<?php echo $row->APKUrl; ?>">
      <label>APKUrl</label>
    </div> 
    <div class="user-box">
      <input type="text" name="Change" value="<?php echo $row->Change; ?>">
      <label>What's new</label>
    </div> 
    <div class="col-12"> <button type="submit" name="save" class="btn btn-primary btn-block logn-btn">Submit</button> </div>
  </form>
</div>
<?php include ('includes/footer.php');?>
</body>
</html>