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

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

//parse config options
$config_ini = parse_ini_file("./config.ini");

if ($config_ini['debug'] == 1 ){
	ini_set('display_errors', 1);
	ini_set('display_startup_errors', 1);
	error_reporting(E_ALL);
}else{
	ini_set('display_errors', 0);
}

//db call
$db = new SQLite3('./api/.db.db');
$adb = new SQLite3('./api/.adb.db');
//user check
$log_check = $db->query("SELECT * FROM users WHERE id='1'");
$roe = $log_check->fetchArray();
$loggedinuser = @$roe['username'];
//login check

if (!isset($_SESSION['name']) == $loggedinuser) {
	header("location:"."index.php");
	exit();
}
//logout due to session time
$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;

//sanitize strings
function sanitize($data) {
	$data = trim($data);
	$data = htmlspecialchars($data, ENT_QUOTES );
	$data = SQLite3::escapeString($data);
	return $data;
}
//current file var
$base_file = basename($_SERVER["SCRIPT_NAME"]);
?>
<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="utf-8" />
  <meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no" />
  <meta name="author" content="RGVIP PANELS" />
  <title>Rgvip Panels</title>

  <!-- CSS & Libs -->
  <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css" />
  <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/animate.css/3.2.3/animate.min.css" />
  <link rel="stylesheet" href="css/rgvip.css" />
  <!-- JS -->
  <script src="https://cdn.jsdelivr.net/npm/particles.js@2.0.0/particles.min.js"></script>

   <style>
    .modal-body .list-group-item, .modal-body .list-group-item i { color: #000 !important; }
   
   /* Estilos base para todas las pantallas */
#page-content-wrapper {
  margin-left: 250px !important;
  width: calc(100% - 250px) !important;
  min-height: 100vh !important;
  pading-top: 5px !important; /* Ajusta según altura de tu navbar */
  transition: all 0.3s ease !important;
  position: relative !important;
 
}
.navbar {
  position: relative;
  top: 5px!important;
  width: 100%;
  height: 56px; /* Ajusta esta altura según tu navbar real */
 
}

/* Cuando el menú está cerrado */
#wrapper.toggled #page-content-wrapper {
  margin-left: 15px !important;
  width: calc(100% - 10px) !important;
}

/* Media query para móviles */
@media (max-width: 992px) {
  #page-content-wrapper {
    margin-left: 10px !important;
    width: calc(100% - 10px) !important;
    padding-top: 5px !important;
  }
  
  #wrapper.toggled #page-content-wrapper {
    margin-left: 0 !important;
    width: calc(100% - 250px) !important;
  }
}
  </style>
