<?php 
if (session_status() === PHP_SESSION_NONE){session_start();}
ini_set('display_errors', 1);
ini_set('display_startup_errors', 1);
error_reporting(E_ALL);


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

$res = $_GET['update'];

//$id = $row['id'];
$title = $data["app_dns"][$res]["dns_title"];
$url = $data["app_dns"][$res]["url"];
$live = $data["app_dns"][$res]["live_dns"];
$epg = $data["app_dns"][$res]["epg_dns"];
$movie = $data["app_dns"][$res]["movie_dns"];
$series = $data["app_dns"][$res]["series_dns"];
$catchup = $data["app_dns"][$res]["catchup_dns"];

if(isset($_POST['submit'])){
    $jsonData = file_get_contents("./api/zyx.json");
$arrayData = json_decode($jsonData, true);
$replacementData = array('app_dns' =>  array($res =>array(
	"dns_title"             => $_POST["dns_title"],
    "url"               => $_POST["url"],
    "live_dns"           => $_POST["live_dns"],
    "epg_dns"                 => $_POST["epg_dns"],
    "movie_dns"    => $_POST["movie_dns"],
    "series_dns"         => $_POST["series_dns"],
    "catchup_dns"                       => $_POST["catchup_dns"])))
    ;
    $newArrayData = array_replace_recursive($arrayData, $replacementData);
$newJsonData = json_encode($newArrayData, JSON_PRETTY_PRINT);
file_put_contents("./api/zyx.json", $newJsonData);

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

?>

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

          <!-- Page Heading -->
          <h1 class="h3 mb-1 text-gray-800"> Update Server Dns</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> Enter Dns Details</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\">Title</label>\n";
echo "						   <input type=\"hidden\" name=\"id\" value=\"$res\">\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"dns_title\" value=\"$title\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">DNS</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"url\" value=\"$url\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Live</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"live_dns\" value=\"$live\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Epg</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"epg_dns\" value=\"$epg\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Movies</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"movie_dns\" value=\"$movie\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Series</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"series_dns\" value=\"$series\">\n";
echo "                        </div>\n";
echo "                      </div>\n";
echo "                      <div>\n";
echo "                        <div class=\"form-group\">\n";
echo "                          <label class=\"bmd-label-floating\">Catch-Up</label>\n";
echo "                          <input type=\"text\" class=\"form-control\" name=\"catchup_dns\" value=\"$catchup\">\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";
