<?php 
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);

$str_data = file_get_contents("api/vpn.json");
$data = json_decode($str_data, true);
 

$res = $_GET['update'];

//$id = $row['id'];
$country = $data["files"][$res]["country"];
$city = $data["files"][$res]["city"];
$file = $data["files"][$res]["file"];
if(isset($_POST['submit'])){
    $jsonData = file_get_contents("./api/vpn.json");
$arrayData = json_decode($jsonData, true);
$replacementData = array('files' =>  array($res =>array(
	"country"             => $_POST["country"],
    "city"               => $_POST["city"],
    "file"           => $_POST["file"]
    )))
    ;
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
file_put_contents("./api/vpn.json", $newJsonData);

header("Location: vpn1.php");
}
include ('includes/header.php');

?>

<!-- Begin Page Content -->
        <div class="container-fluid">

          <!-- Page Heading -->
          <h1 class="h3 mb-1 text-gray-800"> Update Vpn Details</h1>

              <!-- Custom codes -->
                <div class="card border-left-primary alert-primary shadow h-100 card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fa fa-android"></i> Update Vpn Credentials</h6>
                </div>                
                <div class="card-body">
                    <?
echo "                  <form  method=\"post\">\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">country</label>\n";
echo "						   <input type=\"hidden\" name=\"id\" value=\"$res\">\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"country\" value=\"$country\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">city</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"city\" value=\"$city\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">file</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"file\" value=\"$file\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        					<br><button type=\"submit\" name=\"submit\" class=\"btn btn-primary pull-right\">Submit</button>\n";
echo "				</form>\n";
echo "				</div>\n";
echo "              </div>\n";
echo "            </div>\n";
echo "          </div>\n";
echo "    <br><br><br>\n";
include ('includes/footer.php');
echo "</body>\n";
echo "\n";
echo "</html>\n";
