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

$message = '<div class="alert alert-success" id="flash-msg"><h4><i class="icon fa fa-check"></i>Items Updated!</h4></div>';

$db = new SQLite3('./api/.db.db');
$db->exec("CREATE TABLE IF NOT EXISTS perfect(id INTEGER PRIMARY KEY NOT NULL,status VARCHAR(25) ,portal1 VARCHAR(100),portal2 VARCHAR(100),portal3 VARCHAR(100),portal4 VARCHAR(100))");
$rows2 = $db->query("SELECT COUNT(*) as count FROM perfect");
$row2 = $rows2->fetchArray();
$numRows2 = $row2['count'];
if ($numRows2 == 0){
	$db->exec("INSERT INTO perfect(id status,portal1,portal2,portal3,portal4) VALUES('true','http://changeme.net:80','http://changeme.net:80','http://changeme.net:80','http://changeme.net:80')");
}
$rows3 = $db->query("SELECT * FROM perfect");
$row3 = $rows3->fetchArray();
if(isset($_GET['delete'])){
$db->exec("DELETE FROM perfect WHERE id=".$_GET['delete']);
header("Location: perfectManager.php");
}
?>

<div class="main-panel">
      <!-- Navbar -->
<?php

//read and change dns
if(isset($_POST['text'])){
	//maybe create a gen config file for keys if all client has diff key??
	// $status	=   "true";
	$portal1	= strip_tags($_REQUEST['data1']);
	$portal2	= strip_tags($_REQUEST['data2']);
	$portal3	= strip_tags($_REQUEST['data3']);
  $portal4	= strip_tags($_REQUEST['data4']);
		//to not duplicate////
		$sql = "DELETE FROM perfect";
		$db->exec($sql);
    $db->exec("INSERT INTO perfect(id ,status, portal1,portal2,portal3,portal4) VALUES('1' ,'true','$portal1','$portal2','$portal3','$portal4')");
    header('Location: ' . $_SERVER['PHP_SELF']);
}
include ('includes/header.php');
?>

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta http-equiv="X-UA-Compatible" content="IE=edge">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
	<link rel="stylesheet" href="https://www.w3schools.com/w3css/4/w3.css">
</head>
<body>

      <!-- Navbar -->
<div class="content-wrapper">
    <div class="container-fluid">
      <?if(isset($_GET['message'])){echo $_GET['message'];}?>
        <div class="card mb-3">
            <div class="card bg-dark text-white">
              <div class="card-body">
               <div class="table-responsive">
                <div class="alert alert-dark" role="alert">

<div class="main-panel">
      <div class="content">
        <div class="container-fluid">

	<?if(isset($_GET['message'])){echo $_GET['message'];}?>
    <div style="width:600px; margin:0 auto;">
		<div class="row">
		<div class="center">
					<div style="width:600px; margin:0 auto;">
			<h1 class="text-center text-light">Dns Manager</h1>
				<br>
  				<br>
	<div class="container" >
	    <div style="width:600px; margin:0 auto;">
		<div class="row">
		<div class="center">
					<div style="width:600px; margin:0 auto;">
                                         <?if(isset($_GET['message'])){echo $_GET['message'];}?>
						<form method="post">
							<div class="form-group">
								<h4 class="text-center">Change DNS 1</h4>
								<h6 class="form-text text-info">Current DNS is in the box</h6>
								<input type="text" class="form-control" placeholder="http://Your_Dns_Here.ddns.net:8080" name="data1" value="<?php echo $row3['portal1'];?>">
							</div>
							<div class="form-group">
								<h4 class="text-center">Change DNS 2</h4>
								<h6 class="form-text text-info">Current DNS is in the box</h6>
								<input type="text" class="form-control" placeholder="http://Your_Dns_Here.ddns.net:8080" name="data2" value="<?php echo $row3['portal2'];?>">
							</div>
							<div class="form-group">
								<h4 class="text-center">Change DNS 3</h4>
								<h6 class="form-text text-info">Current DNS is in the box</h6>
								<input type="text" class="form-control" placeholder="http://Your_Dns_Here.ddns.net:8080" name="data3" value="<?php echo $row3['portal3'];?>">
							</div>
							<div class="form-group">
								<h4 class="text-center">Change DNS 4</h4>
								<h6 class="form-text text-info">Current DNS is in the box</h6>
								<input type="text" class="form-control" placeholder="http://Your_Dns_Here.ddns.net:8080" name="data4" value="<?php echo $row3['portal4'];?>">
							</div>

							<button type="submit" name="text" class="btn btn-primary">Update</button>
						</form>
						<br>

						<br>

								</div>
							</div>
						</div>
					</div>
				</div>
			</div>
		</div>
<br><br>
<br><br>

</html>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
