<?php
session_start();
if (!isset($_SESSION['usuario_id'])) {
	header('Location: index.php');
	exit;
}

require_once __DIR__ . '/../app/Core/Database.php';
require_once __DIR__ . '/../app/Controllers/ReporteController.php';

$db = (new Database())->conn;
$controlador = new ReporteController($db);
$reportes = $controlador->mostrarReportesPorUsuario($_SESSION['usuario_id']);

//print_r($_SESSION);
?>
<!DOCTYPE html>
<html lang="es">

<head>
	<meta charset="UTF-8">
	<!--meta name="viewport" content="width=device-width, initial-scale=1.0"-->
	<meta name="viewport" content="width=device-width, user-scalable=no" />
	<title>Panel de Reportes</title>
	<style>
		body {
			overflow: hidden;
		}

		.pc-container iframe {
			width: 100%;
			height: 100%;
			border: 0;
			position: absolute;
			top: 0;
			left: 0;
		}
	</style>
	<link rel="icon" href="./assets/images/favicon.svg" type="image/x-icon" />
	<link href="https://fonts.googleapis.com/css2?family=Poppins:wght@400;500;600&display=swap" rel="stylesheet" />

	<link rel="stylesheet" href="./assets/fonts/tabler-icons.min.css" />
	<link rel="stylesheet" href="./assets/fonts/feather.css" />
	<link rel="stylesheet" href="./assets/fonts/fontawesome.css" />
	<link rel="stylesheet" href="./assets/fonts/material.css" />

	<link rel="stylesheet" href="./assets/css/style.css" id="main-style-link" />
	<link rel="stylesheet" href="./assets/css/style-preset.css" />
</head>

