Carpeta controllers
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
<?php
|
||||
|
||||
// Validar sesión
|
||||
|
||||
if (!isset($_SESSION['user'])) {
|
||||
header("Location: index.php?opt=login_operador");
|
||||
exit;
|
||||
}
|
||||
|
||||
$opt = $_GET['opt'] ?? null;
|
||||
|
||||
$user = $_SESSION['user']; // Defino el array del usuario dentro de una variable
|
||||
$rol = $user['rol']; // Defino el rol dentro de la variable
|
||||
$esAdmin = ($rol === 'admin'); // Variable booleana, true = admin
|
||||
|
||||
// Verifico rol del usuarios (solo se permite admin)
|
||||
|
||||
if (!$esAdmin) {
|
||||
header("Location: index.php?opt=home_operador");
|
||||
exit;
|
||||
}
|
||||
|
||||
// Manejo de opt
|
||||
|
||||
switch ($opt) {
|
||||
|
||||
// CARGA DE GRÁFICO DE INFORME
|
||||
|
||||
case 'informe':
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] === 'GET') {
|
||||
|
||||
ob_start();
|
||||
require_once __DIR__ . '/../views/informes/informesView.php';
|
||||
return ob_get_clean();
|
||||
}
|
||||
|
||||
// GENERAR BALANCE ANUAL
|
||||
|
||||
case 'generar_balance_anual':
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
header("Location:index.php?opt=home_operador");
|
||||
exit;
|
||||
}
|
||||
|
||||
$anio = isset($_GET['anio']) ? (int) $_GET['anio'] : date('Y');
|
||||
|
||||
// REQUIERO MODELO DE INFORME
|
||||
|
||||
require_once __DIR__ . '/../models/informeModel.php';
|
||||
$informemodel = new informeModel();
|
||||
|
||||
$datos = $informemodel->obtenerBalanceAnual($anio);
|
||||
|
||||
header('Content-Type: application/json'); // Indica al navegador que se mandará JSON
|
||||
echo json_encode($datos); // Convierte el array de PHP en JSON
|
||||
exit;
|
||||
|
||||
// GENERAR CUENTAS A COBRAR (SERVICIOS)
|
||||
|
||||
case 'generar_cuentas_por_cobrar':
|
||||
|
||||
if ($_SERVER['REQUEST_METHOD'] !== 'GET') {
|
||||
header("Location:index.php?opt=home_operador");
|
||||
exit;
|
||||
}
|
||||
|
||||
$anio = isset($_GET['anio']) ? (int) $_GET['anio'] : date('Y');
|
||||
|
||||
// REQUIERO INFORME DE MODELO
|
||||
|
||||
require_once __DIR__ . '/../models/informeModel.php';
|
||||
$informemodel = new informeModel();
|
||||
|
||||
$datos = $informemodel->obtenerACobrar($anio);
|
||||
|
||||
header('Content-Type: application/json'); // Indica al navegador que se mandará JSON
|
||||
echo json_encode($datos); // Convierte el array de PHP en JSON
|
||||
exit;
|
||||
}
|
||||
Reference in New Issue
Block a user