
<?php
session_start();
ini_set("display_errors", 0);
ini_set("display_startup_errors", 0);
error_reporting(32767);

if (!isset($_SESSION["ansnscript_admin"])) {
    header("location:login.php");
    exit;
}

// Banco principal
$dbans = new SQLite3("./api/.ansdb.db");
$dbans->exec("
    CREATE TABLE IF NOT EXISTS ibo(
        id INTEGER PRIMARY KEY NOT NULL,
        mac_address VARCHAR(100),
        key VARCHAR(100),
        username VARCHAR(100),
        password VARCHAR(100),
        expire_date VARCHAR(100),
        dns VARCHAR(100),
        epg_url VARCHAR(100),
        title VARCHAR(100),
        url VARCHAR(100),
        type VARCHAR(100)
    )
");
$dbans->exec("
    CREATE TABLE IF NOT EXISTS playlist(
        id INTEGER PRIMARY KEY NOT NULL,
        mac_address VARCHAR(100),
        url VARCHAR(100),
        name VARCHAR(100)
    )
");
$dbans->exec("
    CREATE TABLE IF NOT EXISTS theme(
        id INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
        name VARCHAR(100),
        url VARCHAR(100)
    )
");

// Dados do tema
$res      = $dbans->query("SELECT * FROM theme");
$rowCount = $dbans->querySingle("SELECT COUNT(*) FROM theme");

$baseUrl = (isset($_SERVER["HTTPS"]) && $_SERVER["HTTPS"] !== "off" ? "https" : "http")
         . "://" . $_SERVER["HTTP_HOST"] . dirname($_SERVER["PHP_SELF"]);

$HOSTa  = "$baseUrl/img/red.jpg";
$HOSTb  = "$baseUrl/img/blue.jpg";
$HOSTc  = "$baseUrl/img/green.jpg";
$HOSTa1 = "$baseUrl/img/g1.gif";

$mac_count = $dbans->querySingle("SELECT COUNT(*) FROM ibo");

// Banco painel
$dbpans  = new SQLite3("./api/.anspanel.db");
$rowans  = $dbpans->querySingle("SELECT * FROM USERS WHERE ID='1'", true);
$nameans = $rowans["NAME"];
$logoans = $rowans["LOGO"];

// JSON para tema
$jsondata111 = file_get_contents("./includes/ansibo.json");
$json111     = json_decode($jsondata111, true);
$col2        = $json111["info"]["aa"];
?>
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <meta name="google" content="notranslate">

    <script src="https://kit.fontawesome.com/3794d2f89f.js" crossorigin="anonymous"></script>

    <title>UniTV BETA V1</title>
    <link rel="shortcut icon" href="./img/logo.png" type="image/png">
    <link rel="icon" href="./img/logo.png" type="image/png">

    <!-- Custom styles for this template -->
    <link href="css/sb-admin-<?= $col2 ?>.css" rel="stylesheet">
    <link rel="stylesheet" type="text/css" href="css/jquery.datetimepicker.min.css"/>
    <link href="vendor/fontawesome-free/css/all.min.css" rel="stylesheet" type="text/css">
    <link href="https://fonts.googleapis.com/css?family=Nunito:200,300,400,600,700,800,900" rel="stylesheet">
</head>
<body id="page-top">
    <div id="wrapper">
        <!-- Sidebar -->
        <ul class="navbar-nav bg-gradient-primary sidebar sidebar-dark accordion" id="accordionSidebar">
            <!-- Sidebar - Brand -->
            <a class="sidebar-brand d-flex align-items-center justify-content-center" href="https://t.me/brappsprojetos">
                <div class="sidebar-brand-icon">
                    <img class="img-profile rounded-circle" width="65px" src="<?= $logoans ?: 'img/logo.png' ?>">
                </div>
            </a>

            <hr class="sidebar-divider my-0">

            <li class="nav-item">
                <a class="nav-link" href="users.php">
                    <i class="fas fa-fw fa-user-plus"></i>
                    <span>Active</span>
                </a>
            </li>
            
            <li class="nav-item">
                <a class="nav-link" href="profile.php">
                    <i class="fas fa-fw fa-user"></i>
                    <span>Perfil</span>
                </a>
            </li>

            <li class="nav-item">
                <a class="nav-link" href="logout.php">
                    <i class="fas fa-fw fa-sign-out"></i>
                    <span>Sair</span>
                </a>
            </li>
            <div class="text-center d-none d-md-inline">
            </div>
        </ul>
        <!-- End of Sidebar -->

        <!-- Content Wrapper -->
        <div id="content-wrapper" class="d-flex flex-column">
            <!-- Main Content -->
            <div id="content">
                <!-- Topbar -->
                <nav class="navbar navbar-expand navbar-light topbar mb-4 static-top shadow">
                    <!-- Sidebar Toggle (Topbar) -->
                    <button id="sidebarToggleTop" class="btn btn-link d-md-none rounded-circle mr-3">
                        <i class="fa fa-bars"></i>
                    </button>

                    <div>
                        <h5 class="m-0 text-primary"><?= $nameans ?></h5>
                    </div>

                    <!-- Topbar Navbar -->
                    <ul class="navbar-nav ml-auto">
                        <li class="nav-item dropdown no-arrow mx-1">
                            <a class="nav-link dropdown-toggle" href="https://t.me/brappsprojetos">
                                <i class="fa-brands fa-telegram"></i>
                                <span class="badge badge-success">Nosso Telegram</span>
                            </a>
                        </li>

                        
                        <li class="nav-item dropdown no-arrow mx-1">
                            </a>
                        </li>
                    </ul>
                </nav>
                <!-- End of Topbar -->