<body data-pc-header="header-1" data-pc-preset="preset-1" data-pc-sidebar-theme="light" data-pc-sidebar-caption="true" data-pc-direction="ltr" data-pc-theme="light">
	<div class="loader-bg">
		<div class="loader-track">
			<div class="loader-fill"></div>
		</div>
	</div>
	<nav class="pc-sidebar">
		<div class="navbar-wrapper">
			<div class="m-header">
				<a href="#" class="b-brand text-primary">
					<img src="./assets/images/logo.png" alt="logo image" class="logo-lg" />
				</a>
			</div>
			<div class="navbar-content">
				<ul class="pc-navbar">
					<li class="pc-item pc-hasmenu">
						<a href="#" class="pc-link"><span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">Finanzas</span><span class="pc-arrow"><i data-feather="chevron-right"></i></span></a>
						<ul class="pc-submenu">
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiMWNjMTYzZWUtYzI2Ni00YWQ4LWIzMDUtY2Q3ZDg4YjYxZTRjIiwidCI6Ijc5NzhlNjM0LTRlMTctNDVkZi1iOWEyLWY3NGRjOGY3YzA5ZCJ9" target="visorReporte">Reporte Financiero 1</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiYWMwNmI1ZmMtZGYwYS00ODljLWE4NzgtNzM1OGRkYWQzMWMxIiwidCI6IjZiZTgxZjIwLWFlY2MtNGQyZC1hMTM0LWJmZWJlOTAxODE4NCIsImMiOjl9" target="visorReporte">Reporte 2</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiMGEyNmE5MzQtMTUxOS00YmQzLWFkOTMtYWUwYmNiMWIzNmRmIiwidCI6IjdhNTNiMjZhLTI1YTUtNGNiYS05NGM4LTM4ZWFlMWY3MzVjYSJ9" target="visorReporte">Reporte 3</a> </li>
						</ul>
					</li>
					<li class="pc-item pc-hasmenu">
						<a href="#" class="pc-link"><span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">Recursos Humanos</span><span class="pc-arrow"><i data-feather="chevron-right"></i></span></a>
						<ul class="pc-submenu">
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiMmY1NzExNzUtN2ZiMC00NGEzLThjZTMtZjYzYjEzOGQ1NWIwIiwidCI6Ijc5NzhlNjM0LTRlMTctNDVkZi1iOWEyLWY3NGRjOGY3YzA5ZCJ9&pageName=ReportSection" target="visorReporte">Reporte RRHH</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiNmRmYjQ0NDEtNTZjYS00MDhlLThlOWUtYjM1NDVmMTQ5NzNmIiwidCI6IjhkMGNjZmQzLWZhZDctNDhiNy04MzQ3LWE4NWExMzg2MzBmOSIsImMiOjh9" target="visorReporte">Reporte de Ausencias</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiNjE0MjdiZWEtNzQyNy00ZDllLWJkOWItN2U0MDg5YjdlZmFkIiwidCI6IjhkMGNjZmQzLWZhZDctNDhiNy04MzQ3LWE4NWExMzg2MzBmOSIsImMiOjh9" target="visorReporte">Reporte de Empleados</a> </li>
						</ul>
					</li>
					<li class="pc-item pc-hasmenu">
						<a href="#" class="pc-link"><span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">Comercial</span><span class="pc-arrow"><i data-feather="chevron-right"></i></span></a>
						<ul class="pc-submenu">
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiMGEyNmE5MzQtMTUxOS00YmQzLWFkOTMtYWUwYmNiMWIzNmRmIiwidCI6IjdhNTNiMjZhLTI1YTUtNGNiYS05NGM4LTM4ZWFlMWY3MzVjYSJ9" target="visorReporte">Reporte de Ventas</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiYWMwNmI1ZmMtZGYwYS00ODljLWE4NzgtNzM1OGRkYWQzMWMxIiwidCI6IjZiZTgxZjIwLWFlY2MtNGQyZC1hMTM0LWJmZWJlOTAxODE4NCIsImMiOjl9" target="visorReporte">Reporte de Compras</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiMGEyNmE5MzQtMTUxOS00YmQzLWFkOTMtYWUwYmNiMWIzNmRmIiwidCI6IjdhNTNiMjZhLTI1YTUtNGNiYS05NGM4LTM4ZWFlMWY3MzVjYSJ9" target="visorReporte">Reporte de Diario</a> </li>
						</ul>
					</li>
					<li class="pc-item pc-hasmenu">
						<a href="#" class="pc-link"><span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">Operaciones</span><span class="pc-arrow"><i data-feather="chevron-right"></i></span></a>
						<ul class="pc-submenu">
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiOTU0NGEzMDAtMGI2Ni00MmNiLWIxOWEtY2IxYmE5ZDYxNzZmIiwidCI6Ijc5NzhlNjM0LTRlMTctNDVkZi1iOWEyLWY3NGRjOGY3YzA5ZCJ9&pageName=ReportSectione15f76f290d687387405" target="visorReporte">Reporte de Clientes</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiYWMwNmI1ZmMtZGYwYS00ODljLWE4NzgtNzM1OGRkYWQzMWMxIiwidCI6IjZiZTgxZjIwLWFlY2MtNGQyZC1hMTM0LWJmZWJlOTAxODE4NCIsImMiOjl9" target="visorReporte">Reporte 2</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiMGEyNmE5MzQtMTUxOS00YmQzLWFkOTMtYWUwYmNiMWIzNmRmIiwidCI6IjdhNTNiMjZhLTI1YTUtNGNiYS05NGM4LTM4ZWFlMWY3MzVjYSJ9" target="visorReporte">Reporte 3</a> </li>
						</ul>
					</li>
					<li class="pc-item pc-hasmenu">
						<a href="#" class="pc-link"><span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">Agrícola</span><span class="pc-arrow"><i data-feather="chevron-right"></i></span></a>
						<ul class="pc-submenu">
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiNDRmNWU1ZjAtZjM2ZC00NzhjLWE5YTctMGI5ZjQ4YTc5ZWVkIiwidCI6ImI3YWVkYTBjLTY0Y2QtNDlkMi05YTRkLTMwNjIzNjc0MzJlMyIsImMiOjR9" target="visorReporte">Reporte Plaguicidas Químicos</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.powerbi.com/view?r=eyJrIjoiNGIyNmNjNzMtZjgyNS00NTAzLTlkYTMtNzg3ZjQ5NGU0NmE0IiwidCI6ImM1OWRjNTZhLTkzZWMtNGIwNy1iNzFkLTQzYzg0NDkyNTcxOCIsImMiOjR9" target="visorReporte">Reporte Panorama por Estado</a> </li>
							<li class="pc-item"> <a class="pc-link" href="//app.fabric.microsoft.com/view?r=eyJrIjoiMGEyNmE5MzQtMTUxOS00YmQzLWFkOTMtYWUwYmNiMWIzNmRmIiwidCI6IjdhNTNiMjZhLTI1YTUtNGNiYS05NGM4LTM4ZWFlMWY3MzVjYSJ9" target="visorReporte">Reporte de Diario</a> </li>
						</ul>
					</li>
					<?php while ($r = $reportes->fetch_assoc()): ?>
						<li class="pc-item">
							<a href="#" class="pc-link lh-1" onclick="cargarReporte('<?= htmlspecialchars($r['url']) ?>')">
								<span class="pc-micon"> <i class="ph ph-tree-structure"></i> </span><span class="pc-mtext">
								<?= htmlspecialchars($r['nombre']) ?>
								</span>
							</a>
						</li>
					<?php endwhile; ?>
				</ul>
			</div>
		</div>
	</nav>
	<header class="pc-header">
		<div class="m-header">
			<a href="#" class="b-brand text-primary"><img src="./assets/images/logo.png" alt="logo image" class="logo-lg" />
			</a>
		</div>
		<div class="header-wrapper shadow-sm">
			<div class="me-auto pc-mob-drp">
				<ul class="list-unstyled">
					<li class="pc-h-item pc-sidebar-collapse">
						<a href="#" class="pc-head-link ms-0" id="sidebar-hide"> <i class="ph ph-list"></i>
						</a>
					</li>
					<li class="pc-h-item pc-sidebar-popup">
						<a href="#" class="pc-head-link ms-0" id="mobile-collapse"> <i class="ph ph-list"></i>
						</a>
					</li>
				</ul>
			</div>
			<div class="ms-auto">
				<ul class="list-unstyled">
					<li class="dropdown pc-h-item header-user-profile">
						<a class="pc-head-link dropdown-toggle arrow-none me-0" data-bs-toggle="dropdown" href="#" role="button" aria-haspopup="false" data-bs-auto-close="outside" aria-expanded="false"> <img src="./assets/images/user/avatar-2.jpg" alt="user-image" class="user-avtar" />
						</a>
						<div class="dropdown-menu dropdown-user-profile dropdown-menu-end pc-h-dropdown">
							<div class="dropdown-body">
								<div class="profile-notification-scroll position-relative" style="max-height: calc(100vh - 225px)">
									<ul class="list-group list-group-flush w-100">
										<li class="list-group-item">
											<span class="dropdown-item border-0">
												<span class="d-flex align-items-center">
													<span><?= (!is_null($_SESSION['fullname'])) ? htmlspecialchars($_SESSION['fullname']) : 'Desconocido' ?>
														<br>
														<small><?= (!is_null($_SESSION['es_superadmin'])) ? 'Super Admin' : 'Usuario' ?></small>
													</span>
												</span>
											</span>
										</li>
										<li class="list-group-item">
											<a href="#" class="dropdown-item"><span class="d-flex align-items-center"><i class="ph ph-gear-six"></i> <span>Configuración</span> </span></a>
											<a href="logout.php" class="dropdown-item"> <span class="d-flex align-items-center"> <i class="ph ph-power"></i> <span>Cerrar Sesion</span></span></a>
										</li>
									</ul>
								</div>
							</div>
						</div>
					</li>
				</ul>
			</div>
		</div>
	</header>
	<div class="pc-container">
		<iframe id="visorReporte" name="visorReporte" src="//app.powerbi.com/view?r=eyJrIjoiNGMzZTNlMTMtMTY0Zi00NTBlLTkyMGEtZjg0MmYwOGQ0YjM5IiwidCI6IjQ2NTRiNmYxLTBlNDctNDU3OS1hOGExLTAyZmU5ZDk0M2M3YiIsImMiOjl9"></iframe>
	</div>

	<!-- [Page Specific JS] start -->
	<script src="./assets/js/plugins/apexcharts.min.js"></script>
	<script src="./assets/js/plugins/jsvectormap.min.js"></script>
	<script src="./assets/js/plugins/world.js"></script>
	<script src="./assets/js/plugins/world-merc.js"></script>
	<script src="./assets/js/pages/dashboard-sales.js"></script>
	<!-- [Page Specific JS] end -->
	<!-- Required Js -->
	<script src="./assets/js/plugins/popper.min.js"></script>
	<script src="./assets/js/plugins/simplebar.min.js"></script>
	<script src="./assets/js/plugins/bootstrap.min.js"></script>
	<script src="./assets/js/fonts/custom-font.js"></script>
	<script src="./assets/js/script.js"></script>
	<script src="./assets/js/theme.js"></script>
	<script src="./assets/js/plugins/feather.min.js"></script>
	<script>
		function cargarReporte(url) {
			document.getElementById('visorReporte').src = url;
		}

		layout_change("light");
		layout_sidebar_change("light");
		change_box_container("false");
		layout_caption_change("true");
		layout_rtl_change("false");
		preset_change("preset-1");
		header_change("header-1");
	</script>
</body>

</html>