<?php 

 $jsondata = file_get_contents("./api/vpn.json");
$data = json_decode($jsondata, true);
$json = $data;
if(isset($_POST['submit'])){
$message = '<div class="alert alert-primary" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';
$json = $data['files'];
$jsonData = file_get_contents("./api/vpn.json");
$arrayData = json_decode($jsonData, true);

$newData = array('files'=>
array(
   'country'              => $_POST["country"],
   'city'                => $_POST["city"],
   'file'           => $_POST["file"]

     ));
    // $newdata = json_encode($newdata);
     //$index = array_search( $key, $keys, $strict = true );
   $newdata = array_replace($arrayData, $newData);
  
$newdata['files'] = array_values($newdata);  
$newJsonData = json_encode($newdata, 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">Create Vpn</h1>
         
          <!-- Content Row -->
          <div class="row">

            <!-- First Column -->
            <div class="col-lg-12">

              <!-- Custom codes -->
                <div class="card border-left-primary shadow card shadow mb-4">
                <div class="card-header py-3">
                <h6 class="m-0 font-weight-bold text-primary"><i class="fas fa-user-shield"></i> Enter VPN Details</h6>
                </div>
                <div class="card-body">
                            <form method="post">
                                <div class="form-group ">
                                    <label class="control-label " for="country">
                                        <strong> Country</strong>
                                    </label>
                                    <div class="input-group">
                                        <input class="form-control" id="country" name="country" placeholder="Country" value='' type="text"/>
                                    </div>
                                    </div>
                                <div class="form-group ">
                                    <label class="control-label " for="city">
                                        <strong> City</strong> 
                                    </label>
                                    <div class="input-group">
                                        <input class="form-control" id="city" name="city" placeholder="City" value='' type="text"/>
                                    </div>
                                    </div>
                                <div class="form-group ">
                                    <label class="control-label " for="file">
                                        <strong> URL</strong> 
                                    </label>
                                    <div class="input-group">
                                        <input class="form-control" id="file" name="file" placeholder="URL" value='' type="text"/>
                                    </div>
                                    </div>
                                <div class="form-group">
                                        <button class="btn btn-primary btn-icon-split" name="submit" type="submit">
                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Submit</span>
                        </button>
                                </form>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
<br><br><br>
    
    <script>
$('#confirm-delete').on('show.bs.modal', function(e) {
    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
$('#datetimepicker').datetimepicker({
	value:dateTime, 
	step:30,
	format:'Y-m-d H:i:s',
	});
    </script>
    <script src="js/jquery.datetimepicker.js"></script>
</body>

<?php include ('includes/functions.php');?>
</html>