</head>
<body>
  <div id="particles-js"></div>
  <div class="d-flex" id="wrapper">
    <div class="sidebar-overlay" id="sidebarOverlay"></div>
    <!-- Sidebar -->
    <div id="sidebar-wrapper">
      <div class="sidebar-heading">Rgvip Panels</div>
      <a class="list-group-item text-center" href="https://apps-rgvip.com" target="_blank">
        &#169; <?=date("Y")?> * IBO 4k Rgvip *
      </a>
      <div class="list-group list-group-flush">
      <!-- Sistemas -->
  <small class="text-muted px-3 mt-3 d-block">Herramientas</small>
  <a class="list-group-item list-group-item-action" href="sistema_rgvip.php">
    <i class="fa fa-cogs"></i> Limpieza del sistema y Recordatorios
  </a>
  <!-- Personalización -->
  <small class="text-muted px-3 mt-3 d-block">Personalización</small>
  <a class="list-group-item list-group-item-action" href="#" data-toggle="modal" data-target="#modalPersonalizar">
    <i class="fa fa-paint-brush"></i> Personalizar
  </a>
  <!-- DNS -->
  <small class="text-muted px-3 mt-3 d-block">DNS</small>
  <a class="list-group-item list-group-item-action" href="dns.php">
    <i class="fa fa-globe"></i> Registrar DNS
  </a>
  <a class="list-group-item list-group-item-action" href="migrar_dns.php">
    <i class="fa fa-server"></i> Migración masiva DNS
  </a>
  <!-- Usuarios -->
  <small class="text-muted px-3 mt-3 d-block">Usuarios</small>
  <a class="list-group-item list-group-item-action" href="users.php">
    <i class="fa fa-users"></i> Usuarios por MAC
  </a>
  <!--<a class="list-group-item list-group-item-action" href="mRTXSubscription.php">
    <i class="fa fa-calendar"></i> Alertas de expiración
  </a>-->
  <a class="list-group-item list-group-item-action" href="mRTXTrial.php">
    <i class="fa fa-desktop"></i> Cuenta Demo
  </a>
  <!-- Códigos -->
  <small class="text-muted px-3 mt-3 d-block">Códigos</small>
  <a class="list-group-item list-group-item-action" href="generar_codigo.php">
    <i class="fa fa-key"></i> Generar Códigos
  </a>
  <a class="list-group-item list-group-item-action" href="activar.php">
    <i class="fa fa-check-circle"></i> Activar Códigos
  </a>
  <a class="list-group-item list-group-item-action" href="gestionar_codigos.php">
    <i class="fa fa-cogs"></i> Gestionar Códigos
  </a>
  <!-- Enlaces -->
  <small class="text-muted px-3 mt-3 d-block">Enlaces</small>
  <a class="list-group-item list-group-item-action" href="buscar_users.php">
    <i class="fa fa-share-alt"></i> Enlace para Revendedores
  </a>
  <a class="list-group-item list-group-item-action" href="activar_publico.php">
    <i class="fa fa-share-alt"></i> Enlace para Clientes
  </a>
  <!-- Perfil -->
  <small class="text-muted px-3 mt-3 d-block">Perfil</small>
  <a class="list-group-item list-group-item-action" href="user.php">
    <i class="fa fa-user"></i> Actualizar Credenciales
  </a>
</div>
    </div>
    <!-- Main content -->
    <div id="page-content-wrapper">
      <nav class="navbar navbar-expand-lg navbar-dark bg-dark">
        <button class="btn btn-primary" id="menuToggle">
          <img src="img/logo.png?ts=<?= time(); ?>" width="25" height="25" alt="Logo">
        </button>
        <div class="mx-auto text-white" id="pageMessages"></div>
        <a href="logout.php" class="btn btn-danger ml-auto">Salir</a>
      </nav>
      <div class="container-fluid mt-4">
        <!-- Aquí va tu contenido -->
      </div>
  <!-- Modal -->
<div class="modal fade" id="modalPersonalizar" tabindex="-1" role="dialog" aria-labelledby="modalPersonalizarLabel" aria-hidden="true">
  <div class="modal-dialog" role="document">
    <div class="modal-content">
      <div class="modal-header">
        <h5 class="modal-title" id="modalPersonalizarLabel">Opciones de Personalización</h5>
        <button type="button" class="close" data-dismiss="modal" aria-label="Cerrar"><span>&times;</span></button>
      </div>
      <div class="modal-body list-group">
        <a class="list-group-item list-group-item-action" href="mRTXlogo.php"><i class="fa fa-image"></i> Cambiar Logo</a>
        <a class="list-group-item list-group-item-action" href="rgvip_tipos.php"><i class="fa fa-home"></i> Tipos de Fondo</a>
        <a class="list-group-item list-group-item-action" href="mRTXMessage.php"><i class="fa fa-commenting"></i> Texto de Playlist</a>
        <a class="list-group-item list-group-item-action" href="mRTXBG.php"><i class="fa fa-picture-o"></i> Fondo de Playlist</a>
        <a class="list-group-item list-group-item-action" href="rgvip_intro.php"><i class="fa fa-film"></i> Video de Introducción</a>
      </div>
    </div>
  </div>
</div>
  <!-- Scripts -->
  <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js"></script>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js"></script>
  <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js"></script>
  <script src="js/panelrgvip.js"></script>
</body>
</html>
