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

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


if(isset($_GET['delete'])){
    
$prepair = file_get_contents("api/zyx.json");
$json_arr = json_decode($prepair, true);
// delete array and reindex specific array of arrays 
array_splice($json_arr['app_dns'], $delete, 1);
// encode back to json array for saving
$newJsonData = json_encode($json_arr, JSON_PRETTY_PRINT);
// save array as json file
file_put_contents("./api/zyx.json",$newJsonData);
header('Location: dns.php');
$i = (int)$i;
}
include('includes/header.php');
?>	
<div class="modal fade" id="confirm-delete" tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
    <div class="modal-dialog">
        <div class="modal-content">
            <div class="modal-header">
                <h2>Confirm</h2>
            </div>
            <div class="modal-body">
                Do you really want to delete?
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
                <a class="btn btn-danger btn-ok">Delete</a>
            </div>
        </div>
    </div>
</div>
<main role="main" class="col-15 pt-4 px-5"><div class="row justify-text-center"><div class="chartjs-size-monitor" style="position:absolute ; left: 0px; top: 0px; right: 0px; bottom: 0px; overflow: hidden; pointer-events: none; visibility: hidden; z-index: -1;"><div class="chartjs-size-monitor-expand" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:1000000px;height:1000000px;left:0;top:0"></div></div><div class="chartjs-size-monitor-shrink" style="position:absolute;left:0;top:0;right:0;bottom:0;overflow:hidden;pointer-events:none;visibility:hidden;z-index:-1;"><div style="position:absolute;width:200%;height:200%;left:0; top:0"></div></div></div>
          <div id="main">
            
<link rel="stylesheet" href="styles.css">
          <!-- Page Heading -->
          <h1 class=" h3 mb-1 text-gray-800"> Dns Mangement</h1>
                        <a button class="btn btn-primary btn-icon-split" id="button" href="./dns_create.php">
                        <span class="icon text-white-50"><i class="fas fa-check"></i></span><span class="text">Create</span>
                        </button></a>
          </div>
		<div class="table-responsive">
			<table class="table table-striped table-sm alert-primmary">
			<thead class= "text-primary">
				<tr>
                  <th>Dns_title</th>
                  <th>Url</th>
                  <th>Live_dns</th>
				  <th>Epg_dns</th>
				  <th>Movie_dns</th>
				<th>Series_dns</th>
				<th>Catchup_dns
                  <th>Edit</th>
				  <th>Delete</th>
                </tr>
              </thead>
              </tbody>
              <tr>
            <?      
			   for($i = 0; $i < sizeof($data['app_dns']); $i++){         ?>
                  <td><?echo $data["app_dns"][$i]["dns_title"] ?></td>
                  <td><?echo $data["app_dns"][$i]["url"] ?></td>
                  <td><?echo $data["app_dns"][$i]["live_dns"] ?></td>
                   <td><?echo $data["app_dns"][$i]["epg_dns"] ?></td>
                   <td><?echo $data["app_dns"][$i]["movie_dns"] ?></td>
                    <td><?echo $data["app_dns"][$i]["series_dns"] ?></td>
                     <td><?echo $data["app_dns"][$i]["catchup_dns"] ?></td>
				  <td><a href="./dns_update.php?update=<?=$i?>"><i class="fa fa-pencil-square-o" style="font-size:24px;color:blue"></i></a></td>
                  <td><a href="#" data-href="./dns.php?delete=<? echo $i?>" data-toggle="modal" data-target="#confirm-delete"><i class="fa fa-trash-o" style="font-size:24px;color:red"></i></a></td>
                  </tr>
				  <?}?>
                
              </tbody>
			</table>
		</div>
</main>

    <br><br><br>
<?php include ('includes/footer.php');?>
    <script>
$('#confirm-delete').on('show.bs.modal', function(e) {
    $(this).find('.btn-ok').attr('href', $(e.relatedTarget).data('href'));
});
    </script>
    <script> 
$(document).ready(function () {
    $("#flash-msg").delay(3000).fadeOut("slow");
});
  </script>
</body>


