<?php
ini_set('display_errors', 0);
include(__DIR__ . '/functions.php');

if (session_status() === PHP_SESSION_NONE) {
	session_start();
}

$log_check = $db->select('user', '*', 'id = :id', '', [':id' => 1]);
$loggedinuser = !empty($log_check) ? $log_check[0]['username'] : null;

if (!isset($_SESSION['name']) == $loggedinuser) {
	header("location:"."index.php");
	exit();
}

if (isset($_REQUEST['logout'])) {
    session_destroy();
    setcookie("auth", "");
    header("Location: index.php");
    exit;
}

$time = $_SERVER['REQUEST_TIME'];

$timeout_duration = 900;
if (isset($_SESSION['LAST_ACTIVITY']) && (time() - $_SESSION['LAST_ACTIVITY']) > $timeout_duration) {
	session_unset();
	session_destroy();
	session_start();
}
$_SESSION['LAST_ACTIVITY'] = $time;

function sanitize($data) {
	$data = trim($data);
	$data = htmlspecialchars($data, ENT_QUOTES );
	$data = SQLite3::escapeString($data);
	return $data;
}
?>

<!DOCTYPE html>
<html lang="en">
   <head>
      <title>Nova TiVi</title>
      <meta charset="utf-8">
      <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
      <meta name="author" content="RTX">
	  <link rel="icon" type="image/x-icon" href="./img/favicon.ico">
	  <link rel="apple-touch-icon" sizes="180x180" href="./img/apple-touch-icon.png">
	  <link rel="icon" type="image/png" sizes="32x32" href="./img/favicon-32x32.png">
	  <link rel="icon" type="image/png" sizes="16x16" href="./img/favicon-16x16.png">
	  <link rel="manifest" href="./img/site.webmanifest">
      <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
      <link href="css/themes/darkly/bootstrap.css" rel="stylesheet" title="main">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css">
      <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css">
      <link href="css/simple-sidebar.css" rel="stylesheet">
	     <link href="css/style.css" rel="stylesheet">
   </head>

      <div id="net-canvas"></div> 
      <body>
         <div class="d-flex" id="wrapper">
         <!-- Sidebar-->
         <div class="" id="sidebar-wrapper">
            <div class="sidebar-heading">
               <div class="sidebar-logo">
				<img src="./img/login_logo#1.png" alt="logo">
			  </div>
            </div>
            <span>
  <a class="list-group-item" href="#" target="_blank">NovaTiVi</a></span>
           <div class="list-group list-group-flush">
               <a class="list-group-item list-group-item-action " href="main.php">
               <i class="fa fa-cogs"></i>&nbsp;&nbsp;	Ustawienia DNS </a>
               <a class="list-group-item list-group-item-action " href="user.php">
               <i class="fa fa-user" ></i>&nbsp;&nbsp;	Ustawienia konta </a>
         </div>
         </div>
         <!-- /#sidebar-wrapper -->
         <!-- Page Content -->
         <div id="page-content-wrapper">
         <nav class="navbar navbar-expand-lg navbar-dark ctnav">
            <button class="btn btn-primary" id="menu-toggle"><i class="fa fa-bars"></i></button>
            <div class="center" id="pageMessages"></div>
            <a href="<?=basename($_SERVER["SCRIPT_NAME"]).'?logout'?>" class="btn btn-danger ml-auto mr-1"><i class="fa fa-sign-out"></i> Wyloguj się</a> 
         </nav>
         <div class="container-fluid">
         <br>
      <style>
body {
  background-color: #181828;
  background-image: url("./img/binding_dark.webp");
  background-size: cover;
  background-attachment: fixed;
  color: #fff;
  font-family: 'Poppins', sans-serif;
}

/* particles jako warstwa tła */
#particles-js {
  position: fixed;
  top: 0;
  left: 0;
  width: 100%;
  height: 100%;
  background: radial-gradient(circle at center, #1f1f3a, #0d0d1a);
  z-index: -1;
}

/* canvas od particles */
.particles-js-canvas-el {
  position: fixed;
  top: 0;
  left: 0;
}

/* komunikaty */
#pageMessages {
  position: fixed;
  top: 20px;
  left: 50%;
  transform: translateX(-50%);
  width: 50%;
  z-index: 9999;
}

/* alerty */
.alert {
  border-radius: 10px;
  padding: 15px 20px;
  background: rgba(255,255,255,0.08);
  backdrop-filter: blur(10px);
  border: 1px solid rgba(255,255,255,0.1);
  color: #fff;
}

/* zamykanie alertów */
.alert .close {
  position: absolute;
  top: 10px;
  right: 10px;
  font-size: 1em;
  color: #fff;
  opacity: 0.7;
  cursor: pointer;
}

.alert .close:hover {
  opacity: 1;
}

/* ikonki */
.alert .fa {
  margin-right: .5em;
}
       </style>
       	<script src="./js/custom.js"></script>
		<script src="./js/three.min.js"></script>
		<script src="./js/vanta.net.min.js"></script>